source: icGREP/icgrep-devel/icgrep/grep/grep_kernel.h

Last change on this file was 6297, checked in by cameron, 4 months ago

Merge branch 'master' of https://cs-git-research.cs.surrey.sfu.ca/cameron/parabix-devel

File size: 5.7 KB
Line 
1/*
2 *  Copyright (c) 2017 International Characters.
3 *  This software is licensed to the public under the Open Software License 3.0.
4 */
5#ifndef GREP_KERNEL_H
6#define GREP_KERNEL_H
7
8#include <pablo/pablo_kernel.h>  // for PabloKernel
9#include <cc/alphabet.h>
10
11namespace IDISA { class IDISA_Builder; }
12namespace re { class RE; }
13namespace cc { class Alphabet; }
14namespace kernel {
15
16
17class UTF8_nonFinal : public pablo::PabloKernel {
18public:
19    UTF8_nonFinal(const std::unique_ptr<kernel::KernelBuilder> & kb, StreamSet * Source, StreamSet * u8nonFinal);
20    bool isCachable() const override { return true; }
21    bool hasSignature() const override { return false; }
22protected:
23    void generatePabloMethod() override;
24};
25
26class UnicodeLineBreakKernel : public pablo::PabloKernel {
27public:
28    UnicodeLineBreakKernel(const std::unique_ptr<kernel::KernelBuilder> & kb);
29    bool isCachable() const override { return true; }
30    bool hasSignature() const override { return false; }
31protected:
32    void generatePabloMethod() override;
33};
34
35class RequiredStreams_UTF8 : public pablo::PabloKernel {
36public:
37    RequiredStreams_UTF8(const std::unique_ptr<kernel::KernelBuilder> & kb, StreamSet * BasisBits, StreamSet * LineFeedStream, StreamSet * RequiredStreams, StreamSet * UnicodeLB);
38    bool isCachable() const override { return true; }
39    bool hasSignature() const override { return false; }
40protected:
41    void generatePabloMethod() override;
42};
43
44class RequiredStreams_UTF16 : public pablo::PabloKernel {
45public:
46    RequiredStreams_UTF16(const std::unique_ptr<kernel::KernelBuilder> & kb);
47    bool isCachable() const override { return true; }
48    bool hasSignature() const override { return false; }
49protected:
50    void generatePabloMethod() override;
51};
52
53
54class GrepKernelOptions {
55    friend class ICGrepKernel;
56public:
57    using Externals = std::vector<std::pair<std::string, StreamSet *>>;
58    using Alphabets = std::vector<std::pair<std::shared_ptr<cc::Alphabet>, StreamSet *>>;
59    GrepKernelOptions() :
60        mBasisSetNumbering(cc::BitNumbering::LittleEndian),
61        mIndexingAlphabet(&cc::Byte),
62        mPrefixRE(nullptr) {}
63    void setNumbering(cc::BitNumbering numbering);
64    void setIndexingAlphabet(const cc::Alphabet * a);
65    void setSource(StreamSet * s);
66    void setResults(StreamSet * r);
67    void addExternal(std::string name, StreamSet * strm);
68    void addAlphabet(std::shared_ptr<cc::Alphabet> a, StreamSet * basis);
69    void setRE(re::RE * re);
70    void setPrefixRE(re::RE * re);
71
72protected:
73    Bindings streamSetInputBindings();
74    Bindings streamSetOutputBindings();
75    Bindings scalarInputBindings();
76    Bindings scalarOutputBindings();
77    std::string getSignature();
78
79private:
80    cc::BitNumbering mBasisSetNumbering;
81    const cc::Alphabet * mIndexingAlphabet;
82    StreamSet * mSource;
83    StreamSet * mResults;
84    Externals mExternals;
85    Alphabets mAlphabets;
86    re::RE * mRE;
87    re::RE * mPrefixRE;
88    std::string     mSignature;
89};
90
91
92class ICGrepKernel : public pablo::PabloKernel {
93public:
94    ICGrepKernel(const std::unique_ptr<kernel::KernelBuilder> & iBuilder,
95                 std::unique_ptr<GrepKernelOptions> options);
96    std::string makeSignature(const std::unique_ptr<kernel::KernelBuilder> &) override;
97    bool isCachable() const override { return true; }
98    bool hasFamilyName() const override { return true; }
99protected:
100    void generatePabloMethod() override;
101    std::unique_ptr<GrepKernelOptions> mOptions;
102};
103
104struct ByteBitGrepSignature {
105    ByteBitGrepSignature(re::RE * prefix, re::RE * suffix);
106protected:
107    re::RE * const  mPrefixRE;
108    re::RE * const  mSuffixRE;
109    std::string     mSignature;
110};
111
112
113class ByteBitGrepKernel : public ByteBitGrepSignature, public pablo::PabloKernel {
114    using Externals = std::vector<std::pair<std::string, StreamSet *>>;
115public:
116    ByteBitGrepKernel(const std::unique_ptr<kernel::KernelBuilder> & iBuilder, re::RE * const prefix, re::RE * const suffix, StreamSet * const Source, StreamSet * const MatchResults,
117                      const Externals externals = {});
118    std::string makeSignature(const std::unique_ptr<kernel::KernelBuilder> &) override;
119    bool isCachable() const override { return true; }
120    bool hasFamilyName() const override { return true; }
121private:
122    static Bindings makeInputBindings(StreamSet * const source, const Externals & externals);
123protected:
124    void generatePabloMethod() override;
125};
126
127class MatchedLinesKernel : public pablo::PabloKernel {
128public:
129    MatchedLinesKernel(const std::unique_ptr<kernel::KernelBuilder> & builder, StreamSet * OriginalMatches, StreamSet * LineBreakStream, StreamSet * Matches);
130    bool isCachable() const override { return true; }
131    bool hasSignature() const override { return false; }
132protected:
133    void generatePabloMethod() override;
134};
135
136class InvertMatchesKernel : public BlockOrientedKernel {
137public:
138    InvertMatchesKernel(const std::unique_ptr<kernel::KernelBuilder> & b, StreamSet * OriginalMatches, StreamSet * LineBreakStream, StreamSet * Matches);
139private:
140    void generateDoBlockMethod(const std::unique_ptr<kernel::KernelBuilder> & iBuilder) override;
141};
142
143class PopcountKernel : public pablo::PabloKernel {
144public:
145    PopcountKernel(const std::unique_ptr<kernel::KernelBuilder> & builder, StreamSet * const toCount, Scalar * countResult);
146    bool isCachable() const override { return true; }
147    bool hasSignature() const override { return false; }
148protected:
149    void generatePabloMethod() override;
150};
151
152class AbortOnNull final : public MultiBlockKernel {
153public:
154    AbortOnNull(const std::unique_ptr<kernel::KernelBuilder> &, StreamSet * const InputStream, StreamSet * const OutputStream, Scalar * callbackObject);
155private:
156    void generateMultiBlockLogic(const std::unique_ptr<KernelBuilder> & b, llvm::Value * const numOfStrides) final;
157
158};
159
160}
161#endif
Note: See TracBrowser for help on using the repository browser.