source: icGREP/icgrep-devel/icgrep/kernels/interface.h @ 5133

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

Defer binding of buffers to stream sets until kernel generation

File size: 2.6 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#ifndef KERNEL_INTERFACE_H
7#define KERNEL_INTERFACE_H
8
9
10#include <string>
11#include <vector>
12#include <llvm/IR/Type.h>
13#include <IDISA/idisa_builder.h>
14#include "streamset.h"
15
16struct ScalarBinding {
17    llvm::Type * scalarType;
18    std::string scalarName;
19};
20
21struct StreamSetBinding {
22    parabix::StreamSetType ssType;
23    std::string ssName;
24};
25   
26const std::string init_suffix = "_Init";
27const std::string doBlock_suffix = "_DoBlock";
28const std::string doSegment_suffix = "_DoSegment";
29const std::string finalBlock_suffix = "_FinalBlock";
30const std::string accumulator_infix = "_get_";
31
32class KernelInterface {
33
34public:
35    KernelInterface(IDISA::IDISA_Builder * builder,
36                    std::string kernelName,
37                    std::vector<StreamSetBinding> stream_inputs,
38                    std::vector<StreamSetBinding> stream_outputs,
39                    std::vector<ScalarBinding> scalar_parameters,
40                    std::vector<ScalarBinding> scalar_outputs,
41                    std::vector<ScalarBinding> internal_scalars) :
42    iBuilder(builder),
43    mKernelName(kernelName),
44    mStreamSetInputs(stream_inputs),
45    mStreamSetOutputs(stream_outputs),
46    mScalarInputs(scalar_parameters),
47    mScalarOutputs(scalar_outputs),
48    mInternalScalars(internal_scalars),
49    mKernelStateType(nullptr) {}
50   
51   
52    // Add ExternalLinkage method declarations for the kernel to a given client module.
53    void addKernelDeclarations(Module * client);
54   
55    virtual llvm::Value * createInstance(std::vector<llvm::Value *> initialParameters);
56    llvm::Value * createInstance(std::vector<llvm::Value *> initialParameters, std::vector<parabix::StreamSetBuffer *> inputs, std::vector<parabix::StreamSetBuffer *> outputBuffers);
57    llvm::Value * createDoBlockCall(llvm::Value * kernelInstance);
58    llvm::Value * createDoSegmentCall(llvm::Value * kernelInstance, llvm::Value * blkCount);
59    llvm::Value * createFinalBlockCall(llvm::Value * kernelInstance, llvm::Value * remainingBytes);
60    llvm::Value * createGetAccumulatorCall(llvm::Value * kernelInstance, std::string accumName);
61   
62protected:
63   
64    IDISA::IDISA_Builder * iBuilder;
65    std::string mKernelName;
66    std::vector<StreamSetBinding> mStreamSetInputs;
67    std::vector<StreamSetBinding> mStreamSetOutputs;
68    std::vector<ScalarBinding> mScalarInputs;
69    std::vector<ScalarBinding> mScalarOutputs;
70    std::vector<ScalarBinding> mInternalScalars;
71    llvm::Type * mKernelStateType;
72};
73#endif
Note: See TracBrowser for help on using the repository browser.