source: icGREP/icgrep-devel/icgrep/kernels/deletion.h @ 6135

Last change on this file since 6135 was 6037, checked in by cameron, 12 months ago

StreamCompressionCompiler? initial check-in

File size: 6.0 KB
Line 
1/*
2 *  Copyright (c) 2016 International Characters.
3 *  This software is licensed to the public under the Open Software License 3.0.
4 */
5#ifndef DELETION_H
6#define DELETION_H
7
8#include "kernel.h"
9#include <llvm/IR/Value.h>
10#include <toolchain/driver.h>
11
12namespace IDISA { class IDISA_Builder; }
13
14namespace kernel {
15
16class StreamFilterCompiler {
17public:
18    StreamFilterCompiler(Driver & driver, llvm::Type * streamSetType, unsigned bufferBlocks = 0) :
19    mDriver(driver), ssType(streamSetType), mBufferBlocks(bufferBlocks), mIntraFieldCompressionWidth(64) {}
20    void setIntraFieldCompressionWidth(unsigned fw) {mIntraFieldCompressionWidth = fw;}
21    void makeCall(parabix::StreamSetBuffer * mask, parabix::StreamSetBuffer * inputs, parabix::StreamSetBuffer * outputs);
22private:
23    Driver & mDriver;
24    llvm::Type * ssType;
25    unsigned mBufferBlocks;
26    unsigned mIntraFieldCompressionWidth;
27};
28
29//
30// Parallel Prefix Deletion Kernel
31// see Parallel Prefix Compress in Henry S. Warren, Hacker's Delight, Chapter 7
32//
33// Given that we want to delete bits within fields of width fw, moving
34// nondeleted bits to the right, the parallel prefix compress method can
35// be applied.   This requires a preprocessing step to compute log2(fw)
36// masks that can be used to select bits to be moved in each step of the
37// algorithm.
38//
39class DeletionKernel final : public BlockOrientedKernel {
40public:
41    DeletionKernel(const std::unique_ptr<kernel::KernelBuilder> & iBuilder, unsigned fw, unsigned streamCount);
42    bool isCachable() const override { return true; }
43    bool hasSignature() const override { return false; }
44protected:
45    void generateDoBlockMethod(const std::unique_ptr<KernelBuilder> & iBuilder) override;
46    void generateFinalBlockMethod(const std::unique_ptr<KernelBuilder> & iBuilder, llvm::Value * remainingBytes) override;
47private:
48    const unsigned mDeletionFieldWidth;
49    const unsigned mStreamCount;
50};
51
52class FieldCompressKernel final : public MultiBlockKernel {
53public:
54    FieldCompressKernel(const std::unique_ptr<kernel::KernelBuilder> & b, unsigned fw, unsigned streamCount);
55    bool isCachable() const override { return true; }
56    bool hasSignature() const override { return false; }
57protected:
58    void generateMultiBlockLogic(const std::unique_ptr<KernelBuilder> & kb, llvm::Value * const numOfStrides) override;
59private:
60    const unsigned mCompressFieldWidth;
61    const unsigned mStreamCount;
62};
63
64class PEXTFieldCompressKernel final : public MultiBlockKernel {
65public:
66    PEXTFieldCompressKernel(const std::unique_ptr<kernel::KernelBuilder> & b, unsigned fw, unsigned streamCount);
67    bool isCachable() const override { return true; }
68    bool hasSignature() const override { return false; }
69protected:
70    void generateMultiBlockLogic(const std::unique_ptr<KernelBuilder> & kb, llvm::Value * const numOfStrides) override;
71private:
72    const unsigned mPEXTWidth;
73    const unsigned mStreamCount;
74};
75
76//
77//  Given streams that are compressed within fields, produced fully
78//  compressed streams.
79class StreamCompressKernel final : public MultiBlockKernel {
80public:
81    StreamCompressKernel(const std::unique_ptr<kernel::KernelBuilder> & b, unsigned fw, unsigned streamCount);
82    bool isCachable() const override { return true; }
83    bool hasSignature() const override { return false; }
84protected:
85    void generateMultiBlockLogic(const std::unique_ptr<KernelBuilder> & kb, llvm::Value * const numOfBlocks) override;
86private:
87    const unsigned mCompressedFieldWidth;
88    const unsigned mStreamCount;
89};
90
91/*
92Input: a set of bitstreams
93Output: swizzles containing the input bitstreams with the specified bits deleted
94*/
95class SwizzledDeleteByPEXTkernel final : public BlockOrientedKernel {
96public:
97    SwizzledDeleteByPEXTkernel(const std::unique_ptr<kernel::KernelBuilder> & b, unsigned streamCount, unsigned PEXT_width = 64);
98    bool isCachable() const override { return true; }
99    bool hasSignature() const override { return false; }
100protected:
101    void generateDoBlockMethod(const std::unique_ptr<KernelBuilder> & b) override;
102    void generateFinalBlockMethod(const std::unique_ptr<KernelBuilder> & b, llvm::Value * remainingBytes) override;
103private:
104    void generateProcessingLoop(const std::unique_ptr<KernelBuilder> & b, llvm::Value * delMask, const bool flush);
105    std::vector<std::vector<llvm::Value *>> makeSwizzleSets(const std::unique_ptr<KernelBuilder> & b, llvm::Value * delMask);
106private:
107    const unsigned mStreamCount;
108    const unsigned mSwizzleFactor;
109    const unsigned mSwizzleSetCount;
110    const unsigned mPEXTWidth;
111};
112
113class DeleteByPEXTkernel final : public BlockOrientedKernel {
114public:
115    DeleteByPEXTkernel(const std::unique_ptr<kernel::KernelBuilder> & iBuilder, unsigned fw, unsigned streamCount, unsigned PEXT_width = 64);
116    bool isCachable() const override { return true; }
117    bool hasSignature() const override { return false; }
118protected:
119    void generateDoBlockMethod(const std::unique_ptr<KernelBuilder> & iBuilder) override;
120    void generateFinalBlockMethod(const std::unique_ptr<KernelBuilder> & iBuilder, llvm::Value * remainingBytes) override;
121    void generateProcessingLoop(const std::unique_ptr<KernelBuilder> & iBuilder, llvm::Value * delMask);
122private:
123    const unsigned mDelCountFieldWidth;
124    const unsigned mStreamCount;
125    const unsigned mSwizzleFactor;
126    const unsigned mPEXTWidth;
127};
128   
129class SwizzledBitstreamCompressByCount final : public BlockOrientedKernel {
130public:
131    SwizzledBitstreamCompressByCount(const std::unique_ptr<kernel::KernelBuilder> & iBuilder, unsigned bitStreamCount, unsigned fieldWidth = 64);
132    bool isCachable() const override { return true; }
133    bool hasSignature() const override { return false; }
134protected:
135    void generateDoBlockMethod(const std::unique_ptr<KernelBuilder> & iBuilder) override;
136    void generateFinalBlockMethod(const std::unique_ptr<KernelBuilder> & iBuilder, llvm::Value * remainingBytes) override;
137private:
138    const unsigned mBitStreamCount;
139    const unsigned mFieldWidth;
140    const unsigned mSwizzleFactor;
141    const unsigned mSwizzleSetCount;
142};
143
144   
145}
146   
147#endif
148
Note: See TracBrowser for help on using the repository browser.