Ignore:
Timestamp:
Feb 17, 2017, 1:31:45 PM (2 years ago)
Author:
cameron
Message:

Eliminate explicit storage of produced/processed counts for FixedRatio? streams

Location:
icGREP/icgrep-devel/icgrep/kernels
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/kernels/interface.h

    r5325 r5327  
    4040};
    4141
     42//
    4243// FixedRatio(m, n) means that the number of items processed or produced for a principal
    43 // stream set of length L are  m * L/n + L mod n
     44// stream set of length L are ceiling(L*m/n)
     45//
    4446struct FixedRatio : ProcessingRate {
    4547    FixedRatio(unsigned strmItems = 1, unsigned perPrincipalInputItems = 1)
  • icGREP/icgrep-devel/icgrep/kernels/kernel.cpp

    r5325 r5327  
    9191        }
    9292        mScalarInputs.emplace_back(mStreamSetInputBuffers[i]->getPointerType(), mStreamSetInputs[i].name + BUFFER_PTR_SUFFIX);
    93         addScalar(iBuilder->getSizeTy(), mStreamSetInputs[i].name + PROCESSED_ITEM_COUNT_SUFFIX);
     93        if ((i == 0) || !isa<FixedRatio>(mStreamSetInputs[i].rate)) {
     94            addScalar(iBuilder->getSizeTy(), mStreamSetInputs[i].name + PROCESSED_ITEM_COUNT_SUFFIX);
     95        }
    9496       
    9597    }
    9698    for (unsigned i = 0; i < mStreamSetOutputs.size(); i++) {
    9799        mScalarInputs.emplace_back(mStreamSetOutputBuffers[i]->getPointerType(), mStreamSetOutputs[i].name + BUFFER_PTR_SUFFIX);
    98         addScalar(iBuilder->getSizeTy(), mStreamSetOutputs[i].name + PRODUCED_ITEM_COUNT_SUFFIX);
     100        if ((mStreamSetInputs.empty() && (i == 0)) || !isa<FixedRatio>(mStreamSetOutputs[i].rate)) {
     101            addScalar(iBuilder->getSizeTy(), mStreamSetOutputs[i].name + PRODUCED_ITEM_COUNT_SUFFIX);
     102        }
    99103    }
    100104    for (const auto binding : mScalarInputs) {
     
    239243
    240244Value * KernelBuilder::getProcessedItemCount(Value * instance, const std::string & name) const {
     245    unsigned ssIdx = getStreamSetIndex(name);
     246    if (auto * ratio = dyn_cast<FixedRatio>(mStreamSetInputs[ssIdx].rate)) {
     247        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);
     256    }
    241257    return getScalarField(instance, name + PROCESSED_ITEM_COUNT_SUFFIX);
    242258}
    243259
    244260Value * KernelBuilder::getProducedItemCount(Value * instance, const std::string & name) const {
     261    unsigned ssIdx = getStreamSetIndex(name);
     262    if (auto * ratio = dyn_cast<FixedRatio>(mStreamSetOutputs[ssIdx].rate)) {
     263        std::string principalField = mStreamSetInputs.empty() ? mStreamSetOutputs[0].name + PRODUCED_ITEM_COUNT_SUFFIX : mStreamSetInputs[0].name + PROCESSED_ITEM_COUNT_SUFFIX;
     264        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);
     273    }
    245274    return getScalarField(instance, name + PRODUCED_ITEM_COUNT_SUFFIX);
    246275}
     
    286315}
    287316
     317
     318
    288319Value * KernelBuilder::getInputStreamBlockPtr(const std::string & name, Value * streamIndex) const {
    289320    Value * const blockIndex = computeBlockIndex(mStreamSetInputs, name, getProcessedItemCount(name));
     
    468499    processed = getProcessedItemCount(mStreamSetInputs[0].name);
    469500    Value * itemsDone = iBuilder->CreateAdd(processed, stride);
    470    
    471     // Update counts for stream sets with FixedRatio processing rates.
    472     for (unsigned i = 0; i < mStreamSetInputs.size(); i++) {
    473         if (auto * ratio = dyn_cast<FixedRatio>(mStreamSetInputs[i].rate)) {
    474             Value * items = itemsDone;
    475             if (ratio->thisStreamItems != 1) {
    476                 items = iBuilder->CreateMul(iBuilder->getSize(ratio->thisStreamItems), itemsDone);
    477             }
    478             if (ratio->principalInputItems != 1) {
    479                 Value * divisor = iBuilder->getSize(ratio->principalInputItems);
    480                 items = iBuilder->CreateAdd(iBuilder->CreateUDiv(items, divisor), iBuilder->CreateURem(items, divisor));
    481             }
    482             setProcessedItemCount(mStreamSetInputs[i].name, items);
    483         }
    484     }
    485     if (!mDoBlockUpdatesProducedItemCountsAttribute) {
    486         for (unsigned i = 0; i < mStreamSetOutputs.size(); i++) {
    487             if (auto * ratio = dyn_cast<FixedRatio>(mStreamSetOutputs[i].rate)) {
    488                 Value * produced = itemsDone;
    489                 if (ratio->thisStreamItems != 1) {
    490                     produced = iBuilder->CreateMul(iBuilder->getSize(ratio->thisStreamItems), itemsDone);
    491                 }
    492                 if (ratio->principalInputItems != 1) {
    493                     Value * divisor = iBuilder->getSize(ratio->principalInputItems);
    494                     produced = iBuilder->CreateAdd(iBuilder->CreateUDiv(produced, divisor), iBuilder->CreateURem(produced, divisor));
    495                 }
    496                 setProducedItemCount(mStreamSetOutputs[i].name, produced);
    497             }
    498         }
    499     }
     501    setProcessedItemCount(mStreamSetInputs[0].name, itemsDone);
    500502   
    501503    stridesRemaining->addIncoming(iBuilder->CreateSub(stridesRemaining, iBuilder->getSize(1)), strideLoopBody);
     
    513515   
    514516    itemsDone = producerPos[0];
    515        
    516     for (unsigned i = 0; i < mStreamSetInputs.size(); i++) {
    517         if (auto * ratio = dyn_cast<FixedRatio>(mStreamSetInputs[i].rate)) {
    518             Value * items = itemsDone;
    519             if (ratio->thisStreamItems != 1) {
    520                 items = iBuilder->CreateMul(iBuilder->getSize(ratio->thisStreamItems), itemsDone);
    521             }
    522             if (ratio->principalInputItems != 1) {
    523                 Value * divisor = iBuilder->getSize(ratio->principalInputItems);
    524                 items = iBuilder->CreateAdd(iBuilder->CreateUDiv(items, divisor), iBuilder->CreateURem(items, divisor));
    525             }
    526             setProcessedItemCount(mStreamSetInputs[i].name, items);
    527         }
    528     }
    529     if (!mDoBlockUpdatesProducedItemCountsAttribute) {
    530         for (unsigned i = 0; i < mStreamSetOutputs.size(); i++) {
    531             if (auto * ratio = dyn_cast<FixedRatio>(mStreamSetOutputs[i].rate)) {
    532                 Value * produced = itemsDone;
    533                 if (ratio->thisStreamItems != 1) {
    534                     produced = iBuilder->CreateMul(iBuilder->getSize(ratio->thisStreamItems), itemsDone);
    535                 }
    536                 if (ratio->principalInputItems != 1) {
    537                     Value * divisor = iBuilder->getSize(ratio->principalInputItems);
    538                     produced = iBuilder->CreateAdd(iBuilder->CreateUDiv(produced, divisor), iBuilder->CreateURem(produced, divisor));
    539                 }
    540                 setProducedItemCount(mStreamSetOutputs[i].name, produced);
    541             }
    542         }
    543     }
     517    setProcessedItemCount(mStreamSetInputs[0].name, itemsDone);   
    544518   
    545519    setTerminationSignal();
  • icGREP/icgrep-devel/icgrep/kernels/radix64.cpp

    r5325 r5327  
    7878        expand_3_4_shuffle[j] = ConstantVector::get(Idxs);
    7979    }
    80     Constant * Const3 = iBuilder->getSize(3);
    81     Constant * Const4 = iBuilder->getSize(4);
    82     Constant * Const6 = iBuilder->getSize(6);
    83     Constant * Const5 = iBuilder->getSize(5);
    8480
    8581    Constant * tripleBlockSize = iBuilder->getSize(3 * iBuilder->getStride());
     
    159155    loopExitOutput_ptr->addIncoming(loopNextOutputPack, expand_3_4_loop);
    160156
    161     // Update the produced and processed items count based on the loopItemsToDo value.
     157    // Update the processed items count based on the loopItemsToDo value.
    162158    processed = iBuilder->CreateAdd(processed, loopItemsToDo);
    163159    setProcessedItemCount("sourceStream", processed);
    164160
    165     // We have produced 4 output bytes for every 3 input bytes.
    166     Value * totalProduced = iBuilder->CreateMul(iBuilder->CreateUDiv(processed, Const3), Const4);
    167     setProducedItemCount("expandedStream", totalProduced);
    168161
    169162    // Except for final segment processing, we are done.
     
    236229    setProcessedItemCount("sourceStream", processed);
    237230
    238     // We have produced 4 output bytes for every 3 input bytes.  For radix64 applications,
    239     // each output byte will have six significant bits.   If the number of bytes is not
    240     // a multiple of 3, then there will be 8 or 16 additional bits to encode.  This will
    241     // require 2 or 3 additional output bytes given that each output byte only encodes 6 bits.
    242    
    243     Value * totalBits = iBuilder->CreateShl(processed, Const3);
    244     totalProduced = iBuilder->CreateUDiv(iBuilder->CreateAdd(totalBits, Const5), Const6);
    245     setProducedItemCount("expandedStream", totalProduced);
    246231   
    247232    iBuilder->CreateBr(expand3_4_exit);
     
    486471: BlockOrientedKernel(iBuilder, "base64",
    487472            {Binding{iBuilder->getStreamSetTy(1, 8), "radix64stream"}},
    488             {Binding{iBuilder->getStreamSetTy(1, 8), "base64stream"}},
     473            {Binding{iBuilder->getStreamSetTy(1, 8), "base64stream", new ProcessingRate()}},
    489474            {}, {}, {}) {
    490475    setDoBlockUpdatesProducedItemCountsAttribute(true);
Note: See TracChangeset for help on using the changeset viewer.