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

Last change on this file since 6189 was 6189, checked in by nmedfort, 7 months ago

Bug fixes for 32-bit

File size: 6.2 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
16//
17// Parallel Prefix Deletion Kernel
18// see Parallel Prefix Compress in Henry S. Warren, Hacker's Delight, Chapter 7
19//
20// Given that we want to delete bits within fields of width fw, moving
21// nondeleted bits to the right, the parallel prefix compress method can
22// be applied.   This requires a preprocessing step to compute log2(fw)
23// masks that can be used to select bits to be moved in each step of the
24// algorithm.
25//
26class DeletionKernel final : public BlockOrientedKernel {
27public:
28    DeletionKernel(const std::unique_ptr<kernel::KernelBuilder> & iBuilder, unsigned fw, unsigned streamCount);
29    bool isCachable() const override { return true; }
30    bool hasSignature() const override { return false; }
31protected:
32    void generateDoBlockMethod(const std::unique_ptr<KernelBuilder> & iBuilder) override;
33    void generateFinalBlockMethod(const std::unique_ptr<KernelBuilder> & iBuilder, llvm::Value * remainingBytes) override;
34private:
35    const unsigned mDeletionFieldWidth;
36    const unsigned mStreamCount;
37};
38
39class FieldCompressKernel final : public MultiBlockKernel {
40public:
41    #ifdef STREAM_COMPRESS_USING_EXTRACTION_MASK
42    FieldCompressKernel(const std::unique_ptr<kernel::KernelBuilder> & b, StreamSet * inputStreamSet, StreamSet * extractionMask, StreamSet * outputStreamSet);
43    #else
44    FieldCompressKernel(const std::unique_ptr<kernel::KernelBuilder> & b, StreamSet * inputStreamSet, StreamSet * extractionMask, StreamSet * outputStreamSet, StreamSet * unitCounts);
45    #endif
46    bool isCachable() const override { return true; }
47    bool hasSignature() const override { return false; }
48protected:
49    void generateMultiBlockLogic(const std::unique_ptr<KernelBuilder> & kb, llvm::Value * const numOfStrides) override;
50private:
51    const unsigned mCompressFieldWidth;
52    const unsigned mStreamCount;
53};
54
55class PEXTFieldCompressKernel final : public MultiBlockKernel {
56public:
57    PEXTFieldCompressKernel(const std::unique_ptr<kernel::KernelBuilder> & b, unsigned fw, unsigned streamCount);
58    bool isCachable() const override { return true; }
59    bool hasSignature() const override { return false; }
60protected:
61    void generateMultiBlockLogic(const std::unique_ptr<KernelBuilder> & kb, llvm::Value * const numOfStrides) override;
62private:
63    const unsigned mPEXTWidth;
64    const unsigned mStreamCount;
65};
66
67//
68//  Given streams that are compressed within fields, produced fully
69//  compressed streams.
70class StreamCompressKernel final : public MultiBlockKernel {
71public:
72    StreamCompressKernel(const std::unique_ptr<kernel::KernelBuilder> & b
73                         , StreamSet * source
74                         #ifdef STREAM_COMPRESS_USING_EXTRACTION_MASK
75                         , StreamSet * extractionMask
76                         #else
77                         , StreamSet * unitCounts
78                         #endif
79                         , StreamSet * compresedOutput
80                         , const unsigned FieldWidth = sizeof(size_t) * 8);
81
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 MultiBlockKernel {
96public:
97    using SwizzleSets = std::vector<std::vector<llvm::Value *>>;
98    SwizzledDeleteByPEXTkernel(const std::unique_ptr<kernel::KernelBuilder> & b
99                               , StreamSet * selectors, StreamSet * inputStreamSet
100                               , const std::vector<StreamSet *> & outputs
101                               , unsigned PEXTWidth = sizeof(size_t) * 8);
102    bool isCachable() const override { return true; }
103    bool hasSignature() const override { return false; }
104protected:
105    void generateMultiBlockLogic(const std::unique_ptr<KernelBuilder> & b, llvm::Value * const numOfBlocks) override;
106private:
107    SwizzleSets makeSwizzleSets(const std::unique_ptr<KernelBuilder> & b, llvm::Value * selectors, llvm::Value * const strideIndex);
108private:
109    const unsigned mStreamCount;
110    const unsigned mSwizzleFactor;
111    const unsigned mSwizzleSetCount;
112    const unsigned mPEXTWidth;
113};
114
115class DeleteByPEXTkernel final : public BlockOrientedKernel {
116public:
117    DeleteByPEXTkernel(const std::unique_ptr<kernel::KernelBuilder> & iBuilder, unsigned fw, unsigned streamCount, unsigned PEXT_width = sizeof(size_t) * 8);
118    bool isCachable() const override { return true; }
119    bool hasSignature() const override { return false; }
120protected:
121    void generateDoBlockMethod(const std::unique_ptr<KernelBuilder> & iBuilder) override;
122    void generateFinalBlockMethod(const std::unique_ptr<KernelBuilder> & iBuilder, llvm::Value * remainingBytes) override;
123    void generateProcessingLoop(const std::unique_ptr<KernelBuilder> & iBuilder, llvm::Value * delMask);
124private:
125    const unsigned mDelCountFieldWidth;
126    const unsigned mStreamCount;
127    const unsigned mSwizzleFactor;
128    const unsigned mPEXTWidth;
129};
130   
131class SwizzledBitstreamCompressByCount final : public BlockOrientedKernel {
132public:
133    SwizzledBitstreamCompressByCount(const std::unique_ptr<kernel::KernelBuilder> & iBuilder, unsigned bitStreamCount, unsigned fieldWidth = sizeof(size_t) * 8);
134    bool isCachable() const override { return true; }
135    bool hasSignature() const override { return false; }
136protected:
137    void generateDoBlockMethod(const std::unique_ptr<KernelBuilder> & iBuilder) override;
138    void generateFinalBlockMethod(const std::unique_ptr<KernelBuilder> & iBuilder, llvm::Value * remainingBytes) override;
139private:
140    const unsigned mBitStreamCount;
141    const unsigned mFieldWidth;
142    const unsigned mSwizzleFactor;
143    const unsigned mSwizzleSetCount;
144};
145
146   
147}
148   
149#endif
150
Note: See TracBrowser for help on using the repository browser.