Ignore:
Timestamp:
Aug 11, 2018, 9:19:42 PM (12 months ago)
Author:
xwa163
Message:
  1. LZ4 Grep: complete utf8 character classes for multiplexing pipeline
  2. Implement multiple streams version of S2P and P2S
Location:
icGREP/icgrep-devel/icgrep/kernels
Files:
6 edited

Legend:

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

    r6144 r6145  
    112112        }
    113113    }
    114 
    115     StreamCompareKernel::StreamCompareKernel(const std::unique_ptr<kernel::KernelBuilder> &b,
    116                                              unsigned int numberOfStream):
    117             BlockOrientedKernel("UntwistByPEXTKernel",
    118                                 {
    119                                         Binding{b->getStreamSetTy(numberOfStream, 1), "stream1", FixedRate(), Principal()},
    120                                         Binding{b->getStreamSetTy(numberOfStream, 1), "stream2", FixedRate()}
    121                                 },
    122                                 {
    123 //                                        Binding{b->getStreamSetTy(numberOfOutputStream, 1), "basisBits"}
    124                                 }, {}, {}, {}),mNumberOfStream(numberOfStream)
    125     {
    126 //        this->setStride(4 * 1024 * 1024);
    127         this->addScalar(b->getSizeTy(), "pos");
    128     }
    129 
    130     void StreamCompareKernel::generateDoBlockMethod(const std::unique_ptr<KernelBuilder> &b) {
    131         Value* s1 = b->loadInputStreamBlock("stream1", b->getSize(0));
    132         Value* s2 = b->loadInputStreamBlock("stream2", b->getSize(0));
    133 
    134         for (unsigned i = 0 ; i < 4; i++) {
    135             Value* v1 = b->CreateExtractElement(s1, i);
    136             Value* v2 = b->CreateExtractElement(s2, i);
    137             Value* shouldPrint = b->CreateICmpNE(v1, v2);
    138             b->CallPrintIntCond("---pos", b->getScalarField("pos"), shouldPrint);
    139 
    140 //            b->CallPrintIntCond("s1_available", b->getAvailableItemCount("stream1"), shouldPrint);
    141             b->CallPrintRegisterCond("s1", s1, shouldPrint);
    142             b->CallPrintRegisterCond("s2", s2, shouldPrint);
    143         }
    144         b->setScalarField("pos", b->CreateAdd(b->getScalarField("pos"), b->getSize(b->getBitBlockWidth())));
    145     };
    146114}
  • icGREP/icgrep-devel/icgrep/kernels/lz4/untwist_kernel.h

    r6144 r6145  
    2828        void generateDoBlockMethod(const std::unique_ptr<KernelBuilder> & b) override;
    2929    };
    30 
    31 
    32     class StreamCompareKernel final : public BlockOrientedKernel{
    33     public:
    34         StreamCompareKernel(const std::unique_ptr<kernel::KernelBuilder> & b, unsigned numberOfStream = 1);
    35     protected:
    36         const unsigned mNumberOfStream;
    37         void generateDoBlockMethod(const std::unique_ptr<KernelBuilder> & b) override;
    38     };
    3930}
    4031
  • icGREP/icgrep-devel/icgrep/kernels/p2s_kernel.cpp

    r6135 r6145  
    6767}
    6868
     69
     70void P2SMultipleStreamsKernel::generateDoBlockMethod(const std::unique_ptr<kernel::KernelBuilder> &b) {
     71    Value * p_bitblock[8];
     72
     73    unsigned iStreamIndex = 0;
     74    for (unsigned i = 0; i < mNumsOfStreams.size(); i++) {
     75        for (unsigned j = 0; j < mNumsOfStreams[i]; j++) {
     76            p_bitblock[iStreamIndex] = b->loadInputStreamBlock("basisBits_" + std::to_string(i), b->getInt32(j));
     77            iStreamIndex++;
     78        }
     79    }
     80    while (iStreamIndex < 8) {
     81        p_bitblock[iStreamIndex] = ConstantVector::getNullValue(b->getBitBlockType());
     82        iStreamIndex++;
     83    }
     84
     85    Value * s_bytepack[8];
     86    p2s(b, p_bitblock, s_bytepack, mBasisSetNumbering);
     87    for (unsigned j = 0; j < 8; ++j) {
     88        b->storeOutputStreamPack("byteStream", b->getInt32(0), b->getInt32(j), s_bytepack[j]);
     89    }
     90}
     91
     92
    6993inline Value * partial_sum_popcounts(const std::unique_ptr<KernelBuilder> & iBuilder, const unsigned fw, Value * popcounts) {
    7094    Value * summed_counts = popcounts;
     
    192216}
    193217
     218P2SMultipleStreamsKernel::P2SMultipleStreamsKernel(const std::unique_ptr<kernel::KernelBuilder> &b,
     219                                                   cc::BitNumbering basisNumbering,
     220                                                   std::vector<unsigned> numsOfStreams)
     221        : BlockOrientedKernel("p2sMultipleStreams" + cc::numberingSuffix(basisNumbering),
     222                              {/*Binding{b->getStreamSetTy(numOfStreams, 1), "basisBits"}*/},
     223                              {Binding{b->getStreamSetTy(1, 8), "byteStream"}},
     224                              {}, {}, {}),
     225          mBasisSetNumbering(basisNumbering),
     226          mNumsOfStreams(numsOfStreams) {
     227
     228    for (unsigned i = 0; i < numsOfStreams.size(); i++) {
     229        mStreamSetInputs.push_back(Binding{b->getStreamSetTy(numsOfStreams[i], 1), "basisBits_" + std::to_string(i)});
     230    }
     231}
     232
    194233P2SKernelWithCompressedOutput::P2SKernelWithCompressedOutput(const std::unique_ptr<kernel::KernelBuilder> & b, cc::BitNumbering numbering)
    195234: BlockOrientedKernel("p2s_compress" + cc::numberingSuffix(numbering),
     
    219258}
    220259
    221 }
     260
     261}
  • icGREP/icgrep-devel/icgrep/kernels/p2s_kernel.h

    r6135 r6145  
    2222    void generateDoBlockMethod(const std::unique_ptr<kernel::KernelBuilder> & b) override;
    2323    unsigned mNumOfStreams;
     24};
     25
     26
     27class P2SMultipleStreamsKernel final : public BlockOrientedKernel {
     28public:
     29    P2SMultipleStreamsKernel(
     30            const std::unique_ptr<kernel::KernelBuilder> & b,
     31            cc::BitNumbering basisNumbering = cc::BitNumbering::LittleEndian,
     32            std::vector<unsigned> numsOfStreams = std::vector<unsigned>{8}
     33    );
     34private:
     35    cc::BitNumbering mBasisSetNumbering;
     36    void generateDoBlockMethod(const std::unique_ptr<kernel::KernelBuilder> & b) override;
     37    std::vector<unsigned> mNumsOfStreams;
    2438};
    2539
  • icGREP/icgrep-devel/icgrep/kernels/s2p_kernel.cpp

    r6135 r6145  
    176176    }
    177177}
    178    
     178
     179S2PMultipleStreamsKernel::S2PMultipleStreamsKernel(
     180        const std::unique_ptr<kernel::KernelBuilder> & b,
     181        cc::BitNumbering basisNumbering,
     182        bool aligned,
     183        std::vector<unsigned> numsOfStreams)
     184: MultiBlockKernel(aligned ? "s2pMultipleStreams" + cc::numberingSuffix(basisNumbering): "s2p_unaligned" + cc::numberingSuffix(basisNumbering),
     185                   {Binding{b->getStreamSetTy(1, 8), "byteStream", FixedRate(), Principal()}},
     186                   {}, {}, {}, {}),
     187  mBasisSetNumbering(basisNumbering),
     188  mAligned(aligned),
     189  mNumsOfStreams(numsOfStreams)
     190{
     191    for (unsigned i = 0; i < numsOfStreams.size(); i++) {
     192        mStreamSetOutputs.push_back(Binding{b->getStreamSetTy(numsOfStreams[i], 1), "basisBits_" + std::to_string(i)});
     193    }
     194}
     195
     196void S2PMultipleStreamsKernel::generateMultiBlockLogic(const std::unique_ptr<KernelBuilder> &kb,
     197                                                       llvm::Value *const numOfBlocks) {
     198    BasicBlock * entry = kb->GetInsertBlock();
     199    BasicBlock * processBlock = kb->CreateBasicBlock("processBlock");
     200    BasicBlock * s2pDone = kb->CreateBasicBlock("s2pDone");
     201    Constant * const ZERO = kb->getSize(0);
     202
     203    kb->CreateBr(processBlock);
     204
     205    kb->SetInsertPoint(processBlock);
     206    PHINode * blockOffsetPhi = kb->CreatePHI(kb->getSizeTy(), 2); // block offset from the base block, e.g. 0, 1, 2, ...
     207    blockOffsetPhi->addIncoming(ZERO, entry);
     208
     209    Value * bytepack[8];
     210    for (unsigned i = 0; i < 8; i++) {
     211        if (mAligned) {
     212            bytepack[i] = kb->loadInputStreamPack("byteStream", ZERO, kb->getInt32(i), blockOffsetPhi);
     213        } else {
     214            Value * ptr = kb->getInputStreamPackPtr("byteStream", ZERO, kb->getInt32(i), blockOffsetPhi);
     215            // CreateLoad defaults to aligned here, so we need to force the alignment to 1 byte.
     216            bytepack[i] = kb->CreateAlignedLoad(ptr, 1);
     217        }
     218    }
     219    Value * basisbits[8];
     220    s2p(kb, bytepack, basisbits, mBasisSetNumbering);
     221    unsigned iStreamIndex = 0;
     222    for (unsigned i = 0; i < mNumsOfStreams.size(); i++) {
     223        for (unsigned j = 0; j < mNumsOfStreams[i]; j++) {
     224            kb->storeOutputStreamBlock("basisBits_" + std::to_string(i), kb->getInt32(j), blockOffsetPhi, basisbits[iStreamIndex]);
     225            iStreamIndex++;
     226        }
     227    }
     228
     229    Value * nextBlk = kb->CreateAdd(blockOffsetPhi, kb->getSize(1));
     230    blockOffsetPhi->addIncoming(nextBlk, processBlock);
     231    Value * moreToDo = kb->CreateICmpNE(nextBlk, numOfBlocks);
     232    kb->CreateCondBr(moreToDo, processBlock, s2pDone);
     233    kb->SetInsertPoint(s2pDone);
     234}
     235
     236
    179237S2P_21Kernel::S2P_21Kernel(const std::unique_ptr<KernelBuilder> & b, cc::BitNumbering numbering)
    180238: MultiBlockKernel("s2p_21" + cc::numberingSuffix(numbering),
  • icGREP/icgrep-devel/icgrep/kernels/s2p_kernel.h

    r6135 r6145  
    2929};
    3030
     31class S2PMultipleStreamsKernel final : public MultiBlockKernel {
     32public:
     33    S2PMultipleStreamsKernel(const std::unique_ptr<kernel::KernelBuilder> & b, cc::BitNumbering basisNumbering = cc::BitNumbering::LittleEndian, bool aligned = true, std::vector<unsigned> numsOfStreams = std::vector<unsigned>{8});
     34protected:
     35    void generateMultiBlockLogic(const std::unique_ptr<KernelBuilder> & kb, llvm::Value * const numOfStrides) override;
     36private:
     37    cc::BitNumbering mBasisSetNumbering;
     38    bool mAligned;
     39    std::vector<unsigned> mNumsOfStreams;
     40};
     41
     42
    3143class S2P_21Kernel final : public MultiBlockKernel {
    3244public:
Note: See TracChangeset for help on using the changeset viewer.