Changeset 5328 for icGREP


Ignore:
Timestamp:
Feb 18, 2017, 10:07:09 AM (2 years ago)
Author:
cameron
Message:

Refining the ProcessingRate? attribute

Location:
icGREP/icgrep-devel/icgrep
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/UCD/resolve_properties.cpp

    r5267 r5328  
    106106        }
    107107        // Now compatibility properties of UTR #18 Annex C
    108         else if (value == "xdigit") {
    109             Name * digit = makeName("nd", Name::Type::UnicodeProperty);
    110             Name * hexdigit = makeName("hexdigit", Name::Type::UnicodeProperty);
    111             property->setDefinition(makeAlt({digit, hexdigit}));
    112             return true;
    113         } else if (value == "alnum") {
    114             Name * digit = makeName("nd", Name::Type::UnicodeProperty);
    115             Name * alpha = makeName("alphabetic", Name::Type::UnicodeProperty);
    116             property->setDefinition(makeAlt({digit, alpha}));
    117             return true;
    118         } else if (value == "blank") {
    119             Name * space_sep = makeName("space_separator", Name::Type::UnicodeProperty);
    120             CC * tab = makeCC(0x09);
    121             property->setDefinition(makeAlt({space_sep, tab}));
    122             return true;
    123         } else if (value == "graph") {
     108        else if (value == "graph") {
    124109            Name * space = makeName("space", Name::Type::UnicodeProperty);
    125110            Name * ctrl = makeName("control", Name::Type::UnicodeProperty);
     
    127112            Name * unassigned = makeName("cn", Name::Type::UnicodeProperty);
    128113            property->setDefinition(makeDiff(makeAny(), makeAlt({space, ctrl, surr, unassigned})));
    129             return true;
    130         } else if (value == "print") {
    131             Name * graph = makeName("graph", Name::Type::UnicodeProperty);
    132             Name * space_sep = makeName("space_separator", Name::Type::UnicodeProperty);
    133             property->setDefinition(makeAlt({graph, space_sep}));
    134             return true;
    135         } else if (value == "word") {
    136             Name * alnum = makeName("alnum", Name::Type::UnicodeProperty);
    137             Name * mark = makeName("mark", Name::Type::UnicodeProperty);
    138             Name * conn = makeName("connectorpunctuation", Name::Type::UnicodeProperty);
    139             Name * join = makeName("joincontrol", Name::Type::UnicodeProperty);
    140             property->setDefinition(makeAlt({alnum, mark, conn, join}));
    141114            return true;
    142115        } else if (value == "GCB" || value == "NonGCB"){
     
    274247                }
    275248            }
     249            // Try special cases of Unicode TR #18
     250            // Now compatibility properties of UTR #18 Annex C
     251                   
     252            else if (value == "alnum") {
     253                Name * digit = makeName("nd", Name::Type::UnicodeProperty);
     254                Name * alpha = makeName("alphabetic", Name::Type::UnicodeProperty);
     255                return resolveUnicodeSet(digit) + resolveUnicodeSet(alpha);
     256            } else if (value == "xdigit") {
     257                Name * digit = makeName("nd", Name::Type::UnicodeProperty);
     258                Name * hexdigit = makeName("hexdigit", Name::Type::UnicodeProperty);
     259                return resolveUnicodeSet(digit) + resolveUnicodeSet(hexdigit);
     260            } else if (value == "blank") {
     261                Name * space_sep = makeName("space_separator", Name::Type::UnicodeProperty);
     262                return resolveUnicodeSet(space_sep) + UnicodeSet(0x09) /* tab */;
     263            } else if (value == "print") {
     264                Name * graph = makeName("graph", Name::Type::UnicodeProperty);
     265                Name * space_sep = makeName("space_separator", Name::Type::UnicodeProperty);
     266                return resolveUnicodeSet(graph) + resolveUnicodeSet(space_sep);
     267            } else if (value == "word") {
     268                Name * alnum = makeName("alnum", Name::Type::UnicodeProperty);
     269                Name * mark = makeName("mark", Name::Type::UnicodeProperty);
     270                Name * conn = makeName("connectorpunctuation", Name::Type::UnicodeProperty);
     271                Name * join = makeName("joincontrol", Name::Type::UnicodeProperty);
     272                return resolveUnicodeSet(alnum) + resolveUnicodeSet(mark) + resolveUnicodeSet(conn) + resolveUnicodeSet(join);
     273            }
     274
    276275        }
    277276    }
  • icGREP/icgrep-devel/icgrep/kernels/interface.cpp

    r5320 r5328  
    2121
    2222using namespace llvm;
     23
     24ProcessingRate FixedRatio(unsigned strmItemsPer, unsigned perPrincipalInputItems) {
     25    return ProcessingRate(ProcessingRate::ProcessingRateKind::Fixed, strmItemsPer, perPrincipalInputItems);
     26}
     27
     28ProcessingRate MaxRatio(unsigned strmItemsPer, unsigned perPrincipalInputItems) {
     29    return ProcessingRate(ProcessingRate::ProcessingRateKind::Max, strmItemsPer, perPrincipalInputItems);
     30}
     31
     32ProcessingRate RoundUpToMultiple(unsigned itemMultiple) {
     33    return ProcessingRate(ProcessingRate::ProcessingRateKind::RoundUp, itemMultiple, itemMultiple);
     34}
     35
     36ProcessingRate UnknownRate() {
     37    return ProcessingRate(ProcessingRate::ProcessingRateKind::Unknown, 0, 0);
     38}
     39
     40Value * ProcessingRate::CreateRatioCalculation(IDISA::IDISA_Builder * b, Value * principalInputItems) const {
     41    Type * T = principalInputItems->getType();
     42    if (mKind == ProcessingRate::ProcessingRateKind::Fixed || mKind == ProcessingRate::ProcessingRateKind::Max) {
     43        Value * strmItems = (ratio_numerator == 1) ? principalInputItems : b->CreateMul(principalInputItems, ConstantInt::get(T, ratio_numerator));
     44        if (ratio_denominator == 1) return strmItems;
     45        return b->CreateUDiv(b->CreateAdd(ConstantInt::get(T, ratio_denominator - 1), strmItems), ConstantInt::get(T, ratio_denominator));
     46    }
     47    if (mKind == ProcessingRate::ProcessingRateKind::RoundUp) {
     48        Constant * multiple = ConstantInt::get(T, ratio_denominator);
     49        Constant * multipleLess1 = ConstantInt::get(T, ratio_denominator - 1);
     50        return b->CreateMul(b->CreateUDiv(b->CreateAdd(principalInputItems, multipleLess1), multiple), multiple);
     51    }
     52    return nullptr;
     53}
     54
    2355
    2456void KernelInterface::addKernelDeclarations(Module * client) {
  • icGREP/icgrep-devel/icgrep/kernels/interface.h

    r5327 r5328  
    2525//
    2626// The default ratio is FixedRatio(1) which means that there is one item processed or
    27 // produced for every item of the principal input or output item.
     27// produced for every item of the principal input or output stream.
     28// FixedRatio(m, n) means that for every group of n items of the principal stream,
     29// there are m items in the output stream (rounding up).
    2830//
    2931// Kernels which produce a variable number of items use MaxRatio(n), for a maximum
    30 // of n items produced or consumed per principal input or output item.
    31 struct ProcessingRate {
    32     enum class ClassTypeId : unsigned {FixedRatio, MaxRatio, Unknown};
    33     inline ClassTypeId getClassTypeId() const noexcept {
    34         return mClassTypeId;
    35     }
     32// of n items produced or consumed per principal input or output item.  MaxRatio(m, n)
     33// means there are at most m items for every n items of the principal stream.
     34//
     35// RoundUpToMultiple(n) means that number of items produced is the same as the
     36// number of input items, rounded up to an exact multiple of n.
     37//
     38
     39struct ProcessingRate  {
     40    enum ProcessingRateKind : uint8_t {Fixed, RoundUp, Max, Unknown};
     41    ProcessingRate() {}
     42    ProcessingRateKind getKind() const {return mKind;}
     43    bool isExact() const {return (mKind == Fixed)||(mKind == RoundUp) ;}
     44    llvm::Value * CreateRatioCalculation(IDISA::IDISA_Builder * b, llvm::Value * principalInputItems) const;
     45    friend ProcessingRate FixedRatio(unsigned strmItemsPer, unsigned perPrincipalInputItems = 1);
     46    friend ProcessingRate MaxRatio(unsigned strmItemsPer, unsigned perPrincipalInputItems = 1);
     47    friend ProcessingRate RoundUpToMultiple(unsigned itemMultiple);
     48    friend ProcessingRate UnknownRate();
    3649   
    37     ProcessingRate(ClassTypeId t = ClassTypeId::Unknown) : mClassTypeId(t) {}
     50protected:
     51    ProcessingRate(ProcessingRateKind k, unsigned numerator, unsigned denominator)
     52    : mKind(k), ratio_numerator(numerator), ratio_denominator(denominator) {}
     53    ProcessingRateKind mKind;
     54    uint16_t ratio_numerator;
     55    uint16_t ratio_denominator;
     56    bool isVariableRate();
     57};
    3858
    39     const ClassTypeId       mClassTypeId;
    40 };
    41 
    42 //
    43 // FixedRatio(m, n) means that the number of items processed or produced for a principal
    44 // stream set of length L are ceiling(L*m/n)
    45 //
    46 struct FixedRatio : ProcessingRate {
    47     FixedRatio(unsigned strmItems = 1, unsigned perPrincipalInputItems = 1)
    48     : ProcessingRate(ClassTypeId::FixedRatio), thisStreamItems(strmItems), principalInputItems(perPrincipalInputItems) {
    49     }
    50     static inline bool classof(const ProcessingRate * e) {
    51         return e->getClassTypeId() == ClassTypeId::FixedRatio;
    52     }
    53    
    54     unsigned thisStreamItems;
    55     unsigned principalInputItems;
    56 };
    57 
    58 struct MaxRatio : ProcessingRate {
    59     MaxRatio(unsigned strmItems, unsigned perPrincipalInputItems = 1)
    60     : ProcessingRate(ClassTypeId::MaxRatio), thisStreamItems(strmItems), principalInputItems(perPrincipalInputItems) {
    61     }
    62     static inline bool classof(const ProcessingRate * e) {
    63         return e->getClassTypeId() == ClassTypeId::MaxRatio;
    64     }
    65    
    66     unsigned thisStreamItems;
    67     unsigned principalInputItems;
    68 };
    69 
    70        
     59ProcessingRate FixedRatio(unsigned strmItemsPer, unsigned perPrincipalInputItems);
     60ProcessingRate MaxRatio(unsigned strmItemsPer, unsigned perPrincipalInputItems);
     61ProcessingRate RoundUpToMultiple(unsigned itemMultiple);
     62ProcessingRate UnknownRate();
    7163
    7264struct Binding {
    73     Binding(llvm::Type * type, const std::string & name, ProcessingRate * r = nullptr)
    74     : type(type), name(name) {
    75         rate = (r == nullptr) ? new FixedRatio(1, 1) : r;
    76     }
    77 
     65    Binding(llvm::Type * type, const std::string & name, ProcessingRate r = FixedRatio(1))
     66    : type(type), name(name), rate(r) { }
    7867    llvm::Type *        type;
    7968    std::string         name;
    80     ProcessingRate *    rate;
     69    ProcessingRate      rate;
    8170};
    8271
  • icGREP/icgrep-devel/icgrep/kernels/kernel.cpp

    r5327 r5328  
    9191        }
    9292        mScalarInputs.emplace_back(mStreamSetInputBuffers[i]->getPointerType(), mStreamSetInputs[i].name + BUFFER_PTR_SUFFIX);
    93         if ((i == 0) || !isa<FixedRatio>(mStreamSetInputs[i].rate)) {
     93        if ((i == 0) || !mStreamSetInputs[i].rate.isExact()) {
    9494            addScalar(iBuilder->getSizeTy(), mStreamSetInputs[i].name + PROCESSED_ITEM_COUNT_SUFFIX);
    9595        }
     
    9898    for (unsigned i = 0; i < mStreamSetOutputs.size(); i++) {
    9999        mScalarInputs.emplace_back(mStreamSetOutputBuffers[i]->getPointerType(), mStreamSetOutputs[i].name + BUFFER_PTR_SUFFIX);
    100         if ((mStreamSetInputs.empty() && (i == 0)) || !isa<FixedRatio>(mStreamSetOutputs[i].rate)) {
     100        if ((mStreamSetInputs.empty() && (i == 0)) || !mStreamSetOutputs[i].rate.isExact()) {
    101101            addScalar(iBuilder->getSizeTy(), mStreamSetOutputs[i].name + PRODUCED_ITEM_COUNT_SUFFIX);
    102102        }
     
    244244Value * KernelBuilder::getProcessedItemCount(Value * instance, const std::string & name) const {
    245245    unsigned ssIdx = getStreamSetIndex(name);
    246     if (auto * ratio = dyn_cast<FixedRatio>(mStreamSetInputs[ssIdx].rate)) {
     246    if (mStreamSetInputs[ssIdx].rate.isExact()) {
    247247        Value * principalItemsProcessed = getScalarField(instance, mStreamSetInputs[0].name + PROCESSED_ITEM_COUNT_SUFFIX);
    248         Value * items = principalItemsProcessed;
    249         if (ratio->thisStreamItems != 1) {
    250             items = iBuilder->CreateMul(iBuilder->getSize(ratio->thisStreamItems), items);
    251         }
    252         if (ratio->principalInputItems == 1) return items;
    253         Constant * divisor = iBuilder->getSize(ratio->principalInputItems);
    254         Constant * divisorLess1 = iBuilder->getSize(ratio->principalInputItems - 1);
    255         return iBuilder->CreateUDiv(iBuilder->CreateAdd(items, divisorLess1), divisor);
     248        return mStreamSetInputs[ssIdx].rate.CreateRatioCalculation(iBuilder, principalItemsProcessed);
    256249    }
    257250    return getScalarField(instance, name + PROCESSED_ITEM_COUNT_SUFFIX);
     
    260253Value * KernelBuilder::getProducedItemCount(Value * instance, const std::string & name) const {
    261254    unsigned ssIdx = getStreamSetIndex(name);
    262     if (auto * ratio = dyn_cast<FixedRatio>(mStreamSetOutputs[ssIdx].rate)) {
     255    if (mStreamSetOutputs[ssIdx].rate.isExact()) {
    263256        std::string principalField = mStreamSetInputs.empty() ? mStreamSetOutputs[0].name + PRODUCED_ITEM_COUNT_SUFFIX : mStreamSetInputs[0].name + PROCESSED_ITEM_COUNT_SUFFIX;
    264257        Value * principalItemsProcessed = getScalarField(instance, principalField);
    265         Value * items = principalItemsProcessed;
    266         if (ratio->thisStreamItems != 1) {
    267             items = iBuilder->CreateMul(iBuilder->getSize(ratio->thisStreamItems), items);
    268         }
    269         if (ratio->principalInputItems == 1) return items;
    270         Constant * divisor = iBuilder->getSize(ratio->principalInputItems);
    271         Constant * divisorLess1 = iBuilder->getSize(ratio->principalInputItems - 1);
    272         return iBuilder->CreateUDiv(iBuilder->CreateAdd(items, divisorLess1), divisor);
     258        return mStreamSetOutputs[ssIdx].rate.CreateRatioCalculation(iBuilder, principalItemsProcessed);
    273259    }
    274260    return getScalarField(instance, name + PRODUCED_ITEM_COUNT_SUFFIX);
  • icGREP/icgrep-devel/icgrep/kernels/p2s_kernel.cpp

    r5325 r5328  
    9393: BlockOrientedKernel(iBuilder, "p2s_compress",
    9494              {Binding{iBuilder->getStreamSetTy(8, 1), "basisBits"}, Binding{iBuilder->getStreamSetTy(1, 1), "deletionCounts"}},
    95                       {Binding{iBuilder->getStreamSetTy(1, 8), "byteStream", new MaxRatio(1)}},
     95                      {Binding{iBuilder->getStreamSetTy(1, 8), "byteStream", MaxRatio(1)}},
    9696              {}, {}, {}) {
    9797    setDoBlockUpdatesProducedItemCountsAttribute(true);
     
    196196: BlockOrientedKernel(b, "p2s_16_compress",
    197197              {Binding{b->getStreamSetTy(16, 1), "basisBits"}, Binding{b->getStreamSetTy(1, 1), "deletionCounts"}},
    198               {Binding{b->getStreamSetTy(1, 16), "i16Stream", new MaxRatio(1)}},
     198              {Binding{b->getStreamSetTy(1, 16), "i16Stream", MaxRatio(1)}},
    199199              {},
    200200              {},
  • icGREP/icgrep-devel/icgrep/kernels/radix64.cpp

    r5327 r5328  
    339339        storeOutputStreamPack("base64stream", iBuilder->getInt32(0), iBuilder->getInt32(i), base64pack);
    340340    }
    341     Value * produced = getProducedItemCount("base64stream");
    342     produced = iBuilder->CreateAdd(produced, iBuilder->getSize(iBuilder->getStride()));
    343     setProducedItemCount("base64stream", produced);
    344341}
    345342
     
    450447    iBuilder->CreateBr(fbExit);
    451448    iBuilder->SetInsertPoint(fbExit);
    452     Value * produced = iBuilder->CreateAdd(getProducedItemCount("base64stream"), iBuilder->CreateAdd(remainingBytes, padBytes));
    453     setProducedItemCount("base64stream", produced);
    454449}
    455450
     
    457452: SegmentOrientedKernel(iBuilder, "expand3_4",
    458453            {Binding{iBuilder->getStreamSetTy(1, 8), "sourceStream"}},
    459             {Binding{iBuilder->getStreamSetTy(1, 8), "expandedStream", new FixedRatio(4,3)}},
     454            {Binding{iBuilder->getStreamSetTy(1, 8), "expandedStream", FixedRatio(4,3)}},
    460455            {}, {}, {}) {
    461456}
     
    471466: BlockOrientedKernel(iBuilder, "base64",
    472467            {Binding{iBuilder->getStreamSetTy(1, 8), "radix64stream"}},
    473             {Binding{iBuilder->getStreamSetTy(1, 8), "base64stream", new ProcessingRate()}},
     468            {Binding{iBuilder->getStreamSetTy(1, 8), "base64stream", RoundUpToMultiple(4)}},
    474469            {}, {}, {}) {
    475470    setDoBlockUpdatesProducedItemCountsAttribute(true);
Note: See TracChangeset for help on using the changeset viewer.