Changeset 5689


Ignore:
Timestamp:
Oct 13, 2017, 7:06:49 AM (20 months ago)
Author:
cameron
Message:

Multiblock version of s2p - disabled for now

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

Legend:

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

    r5440 r5689  
    112112}   
    113113#endif
    114    
     114#ifdef S2P_MULTIBLOCK
     115
     116void S2PKernel::generateMultiBlockLogic(const std::unique_ptr<KernelBuilder> & kb) {
     117    BasicBlock * entry = kb->GetInsertBlock();
     118    BasicBlock * processBlock = kb->CreateBasicBlock("processBlock");
     119    BasicBlock * s2pDone = kb->CreateBasicBlock("s2pDone");
     120   
     121    Function::arg_iterator args = mCurrentMethod->arg_begin();
     122    args++; //self
     123    Value * itemsToDo = &*(args++);
     124    // Get pointer to start of the StreamSetBlock containing unprocessed input items.
     125    Value * byteStreamPtr = &*(args++);
     126    Value * basisBitsPtr = &*(args++);
     127   
     128    Constant * blockWidth = kb->getSize(kb->getBitBlockWidth());
     129    Value * blocksToDo = kb->CreateUDivCeil(itemsToDo, blockWidth); // 1 if this is the final block
     130   
     131    kb->CreateBr(processBlock);
     132   
     133    kb->SetInsertPoint(processBlock);
     134    PHINode * blockOffsetPhi = kb->CreatePHI(kb->getSizeTy(), 2); // block offset from the base block, e.g. 0, 1, 2, ...
     135    blockOffsetPhi->addIncoming(kb->getSize(0), entry);
     136
     137    Value * bytePackPtr = kb->CreateGEP(byteStreamPtr, {blockOffsetPhi, kb->getInt32(0), kb->getInt32(0)});
     138    Value * basisBlockPtr = kb->CreateGEP(basisBitsPtr, blockOffsetPhi);
     139    Value * bytepack[8];
     140    for (unsigned i = 0; i < 8; i++) {
     141        bytepack[i] = kb->CreateBlockAlignedLoad(kb->CreateGEP(bytePackPtr, kb->getInt32(i)));
     142    }
     143    Value * basisbits[8];
     144    s2p(kb, bytepack, basisbits);
     145    for (unsigned basis_idx = 0; basis_idx < 8; ++basis_idx) {
     146        kb->CreateBlockAlignedStore(basisbits[basis_idx], kb->CreateGEP(basisBlockPtr, {kb->getSize(0), kb->getInt32(basis_idx)}));
     147    }
     148    Value * nextBlk = kb->CreateAdd(blockOffsetPhi, kb->getSize(1));
     149    Value * moreToDo = kb->CreateICmpULT(blockOffsetPhi, blocksToDo);
     150    blockOffsetPhi->addIncoming(nextBlk, processBlock);
     151    kb->CreateCondBr(moreToDo, processBlock, s2pDone);
     152    kb->SetInsertPoint(s2pDone);
     153}
     154#else
    115155void S2PKernel::generateDoBlockMethod(const std::unique_ptr<KernelBuilder> & iBuilder) {
    116156    Value * bytepack[8];
     
    132172
    133173void S2PKernel::generateFinalBlockMethod(const std::unique_ptr<KernelBuilder> & iBuilder, Value * remainingBytes) {
    134     /* Prepare the s2p final block function:
    135      assumption: if remaining bytes is greater than 0, it is safe to read a full block of bytes.
    136      if remaining bytes is zero, no read should be performed (e.g. for mmapped buffer).
    137      */
    138    
     174    // Prepare the s2p final block function:
     175    // assumption: if remaining bytes is greater than 0, it is safe to read a full block of bytes.
     176    //  if remaining bytes is zero, no read should be performed (e.g. for mmapped buffer).
     177 
    139178    BasicBlock * finalPartialBlock = iBuilder->CreateBasicBlock("partial");
    140179    BasicBlock * finalEmptyBlock = iBuilder->CreateBasicBlock("empty");
     
    158197    iBuilder->SetInsertPoint(exitBlock);
    159198}
     199#endif
    160200
    161201S2PKernel::S2PKernel(const std::unique_ptr<KernelBuilder> & b, bool aligned)
    162 : BlockOrientedKernel(aligned ? "s2p" : "s2p_unaligned",
     202#ifdef S2P_MULTIBLOCK
     203    : MultiBlockKernel(aligned ? "s2p" : "s2p_unaligned",
     204#else
     205        : BlockOrientedKernel(aligned ? "s2p" : "s2p_unaligned",
     206#endif
    163207    {Binding{b->getStreamSetTy(1, 8), "byteStream"}}, {Binding{b->getStreamSetTy(8, 1), "basisBits"}}, {}, {}, {}),
    164208  mAligned(aligned) {
  • icGREP/icgrep-devel/icgrep/kernels/s2p_kernel.h

    r5464 r5689  
    99namespace IDISA { class IDISA_Builder; }  // lines 14-14
    1010namespace llvm { class Value; }
    11 
     11#define S2P_MULTIBLOCK
    1212namespace kernel {
    13 
    14 class S2PKernel final : public BlockOrientedKernel {
    15 public:   
     13#ifdef S2P_MULTIBLOCK
     14    class S2PKernel final : public MultiBlockKernel {
     15#else
     16    class S2PKernel final : public BlockOrientedKernel {
     17#endif
     18public:
    1619    S2PKernel(const std::unique_ptr<kernel::KernelBuilder> & b, bool aligned = true);
    1720    bool isCachable() const override { return true; }
    1821    bool hasSignature() const override { return false; }
    1922protected:
     23#ifdef S2P_MULTIBLOCK
     24    void generateMultiBlockLogic(const std::unique_ptr<KernelBuilder> & kb) override;
     25#else
    2026    void generateDoBlockMethod(const std::unique_ptr<KernelBuilder> & iBuilder) override;
    2127    void generateFinalBlockMethod(const std::unique_ptr<KernelBuilder> & iBuilder, llvm::Value * remainingBytes) override;
     28#endif
    2229private:
    2330    bool mAligned;
Note: See TracChangeset for help on using the changeset viewer.