Ignore:
Timestamp:
Sep 21, 2017, 3:10:34 PM (20 months ago)
Author:
nmedfort
Message:

Minor clean up. Bug fix for object cache when the same cached kernel is used twice in a single run. Improvement to RE Minimizer.

File:
1 edited

Legend:

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

    r5641 r5646  
    137137    assert ("KernelBuilder does not have a valid IDISA Builder" && idb);
    138138    if (LLVM_UNLIKELY(mKernelStateType != nullptr)) {
    139         report_fatal_error("Cannot prepare kernel after kernel state finalized");
     139        report_fatal_error(getName() + ": cannot prepare kernel after kernel state finalized");
    140140    }
    141141    const auto blockSize = idb->getBitBlockWidth();
     
    144144        mStride = blockSize;
    145145    }
    146     const auto requiredBlocks = codegen::SegmentSize + ((blockSize + mLookAheadPositions - 1) / blockSize);
    147 
    148146    IntegerType * const sizeTy = idb->getSizeTy();
    149147
     148    assert (mStreamSetInputs.size() == mStreamSetInputBuffers.size());
     149//    assert (mStreamSetInputs.size() == mStreamSetInputLookahead.size());
     150
    150151    for (unsigned i = 0; i < mStreamSetInputs.size(); i++) {
    151         if ((mStreamSetInputBuffers[i]->getBufferBlocks() != 0) && (mStreamSetInputBuffers[i]->getBufferBlocks() < requiredBlocks)) {
    152             //report_fatal_error(getName() + ": " + mStreamSetInputs[i].name + " requires buffer size " + std::to_string(requiredBlocks));
    153         }
     152//        const auto requiredBlocks = codegen::SegmentSize + ((mStreamSetInputLookahead[i] + blockSize - 1) / blockSize);
     153//        if ((mStreamSetInputBuffers[i]->getBufferBlocks() != 0) && (mStreamSetInputBuffers[i]->getBufferBlocks() < requiredBlocks)) {
     154//            report_fatal_error(getName() + ": " + mStreamSetInputs[i].name + " requires buffer size " + std::to_string(requiredBlocks));
     155//        }
    154156        mScalarInputs.emplace_back(mStreamSetInputBuffers[i]->getStreamSetHandle()->getType(), mStreamSetInputs[i].name + BUFFER_PTR_SUFFIX);
    155157        if ((i == 0) || !mStreamSetInputs[i].rate.isExact()) {
     
    157159        }
    158160    }
     161
     162    assert (mStreamSetOutputs.size() == mStreamSetOutputBuffers.size());
    159163
    160164    for (unsigned i = 0; i < mStreamSetOutputs.size(); i++) {
     
    201205    if (LLVM_LIKELY(mKernelStateType == nullptr)) {
    202206        mKernelStateType = StructType::create(idb->getContext(), mKernelFields, getName());
     207        assert (mKernelStateType);
    203208    }
    204209    processingRateAnalysis();
     
    209214    assert ("KernelBuilder does not have a valid IDISA Builder" && idb);
    210215    if (LLVM_UNLIKELY(mKernelStateType != nullptr)) {
    211         report_fatal_error("Cannot prepare kernel after kernel state finalized");
     216        report_fatal_error(getName() + ": cannot prepare kernel after kernel state finalized");
    212217    }
    213218    assert (getModule());
     
    217222        mStride = blockSize;
    218223    }
    219     const auto requiredBlocks = codegen::SegmentSize + ((blockSize + mLookAheadPositions - 1) / blockSize);
    220 
    221224    IntegerType * const sizeTy = idb->getSizeTy();
     225
     226    assert (mStreamSetInputs.size() == mStreamSetInputBuffers.size());
     227//    assert (mStreamSetInputs.size() == mStreamSetInputLookahead.size());
     228
    222229    for (unsigned i = 0; i < mStreamSetInputs.size(); i++) {
    223         if ((mStreamSetInputBuffers[i]->getBufferBlocks() != 0) && (mStreamSetInputBuffers[i]->getBufferBlocks() < requiredBlocks)) {
    224             //report_fatal_error(getName() + ": " + mStreamSetInputs[i].name + " requires buffer size " + std::to_string(requiredBlocks));
    225         }
     230//        const auto requiredBlocks = codegen::SegmentSize + ((mStreamSetInputLookahead[i] + blockSize - 1) / blockSize);
     231//        if ((mStreamSetInputBuffers[i]->getBufferBlocks() != 0) && (mStreamSetInputBuffers[i]->getBufferBlocks() < requiredBlocks)) {
     232//            report_fatal_error(getName() + ": " + mStreamSetInputs[i].name + " requires buffer size " + std::to_string(requiredBlocks));
     233//        }
    226234        mScalarInputs.emplace_back(mStreamSetInputBuffers[i]->getStreamSetHandle()->getType(), mStreamSetInputs[i].name + BUFFER_PTR_SUFFIX);
    227235        if ((i == 0) || !mStreamSetInputs[i].rate.isExact()) {
     
    229237        }
    230238    }
     239
     240    assert (mStreamSetOutputs.size() == mStreamSetOutputBuffers.size());
    231241
    232242    for (unsigned i = 0; i < mStreamSetOutputs.size(); i++) {
     
    248258        addScalar(binding.type, binding.name);
    249259    }
    250 
    251260    Type * const consumerSetTy = StructType::get(sizeTy, sizeTy->getPointerTo()->getPointerTo(), nullptr)->getPointerTo();
    252261    for (unsigned i = 0; i < mStreamSetOutputs.size(); i++) {
    253262        addScalar(consumerSetTy, mStreamSetOutputs[i].name + CONSUMER_SUFFIX);
    254263    }
    255 
    256264    addScalar(sizeTy, LOGICAL_SEGMENT_NO_SCALAR);
    257265    addScalar(idb->getInt1Ty(), TERMINATION_SIGNAL);
    258 
    259266    for (unsigned i = 0; i < mStreamSetOutputs.size(); i++) {
    260267        addScalar(sizeTy, mStreamSetOutputs[i].name + CONSUMED_ITEM_COUNT_SUFFIX);
    261268    }
    262 
    263269    // We compile in a 64-bit CPU cycle counter into every kernel.   It will remain unused
    264270    // in normal execution, but when codegen::EnableCycleCounter is specified, pipelines
    265271    // will be able to add instrumentation to cached modules without recompilation.
    266272    addScalar(idb->getInt64Ty(), CYCLECOUNT_SCALAR);
     273
    267274    mKernelStateType = getModule()->getTypeByName(getName());
    268     assert (mKernelStateType);
     275    if (LLVM_UNLIKELY(mKernelStateType == nullptr)) {
     276        report_fatal_error("Kernel " + getName() + " definition could not be found in the cache object");
     277    }
    269278    processingRateAnalysis();
    270279}
     
    12621271    //kb->GetInsertBlock()->dump();
    12631272    for (unsigned i = 0; i < outputSetCount; i++) {
    1264         requiredOutputBufferSpace[i] = nullptr;
    1265         auto & rate = kernel->getStreamOutput(i).rate;
     1273        const auto & rate = kernel->getStreamOutput(i).rate;
    12661274        if (rate.isUnknownRate()) continue;  // No calculations possible.
    12671275        Kernel::Port port; unsigned ssIdx;
    12681276        std::tie(port, ssIdx) = kernel->getStreamPort(rate.referenceStreamSet());
     1277        Value * base = nullptr;
    12691278        if (port == Kernel::Port::Output) {
    1270             requiredOutputBufferSpace[i] = rate.CreateRatioCalculation(kb.get(), requiredOutputBufferSpace[ssIdx], doFinal);
    1271         }
    1272         else {
    1273             requiredOutputBufferSpace[i] = rate.CreateRatioCalculation(kb.get(), newlyAvailInputItems[ssIdx], doFinal);
    1274         }
     1279            base = requiredOutputBufferSpace[ssIdx]; assert (base);
     1280        } else {
     1281            base = newlyAvailInputItems[ssIdx]; assert (base);
     1282        }
     1283        requiredOutputBufferSpace[i] = rate.CreateRatioCalculation(kb.get(), base, doFinal);
    12751284        if (auto db = dyn_cast<DynamicBuffer>(outputs[i])) {
    12761285            Value * handle = db->getStreamSetHandle();
Note: See TracChangeset for help on using the changeset viewer.