Ignore:
Timestamp:
Dec 16, 2016, 4:16:28 PM (3 years ago)
Author:
nmedfort
Message:

Rewrite of the CarryManager? to support non-carry-collapsing loops.

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

Legend:

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

    r5220 r5227  
    2121    }
    2222    Type * selfType = PointerType::getUnqual(mKernelStateType);
     23
    2324    // Create the accumulator get function prototypes
    2425    for (auto binding : mScalarOutputs) {
     
    3132        self->setName("self");       
    3233    }
     34
    3335    // Create the initialization function prototype
    34 
    3536    std::vector<Type *> initParameters = {selfType};
    3637    for (auto binding : mScalarInputs) {
  • icGREP/icgrep-devel/icgrep/kernels/interface.h

    r5224 r5227  
    108108    std::vector<Binding> mScalarOutputs;
    109109    std::vector<Binding> mInternalScalars;
    110     llvm::Type * mKernelStateType;
     110    llvm::StructType * mKernelStateType;
    111111    llvm::Value * mKernelInstance;
    112112    unsigned mLookAheadPositions;
  • icGREP/icgrep-devel/icgrep/kernels/kernel.cpp

    r5224 r5227  
    99#include <llvm/IR/Value.h>
    1010#include <llvm/Support/raw_ostream.h>
    11 #include <llvm/IR/TypeBuilder.h>
    1211#include <llvm/Support/ErrorHandling.h>
    1312#include <toolchain.h>
     
    2221                                 std::vector<Binding> scalar_parameters,
    2322                                 std::vector<Binding> scalar_outputs,
    24                                  std::vector<Binding> internal_scalars) :
    25     KernelInterface(builder, kernelName, stream_inputs, stream_outputs, scalar_parameters, scalar_outputs, internal_scalars) {}
    26 
    27 void KernelBuilder::addScalar(Type * t, std::string name) {
     23                                 std::vector<Binding> internal_scalars)
     24: KernelInterface(builder, kernelName, stream_inputs, stream_outputs, scalar_parameters, scalar_outputs, internal_scalars) {
     25
     26}
     27
     28unsigned KernelBuilder::addScalar(Type * type, std::string name) {
    2829    if (LLVM_UNLIKELY(mKernelStateType != nullptr)) {
    29         llvm::report_fatal_error("Illegal addition of kernel field after kernel state finalized: " + name);
    30     }
    31     unsigned index = mKernelFields.size();
    32     mKernelFields.push_back(t);
    33     mInternalStateNameMap.emplace(name, index);
     30        llvm::report_fatal_error("Cannot add kernel field " + name + " after kernel state finalized");
     31    }
     32    const auto index = mKernelFields.size();
     33    mKernelMap.emplace(name, index);
     34    mKernelFields.push_back(type);
     35    return index;
    3436}
    3537
     
    5052        throw std::runtime_error(out.str());
    5153    }
    52     addScalar(iBuilder->getSizeTy(), blockNoScalar);
    53     addScalar(iBuilder->getSizeTy(), logicalSegmentNoScalar);
    54     addScalar(iBuilder->getSizeTy(), processedItemCount);
    55     addScalar(iBuilder->getSizeTy(), producedItemCount);
    56     addScalar(iBuilder->getInt1Ty(), terminationSignal);
    5754    int streamSetNo = 0;
    5855    for (unsigned i = 0; i < mStreamSetInputs.size(); i++) {
     
    7875        addScalar(binding.type, binding.name);
    7976    }
     77    addScalar(iBuilder->getSizeTy(), blockNoScalar);
     78    addScalar(iBuilder->getSizeTy(), logicalSegmentNoScalar);
     79    addScalar(iBuilder->getSizeTy(), processedItemCount);
     80    addScalar(iBuilder->getSizeTy(), producedItemCount);
     81    addScalar(iBuilder->getInt1Ty(), terminationSignal);
    8082    mKernelStateType = StructType::create(iBuilder->getContext(), mKernelFields, mKernelName);
    8183}
     
    9597void KernelBuilder::generateKernel(std::vector<StreamSetBuffer *> input_buffers, std::vector<StreamSetBuffer*> output_buffers) {
    9698    auto savePoint = iBuilder->saveIP();
    97     Module * m = iBuilder->getModule();
     99    Module * const m = iBuilder->getModule();
    98100    mStreamSetInputBuffers = input_buffers;
    99101    mStreamSetOutputBuffers = output_buffers;
    100102    prepareKernel();  // possibly overriden by the KernelBuilder subtype
    101     KernelInterface::addKernelDeclarations(m);
     103    addKernelDeclarations(m);
    102104    generateDoBlockMethod();     // must be implemented by the KernelBuilder subtype
    103105    generateFinalBlockMethod();  // possibly overriden by the KernelBuilder subtype
     
    283285}
    284286
    285 Value * KernelBuilder::getScalarIndex(std::string fieldName) {
    286     const auto f = mInternalStateNameMap.find(fieldName);
    287     if (LLVM_UNLIKELY(f == mInternalStateNameMap.end())) {
    288         throw std::runtime_error("Kernel does not contain internal state: " + fieldName);
     287ConstantInt * KernelBuilder::getScalarIndex(const std::string & name) const {
     288    const auto f = mKernelMap.find(name);
     289    if (LLVM_UNLIKELY(f == mKernelMap.end())) {
     290        throw std::runtime_error("Kernel does not contain internal state: " + name);
    289291    }
    290292    return iBuilder->getInt32(f->second);
    291293}
    292294
    293 Value * KernelBuilder::getScalarFieldPtr(Value * self, std::string fieldName) {
     295unsigned KernelBuilder::getScalarCount() const {
     296    return mKernelFields.size();
     297}
     298
     299Value * KernelBuilder::getScalarFieldPtr(Value * self, const std::string & fieldName) {
    294300    return iBuilder->CreateGEP(self, {iBuilder->getInt32(0), getScalarIndex(fieldName)});
    295301}
     
    422428    Module * m = iBuilder->getModule();
    423429    Type * const voidTy = Type::getVoidTy(m->getContext());
    424     Type * const voidPtrTy = TypeBuilder<void *, false>::get(m->getContext());
     430    Type * const voidPtrTy = iBuilder->getVoidPtrTy();
    425431    Type * const int8PtrTy = iBuilder->getInt8PtrTy();
    426432    Type * const int1ty = iBuilder->getInt1Ty();
  • icGREP/icgrep-devel/icgrep/kernels/kernel.h

    r5224 r5227  
    108108    // Add an additional scalar field to the KernelState struct.
    109109    // Must occur before any call to addKernelDeclarations or createKernelModule.
    110     void addScalar(llvm::Type * t, std::string name);
    111    
     110    unsigned addScalar(llvm::Type * type, std::string name);
     111
     112    unsigned getScalarCount() const;
     113
    112114    // Run-time access of Kernel State and parameters of methods for
    113115    // use in implementing kernels.
    114116   
    115117    // Get the index of a named scalar field within the kernel state struct.
    116     llvm::Value * getScalarIndex(std::string);
     118    ConstantInt * getScalarIndex(const std::string & name) const;
    117119   
    118120    // Get the value of a scalar field for a given instance.
     
    128130    unsigned getStreamSetIndex(std::string name);
    129131   
    130     llvm::Value * getScalarFieldPtr(Value * self, std::string name);
     132    llvm::Value * getScalarFieldPtr(Value * self, const std::string & name);
    131133
    132134    llvm::Value * getStreamSetStructPtr(Value * self, std::string name);
     
    143145
    144146    std::vector<llvm::Type *>  mKernelFields;
    145     NameMap                    mInternalStateNameMap;
     147    NameMap                    mKernelMap;
    146148    NameMap                    mStreamSetNameMap;
    147149    std::vector<StreamSetBuffer *> mStreamSetInputBuffers;
  • icGREP/icgrep-devel/icgrep/kernels/p2s_kernel.cpp

    r5217 r5227  
    22#include "kernels/kernel.h"
    33#include "IDISA/idisa_builder.h"
    4 #include <llvm/IR/TypeBuilder.h>
    54#include <llvm/IR/Type.h>
    65#include <iostream>
  • icGREP/icgrep-devel/icgrep/kernels/pipeline.cpp

    r5224 r5227  
    44 */
    55
    6 
     6#include "pipeline.h"
    77#include <toolchain.h>
    8 #include "pipeline.h"
    9 
    108#include <IDISA/idisa_builder.h>
    11 
    129#include <kernels/interface.h>
    1310#include <kernels/kernel.h>
    1411#include <kernels/s2p_kernel.h>
    15 
    16 #include <llvm/IR/TypeBuilder.h>
    1712#include <iostream>
    1813
     
    2318    Module * m = iBuilder->getModule();
    2419    Type * const size_ty = iBuilder->getSizeTy();
    25     Type * const voidTy = Type::getVoidTy(m->getContext());
    26     Type * const voidPtrTy = TypeBuilder<void *, false>::get(m->getContext());
     20    Type * const voidTy = iBuilder->getVoidTy();
     21    Type * const voidPtrTy = iBuilder->getVoidPtrTy();
    2722    Type * const int8PtrTy = iBuilder->getInt8PtrTy();
    2823
     
    10398
    10499    Type * const size_ty = iBuilder->getSizeTy();
    105     Type * const voidPtrTy = TypeBuilder<void *, false>::get(m->getContext());
     100    Type * const voidPtrTy = iBuilder->getVoidPtrTy();
    106101    Type * const int8PtrTy = iBuilder->getInt8PtrTy();
    107102
     
    159154
    160155    Type * pthreadTy = iBuilder->getSizeTy();     
    161     Type * const voidPtrTy = TypeBuilder<void *, false>::get(m->getContext());
     156    Type * const voidPtrTy = iBuilder->getVoidPtrTy();
    162157    Type * const int8PtrTy = iBuilder->getInt8PtrTy();
    163158
Note: See TracChangeset for help on using the changeset viewer.