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

Last change on this file since 5408 was 5408, checked in by nmedfort, 2 years ago

First attempt to allow Kernels to wait for consumers to finish processing before performing a realloc.

File size: 2.0 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
6#include "grep_kernel.h"
7#include <boost/uuid/sha1.hpp>
8#include <re/printer_re.h>
9#include <re/re_toolchain.h>
10#include <pablo/pablo_toolchain.h>
11
12using namespace kernel;
13using namespace pablo;
14using namespace re;
15using namespace llvm;
16
17inline static std::string sha1sum(const std::string & str) {
18    char buffer[41];    // 40 hex-digits and the terminating null
19    uint32_t digest[5]; // 160 bits in total
20    boost::uuids::detail::sha1 sha1;
21    sha1.process_bytes(str.c_str(), str.size());
22    sha1.get_digest(digest);
23    snprintf(buffer, sizeof(buffer), "%.8x%.8x%.8x%.8x%.8x",
24             digest[0], digest[1], digest[2], digest[3], digest[4]);
25    return std::string(buffer);
26}
27
28inline std::string makeSignature(RE * const re_ast, const bool CountOnly) {
29    std::string signature = Printer_RE::PrintRE(re_ast);
30    if (CountOnly) {
31        signature += "-c";
32    }
33    return signature;
34}
35
36ICgrepKernelBuilder::ICgrepKernelBuilder (IDISA::IDISA_Builder * const iBuilder, RE * const re_ast, const bool CountOnly)
37: PabloKernel(iBuilder, "",
38              {Binding{iBuilder->getStreamSetTy(8), "basis"}, Binding{iBuilder->getStreamSetTy(1, 1), "linebreak"}},
39              CountOnly ? std::vector<Binding>{} : std::vector<Binding>{Binding{iBuilder->getStreamSetTy(1, 1), "matches"}},
40              {},
41              CountOnly ? std::vector<Binding>{Binding{iBuilder->getSizeTy(), "matchedLineCount"}} : std::vector<Binding>{})
42, mCountOnly(CountOnly)
43, mRE(re_ast)
44, mSignature(makeSignature(re_ast, CountOnly)) {
45    setName("Parabix:" + sha1sum(mSignature));
46}
47
48std::string ICgrepKernelBuilder::generateKernelSignature(std::string moduleId) {
49    return mSignature;
50}
51
52void ICgrepKernelBuilder::prepareKernel() {
53    re2pablo_compiler(this, regular_expression_passes(mRE), mCountOnly);
54    pablo_function_passes(this);
55    PabloKernel::prepareKernel();
56}
Note: See TracBrowser for help on using the repository browser.