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

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

getScalarIndex, getParameter

File size: 2.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#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    // Add ExternalLinkage method declarations for the kernel to a given client module.
40    void addKernelDeclarations(Module * client);
41   
42    // Create a module for the kernel, including the kernel state type and
43    // all required methods.  The init and accumulator output methods will be
44    // defined, while the doBlock and finalBlock methods will initially be empty.
45    virtual std::unique_ptr<llvm::Module> createKernelModule();
46   
47protected:
48    // Get the index of a named scalar within the kernel state struct.
49    llvm::Value * getScalarIndex(std::string);
50    // Get a parameter by name.
51    llvm::Value * getParameter(Function * f, std::string paramName);
52
53    IDISA::IDISA_Builder * iBuilder;
54    std::string mKernelName;
55    std::vector<StreamSetBinding> mStreamSetInputs;
56    std::vector<StreamSetBinding> mStreamSetOutputs;
57   
58    std::vector<ScalarBinding> mScalarInputs;
59    std::vector<ScalarBinding> mScalarOutputs;
60    std::vector<ScalarBinding> mInternalScalars;
61    llvm::Type *               mKernelStateType;
62    NameMap                    mInternalStateNameMap;
63    NameMap                    mStreamSetNameMap;
64};
65
66
67#endif
Note: See TracBrowser for help on using the repository browser.