source: icGREP/icgrep-devel/icgrep/lzparabix_grep.cpp @ 6133

Last change on this file since 6133 was 6133, checked in by xwa163, 9 months ago
  1. Add sourceCC in multiplexed CC
  2. Remove workaround FakeBasisBits? from ICGrep
  3. Implement Swizzled version of LZParabix
  4. Init checkin for SwizzleByGather? Kernel
File size: 3.2 KB
RevLine 
[6114]1//
2// Created by wxy325 on 2018/6/19.
3//
4
5
6#include <llvm/IR/Module.h>
7#include <llvm/Linker/Linker.h>
8#include <llvm/Support/PrettyStackTrace.h>
9#include <llvm/Support/Signals.h>
10#include <llvm/Support/ManagedStatic.h>
11#include <IR_Gen/idisa_target.h>
12#include <boost/filesystem.hpp>
13#include <boost/iostreams/device/mapped_file.hpp>
14
15#include <cc/cc_compiler.h>
16#include <toolchain/toolchain.h>
17#include <kernels/cc_kernel.h>
18#include <kernels/streamset.h>
19#include <kernels/kernel_builder.h>
20#include <toolchain/cpudriver.h>
[6122]21#include <fstream>
[6114]22#include <iostream>
23
24
25#include <re/re_alt.h>
26#include <re/re_start.h>
27#include <re/re_end.h>
28#include <re/re_utility.h>
29#include <re/re_toolchain.h>
30#include <pablo/pablo_toolchain.h>
31#include <llvm/Support/raw_ostream.h>
32#include <lzparabix/LZParabixGrepGenerator.h>
33
34
35namespace re { class CC; }
36
37using namespace llvm;
38using namespace parabix;
39using namespace kernel;
40
41static cl::OptionCategory lz4GrepFlags("Command Flags", "lz4d options");
42static cl::opt<std::string> regexString(cl::Positional, cl::desc("<regex>"), cl::Required, cl::cat(lz4GrepFlags));
43static cl::opt<std::string> inputFile(cl::Positional, cl::desc("<input file>"), cl::Required, cl::cat(lz4GrepFlags));
44static cl::opt<bool> countOnly("count-only", cl::desc("Only count the match result"), cl::init(false), cl::cat(lz4GrepFlags));
45static cl::opt<bool> enableMultiplexing("enable-multiplexing", cl::desc("Enable CC multiplexing."), cl::init(false), cl::cat(lz4GrepFlags));
[6133]46static cl::opt<bool> swizzledDecompression("swizzled-decompression", cl::desc("Enable Swizzled Decompression."), cl::init(false), cl::cat(lz4GrepFlags));
[6114]47
48static cl::OptionCategory lz4GrepDebugFlags("LZ4 Grep Debug Flags", "lz4d debug options");
49
50
51size_t getFileSize(std::string filename) {
52    std::ifstream f(filename, std::ios::binary | std::ios::ate);
53    if (f.fail()) {
54        return 0;
55    }
56    size_t fileSize = f.tellg();
57    f.close();
58    return fileSize;
59}
60
61
62int main(int argc, char *argv[]) {
63    // This boilerplate provides convenient stack traces and clean LLVM exit
64    // handling. It also initializes the built in support for convenient
65    // command line option handling.
66    sys::PrintStackTraceOnErrorSignal(argv[0]);
67    llvm::PrettyStackTraceProgram X(argc, argv);
68    llvm_shutdown_obj shutdown;
69    codegen::ParseCommandLineOptions(argc, argv, {&lz4GrepFlags, &lz4GrepDebugFlags, codegen::codegen_flags()});
70    std::string fileName = inputFile;
71
72    boost::iostreams::mapped_file_source mappedFile;
73    // Since mmap offset has to be multiples of pages, we can't use it to skip headers.
74    size_t fileSize = getFileSize(fileName);
75    mappedFile.open(fileName , fileSize);
76    //char *fileBuffer = const_cast<char *>(mappedFile.data()) + lz4Frame.getBlocksStart();
77    char *fileBuffer = const_cast<char *>(mappedFile.data());
78    re::RE * re_ast = re::RE_Parser::parse(regexString, re::MULTILINE_MODE_FLAG);
79
[6119]80    LZParabixGrepGenerator g(enableMultiplexing);
[6114]81
[6133]82    g.generateCountOnlyAioPipeline(re_ast, swizzledDecompression);
[6114]83    auto main = g.getCountOnlyGrepMainFunction();
84    uint64_t countResult = main(fileBuffer, 0, fileSize, false);
85    llvm::outs() << countResult << "\n";
86
87
88    mappedFile.close();
89    return 0;
90}
Note: See TracBrowser for help on using the repository browser.