Ignore:
Timestamp:
Jun 27, 2016, 9:43:17 AM (3 years ago)
Author:
cameron
Message:

Updates for kernels with variable output length; stdout kernel

File:
1 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/kernels/p2s_kernel.cpp

    r5074 r5076  
    1010
    1111
    12 
    13 extern "C" {
    14     void buffered_write(const char * ptr, size_t bytes) {
    15         outs().write(ptr, bytes);
    16     }
    17 };
    1812
    1913namespace kernel{
     
    106100       
    107101   
    108 Function * create_write(Module * const mod) {
    109     Function * write = mod->getFunction("write");
    110     if (write == nullptr) {
    111         FunctionType *write_type =
    112         TypeBuilder<long(int, char *, long), false>::get(mod->getContext());
    113         write = cast<Function>(mod->getOrInsertFunction("write", write_type,
    114                                                         AttributeSet().addAttribute(mod->getContext(), 2U, Attribute::NoAlias)));
    115     }
    116     return write;
     102void p2s_16Kernel_withCompressedOutputKernel::prepareKernel() {
     103    setDoBlockReturnType(iBuilder->getInt32Ty());
     104    KernelBuilder::prepareKernel();
    117105}
    118 
    119 const size_t OutputBufferSize=65536;
    120 
     106   
    121107void p2s_16Kernel_withCompressedOutputKernel::generateDoBlockMethod() {
    122     outs().SetBufferSize(OutputBufferSize);
    123108    IDISA::IDISA_Builder::InsertPoint savePoint = iBuilder->saveIP();
    124109    Module * m = iBuilder->getModule();
    125110    Type * i8PtrTy = iBuilder->getInt8PtrTy();
    126     Type * i64 = iBuilder->getIntNTy(64);
     111    Type * i32 = iBuilder->getIntNTy(32);
    127112    Type * bitBlockPtrTy = llvm::PointerType::get(iBuilder->getBitBlockType(), 0);
    128113   
    129     Function * writefn = cast<Function>(m->getOrInsertFunction("buffered_write", iBuilder->getVoidTy(), i8PtrTy, i64, nullptr));
    130 
    131114    Function * doBlockFunction = m->getFunction(mKernelName + doBlock_suffix);
    132115   
     
    156139   
    157140    Value * u16_output_ptr = iBuilder->CreateBitCast(i16StreamBlock_ptr, PointerType::get(iBuilder->getInt16Ty(), 0));
    158     Value * offset = ConstantInt::get(i64, 0);
     141    Value * offset = ConstantInt::get(i32, 0);
    159142   
    160143    for (unsigned j = 0; j < 8; ++j) {
     
    163146        //iBuilder->CallPrintRegister("merge0", merge0);
    164147        iBuilder->CreateAlignedStore(merge0, iBuilder->CreateBitCast(iBuilder->CreateGEP(u16_output_ptr, offset), bitBlockPtrTy), 1);
    165         offset = iBuilder->CreateZExt(iBuilder->CreateExtractElement(unit_counts, iBuilder->getInt32(2*j)), i64);
     148        offset = iBuilder->CreateZExt(iBuilder->CreateExtractElement(unit_counts, iBuilder->getInt32(2*j)), i32);
    166149        //iBuilder->CallPrintInt("offset", offset);
    167150        iBuilder->CreateAlignedStore(merge1, iBuilder->CreateBitCast(iBuilder->CreateGEP(u16_output_ptr, offset), bitBlockPtrTy), 1);
    168151        //iBuilder->CallPrintRegister("merge1", merge1);
    169         offset = iBuilder->CreateZExt(iBuilder->CreateExtractElement(unit_counts, iBuilder->getInt32(2*j+1)), i64);
     152        offset = iBuilder->CreateZExt(iBuilder->CreateExtractElement(unit_counts, iBuilder->getInt32(2*j+1)), i32);
    170153        //iBuilder->CallPrintInt("offset", offset);
    171154    }
    172     Value * byte_offset = iBuilder->CreateAdd(offset, offset);
    173     iBuilder->CreateCall(writefn, std::vector<Value *>({iBuilder->CreateBitCast(i16StreamBlock_ptr, i8PtrTy), byte_offset}));
    174     iBuilder->CreateRetVoid();
     155    iBuilder->CreateRet(offset);
    175156    iBuilder->restoreIP(savePoint);
    176157}
Note: See TracChangeset for help on using the changeset viewer.