source: icGREP/icgrep-devel/icgrep/kernels/grep_kernel.cpp @ 5902

Last change on this file since 5902 was 5902, checked in by cameron, 19 months ago

Initial deployment of bytegrep kernel in icgrep

File size: 19.2 KB
Line 
1/*
2 *  Copyright (c) 2018 International Characters.
3 *  This software is licensed to the public under the Open Software License 3.0.
4 */
5
6#include "grep_kernel.h"
7#include <boost/uuid/sha1.hpp>
8#include <re/printer_re.h>
9#include <re/re_cc.h>
10#include <re/re_name.h>
11#include <re/re_toolchain.h>
12#include <re/re_reverse.h>
13#include <pablo/codegenstate.h>
14#include <pablo/pablo_toolchain.h>
15#include <kernels/kernel_builder.h>
16#include <pablo/builder.hpp>
17#include <pablo/pe_ones.h>          // for Ones
18#include <pablo/pe_var.h>           // for Var
19#include <pablo/pe_zeroes.h>        // for Zeroes
20#include <pablo/boolean.h>
21#include <pablo/pe_count.h>
22#include <pablo/pe_matchstar.h>
23#include <pablo/pe_pack.h>
24#include <cc/cc_compiler.h>         // for CC_Compiler
25#include <cc/alphabet.h>
26#include <cc/multiplex_CCs.h>
27#include <re/re_compiler.h>
28#include <UCD/ucd_compiler.hpp>
29#include <llvm/Support/raw_ostream.h>
30
31using namespace kernel;
32using namespace pablo;
33using namespace re;
34using namespace llvm;
35
36inline static std::string sha1sum(const std::string & str) {
37    char buffer[41];    // 40 hex-digits and the terminating null
38    uint32_t digest[5]; // 160 bits in total
39    boost::uuids::detail::sha1 sha1;
40    sha1.process_bytes(str.c_str(), str.size());
41    sha1.get_digest(digest);
42    snprintf(buffer, sizeof(buffer), "%.8x%.8x%.8x%.8x%.8x",
43             digest[0], digest[1], digest[2], digest[3], digest[4]);
44    return std::string(buffer);
45}
46
47
48UnicodeLineBreakKernel::UnicodeLineBreakKernel(const std::unique_ptr<kernel::KernelBuilder> & kb)
49: PabloKernel(kb,
50              "UTF8_LB",
51              {Binding{kb->getStreamSetTy(8), "basis"}, Binding{kb->getStreamSetTy(1), "lf", FixedRate(), LookAhead(1)}},
52              {Binding{kb->getStreamSetTy(1, 1), "UTF8_LB", FixedRate()}}) {
53}
54
55void UnicodeLineBreakKernel::generatePabloMethod() {
56        PabloBuilder pb(getEntryScope());
57        cc::Parabix_CC_Compiler ccc(getEntryScope(), getInputStreamSet("basis"));
58        UCD::UCDCompiler ucdCompiler(ccc);
59   
60    Name * breakChars = re::makeName("breakChars", makeCC(makeCC(makeCC(0x0A, 0x0D), makeCC(0x85)), makeCC(0x2028,0x2029)));
61    UCD::UCDCompiler::NameMap nameMap;
62    nameMap.emplace(breakChars, nullptr);
63    ucdCompiler.generateWithDefaultIfHierarchy(nameMap, pb);
64    auto f = nameMap.find(breakChars);
65    if (f == nameMap.end()) llvm::report_fatal_error("UnicodeLineBreakKernel compilation failure");
66    PabloAST * breakStream = f-> second;
67    PabloAST * const LF = pb.createExtract(getInput(1), pb.getInteger(0), "LF");
68    PabloAST * const CR = ccc.compileCC(makeByte(0x0D));
69    Var * const CR_before_LF = pb.createVar("CR_before_LFCR_before_LF", pb.createZeroes());
70    auto crb = pb.createScope();
71    pb.createIf(CR, crb);
72    PabloAST * const lookaheadLF = crb.createLookahead(LF, 1, "lookaheadLF");
73    crb.createAssign(CR_before_LF, crb.createAnd(CR, lookaheadLF));
74    breakStream = pb.createXor(breakStream, CR_before_LF);  // Remove CR_before_LF from breakStream
75    Var * const UTF8_LB = getOutputStreamVar("UTF8_LB");
76    pb.createAssign(pb.createExtract(UTF8_LB, pb.getInteger(0)), breakStream);
77}
78
79void RequiredStreams_UTF8::generatePabloMethod() {
80    PabloBuilder pb(getEntryScope());
81    cc::Parabix_CC_Compiler ccc(getEntryScope(), getInputStreamSet("basis"));
82   
83    PabloAST * const LF = pb.createExtract(getInput(1), pb.getInteger(0), "LF");
84    PabloAST * const CR = ccc.compileCC(makeByte(0x0D));
85    PabloAST * const LF_VT_FF_CR = ccc.compileCC("LF,VT,FF,CR", makeByte(0x0A, 0x0D), pb);
86    Var * const LineBreak = pb.createVar("LineBreak", LF_VT_FF_CR);
87   
88    // Remove the CR of any CR+LF
89    Var * const CRLF = pb.createVar("CRLF", pb.createZeroes());
90    auto crb = pb.createScope();
91    pb.createIf(CR, crb);
92    PabloAST * const lookaheadLF = crb.createLookahead(LF, 1, "lookaheadLF");
93    PabloAST * const crlf = crb.createAnd(CR, lookaheadLF);
94    crb.createAssign(CRLF, crlf);
95    PabloAST * removedCRLF = crb.createAnd(LineBreak, crb.createNot(CRLF));
96    crb.createAssign(LineBreak, removedCRLF);
97
98   
99    Zeroes * const ZEROES = pb.createZeroes();
100    PabloAST * const u8pfx = ccc.compileCC(makeByte(0xC0, 0xFF));
101
102
103    Var * const nonFinal = pb.createVar("nonFinal", u8pfx);
104    Var * const u8invalid = pb.createVar("u8invalid", ZEROES);
105    Var * const valid_pfx = pb.createVar("valid_pfx", u8pfx);
106
107    auto it = pb.createScope();
108    pb.createIf(u8pfx, it);
109    PabloAST * const u8pfx2 = ccc.compileCC(makeByte(0xC2, 0xDF), it);
110    PabloAST * const u8pfx3 = ccc.compileCC(makeByte(0xE0, 0xEF), it);
111    PabloAST * const u8pfx4 = ccc.compileCC(makeByte(0xF0, 0xF4), it);
112    PabloAST * const u8suffix = ccc.compileCC("u8suffix", makeByte(0x80, 0xBF), it);
113   
114    //
115    // Two-byte sequences
116    Var * const anyscope = it.createVar("anyscope", ZEROES);
117    auto it2 = it.createScope();
118    it.createIf(u8pfx2, it2);
119    it2.createAssign(anyscope, it2.createAdvance(u8pfx2, 1));
120    PabloAST * NEL = it2.createAnd(it2.createAdvance(ccc.compileCC(makeByte(0xC2), it2), 1), ccc.compileCC(makeByte(0x85), it2), "NEL");
121    it2.createAssign(LineBreak, it2.createOr(LineBreak, NEL));
122
123
124    //
125    // Three-byte sequences   
126    Var * const EF_invalid = it.createVar("EF_invalid", ZEROES);
127    auto it3 = it.createScope();
128    it.createIf(u8pfx3, it3);
129    PabloAST * const u8scope32 = it3.createAdvance(u8pfx3, 1);
130    it3.createAssign(nonFinal, it3.createOr(nonFinal, u8scope32));
131    PabloAST * const u8scope33 = it3.createAdvance(u8pfx3, 2);
132    PabloAST * const u8scope3X = it3.createOr(u8scope32, u8scope33);
133    it3.createAssign(anyscope, it3.createOr(anyscope, u8scope3X));
134    PabloAST * const E0_invalid = it3.createAnd(it3.createAdvance(ccc.compileCC(makeByte(0xE0), it3), 1), ccc.compileCC(makeByte(0x80, 0x9F), it3));
135    PabloAST * const ED_invalid = it3.createAnd(it3.createAdvance(ccc.compileCC(makeByte(0xED), it3), 1), ccc.compileCC(makeByte(0xA0, 0xBF), it3));
136    PabloAST * const EX_invalid = it3.createOr(E0_invalid, ED_invalid);
137    it3.createAssign(EF_invalid, EX_invalid);
138    PabloAST * E2_80 = it3.createAnd(it3.createAdvance(ccc.compileCC(makeByte(0xE2), it3), 1), ccc.compileCC(makeByte(0x80), it3));
139    PabloAST * LS_PS = it3.createAnd(it3.createAdvance(E2_80, 1), ccc.compileCC(makeByte(0xA8,0xA9), it3), "LS_PS");
140    it3.createAssign(LineBreak, it3.createOr(LineBreak, LS_PS));
141
142    //
143    // Four-byte sequences
144    auto it4 = it.createScope();
145    it.createIf(u8pfx4, it4);
146    PabloAST * const u8scope42 = it4.createAdvance(u8pfx4, 1, "u8scope42");
147    PabloAST * const u8scope43 = it4.createAdvance(u8scope42, 1, "u8scope43");
148    PabloAST * const u8scope44 = it4.createAdvance(u8scope43, 1, "u8scope44");
149    PabloAST * const u8scope4nonfinal = it4.createOr(u8scope42, u8scope43);
150    it4.createAssign(nonFinal, it4.createOr(nonFinal, u8scope4nonfinal));
151    PabloAST * const u8scope4X = it4.createOr(u8scope4nonfinal, u8scope44);
152    it4.createAssign(anyscope, it4.createOr(anyscope, u8scope4X));
153    PabloAST * const F0_invalid = it4.createAnd(it4.createAdvance(ccc.compileCC(makeByte(0xF0), it4), 1), ccc.compileCC(makeByte(0x80, 0x8F), it4));
154    PabloAST * const F4_invalid = it4.createAnd(it4.createAdvance(ccc.compileCC(makeByte(0xF4), it4), 1), ccc.compileCC(makeByte(0x90, 0xBF), it4));
155    PabloAST * const FX_invalid = it4.createOr(F0_invalid, F4_invalid);
156    it4.createAssign(EF_invalid, it4.createOr(EF_invalid, FX_invalid));
157   
158    //
159    // Invalid cases
160    PabloAST * const legalpfx = it.createOr(it.createOr(u8pfx2, u8pfx3), u8pfx4);
161    //  Any scope that does not have a suffix byte, and any suffix byte that is not in
162    //  a scope is a mismatch, i.e., invalid UTF-8.
163    PabloAST * const mismatch = it.createXor(anyscope, u8suffix);
164    //
165    PabloAST * const pfx_invalid = it.createXor(valid_pfx, legalpfx);
166    it.createAssign(u8invalid, it.createOr(pfx_invalid, it.createOr(mismatch, EF_invalid)));
167    PabloAST * const u8valid = it.createNot(u8invalid, "u8valid");
168    //
169    //
170    it.createAssign(nonFinal, it.createAnd(nonFinal, u8valid));
171    pb.createAssign(nonFinal, pb.createOr(nonFinal, CRLF));
172    //PabloAST * unterminatedLineAtEOF = pb.createAtEOF(pb.createAdvance(pb.createNot(LineBreak), 1), "unterminatedLineAtEOF");
173   
174    Var * const required = getOutputStreamVar("nonFinal");
175    pb.createAssign(pb.createExtract(required, pb.getInteger(0)), nonFinal);
176    pb.createAssign(pb.createExtract(getOutputStreamVar("UnicodeLB"), pb.getInteger(0)), LineBreak);//pb.createOr(LineBreak, unterminatedLineAtEOF, "EOL"));
177}
178
179RequiredStreams_UTF8::RequiredStreams_UTF8(const std::unique_ptr<kernel::KernelBuilder> & kb)
180: PabloKernel(kb, "RequiredStreams_UTF8",
181// input
182{Binding{kb->getStreamSetTy(8), "basis"}, Binding{kb->getStreamSetTy(1), "lf", FixedRate(), LookAhead(1)}},
183// output
184{Binding{kb->getStreamSetTy(1), "nonFinal", FixedRate()},
185 Binding{kb->getStreamSetTy(1), "UnicodeLB", FixedRate()}}) {
186
187}
188
189void RequiredStreams_UTF16::generatePabloMethod() {
190    PabloBuilder pb(getEntryScope());
191    cc::Parabix_CC_Compiler ccc(getEntryScope(), getInputStreamSet("basis"));
192   
193    PabloAST * u16hi_hi_surrogate = ccc.compileCC(makeCC(0xD800, 0xDBFF, &cc::UTF16));    //u16hi_hi_surrogate = [\xD8-\xDB]
194    PabloAST * u16hi_lo_surrogate = ccc.compileCC(makeCC(0xDC00, 0xDFFF, &cc::UTF16));    //u16hi_lo_surrogate = [\xDC-\xDF]
195   
196    PabloAST * invalidTemp = pb.createAdvance(u16hi_hi_surrogate, 1, "InvalidTemp");
197    PabloAST * u16invalid = pb.createXor(invalidTemp, u16hi_lo_surrogate, "u16invalid");
198
199    PabloAST * u16valid = pb.createNot(u16invalid, "u16valid");
200    PabloAST * nonFinal = pb.createAnd(u16hi_hi_surrogate, u16valid, "nonfinal");
201
202    PabloAST * u16single_temp = pb.createOr(ccc.compileCC(makeCC(0x0000, 0xD7FF, &cc::UTF16)), ccc.compileCC(makeCC(0xE000, 0xFFFF, &cc::UTF16)));
203    PabloAST * u16single = pb.createAnd(u16single_temp, pb.createNot(u16invalid));
204
205    PabloAST * const nonFinalCodeUnits = pb.createExtract(getInput(1), pb.getInteger(0));
206    PabloAST * const initial = pb.createOr(u16single, u16hi_hi_surrogate, "initial");
207    PabloAST * const final = pb.createNot(pb.createOr(pb.createOr(u16hi_hi_surrogate, u16invalid), nonFinalCodeUnits), "final");
208
209    Var * const required = getOutputStreamVar("required");
210    pb.createAssign(pb.createExtract(required, pb.getInteger(0)), initial);
211    pb.createAssign(pb.createExtract(required, pb.getInteger(1)), nonFinal);
212    pb.createAssign(pb.createExtract(required, pb.getInteger(2)), final);
213
214}
215
216RequiredStreams_UTF16::RequiredStreams_UTF16(const std::unique_ptr<kernel::KernelBuilder> & kb)
217: PabloKernel(kb, "RequiredStreams_UTF16",               
218// inputs
219{Binding{kb->getStreamSetTy(8), "basis"}},
220// output
221{Binding{kb->getStreamSetTy(3), "required", FixedRate(), Add1()}}) {
222
223}
224
225ICGrepSignature::ICGrepSignature(re::RE * const re_ast)
226: mRE(re_ast)
227, mSignature(Printer_RE::PrintRE(mRE)) {
228   
229}
230
231// Helper to compute stream set inputs to pass into PabloKernel constructor.
232inline std::vector<Binding> icGrepInputs(const std::unique_ptr<kernel::KernelBuilder> & b,
233                                         const std::vector<std::string> & externals,
234                                         const std::vector<cc::Alphabet *> & alphabets) {
235    std::vector<Binding> streamSetInputs = {
236        Binding{b->getStreamSetTy(8), "basis"},
237    };
238    for (auto & e : externals) {
239        streamSetInputs.push_back(Binding{b->getStreamSetTy(1, 1), e});
240    }
241    for (const auto & alphabet : alphabets) {
242        unsigned basis_size = cast<cc::MultiplexedAlphabet>(alphabet)->getMultiplexedCCs().size();
243        streamSetInputs.push_back(Binding{b->getStreamSetTy(basis_size, 1), alphabet->getName() + "_basis"});
244    }
245    return streamSetInputs;
246}
247
248ICGrepKernel::ICGrepKernel(const std::unique_ptr<kernel::KernelBuilder> & b, RE * const re, std::vector<std::string> externals, std::vector<cc::Alphabet *> alphabets)
249: ICGrepSignature(re)
250, PabloKernel(b, "ic" + sha1sum(mSignature),
251// inputs
252icGrepInputs(b, externals, alphabets),
253// output
254{Binding{b->getStreamSetTy(1, 1), "matches", FixedRate(), Add1()}})
255, mExternals(externals)
256, mAlphabets(alphabets) {
257}
258
259std::string ICGrepKernel::makeSignature(const std::unique_ptr<kernel::KernelBuilder> &) {
260    return mSignature;
261}
262
263void ICGrepKernel::generatePabloMethod() {
264    PabloBuilder pb(getEntryScope());
265    cc::Parabix_CC_Compiler ccc(getEntryScope(), getInputStreamSet("basis"));
266    RE_Compiler re_compiler(getEntryScope(), ccc);
267    for (auto & e : mExternals) {
268        re_compiler.addPrecompiled(e, pb.createExtract(getInputStreamVar(e), pb.getInteger(0)));
269    }
270    for (auto a : mAlphabets) {
271        auto mpx_basis = getInputStreamSet(a->getName() + "_basis");
272        re_compiler.addAlphabet(a, mpx_basis);
273    }
274    PabloAST * const matches = re_compiler.compile(mRE);
275    Var * const output = getOutputStreamVar("matches");
276    pb.createAssign(pb.createExtract(output, pb.getInteger(0)), matches);
277}
278
279
280ByteGrepSignature::ByteGrepSignature(RE * re)
281: mRE(re)
282, mSignature(Printer_RE::PrintRE(re) ) {
283}
284
285ByteGrepKernel::ByteGrepKernel(const std::unique_ptr<kernel::KernelBuilder> & b, RE * const re, std::vector<std::string> externals)
286: ByteGrepSignature(re)
287, PabloKernel(b, "bBc" + sha1sum(mSignature),
288              // inputs
289{Binding{b->getStreamSetTy(1, 8), "byteData"}},
290              // output
291{Binding{b->getStreamSetTy(1, 1), "matches", FixedRate(), Add1()}})
292, mExternals(externals) {
293    for (auto & e : externals) {
294        mStreamSetInputs.push_back(Binding{b->getStreamSetTy(1, 1), e});
295    }
296}
297
298std::string ByteGrepKernel::makeSignature(const std::unique_ptr<kernel::KernelBuilder> &) {
299    return mSignature;
300}
301
302
303void ByteGrepKernel::generatePabloMethod() {
304    PabloBuilder pb(getEntryScope());
305    PabloAST * u8bytes = pb.createExtract(getInput(0), pb.getInteger(0));
306    cc::Direct_CC_Compiler dcc(getEntryScope(), u8bytes);
307    RE_Compiler re_byte_compiler(getEntryScope(), dcc);
308    for (auto & e : mExternals) {
309        re_byte_compiler.addPrecompiled(e, pb.createExtract(getInputStreamVar(e), pb.getInteger(0)));
310    }
311    PabloAST * const matches = re_byte_compiler.compile(mRE);
312   
313    Var * const output = getOutputStreamVar("matches");
314    pb.createAssign(pb.createExtract(output, pb.getInteger(0)), matches);
315}
316
317// Helper to compute stream set inputs to pass into PabloKernel constructor.
318inline std::vector<Binding> byteBitGrepInputs(const std::unique_ptr<kernel::KernelBuilder> & b,
319                                              const std::vector<std::string> & externals) {
320    std::vector<Binding> streamSetInputs = {
321        Binding{b->getStreamSetTy(1, 8), "bytedata"},
322    };
323    for (auto & e : externals) {
324        streamSetInputs.push_back(Binding{b->getStreamSetTy(1, 1), e});
325    }
326    return streamSetInputs;
327}
328
329ByteBitGrepSignature::ByteBitGrepSignature(RE * prefix, RE * suffix)
330: mPrefixRE(prefix)
331, mSuffixRE(suffix)
332, mSignature(Printer_RE::PrintRE(mPrefixRE) + Printer_RE::PrintRE(mSuffixRE) ) {
333}
334
335ByteBitGrepKernel::ByteBitGrepKernel(const std::unique_ptr<kernel::KernelBuilder> & b, RE * const prefixRE, RE * const suffixRE, std::vector<std::string> externals)
336: ByteBitGrepSignature(prefixRE, suffixRE)
337, PabloKernel(b, "bBc" + sha1sum(mSignature),
338              // inputs
339              byteBitGrepInputs(b, externals),
340              // output
341{Binding{b->getStreamSetTy(1, 1), "matches", FixedRate(), Add1()}})
342, mExternals(externals) {
343}
344
345std::string ByteBitGrepKernel::makeSignature(const std::unique_ptr<kernel::KernelBuilder> &) {
346    return mSignature;
347}
348
349
350void ByteBitGrepKernel::generatePabloMethod() {
351    PabloBuilder pb(getEntryScope());
352    PabloAST * u8bytes = pb.createExtract(getInput(0), pb.getInteger(0));
353    cc::Direct_CC_Compiler dcc(getEntryScope(), u8bytes);
354    RE_Compiler re_byte_compiler(getEntryScope(), dcc);
355    for (auto & e : mExternals) {
356        re_byte_compiler.addPrecompiled(e, pb.createExtract(getInputStreamVar(e), pb.getInteger(0)));
357    }
358    PabloAST * const prefixMatches = re_byte_compiler.compile(mPrefixRE);
359   
360    PabloBlock * scope1 = getEntryScope()->createScope();
361    pb.createIf(prefixMatches, scope1);
362   
363    PabloAST * nybbles[2];
364    nybbles[0] = scope1->createPackL(scope1->getInteger(8), u8bytes);
365    nybbles[1] = scope1->createPackH(scope1->getInteger(8), u8bytes);
366   
367    PabloAST * bitpairs[4];
368    for (unsigned i = 0; i < 2; i++) {
369        bitpairs[2*i] = scope1->createPackL(scope1->getInteger(4), nybbles[i]);
370        bitpairs[2*i + 1] = scope1->createPackH(scope1->getInteger(4), nybbles[i]);
371    }
372   
373    std::vector<PabloAST *> basis(8);
374    for (unsigned i = 0; i < 4; i++) {
375        basis[7-2*i] = scope1->createPackL(scope1->getInteger(2), bitpairs[i]);
376        basis[7-(2*i + 1)] = scope1->createPackH(scope1->getInteger(2), bitpairs[i]);
377    }
378   
379    cc::Parabix_CC_Compiler ccc(scope1, basis);
380    RE_Compiler re_compiler(scope1, ccc);
381    PabloAST * const matches = re_compiler.compile(mSuffixRE, prefixMatches);
382    Var * const output = getOutputStreamVar("matches");
383    pb.createAssign(pb.createExtract(output, pb.getInteger(0)), matches);
384}
385
386
387
388
389void MatchedLinesKernel::generatePabloMethod() {
390    PabloBuilder pb(getEntryScope());
391    PabloAST * matchResults = pb.createExtract(getInputStreamVar("matchResults"), pb.getInteger(0));
392    PabloAST * lineBreaks = pb.createExtract(getInputStreamVar("lineBreaks"), pb.getInteger(0));
393    PabloAST * notLB = pb.createNot(lineBreaks);
394    PabloAST * match_follow = pb.createMatchStar(matchResults, notLB);
395    PabloAST * unterminatedLineAtEOF = pb.createAtEOF(pb.createAdvance(notLB, 1), "unterminatedLineAtEOF");
396    Var * const matchedLines = getOutputStreamVar("matchedLines");
397    pb.createAssign(pb.createExtract(matchedLines, pb.getInteger(0)), pb.createAnd(match_follow, pb.createOr(lineBreaks, unterminatedLineAtEOF)));
398}
399
400MatchedLinesKernel::MatchedLinesKernel (const std::unique_ptr<kernel::KernelBuilder> & iBuilder)
401: PabloKernel(iBuilder, "MatchedLines",
402// inputs
403{Binding{iBuilder->getStreamSetTy(1), "matchResults"}
404,Binding{iBuilder->getStreamSetTy(1), "lineBreaks"}},
405// output
406{Binding{iBuilder->getStreamSetTy(1), "matchedLines", FixedRate(), Add1()}}) {
407
408}
409
410
411void InvertMatchesKernel::generateDoBlockMethod(const std::unique_ptr<KernelBuilder> & iBuilder) {
412    Value * input = iBuilder->loadInputStreamBlock("matchedLines", iBuilder->getInt32(0));
413    Value * lbs = iBuilder->loadInputStreamBlock("lineBreaks", iBuilder->getInt32(0));
414    Value * inverted = iBuilder->CreateXor(input, lbs);
415    iBuilder->storeOutputStreamBlock("nonMatches", iBuilder->getInt32(0), inverted);
416}
417
418InvertMatchesKernel::InvertMatchesKernel(const std::unique_ptr<kernel::KernelBuilder> & builder)
419: BlockOrientedKernel("Invert",
420// Inputs
421{Binding{builder->getStreamSetTy(1, 1), "matchedLines"}, Binding{builder->getStreamSetTy(1, 1), "lineBreaks"}},
422// Outputs
423{Binding{builder->getStreamSetTy(1, 1), "nonMatches"}},
424// Input/Output Scalars and internal state
425{}, {}, {}) {
426
427}
428
429
430void PopcountKernel::generatePabloMethod() {
431    auto pb = this->getEntryScope();
432    const auto toCount = pb->createExtract(getInputStreamVar("toCount"), pb->getInteger(0));
433    pablo::Var * countResult = getOutputScalarVar("countResult");
434    pb->createAssign(countResult, pb->createCount(toCount));
435}
436
437PopcountKernel::PopcountKernel (const std::unique_ptr<kernel::KernelBuilder> & iBuilder)
438: PabloKernel(iBuilder, "Popcount",
439{Binding{iBuilder->getStreamSetTy(1), "toCount"}},
440{},
441{},
442{Binding{iBuilder->getSizeTy(), "countResult"}}) {
443
444}
Note: See TracBrowser for help on using the repository browser.