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

Last change on this file since 5941 was 5856, checked in by nmedfort, 19 months ago

Revised pipeline structure to better control I/O rates

File size: 4.4 KB
RevLine 
[5429]1#ifndef SOURCE_KERNEL_H
2#define SOURCE_KERNEL_H
3
4#include "kernel.h"
[5436]5namespace kernel { class KernelBuilder; }
[5429]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 {
[5706]14    friend class FDSourceKernel;
[5429]15public:
[5856]16    MMapSourceKernel(const std::unique_ptr<kernel::KernelBuilder> & iBuilder, const unsigned codeUnitWidth = 8);
[5431]17    bool isCachable() const override { return true; }
[5464]18    bool hasSignature() const override { return false; }
[5706]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 {
[5856]23        generateInitializeMethod(mFileSizeFunction, mCodeUnitWidth, iBuilder);
[5706]24    }
25    void generateDoSegmentMethod(const std::unique_ptr<kernel::KernelBuilder> & iBuilder) override {
[5856]26        generateDoSegmentMethod(mCodeUnitWidth, iBuilder);
[5706]27    }
28    void generateFinalizeMethod(const std::unique_ptr<kernel::KernelBuilder> & iBuilder) override {
29        unmapSourceBuffer(iBuilder);
30    }
[5429]31protected:
[5706]32    static llvm::Function * linkFileSizeMethod(const std::unique_ptr<kernel::KernelBuilder> & iBuilder);
[5856]33    static void generateInitializeMethod(llvm::Function * fileSize, const unsigned codeUnitWidth, const std::unique_ptr<kernel::KernelBuilder> & iBuilder);
34    static void generateDoSegmentMethod(const unsigned codeUnitWidth, const std::unique_ptr<kernel::KernelBuilder> & iBuilder);
[5706]35    static void unmapSourceBuffer(const std::unique_ptr<kernel::KernelBuilder> & iBuilder);
36protected:
[5761]37    const unsigned mCodeUnitWidth;
[5757]38    llvm::Function * mFileSizeFunction;
[5429]39};
40
41class ReadSourceKernel final : public SegmentOrientedKernel {
[5706]42    friend class FDSourceKernel;
[5429]43public:
[5856]44    ReadSourceKernel(const std::unique_ptr<kernel::KernelBuilder> & iBuilder, const unsigned codeUnitWidth = 8);
[5431]45    bool isCachable() const override { return true; }
[5464]46    bool hasSignature() const override { return false; }
[5706]47    void generateInitializeMethod(const std::unique_ptr<kernel::KernelBuilder> & iBuilder) override {
[5856]48        generateInitializeMethod(mCodeUnitWidth, getStride(), iBuilder);
[5706]49    }
50    void generateDoSegmentMethod(const std::unique_ptr<kernel::KernelBuilder> & iBuilder) override {
[5856]51        generateDoSegmentMethod(mCodeUnitWidth, getStride(), iBuilder);
[5706]52    }
53    void generateFinalizeMethod(const std::unique_ptr<kernel::KernelBuilder> & iBuilder) override {
54        freeBuffer(iBuilder);
55    }
56protected:
[5856]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);
[5706]59    static void freeBuffer(const std::unique_ptr<kernel::KernelBuilder> & iBuilder);
[5429]60private:
[5757]61    const unsigned mCodeUnitWidth;
[5429]62};
63
[5693]64class FDSourceKernel final : public SegmentOrientedKernel {
65public:
[5856]66    FDSourceKernel(const std::unique_ptr<kernel::KernelBuilder> & iBuilder, const unsigned codeUnitWidth = 8);
[5693]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:
[5757]74    const unsigned mCodeUnitWidth;
75    llvm::Function * mFileSizeFunction;
[5693]76};
77   
[5429]78class MemorySourceKernel final : public SegmentOrientedKernel {
79public:
[5856]80    MemorySourceKernel(const std::unique_ptr<kernel::KernelBuilder> & iBuilder, llvm::Type * const type, const unsigned codeUnitWidth = 8);
[5464]81    bool hasSignature() const override { return false; }
[5429]82protected:
[5440]83    void generateInitializeMethod(const std::unique_ptr<kernel::KernelBuilder> & iBuilder) override;
84    void generateDoSegmentMethod(const std::unique_ptr<kernel::KernelBuilder> & iBuilder) override;
[5429]85private:
[5757]86    const unsigned mCodeUnitWidth;
[5429]87};
88
89}
90
91#endif // SOURCE_KERNEL_H
Note: See TracBrowser for help on using the repository browser.