source: icGREP/icgrep-devel/icgrep/kernels/source_kernel.h @ 6034

Last change on this file since 6034 was 6008, checked in by nmedfort, 17 months ago

Removed temporary buffers from pipeline and placed them in the source kernels.

File size: 4.5 KB
Line 
1#ifndef SOURCE_KERNEL_H
2#define SOURCE_KERNEL_H
3
4#include "kernel.h"
5namespace kernel { class KernelBuilder; }
6
7namespace kernel {
8
9/* The MMapSourceKernel is a simple wrapper for an external MMap file buffer.
10   The doSegment method of this kernel feeds one segment at a time to a
11   pipeline. */
12
13class MMapSourceKernel final : public SegmentOrientedKernel {
14    friend class FDSourceKernel;
15public:
16    MMapSourceKernel(const std::unique_ptr<kernel::KernelBuilder> & iBuilder, const unsigned codeUnitWidth = 8);
17    bool isCachable() const override { return true; }
18    bool hasSignature() const override { return false; }
19    void linkExternalMethods(const std::unique_ptr<kernel::KernelBuilder> & iBuilder) override {
20        mFileSizeFunction = linkFileSizeMethod(iBuilder);
21    }
22    void generateInitializeMethod(const std::unique_ptr<kernel::KernelBuilder> & iBuilder) override {
23        generateInitializeMethod(mFileSizeFunction, mCodeUnitWidth, iBuilder);
24    }
25    void generateDoSegmentMethod(const std::unique_ptr<kernel::KernelBuilder> & iBuilder) override {
26        generateDoSegmentMethod(mCodeUnitWidth, iBuilder);
27    }
28    void generateFinalizeMethod(const std::unique_ptr<kernel::KernelBuilder> & iBuilder) override {
29        freeBuffer(iBuilder);
30    }
31protected:
32    static llvm::Function * linkFileSizeMethod(const std::unique_ptr<kernel::KernelBuilder> & b);
33    static void generateInitializeMethod(llvm::Function * fileSize, const unsigned codeUnitWidth, const std::unique_ptr<kernel::KernelBuilder> & b);
34    static void generateDoSegmentMethod(const unsigned codeUnitWidth, const std::unique_ptr<kernel::KernelBuilder> & b);
35    static void freeBuffer(const std::unique_ptr<kernel::KernelBuilder> & iBuilder);
36protected:
37    const unsigned mCodeUnitWidth;
38    llvm::Function * mFileSizeFunction;
39};
40
41class ReadSourceKernel final : public SegmentOrientedKernel {
42    friend class FDSourceKernel;
43public:
44    ReadSourceKernel(const std::unique_ptr<kernel::KernelBuilder> & iBuilder, const unsigned codeUnitWidth = 8);
45    bool isCachable() const override { return true; }
46    bool hasSignature() const override { return false; }
47    void generateInitializeMethod(const std::unique_ptr<kernel::KernelBuilder> & iBuilder) override {
48        generateInitializeMethod(mCodeUnitWidth, getStride(), iBuilder);
49    }
50    void generateDoSegmentMethod(const std::unique_ptr<kernel::KernelBuilder> & iBuilder) override {
51        generateDoSegmentMethod(mCodeUnitWidth, getStride(), iBuilder);
52    }
53    void generateFinalizeMethod(const std::unique_ptr<kernel::KernelBuilder> & iBuilder) override {
54        freeBuffer(iBuilder);
55    }
56protected:
57    static void generateInitializeMethod(const unsigned codeUnitWidth, const unsigned stride, const std::unique_ptr<kernel::KernelBuilder> & iBuilder);
58    static void generateDoSegmentMethod(const unsigned codeUnitWidth, const unsigned stride, const std::unique_ptr<kernel::KernelBuilder> & iBuilder);
59    static void freeBuffer(const std::unique_ptr<kernel::KernelBuilder> & iBuilder);
60private:
61    const unsigned mCodeUnitWidth;
62};
63
64class FDSourceKernel final : public SegmentOrientedKernel {
65public:
66    FDSourceKernel(const std::unique_ptr<kernel::KernelBuilder> & iBuilder, const unsigned codeUnitWidth = 8);
67    bool isCachable() const override { return true; }
68    bool hasSignature() const override { return false; }
69    void linkExternalMethods(const std::unique_ptr<kernel::KernelBuilder> & iBuilder) override;
70    void generateInitializeMethod(const std::unique_ptr<kernel::KernelBuilder> & iBuilder) override;
71    void generateDoSegmentMethod(const std::unique_ptr<kernel::KernelBuilder> & iBuilder) override;
72    void generateFinalizeMethod(const std::unique_ptr<kernel::KernelBuilder> & iBuilder) override;
73protected:
74    const unsigned mCodeUnitWidth;
75    llvm::Function * mFileSizeFunction;
76};
77   
78class MemorySourceKernel final : public SegmentOrientedKernel {
79public:
80    MemorySourceKernel(const std::unique_ptr<kernel::KernelBuilder> & iBuilder, const unsigned streamSetCount = 1, const unsigned codeUnitWidth = 8);
81    bool hasSignature() const override { return false; }
82protected:
83    void generateInitializeMethod(const std::unique_ptr<kernel::KernelBuilder> & iBuilder) override;
84    void generateDoSegmentMethod(const std::unique_ptr<kernel::KernelBuilder> & iBuilder) override;
85    void generateFinalizeMethod(const std::unique_ptr<kernel::KernelBuilder> & iBuilder) override;
86private:
87    const unsigned mStreamSetCount;
88    const unsigned mCodeUnitWidth;
89};
90
91}
92
93#endif // SOURCE_KERNEL_H
Note: See TracBrowser for help on using the repository browser.