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.

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

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/editd/editd_cpu_kernel.cpp

    r5283 r5285  
    2323}
    2424
    25 void editdCPUKernel::generateFinalBlockMethod() const {
    26     IDISA::IDISA_Builder::InsertPoint savePoint = iBuilder->saveIP();
    27     Module * m = iBuilder->getModule();
    28     Function * doBlockFunction = m->getFunction(mKernelName + doBlock_suffix);
    29     Function * finalBlockFunction = m->getFunction(mKernelName + finalBlock_suffix);
    30     iBuilder->SetInsertPoint(BasicBlock::Create(iBuilder->getContext(), "fb_entry", finalBlockFunction, 0));
    31     // Final Block arguments: self, remaining, then the standard DoBlock args.
    32     Function::arg_iterator args = finalBlockFunction->arg_begin();
    33     Value * self = &*(args++);
    34     Value * remaining = &*(args++);
    35     std::vector<Value *> doBlockArgs = {self};
    36     while (args != finalBlockFunction->arg_end()){
    37         doBlockArgs.push_back(&*args++);
    38     }
    39     setScalarField(self, "EOFmask", iBuilder->bitblock_mask_from(remaining));
    40     iBuilder->CreateCall(doBlockFunction, doBlockArgs);
    41     iBuilder->CreateRetVoid();
    42     iBuilder->restoreIP(savePoint);
    43 }
    44    
    45 void editdCPUKernel::generateDoBlockMethod() const {
    46     IDISA::IDISA_Builder::InsertPoint savePoint = iBuilder->saveIP();
    47     Module * m = iBuilder->getModule(); 
     25void editdCPUKernel::generateDoBlockMethod(Function * function, Value * self, Value * blockNo) const {
     26    auto savePoint = iBuilder->saveIP();
    4827
    4928    Type * const int32ty = iBuilder->getInt32Ty();
    5029    Type * const int8ty = iBuilder->getInt8Ty();
    5130
    52     Function * doBlockFunction = m->getFunction(mKernelName + doBlock_suffix);
    53        
    54     BasicBlock * entryBlock = BasicBlock::Create(iBuilder->getContext(), "entry", doBlockFunction, 0);
    55    
    56     iBuilder->SetInsertPoint(entryBlock);
    57 
    58     Value * kernelStuctParam = getParameter(doBlockFunction, "self");
    59     Value * pattStartPtr = getScalarField(kernelStuctParam, "pattStream");
    60     Value * stideCarryArr = getScalarField(kernelStuctParam, "srideCarry");
    61     Value * blockNo = getScalarField(kernelStuctParam, blockNoScalar);
     31    Value * pattStartPtr = getScalarField(self, "pattStream");
     32    Value * stideCarryArr = getScalarField(self, "srideCarry");
    6233
    6334    unsigned carryIdx = 0;
    6435
    65     std::vector<std::vector<Value *>> e(mPatternLen+1, std::vector<Value *>(mEditDistance+1));
    66     std::vector<std::vector<Value *>> adv(mPatternLen, std::vector<Value *>(mEditDistance+1));
     36    std::vector<std::vector<Value *>> e(mPatternLen + 1, std::vector<Value *>(mEditDistance + 1));
     37    std::vector<std::vector<Value *>> adv(mPatternLen, std::vector<Value *>(mEditDistance + 1));
    6738    std::vector<std::vector<int>> calculated(mPatternLen, std::vector<int>(mEditDistance + 1, 0));
    6839    Value * pattPos = iBuilder->getInt32(0);
     
    7041    Value * pattCh = iBuilder->CreateLoad(pattPtr);
    7142    Value * pattIdx = iBuilder->CreateAnd(iBuilder->CreateLShr(pattCh, 1), ConstantInt::get(int8ty, 3));
    72     Value * pattStreamPtr = getStream(kernelStuctParam, "CCStream", blockNo, iBuilder->CreateZExt(pattIdx, int32ty));
     43    Value * pattStreamPtr = getStream(self, "CCStream", blockNo, iBuilder->CreateZExt(pattIdx, int32ty));
    7344    Value * pattStream = iBuilder->CreateLoad(pattStreamPtr);
    7445    pattPos = iBuilder->CreateAdd(pattPos, ConstantInt::get(int32ty, 1));
     
    8354        pattCh = iBuilder->CreateLoad(pattPtr);
    8455        pattIdx = iBuilder->CreateAnd(iBuilder->CreateLShr(pattCh, 1), ConstantInt::get(int8ty, 3));
    85         pattStreamPtr = getStream(kernelStuctParam, "CCStream", blockNo, iBuilder->CreateZExt(pattIdx, int32ty));
     56        pattStreamPtr = getStream(self, "CCStream", blockNo, iBuilder->CreateZExt(pattIdx, int32ty));
    8657        pattStream = iBuilder->CreateLoad(pattStreamPtr);
    8758
     
    10172    }
    10273   
    103     Value * ptr = getStream(kernelStuctParam, "ResultStream", blockNo, iBuilder->getInt32(0));
     74    Value * ptr = getStream(self, "ResultStream", blockNo, iBuilder->getInt32(0));
    10475    iBuilder->CreateStore(e[mPatternLen - 1][0], ptr);
    10576    for(unsigned j = 1; j<= mEditDistance; j++){
    106         ptr = getStream(kernelStuctParam, "ResultStream", blockNo, iBuilder->getInt32(j));
     77        ptr = getStream(self, "ResultStream", blockNo, iBuilder->getInt32(j));
    10778        iBuilder->CreateStore(iBuilder->CreateAnd(e[mPatternLen-1][j], iBuilder->CreateNot(e[mPatternLen-1][j-1])), ptr);
    10879    }
     
    11081    iBuilder->CreateRetVoid();
    11182    iBuilder->restoreIP(savePoint);
     83}
     84
     85void editdCPUKernel::generateFinalBlockMethod(Function * function, Value * self, Value * remainingBytes, Value * blockNo) const {
     86    setScalarField(self, "EOFmask", iBuilder->bitblock_mask_from(remainingBytes));
     87    iBuilder->CreateCall(getDoBlockFunction(), {self});
    11288}
    11389
  • icGREP/icgrep-devel/icgrep/editd/editd_cpu_kernel.h

    r5283 r5285  
    1616class editdCPUKernel : public BlockOrientedKernel {
    1717public:
    18    
     18
    1919    editdCPUKernel(IDISA::IDISA_Builder * b, unsigned dist, unsigned pattLen);
    2020   
    2121   
    2222private:
    23     void generateDoBlockMethod() const override;
    24     void generateFinalBlockMethod() const override;
     23    void generateDoBlockMethod(llvm::Function * function, llvm::Value * self, llvm::Value * blockNo) const override;
     24    void generateFinalBlockMethod(llvm::Function * function, llvm::Value * self, llvm::Value * remainingBytes, llvm::Value * blockNo) const override;
    2525    void bitblock_advance_ci_co(llvm::Value * val, unsigned shift, llvm::Value * stideCarryArr, unsigned carryIdx, std::vector<std::vector<llvm::Value *>> & adv, std::vector<std::vector<int>> & calculated, int i, int j) const;
    2626    unsigned mEditDistance;
  • icGREP/icgrep-devel/icgrep/editd/editd_gpu_kernel.cpp

    r5283 r5285  
    1212
    1313void bitblock_advance_ci_co(IDISA::IDISA_Builder * iBuilder, Value * val, unsigned shift, Value * stideCarryArr, unsigned carryIdx, std::vector<std::vector<Value *>> & adv, std::vector<std::vector<int>> & calculated, int i, int j){   
    14     if(!calculated[i][j]){
     14    if (!calculated[i][j]) {
    1515        Value * ptr = iBuilder->CreateGEP(stideCarryArr, {iBuilder->getInt32(0), iBuilder->getInt32(carryIdx)});
    1616        Value * ci = iBuilder->CreateLoad(ptr);
     
    2020        calculated[i][j] = 1;
    2121    }
    22     return;
    2322}
    2423
    25 void editdGPUKernel::generateFinalBlockMethod() const {
    26     IDISA::IDISA_Builder::InsertPoint savePoint = iBuilder->saveIP();
    27     Module * m = iBuilder->getModule();
    28     Function * doBlockFunction = m->getFunction(mKernelName + doBlock_suffix);
    29     Function * finalBlockFunction = m->getFunction(mKernelName + finalBlock_suffix);
    30     iBuilder->SetInsertPoint(BasicBlock::Create(iBuilder->getContext(), "fb_entry", finalBlockFunction, 0));
    31     // Final Block arguments: self, remaining, then the standard DoBlock args.
    32     Function::arg_iterator args = finalBlockFunction->arg_begin();
    33     Value * self = &*(args++);
    34     Value * remaining = &*(args++);
    35     std::vector<Value *> doBlockArgs = {self};
    36     while (args != finalBlockFunction->arg_end()){
    37         doBlockArgs.push_back(&*args++);
    38     }
    39     setScalarField(self, "EOFmask", iBuilder->bitblock_mask_from(remaining));
    40     iBuilder->CreateCall(doBlockFunction, doBlockArgs);
    41     iBuilder->CreateRetVoid();
    42     iBuilder->restoreIP(savePoint);
    43 }
    44    
    45 void editdGPUKernel::generateDoBlockMethod() const {
    46     IDISA::IDISA_Builder::InsertPoint savePoint = iBuilder->saveIP();
    47     Module * m = iBuilder->getModule(); 
     24void editdGPUKernel::generateDoBlockMethod(Function * function, Value * self, Value * blockNo) const {
    4825
    49     Type * const int32ty = iBuilder->getInt32Ty();
    50     Type * const int8ty = iBuilder->getInt8Ty();
    51 
    52     Function * doBlockFunction = m->getFunction(mKernelName + doBlock_suffix);
    53        
    54     BasicBlock * entryBlock = BasicBlock::Create(iBuilder->getContext(), "entry", doBlockFunction, 0);
    55    
    56     iBuilder->SetInsertPoint(entryBlock);
    57 
    58     Value * kernelStuctParam = getParameter(doBlockFunction, "self");
    59     Value * pattBuf = getScalarField(kernelStuctParam, "pattStream");
    60     Value * stideCarryArr = getScalarField(kernelStuctParam, "srideCarry");
    61     Value * blockNo = getScalarField(kernelStuctParam, blockNoScalar);
    62     Value * pattLen = ConstantInt::get(int32ty, mPatternLen+1);
    63     Value * pattPos = ConstantInt::get(int32ty, 0);
     26    IntegerType * const int32ty = iBuilder->getInt32Ty();
     27    IntegerType * const int8ty = iBuilder->getInt8Ty();
     28    Value * pattLen = iBuilder->getInt32(mPatternLen + 1);
     29    Value * pattPos = iBuilder->getInt32(0);
     30    Value * pattBuf = getScalarField(self, "pattStream");
     31    Value * stideCarryArr = getScalarField(self, "srideCarry");
    6432   
    6533    unsigned carryIdx = 0;
     
    6937    std::vector<std::vector<int>> calculated(mPatternLen, std::vector<int>(mEditDistance + 1, 0));
    7038
     39    Module * m = iBuilder->getModule();
    7140    Function * bidFunc = cast<Function>(m->getOrInsertFunction("llvm.nvvm.read.ptx.sreg.ctaid.x", int32ty, nullptr));
    7241    Value * bid = iBuilder->CreateCall(bidFunc);
     
    7544    Value * pattCh = iBuilder->CreateLoad(pattPtr);
    7645    Value * pattIdx = iBuilder->CreateAnd(iBuilder->CreateLShr(pattCh, 1), ConstantInt::get(int8ty, 3));
    77     Value * pattStreamPtr = getStream(kernelStuctParam, "CCStream", blockNo, iBuilder->CreateZExt(pattIdx, int32ty));
     46    Value * pattStreamPtr = getStream(self, "CCStream", blockNo, iBuilder->CreateZExt(pattIdx, int32ty));
    7847    Value * pattStream = iBuilder->CreateLoad(pattStreamPtr);
    7948    pattPos = iBuilder->CreateAdd(pattPos, ConstantInt::get(int32ty, 1));
     
    8150    e[0][0] = pattStream;
    8251    for(unsigned j = 1; j <= mEditDistance; j++){
    83       e[0][j] = iBuilder->allOnes();
     52        e[0][j] = iBuilder->allOnes();
    8453    }
    85 
    86     for(unsigned i = 1; i<mPatternLen; i++){     
     54    for(unsigned i = 1; i < mPatternLen; i++){
    8755        pattPtr = iBuilder->CreateGEP(pattStartPtr, pattPos);
    8856        pattCh = iBuilder->CreateLoad(pattPtr);
    8957        pattIdx = iBuilder->CreateAnd(iBuilder->CreateLShr(pattCh, 1), ConstantInt::get(int8ty, 3));
    90         pattStreamPtr = getStream(kernelStuctParam, "CCStream", blockNo, iBuilder->CreateZExt(pattIdx, int32ty));
     58        pattStreamPtr = getStream(self, "CCStream", blockNo, iBuilder->CreateZExt(pattIdx, int32ty));
    9159        pattStream = iBuilder->CreateLoad(pattStreamPtr);
    92 
    9360        bitblock_advance_ci_co(iBuilder, e[i-1][0], 1, stideCarryArr, carryIdx++, adv, calculated, i-1, 0);
    9461        e[i][0] = iBuilder->CreateAnd(adv[i-1][0], pattStream);
     
    10168            Value * tmp3 = iBuilder->CreateOr(adv[i][j-1], e[i-1][j-1]);
    10269            e[i][j] = iBuilder->CreateOr(iBuilder->CreateOr(tmp1, tmp2), tmp3);
    103 
    10470        }
    10571        pattPos = iBuilder->CreateAdd(pattPos, ConstantInt::get(int32ty, 1));
    10672    }
    107 
    108     Value * ptr = getStream(kernelStuctParam, "ResultStream", blockNo, iBuilder->getInt32(0));
     73    Value * ptr = getStream(self, "ResultStream", blockNo, iBuilder->getInt32(0));
    10974    iBuilder->CreateStore(e[mPatternLen-1][0], ptr);
    11075    for(unsigned j = 1; j<= mEditDistance; j++){
    111         ptr = getStream(kernelStuctParam, "ResultStream", blockNo, iBuilder->getInt32(j));
     76        ptr = getStream(self, "ResultStream", blockNo, iBuilder->getInt32(j));
    11277        iBuilder->CreateStore(iBuilder->CreateAnd(e[mPatternLen - 1][j], iBuilder->CreateNot(e[mPatternLen - 1][j - 1])), ptr);
    11378    }
    114     iBuilder->CreateRetVoid();
    115     iBuilder->restoreIP(savePoint);
     79}
     80
     81void editdGPUKernel::generateFinalBlockMethod(Function * function, Value * self, Value * remainingBytes, Value * blockNo) const {
     82    setScalarField(self, "EOFmask", iBuilder->bitblock_mask_from(remainingBytes));
     83    iBuilder->CreateCall(getDoBlockFunction(), { self });
    11684}
    11785
     
    12391              Binding{PointerType::get(ArrayType::get(b->getBitBlockType(), pattLen * (dist + 1) * 4), 0), "srideCarry"}},
    12492              {},
    125               {Binding{b->getBitBlockType(), "EOFmask"}}),
    126 mEditDistance(dist),
    127 mPatternLen(pattLen) {
    128 setDoBlockUpdatesProducedItemCountsAttribute(false);
     93              {Binding{b->getBitBlockType(), "EOFmask"}})
     94, mEditDistance(dist)
     95, mPatternLen(pattLen) {
     96    setDoBlockUpdatesProducedItemCountsAttribute(false);
    12997}
    13098
  • icGREP/icgrep-devel/icgrep/editd/editd_gpu_kernel.h

    r5283 r5285  
    2121   
    2222private:
    23     void generateDoBlockMethod() const override;
    24     void generateFinalBlockMethod() const override;
     23    void generateDoBlockMethod(llvm::Function * function, llvm::Value * self, llvm::Value * blockNo) const override;
     24    void generateFinalBlockMethod(llvm::Function * function, llvm::Value * self, llvm::Value * remainingBytes, llvm::Value * blockNo) const override;
    2525    unsigned mEditDistance;
    2626    unsigned mPatternLen;
  • icGREP/icgrep-devel/icgrep/editd/editdscan_kernel.cpp

    r5283 r5285  
    1818}
    1919
    20 void editdScanKernel::generateDoBlockMethod() const {
     20void editdScanKernel::generateDoBlockMethod(Function * function, Value * self, Value * blockNo) const {
    2121    auto savePoint = iBuilder->saveIP();
    22     Module * m = iBuilder->getModule();
    23     Function * scanWordFunction = generateScanWordRoutine(m);
     22    Function * scanWordFunction = generateScanWordRoutine(iBuilder->getModule());
     23    iBuilder->restoreIP(savePoint);
     24
    2425    const unsigned fieldCount = iBuilder->getBitBlockWidth() / mScanwordBitWidth;
    2526    Type * T = iBuilder->getIntNTy(mScanwordBitWidth);
    26     Type * scanwordVectorType =  VectorType::get(T, fieldCount);
    27 
    28     Function * doBlockFunction = m->getFunction(mKernelName + doBlock_suffix);
    29 
    30     iBuilder->SetInsertPoint(BasicBlock::Create(iBuilder->getContext(), "entry", doBlockFunction, 0));
    31     Value * kernelStuctParam = getParameter(doBlockFunction, "self");
    32     Value * blockNo = getScalarField(kernelStuctParam, blockNoScalar);
     27    VectorType * scanwordVectorType =  VectorType::get(T, fieldCount);
    3328    Value * scanwordPos = iBuilder->CreateMul(blockNo, ConstantInt::get(blockNo->getType(), iBuilder->getBitBlockWidth()));
    3429   
    3530    std::vector<Value * > matchWordVectors;
    36     for(unsigned d = 0; d <= mEditDistance; d++){
    37         Value * ptr = getStream(kernelStuctParam, "matchResults", blockNo, iBuilder->getInt32(d));
     31    for(unsigned d = 0; d <= mEditDistance; d++) {
     32        Value * ptr = getStream(self, "matchResults", blockNo, iBuilder->getInt32(d));
    3833        Value * matches = iBuilder->CreateBlockAlignedLoad(ptr);
    3934        matchWordVectors.push_back(iBuilder->CreateBitCast(matches, scanwordVectorType));
    4035    }
    4136   
    42     for(unsigned i = 0; i < fieldCount; ++i){       
    43         for(unsigned d = 0; d <= mEditDistance; d++){
     37    for(unsigned i = 0; i < fieldCount; ++i) {
     38        for(unsigned d = 0; d <= mEditDistance; d++) {
    4439            Value * matchWord = iBuilder->CreateExtractElement(matchWordVectors[d], ConstantInt::get(T, i));
    4540            iBuilder->CreateCall(scanWordFunction, {matchWord, iBuilder->getInt32(d), scanwordPos});
     
    4843
    4944    }
    50     iBuilder -> CreateRetVoid();
    51     iBuilder->restoreIP(savePoint);
    5245}
    5346
    5447Function * editdScanKernel::generateScanWordRoutine(Module * m) const {
    5548
    56     Type * T = iBuilder->getIntNTy(mScanwordBitWidth);
     49    IntegerType * T = iBuilder->getIntNTy(mScanwordBitWidth);
    5750
    5851    Function * scanFunc = cast<Function>(m->getOrInsertFunction("scan_word", iBuilder->getVoidTy(), T, iBuilder->getInt32Ty(), T, nullptr));
  • icGREP/icgrep-devel/icgrep/editd/editdscan_kernel.h

    r5283 r5285  
    1818       
    1919private:
    20     void generateDoBlockMethod() const override;
     20    void generateDoBlockMethod(llvm::Function * function, llvm::Value * self, llvm::Value * blockNo) const override;
    2121    llvm::Function * generateScanWordRoutine(llvm::Module * m) const;
    2222       
Note: See TracChangeset for help on using the changeset viewer.