Changeset 6274


Ignore:
Timestamp:
Jan 6, 2019, 12:31:28 PM (9 months ago)
Author:
nmedfort
Message:

Fixed cycle counter logic and moved counters into pipeline struct

Location:
icGREP/icgrep-devel/icgrep/kernels
Files:
8 edited

Legend:

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

    r6273 r6274  
    114114        }
    115115    }
    116 
    117     // We compile in a 64-bit CPU cycle counter into every kernel.   It will remain unused
    118     // in normal execution, but when codegen::EnableCycleCounter is specified, pipelines
    119     // will be able to add instrumentation to cached modules without recompilation.
    120     addInternalScalar(b->getInt64Ty(), CYCLECOUNT_SCALAR);
    121116
    122117}
  • icGREP/icgrep-devel/icgrep/kernels/kernel.h

    r6273 r6274  
    3535
    3636const static std::string BUFFER_HANDLE_SUFFIX = "_buffer";
    37 const static std::string CYCLECOUNT_SCALAR = "CPUcycles";
    3837
    3938namespace kernel {
  • icGREP/icgrep-devel/icgrep/kernels/kernel_builder.cpp

    r6273 r6274  
    2626void KernelBuilder::setScalarField(const StringRef fieldName, Value * const value) {
    2727    CreateStore(value, getScalarFieldPtr(fieldName));
    28 }
    29 
    30 Value * KernelBuilder::getCycleCountPtr() {
    31     return getScalarFieldPtr(CYCLECOUNT_SCALAR);
    3228}
    3329
  • icGREP/icgrep-devel/icgrep/kernels/kernel_builder.h

    r6273 r6274  
    4848
    4949    void setTerminationSignal(llvm::Value * const value);
    50 
    51     llvm::Value * getCycleCountPtr();
    5250
    5351    // Run-time access of Kernel State and parameters of methods for
  • icGREP/icgrep-devel/icgrep/kernels/pipeline/cycle_counter_logic.hpp

    r6261 r6274  
    44
    55namespace kernel {
     6
     7/** ------------------------------------------------------------------------------------------------------------- *
     8 * @brief addInternalKernelCycleCountProperties
     9 ** ------------------------------------------------------------------------------------------------------------- */
     10inline void PipelineCompiler::addInternalKernelCycleCountProperties(BuilderRef b, const unsigned kernel) {
     11    if (LLVM_UNLIKELY(DebugOptionIsSet(codegen::EnableCycleCounter))) {
     12        const auto prefix = makeKernelName(kernel);
     13        mPipelineKernel->addInternalScalar(b->getInt64Ty(), prefix + CYCLE_COUNT_SUFFIX);
     14    }
     15}
    616
    717/** ------------------------------------------------------------------------------------------------------------- *
     
    2131inline void PipelineCompiler::updateOptionalCycleCounter(BuilderRef b) {
    2232    if (LLVM_UNLIKELY(DebugOptionIsSet(codegen::EnableCycleCounter))) {
     33        const auto prefix = makeKernelName(mKernelIndex);
     34        b->setKernel(mPipelineKernel);
     35        Value * const counterPtr = b->getScalarFieldPtr(prefix + CYCLE_COUNT_SUFFIX);
     36        Value * runningCount = b->CreateLoad(counterPtr, true);
    2337        Value * const cycleCountEnd = b->CreateReadCycleCounter();
    24         Value * const counterPtr = b->getCycleCountPtr();
    25         Value * runningCount = b->CreateLoad(counterPtr);
    2638        Value * const segmentCycleCount = b->CreateSub(cycleCountEnd, mCycleCountStart);
    2739        runningCount = b->CreateAdd(runningCount, segmentCycleCount);
    2840        b->CreateStore(runningCount, counterPtr);
     41        b->setKernel(mKernel);
    2942        mCycleCountStart = cycleCountEnd;
     43    }
     44}
     45
     46/** ------------------------------------------------------------------------------------------------------------- *
     47 * @brief selectPrincipleCycleCountBinding
     48 ** ------------------------------------------------------------------------------------------------------------- */
     49inline const Binding & PipelineCompiler::selectPrincipleCycleCountBinding(const unsigned i) const {
     50    const Kernel * const kernel = mPipeline[i];
     51    if (LLVM_UNLIKELY(kernel->getNumOfStreamInputs() == 0)) {
     52        return kernel->getOutputStreamSetBinding(0);
     53    } else {
     54        return kernel->getInputStreamSetBinding(0);
    3055    }
    3156}
     
    3863        Value* FP_100 = ConstantFP::get(b->getDoubleTy(), 100.0);
    3964        Value* totalCycles = b->getSize(0);
     65        b->setKernel(mPipelineKernel);
    4066        for (unsigned i = mFirstKernel; i < mLastKernel; ++i) {
    41             const Kernel * const kernel = mPipeline[i];
    42             b->setKernel(kernel);
    43             Value * cycles = b->CreateLoad(b->getCycleCountPtr());
     67            const auto prefix = makeKernelName(i);
     68            Value * const counterPtr = b->getScalarFieldPtr(prefix + CYCLE_COUNT_SUFFIX);
     69            Value * const cycles = b->CreateLoad(counterPtr);
    4470            totalCycles = b->CreateAdd(totalCycles, cycles);
    4571        }
     
    4773
    4874        for (unsigned i = mFirstKernel; i < mLastKernel; ++i) {
    49             const Kernel * const kernel = mPipeline[i];
    50             b->setKernel(kernel);
    51             const auto & inputs = kernel->getInputStreamSetBindings();
    52             const auto & outputs = kernel->getOutputStreamSetBindings();
    53             Value * items = nullptr;
    54             if (inputs.empty()) {
    55                 items = b->getProducedItemCount(outputs[0].getName());
    56             } else {
    57                 items = b->getProcessedItemCount(inputs[0].getName());
     75
     76            const Binding & binding = selectPrincipleCycleCountBinding(i);
     77            Value * const items = b->getScalarField(makeBufferName(i, binding) + ITEM_COUNT_SUFFIX);
     78
     79            const auto numOfInputs = mKernel->getNumOfStreamInputs();
     80            for (unsigned i = 0; i < numOfInputs; ++i) {
     81                const Binding & input = mKernel->getInputStreamSetBinding(i);
     82                const auto prefix = makeBufferName(mKernelIndex, input);
     83                mInitiallyProcessedItemCount[i] = b->getScalarField(prefix + ITEM_COUNT_SUFFIX);
     84                if (input.isDeferred()) {
     85                    mInitiallyProcessedDeferredItemCount[i] = b->getScalarField(prefix + DEFERRED_ITEM_COUNT_SUFFIX);
     86                }
    5887            }
     88            const auto numOfOutputs = mKernel->getNumOfStreamOutputs();
     89            for (unsigned i = 0; i < numOfOutputs; ++i) {
     90                const Binding & output = mKernel->getOutputStreamSetBinding(i);
     91                const auto prefix = makeBufferName(mKernelIndex, output);
     92                mInitiallyProducedItemCount[i] = b->getScalarField(prefix + ITEM_COUNT_SUFFIX);
     93            }
     94
    5995            Value * fItems = b->CreateUIToFP(items, b->getDoubleTy());
    60             Value * cycles = b->CreateLoad(b->getCycleCountPtr());
     96            const auto name = makeKernelName(i);
     97            Value * const counterPtr = b->getScalarFieldPtr(name + CYCLE_COUNT_SUFFIX);
     98            Value * cycles = b->CreateLoad(counterPtr);
    6199            Value * fCycles = b->CreateUIToFP(cycles, b->getDoubleTy());
    62100            Value * percentage = b->CreateFDiv(b->CreateFMul(fCycles, FP_100), fTotalCycle);
    63101
     102            const Kernel * const kernel = mPipeline[i];
    64103            const auto formatString = kernel->getName() + ": %7.2e items processed;"
    65104                                                          "  %7.2e CPU cycles,"
  • icGREP/icgrep-devel/icgrep/kernels/pipeline/pipeline_builder.cpp

    r6273 r6274  
    264264
    265265    out << 'P' << mNumOfThreads;
     266    if (LLVM_UNLIKELY(DebugOptionIsSet(codegen::EnableCycleCounter))) {
     267        out << "+CYC";
     268    }
    266269    for (auto i : ordering) {
    267270        if (LLVM_LIKELY(i < numOfKernels)) {
  • icGREP/icgrep-devel/icgrep/kernels/pipeline/pipeline_compiler.hpp

    r6272 r6274  
    157157const static std::string DEFERRED_ITEM_COUNT_SUFFIX = ".ICD";
    158158const static std::string CONSUMED_ITEM_COUNT_SUFFIX = ".CON";
     159const static std::string CYCLE_COUNT_SUFFIX = ".CYC";
    159160
    160161class PipelineCompiler {
     
    355356// cycle counter functions
    356357
     358    void addInternalKernelCycleCountProperties(BuilderRef b, const unsigned kernel);
    357359    void startOptionalCycleCounter(BuilderRef b);
    358360    void updateOptionalCycleCounter(BuilderRef b);
    359361    void printOptionalCycleCounter(BuilderRef b);
     362    const Binding & selectPrincipleCycleCountBinding(const unsigned i) const;
    360363
    361364// analysis functions
  • icGREP/icgrep-devel/icgrep/kernels/pipeline/pipeline_logic.hpp

    r6273 r6274  
    5858    const auto name = makeKernelName(kernelIndex);
    5959
    60 //    mPipelineKernel->addInternalScalar(sizeTy, name + TERMINATION_SIGNAL_SUFFIX);
    6160    mPipelineKernel->addInternalScalar(sizeTy, name + LOGICAL_SEGMENT_SUFFIX);
    6261
     
    8079    }
    8180
     81    addInternalKernelCycleCountProperties(b, kernelIndex);
    8282}
    8383
Note: See TracChangeset for help on using the changeset viewer.