Changeset 5409 for icGREP


Ignore:
Timestamp:
Apr 16, 2017, 9:44:17 AM (2 years ago)
Author:
cameron
Message:

Parabix driver can take ownership and allocate buffers

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

Legend:

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

    r5408 r5409  
    3535
    3636using namespace llvm;
     37using namespace parabix;
    3738
    3839namespace codegen {
     
    210211    }
    211212}
     213
     214ExternalFileBuffer * ParabixDriver::addExternalBuffer(std::unique_ptr<ExternalFileBuffer> b, Value * externalBuf) {
     215    ExternalFileBuffer * rawBuf = b.get();
     216    mOwnedBuffers.push_back(std::move(b));
     217    rawBuf->setStreamSetBuffer(externalBuf);
     218    return rawBuf;
     219}
     220
     221StreamSetBuffer * ParabixDriver::addBuffer(std::unique_ptr<StreamSetBuffer> b) {
     222    b->allocateBuffer();
     223    mOwnedBuffers.push_back(std::move(b));
     224    return mOwnedBuffers.back().get();
     225}
     226
    212227
    213228void ParabixDriver::addKernelCall(kernel::KernelBuilder & kb, const std::vector<parabix::StreamSetBuffer *> & inputs, const std::vector<parabix::StreamSetBuffer *> & outputs) {
  • icGREP/icgrep-devel/icgrep/kernels/toolchain.h

    r5402 r5409  
    1919namespace IDISA { class IDISA_Builder; }
    2020namespace kernel { class KernelBuilder; }
    21 namespace parabix { class StreamSetBuffer; }
     21//namespace parabix { class StreamSetBuffer; }
     22#include <kernels/streamset.h>
    2223class ParabixObjectCache;
    2324
     
    6768    IDISA::IDISA_Builder * getIDISA_Builder() {return iBuilder;}
    6869   
     70    parabix::ExternalFileBuffer * addExternalBuffer(std::unique_ptr<parabix::ExternalFileBuffer> b, llvm::Value * externalBuf);
     71   
     72    parabix::StreamSetBuffer * addBuffer(std::unique_ptr<parabix::StreamSetBuffer> b);
     73   
    6974    void addKernelCall(kernel::KernelBuilder & kb, const std::vector<parabix::StreamSetBuffer *> & inputs, const std::vector<parabix::StreamSetBuffer *> & outputs);
    7075   
     
    8792    ParabixObjectCache *                    mCache;
    8893    std::vector<kernel::KernelBuilder *>    mKernelList;
     94    // Owned kernels and buffers that will persist with this ParabixDriver instance.
     95    std::vector<std::unique_ptr<kernel::KernelBuilder>> mOwnedKernels;
     96    std::vector<std::unique_ptr<parabix::StreamSetBuffer>> mOwnedBuffers;
    8997    ModuleMap                               mModuleMap;
    9098};
  • icGREP/icgrep-devel/icgrep/u8u16.cpp

    r5402 r5409  
    280280    fileSize->setName("fileSize");
    281281
     282    iBuilder->SetInsertPoint(BasicBlock::Create(mod->getContext(), "entry", main,0));
     283   
    282284    // File data from mmap
    283     ExternalFileBuffer ByteStream(iBuilder, iBuilder->getStreamSetTy(1, 8));
    284 
    285     MMapSourceKernel mmapK(iBuilder, segmentSize); 
     285    StreamSetBuffer * ByteStream = pxDriver.addExternalBuffer(make_unique<ExternalFileBuffer>(iBuilder, iBuilder->getStreamSetTy(1, 8)), inputStream);
     286   
     287    MMapSourceKernel mmapK(iBuilder, segmentSize);
    286288    mmapK.setInitialArguments({fileSize});
    287     pxDriver.addKernelCall(mmapK, {}, {&ByteStream});
    288 
     289    pxDriver.addKernelCall(mmapK, {}, {ByteStream});
     290   
    289291    // Transposed bits from s2p
    290     CircularBuffer BasisBits(iBuilder, iBuilder->getStreamSetTy(8), segmentSize * bufferSegments);
    291 
     292    StreamSetBuffer * BasisBits = pxDriver.addBuffer(make_unique<CircularBuffer>(iBuilder, iBuilder->getStreamSetTy(8, 1), segmentSize * bufferSegments));
     293   
    292294    S2PKernel s2pk(iBuilder);
    293     pxDriver.addKernelCall(s2pk, {&ByteStream}, {&BasisBits});
     295    pxDriver.addKernelCall(s2pk, {ByteStream}, {BasisBits});
    294296   
    295297    // Calculate UTF-16 data bits through bitwise logic on u8-indexed streams.
    296     CircularBuffer U8u16Bits(iBuilder, iBuilder->getStreamSetTy(16), segmentSize * bufferSegments);
    297     CircularBuffer DelMask(iBuilder, iBuilder->getStreamSetTy(), segmentSize * bufferSegments);
    298     CircularBuffer ErrorMask(iBuilder, iBuilder->getStreamSetTy(), segmentSize * bufferSegments);
    299 
     298    StreamSetBuffer * U8u16Bits = pxDriver.addBuffer(make_unique<CircularBuffer>(iBuilder, iBuilder->getStreamSetTy(16), segmentSize * bufferSegments));
     299    StreamSetBuffer * DelMask = pxDriver.addBuffer(make_unique<CircularBuffer>(iBuilder, iBuilder->getStreamSetTy(), segmentSize * bufferSegments));
     300    StreamSetBuffer * ErrorMask = pxDriver.addBuffer(make_unique<CircularBuffer>(iBuilder, iBuilder->getStreamSetTy(), segmentSize * bufferSegments));
     301   
    300302    PabloKernel u8u16k(iBuilder, "u8u16",
    301303                       {Binding{iBuilder->getStreamSetTy(8, 1), "u8bit"}},
     
    305307   
    306308    u8u16_pablo(&u8u16k);
    307     pxDriver.addKernelCall(u8u16k, {&BasisBits}, {&U8u16Bits, &DelMask, &ErrorMask});
    308 
     309    pxDriver.addKernelCall(u8u16k, {BasisBits}, {U8u16Bits, DelMask, ErrorMask});
     310   
    309311    // Apply a deletion algorithm to discard all but the final position of the UTF-8
    310312    // sequences for each UTF-16 code unit. Swizzle the results.
    311     CircularBuffer SwizzleFields0(iBuilder, iBuilder->getStreamSetTy(4), segmentSize * bufferSegments);
    312     CircularBuffer SwizzleFields1(iBuilder, iBuilder->getStreamSetTy(4), segmentSize * bufferSegments);
    313     CircularBuffer SwizzleFields2(iBuilder, iBuilder->getStreamSetTy(4), segmentSize * bufferSegments);
    314     CircularBuffer SwizzleFields3(iBuilder, iBuilder->getStreamSetTy(4), segmentSize * bufferSegments);
    315     CircularBuffer DeletionCounts(iBuilder, iBuilder->getStreamSetTy(), segmentSize * bufferSegments);
    316 
     313    StreamSetBuffer * SwizzleFields0 = pxDriver.addBuffer(make_unique<CircularBuffer>(iBuilder, iBuilder->getStreamSetTy(4), segmentSize * bufferSegments));
     314    StreamSetBuffer * SwizzleFields1 = pxDriver.addBuffer(make_unique<CircularBuffer>(iBuilder, iBuilder->getStreamSetTy(4), segmentSize * bufferSegments));
     315    StreamSetBuffer * SwizzleFields2 = pxDriver.addBuffer(make_unique<CircularBuffer>(iBuilder, iBuilder->getStreamSetTy(4), segmentSize * bufferSegments));
     316    StreamSetBuffer * SwizzleFields3 = pxDriver.addBuffer(make_unique<CircularBuffer>(iBuilder, iBuilder->getStreamSetTy(4), segmentSize * bufferSegments));
     317    StreamSetBuffer * DeletionCounts = pxDriver.addBuffer(make_unique<CircularBuffer>(iBuilder, iBuilder->getStreamSetTy(), segmentSize * bufferSegments));
     318   
    317319    DeleteByPEXTkernel delK(iBuilder, 64, 16, true);
    318     pxDriver.addKernelCall(delK, {&U8u16Bits, &DelMask}, {&SwizzleFields0, &SwizzleFields1, &SwizzleFields2, &SwizzleFields3, &DeletionCounts});
    319 
     320    pxDriver.addKernelCall(delK, {U8u16Bits, DelMask}, {SwizzleFields0, SwizzleFields1, SwizzleFields2, SwizzleFields3, DeletionCounts});
     321   
    320322    //  Produce fully compressed swizzled UTF-16 bit streams
    321     SwizzledCopybackBuffer u16Swizzle0(iBuilder, iBuilder->getStreamSetTy(4), segmentSize * (bufferSegments+2), 1);
    322     SwizzledCopybackBuffer u16Swizzle1(iBuilder, iBuilder->getStreamSetTy(4), segmentSize * (bufferSegments+2), 1);
    323     SwizzledCopybackBuffer u16Swizzle2(iBuilder, iBuilder->getStreamSetTy(4), segmentSize * (bufferSegments+2), 1);
    324     SwizzledCopybackBuffer u16Swizzle3(iBuilder, iBuilder->getStreamSetTy(4), segmentSize * (bufferSegments+2), 1);
    325 
     323    StreamSetBuffer * u16Swizzle0 = pxDriver.addBuffer(make_unique<SwizzledCopybackBuffer>(iBuilder, iBuilder->getStreamSetTy(4), segmentSize * (bufferSegments+2), 1));
     324    StreamSetBuffer * u16Swizzle1 = pxDriver.addBuffer(make_unique<SwizzledCopybackBuffer>(iBuilder, iBuilder->getStreamSetTy(4), segmentSize * (bufferSegments+2), 1));
     325    StreamSetBuffer * u16Swizzle2 = pxDriver.addBuffer(make_unique<SwizzledCopybackBuffer>(iBuilder, iBuilder->getStreamSetTy(4), segmentSize * (bufferSegments+2), 1));
     326    StreamSetBuffer * u16Swizzle3 = pxDriver.addBuffer(make_unique<SwizzledCopybackBuffer>(iBuilder, iBuilder->getStreamSetTy(4), segmentSize * (bufferSegments+2), 1));
     327   
    326328    SwizzledBitstreamCompressByCount compressK(iBuilder, 16);
    327     pxDriver.addKernelCall(compressK, {&DeletionCounts, &SwizzleFields0, &SwizzleFields1, &SwizzleFields2, &SwizzleFields3},
    328                              {&u16Swizzle0, &u16Swizzle1, &u16Swizzle2, &u16Swizzle3});
    329  
     329    pxDriver.addKernelCall(compressK, {DeletionCounts, SwizzleFields0, SwizzleFields1, SwizzleFields2, SwizzleFields3},
     330                           {u16Swizzle0, u16Swizzle1, u16Swizzle2, u16Swizzle3});
     331    
    330332    // Produce unswizzled UTF-16 bit streams
    331     CircularBuffer u16bits(iBuilder, iBuilder->getStreamSetTy(16), segmentSize * bufferSegments);
     333    StreamSetBuffer * u16bits = pxDriver.addBuffer(make_unique<CircularBuffer>(iBuilder, iBuilder->getStreamSetTy(16), segmentSize * bufferSegments));
    332334    SwizzleGenerator unSwizzleK(iBuilder, 16, 1, 4);
    333335    unSwizzleK.setName("unswizzle");
    334     pxDriver.addKernelCall(unSwizzleK, {&u16Swizzle0, &u16Swizzle1, &u16Swizzle2, &u16Swizzle3}, {&u16bits});
    335    
    336     // Different choices for the output buffer depending on chosen option.
    337     ExternalFileBuffer U16external(iBuilder, iBuilder->getStreamSetTy(1, 16));
    338     CircularBuffer U16out(iBuilder, iBuilder->getStreamSetTy(1, 16), segmentSize * bufferSegments);
    339 
     336    pxDriver.addKernelCall(unSwizzleK, {u16Swizzle0, u16Swizzle1, u16Swizzle2, u16Swizzle3}, {u16bits});
     337   
     338   
    340339    P2S16Kernel p2sk(iBuilder);
    341 
    342     //P2S16KernelWithCompressedOutput p2sk(iBuilder);
    343 
     340   
    344341    FileSink outK(iBuilder, 16);
    345     if (mMapBuffering || memAlignBuffering) {
    346         pxDriver.addKernelCall(p2sk, {&u16bits}, {&U16external});
    347         pxDriver.addKernelCall(outK, {&U16external}, {});
    348     } else {
    349         pxDriver.addKernelCall(p2sk, {&u16bits}, {&U16out});
    350         pxDriver.addKernelCall(outK, {&U16out}, {});
    351     }
    352    
    353     iBuilder->SetInsertPoint(BasicBlock::Create(mod->getContext(), "entry", main,0));
    354 
    355     ByteStream.setStreamSetBuffer(inputStream);
    356     BasisBits.allocateBuffer();
    357     U8u16Bits.allocateBuffer();
    358     DelMask.allocateBuffer();
    359     ErrorMask.allocateBuffer();
    360     DeletionCounts.allocateBuffer();
    361     SwizzleFields0.allocateBuffer();
    362     SwizzleFields1.allocateBuffer();
    363     SwizzleFields2.allocateBuffer();
    364     SwizzleFields3.allocateBuffer();
    365     u16Swizzle0.allocateBuffer();
    366     u16Swizzle1.allocateBuffer();
    367     u16Swizzle2.allocateBuffer();
    368     u16Swizzle3.allocateBuffer();
    369     u16bits.allocateBuffer();
    370 
    371     if (mMapBuffering || memAlignBuffering) {
    372         U16external.setStreamSetBuffer(outputStream);
    373     } else {
    374         U16out.allocateBuffer();
    375     }
    376342    Value * fName = iBuilder->CreatePointerCast(iBuilder->CreateGlobalString(outputFile.c_str()), iBuilder->getInt8PtrTy());
    377343    outK.setInitialArguments({fName});
    378 
     344   
     345    // Different choices for the output buffer depending on chosen option.
     346    StreamSetBuffer * U16out = nullptr;
     347    if (mMapBuffering || memAlignBuffering) {
     348        U16out = pxDriver.addExternalBuffer(make_unique<ExternalFileBuffer>(iBuilder, iBuilder->getStreamSetTy(1, 16)), outputStream);
     349    } else {
     350        U16out = pxDriver.addBuffer(make_unique<CircularBuffer>(iBuilder, iBuilder->getStreamSetTy(1, 16), segmentSize * bufferSegments));
     351    }
     352    pxDriver.addKernelCall(p2sk, {u16bits}, {U16out});
     353    pxDriver.addKernelCall(outK, {U16out}, {});
     354   
    379355    pxDriver.generatePipelineIR();
    380 
     356   
    381357    iBuilder->CreateRetVoid();
    382 
     358   
    383359    pxDriver.linkAndFinalize();
    384360}
     
    411387    fileSize->setName("fileSize");
    412388   
    413     ExternalFileBuffer ByteStream(iBuilder, iBuilder->getStreamSetTy(1, 8));
    414    
    415     CircularBuffer BasisBits(iBuilder, iBuilder->getStreamSetTy(8), segmentSize * bufferSegments);
    416    
    417     CircularBuffer U8u16Bits(iBuilder, iBuilder->getStreamSetTy(16), segmentSize * bufferSegments);
    418     CircularBuffer DelMask(iBuilder, iBuilder->getStreamSetTy(), segmentSize * bufferSegments);
    419     CircularBuffer ErrorMask(iBuilder, iBuilder->getStreamSetTy(), segmentSize * bufferSegments);
    420    
    421     CircularBuffer U16Bits(iBuilder, iBuilder->getStreamSetTy(16), segmentSize * bufferSegments);
    422    
    423     CircularBuffer DeletionCounts(iBuilder, iBuilder->getStreamSetTy(), segmentSize * bufferSegments);
    424    
    425     // Different choices for the output buffer depending on chosen option.
    426     ExternalFileBuffer U16external(iBuilder, iBuilder->getStreamSetTy(1, 16));
    427     CircularCopybackBuffer U16out(iBuilder, iBuilder->getStreamSetTy(1, 16), segmentSize * bufferSegments, 1 /*overflow block*/);
    428    
    429     MMapSourceKernel mmapK(iBuilder, segmentSize);
     389    iBuilder->SetInsertPoint(BasicBlock::Create(mod->getContext(), "entry", main,0));
     390
     391    // File data from mmap
     392    StreamSetBuffer * ByteStream = pxDriver.addExternalBuffer(make_unique<ExternalFileBuffer>(iBuilder, iBuilder->getStreamSetTy(1, 8)), inputStream);
     393   
     394    MMapSourceKernel mmapK(iBuilder, segmentSize);
    430395    mmapK.setInitialArguments({fileSize});
    431     pxDriver.addKernelCall(mmapK, {}, {&ByteStream});
     396    pxDriver.addKernelCall(mmapK, {}, {ByteStream});
     397   
     398    // Transposed bits from s2p
     399    StreamSetBuffer * BasisBits = pxDriver.addBuffer(make_unique<CircularBuffer>(iBuilder, iBuilder->getStreamSetTy(8, 1), segmentSize * bufferSegments));
    432400   
    433401    S2PKernel s2pk(iBuilder);
    434     pxDriver.addKernelCall(s2pk, {&ByteStream}, {&BasisBits});
     402    pxDriver.addKernelCall(s2pk, {ByteStream}, {BasisBits});
     403
     404    // Calculate UTF-16 data bits through bitwise logic on u8-indexed streams.
     405    StreamSetBuffer * U8u16Bits = pxDriver.addBuffer(make_unique<CircularBuffer>(iBuilder, iBuilder->getStreamSetTy(16), segmentSize * bufferSegments));
     406    StreamSetBuffer * DelMask = pxDriver.addBuffer(make_unique<CircularBuffer>(iBuilder, iBuilder->getStreamSetTy(), segmentSize * bufferSegments));
     407    StreamSetBuffer * ErrorMask = pxDriver.addBuffer(make_unique<CircularBuffer>(iBuilder, iBuilder->getStreamSetTy(), segmentSize * bufferSegments));
    435408   
    436409    PabloKernel u8u16k(iBuilder, "u8u16",
     
    441414   
    442415    u8u16_pablo(&u8u16k);
    443     pxDriver.addKernelCall(u8u16k, {&BasisBits}, {&U8u16Bits, &DelMask, &ErrorMask});
    444    
     416    pxDriver.addKernelCall(u8u16k, {BasisBits}, {U8u16Bits, DelMask, ErrorMask});
     417   
     418    StreamSetBuffer * U16Bits = pxDriver.addBuffer(make_unique<CircularBuffer>(iBuilder, iBuilder->getStreamSetTy(16), segmentSize * bufferSegments));
     419   
     420    StreamSetBuffer * DeletionCounts = pxDriver.addBuffer(make_unique<CircularBuffer>(iBuilder, iBuilder->getStreamSetTy(), segmentSize * bufferSegments));
     421
    445422    DeletionKernel delK(iBuilder, iBuilder->getBitBlockWidth()/16, 16);
    446     pxDriver.addKernelCall(delK, {&U8u16Bits, &DelMask}, {&U16Bits, &DeletionCounts});
     423    pxDriver.addKernelCall(delK, {U8u16Bits, DelMask}, {U16Bits, DeletionCounts});
    447424   
    448425    P2S16KernelWithCompressedOutput p2sk(iBuilder);
    449426   
    450427    FileSink outK(iBuilder, 16);
    451     if (mMapBuffering || memAlignBuffering) {
    452         pxDriver.addKernelCall(p2sk, {&U16Bits, &DeletionCounts}, {&U16external});
    453         pxDriver.addKernelCall(outK, {&U16external}, {});
    454     } else {
    455         pxDriver.addKernelCall(p2sk, {&U16Bits, &DeletionCounts}, {&U16out});
    456         pxDriver.addKernelCall(outK, {&U16out}, {});
    457     }
    458     iBuilder->SetInsertPoint(BasicBlock::Create(mod->getContext(), "entry", main,0));
    459    
    460     ByteStream.setStreamSetBuffer(inputStream);
    461     BasisBits.allocateBuffer();
    462     U8u16Bits.allocateBuffer();
    463     DelMask.allocateBuffer();
    464     ErrorMask.allocateBuffer();
    465     U16Bits.allocateBuffer();
    466     DeletionCounts.allocateBuffer();
    467     if (mMapBuffering || memAlignBuffering) {
    468         U16external.setStreamSetBuffer(outputStream);
    469     } else {
    470         U16out.allocateBuffer();
    471     }
    472428    Value * fName = iBuilder->CreatePointerCast(iBuilder->CreateGlobalString(outputFile.c_str()), iBuilder->getInt8PtrTy());
    473429    outK.setInitialArguments({fName});
    474430   
     431    // Different choices for the output buffer depending on chosen option.
     432    StreamSetBuffer * U16out = nullptr;
     433    if (mMapBuffering || memAlignBuffering) {
     434        U16out = pxDriver.addExternalBuffer(make_unique<ExternalFileBuffer>(iBuilder, iBuilder->getStreamSetTy(1, 16)), outputStream);
     435    } else {
     436        U16out = pxDriver.addBuffer(make_unique<CircularCopybackBuffer>(iBuilder, iBuilder->getStreamSetTy(1, 16), segmentSize * bufferSegments, 1 /*overflow block*/));
     437    }
     438    pxDriver.addKernelCall(p2sk, {U16Bits, DeletionCounts}, {U16out});
     439    pxDriver.addKernelCall(outK, {U16out}, {});
     440   
    475441    pxDriver.generatePipelineIR();
    476 
    477442   
    478443    iBuilder->CreateRetVoid();
  • icGREP/icgrep-devel/icgrep/wc.cpp

    r5402 r5409  
    150150    Value * const fileIdx = &*(args++);
    151151    fileIdx->setName("fileIdx");
    152    
    153     ExternalFileBuffer ByteStream(iBuilder, iBuilder->getStreamSetTy(1, 8));
    154 
    155     SingleBlockBuffer BasisBits(iBuilder, iBuilder->getStreamSetTy(8, 1));
    156152    iBuilder->SetInsertPoint(BasicBlock::Create(m->getContext(), "entry", main,0));
     153
     154    StreamSetBuffer * ByteStream = pxDriver.addExternalBuffer(make_unique<ExternalFileBuffer>(iBuilder, iBuilder->getStreamSetTy(1, 8)), inputStream);
     155
     156    StreamSetBuffer * BasisBits = pxDriver.addBuffer(make_unique<SingleBlockBuffer>(iBuilder, iBuilder->getStreamSetTy(8, 1)));
    157157
    158158    MMapSourceKernel mmapK(iBuilder);
    159159    mmapK.setInitialArguments({fileSize});
    160     pxDriver.addKernelCall(mmapK, {}, {&ByteStream});
     160    pxDriver.addKernelCall(mmapK, {}, {ByteStream});
    161161
    162162    S2PKernel  s2pk(iBuilder);
    163     pxDriver.addKernelCall(s2pk, {&ByteStream}, {&BasisBits});
     163    pxDriver.addKernelCall(s2pk, {ByteStream}, {BasisBits});
    164164   
    165165    PabloKernel wck(iBuilder, "Parabix:wc",
     
    171171    wc_gen(&wck);
    172172    pablo_function_passes(&wck);
    173     pxDriver.addKernelCall(wck, {&BasisBits}, {});
    174 
    175     ByteStream.setStreamSetBuffer(inputStream);
    176     BasisBits.allocateBuffer();
     173    pxDriver.addKernelCall(wck, {BasisBits}, {});
     174
    177175
    178176    pxDriver.generatePipelineIR();
Note: See TracChangeset for help on using the changeset viewer.