source: icGREP/icgrep-devel/icgrep/kernels/kernel.h @ 5063

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

New kernel infrastructure

File size: 2.4 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_BUILDER_H
7#define KERNEL_BUILDER_H
8
9
10#include "interface.h"
11#include <vector>
12#include <llvm/IR/Type.h>
13#include <IDISA/idisa_builder.h>
14#include <boost/container/flat_map.hpp>
15
16
17namespace kernel {
18   
19class KernelBuilder : public KernelInterface {
20    using NameMap = boost::container::flat_map<std::string, llvm::ConstantInt *>;
21
22public:
23    KernelBuilder(IDISA::IDISA_Builder * builder,
24                    std::string kernelName,
25                    std::vector<StreamSetBinding> stream_inputs,
26                    std::vector<StreamSetBinding> stream_outputs,
27                    std::vector<ScalarBinding> scalar_parameters,
28                    std::vector<ScalarBinding> scalar_outputs,
29                    std::vector<ScalarBinding> internal_scalars);
30   
31    // Add an additional scalar field to the KernelState struct.
32    // Must occur before any call to addKernelDeclarations or createKernelModule.
33    void addScalar(llvm::Type * t, std::string scalarName);
34   
35    void finalizeKernelStateType();
36   
37    // Create a module for the kernel, including the kernel state type and
38    // all required methods.  The init and accumulator output methods will be
39    // defined, while the doBlock and finalBlock methods will initially be empty.
40    //
41    virtual std::unique_ptr<llvm::Module> createKernelModule();
42   
43    // Generate Kernel to the current module.
44    virtual void generateKernel();
45   
46    // Add a FinalBlock method that simply calls DoBlock without additional
47    // preparation.
48    void addTrivialFinalBlockMethod(Module * m);
49   
50    // Run-time access of Kernel State and parameters of methods for
51    // use in implementing kernels.
52   
53    // Get the index of a named scalar field within the kernel state struct.
54    llvm::Value * getScalarIndex(std::string);
55   
56    // Get the value of a scalar field for a given instance.
57    llvm::Value * getScalarField(llvm::Value * self, std::string fieldName);
58   
59    // Set the value of a scalar field for a given instance.
60    void setScalarField(llvm::Value * self, std::string fieldName, llvm::Value * newFieldVal);
61   
62    // Get a parameter by name.
63    llvm::Value * getParameter(llvm::Function * f, std::string paramName);
64
65protected:
66
67    std::vector<llvm::Type *>  mKernelFields;
68    NameMap                    mInternalStateNameMap;
69};
70}
71#endif
Note: See TracBrowser for help on using the repository browser.