Ignore:
Timestamp:
Jul 15, 2016, 10:04:55 PM (3 years ago)
Author:
cameron
Message:

Initial doSegment support; pipeline generation

File:
1 edited

Legend:

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

    r5076 r5086  
    105105        finalBlockArg->setName(outputSet.ssName);
    106106    }
     107   
     108    // Create the doSegment function prototype.
     109    std::vector<Type *> doSegmentParameters = {selfType, iBuilder->getInt64Ty()};
     110    FunctionType * doSegmentFunctionType = FunctionType::get(mDoBlockReturnType, doSegmentParameters, false);
     111    std::string doSegmentName = mKernelName + doSegment_suffix;
     112    Function * doSegmentFn = Function::Create(doSegmentFunctionType, GlobalValue::ExternalLinkage, doSegmentName, client);
     113    doSegmentFn->setCallingConv(CallingConv::C);
     114    doSegmentFn->setDoesNotThrow();
     115    for (int i = 1; i <= doBlockParameters.size(); i++) {
     116        doSegmentFn->setDoesNotCapture(i);
     117    }
    107118    iBuilder->setModule(saveModule);
    108119    iBuilder->restoreIP(savePoint);
     
    129140}
    130141
     142Value * KernelInterface::createInstance(std::vector<Value *> args,
     143                                        std::vector<StreamSetBuffer *> inputBuffers,
     144                                        std::vector<StreamSetBuffer *> outputBuffers) {
     145    Value * kernelInstance = iBuilder->CreateAlloca(mKernelStateType);
     146    Module * m = iBuilder->getModule();
     147    std::vector<Value *> init_args = {kernelInstance};
     148    for (auto a : args) {
     149        init_args.push_back(a);
     150    }
     151    for (auto b : inputBuffers) {
     152        init_args.push_back(b->getStreamSetBufferPtr());
     153        init_args.push_back(iBuilder->getInt64(b->getSegmentSize() - 1));
     154    }
     155    for (auto b : outputBuffers) {
     156        init_args.push_back(b->getStreamSetBufferPtr());
     157        init_args.push_back(iBuilder->getInt64(b->getSegmentSize() - 1));
     158    }
     159    std::string initFnName = mKernelName + init_suffix;
     160    Function * initMethod = m->getFunction(initFnName);
     161    if (!initMethod) {
     162        throw std::runtime_error("Cannot find " + initFnName);
     163    }
     164    iBuilder->CreateCall(initMethod, init_args);
     165    return kernelInstance;
     166}
     167
     168
     169
     170
    131171Value * KernelInterface::createDoBlockCall(Value * self, std::vector<Value *> streamSets) {
    132172    Module * m = iBuilder->getModule();
     
    157197}
    158198
     199Value * KernelInterface::createDoSegmentCall(Value * self, Value * blksToDo) {
     200    Module * m = iBuilder->getModule();
     201    std::string fnName = mKernelName + doSegment_suffix;
     202    Function * method = m->getFunction(fnName);
     203    if (!method) {
     204        throw std::runtime_error("Cannot find " + fnName);
     205    }
     206    std::vector<Value *> args = {self, blksToDo};
     207    return iBuilder->CreateCall(method, args);
     208}
     209
    159210Value * KernelInterface::createGetAccumulatorCall(Value * self, std::string accumName) {
    160211    Module * m = iBuilder->getModule();
Note: See TracChangeset for help on using the changeset viewer.