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

Last change on this file since 5165 was 5165, checked in by lindanl, 3 years ago

Add segment pipeline parallel strategy. Move ballot function to IDISA NVPTX.

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