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

Last change on this file since 5757 was 5757, checked in by nmedfort, 16 months ago

Bug fixes + more assertions to prevent similar errors.

File size: 4.9 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 blocksRequiredPerSegment = 1, 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, mBlocksRequiredPerSegment, iBuilder);
24    }
25    void generateDoSegmentMethod(const std::unique_ptr<kernel::KernelBuilder> & iBuilder) override {
26        generateDoSegmentMethod(mCodeUnitWidth, mBlocksRequiredPerSegment, iBuilder);
27    }
28    void generateFinalizeMethod(const std::unique_ptr<kernel::KernelBuilder> & iBuilder) override {
29        unmapSourceBuffer(iBuilder);
30    }
31protected:
32    static llvm::Function * linkFileSizeMethod(const std::unique_ptr<kernel::KernelBuilder> & iBuilder);
33    static void generateInitializeMethod(llvm::Function * fileSize, const unsigned codeUnitWidth, const unsigned blocksRequiredPerSegment, const std::unique_ptr<kernel::KernelBuilder> & iBuilder);
34    static void generateDoSegmentMethod(const unsigned codeUnitWidth, const unsigned blocksRequiredPerSegment, const std::unique_ptr<kernel::KernelBuilder> & iBuilder);
35    static void unmapSourceBuffer(const std::unique_ptr<kernel::KernelBuilder> & iBuilder);
36protected:
37    const unsigned   mBlocksRequiredPerSegment;
38    const unsigned   mCodeUnitWidth;
39    llvm::Function * mFileSizeFunction;
40};
41
42class ReadSourceKernel final : public SegmentOrientedKernel {
43    friend class FDSourceKernel;
44public:
45    ReadSourceKernel(const std::unique_ptr<kernel::KernelBuilder> & iBuilder, const unsigned blocksRequiredPerSegment = 1, const unsigned codeUnitWidth = 8);
46    bool isCachable() const override { return true; }
47    bool hasSignature() const override { return false; }
48    void generateInitializeMethod(const std::unique_ptr<kernel::KernelBuilder> & iBuilder) override {
49        generateInitializeMethod(mCodeUnitWidth, mBlocksRequiredPerSegment, iBuilder);
50    }
51    void generateDoSegmentMethod(const std::unique_ptr<kernel::KernelBuilder> & iBuilder) override {
52        generateDoSegmentMethod(mCodeUnitWidth, mBlocksRequiredPerSegment, iBuilder);
53    }
54    void generateFinalizeMethod(const std::unique_ptr<kernel::KernelBuilder> & iBuilder) override {
55        freeBuffer(iBuilder);
56    }
57protected:
58    static void generateInitializeMethod(const unsigned codeUnitWidth, const unsigned blocksRequiredPerSegment, const std::unique_ptr<kernel::KernelBuilder> & iBuilder);
59    static void generateDoSegmentMethod(const unsigned codeUnitWidth, const unsigned blocksRequiredPerSegment, const std::unique_ptr<kernel::KernelBuilder> & iBuilder);
60    static void freeBuffer(const std::unique_ptr<kernel::KernelBuilder> & iBuilder);
61private:
62    const unsigned mBlocksRequiredPerSegment;
63    const unsigned mCodeUnitWidth;
64};
65
66class FDSourceKernel final : public SegmentOrientedKernel {
67public:
68    FDSourceKernel(const std::unique_ptr<kernel::KernelBuilder> & iBuilder, const unsigned blocksRequiredPerSegment = 1, const unsigned codeUnitWidth = 8);
69    bool isCachable() const override { return true; }
70    bool hasSignature() const override { return false; }
71    void linkExternalMethods(const std::unique_ptr<kernel::KernelBuilder> & iBuilder) override;
72    void generateInitializeMethod(const std::unique_ptr<kernel::KernelBuilder> & iBuilder) override;
73    void generateDoSegmentMethod(const std::unique_ptr<kernel::KernelBuilder> & iBuilder) override;
74    void generateFinalizeMethod(const std::unique_ptr<kernel::KernelBuilder> & iBuilder) override;
75protected:
76    const unsigned mBlocksRequiredPerSegment;
77    const unsigned mCodeUnitWidth;
78    llvm::Function * mFileSizeFunction;
79};
80   
81class MemorySourceKernel final : public SegmentOrientedKernel {
82public:
83    MemorySourceKernel(const std::unique_ptr<kernel::KernelBuilder> & iBuilder, llvm::Type * const type, const unsigned blocksRequiredPerSegment = 1, const unsigned codeUnitWidth = 8);
84    bool hasSignature() const override { return false; }
85protected:
86    void generateInitializeMethod(const std::unique_ptr<kernel::KernelBuilder> & iBuilder) override;
87    void generateDoSegmentMethod(const std::unique_ptr<kernel::KernelBuilder> & iBuilder) override;
88private:
89    const unsigned mBlocksRequiredPerSegment;
90    const unsigned mCodeUnitWidth;
91};
92
93}
94
95#endif // SOURCE_KERNEL_H
Note: See TracBrowser for help on using the repository browser.