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

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

Cache signature is now written into .kernel bitcode file. Minor bug fix and revision of GrepEngine::DoGrepThreadMethod?

File size: 4.8 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 stridesPerSegment = 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, mStride * mStridesPerSegment, iBuilder);
24    }
25    void generateDoSegmentMethod(const std::unique_ptr<kernel::KernelBuilder> & iBuilder) override {
26        generateDoSegmentMethod(mCodeUnitWidth, mStride * mStridesPerSegment, 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 segmentSize, const std::unique_ptr<kernel::KernelBuilder> & iBuilder);
34    static void generateDoSegmentMethod(const unsigned codeUnitWidth, const unsigned segmentSize, const std::unique_ptr<kernel::KernelBuilder> & iBuilder);
35    static void unmapSourceBuffer(const std::unique_ptr<kernel::KernelBuilder> & iBuilder);
36protected:
37    const unsigned mStridesPerSegment;
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 stridesPerSegment = 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, mStride * mStridesPerSegment, iBuilder);
50    }
51    void generateDoSegmentMethod(const std::unique_ptr<kernel::KernelBuilder> & iBuilder) override {
52        generateDoSegmentMethod(mCodeUnitWidth, mStride * mStridesPerSegment, 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 segmentSize, const std::unique_ptr<kernel::KernelBuilder> & iBuilder);
59    static void generateDoSegmentMethod(const unsigned codeUnitWidth, const unsigned segmentSize, const std::unique_ptr<kernel::KernelBuilder> & iBuilder);
60    static void freeBuffer(const std::unique_ptr<kernel::KernelBuilder> & iBuilder);
61private:
62    const unsigned mStridesPerSegment;
63    const unsigned mCodeUnitWidth;
64};
65
66class FDSourceKernel final : public SegmentOrientedKernel {
67public:
68    FDSourceKernel(const std::unique_ptr<kernel::KernelBuilder> & iBuilder, const unsigned stridesPerSegment = 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 mStridesPerSegment;
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 stridesPerSegment = 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 mStridesPerSegment;
90    const unsigned mCodeUnitWidth;
91};
92
93}
94
95#endif // SOURCE_KERNEL_H
Note: See TracBrowser for help on using the repository browser.