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

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

Buffer class hierarchy; s2p kernel demonstrates specialization for different buffer strategies

File size: 3.2 KB
Line 
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>
7#include <pablo/pablo_compiler.h>
8#include <llvm/Support/Debug.h>
9
10
11using namespace pablo;
12using namespace kernel;
13using namespace parabix;
14
15PabloKernel::PabloKernel(IDISA::IDISA_Builder * builder,
16                         std::string kernelName,
17                         PabloFunction * function,
18                         std::vector<std::string> accumulators) :
19    KernelBuilder(builder, kernelName,
20                    {StreamSetBinding{StreamSetType(function->getNumOfParameters(), 1), "inputs"}},
21                    {},
22                    {},
23                    {},
24                    {ScalarBinding{builder->getBitBlockType(), "EOFmark"}}),
25    mPabloFunction(function) {
26    unsigned output_streams = function->getNumOfResults();
27    if (output_streams > 0) {
28        mStreamSetOutputs = {StreamSetBinding{StreamSetType(output_streams, 1), "outputs"}};
29    }
30    mScalarOutputs = accumBindings(accumulators);
31    pablo_compiler = new PabloCompiler(builder, this, function);
32}
33
34std::vector<ScalarBinding> PabloKernel::accumBindings(std::vector<std::string> accum_names) {
35    std::vector<ScalarBinding> vec;
36    Type * accum_t = iBuilder->getInt64Ty();
37    for (auto a : accum_names) {
38        vec.push_back(ScalarBinding{accum_t, a});
39        addScalar(accum_t, a);
40    }
41    return vec;
42}
43
44void PabloKernel::prepareKernel() {
45    Type * carryDataType = pablo_compiler->initializeCarryData();
46    addScalar(carryDataType, "carries");
47    KernelBuilder::prepareKernel();
48}
49
50void PabloKernel::generateDoBlockMethod() {
51    IDISA::IDISA_Builder::InsertPoint savePoint = iBuilder->saveIP();
52    Module * m = iBuilder->getModule();
53    pablo_compiler->compile(m->getFunction(mKernelName + doBlock_suffix));
54    iBuilder->restoreIP(savePoint);
55}
56
57void PabloKernel::generateFinalBlockMethod() {
58    IDISA::IDISA_Builder::InsertPoint savePoint = iBuilder->saveIP();
59    Module * m = iBuilder->getModule();
60    Function * doBlockFunction = m->getFunction(mKernelName + doBlock_suffix);
61    Function * finalBlockFunction = m->getFunction(mKernelName + finalBlock_suffix);
62    iBuilder->SetInsertPoint(BasicBlock::Create(iBuilder->getContext(), "fb_entry", finalBlockFunction, 0));
63    // Final Block arguments: self, remaining, then the standard DoBlock args.
64    Function::arg_iterator args = finalBlockFunction->arg_begin();
65    Value * self = &*(args++);
66    Value * remaining = &*(args++);
67    std::vector<Value *> doBlockArgs = {self};
68    while (args != finalBlockFunction->arg_end()){
69        doBlockArgs.push_back(&*args++);
70    }
71    // Standard Pablo convention for final block processing: set a bit marking
72    // the position just past EOF.
73    Type * bitBlockInt = iBuilder->getIntNTy(iBuilder->getBitBlockWidth());
74    Value * EOFmark = iBuilder->CreateShl(ConstantInt::get(bitBlockInt, 1), iBuilder->CreateZExt(remaining, bitBlockInt));
75    setScalarField(self, "EOFmark", iBuilder->CreateBitCast(EOFmark, iBuilder->getBitBlockType()));
76    iBuilder->CreateCall(doBlockFunction, doBlockArgs);
77    iBuilder->CreateRetVoid();
78    iBuilder->restoreIP(savePoint);
79}
80
Note: See TracBrowser for help on using the repository browser.