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

Last change on this file since 5611 was 5540, checked in by cameron, 2 years ago

Integrated AVX deletion kernel

File size: 4.9 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
12//
13// Parallel Prefix Deletion
14// see Parallel Prefix Compress in Henry S. Warren, Hacker's Delight, Chapter 7
15//
16// Given that we want to delete bits within fields of width fw, moving
17// nondeleted bits to the right, the parallel prefix compress method can
18// be applied.   This requires a preprocessing step to compute log2(fw)
19// masks that can be used to select bits to be moved in each step of the
20// algorithm.
21//
22
23namespace kernel {
24
25/*
26Input: a set of bitstreams
27Output: swizzles containing the input bitstreams with the specified bits deleted
28*/
29class SwizzledDeleteByPEXTkernel final : public BlockOrientedKernel {
30public:
31    SwizzledDeleteByPEXTkernel(const std::unique_ptr<kernel::KernelBuilder> & iBuilder, unsigned fw, unsigned streamCount, unsigned PEXT_width = 64);
32    bool isCachable() const override { return true; }
33    bool hasSignature() const override { return false; }
34protected:
35    void generateDoBlockMethod(const std::unique_ptr<KernelBuilder> & iBuilder) override;
36    void generateFinalBlockMethod(const std::unique_ptr<KernelBuilder> & iBuilder, llvm::Value * remainingBytes) override;
37    std::vector<llvm::Value *> get_PEXT_masks(const std::unique_ptr<KernelBuilder> & iBuilder, llvm::Value * del_mask);
38    void generateProcessingLoop(const std::unique_ptr<KernelBuilder> & iBuilder, const std::vector<llvm::Value *> & masks, 
39                                llvm::Value * delMask);
40    void generatePEXTAndSwizzleLoop(const std::unique_ptr<KernelBuilder> & iBuilder, const std::vector<llvm::Value *> & masks, std::vector<llvm::Value *> counts);
41    std::vector<llvm::Value *> apply_PEXT_deletion_with_swizzle(const std::unique_ptr<KernelBuilder> & iBuilder, 
42                                                                const std::vector<llvm::Value *> & masks, std::vector<llvm::Value *> strms);
43    llvm::Value * apply_PEXT_deletion(const std::unique_ptr<KernelBuilder> & iBuilder, const std::vector<llvm::Value *> & masks,
44                                      llvm::Value * strm);
45private:
46    const unsigned mDelCountFieldWidth;
47    const unsigned mStreamCount;
48    const unsigned mSwizzleFactor;
49    const unsigned mSwizzleSetCount;
50    const unsigned mPEXTWidth;
51    static constexpr const char* mOutputSwizzleNameBase = "outputStreamSet";
52};
53
54class DeletionKernel final : public BlockOrientedKernel {
55public:
56    DeletionKernel(const std::unique_ptr<kernel::KernelBuilder> & iBuilder, unsigned fw, unsigned streamCount);
57    bool isCachable() const override { return true; }
58    bool hasSignature() const override { return false; }
59protected:
60    void generateDoBlockMethod(const std::unique_ptr<KernelBuilder> & iBuilder) override;
61    void generateFinalBlockMethod(const std::unique_ptr<KernelBuilder> & iBuilder, llvm::Value * remainingBytes) override;
62private:
63    const unsigned mDeletionFieldWidth;
64    const unsigned mStreamCount;
65};
66
67class DeleteByPEXTkernel final : public BlockOrientedKernel {
68public:
69    DeleteByPEXTkernel(const std::unique_ptr<kernel::KernelBuilder> & iBuilder, unsigned fw, unsigned streamCount, bool shouldSwizzle);
70    bool isCachable() const override { return true; }
71    bool hasSignature() const override { return false; }
72protected:
73    void generateDoBlockMethod(const std::unique_ptr<KernelBuilder> & iBuilder) override;
74    void generateFinalBlockMethod(const std::unique_ptr<KernelBuilder> & iBuilder, llvm::Value * remainingBytes) override;
75    void generatePEXTAndSwizzleLoop(const std::unique_ptr<KernelBuilder> & iBuilder, const std::vector<llvm::Value *> & masks);
76    void generatePEXTLoop(const std::unique_ptr<KernelBuilder> & iBuilder, const std::vector<llvm::Value *> & masks);
77    void generateProcessingLoop(const std::unique_ptr<KernelBuilder> & iBuilder, const std::vector<llvm::Value *> & masks, llvm::Value * delMask);
78private:
79    const unsigned mDelCountFieldWidth;
80    const unsigned mStreamCount;
81    const unsigned mSwizzleFactor;
82    const bool mShouldSwizzle;
83    static constexpr const char* mOutputSwizzleNameBase = "outputStreamSet";
84};
85   
86class SwizzledBitstreamCompressByCount final : public BlockOrientedKernel {
87public:
88    SwizzledBitstreamCompressByCount(const std::unique_ptr<kernel::KernelBuilder> & iBuilder, unsigned bitStreamCount, unsigned fieldWidth = 64);
89    bool isCachable() const override { return true; }
90    bool hasSignature() const override { return false; }
91protected:
92    void generateDoBlockMethod(const std::unique_ptr<KernelBuilder> & iBuilder) override;
93    void generateFinalBlockMethod(const std::unique_ptr<KernelBuilder> & iBuilder, llvm::Value * remainingBytes) override;
94private:
95    const unsigned mBitStreamCount;
96    const unsigned mFieldWidth;
97    const unsigned mSwizzleFactor;
98    const unsigned mSwizzleSetCount;
99};
100
101   
102}
103   
104#endif
105
Note: See TracBrowser for help on using the repository browser.