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

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

Kernel/pipeline progress: sychronize with logicalSegmentNo

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