Changeset 5414


Ignore:
Timestamp:
Apr 19, 2017, 10:57:56 AM (22 months ago)
Author:
cameron
Message:

Parabix driver can take ownership of kernelbuilder instances; uniquify mmap kernel name

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

Legend:

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

    r5398 r5414  
    4444
    4545MMapSourceKernel::MMapSourceKernel(IDISA::IDISA_Builder * iBuilder, unsigned blocksPerSegment, unsigned codeUnitWidth)
    46 : SegmentOrientedKernel(iBuilder, "Parabix:mmap_source",
     46    : SegmentOrientedKernel(iBuilder, "Parabix:mmap_source" + std::to_string(blocksPerSegment) + "@" + std::to_string(codeUnitWidth),
    4747    {},
    4848    {Binding{iBuilder->getStreamSetTy(1, codeUnitWidth), "sourceBuffer"}},
  • icGREP/icgrep-devel/icgrep/kernels/toolchain.cpp

    r5411 r5414  
    224224}
    225225
     226kernel::KernelBuilder * ParabixDriver::addKernelInstance(std::unique_ptr<kernel::KernelBuilder> kb) {
     227    mOwnedKernels.push_back(std::move(kb));
     228    return mOwnedKernels.back().get();
     229}
     230
    226231
    227232void ParabixDriver::addKernelCall(kernel::KernelBuilder & kb, const std::vector<parabix::StreamSetBuffer *> & inputs, const std::vector<parabix::StreamSetBuffer *> & outputs) {
    228233    assert (mModuleMap.count(&kb) == 0);
    229     mKernelList.push_back(&kb);
     234    mPipeline.push_back(&kb);
    230235    mModuleMap.emplace(&kb, kb.createKernelStub(inputs, outputs));
     236}
     237
     238void ParabixDriver::makeKernelCall(kernel::KernelBuilder * kb, const std::vector<parabix::StreamSetBuffer *> & inputs, const std::vector<parabix::StreamSetBuffer *> & outputs) {
     239    assert (mModuleMap.count(kb) == 0);
     240    mPipeline.push_back(kb);
     241    mModuleMap.emplace(kb, kb->createKernelStub(inputs, outputs));
    231242}
    232243
    233244void ParabixDriver::generatePipelineIR() {
    234245    #ifndef NDEBUG
    235     if (LLVM_UNLIKELY(mKernelList.empty())) {
     246    if (LLVM_UNLIKELY(mPipeline.empty())) {
    236247        report_fatal_error("Pipeline must contain at least one kernel");
    237248    } else {
    238         boost::container::flat_set<kernel::KernelBuilder *> K(mKernelList.begin(), mKernelList.end());
    239         if (LLVM_UNLIKELY(K.size() != mKernelList.size())) {
     249        boost::container::flat_set<kernel::KernelBuilder *> K(mPipeline.begin(), mPipeline.end());
     250        if (LLVM_UNLIKELY(K.size() != mPipeline.size())) {
    240251            report_fatal_error("Kernel definitions can only occur once in the pipeline");
    241252        }
     
    243254    #endif
    244255    // note: instantiation of all kernels must occur prior to initialization
    245     for (const auto & k : mKernelList) {
     256    for (const auto & k : mPipeline) {
    246257        k->addKernelDeclarations(mMainModule);
    247258    }
    248     for (const auto & k : mKernelList) {
     259    for (const auto & k : mPipeline) {
    249260        k->createInstance();
    250261    }
    251     for (const auto & k : mKernelList) {
     262    for (const auto & k : mPipeline) {
    252263        k->initializeInstance();
    253264    }
    254265    if (codegen::pipelineParallel) {
    255         generateParallelPipeline(iBuilder, mKernelList);
     266        generateParallelPipeline(iBuilder, mPipeline);
    256267    } else if (codegen::segmentPipelineParallel) {
    257         generateSegmentParallelPipeline(iBuilder, mKernelList);
     268        generateSegmentParallelPipeline(iBuilder, mPipeline);
    258269    } else {
    259270        codegen::ThreadNum = 1;
    260         generatePipelineLoop(iBuilder, mKernelList);
    261     }
    262     for (const auto & k : mKernelList) {
     271        generatePipelineLoop(iBuilder, mPipeline);
     272    }
     273    for (const auto & k : mPipeline) {
    263274        k->terminateInstance();
    264275    }
  • icGREP/icgrep-devel/icgrep/kernels/toolchain.h

    r5409 r5414  
    7272    parabix::StreamSetBuffer * addBuffer(std::unique_ptr<parabix::StreamSetBuffer> b);
    7373   
     74    kernel::KernelBuilder * addKernelInstance(std::unique_ptr<kernel::KernelBuilder> kb);
     75   
    7476    void addKernelCall(kernel::KernelBuilder & kb, const std::vector<parabix::StreamSetBuffer *> & inputs, const std::vector<parabix::StreamSetBuffer *> & outputs);
     77    void makeKernelCall(kernel::KernelBuilder * kb, const std::vector<parabix::StreamSetBuffer *> & inputs, const std::vector<parabix::StreamSetBuffer *> & outputs);
    7578   
    7679    void generatePipelineIR();
     
    9194    llvm::ExecutionEngine *                 mEngine;
    9295    ParabixObjectCache *                    mCache;
    93     std::vector<kernel::KernelBuilder *>    mKernelList;
     96    std::vector<kernel::KernelBuilder *>    mPipeline;
    9497    // Owned kernels and buffers that will persist with this ParabixDriver instance.
    9598    std::vector<std::unique_ptr<kernel::KernelBuilder>> mOwnedKernels;
  • icGREP/icgrep-devel/icgrep/u8u16.cpp

    r5409 r5414  
    5151
    5252
    53 void u8u16_pablo(PabloKernel * kernel) {
     53std::unique_ptr<PabloKernel> u8u16_pablo(IDISA::IDISA_Builder * iBuilder) {
     54
     55    auto kernel = std::unique_ptr<PabloKernel>(new PabloKernel(iBuilder, "u8u16",
     56                       {Binding{iBuilder->getStreamSetTy(8, 1), "u8bit"}},
     57                       {Binding{iBuilder->getStreamSetTy(16, 1), "u16bit"},
     58                           Binding{iBuilder->getStreamSetTy(1, 1), "delMask"},
     59                           Binding{iBuilder->getStreamSetTy(1, 1), "errMask"}}, {}));
     60   
    5461    //  input: 8 basis bit streams
    5562   
     
    5865    //  output: 16 u8-indexed streams, + delmask stream + error stream
    5966   
    60     cc::CC_Compiler ccc(kernel, u8bitSet);
     67    cc::CC_Compiler ccc(kernel.get(), u8bitSet);
    6168   
    6269    PabloBuilder & main = ccc.getBuilder();
     
    251258    main.createAssign(main.createExtract(error_mask_out,  main.getInteger(0)), error_mask);
    252259
    253     pablo_function_passes(kernel);
     260    pablo_function_passes(kernel.get());
     261    return kernel;
    254262}
    255263
     
    285293    StreamSetBuffer * ByteStream = pxDriver.addExternalBuffer(make_unique<ExternalFileBuffer>(iBuilder, iBuilder->getStreamSetTy(1, 8)), inputStream);
    286294   
    287     MMapSourceKernel mmapK(iBuilder, segmentSize);
    288     mmapK.setInitialArguments({fileSize});
    289     pxDriver.addKernelCall(mmapK, {}, {ByteStream});
     295    KernelBuilder * mmapK = pxDriver.addKernelInstance(make_unique<MMapSourceKernel>(iBuilder, segmentSize));
     296    mmapK->setInitialArguments({fileSize});
     297    pxDriver.makeKernelCall(mmapK, {}, {ByteStream});
    290298   
    291299    // Transposed bits from s2p
    292300    StreamSetBuffer * BasisBits = pxDriver.addBuffer(make_unique<CircularBuffer>(iBuilder, iBuilder->getStreamSetTy(8, 1), segmentSize * bufferSegments));
    293301   
    294     S2PKernel s2pk(iBuilder);
    295     pxDriver.addKernelCall(s2pk, {ByteStream}, {BasisBits});
     302    KernelBuilder * s2pk = pxDriver.addKernelInstance(make_unique<S2PKernel>(iBuilder));
     303    pxDriver.makeKernelCall(s2pk, {ByteStream}, {BasisBits});
    296304   
    297305    // Calculate UTF-16 data bits through bitwise logic on u8-indexed streams.
     
    300308    StreamSetBuffer * ErrorMask = pxDriver.addBuffer(make_unique<CircularBuffer>(iBuilder, iBuilder->getStreamSetTy(), segmentSize * bufferSegments));
    301309   
    302     PabloKernel u8u16k(iBuilder, "u8u16",
    303                        {Binding{iBuilder->getStreamSetTy(8, 1), "u8bit"}},
    304                        {Binding{iBuilder->getStreamSetTy(16, 1), "u16bit"},
    305                            Binding{iBuilder->getStreamSetTy(1, 1), "delMask"},
    306                            Binding{iBuilder->getStreamSetTy(1, 1), "errMask"}}, {});
    307    
    308     u8u16_pablo(&u8u16k);
    309     pxDriver.addKernelCall(u8u16k, {BasisBits}, {U8u16Bits, DelMask, ErrorMask});
     310    KernelBuilder * u8u16k = pxDriver.addKernelInstance(u8u16_pablo(iBuilder));
     311    pxDriver.makeKernelCall(u8u16k, {BasisBits}, {U8u16Bits, DelMask, ErrorMask});
    310312   
    311313    // Apply a deletion algorithm to discard all but the final position of the UTF-8
     
    317319    StreamSetBuffer * DeletionCounts = pxDriver.addBuffer(make_unique<CircularBuffer>(iBuilder, iBuilder->getStreamSetTy(), segmentSize * bufferSegments));
    318320   
    319     DeleteByPEXTkernel delK(iBuilder, 64, 16, true);
    320     pxDriver.addKernelCall(delK, {U8u16Bits, DelMask}, {SwizzleFields0, SwizzleFields1, SwizzleFields2, SwizzleFields3, DeletionCounts});
     321    KernelBuilder * delK = pxDriver.addKernelInstance(make_unique<DeleteByPEXTkernel>(iBuilder, 64, 16, true));
     322    pxDriver.makeKernelCall(delK, {U8u16Bits, DelMask}, {SwizzleFields0, SwizzleFields1, SwizzleFields2, SwizzleFields3, DeletionCounts});
    321323   
    322324    //  Produce fully compressed swizzled UTF-16 bit streams
     
    326328    StreamSetBuffer * u16Swizzle3 = pxDriver.addBuffer(make_unique<SwizzledCopybackBuffer>(iBuilder, iBuilder->getStreamSetTy(4), segmentSize * (bufferSegments+2), 1));
    327329   
    328     SwizzledBitstreamCompressByCount compressK(iBuilder, 16);
    329     pxDriver.addKernelCall(compressK, {DeletionCounts, SwizzleFields0, SwizzleFields1, SwizzleFields2, SwizzleFields3},
     330    KernelBuilder * compressK = pxDriver.addKernelInstance(make_unique<SwizzledBitstreamCompressByCount>(iBuilder, 16));
     331    pxDriver.makeKernelCall(compressK, {DeletionCounts, SwizzleFields0, SwizzleFields1, SwizzleFields2, SwizzleFields3},
    330332                           {u16Swizzle0, u16Swizzle1, u16Swizzle2, u16Swizzle3});
    331333   
    332334    // Produce unswizzled UTF-16 bit streams
    333335    StreamSetBuffer * u16bits = pxDriver.addBuffer(make_unique<CircularBuffer>(iBuilder, iBuilder->getStreamSetTy(16), segmentSize * bufferSegments));
    334     SwizzleGenerator unSwizzleK(iBuilder, 16, 1, 4);
    335     unSwizzleK.setName("unswizzle");
    336     pxDriver.addKernelCall(unSwizzleK, {u16Swizzle0, u16Swizzle1, u16Swizzle2, u16Swizzle3}, {u16bits});
    337    
    338    
    339     P2S16Kernel p2sk(iBuilder);
    340    
    341     FileSink outK(iBuilder, 16);
     336   
     337    KernelBuilder * unSwizzleK = pxDriver.addKernelInstance(make_unique<SwizzleGenerator>(iBuilder, 16, 1, 4));
     338    pxDriver.makeKernelCall(unSwizzleK, {u16Swizzle0, u16Swizzle1, u16Swizzle2, u16Swizzle3}, {u16bits});
     339   
     340    KernelBuilder * p2sk = pxDriver.addKernelInstance(make_unique<P2S16Kernel>(iBuilder));
     341   
     342    KernelBuilder * outK = pxDriver.addKernelInstance(make_unique<FileSink>(iBuilder, 16));
    342343    Value * fName = iBuilder->CreatePointerCast(iBuilder->CreateGlobalString(outputFile.c_str()), iBuilder->getInt8PtrTy());
    343     outK.setInitialArguments({fName});
    344    
     344    outK->setInitialArguments({fName});
     345       
    345346    // Different choices for the output buffer depending on chosen option.
    346347    StreamSetBuffer * U16out = nullptr;
     
    350351        U16out = pxDriver.addBuffer(make_unique<CircularBuffer>(iBuilder, iBuilder->getStreamSetTy(1, 16), segmentSize * bufferSegments));
    351352    }
    352     pxDriver.addKernelCall(p2sk, {u16bits}, {U16out});
    353     pxDriver.addKernelCall(outK, {U16out}, {});
     353    pxDriver.makeKernelCall(p2sk, {u16bits}, {U16out});
     354    pxDriver.makeKernelCall(outK, {U16out}, {});
    354355   
    355356    pxDriver.generatePipelineIR();
     
    392393    StreamSetBuffer * ByteStream = pxDriver.addExternalBuffer(make_unique<ExternalFileBuffer>(iBuilder, iBuilder->getStreamSetTy(1, 8)), inputStream);
    393394   
    394     MMapSourceKernel mmapK(iBuilder, segmentSize);
    395     mmapK.setInitialArguments({fileSize});
    396     pxDriver.addKernelCall(mmapK, {}, {ByteStream});
     395    KernelBuilder * mmapK = pxDriver.addKernelInstance(make_unique<MMapSourceKernel>(iBuilder, segmentSize));
     396    mmapK->setInitialArguments({fileSize});
     397    pxDriver.makeKernelCall(mmapK, {}, {ByteStream});
    397398   
    398399    // Transposed bits from s2p
    399400    StreamSetBuffer * BasisBits = pxDriver.addBuffer(make_unique<CircularBuffer>(iBuilder, iBuilder->getStreamSetTy(8, 1), segmentSize * bufferSegments));
    400401   
    401     S2PKernel s2pk(iBuilder);
    402     pxDriver.addKernelCall(s2pk, {ByteStream}, {BasisBits});
    403 
     402    KernelBuilder * s2pk = pxDriver.addKernelInstance(make_unique<S2PKernel>(iBuilder));
     403    pxDriver.makeKernelCall(s2pk, {ByteStream}, {BasisBits});
     404   
    404405    // Calculate UTF-16 data bits through bitwise logic on u8-indexed streams.
    405406    StreamSetBuffer * U8u16Bits = pxDriver.addBuffer(make_unique<CircularBuffer>(iBuilder, iBuilder->getStreamSetTy(16), segmentSize * bufferSegments));
     
    407408    StreamSetBuffer * ErrorMask = pxDriver.addBuffer(make_unique<CircularBuffer>(iBuilder, iBuilder->getStreamSetTy(), segmentSize * bufferSegments));
    408409   
    409     PabloKernel u8u16k(iBuilder, "u8u16",
    410                        {Binding{iBuilder->getStreamSetTy(8, 1), "u8bit"}},
    411                        {Binding{iBuilder->getStreamSetTy(16, 1), "u16bit"},
    412                            Binding{iBuilder->getStreamSetTy(1, 1), "delMask"},
    413                            Binding{iBuilder->getStreamSetTy(1, 1), "errMask"}}, {});
    414    
    415     u8u16_pablo(&u8u16k);
    416     pxDriver.addKernelCall(u8u16k, {BasisBits}, {U8u16Bits, DelMask, ErrorMask});
     410    KernelBuilder * u8u16k = pxDriver.addKernelInstance(u8u16_pablo(iBuilder));
     411    pxDriver.makeKernelCall(u8u16k, {BasisBits}, {U8u16Bits, DelMask, ErrorMask});
    417412   
    418413    StreamSetBuffer * U16Bits = pxDriver.addBuffer(make_unique<CircularBuffer>(iBuilder, iBuilder->getStreamSetTy(16), segmentSize * bufferSegments));
     
    420415    StreamSetBuffer * DeletionCounts = pxDriver.addBuffer(make_unique<CircularBuffer>(iBuilder, iBuilder->getStreamSetTy(), segmentSize * bufferSegments));
    421416
    422     DeletionKernel delK(iBuilder, iBuilder->getBitBlockWidth()/16, 16);
    423     pxDriver.addKernelCall(delK, {U8u16Bits, DelMask}, {U16Bits, DeletionCounts});
    424    
    425     P2S16KernelWithCompressedOutput p2sk(iBuilder);
    426    
    427     FileSink outK(iBuilder, 16);
     417    KernelBuilder * delK = pxDriver.addKernelInstance(make_unique<DeletionKernel>(iBuilder, iBuilder->getBitBlockWidth()/16, 16));
     418    pxDriver.makeKernelCall(delK, {U8u16Bits, DelMask}, {U16Bits, DeletionCounts});
     419   
     420    KernelBuilder * p2sk = pxDriver.addKernelInstance(make_unique<P2S16KernelWithCompressedOutput>(iBuilder));
     421   
     422    KernelBuilder * outK = pxDriver.addKernelInstance(make_unique<FileSink>(iBuilder, 16));
    428423    Value * fName = iBuilder->CreatePointerCast(iBuilder->CreateGlobalString(outputFile.c_str()), iBuilder->getInt8PtrTy());
    429     outK.setInitialArguments({fName});
     424    outK->setInitialArguments({fName});
    430425   
    431426    // Different choices for the output buffer depending on chosen option.
     
    436431        U16out = pxDriver.addBuffer(make_unique<CircularCopybackBuffer>(iBuilder, iBuilder->getStreamSetTy(1, 16), segmentSize * bufferSegments, 1 /*overflow block*/));
    437432    }
    438     pxDriver.addKernelCall(p2sk, {U16Bits, DeletionCounts}, {U16out});
    439     pxDriver.addKernelCall(outK, {U16out}, {});
     433    pxDriver.makeKernelCall(p2sk, {U16Bits, DeletionCounts}, {U16out});
     434    pxDriver.makeKernelCall(outK, {U16out}, {});
    440435   
    441436    pxDriver.generatePipelineIR();
  • icGREP/icgrep-devel/icgrep/wc.cpp

    r5411 r5414  
    8888//
    8989
    90 void wc_gen(PabloKernel * kernel) {
     90std::unique_ptr<PabloKernel> wc_gen(IDISA::IDISA_Builder * iBuilder) {
     91   
     92    auto kernel = std::unique_ptr<PabloKernel>(new PabloKernel(iBuilder, "Parabix:wc",
     93                    {Binding{iBuilder->getStreamSetTy(8, 1), "u8bit"}},
     94                    {},
     95                    {},
     96                    {Binding{iBuilder->getSizeTy(), "lineCount"}, Binding{iBuilder->getSizeTy(), "wordCount"}, Binding{iBuilder->getSizeTy(), "charCount"}}));
     97   
    9198    //  input: 8 basis bit streams
    9299    const auto u8bitSet = kernel->getInputStreamVar("u8bit");
    93100    //  output: 3 counters
    94101   
    95     cc::CC_Compiler ccc(kernel, u8bitSet);
     102    cc::CC_Compiler ccc(kernel.get(), u8bitSet);
    96103   
    97104    PabloBuilder & pb = ccc.getBuilder();
     
    121128        pb.createAssign(cc, pb.createCount(u8Begin));
    122129    }
     130    pablo_function_passes(kernel.get());
     131    return kernel;
    123132}
    124133
     
    156165    StreamSetBuffer * BasisBits = pxDriver.addBuffer(make_unique<SingleBlockBuffer>(iBuilder, iBuilder->getStreamSetTy(8, 1)));
    157166
    158     MMapSourceKernel mmapK(iBuilder);
    159     mmapK.setInitialArguments({fileSize});
    160     pxDriver.addKernelCall(mmapK, {}, {ByteStream});
    161 
    162     S2PKernel  s2pk(iBuilder);
    163     pxDriver.addKernelCall(s2pk, {ByteStream}, {BasisBits});
    164    
    165     PabloKernel wck(iBuilder, "Parabix:wc",
    166         {Binding{iBuilder->getStreamSetTy(8, 1), "u8bit"}},
    167         {},
    168         {},
    169         {Binding{iBuilder->getSizeTy(), "lineCount"}, Binding{iBuilder->getSizeTy(), "wordCount"}, Binding{iBuilder->getSizeTy(), "charCount"}});
    170 
    171     wc_gen(&wck);
    172     pablo_function_passes(&wck);
    173     pxDriver.addKernelCall(wck, {BasisBits}, {});
     167    KernelBuilder * mmapK = pxDriver.addKernelInstance(make_unique<MMapSourceKernel>(iBuilder));
     168    mmapK->setInitialArguments({fileSize});
     169    pxDriver.makeKernelCall(mmapK, {}, {ByteStream});
     170
     171    KernelBuilder * s2pk = pxDriver.addKernelInstance(make_unique<S2PKernel>(iBuilder));
     172    pxDriver.makeKernelCall(s2pk, {ByteStream}, {BasisBits});
     173   
     174    KernelBuilder * wck = pxDriver.addKernelInstance(wc_gen(iBuilder));
     175    pxDriver.makeKernelCall(wck, {BasisBits}, {});
    174176
    175177
    176178    pxDriver.generatePipelineIR();
    177179   
    178     Value * lineCount = wck.createGetAccumulatorCall("lineCount");
    179     Value * wordCount = wck.createGetAccumulatorCall("wordCount");
    180     Value * charCount = wck.createGetAccumulatorCall("charCount");
     180    Value * lineCount = wck->createGetAccumulatorCall("lineCount");
     181    Value * wordCount = wck->createGetAccumulatorCall("wordCount");
     182    Value * charCount = wck->createGetAccumulatorCall("charCount");
    181183
    182184    iBuilder->CreateCall(record_counts_routine, std::vector<Value *>({lineCount, wordCount, charCount, fileSize, fileIdx}));
Note: See TracChangeset for help on using the changeset viewer.