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

u8u16 pipeline

File:
1 edited

Legend:

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