source: icGREP/icgrep-devel/icgrep/kernels/interface.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: 3.6 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#include <string>
10#include <vector>
11#include <llvm/IR/Type.h>
12#include <IDISA/idisa_builder.h>
13#include "streamset.h"
14
15
16struct ScalarBinding {
17    llvm::Type * scalarType;
18    std::string scalarName;
19};
20
21struct StreamSetBinding {
22    parabix::StreamSetType ssType;
23    std::string ssName;
24};
25   
26const std::string init_suffix = "_Init";
27const std::string doBlock_suffix = "_DoBlock";
28const std::string doSegment_suffix = "_DoSegment";
29const std::string finalBlock_suffix = "_FinalBlock";
30const std::string accumulator_infix = "_get_";
31
32class KernelInterface {
33
34public:
35    /*
36     
37     This class defines the methods to be used to generate the code 
38     necessary for declaring, allocating, calling and synchronizing
39     kernels.   The methods to be used for constructing kernels are defined
40     within the KernelBuilder class of kernel.h
41     
42     */
43   
44    std::string & getName() { return mKernelName;}
45   
46    std::vector<StreamSetBinding> getStreamInputs() {return mStreamSetInputs;}
47    std::vector<StreamSetBinding> getStreamOutputs() {return mStreamSetOutputs;}
48    std::vector<ScalarBinding> getScalarInputs() { return mScalarInputs;}
49    std::vector<ScalarBinding> getScalarOutputs() { return mScalarOutputs;}
50   
51   
52    // Add ExternalLinkage method declarations for the kernel to a given client module.
53    void addKernelDeclarations(Module * client);
54   
55    virtual llvm::Value * createInstance(std::vector<llvm::Value *> initialParameters);
56
57    llvm::Value * createDoSegmentCall(llvm::Value * kernelInstance, llvm::Value * blkCount);
58    llvm::Value * createFinalBlockCall(llvm::Value * kernelInstance, llvm::Value * remainingBytes);
59    llvm::Value * createGetAccumulatorCall(llvm::Value * kernelInstance, std::string accumName);
60   
61    unsigned getLookAhead() { return mLookAheadPositions; }
62   
63   
64    virtual llvm::Value * getLogicalSegmentNo(llvm::Value * kernelInstance) = 0;
65    virtual llvm::Value * getProcessedItemCount(llvm::Value * kernelInstance) = 0;
66    virtual llvm::Value * getProducedItemCount(llvm::Value * kernelInstance) = 0;
67    virtual llvm::Value * getTerminationSignal(llvm::Value * kernelInstance) = 0;
68   
69protected:
70    KernelInterface(IDISA::IDISA_Builder * builder,
71                    std::string kernelName,
72                    std::vector<StreamSetBinding> stream_inputs,
73                    std::vector<StreamSetBinding> stream_outputs,
74                    std::vector<ScalarBinding> scalar_parameters,
75                    std::vector<ScalarBinding> scalar_outputs,
76                    std::vector<ScalarBinding> internal_scalars) :
77    iBuilder(builder),
78    mKernelName(kernelName),
79    mStreamSetInputs(stream_inputs),
80    mStreamSetOutputs(stream_outputs),
81    mScalarInputs(scalar_parameters),
82    mScalarOutputs(scalar_outputs),
83    mInternalScalars(internal_scalars),
84    mKernelStateType(nullptr),
85    mLookAheadPositions(0) {}
86   
87   
88   
89    IDISA::IDISA_Builder * iBuilder;
90    std::string mKernelName;
91    std::vector<StreamSetBinding> mStreamSetInputs;
92    std::vector<StreamSetBinding> mStreamSetOutputs;
93    std::vector<ScalarBinding> mScalarInputs;
94    std::vector<ScalarBinding> mScalarOutputs;
95    std::vector<ScalarBinding> mInternalScalars;
96    llvm::Type * mKernelStateType;
97    unsigned mLookAheadPositions;
98   
99    void setLookAhead(unsigned lookAheadPositions) {mLookAheadPositions = lookAheadPositions;}
100    llvm::Value * createDoBlockCall(llvm::Value * kernelInstance);
101
102};
103#endif
Note: See TracBrowser for help on using the repository browser.