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

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

DoBlock/FinalBlock/DoSegment? Kernel functions always return void; clean-up

File size: 3.9 KB
RevLine 
[4924]1/*
2 *  Copyright (c) 2016 International Characters.
3 *  This software is licensed to the public under the Open Software License 3.0.
4 */
5
[5063]6#ifndef KERNEL_BUILDER_H
7#define KERNEL_BUILDER_H
8
9
10#include "interface.h"
[4959]11#include <vector>
[5063]12#include <llvm/IR/Type.h>
13#include <IDISA/idisa_builder.h>
[4970]14#include <boost/container/flat_map.hpp>
[4924]15
[5086]16const std::string blockNoScalar = "blockNo";
17const std::string basePtrSuffix = "_basePtr";
18const std::string blkMaskSuffix = "_blkMask";
[4924]19
[5086]20
[4974]21namespace kernel {
[5051]22   
[5063]23class KernelBuilder : public KernelInterface {
[5104]24    using NameMap = boost::container::flat_map<std::string, unsigned>;
[4974]25
[4924]26public:
[5063]27    KernelBuilder(IDISA::IDISA_Builder * builder,
28                    std::string kernelName,
29                    std::vector<StreamSetBinding> stream_inputs,
30                    std::vector<StreamSetBinding> stream_outputs,
31                    std::vector<ScalarBinding> scalar_parameters,
32                    std::vector<ScalarBinding> scalar_outputs,
33                    std::vector<ScalarBinding> internal_scalars);
[5051]34   
[5074]35    // Create a module for the kernel, including the kernel state type declaration and
36    // the full implementation of all required methods.     
37    //
38    std::unique_ptr<llvm::Module> createKernelModule();
[5051]39   
[5074]40    // Generate the Kernel to the current module (iBuilder->getModule()).
41    void generateKernel();
[5051]42   
[5097]43protected:
[5063]44    //
[5074]45    // Kernel builder subtypes define their logic of kernel construction
46    // in terms of 3 virtual methods for
47    // (a) preparing the Kernel state data structure
48    // (b) defining the logic of the doBlock function, and
49    // (c) defining the logic of the finalBlock function.
50    //
51    // Note: the kernel state data structure must only be finalized after
52    // all scalar fields have been added.   If there are no fields to
53    // be added, the default method for preparing kernel state may be used.
[5051]54   
[5076]55    virtual void prepareKernel();
[5063]56   
[5074]57    // Each kernel builder subtype must provide its own logic for generating
58    // doBlock calls.
59    virtual void generateDoBlockMethod() = 0;
[5063]60   
[5074]61    // Each kernel builder subtypre must also specify the logic for processing the
62    // final block of stream data, if there is any special processing required
63    // beyond simply calling the doBlock function.   In the case that the final block
64    // processing may be trivially implemented by dispatching to the doBlock method
65    // without additional preparation, the default generateFinalBlockMethod need
66    // not be overridden.
67   
68    virtual void generateFinalBlockMethod();
69   
[5099]70    virtual void generateDoSegmentMethod();
[5086]71   
[5074]72    // Add an additional scalar field to the KernelState struct.
73    // Must occur before any call to addKernelDeclarations or createKernelModule.
74    void addScalar(llvm::Type * t, std::string scalarName);
[5076]75   
[5063]76    // Run-time access of Kernel State and parameters of methods for
77    // use in implementing kernels.
78   
79    // Get the index of a named scalar field within the kernel state struct.
80    llvm::Value * getScalarIndex(std::string);
81   
82    // Get the value of a scalar field for a given instance.
83    llvm::Value * getScalarField(llvm::Value * self, std::string fieldName);
84   
85    // Set the value of a scalar field for a given instance.
86    void setScalarField(llvm::Value * self, std::string fieldName, llvm::Value * newFieldVal);
87   
88    // Get a parameter by name.
89    llvm::Value * getParameter(llvm::Function * f, std::string paramName);
[5104]90   
91    // Stream set helpers.
92    unsigned getStreamSetIndex(std::string ssName);
93   
94    llvm::Value * getStreamSetBasePtr(Value * self, std::string ssName);
[5109]95    size_t getStreamSetBufferSize(Value * self, std::string ssName);
96
[5104]97    llvm::Value * getStreamSetBlockPtr(Value * self, std::string ssName, Value * blockNo);
98       
[5097]99protected:
[4959]100
[5063]101    std::vector<llvm::Type *>  mKernelFields;
102    NameMap                    mInternalStateNameMap;
[5104]103    NameMap                    mStreamSetNameMap;
[4924]104};
[4959]105}
[5063]106#endif
Note: See TracBrowser for help on using the repository browser.