Ignore:
Timestamp:
Apr 22, 2017, 4:03:25 PM (2 years ago)
Author:
nmedfort
Message:

Removed non-functional CUDA code from icgrep and consolidated grep and multigrep mode into a single function; allowed segment parallel pipeline to utilize process as its initial thread; modified MMapSourceKernel to map and perform mmap directly and advise the OS to drop consumed data streams.

File:
1 edited

Legend:

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

    r5411 r5418  
    1111#include <llvm/IR/Module.h>
    1212#include <IR_Gen/idisa_builder.h>
    13 namespace llvm { class Module; }
    14 namespace llvm { class Type; }
    1513
    1614static const auto INIT_SUFFIX = "_Init";
    1715
    18 static const auto TERMINATE_SUFFIX = "_Terminate";
    19 
    2016static const auto DO_SEGMENT_SUFFIX = "_DoSegment";
    2117
    22 static const auto ACCUMULATOR_INFIX = "_get_";
     18static const auto TERMINATE_SUFFIX = "_Terminate";
    2319
    2420using namespace llvm;
     
    7369
    7470void KernelInterface::addKernelDeclarations(Module * const client) {
    75     Module * saveModule = iBuilder->getModule();
    76     auto savePoint = iBuilder->saveIP();
     71    Module * const saveModule = iBuilder->getModule();
    7772    iBuilder->setModule(client);
    7873    if (mKernelStateType == nullptr) {
     
    8277    IntegerType * const sizeTy = iBuilder->getSizeTy();
    8378    PointerType * const consumerTy = StructType::get(sizeTy, sizeTy->getPointerTo()->getPointerTo(), nullptr)->getPointerTo();
     79    Type * const voidTy = iBuilder->getVoidTy();
    8480
    8581    // Create the initialization function prototype
     
    9086    initParameters.insert(initParameters.end(), mStreamSetOutputs.size(), consumerTy);
    9187
    92     FunctionType * initType = FunctionType::get(iBuilder->getVoidTy(), initParameters, false);
    93     Function * init = Function::Create(initType, GlobalValue::ExternalLinkage, getName() + INIT_SUFFIX, client);
    94     init->setCallingConv(CallingConv::C);
    95     init->setDoesNotThrow();
    96     auto args = init->arg_begin();
     88    FunctionType * const initType = FunctionType::get(voidTy, initParameters, false);
     89    Function * const initFunc = Function::Create(initType, GlobalValue::ExternalLinkage, getName() + INIT_SUFFIX, client);
     90    initFunc->setCallingConv(CallingConv::C);
     91    initFunc->setDoesNotThrow();
     92    auto args = initFunc->arg_begin();
    9793    args->setName("self");
    9894    for (auto binding : mScalarInputs) {
     
    10096    }
    10197    for (auto binding : mStreamSetOutputs) {
    102         args->setName(binding.name + "ConsumerLogicalSegments");       
    103         ++args;
     98        (args++)->setName(binding.name + "ConsumerLocks");
    10499    }
    105100
     
    108103    params.insert(params.end(), mStreamSetInputs.size(), sizeTy);
    109104
    110     FunctionType * const doSegmentType = FunctionType::get(iBuilder->getVoidTy(), params, false);
    111     Function * doSegment = Function::Create(doSegmentType, GlobalValue::ExternalLinkage, getName() + DO_SEGMENT_SUFFIX, client);
     105    FunctionType * const doSegmentType = FunctionType::get(voidTy, params, false);
     106    Function * const doSegment = Function::Create(doSegmentType, GlobalValue::ExternalLinkage, getName() + DO_SEGMENT_SUFFIX, client);
    112107    doSegment->setCallingConv(CallingConv::C);
    113108    doSegment->setDoesNotThrow();
    114     doSegment->setDoesNotCapture(1); // for self parameter only.
     109    doSegment->setDoesNotCapture(1); // for self parameter only.   
    115110    args = doSegment->arg_begin();
    116111    args->setName("self");
     
    121116
    122117    // Create the terminate function prototype
    123     FunctionType * terminateType = FunctionType::get(iBuilder->getVoidTy(), {selfType}, false);
    124     Function * terminateFunc = Function::Create(terminateType, GlobalValue::ExternalLinkage, getName() + TERMINATE_SUFFIX, client);
     118    Type * resultType = nullptr;
     119    if (mScalarOutputs.empty()) {
     120        resultType = iBuilder->getVoidTy();
     121    } else {
     122        const auto n = mScalarOutputs.size();
     123        Type * outputType[n];
     124        for (unsigned i = 0; i < n; ++i) {
     125            outputType[i] = mScalarOutputs[i].type;
     126        }
     127        if (n == 1) {
     128            resultType = outputType[0];
     129        } else {
     130            resultType = StructType::get(iBuilder->getContext(), ArrayRef<Type *>(outputType, n));
     131        }
     132    }
     133    FunctionType * const terminateType = FunctionType::get(resultType, {selfType}, false);
     134    Function * const terminateFunc = Function::Create(terminateType, GlobalValue::ExternalLinkage, getName() + TERMINATE_SUFFIX, client);
    125135    terminateFunc->setCallingConv(CallingConv::C);
    126136    terminateFunc->setDoesNotThrow();
     
    129139    args->setName("self");
    130140
    131     /// INVESTIGATE: replace the accumulator methods with a single Exit method that handles any clean up and returns
    132     /// a struct containing all scalar outputs?
    133 
    134     // Create the accumulator get function prototypes
    135     for (const auto & binding : mScalarOutputs) {
    136         FunctionType * accumFnType = FunctionType::get(binding.type, {selfType}, false);
    137         Function * accumFn = Function::Create(accumFnType, GlobalValue::ExternalLinkage, getName() + ACCUMULATOR_INFIX + binding.name, client);
    138         accumFn->setCallingConv(CallingConv::C);
    139         accumFn->setDoesNotThrow();
    140         accumFn->setDoesNotCapture(1);
    141         auto args = accumFn->arg_begin();
    142         args->setName("self");
    143     }
    144 
    145141    iBuilder->setModule(saveModule);
    146     iBuilder->restoreIP(savePoint);
    147142}
    148143
    149144void KernelInterface::setInitialArguments(std::vector<Value *> args) {
    150145    mInitialArguments = args;
    151 }
    152 
    153 llvm::Function * KernelInterface::getAccumulatorFunction(const std::string & accumName) const {
    154     const auto name = getName() + ACCUMULATOR_INFIX + accumName;
    155     Function * f = iBuilder->getModule()->getFunction(name);
    156     if (LLVM_UNLIKELY(f == nullptr)) {
    157         llvm::report_fatal_error("Cannot find " + name);
    158     }
    159     return f;
    160146}
    161147
Note: See TracChangeset for help on using the changeset viewer.