Ignore:
Timestamp:
Dec 3, 2017, 12:40:40 PM (23 months ago)
Author:
nmedfort
Message:

Bug fixes and simplified MultiBlockKernel? logic

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

Legend:

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

    r5646 r5755  
    1818}
    1919
    20 ExternalBuffer * Driver::addExternalBuffer(std::unique_ptr<ExternalBuffer> b) {
    21     mOwnedBuffers.emplace_back(std::move(b));
    22     return cast<ExternalBuffer>(mOwnedBuffers.back().get());
    23 }
    24 
    25 StreamSetBuffer * Driver::addBuffer(std::unique_ptr<StreamSetBuffer> b) {
    26     b->allocateBuffer(iBuilder);
    27     mOwnedBuffers.emplace_back(std::move(b));
    28     return mOwnedBuffers.back().get();
    29 }
    30 
    31 kernel::Kernel * Driver::addKernelInstance(std::unique_ptr<Kernel> kb) {
    32     mOwnedKernels.emplace_back(std::move(kb));
    33     return mOwnedKernels.back().get();
    34 }
    35 
    3620void Driver::deallocateBuffers() {
    3721    for (const auto & b : mOwnedBuffers) {
  • icGREP/icgrep-devel/icgrep/toolchain/driver.h

    r5735 r5755  
    88#include <string>
    99#include <vector>
     10#include <memory>
    1011
    1112namespace llvm { class Function; }
     
    2324    }
    2425
    25     parabix::ExternalBuffer * addExternalBuffer(std::unique_ptr<parabix::ExternalBuffer> b);
     26    template<typename BufferType, typename... Args>
     27    parabix::StreamSetBuffer * addBuffer(Args &&... args) {
     28        BufferType * const b = new BufferType(std::forward<Args>(args) ...);
     29        mOwnedBuffers.emplace_back(b);
     30        if (!std::is_same<BufferType, parabix::ExternalBuffer>::value) {
     31            mOwnedBuffers.back()->allocateBuffer(iBuilder);
     32        }
     33        return b;
     34    }
    2635
    27     parabix::StreamSetBuffer * addBuffer(std::unique_ptr<parabix::StreamSetBuffer> b);
    28 
    29     kernel::Kernel * addKernelInstance(std::unique_ptr<kernel::Kernel> kb);
     36    template<typename KernelType, typename... Args>
     37    kernel::Kernel * addKernelInstance(Args &&... args) {
     38        KernelType * const k = new KernelType(std::forward<Args>(args) ...);
     39        mOwnedKernels.emplace_back(k);
     40        return k;
     41    }
    3042
    3143    void addKernelCall(kernel::Kernel & kb, const std::vector<parabix::StreamSetBuffer *> & inputs, const std::vector<parabix::StreamSetBuffer *> & outputs) {
  • icGREP/icgrep-devel/icgrep/toolchain/grep_pipeline.cpp

    r5695 r5755  
    5252    idb->SetInsertPoint(BasicBlock::Create(M->getContext(), "entry", mainFunc, 0));
    5353   
    54     StreamSetBuffer * ByteStream = pxDriver.addBuffer(make_unique<SourceBuffer>(idb, idb->getStreamSetTy(1, 8)));
    55     kernel::Kernel * sourceK = pxDriver.addKernelInstance(make_unique<kernel::MemorySourceKernel>(idb, idb->getInt8PtrTy(), segmentSize));
     54    StreamSetBuffer * ByteStream = pxDriver.addBuffer<SourceBuffer>(idb, idb->getStreamSetTy(1, 8));
     55    kernel::Kernel * sourceK = pxDriver.addKernelInstance<kernel::MemorySourceKernel>(idb, idb->getInt8PtrTy(), segmentSize);
    5656    sourceK->setInitialArguments({buffer, length});
    5757    pxDriver.makeKernelCall(sourceK, {}, {ByteStream});
    5858   
    59     StreamSetBuffer * BasisBits = pxDriver.addBuffer(make_unique<CircularBuffer>(idb, idb->getStreamSetTy(8, 1), segmentSize));
     59    StreamSetBuffer * BasisBits = pxDriver.addBuffer<CircularBuffer>(idb, idb->getStreamSetTy(8, 1), segmentSize);
    6060   
    61     kernel::Kernel * s2pk = pxDriver.addKernelInstance(make_unique<kernel::S2PKernel>(idb));
     61    kernel::Kernel * s2pk = pxDriver.addKernelInstance<kernel::S2PKernel>(idb);
    6262    pxDriver.makeKernelCall(s2pk, {ByteStream}, {BasisBits});
    6363   
    64     kernel::Kernel * linebreakK = pxDriver.addKernelInstance(make_unique<kernel::LineBreakKernelBuilder>(idb, 8));
    65     StreamSetBuffer * LineBreakStream = pxDriver.addBuffer(make_unique<CircularBuffer>(idb, idb->getStreamSetTy(1, 1), segmentSize));
     64    kernel::Kernel * linebreakK = pxDriver.addKernelInstance<kernel::LineBreakKernelBuilder>(idb, 8);
     65    StreamSetBuffer * LineBreakStream = pxDriver.addBuffer<CircularBuffer>(idb, idb->getStreamSetTy(1, 1), segmentSize);
    6666    pxDriver.makeKernelCall(linebreakK, {BasisBits}, {LineBreakStream});
    6767   
    68     kernel::Kernel * requiredStreamsK = pxDriver.addKernelInstance(make_unique<kernel::RequiredStreams_UTF8>(idb));
    69     StreamSetBuffer * RequiredStreams = pxDriver.addBuffer(make_unique<CircularBuffer>(idb, idb->getStreamSetTy(4, 1), segmentSize));
     68    kernel::Kernel * requiredStreamsK = pxDriver.addKernelInstance<kernel::RequiredStreams_UTF8>(idb);
     69    StreamSetBuffer * RequiredStreams = pxDriver.addBuffer<CircularBuffer>(idb, idb->getStreamSetTy(4, 1), segmentSize);
    7070    pxDriver.makeKernelCall(requiredStreamsK, {BasisBits}, {RequiredStreams});
    7171   
    72     StreamSetBuffer * MatchResults = pxDriver.addBuffer(make_unique<CircularBuffer>(idb, idb->getStreamSetTy(1, 1), segmentSize));
    73     kernel::Kernel * icgrepK = pxDriver.addKernelInstance(make_unique<kernel::ICGrepKernel>(idb, pattern));
     72    StreamSetBuffer * MatchResults = pxDriver.addBuffer<CircularBuffer>(idb, idb->getStreamSetTy(1, 1), segmentSize);
     73    kernel::Kernel * icgrepK = pxDriver.addKernelInstance<kernel::ICGrepKernel>(idb, pattern);
    7474    pxDriver.makeKernelCall(icgrepK, {BasisBits, LineBreakStream, RequiredStreams}, {MatchResults});
    7575   
    76     StreamSetBuffer * MatchedLines = pxDriver.addBuffer(make_unique<CircularBuffer>(idb, idb->getStreamSetTy(1, 1), segmentSize));
    77     kernel::Kernel * matchedLinesK = pxDriver.addKernelInstance(make_unique<kernel::MatchedLinesKernel>(idb));
     76    StreamSetBuffer * MatchedLines = pxDriver.addBuffer<CircularBuffer>(idb, idb->getStreamSetTy(1, 1), segmentSize);
     77    kernel::Kernel * matchedLinesK = pxDriver.addKernelInstance<kernel::MatchedLinesKernel>(idb);
    7878    pxDriver.makeKernelCall(matchedLinesK, {MatchResults, LineBreakStream}, {MatchedLines});
    7979   
    80     kernel::Kernel * scanMatchK = pxDriver.addKernelInstance(make_unique<kernel::ScanMatchKernel>(idb));
     80    kernel::Kernel * scanMatchK = pxDriver.addKernelInstance<kernel::ScanMatchKernel>(idb);
    8181    scanMatchK->setInitialArguments({ConstantInt::get(idb->getIntAddrTy(), reinterpret_cast<intptr_t>(accum))});
    8282    pxDriver.makeKernelCall(scanMatchK, {MatchedLines, LineBreakStream, ByteStream}, {});
  • icGREP/icgrep-devel/icgrep/toolchain/pipeline.cpp

    r5748 r5755  
    195195        for (unsigned i = 0; i < outputs.size(); ++i) {
    196196            if (outputs[i] == buf) {
    197                 const auto binding = k->getStreamOutput(i);
     197                const auto & binding = k->getStreamOutput(i);
    198198                if (LLVM_UNLIKELY(binding.getRate().isDerived())) {
    199199                    continue;
     
    584584        for (unsigned i = 0; i < outputs.size(); ++i) {
    585585            if (outputs[i] == buf) {
    586                 const auto binding = k->getStreamOutput(i);
     586                const auto & binding = k->getStreamOutput(i);
    587587                if (LLVM_UNLIKELY(binding.getRate().isDerived())) {
    588588                    continue;
     
    621621}
    622622
    623 void applyOutputBufferExpansions(const std::unique_ptr<KernelBuilder> & b, const std::string & name, DynamicBuffer * const db, const uint64_t l) {
     623void applyOutputBufferExpansions(const std::unique_ptr<KernelBuilder> & b, const std::string & name, DynamicBuffer * const db, const uint64_t baseSize) {
    624624
    625625    BasicBlock * const doExpand = b->CreateBasicBlock(name + "Expand");
     
    634634    Value * const produced = b->getProducedItemCount(name);
    635635    Value * const consumed = b->getConsumedItemCount(name);
    636     Value * const required = b->CreateAdd(b->CreateSub(produced, consumed), b->getSize(2 * l));
     636    Value * const required = b->CreateAdd(b->CreateSub(produced, consumed), b->getSize(2 * baseSize));
    637637
    638638    b->CreateCondBr(b->CreateICmpUGT(required, db->getCapacity(b.get(), handle)), doExpand, bufferReady);
     
    656656}
    657657
     658ProcessingRate::RateValue getUpperBound(const Kernel * const k, const ProcessingRate & rate) {
     659    if (rate.isFixed() || rate.isBounded()) {
     660        return rate.getUpperBound();
     661    } else if (rate.isRelative()) {
     662        return rate.getRate() * getUpperBound(k, getBinding(k, rate.getReference()).getRate());
     663    } else { // if (rate.isUnknown())
     664        return 0;
     665    }
     666}
     667
    658668void applyOutputBufferExpansions(const std::unique_ptr<KernelBuilder> & b, const Kernel * k) {
    659669    const auto & outputs = k->getStreamSetOutputBuffers();
    660670    for (unsigned i = 0; i < outputs.size(); i++) {
    661671        if (isa<DynamicBuffer>(outputs[i])) {
    662             const ProcessingRate & rate = k->getStreamOutput(i).getRate();
    663             if (rate.isFixed() || rate.isBounded()) {
     672            const auto ub = getUpperBound(k, k->getStreamOutput(i).getRate());
     673            const auto baseSize = (ub.numerator() * k->getStride() + ub.denominator() - 1) / ub.denominator();
     674            if (LLVM_LIKELY(baseSize > 0)) {
    664675                const auto & name = k->getStreamOutput(i).getName();
    665                 const auto l = rate.getUpperBound() * k->getKernelStride();
    666                 applyOutputBufferExpansions(b, name, cast<DynamicBuffer>(outputs[i]), l);
    667             } else if (rate.isExactlyRelative()) {
    668                 const auto binding = getBinding(k, rate.getReference());
    669                 const ProcessingRate & ref = binding.getRate();
    670                 if (rate.isFixed() || rate.isBounded()) {
    671                     const auto & name = k->getStreamOutput(i).getName();
    672                     const auto l = (ref.getUpperBound() * rate.getNumerator() * k->getKernelStride() + rate.getDenominator() - 1) / rate.getDenominator();
    673                     applyOutputBufferExpansions(b, name, cast<DynamicBuffer>(outputs[i]), l);
    674                 }
    675             }
    676         }
    677     }
    678 }
     676                applyOutputBufferExpansions(b, name, cast<DynamicBuffer>(outputs[i]), baseSize);
     677            }
     678        }
     679    }
     680}
  • icGREP/icgrep-devel/icgrep/toolchain/toolchain.cpp

    r5748 r5755  
    128128
    129129bool DebugOptionIsSet(const DebugFlags flag) {
    130     // if (IN_DEBUG_MODE && (flag == EnableAsserts)) return true;
    131130    return DebugOptions.isSet(flag);
    132131}
     
    193192    cl::AddExtraVersionPrinter(&printParabixVersion);
    194193}
    195 
    196 bool AVX2_available() {
    197     StringMap<bool> HostCPUFeatures;
    198     if (sys::getHostCPUFeatures(HostCPUFeatures)) {
    199         auto f = HostCPUFeatures.find("avx2");
    200         return ((f != HostCPUFeatures.end()) && f->second);
    201     }
    202     return false;
    203 }
  • icGREP/icgrep-devel/icgrep/toolchain/toolchain.h

    r5746 r5755  
    9393void AddParabixVersionPrinter();
    9494
    95 bool AVX2_available();
    96 
    9795#endif
Note: See TracChangeset for help on using the changeset viewer.