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

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

Support for KernelInterface? instances

File size: 3.3 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 <boost/container/flat_map.hpp>
15#include "streamset.h"
16
17struct ScalarBinding {
18    llvm::Type * scalarType;
19    std::string scalarName;
20};
21
22struct StreamSetBinding {
23    kernel::StreamSetType ssType;
24    std::string ssName;
25};
26   
27class KernelInterface {
28    using NameMap = boost::container::flat_map<std::string, llvm::ConstantInt *>;
29
30public:
31    KernelInterface(IDISA::IDISA_Builder * builder,
32                    std::string kernelName,
33                    std::vector<StreamSetBinding> stream_inputs,
34                    std::vector<StreamSetBinding> stream_outputs,
35                    std::vector<ScalarBinding> scalar_parameters,
36                    std::vector<ScalarBinding> scalar_outputs,
37                    std::vector<ScalarBinding> internal_scalars);
38   
39    void finalizeKernelStateType();
40   
41    // Add ExternalLinkage method declarations for the kernel to a given client module.
42    void addKernelDeclarations(Module * client);
43   
44    // Create a module for the kernel, including the kernel state type and
45    // all required methods.  The init and accumulator output methods will be
46    // defined, while the doBlock and finalBlock methods will initially be empty.
47    //
48    virtual std::unique_ptr<llvm::Module> createKernelModule();
49   
50    llvm::Value * createInstance(std::vector<llvm::Value *> initialParameters);
51    llvm::Value * createDoBlockCall(llvm::Value * kernelInstance, std::vector<Value *> streamSets);
52    llvm::Value * createFinalBlockCall(llvm::Value * kernelInstance, llvm::Value * remainingBytes, std::vector<llvm::Value *> streamSets);
53    llvm::Value * createGetAccumulatorCall(llvm::Value * kernelInstance, std::string accumName);
54   
55   
56protected:
57    // Add an additional scalar field to the KernelState struct.
58    // Must occur before any call to addKernelDeclarations or createKernelModule.
59    void addScalar(llvm::Type * t, std::string scalarName);
60   
61    // Run-time access of Kernel State and parameters of methods for
62    // use in implementing kernels.
63   
64    // Get the index of a named scalar field within the kernel state struct.
65    llvm::Value * getScalarIndex(std::string);
66   
67    // Get the value of a scalar field for a given instance.
68    llvm::Value * getScalarField(llvm::Value * self, std::string fieldName);
69   
70    // Set the value of a scalar field for a given instance.
71    void setScalarField(llvm::Value * self, std::string fieldName, llvm::Value * newFieldVal);
72   
73    // Get a parameter by name.
74    llvm::Value * getParameter(llvm::Function * f, std::string paramName);
75
76
77    IDISA::IDISA_Builder * iBuilder;
78    std::string mKernelName;
79    std::vector<StreamSetBinding> mStreamSetInputs;
80    std::vector<StreamSetBinding> mStreamSetOutputs;
81   
82    std::vector<ScalarBinding> mScalarInputs;
83    std::vector<ScalarBinding> mScalarOutputs;
84    std::vector<ScalarBinding> mInternalScalars;
85
86    std::vector<llvm::Type *>  mKernelFields;
87    llvm::Type *               mKernelStateType;
88    NameMap                    mInternalStateNameMap;
89};
90
91#endif
Note: See TracBrowser for help on using the repository browser.