source: icGREP/icgrep-devel/icgrep/pablo/pablo_kernel.cpp @ 5102

Last change on this file since 5102 was 5102, checked in by cameron, 3 years ago

Kernel system restructuring progress

File size: 3.9 KB
RevLine 
[5057]1/*
2 *  Copyright (c) 2016 International Characters.
3 *  This software is licensed to the public under the Open Software License 3.0.
4 */
5
6#include <pablo/pablo_kernel.h>
[5059]7#include <pablo/pablo_compiler.h>
8#include <llvm/Support/Debug.h>
[5057]9
10
11using namespace pablo;
[5059]12using namespace kernel;
[5100]13using namespace parabix;
[5057]14
15PabloKernel::PabloKernel(IDISA::IDISA_Builder * builder,
[5059]16                         std::string kernelName,
[5062]17                         PabloFunction * function,
[5102]18                         StreamSetBuffer & inputBuffer,
19                         StreamSetBuffer & outputBuffer,
[5059]20                         std::vector<std::string> accumulators) :
[5062]21    KernelBuilder(builder, kernelName,
[5102]22                    {StreamSetBinding{inputBuffer, "inputs"}},
23                    {StreamSetBinding{outputBuffer, "outputs"}},
[5057]24                    {},
[5059]25                    {},
[5102]26                    {ScalarBinding{builder->getBitBlockType(), "EOFmark"}}),
27    mPabloFunction(function) {
28    unsigned output_streams = function->getNumOfResults();
29    assert (output_streams > 0);
30    mScalarOutputs = accumBindings(accumulators);
31    pablo_compiler = new PabloCompiler(builder, this, function);
32}
33
34PabloKernel::PabloKernel(IDISA::IDISA_Builder * builder,
35                         std::string kernelName,
36                         PabloFunction * function,
37                         StreamSetBuffer & inputBuffer,
38                         std::vector<std::string> accumulators) :
39    KernelBuilder(builder, kernelName,
40                    {StreamSetBinding{inputBuffer, "inputs"}},
[5063]41                    {},
[5102]42                    {},
43                    {},
[5096]44                    {ScalarBinding{builder->getBitBlockType(), "EOFmark"}}),
[5062]45    mPabloFunction(function) {
[5063]46    unsigned output_streams = function->getNumOfResults();
[5102]47    assert (output_streams == 0);
[5059]48    mScalarOutputs = accumBindings(accumulators);
[5062]49    pablo_compiler = new PabloCompiler(builder, this, function);
[5059]50}
[5057]51
[5102]52
[5059]53std::vector<ScalarBinding> PabloKernel::accumBindings(std::vector<std::string> accum_names) {
[5057]54    std::vector<ScalarBinding> vec;
[5059]55    Type * accum_t = iBuilder->getInt64Ty();
56    for (auto a : accum_names) {
[5057]57        vec.push_back(ScalarBinding{accum_t, a});
[5063]58        addScalar(accum_t, a);
[5057]59    }
60    return vec;
61}
62
[5076]63void PabloKernel::prepareKernel() {
[5062]64    Type * carryDataType = pablo_compiler->initializeCarryData();
65    addScalar(carryDataType, "carries");
[5076]66    KernelBuilder::prepareKernel();
[5062]67}
[5059]68
[5074]69void PabloKernel::generateDoBlockMethod() {
[5063]70    IDISA::IDISA_Builder::InsertPoint savePoint = iBuilder->saveIP();
[5062]71    Module * m = iBuilder->getModule();
72    pablo_compiler->compile(m->getFunction(mKernelName + doBlock_suffix));
[5063]73    iBuilder->restoreIP(savePoint);
[5057]74}
75
[5074]76void PabloKernel::generateFinalBlockMethod() {
[5063]77    IDISA::IDISA_Builder::InsertPoint savePoint = iBuilder->saveIP();
[5074]78    Module * m = iBuilder->getModule();
[5062]79    Function * doBlockFunction = m->getFunction(mKernelName + doBlock_suffix);
80    Function * finalBlockFunction = m->getFunction(mKernelName + finalBlock_suffix);
[5057]81    iBuilder->SetInsertPoint(BasicBlock::Create(iBuilder->getContext(), "fb_entry", finalBlockFunction, 0));
82    // Final Block arguments: self, remaining, then the standard DoBlock args.
[5059]83    Function::arg_iterator args = finalBlockFunction->arg_begin();
[5057]84    Value * self = &*(args++);
85    Value * remaining = &*(args++);
86    std::vector<Value *> doBlockArgs = {self};
[5059]87    while (args != finalBlockFunction->arg_end()){
[5057]88        doBlockArgs.push_back(&*args++);
89    }
90    // Standard Pablo convention for final block processing: set a bit marking
91    // the position just past EOF.
[5059]92    Type * bitBlockInt = iBuilder->getIntNTy(iBuilder->getBitBlockWidth());
93    Value * EOFmark = iBuilder->CreateShl(ConstantInt::get(bitBlockInt, 1), iBuilder->CreateZExt(remaining, bitBlockInt));
94    setScalarField(self, "EOFmark", iBuilder->CreateBitCast(EOFmark, iBuilder->getBitBlockType()));
[5057]95    iBuilder->CreateCall(doBlockFunction, doBlockArgs);
96    iBuilder->CreateRetVoid();
[5063]97    iBuilder->restoreIP(savePoint);
[5057]98}
99
Note: See TracBrowser for help on using the repository browser.