Changeset 5109 for icGREP


Ignore:
Timestamp:
Jul 28, 2016, 11:31:36 AM (3 years ago)
Author:
cameron
Message:

u8u16 pipeline

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

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/CMakeLists.txt

    r5108 r5109  
    113113
    114114add_executable(icgrep icgrep.cpp toolchain.cpp grep_engine.cpp kernels/pipeline.cpp kernels/scanmatchgen.cpp ${PRECOMPILED_FILES})
    115 add_executable(u8u16 u8u16.cpp toolchain.cpp kernels/p2s_kernel.cpp kernels/pipeline.cpp kernels/deletion.cpp kernels/stdout_kernel.cpp)
     115add_executable(u8u16 u8u16.cpp toolchain.cpp kernels/p2s_kernel.cpp kernels/pipeline.cpp kernels/deletion.cpp)
    116116#add_executable(symtbl symboltable.cpp toolchain.cpp kernels/symboltablepipeline.cpp kernels/stdout_kernel.cpp grep_engine.cpp kernels/pipeline.cpp kernels/scanmatchgen.cpp ${PRECOMPILED_FILES})
    117117add_executable(wc wc.cpp toolchain.cpp kernels/pipeline.cpp)
  • icGREP/icgrep-devel/icgrep/kernels/deletion.cpp

    r5104 r5109  
    8989    iBuilder->SetInsertPoint(BasicBlock::Create(iBuilder->getContext(), "entry", finalBlockFunction, 0));
    9090    Value * remainingBytes = getParameter(finalBlockFunction, "remainingBytes");
    91     Value * self = getParameter(doBlockFunction, "self");
     91    Value * self = getParameter(finalBlockFunction, "self");
    9292    Value * blockNo = getScalarField(self, blockNoScalar);
    9393    Value * inputStreamBlock = getStreamSetBlockPtr(self, "inputStreamSet", blockNo);
  • icGREP/icgrep-devel/icgrep/kernels/kernel.cpp

    r5106 r5109  
    201201}
    202202
     203
     204
    203205Value * KernelBuilder::getScalarField(Value * self, std::string fieldName) {
    204206    Value * ptr = iBuilder->CreateGEP(self, {iBuilder->getInt32(0), getScalarIndex(fieldName)});
     
    226228    }
    227229    return f->second;
     230}
     231
     232size_t KernelBuilder::getStreamSetBufferSize(Value * self, std::string ssName) {
     233    unsigned ssIndex = getStreamSetIndex(ssName);
     234    if (ssIndex < mStreamSetInputs.size()) {
     235        return mStreamSetInputs[ssIndex].ssType.getBufferSize();
     236    }
     237    else {
     238        return mStreamSetOutputs[ssIndex - mStreamSetInputs.size()].ssType.getBufferSize();
     239    }
    228240}
    229241
  • icGREP/icgrep-devel/icgrep/kernels/kernel.h

    r5104 r5109  
    9797   
    9898    llvm::Value * getStreamSetBasePtr(Value * self, std::string ssName);
    99    
     99    size_t getStreamSetBufferSize(Value * self, std::string ssName);
     100
    100101    llvm::Value * getStreamSetBlockPtr(Value * self, std::string ssName, Value * blockNo);
    101102       
  • icGREP/icgrep-devel/icgrep/kernels/p2s_kernel.cpp

    r5104 r5109  
    150150
    151151void p2s_16Kernel_withCompressedOutput::prepareKernel() {
    152     setDoBlockReturnType(iBuilder->getInt32Ty());
    153152    KernelBuilder::prepareKernel();
    154153}
     154   
     155    static Function * create_write(Module * const mod) {
     156        Function * write = mod->getFunction("write");
     157        if (write == nullptr) {
     158            FunctionType *write_type =
     159            TypeBuilder<long(int, char *, long), false>::get(mod->getContext());
     160            write = cast<Function>(mod->getOrInsertFunction("write", write_type,
     161                                                            AttributeSet().addAttribute(mod->getContext(), 2U, Attribute::NoAlias)));
     162        }
     163        return write;
     164    }
     165   
     166   
    155167   
    156168void p2s_16Kernel_withCompressedOutput::generateDoBlockMethod() {
     
    159171    Type * i32 = iBuilder->getIntNTy(32);
    160172    Type * bitBlockPtrTy = llvm::PointerType::get(iBuilder->getBitBlockType(), 0);
    161    
     173    Type * i8PtrTy = iBuilder->getInt8PtrTy();
     174
     175    Function * writefn = create_write(m);
     176
    162177    Function * doBlockFunction = m->getFunction(mKernelName + doBlock_suffix);
    163178   
     
    167182    Value * basisBitsBlock_ptr = getStreamSetBlockPtr(self, "basisBits", blockNo);
    168183    Value * delCountBlock_ptr = getStreamSetBlockPtr(self, "deletionCounts", blockNo);
    169     Value * i16StreamBlock_ptr = getStreamSetBlockPtr(self, "i16Stream", blockNo);
     184    Value * i16UnitsGenerated = getScalarField(self, "unitsGenerated");  // units generated to buffer
     185    Value * i16UnitsWritten = getScalarField(self, "unitsWritten");  // units written to stdout
     186   
     187    Value * i16StreamBase_ptr = iBuilder->CreateBitCast(getStreamSetBasePtr(self, "i16Stream"), PointerType::get(iBuilder->getInt16Ty(), 0));
     188    Value * u16_output_ptr = iBuilder->CreateGEP(i16StreamBase_ptr, iBuilder->CreateSub(i16UnitsGenerated, i16UnitsWritten));
     189
    170190   
    171191    Value * hi_input[8];
     
    187207    Value * unit_counts = iBuilder->fwCast(UTF_16_units_per_register, iBuilder->CreateBlockAlignedLoad(delCountBlock_ptr, {iBuilder->getInt32(0), iBuilder->getInt32(0)}));
    188208   
    189     Value * u16_output_ptr = iBuilder->CreateBitCast(i16StreamBlock_ptr, PointerType::get(iBuilder->getInt16Ty(), 0));
    190209    Value * offset = ConstantInt::get(i32, 0);
    191210   
     
    202221        //iBuilder->CallPrintInt("offset", offset);
    203222    }
    204     iBuilder->CreateRet(offset);
    205     iBuilder->restoreIP(savePoint);
    206 }
    207        
    208 }
     223   
     224    i16UnitsGenerated = iBuilder->CreateAdd(i16UnitsGenerated, iBuilder->CreateZExt(offset, iBuilder->getSizeTy()));
     225    setScalarField(self, "unitsGenerated", i16UnitsGenerated);
     226   
     227    Value * unitsInBuffer = iBuilder->CreateSub(i16UnitsGenerated, i16UnitsWritten);
     228    Value * lessThanABlockRemaining = iBuilder->CreateICmpUGT(unitsInBuffer, ConstantInt::get(iBuilder->getSizeTy(), (getStreamSetBufferSize(self, "i16Stream") - 1) * iBuilder->getBitBlockWidth()));
     229    BasicBlock * flushStmts = BasicBlock::Create(iBuilder->getContext(), "flush", doBlockFunction, 0);
     230    BasicBlock * exitStmts = BasicBlock::Create(iBuilder->getContext(), "exit", doBlockFunction, 0);
     231    iBuilder->CreateCondBr(lessThanABlockRemaining, flushStmts, exitStmts);
     232   
     233    iBuilder->SetInsertPoint(flushStmts);
     234    iBuilder->CreateCall(writefn, std::vector<Value *>({iBuilder->getInt32(1), iBuilder->CreateBitCast(i16StreamBase_ptr, i8PtrTy), iBuilder->CreateAdd(unitsInBuffer, unitsInBuffer)}));
     235    setScalarField(self, "unitsWritten", i16UnitsGenerated); // Everything generated has now been written.
     236    iBuilder->CreateBr(exitStmts);
     237   
     238    iBuilder->SetInsertPoint(exitStmts);
     239    iBuilder->CreateRetVoid();
     240    iBuilder->restoreIP(savePoint);
     241}
     242
     243void p2s_16Kernel_withCompressedOutput::generateFinalBlockMethod() {
     244    IDISA::IDISA_Builder::InsertPoint savePoint = iBuilder->saveIP();
     245    Module * m = iBuilder->getModule();
     246    Type * i32 = iBuilder->getIntNTy(32);
     247    Type * bitBlockPtrTy = llvm::PointerType::get(iBuilder->getBitBlockType(), 0);
     248    Type * i8PtrTy = iBuilder->getInt8PtrTy();
     249    Function * writefn = create_write(m);
     250    Function * doBlockFunction = m->getFunction(mKernelName + doBlock_suffix);
     251    Function * finalBlockFunction = m->getFunction(mKernelName + finalBlock_suffix);
     252    iBuilder->SetInsertPoint(BasicBlock::Create(iBuilder->getContext(), "fb_entry", finalBlockFunction, 0));
     253    // Final Block arguments: self, remaining, then the standard DoBlock args.
     254    Function::arg_iterator args = finalBlockFunction->arg_begin();
     255    Value * self = &*(args++);
     256    /* Skip "remaining" arg */ args++;
     257    std::vector<Value *> doBlockArgs = {self};
     258    while (args != finalBlockFunction->arg_end()){
     259        doBlockArgs.push_back(&*args++);
     260    }
     261    iBuilder->CreateCall(doBlockFunction, doBlockArgs);
     262    Value * i16UnitsGenerated = getScalarField(self, "unitsGenerated");  // units generated to buffer
     263    Value * i16UnitsWritten = getScalarField(self, "unitsWritten");  // units written to stdout
     264    Value * unitsInBuffer = iBuilder->CreateSub(i16UnitsGenerated, i16UnitsWritten);
     265    Value * mustFlush = iBuilder->CreateICmpUGT(unitsInBuffer, ConstantInt::get(iBuilder->getSizeTy(), 0));
     266   
     267    BasicBlock * flushStmts = BasicBlock::Create(iBuilder->getContext(), "flush", finalBlockFunction, 0);
     268    BasicBlock * exitStmts = BasicBlock::Create(iBuilder->getContext(), "exit", finalBlockFunction, 0);
     269    iBuilder->CreateCondBr(mustFlush, flushStmts, exitStmts);
     270   
     271    iBuilder->SetInsertPoint(flushStmts);
     272    Value * i16StreamBase_ptr = iBuilder->CreateBitCast(getStreamSetBasePtr(self, "i16Stream"), PointerType::get(iBuilder->getInt16Ty(), 0));
     273    iBuilder->CreateCall(writefn, std::vector<Value *>({iBuilder->getInt32(1), iBuilder->CreateBitCast(i16StreamBase_ptr, i8PtrTy), iBuilder->CreateAdd(unitsInBuffer, unitsInBuffer)}));
     274    setScalarField(self, "unitsWritten", i16UnitsGenerated); // Everything generated has now been written.
     275    iBuilder->CreateBr(exitStmts);
     276   
     277    iBuilder->SetInsertPoint(exitStmts);
     278    iBuilder->CreateRetVoid();
     279    iBuilder->restoreIP(savePoint);
     280}
     281   
     282   
     283}
  • icGREP/icgrep-devel/icgrep/kernels/p2s_kernel.h

    r5102 r5109  
    1616namespace kernel {
    1717
    18 
    19 //    void generateP2SKernel(llvm::Module *, IDISA::IDISA_Builder * iBuilder, KernelBuilder * kBuilder);
    20 
    21 //    void generateP2S_16Kernel(llvm::Module *, IDISA::IDISA_Builder * iBuilder, KernelBuilder * kBuilder);
    22 
    23 //    void generateP2S_16_withCompressedOutputKernel(llvm::Module *, IDISA::IDISA_Builder * iBuilder, KernelBuilder * kBuilder);
    24    
    2518   
    2619class p2sKernel : public KernelBuilder {
     
    7164                  {StreamSetBinding{basisBits, "basisBits"}, StreamSetBinding{deletionCounts, "deletionCounts"}},
    7265                  {StreamSetBinding{i16Stream, "i16Stream"}},
    73                   {}, {}, {}) {}
     66                  {},
     67                  {},
     68                  {ScalarBinding{iBuilder->getSizeTy(), "unitsGenerated"}, ScalarBinding{iBuilder->getSizeTy(), "unitsWritten"}}) {}
    7469       
    7570private:
    7671    void prepareKernel() override;
    7772    void generateDoBlockMethod() override;
     73    void generateFinalBlockMethod() override;
    7874};
    7975   
  • icGREP/icgrep-devel/icgrep/u8u16.cpp

    r5101 r5109  
    219219
    220220using namespace kernel;
     221using namespace parabix;
    221222
    222223const unsigned u16OutputBlocks = 64;
     
    224225Function * u8u16Pipeline(Module * mMod, IDISA::IDISA_Builder * iBuilder, pablo::PabloFunction * function) {
    225226    Type * mBitBlockType = iBuilder->getBitBlockType();
    226     s2pKernel  s2pk(iBuilder);
     227
     228   
     229    ExternalUnboundedBuffer ByteStream(iBuilder, StreamSetType(1, i8));
     230    SingleBlockBuffer BasisBits(iBuilder, StreamSetType(8, i1));
     231    SingleBlockBuffer U8u16Bits(iBuilder, StreamSetType(18, i1));
     232    SingleBlockBuffer U16Bits(iBuilder, StreamSetType(16, i1));
     233    SingleBlockBuffer DeletionCounts(iBuilder, StreamSetType(1, i1));
     234    CircularBuffer U16out(iBuilder, StreamSetType(1, i16), u16OutputBlocks);
     235
     236    s2pKernel  s2pk(iBuilder, ByteStream, BasisBits);
    227237    s2pk.generateKernel();
    228238   
    229239    pablo_function_passes(function);
    230     pablo::PabloKernel  u8u16k(iBuilder, "u8u16", function, {});
     240    pablo::PabloKernel  u8u16k(iBuilder, "u8u16", function, BasisBits, U8u16Bits, {});
    231241    u8u16k.generateKernel();
    232242   
    233     deletionKernel delK(iBuilder, iBuilder->getBitBlockWidth()/16, 16);
     243    deletionKernel delK(iBuilder, iBuilder->getBitBlockWidth()/16, 16, U8u16Bits, U16Bits, DeletionCounts);
    234244    delK.generateKernel();
    235245   
    236     p2s_16Kernel_withCompressedOutput p2sk(iBuilder);   
     246    p2s_16Kernel_withCompressedOutput p2sk(iBuilder, U16Bits, DeletionCounts, U16out);
    237247    p2sk.generateKernel();
    238248   
    239     stdOutKernel stdOutK(iBuilder, 16);
    240     stdOutK.generateKernel();
    241    
    242     Type * const int64ty = iBuilder->getInt64Ty();
     249    Type * const size_ty = iBuilder->getSizeTy();
    243250    Type * i16PtrTy = PointerType::get(iBuilder->getInt16Ty(), 0);
    244251    Type * const voidTy = Type::getVoidTy(mMod->getContext());
    245252    Type * const inputType = PointerType::get(ArrayType::get(ArrayType::get(mBitBlockType, 8), 1), 0);
    246253   
    247     Function * const main = cast<Function>(mMod->getOrInsertFunction("Main", voidTy, inputType, int64ty, nullptr));
     254    Function * const main = cast<Function>(mMod->getOrInsertFunction("Main", voidTy, inputType, size_ty, nullptr));
    248255    main->setCallingConv(CallingConv::C);
    249256    Function::arg_iterator args = main->arg_begin();
     
    256263    iBuilder->SetInsertPoint(BasicBlock::Create(mMod->getContext(), "entry", main,0));
    257264       
    258     kernel::StreamSetBuffer ByteStream(iBuilder, StreamSetType(1, 8), 0);
    259     kernel::StreamSetBuffer BasisBits(iBuilder, StreamSetType(8, 1), 1);
    260     kernel::StreamSetBuffer U8u16Bits(iBuilder, StreamSetType(18, 1), 1);
    261     kernel::StreamSetBuffer U16Bits(iBuilder, StreamSetType(16, 1), 1);
    262     kernel::StreamSetBuffer DeletionCounts(iBuilder, StreamSetType(1, 1), 1);
    263     kernel::StreamSetBuffer U16out(iBuilder, StreamSetType(1, 16), u16OutputBlocks);
    264265
    265266    ByteStream.setStreamSetBuffer(inputStream);
     
    268269    U16Bits.allocateBuffer();
    269270    DeletionCounts.allocateBuffer();
    270     Value * u16out = U16out.allocateBuffer();
    271    
     271    U16out.allocateBuffer();
     272
    272273    Value * s2pInstance = s2pk.createInstance({}, {&ByteStream}, {&BasisBits});
    273274    Value * u8u16Instance = u8u16k.createInstance({}, {&BasisBits}, {&U8u16Bits});
    274275    Value * delInstance = delK.createInstance({}, {&U8u16Bits}, {&U16Bits, &DeletionCounts});
    275276    Value * p2sInstance = p2sk.createInstance({}, {&U16Bits, &DeletionCounts}, {&U16out});
    276     Value * stdOutInstance = stdOutK.createInstance({u16out, iBuilder->CreateGEP(u16out, {iBuilder->getInt32(u16OutputBlocks-2)})}, {&U16out}, {});
    277    
    278     generatePipelineLoop(iBuilder, {&s2pk, &u8u16k, &delK, &p2sk, &stdOutK}, {s2pInstance, u8u16Instance, delInstance, p2sInstance, stdOutInstance}, fileSize);
     277   
     278    generatePipelineLoop(iBuilder, {&s2pk, &u8u16k, &delK, &p2sk}, {s2pInstance, u8u16Instance, delInstance, p2sInstance}, fileSize);
    279279   
    280280    iBuilder->CreateRetVoid();
  • icGREP/icgrep-devel/icgrep/wc.cpp

    r5102 r5109  
    158158
    159159    Constant * record_counts_routine;
    160     Type * const int64ty = iBuilder->getInt64Ty();
     160    Type * const size_ty = iBuilder->getSizeTy();
    161161    Type * const voidTy = Type::getVoidTy(mMod->getContext());
    162     record_counts_routine = mMod->getOrInsertFunction("record_counts", voidTy, int64ty, int64ty, int64ty, int64ty, int64ty, nullptr);
     162    record_counts_routine = mMod->getOrInsertFunction("record_counts", voidTy, size_ty, size_ty, size_ty, size_ty, size_ty, nullptr);
    163163    Type * const inputType = PointerType::get(ArrayType::get(ArrayType::get(mBitBlockType, 8), 1), 0);
    164164   
    165     Function * const main = cast<Function>(mMod->getOrInsertFunction("Main", voidTy, inputType, int64ty, int64ty, nullptr));
     165    Function * const main = cast<Function>(mMod->getOrInsertFunction("Main", voidTy, inputType, size_ty, size_ty, nullptr));
    166166    main->setCallingConv(CallingConv::C);
    167167    Function::arg_iterator args = main->arg_begin();
Note: See TracChangeset for help on using the changeset viewer.