Ignore:
Timestamp:
Jan 28, 2017, 3:12:03 PM (2 years ago)
Author:
nmedfort
Message:

Start of work to simplify kernel writing. Removed generateDoBlockLogic method.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/kernels/deletion.cpp

    r5283 r5285  
    5353// Outputs: the deleted streams, plus a partial sum popcount
    5454
    55 void DeletionKernel::generateDoBlockMethod() const {
    56 
    57     auto savePoint = iBuilder->saveIP();
    58     Module * m = iBuilder->getModule();
    59 
    60     Function * doBlockFunction = m->getFunction(mKernelName + doBlock_suffix);
    61 
    62     iBuilder->SetInsertPoint(BasicBlock::Create(iBuilder->getContext(), "entry", doBlockFunction, 0));
    63 
    64     Value * self = getParameter(doBlockFunction, "self");
    65 
    66     Value * blockNo = getScalarField(self, blockNoScalar);
    67 
     55void DeletionKernel::generateDoBlockMethod(Function * function, Value * self, Value * blockNo) const {
    6856    Value * delMaskPtr = getStream(self, "delMaskSet", blockNo, iBuilder->getInt32(0));
    6957    Value * delMask = iBuilder->CreateBlockAlignedLoad(delMaskPtr);
    70 
    7158    std::vector<Value *> move_masks = parallel_prefix_deletion_masks(iBuilder, mDeletionFieldWidth, delMask);
    72 
    7359    for (unsigned j = 0; j < mStreamCount; ++j) {
    7460        Value * inputStreamPtr = getStream(self, "inputStreamSet", blockNo, iBuilder->getInt32(j));
    7561        Value * input = iBuilder->CreateBlockAlignedLoad(inputStreamPtr);
    76 
    7762        Value * output = apply_parallel_prefix_deletion(iBuilder, mDeletionFieldWidth, delMask, move_masks, input);
    78 
    7963        Value * outputStreamPtr = getStream(self, "outputStreamSet", blockNo, iBuilder->getInt32(j));
    8064        iBuilder->CreateBlockAlignedStore(output, outputStreamPtr);
     
    8367    Value * delCountPtr = getStream(self, "deletionCounts", blockNo, iBuilder->getInt32(0));
    8468    iBuilder->CreateBlockAlignedStore(iBuilder->bitCast(delCount), delCountPtr);
    85     /* Stream deletion has only been applied within fields; the actual number of data items
    86      * has not yet changed.   */
     69    // Stream deletion has only been applied within fields; the actual number of data items has not yet changed.
    8770    Value * produced = getProducedItemCount(self, "outputStreamSet");
    8871    produced = iBuilder->CreateAdd(produced, iBuilder->getSize(iBuilder->getStride()));
    8972    setProducedItemCount(self, "outputStreamSet", produced);
    9073    setProducedItemCount(self, "deletionCounts", produced);
    91     iBuilder->CreateRetVoid();
    92     iBuilder->restoreIP(savePoint);
    9374}
    9475
    95 void DeletionKernel::generateFinalBlockMethod() const {
    96     auto savePoint = iBuilder->saveIP();
    97     Module * m = iBuilder->getModule();
    98 
    99     unsigned blockSize = iBuilder->getBitBlockWidth();
    100     Function * doBlockFunction = m->getFunction(mKernelName + doBlock_suffix);
    101     Function * finalBlockFunction = m->getFunction(mKernelName + finalBlock_suffix);
    102 
    103     iBuilder->SetInsertPoint(BasicBlock::Create(iBuilder->getContext(), "entry", finalBlockFunction, 0));
    104     Value * remainingBytes = getParameter(finalBlockFunction, "remainingBytes");
    105     Value * self = getParameter(finalBlockFunction, "self");
    106     Value * blockNo = getScalarField(self, blockNoScalar);
    107     Value * remaining = iBuilder->CreateZExt(remainingBytes, iBuilder->getIntNTy(blockSize));
    108     Value * EOF_del = iBuilder->bitCast(iBuilder->CreateShl(Constant::getAllOnesValue(iBuilder->getIntNTy(blockSize)), remaining));
     76void DeletionKernel::generateFinalBlockMethod(Function * function, Value * self, Value * remainingBytes, Value * blockNo) const {
     77    IntegerType * vecTy = iBuilder->getIntNTy(iBuilder->getBitBlockWidth());
     78    Value * remaining = iBuilder->CreateZExt(remainingBytes, vecTy);
     79    Value * EOF_del = iBuilder->bitCast(iBuilder->CreateShl(Constant::getAllOnesValue(vecTy), remaining));
    10980    Value * const delmaskPtr = getStream(self, "delMaskSet", blockNo, iBuilder->getInt32(0));
    11081    Value * const delmaskVal = iBuilder->CreateBlockAlignedLoad(delmaskPtr);
    11182    iBuilder->CreateBlockAlignedStore(iBuilder->CreateOr(EOF_del, delmaskVal), delmaskPtr);
    112     iBuilder->CreateCall(doBlockFunction, {self});
    113     /* Adjust the produced item count */
     83    iBuilder->CreateCall(getDoBlockFunction(), {self});
     84    // Adjust the produced item count
    11485    Value * produced = getProducedItemCount(self, "outputStreamSet");
    11586    produced = iBuilder->CreateSub(produced, iBuilder->getSize(iBuilder->getStride()));
     
    11788    setProducedItemCount(self, "outputStreamSet", produced);
    11889    setProducedItemCount(self, "deletionCounts", produced);
    119 
    120     iBuilder->CreateRetVoid();
    121     iBuilder->restoreIP(savePoint);
    12290}
    12391
    124 DeletionKernel::DeletionKernel(IDISA::IDISA_Builder * iBuilder, unsigned fw, unsigned streamCount) :
    125 BlockOrientedKernel(iBuilder, "del",
     92DeletionKernel::DeletionKernel(IDISA::IDISA_Builder * iBuilder, unsigned fw, unsigned streamCount)
     93: BlockOrientedKernel(iBuilder, "del",
    12694              {Binding{iBuilder->getStreamSetTy(streamCount), "inputStreamSet"},
    12795               Binding{iBuilder->getStreamSetTy(), "delMaskSet"}},
    12896              {Binding{iBuilder->getStreamSetTy(streamCount), "outputStreamSet"},
    12997               Binding{iBuilder->getStreamSetTy(), "deletionCounts"}},
    130               {}, {}, {}),
    131 mDeletionFieldWidth(fw),
    132 mStreamCount(streamCount) {
     98              {}, {}, {})
     99, mDeletionFieldWidth(fw)
     100, mStreamCount(streamCount) {
    133101    mDoBlockUpdatesProducedItemCountsAttribute = true;
    134102}
Note: See TracChangeset for help on using the changeset viewer.