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

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

PEXTFieldCompressKernel

File size: 5.4 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>
10namespace IDISA { class IDISA_Builder; }
11
12namespace kernel {
13
14//
15// Parallel Prefix Deletion Kernel
16// see Parallel Prefix Compress in Henry S. Warren, Hacker's Delight, Chapter 7
17//
18// Given that we want to delete bits within fields of width fw, moving
19// nondeleted bits to the right, the parallel prefix compress method can
20// be applied.   This requires a preprocessing step to compute log2(fw)
21// masks that can be used to select bits to be moved in each step of the
22// algorithm.
23//
24class DeletionKernel final : public BlockOrientedKernel {
25public:
26    DeletionKernel(const std::unique_ptr<kernel::KernelBuilder> & iBuilder, unsigned fw, unsigned streamCount);
27    bool isCachable() const override { return true; }
28    bool hasSignature() const override { return false; }
29protected:
30    void generateDoBlockMethod(const std::unique_ptr<KernelBuilder> & iBuilder) override;
31    void generateFinalBlockMethod(const std::unique_ptr<KernelBuilder> & iBuilder, llvm::Value * remainingBytes) override;
32private:
33    const unsigned mDeletionFieldWidth;
34    const unsigned mStreamCount;
35};
36
37class FieldCompressKernel final : public MultiBlockKernel {
38public:
39    FieldCompressKernel(const std::unique_ptr<kernel::KernelBuilder> & b, unsigned fw, unsigned streamCount);
40    bool isCachable() const override { return true; }
41    bool hasSignature() const override { return false; }
42protected:
43    void generateMultiBlockLogic(const std::unique_ptr<KernelBuilder> & kb, llvm::Value * const numOfStrides) override;
44private:
45    const unsigned mCompressFieldWidth;
46    const unsigned mStreamCount;
47};
48
49class PEXTFieldCompressKernel final : public MultiBlockKernel {
50public:
51    PEXTFieldCompressKernel(const std::unique_ptr<kernel::KernelBuilder> & b, unsigned fw, unsigned streamCount);
52    bool isCachable() const override { return true; }
53    bool hasSignature() const override { return false; }
54protected:
55    void generateMultiBlockLogic(const std::unique_ptr<KernelBuilder> & kb, llvm::Value * const numOfStrides) override;
56private:
57    const unsigned mPEXTWidth;
58    const unsigned mStreamCount;
59};
60
61//
62//  Given streams that are compreseed within fields, produced fully
63//  compressed streams.
64class StreamCompressKernel final : public MultiBlockKernel {
65public:
66    StreamCompressKernel(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 numOfBlocks) override;
71private:
72    const unsigned mCompressedFieldWidth;
73    const unsigned mStreamCount;
74};
75
76/*
77Input: a set of bitstreams
78Output: swizzles containing the input bitstreams with the specified bits deleted
79*/
80class SwizzledDeleteByPEXTkernel final : public BlockOrientedKernel {
81public:
82    SwizzledDeleteByPEXTkernel(const std::unique_ptr<kernel::KernelBuilder> & b, unsigned streamCount, unsigned PEXT_width = 64);
83    bool isCachable() const override { return true; }
84    bool hasSignature() const override { return false; }
85protected:
86    void generateDoBlockMethod(const std::unique_ptr<KernelBuilder> & b) override;
87    void generateFinalBlockMethod(const std::unique_ptr<KernelBuilder> & b, llvm::Value * remainingBytes) override;
88private:
89    void generateProcessingLoop(const std::unique_ptr<KernelBuilder> & b, llvm::Value * delMask, const bool flush);
90    std::vector<std::vector<llvm::Value *>> makeSwizzleSets(const std::unique_ptr<KernelBuilder> & b, llvm::Value * delMask);
91private:
92    const unsigned mStreamCount;
93    const unsigned mSwizzleFactor;
94    const unsigned mSwizzleSetCount;
95    const unsigned mPEXTWidth;
96};
97
98class DeleteByPEXTkernel final : public BlockOrientedKernel {
99public:
100    DeleteByPEXTkernel(const std::unique_ptr<kernel::KernelBuilder> & iBuilder, unsigned fw, unsigned streamCount, unsigned PEXT_width = 64);
101    bool isCachable() const override { return true; }
102    bool hasSignature() const override { return false; }
103protected:
104    void generateDoBlockMethod(const std::unique_ptr<KernelBuilder> & iBuilder) override;
105    void generateFinalBlockMethod(const std::unique_ptr<KernelBuilder> & iBuilder, llvm::Value * remainingBytes) override;
106    void generateProcessingLoop(const std::unique_ptr<KernelBuilder> & iBuilder, llvm::Value * delMask);
107private:
108    const unsigned mDelCountFieldWidth;
109    const unsigned mStreamCount;
110    const unsigned mSwizzleFactor;
111    const unsigned mPEXTWidth;
112};
113   
114class SwizzledBitstreamCompressByCount final : public BlockOrientedKernel {
115public:
116    SwizzledBitstreamCompressByCount(const std::unique_ptr<kernel::KernelBuilder> & iBuilder, unsigned bitStreamCount, unsigned fieldWidth = 64);
117    bool isCachable() const override { return true; }
118    bool hasSignature() const override { return false; }
119protected:
120    void generateDoBlockMethod(const std::unique_ptr<KernelBuilder> & iBuilder) override;
121    void generateFinalBlockMethod(const std::unique_ptr<KernelBuilder> & iBuilder, llvm::Value * remainingBytes) override;
122private:
123    const unsigned mBitStreamCount;
124    const unsigned mFieldWidth;
125    const unsigned mSwizzleFactor;
126    const unsigned mSwizzleSetCount;
127};
128
129   
130}
131   
132#endif
133
Note: See TracBrowser for help on using the repository browser.