Ignore:
Timestamp:
Oct 8, 2016, 7:33:08 PM (3 years ago)
Author:
cameron
Message:

Linear buffers; stdout_kernel; cache-aligned alloca, restructured u8u16, clean-ups

File:
1 edited

Legend:

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

    r5183 r5185  
    5353        }
    5454        if ((mStreamSetInputBuffers[i]->getBufferSize() > 0) && (mStreamSetInputBuffers[i]->getBufferSize() < codegen::SegmentSize + (blockSize + mLookAheadPositions - 1)/blockSize)) {
    55              errs() << "buffer size = " << mStreamSetInputBuffers[i]->getBufferSize() << "\n";
    56              llvm::report_fatal_error("Kernel preparation: Buffer size too small.");
     55             errs() << " buffer size = " << mStreamSetInputBuffers[i]->getBufferSize() << "\n";
     56             llvm::report_fatal_error("Kernel preparation: Buffer size too small " + mStreamSetInputs[i].ssName);
    5757        }
    58         mScalarInputs.push_back(ScalarBinding{mStreamSetInputBuffers[i]->getStreamSetStructPointerType(), mStreamSetInputs[i].ssName + basePtrSuffix});
     58        mScalarInputs.push_back(ScalarBinding{mStreamSetInputBuffers[i]->getStreamSetStructPointerType(), mStreamSetInputs[i].ssName + structPtrSuffix});
    5959        mStreamSetNameMap.emplace(mStreamSetInputs[i].ssName, streamSetNo);
    6060        streamSetNo++;
     
    6262    for (unsigned i = 0; i < mStreamSetOutputs.size(); i++) {
    6363        if (!(mStreamSetOutputBuffers[i]->getBufferStreamSetType() == mStreamSetOutputs[i].ssType)) {
    64              llvm::report_fatal_error("Kernel preparation: Incorrect output buffer type");
     64             llvm::report_fatal_error("Kernel preparation: Incorrect output buffer type " + mStreamSetOutputs[i].ssName);
    6565        }
    66         mScalarInputs.push_back(ScalarBinding{mStreamSetOutputBuffers[i]->getStreamSetStructPointerType(), mStreamSetOutputs[i].ssName + basePtrSuffix});
     66        mScalarInputs.push_back(ScalarBinding{mStreamSetOutputBuffers[i]->getStreamSetStructPointerType(), mStreamSetOutputs[i].ssName + structPtrSuffix});
    6767        mStreamSetNameMap.emplace(mStreamSetOutputs[i].ssName, streamSetNo);
    6868        streamSetNo++;
     
    149149}
    150150
     151// Note: this may be overridden to incorporate doBlock logic directly into
     152// the doSegment function.
    151153void KernelBuilder::generateDoBlockLogic(Value * self, Value * blockNo) {
    152154    Function * doBlockFunction = iBuilder->getModule()->getFunction(mKernelName + doBlock_suffix);
     
    176178   
    177179    for (unsigned i = 0; i < mStreamSetInputs.size(); i++) {
    178         Value * basePtr = getStreamSetBasePtr(self, mStreamSetInputs[i].ssName);
    179         inbufProducerPtrs.push_back(mStreamSetInputBuffers[i]->getProducerPosPtr(basePtr));
     180        Value * ssStructPtr = getStreamSetStructPtr(self, mStreamSetInputs[i].ssName);
     181        inbufProducerPtrs.push_back(mStreamSetInputBuffers[i]->getProducerPosPtr(ssStructPtr));
    180182    }
    181183   
     
    198200    /* Adjust the number of full blocks to do, based on the available data, if necessary. */
    199201    blocksToDo = iBuilder->CreateSelect(iBuilder->CreateICmpULT(blocksToDo, blocksAvail), blocksToDo, blocksAvail);
     202    //iBuilder->CallPrintInt(mKernelName + "_blocksAvail", blocksAvail);
    200203    iBuilder->CreateBr(blockLoopCond);
    201204
     
    208211    iBuilder->SetInsertPoint(blockLoopBody);
    209212    Value * blockNo = getScalarField(self, blockNoScalar);   
     213
    210214    generateDoBlockLogic(self, blockNo);
    211215    setBlockNo(self, iBuilder->CreateAdd(blockNo, strideBlocks));
     
    221225#endif
    222226    for (unsigned i = 0; i < mStreamSetOutputs.size(); i++) {
    223         Value * basePtr = getStreamSetBasePtr(self, mStreamSetOutputs[i].ssName);
    224         Value * producerPosPtr = mStreamSetOutputBuffers[i]->getProducerPosPtr(basePtr);
     227        Value * ssStructPtr = getStreamSetStructPtr(self, mStreamSetOutputs[i].ssName);
     228        Value * producerPosPtr = mStreamSetOutputBuffers[i]->getProducerPosPtr(ssStructPtr);
    225229        iBuilder->CreateAlignedStore(produced, producerPosPtr, sizeof(size_t))->setOrdering(AtomicOrdering::Release);
    226230    }
     
    332336}
    333337
    334 Value * KernelBuilder::getStreamSetBasePtr(Value * self, std::string ssName) {
    335     return getScalarField(self, ssName + basePtrSuffix);
     338Value * KernelBuilder::getStreamSetStructPtr(Value * self, std::string ssName) {
     339    return getScalarField(self, ssName + structPtrSuffix);
    336340}
    337341
    338342Value * KernelBuilder::getStreamSetBlockPtr(Value * self, std::string ssName, Value * blockNo) {
    339     Value * basePtr = getStreamSetBasePtr(self, ssName);
     343    Value * ssStructPtr = getStreamSetStructPtr(self, ssName);
    340344    unsigned ssIndex = getStreamSetIndex(ssName);
    341345    if (ssIndex < mStreamSetInputs.size()) {
    342         return mStreamSetInputBuffers[ssIndex]->getStreamSetBlockPointer(basePtr, blockNo);
     346        return mStreamSetInputBuffers[ssIndex]->getStreamSetBlockPointer(ssStructPtr, blockNo);
    343347    }
    344348    else {
    345         return mStreamSetOutputBuffers[ssIndex - mStreamSetInputs.size()]->getStreamSetBlockPointer(basePtr, blockNo);
     349        return mStreamSetOutputBuffers[ssIndex - mStreamSetInputs.size()]->getStreamSetBlockPointer(ssStructPtr, blockNo);
    346350    }
    347351}
    348352
    349353Value * KernelBuilder::createInstance(std::vector<Value *> args) {
    350     Value * kernelInstance = iBuilder->CreateAlloca(mKernelStateType);
     354    Value * kernelInstance = iBuilder->CreateCacheAlignedAlloca(mKernelStateType);
    351355    Module * m = iBuilder->getModule();
    352356    std::vector<Value *> init_args = {kernelInstance};
     
    394398
    395399    for (unsigned i = 0; i < mStreamSetInputs.size(); i++) {
    396         Value * basePtr = getStreamSetBasePtr(self, mStreamSetInputs[i].ssName);
    397         inbufProducerPtrs.push_back(mStreamSetInputBuffers[i]->getProducerPosPtr(basePtr));
    398         inbufConsumerPtrs.push_back(mStreamSetInputBuffers[i]->getConsumerPosPtr(basePtr));
    399         endSignalPtrs.push_back(mStreamSetInputBuffers[i]->hasEndOfInputPtr(basePtr));
     400        Value * ssStructPtr = getStreamSetStructPtr(self, mStreamSetInputs[i].ssName);
     401        inbufProducerPtrs.push_back(mStreamSetInputBuffers[i]->getProducerPosPtr(ssStructPtr));
     402        inbufConsumerPtrs.push_back(mStreamSetInputBuffers[i]->getConsumerPosPtr(ssStructPtr));
     403        endSignalPtrs.push_back(mStreamSetInputBuffers[i]->hasEndOfInputPtr(ssStructPtr));
    400404    }
    401405    for (unsigned i = 0; i < mStreamSetOutputs.size(); i++) {
    402         Value * basePtr = getStreamSetBasePtr(self, mStreamSetOutputs[i].ssName);
    403         outbufProducerPtrs.push_back(mStreamSetOutputBuffers[i]->getProducerPosPtr(basePtr));
    404         outbufConsumerPtrs.push_back(mStreamSetOutputBuffers[i]->getConsumerPosPtr(basePtr));
     406        Value * ssStructPtr = getStreamSetStructPtr(self, mStreamSetOutputs[i].ssName);
     407        outbufProducerPtrs.push_back(mStreamSetOutputBuffers[i]->getProducerPosPtr(ssStructPtr));
     408        outbufConsumerPtrs.push_back(mStreamSetOutputBuffers[i]->getConsumerPosPtr(ssStructPtr));
    405409    }
    406410
     
    493497        iBuilder->SetInsertPoint(earlyEndBlock);
    494498        for (unsigned i = 0; i < mStreamSetOutputs.size(); i++) {
    495             Value * basePtr = getStreamSetBasePtr(self, mStreamSetOutputs[i].ssName);
    496             mStreamSetOutputBuffers[i]->setEndOfInput(basePtr);
     499            Value * ssStructPtr = getStreamSetStructPtr(self, mStreamSetOutputs[i].ssName);
     500            mStreamSetOutputBuffers[i]->setEndOfInput(ssStructPtr);
    497501        }       
    498502    }
     
    528532
    529533    for (unsigned i = 0; i < mStreamSetOutputs.size(); i++) {
    530         Value * basePtr = getStreamSetBasePtr(self, mStreamSetOutputs[i].ssName);
    531         mStreamSetOutputBuffers[i]->setEndOfInput(basePtr);
     534        Value * ssStructPtr = getStreamSetStructPtr(self, mStreamSetOutputs[i].ssName);
     535        mStreamSetOutputBuffers[i]->setEndOfInput(ssStructPtr);
    532536    }
    533537
Note: See TracChangeset for help on using the changeset viewer.