Ignore:
Timestamp:
Nov 18, 2016, 1:46:55 PM (2 years ago)
Author:
nmedfort
Message:

Merged PabloFunction? and PabloKernel? classes. Updated projects where necessary.

File:
1 edited

Legend:

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

    r5202 r5217  
    2626#include <pablo/pablo_toolchain.h>
    2727#include <pablo/pablo_kernel.h>
    28 #include <pablo/function.h>
     28#include <pablo/prototype.h>
    2929#include <IDISA/idisa_builder.h>
    3030#include <IDISA/idisa_target.h>
     
    5454static cl::opt<bool> memAlignBuffering("memalign-buffering", cl::desc("Enable posix_memalign buffering."), cl::cat(u8u16Options));
    5555
    56 //
    57 //
    58 //
    59 namespace pablo {
    60 
    61 PabloFunction * u8u16_pablo() {
     56
     57using namespace pablo;
     58using namespace kernel;
     59using namespace parabix;
     60
     61void u8u16_pablo(PabloKernel * kernel) {
    6262    //  input: 8 basis bit streams
    6363    //  output: 16 u8-indexed streams, + delmask stream + error stream
    64     PabloFunction * function = PabloFunction::Create("u8u16"); // , 1, 18
    65     cc::CC_Compiler ccc(*function);
     64
     65    cc::CC_Compiler ccc(kernel);
    6666   
    6767    PabloBuilder & main = ccc.getBuilder();
     
    8181    Var * delmask = main.createVar("delmask", zeroes);
    8282    Var * error_mask = main.createVar("error_mask", zeroes);
    83 
    84 
    8583
    8684    // The logic for processing non-ASCII bytes will be embedded within an if-hierarchy.
     
    245243    main.createAssign(u16_lo[7], main.createOr(main.createAnd(last_byte, u8_bits[7]), s43_lo7));
    246244   
    247     Var * output = function->addResult("output", getStreamTy(1, 18));
     245    Var * output = kernel->addOutput("output", kernel->getStreamSetTy(16));
     246    Var * delmask_out = kernel->addOutput("delmask_out", kernel->getStreamSetTy());
     247    Var * error_mask_out = kernel->addOutput("error_mask_out", kernel->getStreamSetTy());
    248248    for (unsigned i = 0; i < 8; i++) {
    249249        main.createAssign(main.createExtract(output, i), u16_hi[i]);
     
    252252        main.createAssign(main.createExtract(output, i + 8), u16_lo[i]);
    253253    }
    254     main.createAssign(main.createExtract(output, 16), delmask);
    255     main.createAssign(main.createExtract(output, 17), error_mask);
    256 
    257     return function;
     254    main.createAssign(main.createExtract(delmask_out, main.getInteger(0)), delmask);
     255    main.createAssign(main.createExtract(error_mask_out,  main.getInteger(0)), error_mask);
     256
     257    pablo_function_passes(kernel);
    258258}
    259 }
    260 
    261 
    262 
    263 using namespace kernel;
    264 using namespace parabix;
    265 
    266 Function * u8u16Pipeline(Module * mMod, IDISA::IDISA_Builder * iBuilder, pablo::PabloFunction * function) {
    267     Type * mBitBlockType = iBuilder->getBitBlockType();
     259
     260Function * u8u16Pipeline(Module * mod, IDISA::IDISA_Builder * iBuilder) {
    268261
    269262    const unsigned segmentSize = codegen::SegmentSize;
    270263    const unsigned bufferSegments = codegen::BufferSegments;
    271264   
    272     ExternalFileBuffer ByteStream(iBuilder, StreamSetType(iBuilder,1, 8));
    273 
    274     CircularBuffer BasisBits(iBuilder, StreamSetType(iBuilder,8, 1), segmentSize * bufferSegments);
    275 
    276     CircularBuffer U8u16Bits(iBuilder, StreamSetType(iBuilder, 18, 1), segmentSize * bufferSegments);
    277 
    278     CircularBuffer U16Bits(iBuilder, StreamSetType(iBuilder,16, 1), segmentSize * bufferSegments);
    279    
    280     CircularBuffer DeletionCounts(iBuilder, StreamSetType(iBuilder, 1, 1), segmentSize * bufferSegments);
     265    assert (iBuilder);
     266
     267    ExternalFileBuffer ByteStream(iBuilder, iBuilder->getStreamSetTy(1, 8));
     268
     269    CircularBuffer BasisBits(iBuilder, iBuilder->getStreamSetTy(8), segmentSize * bufferSegments);
     270
     271    CircularBuffer U8u16Bits(iBuilder, iBuilder->getStreamSetTy(16), segmentSize * bufferSegments);
     272    CircularBuffer DelMask(iBuilder, iBuilder->getStreamSetTy(), segmentSize * bufferSegments);
     273    CircularBuffer ErrorMask(iBuilder, iBuilder->getStreamSetTy(), segmentSize * bufferSegments);
     274
     275    CircularBuffer U16Bits(iBuilder, iBuilder->getStreamSetTy(16), segmentSize * bufferSegments);
     276   
     277    CircularBuffer DeletionCounts(iBuilder, iBuilder->getStreamSetTy(), segmentSize * bufferSegments);
    281278
    282279    // Different choices for the output buffer depending on chosen option.
    283     ExternalFileBuffer U16external(iBuilder, StreamSetType(iBuilder,1, 16));
    284     LinearCopybackBuffer U16out(iBuilder, StreamSetType(iBuilder,1, 16), segmentSize * bufferSegments + 2);
    285 
    286     s2pKernel  s2pk(iBuilder);
     280    ExternalFileBuffer U16external(iBuilder, iBuilder->getStreamSetTy(1, 16));
     281    LinearCopybackBuffer U16out(iBuilder, iBuilder->getStreamSetTy(16, 16), segmentSize * bufferSegments + 2);
     282
     283    s2pKernel s2pk(iBuilder);
     284
    287285    s2pk.generateKernel({&ByteStream}, {&BasisBits});
    288286
    289     pablo_function_passes(function);
    290     pablo::PabloKernel u8u16k(iBuilder, "u8u16", function);
    291     u8u16k.generateKernel({&BasisBits}, {&U8u16Bits});
    292    
     287    pablo::PabloKernel u8u16k(iBuilder, "u8u16");
     288
     289    u8u16_pablo(&u8u16k);
     290
     291    u8u16k.generateKernel({&BasisBits}, {&U8u16Bits, &DelMask, &ErrorMask});
     292
    293293    DeletionKernel delK(iBuilder, iBuilder->getBitBlockWidth()/16, 16);
    294     delK.generateKernel({&U8u16Bits}, {&U16Bits, &DeletionCounts});
    295    
     294    delK.generateKernel({&U8u16Bits, &DelMask}, {&U16Bits, &DeletionCounts});
     295
    296296    p2s_16Kernel_withCompressedOutput p2sk(iBuilder);
    297    
     297
    298298    stdOutKernel stdoutK(iBuilder, 16);
    299    
     299
    300300    if (mMapBuffering || memAlignBuffering) {
    301301        p2sk.generateKernel({&U16Bits, &DeletionCounts}, {&U16external});
    302302        stdoutK.generateKernel({&U16external}, {});
    303     }
    304     else {
     303    } else {
    305304        p2sk.generateKernel({&U16Bits, &DeletionCounts}, {&U16out});
    306305        stdoutK.generateKernel({&U16out}, {});
    307306    }
    308    
     307
    309308    Type * const size_ty = iBuilder->getSizeTy();
    310     Type * const voidTy = Type::getVoidTy(mMod->getContext());
    311     Type * const inputType = PointerType::get(ArrayType::get(ArrayType::get(mBitBlockType, 8), 1), 0);
    312     Type * const outputType = PointerType::get(ArrayType::get(ArrayType::get(mBitBlockType, 16), 1), 0);
     309    Type * const voidTy = Type::getVoidTy(mod->getContext());
     310    Type * const bitBlockType = iBuilder->getBitBlockType();
     311    Type * const inputType = ArrayType::get(ArrayType::get(bitBlockType, 8), 1)->getPointerTo();
     312    Type * const outputType = ArrayType::get(ArrayType::get(bitBlockType, 16), 1)->getPointerTo();
    313313    Type * const int32ty = iBuilder->getInt32Ty();
    314314    Type * const int8PtrTy = iBuilder->getInt8PtrTy();
    315     Type * const voidPtrTy = TypeBuilder<void *, false>::get(mMod->getContext());
    316 
    317    
    318     Function * const main = cast<Function>(mMod->getOrInsertFunction("Main", voidTy, inputType, outputType, size_ty, nullptr));
     315    Type * const voidPtrTy = Type::getVoidTy(mod->getContext())->getPointerTo();
     316
     317    Function * const main = cast<Function>(mod->getOrInsertFunction("Main", voidTy, inputType, outputType, size_ty, nullptr));
    319318    main->setCallingConv(CallingConv::C);
    320319    Function::arg_iterator args = main->arg_begin();
    321    
     320
    322321    Value * const inputStream = &*(args++);
    323322    inputStream->setName("inputStream");
     
    326325    Value * const fileSize = &*(args++);
    327326    fileSize->setName("fileSize");
    328    
    329     iBuilder->SetInsertPoint(BasicBlock::Create(mMod->getContext(), "entry", main,0));
    330        
     327
     328    iBuilder->SetInsertPoint(BasicBlock::Create(mod->getContext(), "entry", main,0));
    331329
    332330    ByteStream.setStreamSetBuffer(inputStream, fileSize);
    333331    BasisBits.allocateBuffer();
    334332    U8u16Bits.allocateBuffer();
     333    DelMask.allocateBuffer();
     334    ErrorMask.allocateBuffer();
    335335    U16Bits.allocateBuffer();
    336336    DeletionCounts.allocateBuffer();
    337337    if (mMapBuffering || memAlignBuffering) {
    338338        U16external.setEmptyBuffer(outputStream);
    339     }
    340     else {
     339    } else {
    341340        U16out.allocateBuffer();
    342341    }
     
    346345    Value * p2sInstance = p2sk.createInstance({});
    347346    Value * stdoutInstance = stdoutK.createInstance({});
    348    
     347
    349348    Type * pthreadTy = size_ty;
    350349    FunctionType * funVoidPtrVoidTy = FunctionType::get(voidTy, int8PtrTy, false);
    351    
    352     Function * pthreadCreateFunc = cast<Function>(mMod->getOrInsertFunction("pthread_create",
     350
     351    Function * pthreadCreateFunc = cast<Function>(mod->getOrInsertFunction("pthread_create",
    353352                                                                         int32ty,
    354353                                                                         pthreadTy->getPointerTo(),
     
    357356                                                                         voidPtrTy, nullptr));
    358357    pthreadCreateFunc->setCallingConv(llvm::CallingConv::C);
    359     Function * pthreadJoinFunc = cast<Function>(mMod->getOrInsertFunction("pthread_join",
     358    Function * pthreadJoinFunc = cast<Function>(mod->getOrInsertFunction("pthread_join",
    360359                                                                       int32ty,
    361360                                                                       pthreadTy,
    362361                                                                       PointerType::get(int8PtrTy, 0), nullptr));
    363362    pthreadJoinFunc->setCallingConv(llvm::CallingConv::C);
    364    
    365     Function * pthreadExitFunc = cast<Function>(mMod->getOrInsertFunction("pthread_exit",
    366                                                                        voidTy, 
     363
     364    Function * pthreadExitFunc = cast<Function>(mod->getOrInsertFunction("pthread_exit",
     365                                                                       voidTy,
    367366                                                                       voidPtrTy, nullptr));
    368367    pthreadExitFunc->addFnAttr(llvm::Attribute::NoReturn);
     
    371370    if (segmentPipelineParallel){
    372371        generateSegmentParallelPipeline(iBuilder, {&s2pk, &u8u16k, &delK, &p2sk, &stdoutK}, {s2pInstance, u8u16Instance, delInstance, p2sInstance, stdoutInstance}, fileSize);
    373     }
    374     else{
     372    } else {
    375373        generatePipelineLoop(iBuilder, {&s2pk, &u8u16k, &delK, &p2sk, &stdoutK}, {s2pInstance, u8u16Instance, delInstance, p2sInstance, stdoutInstance}, fileSize);
    376374    }
     
    393391    IDISA::IDISA_Builder * idb = IDISA::GetIDISA_Builder(M);
    394392
    395     pablo::PabloFunction * function = pablo::u8u16_pablo();
    396    
    397     llvm::Function * main_IR = u8u16Pipeline(M, idb, function);
     393    llvm::Function * main_IR = u8u16Pipeline(M, idb);
    398394   
    399395    verifyModule(*M, &dbgs());
Note: See TracChangeset for help on using the changeset viewer.