Ignore:
Timestamp:
Jun 27, 2016, 9:43:17 AM (3 years ago)
Author:
cameron
Message:

Updates for kernels with variable output length; stdout kernel

File:
1 edited

Legend:

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

    r5074 r5076  
    2020                                 std::vector<ScalarBinding> scalar_outputs,
    2121                                 std::vector<ScalarBinding> internal_scalars) :
    22     KernelInterface(builder, kernelName, stream_inputs, stream_outputs, scalar_parameters, scalar_outputs, internal_scalars) {
    23    
    24     for (auto binding : scalar_parameters) {
    25         addScalar(binding.scalarType, binding.scalarName);
    26     }
    27     for (auto binding : scalar_outputs) {
    28         addScalar(binding.scalarType, binding.scalarName);
    29     }
    30     for (auto binding : internal_scalars) {
    31         addScalar(binding.scalarType, binding.scalarName);
    32     }
    33 }
     22    KernelInterface(builder, kernelName, stream_inputs, stream_outputs, scalar_parameters, scalar_outputs, internal_scalars) {}
    3423
    3524void KernelBuilder::addScalar(Type * t, std::string scalarName) {
     
    4231}
    4332
    44 void KernelBuilder::prepareKernelStateType() {
     33void KernelBuilder::setDoBlockReturnType(llvm::Type * t) {
     34    mDoBlockReturnType = t;
     35}
     36
     37void KernelBuilder::prepareKernel() {
     38    if (!mDoBlockReturnType) mDoBlockReturnType = iBuilder->getVoidTy();
     39    for (auto binding : mScalarInputs) {
     40        addScalar(binding.scalarType, binding.scalarName);
     41    }
     42    for (auto binding : mScalarOutputs) {
     43        addScalar(binding.scalarType, binding.scalarName);
     44    }
     45    for (auto binding : mInternalScalars) {
     46        addScalar(binding.scalarType, binding.scalarName);
     47    }
    4548    mKernelStateType = StructType::create(getGlobalContext(), mKernelFields, mKernelName);
    4649}
     
    6265    Module * m = iBuilder->getModule();
    6366
    64     prepareKernelStateType();  // possibly overriden by the KernelBuilder subtype
     67    prepareKernel();  // possibly overriden by the KernelBuilder subtype
    6568    KernelInterface::addKernelDeclarations(m);
    6669    generateDoBlockMethod();     // must be implemented by the KernelBuilder subtype
     
    108111        doBlockArgs.push_back(&*args++);
    109112    }
    110     iBuilder->CreateCall(doBlockFunction, doBlockArgs);
    111     iBuilder->CreateRetVoid();
     113    Value * rslt = iBuilder->CreateCall(doBlockFunction, doBlockArgs);
     114    if (mDoBlockReturnType->isVoidTy()) {
     115        iBuilder->CreateRetVoid();
     116    }
     117    else {
     118        iBuilder->CreateRet(rslt);
     119    }
    112120    iBuilder->restoreIP(savePoint);
    113121}
Note: See TracChangeset for help on using the changeset viewer.