Changeset 5142 for icGREP/icgrep-devel


Ignore:
Timestamp:
Sep 5, 2016, 9:13:11 AM (3 years ago)
Author:
cameron
Message:

ExternalFileBuffer?, SingleBlockBuffer? fixes

Location:
icGREP/icgrep-devel/icgrep
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/grep_engine.cpp

    r5139 r5142  
    3030#include <kernels/scanmatchgen.h>
    3131#include <kernels/s2p_kernel.h>
     32#include <kernels/cc_kernel.h>
    3233#include <kernels/pipeline.h>
    3334
     
    152153    fileIdx->setName("fileIdx");
    153154       
    154     ExternalUnboundedBuffer ByteStream(iBuilder, StreamSetType(1, i8));
     155    ExternalFileBuffer ByteStream(iBuilder, StreamSetType(1, i8));
    155156    CircularBuffer BasisBits(iBuilder, StreamSetType(8, i1), segmentSize * bufferSegments);
    156157
    157158    kernel::s2pKernel  s2pk(iBuilder);
    158159    s2pk.generateKernel({&ByteStream}, {&BasisBits});
    159 
    160     re_ast = re::regular_expression_passes(re_ast);   
     160   
     161    re_ast = re::regular_expression_passes(re_ast);
    161162    pablo::PabloFunction * function = re::re2pablo_compiler(encodingBits, re_ast, CountOnly);
    162163    pablo_function_passes(function);
    163164
    164     ByteStream.setStreamSetBuffer(inputStream);
     165    ByteStream.setStreamSetBuffer(inputStream, fileSize);
    165166    BasisBits.allocateBuffer();
    166 
    167     Value * producerPtr = ByteStream.getProducerPosPtr(ByteStream.getStreamSetStructPtr());
    168     iBuilder->CreateAlignedStore(fileSize, producerPtr, 8)->setOrdering(Release);
    169167
    170168    Value * s2pInstance = s2pk.createInstance({});
  • icGREP/icgrep-devel/icgrep/kernels/kernel.cpp

    r5135 r5142  
    3434
    3535void KernelBuilder::prepareKernel() {
     36    unsigned blockSize = iBuilder->getBitBlockWidth();
    3637    if (mStreamSetInputs.size() != mStreamSetInputBuffers.size()) {
    3738        throw std::runtime_error("Kernel preparation: Incorrect number of input buffers");
     
    4344    int streamSetNo = 0;
    4445    for (unsigned i = 0; i < mStreamSetInputs.size(); i++) {
     46        size_t bufferSize = mStreamSetInputBuffers[i]->getBufferSize() * blockSize;
    4547        if (!(mStreamSetInputBuffers[i]->getBufferStreamSetType() == mStreamSetInputs[i].ssType)) {
    4648             throw std::runtime_error("Kernel preparation: Incorrect input buffer type");
    4749        }
     50        if ((bufferSize > 0) && (bufferSize < codegen::SegmentSize + (blockSize + mLookAheadPositions - 1)/blockSize)) {
     51             errs() << "buffer size = " << mStreamSetInputBuffers[i]->getBufferSize() << "\n";
     52             throw std::runtime_error("Kernel preparation: Buffer size too small.");
     53        }
     54
    4855        mScalarInputs.push_back(ScalarBinding{mStreamSetInputBuffers[i]->getStreamSetStructPointerType(), mStreamSetInputs[i].ssName + basePtrSuffix});
    4956        mStreamSetNameMap.emplace(mStreamSetInputs[i].ssName, streamSetNo);
  • icGREP/icgrep-devel/icgrep/kernels/streamset.cpp

    r5139 r5142  
    6464    Type * const size_ty = iBuilder->getSizeTy();
    6565    Type * const int8ty = iBuilder->getInt8Ty();
     66    mStreamSetBufferPtr = iBuilder->CreateAlloca(mStreamSetType.getStreamSetBlockType(iBuilder));
    6667    mStreamSetStructPtr = iBuilder->CreateAlloca(mStreamSetStructType);
    6768    iBuilder->CreateStore(ConstantInt::get(size_ty, 0), iBuilder->CreateGEP(mStreamSetStructPtr, {iBuilder->getInt32(0), iBuilder->getInt32(iProducer_pos)}));
    6869    iBuilder->CreateStore(ConstantInt::get(size_ty, 0), iBuilder->CreateGEP(mStreamSetStructPtr, {iBuilder->getInt32(0), iBuilder->getInt32(iConsumer_pos)}));
    6970    iBuilder->CreateStore(ConstantInt::get(int8ty, 0), iBuilder->CreateGEP(mStreamSetStructPtr, {iBuilder->getInt32(0), iBuilder->getInt32(iEnd_of_input)}));
    70     mStreamSetBufferPtr = iBuilder->CreateGEP(mStreamSetStructPtr, {iBuilder->getInt32(0), iBuilder->getInt32(iBuffer_ptr)});
     71    iBuilder->CreateStore(mStreamSetBufferPtr, iBuilder->CreateGEP(mStreamSetStructPtr, {iBuilder->getInt32(0), iBuilder->getInt32(iBuffer_ptr)}));
    7172    return mStreamSetBufferPtr;
    7273}
     
    7475// For a single block buffer, the block pointer is always the buffer base pointer.
    7576llvm::Value * SingleBlockBuffer::getStreamSetBlockPointer(llvm::Value * basePtr, llvm::Value * blockNo) {
    76     return iBuilder->CreateGEP(mStreamSetType.getStreamSetBlockType(iBuilder), basePtr, {iBuilder->getInt32(0), iBuilder->getInt32(3)});
     77    Value * handle = iBuilder->CreateGEP(basePtr, {iBuilder->getInt32(0), iBuilder->getInt32(iBuffer_ptr)});
     78    return iBuilder->CreateLoad(handle);
    7779}
    7880
     
    8082// External Unbounded Buffer
    8183
    82 size_t ExternalUnboundedBuffer::getBufferSize() {
     84size_t ExternalFileBuffer::getBufferSize() {
    8385    return 0;
    8486}
    8587
    86 void ExternalUnboundedBuffer::setStreamSetBuffer(llvm::Value * ptr) {
     88void ExternalFileBuffer::setStreamSetBuffer(llvm::Value * ptr, Value * fileSize) {
    8789
    8890    Type * const size_ty = iBuilder->getSizeTy();
     
    9395
    9496    mStreamSetStructPtr = iBuilder->CreateAlloca(mStreamSetStructType);
    95     iBuilder->CreateStore(ConstantInt::get(size_ty, 0), iBuilder->CreateGEP(mStreamSetStructPtr, {iBuilder->getInt32(0), iBuilder->getInt32(iProducer_pos)}));
     97    iBuilder->CreateStore(fileSize, iBuilder->CreateGEP(mStreamSetStructPtr, {iBuilder->getInt32(0), iBuilder->getInt32(iProducer_pos)}));
    9698    iBuilder->CreateStore(ConstantInt::get(size_ty, 0), iBuilder->CreateGEP(mStreamSetStructPtr, {iBuilder->getInt32(0), iBuilder->getInt32(iConsumer_pos)}));
    9799    iBuilder->CreateStore(ConstantInt::get(int8ty, 1), iBuilder->CreateGEP(mStreamSetStructPtr, {iBuilder->getInt32(0), iBuilder->getInt32(iEnd_of_input)}));
    98100    iBuilder->CreateStore(mStreamSetBufferPtr, iBuilder->CreateGEP(mStreamSetStructPtr, {iBuilder->getInt32(0), iBuilder->getInt32(iBuffer_ptr)}));
    99 
    100101}
    101102
    102 llvm::PointerType * ExternalUnboundedBuffer::getStreamBufferPointerType() {
     103llvm::PointerType * ExternalFileBuffer::getStreamBufferPointerType() {
    103104    return PointerType::get(mStreamSetType.getStreamSetBlockType(iBuilder), mAddrSpace);
    104105}
    105106
    106 llvm::Value * ExternalUnboundedBuffer::allocateBuffer() {
     107llvm::Value * ExternalFileBuffer::allocateBuffer() {
    107108    throw std::runtime_error("External buffers cannot be allocated.");
    108109}
    109110
    110 llvm::Value * ExternalUnboundedBuffer::getStreamSetBlockPointer(llvm::Value * basePtr, llvm::Value * blockNo) {
     111llvm::Value * ExternalFileBuffer::getStreamSetBlockPointer(llvm::Value * basePtr, llvm::Value * blockNo) {
    111112    Value * handle = iBuilder->CreateGEP(basePtr, {iBuilder->getInt32(0), iBuilder->getInt32(iBuffer_ptr)});
    112113    return iBuilder->CreateGEP(iBuilder->CreateLoad(handle), {blockNo});
  • icGREP/icgrep-devel/icgrep/kernels/streamset.h

    r5139 r5142  
    3232class StreamSetBuffer {
    3333public:
    34     enum class BufferKind : unsigned {BlockBuffer, ExternalUnboundedBuffer, CircularBuffer, ExpandingBuffer};
     34    enum class BufferKind : unsigned {BlockBuffer, ExternalFileBuffer, CircularBuffer, ExpandingBuffer};
    3535    inline BufferKind getBufferKind() const {return mBufferKind;}
    3636    inline StreamSetType& getBufferStreamSetType() {return mStreamSetType;}
     
    8989                                                                    iBuilder->getSizeTy(),
    9090                                                                    iBuilder->getInt8Ty(),
    91                                                                     mStreamSetType.getStreamSetBlockType(iBuilder)}));
     91                                                                    getStreamBufferPointerType()}));
    9292
    9393    }
     
    9898};
    9999   
    100 class ExternalUnboundedBuffer : public StreamSetBuffer {
     100class ExternalFileBuffer : public StreamSetBuffer {
    101101public:
    102     static inline bool classof(const StreamSetBuffer * b) {return b->getBufferKind() == BufferKind::ExternalUnboundedBuffer;}
     102    static inline bool classof(const StreamSetBuffer * b) {return b->getBufferKind() == BufferKind::ExternalFileBuffer;}
    103103   
    104     ExternalUnboundedBuffer(IDISA::IDISA_Builder * b, StreamSetType ss_type, unsigned AddressSpace = 0) :
    105         StreamSetBuffer(BufferKind::ExternalUnboundedBuffer, b, ss_type) {
     104    ExternalFileBuffer(IDISA::IDISA_Builder * b, StreamSetType ss_type, unsigned AddressSpace = 0) :
     105        StreamSetBuffer(BufferKind::ExternalFileBuffer, b, ss_type) {
    106106            mBufferBlocks = 0;
    107107            mAddrSpace = AddressSpace;
     
    114114    llvm::PointerType * getStreamBufferPointerType() override;
    115115
    116     void setStreamSetBuffer(llvm::Value * ptr);
     116    void setStreamSetBuffer(llvm::Value * ptr, llvm::Value * fileSize);
    117117   
    118118    size_t getBufferSize() override;
  • icGREP/icgrep-devel/icgrep/pablo/carry_manager.cpp

    r5117 r5142  
    114114 ** ------------------------------------------------------------------------------------------------------------- */
    115115Value * CarryManager::shortAdvanceCarryInCarryOut(const unsigned index, const unsigned shiftAmount, Value * const value) {
    116     Value * result = nullptr;
    117116    Value * const carryIn = getCarryPack(index);
    118117    assert (index < mCarryOutPack.size());
  • icGREP/icgrep-devel/icgrep/u8u16.cpp

    r5141 r5142  
    226226
    227227   
    228     ExternalUnboundedBuffer ByteStream(iBuilder, StreamSetType(1, i8));
     228    ExternalFileBuffer ByteStream(iBuilder, StreamSetType(1, i8));
    229229    SingleBlockBuffer BasisBits(iBuilder, StreamSetType(8, i1));
    230230    SingleBlockBuffer U8u16Bits(iBuilder, StreamSetType(18, i1));
     
    262262       
    263263
    264     ByteStream.setStreamSetBuffer(inputStream);
     264    ByteStream.setStreamSetBuffer(inputStream, fileSize);
    265265    BasisBits.allocateBuffer();
    266266    U8u16Bits.allocateBuffer();
  • icGREP/icgrep-devel/icgrep/wc.cpp

    r5137 r5142  
    139139    Type * mBitBlockType = iBuilder->getBitBlockType();
    140140   
    141     ExternalUnboundedBuffer ByteStream(iBuilder, StreamSetType(1, i8));
     141    ExternalFileBuffer ByteStream(iBuilder, StreamSetType(1, i8));
    142142    SingleBlockBuffer BasisBits(iBuilder, StreamSetType(8, i1));
    143    
     143    //CircularBuffer BasisBits(iBuilder, StreamSetType(8, i1), codegen::SegmentSize * codegen::BufferSegments);
     144
    144145    s2pKernel  s2pk(iBuilder);
    145146    std::unique_ptr<Module> s2pM = s2pk.createKernelModule({&ByteStream}, {&BasisBits});
     
    172173    iBuilder->SetInsertPoint(BasicBlock::Create(mMod->getContext(), "entry", main,0));
    173174
    174     ByteStream.setStreamSetBuffer(inputStream);
     175    ByteStream.setStreamSetBuffer(inputStream, fileSize);
    175176    BasisBits.allocateBuffer();
    176177   
Note: See TracChangeset for help on using the changeset viewer.