Changeset 5395 for icGREP


Ignore:
Timestamp:
Apr 6, 2017, 4:14:34 PM (2 years ago)
Author:
cameron
Message:

Uniquify kernel names with buffer types/sizes; update u8u16 to use ParabixDriver?

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

Legend:

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

    r5392 r5395  
    122122
    123123std::unique_ptr<Module> KernelBuilder::createKernelStub() {
    124     return make_unique<Module>(getName() + "_" + iBuilder->getBuilderUniqueName(), iBuilder->getContext());
     124    std::string cacheName = getName() + "_" + iBuilder->getBuilderUniqueName();
     125    for (auto & b: mStreamSetInputBuffers) {
     126        cacheName += ":" + b->getUniqueID();
     127    }
     128    for (auto & b: mStreamSetOutputBuffers) {
     129        cacheName += ":" + b->getUniqueID();
     130    }
     131    return make_unique<Module>(cacheName, iBuilder->getContext());
    125132}
    126133
     
    181188
    182189void KernelBuilder::generateKernel() {
     190    if (mIsGenerated) return;
    183191    auto savePoint = iBuilder->saveIP();
    184192    addKernelDeclarations(iBuilder->getModule());
     
    195203    }
    196204    iBuilder->restoreIP(savePoint);
     205    mIsGenerated = true;
    197206}
    198207
     
    523532    ConstantInt * stride = iBuilder->getSize(iBuilder->getStride());
    524533    Value * availablePos = producerPos[0];
    525     for (unsigned i = 1; i < mStreamSetInputs.size(); i++) {
    526         Value * p = producerPos[i];
    527         availablePos = iBuilder->CreateSelect(iBuilder->CreateICmpULT(availablePos, p), availablePos, p);
    528     }
    529 
    530534    Value * processed = getProcessedItemCount(mStreamSetInputs[0].name);
    531535    Value * itemsAvail = iBuilder->CreateSub(availablePos, processed);
     
    778782, mSelf(nullptr)
    779783, mCurrentMethod(nullptr)
    780 , mNoTerminateAttribute(false) {
     784, mNoTerminateAttribute(false)
     785, mIsGenerated(false) {
    781786
    782787}
  • icGREP/icgrep-devel/icgrep/kernels/kernel.h

    r5392 r5395  
    327327    std::vector<const parabix::StreamSetBuffer *>   mStreamSetOutputBuffers;
    328328    bool                                            mNoTerminateAttribute;
     329    bool                                            mIsGenerated;
    329330
    330331};
  • icGREP/icgrep-devel/icgrep/kernels/p2s_kernel.cpp

    r5356 r5395  
    147147
    148148P2SKernel::P2SKernel(IDISA::IDISA_Builder * iBuilder)
    149 : BlockOrientedKernel(iBuilder, "p2s",
     149: BlockOrientedKernel(iBuilder, "Parabix:p2s",
    150150              {Binding{iBuilder->getStreamSetTy(8, 1), "basisBits"}},
    151151              {Binding{iBuilder->getStreamSetTy(1, 8), "byteStream"}},
     
    154154
    155155P2SKernelWithCompressedOutput::P2SKernelWithCompressedOutput(IDISA::IDISA_Builder * iBuilder)
    156 : BlockOrientedKernel(iBuilder, "p2s_compress",
     156: BlockOrientedKernel(iBuilder, "Parabix:p2s_compress",
    157157              {Binding{iBuilder->getStreamSetTy(8, 1), "basisBits"}, Binding{iBuilder->getStreamSetTy(1, 1), "deletionCounts"}},
    158158                      {Binding{iBuilder->getStreamSetTy(1, 8), "byteStream", MaxRatio(1)}},
     
    161161
    162162P2S16Kernel::P2S16Kernel(IDISA::IDISA_Builder * iBuilder)
    163 : BlockOrientedKernel(iBuilder, "p2s_16",
     163: BlockOrientedKernel(iBuilder, "Parabix:p2s_16",
    164164              {Binding{iBuilder->getStreamSetTy(16, 1), "basisBits"}},
    165165              {Binding{iBuilder->getStreamSetTy(1, 16), "i16Stream"}},
     
    169169
    170170P2S16KernelWithCompressedOutput::P2S16KernelWithCompressedOutput(IDISA::IDISA_Builder * b)
    171 : BlockOrientedKernel(b, "p2s_16_compress",
     171: BlockOrientedKernel(b, "Parabix:p2s_16_compress",
    172172              {Binding{b->getStreamSetTy(16, 1), "basisBits"}, Binding{b->getStreamSetTy(1, 1), "deletionCounts"}},
    173173              {Binding{b->getStreamSetTy(1, 16), "i16Stream", MaxRatio(1)}},
  • icGREP/icgrep-devel/icgrep/kernels/streamset.cpp

    r5390 r5395  
    303303SwizzledCopybackBuffer::SwizzledCopybackBuffer(IDISA::IDISA_Builder * b, Type * type, size_t bufferBlocks, size_t overflowBlocks, unsigned fieldwidth, unsigned AddressSpace)
    304304: StreamSetBuffer(BufferKind::SwizzledCopybackBuffer, b, type, resolveStreamSetType(b, type), bufferBlocks, AddressSpace), mOverflowBlocks(overflowBlocks), mFieldWidth(fieldwidth) {
    305    
     305    mUniqueID = "SW" + std::to_string(fieldwidth) + ":" + std::to_string(bufferBlocks);
     306    if (mOverflowBlocks != 1) mUniqueID += "_" + std::to_string(mOverflowBlocks);
     307    if (AddressSpace > 0) mUniqueID += "@" + std::to_string(AddressSpace);
     308
    306309}
    307310
     
    461464SingleBlockBuffer::SingleBlockBuffer(IDISA::IDISA_Builder * b, Type * type)
    462465: StreamSetBuffer(BufferKind::BlockBuffer, b, type, resolveStreamSetType(b, type), 1, 0) {
     466    mUniqueID = "S";
    463467
    464468}
     
    466470ExternalFileBuffer::ExternalFileBuffer(IDISA::IDISA_Builder * b, Type * type, unsigned AddressSpace)
    467471: StreamSetBuffer(BufferKind::ExternalFileBuffer, b, type, resolveStreamSetType(b, type), 0, AddressSpace) {
    468 
     472    mUniqueID = "E";
     473    if (AddressSpace > 0) mUniqueID += "@" + std::to_string(AddressSpace);
    469474}
    470475
    471476ExtensibleBuffer::ExtensibleBuffer(IDISA::IDISA_Builder * b, Type * type, size_t bufferBlocks, unsigned AddressSpace)
    472477: StreamSetBuffer(BufferKind::ExtensibleBuffer, b, type, StructType::get(b->getSizeTy(), resolveStreamSetType(b, type)->getPointerTo(), nullptr), bufferBlocks, AddressSpace) {
    473 
     478    mUniqueID = "XT" + std::to_string(bufferBlocks);
     479    if (AddressSpace > 0) mUniqueID += "@" + std::to_string(AddressSpace);
    474480}
    475481
    476482CircularBuffer::CircularBuffer(IDISA::IDISA_Builder * b, Type * type, size_t bufferBlocks, unsigned AddressSpace)
    477483: StreamSetBuffer(BufferKind::CircularBuffer, b, type, resolveStreamSetType(b, type), bufferBlocks, AddressSpace) {
     484    mUniqueID = "C" + std::to_string(bufferBlocks);
     485    if (AddressSpace > 0) mUniqueID += "@" + std::to_string(AddressSpace);
    478486
    479487}
     
    481489CircularCopybackBuffer::CircularCopybackBuffer(IDISA::IDISA_Builder * b, Type * type, size_t bufferBlocks, size_t overflowBlocks, unsigned AddressSpace)
    482490: StreamSetBuffer(BufferKind::CircularCopybackBuffer, b, type, resolveStreamSetType(b, type), bufferBlocks, AddressSpace), mOverflowBlocks(overflowBlocks) {
    483 
     491    mUniqueID = "CC" + std::to_string(bufferBlocks);
     492    if (mOverflowBlocks != 1) mUniqueID += "_" + std::to_string(mOverflowBlocks);
     493    if (AddressSpace > 0) mUniqueID += "@" + std::to_string(AddressSpace);
    484494}
    485495
     
    487497: StreamSetBuffer(BufferKind::ExpandableBuffer, b, type, resolveExpandableStreamSetType(b, type), bufferBlocks, AddressSpace)
    488498, mInitialCapacity(type->getArrayNumElements()) {
    489 
     499    mUniqueID = "XP" + std::to_string(bufferBlocks);
     500    if (AddressSpace > 0) mUniqueID += "@" + std::to_string(AddressSpace);
    490501}
    491502
  • icGREP/icgrep-devel/icgrep/kernels/streamset.h

    r5390 r5395  
    2323    BufferKind getBufferKind() const {
    2424        return mBufferKind;
     25    }
     26   
     27    std::string getUniqueID() const {
     28        return mUniqueID;
    2529    }
    2630
     
    8690    llvm::Value *                   mStreamSetBufferPtr;
    8791    llvm::Type * const              mBaseType;
     92    std::string                     mUniqueID;
    8893};   
    8994
  • icGREP/icgrep-devel/icgrep/u8u16.cpp

    r5377 r5395  
    254254}
    255255
    256 Function * u8u16PipelineAVX2(Module * mod, IDISA::IDISA_Builder * iBuilder) {
    257 
     256void u8u16PipelineAVX2Gen(ParabixDriver & pxDriver) {
     257
     258    IDISA::IDISA_Builder * iBuilder = pxDriver.getIDISA_Builder();
     259    Module * mod = iBuilder->getModule();
    258260    const unsigned segmentSize = codegen::SegmentSize;
    259261    const unsigned bufferSegments = codegen::ThreadNum+1;
     
    282284
    283285    MMapSourceKernel mmapK(iBuilder, segmentSize);
    284     mmapK.generateKernel({}, {&ByteStream});
    285286    mmapK.setInitialArguments({fileSize});
    286    
     287    pxDriver.addKernelCall(mmapK, {}, {&ByteStream});
     288
    287289    // Transposed bits from s2p
    288290    CircularBuffer BasisBits(iBuilder, iBuilder->getStreamSetTy(8), segmentSize * bufferSegments);
    289291
    290292    S2PKernel s2pk(iBuilder);
    291     s2pk.generateKernel({&ByteStream}, {&BasisBits});
     293    pxDriver.addKernelCall(s2pk, {&ByteStream}, {&BasisBits});
    292294   
    293295    // Calculate UTF-16 data bits through bitwise logic on u8-indexed streams.
     
    303305   
    304306    u8u16_pablo(&u8u16k);
    305     u8u16k.generateKernel({&BasisBits}, {&U8u16Bits, &DelMask, &ErrorMask});
     307    pxDriver.addKernelCall(u8u16k, {&BasisBits}, {&U8u16Bits, &DelMask, &ErrorMask});
    306308
    307309    // Apply a deletion algorithm to discard all but the final position of the UTF-8
     
    314316
    315317    DeleteByPEXTkernel delK(iBuilder, 64, 16, true);
    316     delK.generateKernel({&U8u16Bits, &DelMask}, {&SwizzleFields0, &SwizzleFields1, &SwizzleFields2, &SwizzleFields3, &DeletionCounts});
     318    pxDriver.addKernelCall(delK, {&U8u16Bits, &DelMask}, {&SwizzleFields0, &SwizzleFields1, &SwizzleFields2, &SwizzleFields3, &DeletionCounts});
    317319;
    318320    //  Produce fully compressed swizzled UTF-16 bit streams
     
    323325
    324326    SwizzledBitstreamCompressByCount compressK(iBuilder, 16);
    325     compressK.generateKernel({&DeletionCounts, &SwizzleFields0, &SwizzleFields1, &SwizzleFields2, &SwizzleFields3},
     327    pxDriver.addKernelCall(compressK, {&DeletionCounts, &SwizzleFields0, &SwizzleFields1, &SwizzleFields2, &SwizzleFields3},
    326328                             {&u16Swizzle0, &u16Swizzle1, &u16Swizzle2, &u16Swizzle3});
    327329 
     
    330332    SwizzleGenerator unSwizzleK(iBuilder, 16, 1, 4);
    331333    unSwizzleK.setName("unswizzle");
    332     unSwizzleK.generateKernel({&u16Swizzle0, &u16Swizzle1, &u16Swizzle2, &u16Swizzle3}, {&u16bits});
     334    pxDriver.addKernelCall(unSwizzleK, {&u16Swizzle0, &u16Swizzle1, &u16Swizzle2, &u16Swizzle3}, {&u16bits});
    333335   
    334336    // Different choices for the output buffer depending on chosen option.
     
    342344    FileSink outK(iBuilder, 16);
    343345    if (mMapBuffering || memAlignBuffering) {
    344         p2sk.generateKernel({&u16bits}, {&U16external});
    345         outK.generateKernel({&U16external}, {});
     346        pxDriver.addKernelCall(p2sk, {&u16bits}, {&U16external});
     347        pxDriver.addKernelCall(outK, {&U16external}, {});
    346348    } else {
    347         p2sk.generateKernel({&u16bits}, {&U16out});
    348         outK.generateKernel({&U16out}, {});
     349        pxDriver.addKernelCall(p2sk, {&u16bits}, {&U16out});
     350        pxDriver.addKernelCall(outK, {&U16out}, {});
    349351    }
    350352   
     
    375377    outK.setInitialArguments({fName});
    376378
    377     generatePipeline(iBuilder, {&mmapK, &s2pk, &u8u16k, &delK, &compressK, &unSwizzleK, &p2sk, &outK});
     379    pxDriver.generatePipelineIR();
    378380
    379381    iBuilder->CreateRetVoid();
    380     return main;
     382    pxDriver.JITcompileMain();
     383    pxDriver.linkAndFinalize();
    381384}
    382385
    383 
    384 Function * u8u16Pipeline(Module * mod, IDISA::IDISA_Builder * iBuilder) {
     386void u8u16PipelineGen(ParabixDriver & pxDriver) {
     387   
     388    IDISA::IDISA_Builder * iBuilder = pxDriver.getIDISA_Builder();
     389    Module * mod = iBuilder->getModule();
    385390   
    386391    const unsigned segmentSize = codegen::SegmentSize;
     
    423428   
    424429    MMapSourceKernel mmapK(iBuilder, segmentSize);
    425     mmapK.generateKernel({}, {&ByteStream});
    426430    mmapK.setInitialArguments({fileSize});
     431    pxDriver.addKernelCall(mmapK, {}, {&ByteStream});
    427432   
    428433    S2PKernel s2pk(iBuilder);
    429    
    430     s2pk.generateKernel({&ByteStream}, {&BasisBits});
     434    pxDriver.addKernelCall(s2pk, {&ByteStream}, {&BasisBits});
    431435   
    432436    PabloKernel u8u16k(iBuilder, "u8u16",
     
    437441   
    438442    u8u16_pablo(&u8u16k);
    439    
    440     u8u16k.generateKernel({&BasisBits}, {&U8u16Bits, &DelMask, &ErrorMask});
     443    pxDriver.addKernelCall(u8u16k, {&BasisBits}, {&U8u16Bits, &DelMask, &ErrorMask});
    441444   
    442445    DeletionKernel delK(iBuilder, iBuilder->getBitBlockWidth()/16, 16);
    443     delK.generateKernel({&U8u16Bits, &DelMask}, {&U16Bits, &DeletionCounts});
     446    pxDriver.addKernelCall(delK, {&U8u16Bits, &DelMask}, {&U16Bits, &DeletionCounts});
    444447   
    445448    P2S16KernelWithCompressedOutput p2sk(iBuilder);
     
    447450    FileSink outK(iBuilder, 16);
    448451    if (mMapBuffering || memAlignBuffering) {
    449         p2sk.generateKernel({&U16Bits, &DeletionCounts}, {&U16external});
    450         outK.generateKernel({&U16external}, {});
     452        pxDriver.addKernelCall(p2sk, {&U16Bits, &DeletionCounts}, {&U16external});
     453        pxDriver.addKernelCall(outK, {&U16external}, {});
    451454    } else {
    452         p2sk.generateKernel({&U16Bits, &DeletionCounts}, {&U16out});
    453         outK.generateKernel({&U16out}, {});
     455        pxDriver.addKernelCall(p2sk, {&U16Bits, &DeletionCounts}, {&U16out});
     456        pxDriver.addKernelCall(outK, {&U16out}, {});
    454457    }
    455458    iBuilder->SetInsertPoint(BasicBlock::Create(mod->getContext(), "entry", main,0));
     
    470473    outK.setInitialArguments({fName});
    471474   
    472     generatePipeline(iBuilder, {&mmapK, &s2pk, &u8u16k, &delK, &p2sk, &outK});
     475    pxDriver.generatePipelineIR();
     476
    473477   
    474478    iBuilder->CreateRetVoid();
    475     return main;
     479    pxDriver.JITcompileMain();
     480    pxDriver.linkAndFinalize();
    476481}
    477482
     
    479484
    480485typedef void (*u8u16FunctionType)(char * byte_data, char * output_data, size_t filesize);
    481 
    482 static ExecutionEngine * u8u16Engine = nullptr;
    483486
    484487u8u16FunctionType u8u16CodeGen(void) {
     
    486489    Module * M = new Module("u8u16", TheContext);
    487490    IDISA::IDISA_Builder * idb = IDISA::GetIDISA_Builder(M);
    488 
    489     llvm::Function * main_IR = (enableAVXdel && AVX2_available() && codegen::BlockSize==256) ? u8u16PipelineAVX2(M, idb) : u8u16Pipeline(M, idb);
    490 
    491     verifyModule(*M, &dbgs());
    492     u8u16Engine = JIT_to_ExecutionEngine(M);   
    493     u8u16Engine->finalizeObject();
     491    ParabixDriver pxDriver(idb);
     492   
     493    if (enableAVXdel && AVX2_available() && codegen::BlockSize==256) {
     494        //u8u16PipelineAVX2(M, idb)
     495        u8u16PipelineAVX2Gen(pxDriver);
     496    }
     497    else{
     498        //u8u16Pipeline(M, idb);
     499        u8u16PipelineGen(pxDriver);
     500    }
     501    u8u16FunctionType main = reinterpret_cast<u8u16FunctionType>(pxDriver.getPointerToMain());
    494502
    495503    delete idb;
    496     return reinterpret_cast<u8u16FunctionType>(u8u16Engine->getPointerToFunction(main_IR));
     504    return main;
    497505}
    498506
Note: See TracChangeset for help on using the changeset viewer.