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

u8u16 pipeline

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

Legend:

Unmodified
Added
Removed
  • 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   
Note: See TracChangeset for help on using the changeset viewer.