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

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

File:
1 edited

Legend:

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