Changeset 6002


Ignore:
Timestamp:
Apr 29, 2018, 3:29:10 PM (3 weeks ago)
Author:
nmedfort
Message:

Bug fix

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

Legend:

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

    r6001 r6002  
    116116}   
    117117#endif
    118 #ifdef S2P_MULTIBLOCK
    119118
    120119void S2PKernel::generateMultiBlockLogic(const std::unique_ptr<KernelBuilder> & kb, Value * const numOfBlocks) {
     
    128127    kb->SetInsertPoint(processBlock);
    129128    PHINode * blockOffsetPhi = kb->CreatePHI(kb->getSizeTy(), 2); // block offset from the base block, e.g. 0, 1, 2, ...
    130     blockOffsetPhi->addIncoming(kb->getSize(0), entry);
     129    blockOffsetPhi->addIncoming(ZERO, entry);
    131130
    132131    Value * bytepack[8];
     
    136135    Value * basisbits[8];
    137136    s2p(kb, bytepack, basisbits);
    138     for (unsigned basis_idx = 0; basis_idx < 8; ++basis_idx) {
    139         kb->storeOutputStreamBlock("basisBits", kb->getInt32(basis_idx), blockOffsetPhi, basisbits[basis_idx]);
     137    for (unsigned i = 0; i < 8; ++i) {
     138        kb->storeOutputStreamBlock("basisBits", kb->getInt32(i), blockOffsetPhi, basisbits[i]);
    140139    }
    141140    Value * nextBlk = kb->CreateAdd(blockOffsetPhi, kb->getSize(1));
    142     Value * moreToDo = kb->CreateICmpULT(blockOffsetPhi, numOfBlocks);
    143141    blockOffsetPhi->addIncoming(nextBlk, processBlock);
     142    Value * moreToDo = kb->CreateICmpNE(nextBlk, numOfBlocks);
    144143    kb->CreateCondBr(moreToDo, processBlock, s2pDone);
    145144    kb->SetInsertPoint(s2pDone);
    146145}
    147 #else
    148 void S2PKernel::generateDoBlockMethod(const std::unique_ptr<KernelBuilder> & iBuilder) {
    149     Value * bytepack[8];
    150     for (unsigned i = 0; i < 8; i++) {
    151         if (mAligned) {
    152             bytepack[i] = iBuilder->loadInputStreamPack("byteStream", iBuilder->getInt32(0), iBuilder->getInt32(i));
    153         } else {
    154             Value * ptr = iBuilder->getInputStreamPackPtr("byteStream", iBuilder->getInt32(0), iBuilder->getInt32(i));
    155             // CreateLoad defaults to aligned here, so we need to force the alignment to 1 byte.
    156             bytepack[i] = iBuilder->CreateAlignedLoad(ptr, 1);           
    157         }
    158     }
    159     Value * basisbits[8];
    160     s2p(iBuilder, bytepack, basisbits);
    161     for (unsigned i = 0; i < 8; ++i) {
    162         iBuilder->storeOutputStreamBlock("basisBits", iBuilder->getInt32(i), basisbits[i]);
    163     }
    164 }
    165 
    166 void S2PKernel::generateFinalBlockMethod(const std::unique_ptr<KernelBuilder> & iBuilder, Value * remainingBytes) {
    167     // Prepare the s2p final block function:
    168     // assumption: if remaining bytes is greater than 0, it is safe to read a full block of bytes.
    169     //  if remaining bytes is zero, no read should be performed (e.g. for mmapped buffer).
    170  
    171     BasicBlock * finalPartialBlock = iBuilder->CreateBasicBlock("partial");
    172     BasicBlock * finalEmptyBlock = iBuilder->CreateBasicBlock("empty");
    173     BasicBlock * exitBlock = iBuilder->CreateBasicBlock("exit");
    174    
    175     Value * emptyBlockCond = iBuilder->CreateICmpEQ(remainingBytes, iBuilder->getSize(0));
    176     iBuilder->CreateCondBr(emptyBlockCond, finalEmptyBlock, finalPartialBlock);
    177     iBuilder->SetInsertPoint(finalPartialBlock);
    178     CreateDoBlockMethodCall(iBuilder);
    179    
    180     iBuilder->CreateBr(exitBlock);
    181    
    182     iBuilder->SetInsertPoint(finalEmptyBlock);
    183 
    184     for (unsigned i = 0; i < 8; ++i) {
    185         iBuilder->storeOutputStreamBlock("basisBits", iBuilder->getInt32(i), Constant::getNullValue(iBuilder->getBitBlockType()));
    186     }
    187 
    188     iBuilder->CreateBr(exitBlock);
    189    
    190     iBuilder->SetInsertPoint(exitBlock);
    191 }
    192 #endif
    193146
    194147S2PKernel::S2PKernel(const std::unique_ptr<KernelBuilder> & b, bool aligned)
    195 #ifdef S2P_MULTIBLOCK
    196     : MultiBlockKernel(aligned ? "s2p" : "s2p_unaligned",
    197 #else
    198         : BlockOrientedKernel(aligned ? "s2p" : "s2p_unaligned",
    199 #endif
     148: MultiBlockKernel(aligned ? "s2p" : "s2p_unaligned",
    200149    {Binding{b->getStreamSetTy(1, 8), "byteStream", FixedRate(), Principal()}},
    201150    {Binding{b->getStreamSetTy(8, 1), "basisBits"}}, {}, {}, {}),
  • icGREP/icgrep-devel/icgrep/kernels/s2p_kernel.h

    r6001 r6002  
    1313namespace llvm { class Value; }
    1414
    15 #define S2P_MULTIBLOCK
    1615namespace kernel {
    17 #ifdef S2P_MULTIBLOCK
    18     class S2PKernel final : public MultiBlockKernel {
    19 #else
    20     class S2PKernel final : public BlockOrientedKernel {
    21 #endif
     16
     17class S2PKernel final : public MultiBlockKernel {
    2218public:
    2319    S2PKernel(const std::unique_ptr<kernel::KernelBuilder> & b, bool aligned = true);
     
    2521    bool hasSignature() const override { return false; }
    2622protected:
    27 #ifdef S2P_MULTIBLOCK
    2823    void generateMultiBlockLogic(const std::unique_ptr<KernelBuilder> & kb, llvm::Value * const numOfStrides) override;
    29 #else
    30     void generateDoBlockMethod(const std::unique_ptr<KernelBuilder> & iBuilder) override;
    31     void generateFinalBlockMethod(const std::unique_ptr<KernelBuilder> & iBuilder, llvm::Value * remainingBytes) override;
    32 #endif
    3324private:
    3425    bool mAligned;
Note: See TracChangeset for help on using the changeset viewer.