source: icGREP/icgrep-devel/icgrep/kernels/sequential_kernel.h @ 5941

Last change on this file since 5941 was 5905, checked in by xwa163, 15 months ago
  1. Fix some bugs in match copy kernel
  2. Remove some legacy codes from match copy kernel and sequential kernel
File size: 5.6 KB
Line 
1//
2//
3
4#ifndef ICGREP_SEQUENTIAL_SEGMENT_ORIENTED_KERNEL_H
5#define ICGREP_SEQUENTIAL_SEGMENT_ORIENTED_KERNEL_H
6
7#include "kernel.h"
8#include <vector>
9#include <map>
10
11namespace llvm {
12    class Module;
13    class Function;
14    class BasicBlock;
15    class Value;
16}
17
18namespace IDISA { class IDISA_Builder; }
19
20namespace kernel {
21    class SequentialKernel : public MultiBlockKernel {
22    protected:
23        SequentialKernel(
24                const std::unique_ptr<kernel::KernelBuilder> & iBuilder,
25                std::string && kernelName,
26                std::vector<Binding> && stream_inputs,
27                std::vector<Binding> && stream_outputs,
28                std::vector<Binding> && scalar_parameters,
29                std::vector<Binding> && scalar_outputs,
30                std::vector<Binding> && internal_scalars);
31
32        virtual void generateMultiBlockLogic(const std::unique_ptr<KernelBuilder> &iBuilder, llvm::Value * const numOfStrides) override;
33
34        virtual void generateDoSequentialSegmentMethod(const std::unique_ptr<KernelBuilder> &iBuilder);
35
36        //Cursor
37        void initBufferCursor(const std::unique_ptr<KernelBuilder> &iBuilder, std::vector<std::string> cursorNames);
38
39        llvm::Value* getCursorValue(const std::unique_ptr<KernelBuilder> &iBuilder, std::string cursorName);
40        void advanceCursor(const std::unique_ptr<KernelBuilder> &iBuilder, std::string cursorName, llvm::Value* nums);
41        void advanceCursorUntilPos(const std::unique_ptr<KernelBuilder> &iBuilder, std::string cursorName, llvm::Value* position);
42        llvm::BasicBlock* advanceCursorUntilNextOne(const std::unique_ptr<KernelBuilder> &iBuilder, std::string cursorName, std::string inputStreamBufferName, llvm::Value* maxPos);
43        llvm::BasicBlock* advanceCursorUntilNextZero(const std::unique_ptr<KernelBuilder> &iBuilder,
44                                                     std::string cursorName, std::string inputStreamBufferName, llvm::Value* maxPos);
45
46        // Helper Functions
47        void markCircularOutputBitstreamOnePack(const std::unique_ptr<KernelBuilder> &iBuilder, const std::string& bitstreamName, llvm::Value* start, llvm::Value* end, bool isOne);
48        llvm::BasicBlock* markCircularOutputBitstream(const std::unique_ptr<KernelBuilder> &iBuilder, const std::string& bitstreamName, llvm::Value* start, llvm::Value* end, bool isOne, bool setProduced = true);
49
50        llvm::Value* generateLoadCircularInputPack(const std::unique_ptr<KernelBuilder> &iBuilder, std::string inputBufferName, llvm::Value* offset);
51        llvm::Value* generateLoadCircularInput(const std::unique_ptr<KernelBuilder> &iBuilder, std::string inputBufferName, llvm::Value* offset, llvm::Type* pointerType);
52        llvm::Value* generateLoadSourceInputByte(const std::unique_ptr<KernelBuilder> &iBuilder, std::string sourceBuffername, llvm::Value* offset);
53        void generateStoreCircularOutput(const std::unique_ptr<KernelBuilder> &iBuilder, std::string outputBufferName, llvm::Type* pointerType, llvm::Value* value);
54        void increaseScalarField(const std::unique_ptr<KernelBuilder> &iBuilder, const std::string& fieldName, llvm::Value* value);
55
56
57        llvm::Value* offsetToActualBufferOffset(const std::unique_ptr<KernelBuilder> &iBuilder, std::string inputBufferName, llvm::Value* offset);
58        llvm::Value* offsetToPackOffset(const std::unique_ptr<KernelBuilder> &iBuilder, llvm::Value* offset);
59        llvm::Value* offsetToPackIndex(const std::unique_ptr<KernelBuilder> &iBuilder, llvm::Value* offset);
60        llvm::Value* offsetToPackBaseOffset(const std::unique_ptr<KernelBuilder> &iBuilder, llvm::Value* offset);
61
62        llvm::BasicBlock* waitCursorUntilInputAvailable(const std::unique_ptr<KernelBuilder> &iBuilder, std::string cursorName, std::string inputStreamBufferName);
63
64
65        size_t getInputBufferSize(const std::unique_ptr<KernelBuilder> &iBuilder, std::string bufferName);
66        size_t getOutputBufferSize(const std::unique_ptr<KernelBuilder> &iBuilder, std::string bufferName);
67
68    private:
69        // forwardBits, packEnd, exceedAvailable
70        std::pair<llvm::Value*, std::pair<llvm::Value*, llvm::Value*>> genereateCountForwardBitsOnePack(const std::unique_ptr<KernelBuilder> &iBuilder, std::string inputStreamBufferName, llvm::Value* beginOffset, bool isZero = true);
71
72        // forwardBits, isFinished
73        // maxCount for final bits
74        std::pair<llvm::Value*, llvm::Value*> generateCountForwardBits(const std::unique_ptr<KernelBuilder> &iBuilder, std::string inputStreamBufferName, llvm::Value* beginOffset, bool isZero = true, llvm::Value* maxPos = NULL);
75        std::pair<llvm::Value*, llvm::Value*> generateCountForwardZeros(const std::unique_ptr<KernelBuilder> &iBuilder, std::string inputStreamBufferName, llvm::Value* beginOffset, llvm::Value* maxPos = NULL);
76        std::pair<llvm::Value*, llvm::Value*> generateCountForwardOnes(const std::unique_ptr<KernelBuilder> &iBuilder, std::string inputStreamBufferName, llvm::Value* beginOffset, llvm::Value* maxPos = NULL);
77
78        std::vector<llvm::BasicBlock*> stateBlocks;
79
80        inline std::string generateCursorFullname(std::string cursorName);
81
82        // CursorValue should not be set directly in user implemented kernel
83        void setCursorValue(const std::unique_ptr<KernelBuilder> &iBuilder, std::string cursorName, llvm::Value* value);
84
85        llvm::BasicBlock* exitBlock;
86
87        inline void recordCountForwardTempMaxPos(const std::unique_ptr<KernelBuilder> &iBuilder, llvm::Value* maxPos);
88        inline llvm::Value* restoreCountForwardTempMaxPos(const std::unique_ptr<KernelBuilder> &iBuilder, llvm::Value* currentMaxPos);
89    };
90}
91
92#endif //ICGREP_SEQUENTIAL_SEGMENT_ORIENTED_KERNEL_H
Note: See TracBrowser for help on using the repository browser.