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

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

Integrated AVX deletion kernel

File size: 4.9 KB
RevLine 
[4981]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
[5071]8#include "kernel.h"
[5362]9#include <llvm/IR/Value.h>
[5002]10namespace IDISA { class IDISA_Builder; }
11
[4981]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
[5202]23namespace kernel {
24
[5540]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
[5431]54class DeletionKernel final : public BlockOrientedKernel {
[5071]55public:
[5436]56    DeletionKernel(const std::unique_ptr<kernel::KernelBuilder> & iBuilder, unsigned fw, unsigned streamCount);
[5431]57    bool isCachable() const override { return true; }
[5464]58    bool hasSignature() const override { return false; }
[5260]59protected:
[5440]60    void generateDoBlockMethod(const std::unique_ptr<KernelBuilder> & iBuilder) override;
61    void generateFinalBlockMethod(const std::unique_ptr<KernelBuilder> & iBuilder, llvm::Value * remainingBytes) override;
[5260]62private:
[5267]63    const unsigned mDeletionFieldWidth;
64    const unsigned mStreamCount;
[5071]65};
[5202]66
[5431]67class DeleteByPEXTkernel final : public BlockOrientedKernel {
[5313]68public:
[5436]69    DeleteByPEXTkernel(const std::unique_ptr<kernel::KernelBuilder> & iBuilder, unsigned fw, unsigned streamCount, bool shouldSwizzle);
[5431]70    bool isCachable() const override { return true; }
[5464]71    bool hasSignature() const override { return false; }
[5313]72protected:
[5440]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);
[5313]78private:
79    const unsigned mDelCountFieldWidth;
80    const unsigned mStreamCount;
[5362]81    const unsigned mSwizzleFactor;
82    const bool mShouldSwizzle;
83    static constexpr const char* mOutputSwizzleNameBase = "outputStreamSet";
[5313]84};
[5355]85   
[5431]86class SwizzledBitstreamCompressByCount final : public BlockOrientedKernel {
[5355]87public:
[5436]88    SwizzledBitstreamCompressByCount(const std::unique_ptr<kernel::KernelBuilder> & iBuilder, unsigned bitStreamCount, unsigned fieldWidth = 64);
[5431]89    bool isCachable() const override { return true; }
[5464]90    bool hasSignature() const override { return false; }
[5355]91protected:
[5440]92    void generateDoBlockMethod(const std::unique_ptr<KernelBuilder> & iBuilder) override;
93    void generateFinalBlockMethod(const std::unique_ptr<KernelBuilder> & iBuilder, llvm::Value * remainingBytes) override;
[5355]94private:
95    const unsigned mBitStreamCount;
96    const unsigned mFieldWidth;
97    const unsigned mSwizzleFactor;
98    const unsigned mSwizzleSetCount;
99};
100
101   
[5202]102}
[5071]103   
[4981]104#endif
105
Note: See TracBrowser for help on using the repository browser.