Changeset 5096


Ignore:
Timestamp:
Jul 17, 2016, 11:12:34 AM (3 years ago)
Author:
cameron
Message:

Simplify kernel DoBlock? interface

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

Legend:

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

    r5095 r5096  
    5454    std::vector<Type *> doBlockParameters = {selfType};
    5555    std::vector<Type *> finalBlockParameters = {selfType, iBuilder->getInt64Ty()};
     56    /*
    5657    for (auto inputSet : mStreamSetInputs) {
    5758        Type * inputSetParmType = PointerType::getUnqual(inputSet.ssType.getStreamSetBlockType(iBuilder));
     
    6465        finalBlockParameters.push_back(outputSetParmType);
    6566    }
     67     */
    6668    FunctionType * doBlockFunctionType = FunctionType::get(mDoBlockReturnType, doBlockParameters, false);
    6769    std::string doBlockName = mKernelName + doBlock_suffix;
     
    9395    finalBlockArg->setName("remainingBytes");
    9496
    95     for (auto inputSet : mStreamSetInputs) {
     97/*    for (auto inputSet : mStreamSetInputs) {
    9698        doBlockArg = &*(doBlockArgs++);
    9799        finalBlockArg = &*(finalBlockArgs++);
     
    105107        finalBlockArg->setName(outputSet.ssName);
    106108    }
    107    
     109    */
    108110    // Create the doSegment function prototype.
    109111    std::vector<Type *> doSegmentParameters = {selfType, iBuilder->getInt64Ty()};
     
    169171}
    170172
    171 
    172 
    173 
    174 Value * KernelInterface::createDoBlockCall(Value * self, std::vector<Value *> streamSets) {
     173Value * KernelInterface::createDoBlockCall(Value * self) {
    175174    Module * m = iBuilder->getModule();
    176175    std::string doBlockName = mKernelName + doBlock_suffix;
     
    180179    }
    181180    std::vector<Value *> args = {self};
    182     for (auto ss : streamSets) {
    183         args.push_back(ss);
    184     }
    185181    return iBuilder->CreateCall(doBlockMethod, args);
    186182}
    187183
    188 Value * KernelInterface::createFinalBlockCall(Value * self, Value * remainingBytes, std::vector<Value *> streamSets) {
     184Value * KernelInterface::createFinalBlockCall(Value * self, Value * remainingBytes) {
    189185    Module * m = iBuilder->getModule();
    190186    std::string finalBlockName = mKernelName + finalBlock_suffix;
     
    194190    }
    195191    std::vector<Value *> args = {self, remainingBytes};
    196     for (auto ss : streamSets) {
    197         args.push_back(ss);
    198     }
    199192    return iBuilder->CreateCall(finalBlockMethod, args);
    200193}
     194
    201195
    202196Value * KernelInterface::createDoSegmentCall(Value * self, Value * blksToDo) {
  • icGREP/icgrep-devel/icgrep/kernels/interface.h

    r5086 r5096  
    5757    llvm::Value * createInstance(std::vector<llvm::Value *> initialParameters);
    5858    llvm::Value * createInstance(std::vector<llvm::Value *> initialParameters, std::vector<kernel::StreamSetBuffer *> inputs, std::vector<kernel::StreamSetBuffer *> outputBuffers);
    59     llvm::Value * createDoBlockCall(llvm::Value * kernelInstance, std::vector<Value *> streamSets);
     59    llvm::Value * createDoBlockCall(llvm::Value * kernelInstance);
    6060    llvm::Value * createDoSegmentCall(llvm::Value * kernelInstance, llvm::Value * blkCount);
    61     llvm::Value * createFinalBlockCall(llvm::Value * kernelInstance, llvm::Value * remainingBytes, std::vector<llvm::Value *> streamSets);
     61    llvm::Value * createFinalBlockCall(llvm::Value * kernelInstance, llvm::Value * remainingBytes);
    6262    llvm::Value * createGetAccumulatorCall(llvm::Value * kernelInstance, std::string accumName);
    6363   
  • icGREP/icgrep-devel/icgrep/kernels/kernel.cpp

    r5086 r5096  
    151151    std::vector<Value *> basePtrs;
    152152    std::vector<Value *> blockMasks;
    153     for (auto sSet : mStreamSetInputs) {
     153/*    for (auto sSet : mStreamSetInputs) {
    154154        basePtrs.push_back(getScalarField(self, sSet.ssName + basePtrSuffix));
    155155        blockMasks.push_back(getScalarField(self, sSet.ssName + blkMaskSuffix));
     
    158158        basePtrs.push_back(getScalarField(self, sSet.ssName + basePtrSuffix));
    159159        blockMasks.push_back(getScalarField(self, sSet.ssName + blkMaskSuffix));
    160     }
     160    }*/
    161161   
    162162    iBuilder->CreateBr(blockLoop);
     
    169169    std::vector<Value *> doBlockArgs = {self};
    170170
    171     for (unsigned i = 0; i < basePtrs.size(); i++) {
    172         doBlockArgs.push_back(iBuilder->CreateGEP(basePtrs[i], iBuilder->CreateAnd(blockNo, blockMasks[i])));
    173     }
     171    for (auto sSet : mStreamSetInputs) {
     172        doBlockArgs.push_back(getCircularBufferBlockPointer(self, sSet.ssName, blockNo));
     173    }
     174    for (auto sSet : mStreamSetOutputs) {
     175        doBlockArgs.push_back(getCircularBufferBlockPointer(self, sSet.ssName, blockNo));
     176    }
     177//    for (unsigned i = 0; i < basePtrs.size(); i++) {
     178//        doBlockArgs.push_back(iBuilder->CreateGEP(basePtrs[i], iBuilder->CreateAnd(blockNo, blockMasks[i])));
     179//    }
    174180    Value * rslt = iBuilder->CreateCall(doBlockFunction, doBlockArgs);
    175181    setScalarField(self, blockNoScalar, iBuilder->CreateAdd(blockNo, iBuilder->getInt64(1)));
     
    218224}
    219225
    220 
    221 
     226Value * KernelBuilder::getCircularBufferBlockPointer(Value * self, std::string streamName, Value * blockNo) {
     227    Value * bufferBase = getScalarField(self, streamName + basePtrSuffix);
     228    Value * blockMask = getScalarField(self, streamName + blkMaskSuffix);
     229    return iBuilder->CreateGEP(bufferBase, iBuilder->CreateAnd(blockNo, blockMask));
     230}
     231
     232
     233
  • icGREP/icgrep-devel/icgrep/kernels/kernel.h

    r5086 r5096  
    9292    // Get a parameter by name.
    9393    llvm::Value * getParameter(llvm::Function * f, std::string paramName);
     94   
     95    // Helper.
     96    Value * getCircularBufferBlockPointer(llvm::Value * self, std::string streamName, llvm::Value * blockNo);
     97
    9498
    9599//protected:
  • icGREP/icgrep-devel/icgrep/kernels/pipeline.cpp

    r5086 r5096  
    9898   
    9999    for (unsigned i = 0; i < kernels.size(); i++) {
    100         std::vector<Value *> basePtrs;
    101         std::vector<Value *> blockMasks;
    102         for (auto sSet : kernels[i]->mStreamSetInputs) {
    103             basePtrs.push_back(kernels[i]->getScalarField(instances[i], sSet.ssName + basePtrSuffix));
    104             blockMasks.push_back(kernels[i]->getScalarField(instances[i], sSet.ssName + blkMaskSuffix));
    105         }
    106         for (auto sSet : kernels[i]->mStreamSetOutputs) {
    107             basePtrs.push_back(kernels[i]->getScalarField(instances[i], sSet.ssName + basePtrSuffix));
    108             blockMasks.push_back(kernels[i]->getScalarField(instances[i], sSet.ssName + blkMaskSuffix));
    109         }
    110         std::vector<Value *> args;
    111         for (unsigned i = 0; i < basePtrs.size(); i++) {
    112             args.push_back(iBuilder->CreateGEP(basePtrs[i], iBuilder->CreateAnd(blockNo, blockMasks[i])));
    113         }
    114         kernels[i]->createFinalBlockCall(instances[i], remainingBytes, args);
     100        kernels[i]->createFinalBlockCall(instances[i], remainingBytes);
    115101    }
    116102}
  • icGREP/icgrep-devel/icgrep/kernels/s2p_kernel.cpp

    r5074 r5096  
    133133    Value * self = getParameter(finalBlockFunction, "self");
    134134    Value * remainingBytes = getParameter(finalBlockFunction, "remainingBytes");
    135     Value * byteStreamBlock_ptr = getParameter(finalBlockFunction, "byteStream");
    136     Value * basisBitsBlock_ptr = getParameter(finalBlockFunction, "basisBits");
    137135   
    138136    BasicBlock * finalPartialBlock = BasicBlock::Create(iBuilder->getContext(), "partial", finalBlockFunction, 0);
     
    143141    iBuilder->CreateCondBr(emptyBlockCond, finalEmptyBlock, finalPartialBlock);
    144142    iBuilder->SetInsertPoint(finalPartialBlock);
    145     iBuilder->CreateCall(doBlockFunction, {self, byteStreamBlock_ptr, basisBitsBlock_ptr});
     143    iBuilder->CreateCall(doBlockFunction, {self});
    146144   
    147145    iBuilder->CreateBr(exitBlock);
    148146   
    149147    iBuilder->SetInsertPoint(finalEmptyBlock);
     148    Value * blockNo = getScalarField(self, blockNoScalar);
     149    Value * basisBitsBlock_ptr = getCircularBufferBlockPointer(self, mStreamSetOutputs[0].ssName, blockNo);   
    150150    iBuilder->CreateStore(Constant::getNullValue(basisBitsBlock_ptr->getType()->getPointerElementType()), basisBitsBlock_ptr);
    151151    iBuilder->CreateBr(exitBlock);
     
    165165    iBuilder->SetInsertPoint(BasicBlock::Create(iBuilder->getContext(), "entry", doBlockFunction, 0));
    166166   
    167     Value * byteStreamBlock_ptr = getParameter(doBlockFunction, "byteStream");
    168     Value * basisBitsBlock_ptr = getParameter(doBlockFunction, "basisBits");
     167    Value * self = getParameter(doBlockFunction, "self");
     168
     169    Value * blockNo = getScalarField(self, blockNoScalar);
     170    Value * byteStreamBlock_ptr = getCircularBufferBlockPointer(self, mStreamSetInputs[0].ssName, blockNo);
     171    Value * basisBitsBlock_ptr = getCircularBufferBlockPointer(self, mStreamSetOutputs[0].ssName, blockNo);   
     172   
    169173    Value * s_bytepack[8];
    170174    for (unsigned i = 0; i < 8; i++) {
  • icGREP/icgrep-devel/icgrep/kernels/scanmatchgen.cpp

    r5074 r5096  
    4848    Type * scanwordVectorType =  VectorType::get(T, fieldCount);
    4949
    50     Function * doBlockFunction = m->getFunction(mKernelName + "_DoBlock");
     50    Function * doBlockFunction = m->getFunction(mKernelName + doBlock_suffix);
    5151
    5252    iBuilder->SetInsertPoint(BasicBlock::Create(iBuilder->getContext(), "entry", doBlockFunction, 0));
    5353    Value * kernelStuctParam = getParameter(doBlockFunction, "self");
    54     Value * scanwordPos = getScalarField(kernelStuctParam, "BlockNo");
    55     scanwordPos = iBuilder->CreateMul(scanwordPos, ConstantInt::get(scanwordPos->getType(), iBuilder->getBitBlockWidth()));
     54    Value * blockNo = getScalarField(kernelStuctParam, blockNoScalar);
     55    Value * scanwordPos = iBuilder->CreateMul(blockNo, ConstantInt::get(blockNo->getType(), iBuilder->getBitBlockWidth()));
    5656   
    5757    Value * recordStart = getScalarField(kernelStuctParam, "LineStart");
    5858    Value * recordNum = getScalarField(kernelStuctParam, "LineNum");
    59     Value * matchResultsPtr = getParameter(doBlockFunction, "matchResults");
     59   
     60    Value * matchResultsPtr = getCircularBufferBlockPointer(kernelStuctParam, "matchResults", blockNo);
     61   
    6062    Value * matches = iBuilder->CreateBlockAlignedLoad(matchResultsPtr, {iBuilder->getInt32(0), iBuilder->getInt32(0)});
    6163    Value * linebreaks = iBuilder->CreateBlockAlignedLoad(matchResultsPtr, {iBuilder->getInt32(0), iBuilder->getInt32(1)});
     
    7274    setScalarField(kernelStuctParam, "LineStart", recordStart);
    7375    setScalarField(kernelStuctParam, "LineNum", recordNum);
    74     setScalarField(kernelStuctParam, "BlockNo", iBuilder->CreateAdd(getScalarField(kernelStuctParam, "BlockNo"), iBuilder->getInt64(1)));
    7576    iBuilder -> CreateRetVoid();
    7677    iBuilder->restoreIP(savePoint);
  • icGREP/icgrep-devel/icgrep/pablo/carry_manager.cpp

    r5063 r5096  
    198198    const unsigned bufsize = mCarryInfo->longAdvanceBufferSize(shiftAmount);
    199199    Value * indexMask = iBuilder->getInt64(bufsize - 1);  // A mask to implement circular buffer indexing
    200     Value * blockIndex = mKernelBuilder->getScalarField(mSelf, "BlockNo");
     200    Value * blockIndex = mKernelBuilder->getScalarField(mSelf, blockNoScalar);
    201201    Value * loadIndex0 = iBuilder->CreateAdd(iBuilder->CreateAnd(iBuilder->CreateSub(blockIndex, iBuilder->getInt64(advanceEntries)), indexMask), advBaseIndex);
    202202    Value * storeIndex = iBuilder->CreateAdd(iBuilder->CreateAnd(blockIndex, indexMask), advBaseIndex);
  • icGREP/icgrep-devel/icgrep/pablo/pablo_compiler.cpp

    r5064 r5096  
    6363    mCarryManager->initializeCodeGen(mKernelBuilder, mSelf);
    6464     
    65     Value * inputSet_ptr = mKernelBuilder->getParameter(doBlockFunction, "inputs");
     65    Value * blockNo = mKernelBuilder->getScalarField(mSelf, blockNoScalar);
     66    Value * inputSet_ptr = mKernelBuilder->getCircularBufferBlockPointer(mSelf, "inputs", blockNo);
    6667   
    6768    Value * outputSet_ptr = nullptr;
    6869    if (mPabloFunction->getNumOfResults() > 0) {
    69         outputSet_ptr = mKernelBuilder->getParameter(doBlockFunction, "outputs");
     70        outputSet_ptr = mKernelBuilder->getCircularBufferBlockPointer(mSelf, mKernelBuilder->mStreamSetOutputs[0].ssName, blockNo);
    7071    }
    7172    for (unsigned j = 0; j < mPabloFunction->getNumOfParameters(); ++j) {
    7273        Value * inputVal = iBuilder->CreateGEP(inputSet_ptr, {iBuilder->getInt32(0), iBuilder->getInt32(j)});
    73         //Value * inputVal = iBuilder->CreateBlockAlignedLoad(inputSet_ptr, {iBuilder->getInt32(0), iBuilder->getInt32(j)});
    7474        const Var * const var = mPabloFunction->getParameter(j);
    7575        if (DebugOptionIsSet(DumpTrace)) {
     
    8888        iBuilder->CreateBlockAlignedStore(f->second, outputSet_ptr, {iBuilder->getInt32(0), iBuilder->getInt32(j)});
    8989    }
    90     mKernelBuilder->setScalarField(mSelf, "BlockNo", iBuilder->CreateAdd(mKernelBuilder->getScalarField(mSelf, "BlockNo"), iBuilder->getInt64(1)));
    9190    iBuilder->CreateRetVoid();
    9291
  • icGREP/icgrep-devel/icgrep/pablo/pablo_kernel.cpp

    r5076 r5096  
    2121                    {},
    2222                    {},
    23                     {ScalarBinding{builder->getInt64Ty(), "BlockNo"},
    24                      ScalarBinding{builder->getBitBlockType(), "EOFmark"}}),
     23                    {ScalarBinding{builder->getBitBlockType(), "EOFmark"}}),
    2524    mPabloFunction(function) {
    2625    unsigned output_streams = function->getNumOfResults();
Note: See TracChangeset for help on using the changeset viewer.