source: icGREP/icgrep-devel/icgrep/kernels/cc_kernel.cpp @ 6184

Last change on this file since 6184 was 6184, checked in by nmedfort, 7 months ago

Initial version of PipelineKernel? + revised StreamSet? model.

File size: 2.4 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 "cc_kernel.h"
7#include <re/re_cc.h>
8#include <cc/cc_compiler.h>
9#include <kernels/kernel_builder.h>
10#include <llvm/Support/raw_ostream.h>
11
12using namespace cc;
13using namespace kernel;
14using namespace pablo;
15using namespace re;
16using namespace llvm;
17
18// ccNameStr, std::vector<re::CC *>{cc}, ByteStream, ccStream
19
20DirectCharacterClassKernelBuilder::DirectCharacterClassKernelBuilder(
21        const std::unique_ptr<kernel::KernelBuilder> & b, std::string ccSetName, std::vector<re::CC *> charClasses, StreamSet * byteStream, StreamSet * ccStream)
22: PabloKernel(b, ccSetName +"_direct",
23// input
24{Binding{"byteStream", byteStream}},
25// output
26{Binding{"ccStream", ccStream}})
27, mCharClasses(std::move(charClasses)) {
28    if (LLVM_UNLIKELY(ccStream->getNumElements() != mCharClasses.size())) {
29        report_fatal_error("cc streamset must have " + std::to_string(mCharClasses.size()) + " streams");
30    }
31}
32
33void DirectCharacterClassKernelBuilder::generatePabloMethod() {
34    PabloBuilder pb(getEntryScope());
35    cc::Direct_CC_Compiler ccc(getEntryScope(), getInputStreamSet("byteStream")[0]);
36    Var * outputVar = getOutputStreamVar("ccStream");
37    for (unsigned i = 0; i < mCharClasses.size(); ++i) {
38        pb.createAssign(pb.createExtract(outputVar, i), ccc.compileCC(mCharClasses[i]));
39    }
40}
41
42
43ParabixCharacterClassKernelBuilder::ParabixCharacterClassKernelBuilder (const std::unique_ptr<kernel::KernelBuilder> & b, std::string ccSetName, const std::vector<CC *> & charClasses, StreamSet * basisStream, StreamSet * outputStream)
44: PabloKernel(b, ccSetName +"_kernel",
45// stream inputs
46{Binding{"basis", basisStream}}
47// stream outputs
48, {Binding("outputStream", outputStream)}
49)
50, mCharClasses(charClasses) {
51    if (LLVM_UNLIKELY(outputStream->getNumElements() != mCharClasses.size())) {
52        report_fatal_error("output streamset must have " + std::to_string(mCharClasses.size()) + " streams");
53    }
54}
55
56void ParabixCharacterClassKernelBuilder::generatePabloMethod() {
57    PabloBuilder pb(getEntryScope());
58    cc::Parabix_CC_Compiler ccc(getEntryScope(), getInputStreamSet("basis"));
59    Var * outputVar = getOutputStreamVar("outputStream");
60    for (unsigned i = 0; i < mCharClasses.size(); ++i) {
61        pb.createAssign(pb.createExtract(outputVar, i), ccc.compileCC(mCharClasses[i]));
62    }
63}
Note: See TracBrowser for help on using the repository browser.