Ignore:
Timestamp:
Jul 23, 2018, 4:56:33 AM (9 months ago)
Author:
xwa163
Message:
  1. More experiment on lz4 grep
  2. Improve performance of lzparabix grep
File:
1 edited

Legend:

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

    r6111 r6132  
    1515
    1616namespace kernel{
     17    std::string LZ4ByteStreamAioKernel::getCopyByteStreamName() {
     18        return mCopyOtherByteStream ? "targetByteStream" : "byteStream";
     19    }
    1720
    18     LZ4ByteStreamAioKernel::LZ4ByteStreamAioKernel(const std::unique_ptr<kernel::KernelBuilder> &b, unsigned blockSize)
    19             : LZ4SequentialAioBaseKernel(b, "LZ4ByteStreamAioKernel", blockSize) {
     21    LZ4ByteStreamAioKernel::LZ4ByteStreamAioKernel(const std::unique_ptr<kernel::KernelBuilder> &b, bool copyOtherByteStream, unsigned blockSize)
     22            : LZ4SequentialAioBaseKernel(b, "LZ4ByteStreamAioKernel", blockSize),
     23              mCopyOtherByteStream(copyOtherByteStream) {
    2024        mStreamSetOutputs.push_back(Binding{b->getStreamSetTy(1, 8), "outputStream", BoundedRate(0, 1)});
     25        this->addScalar(b->getInt8PtrTy(), "temporaryInputPtr");
     26        if (copyOtherByteStream) {
     27            mStreamSetInputs.push_back(Binding{b->getStreamSetTy(1, 8), "targetByteStream", RateEqualTo("byteStream")});
     28        }
    2129    }
    2230
    2331    void LZ4ByteStreamAioKernel::doLiteralCopy(const std::unique_ptr<KernelBuilder> &b, llvm::Value *literalStart,
    24                                                llvm::Value *literalLength) {
     32                                               llvm::Value *literalLength, llvm::Value* blockStart) {
    2533        unsigned fw = 64;
    2634        Type* INT_FW_PTR = b->getIntNTy(fw)->getPointerTo();
    2735
    28         Value* inputBytePtr = b->getRawInputPointer("byteStream", literalStart);
     36        Value* inputBytePtr = b->getScalarField("temporaryInputPtr");
     37        inputBytePtr = b->CreateGEP(inputBytePtr, b->CreateSub(literalStart, blockStart));
     38
    2939        Value* inputPtr = b->CreatePointerCast(inputBytePtr, INT_FW_PTR);
    3040
     
    3343        Value* outputPtr = b->getRawOutputPointer("outputStream", b->CreateURem(outputPos, outputBufferSize));
    3444        outputPtr = b->CreatePointerCast(outputPtr, INT_FW_PTR);
    35 
    36         // We can always assume that we have enough output buffer based on our output buffer allocation strategy (except in extract only case)
    3745
    3846        BasicBlock* entryBlock = b->GetInsertBlock();
     
    120128    }
    121129
     130    void LZ4ByteStreamAioKernel::initializationMethod(const std::unique_ptr<KernelBuilder> &b) {
     131        b->setScalarField("temporaryInputPtr", b->CreateMalloc(b->getSize(mBlockSize)));
     132    }
     133
     134    void LZ4ByteStreamAioKernel::prepareProcessBlock(const std::unique_ptr<KernelBuilder> &b, llvm::Value* blockStart, llvm::Value* blockEnd) {
     135        Value* rawInputPtr = b->CreatePointerCast(b->getRawInputPointer(this->getCopyByteStreamName(), b->getSize(0)), b->getInt8PtrTy());
     136        Value* inputCapacity = b->getCapacity(this->getCopyByteStreamName());
     137
     138        Value* blockStartRem = b->CreateURem(blockStart, inputCapacity);
     139        Value* remSize = b->CreateSub(inputCapacity, blockStartRem);
     140
     141        Value* blockSize = b->CreateSub(blockEnd, blockStart);
     142
     143        Value* copySize1 = b->CreateUMin(remSize, blockSize);
     144        Value* copySize2 = b->CreateSub(blockSize, copySize1);
     145
     146        Value* temporayInputPtr = b->getScalarField("temporaryInputPtr");
     147
     148        b->CreateMemCpy(temporayInputPtr, b->CreateGEP(rawInputPtr, blockStartRem), copySize1, 1);
     149        b->CreateMemCpy(b->CreateGEP(temporayInputPtr, copySize1), rawInputPtr, copySize2, 1);
     150    }
     151
     152    void LZ4ByteStreamAioKernel::beforeTermination(const std::unique_ptr<KernelBuilder> &b) {
     153        b->CreateFree(b->getScalarField("temporaryInputPtr"));
     154//        b->CallPrintInt("beforeTermination", b->getSize(0));
     155    }
     156
    122157}
Note: See TracChangeset for help on using the changeset viewer.