source: icGREP/icgrep-devel/icgrep/base64.cpp @ 6237

Last change on this file since 6237 was 6209, checked in by nmedfort, 8 months ago

Initial cache janitor daemon test

File size: 3.2 KB
Line 
1/*
2 *  Copyright (c) 2016 International Characters.
3 *  This software is licensed to the public under the Open Software License 3.0.
4 *  icgrep is a trademark of International Characters.
5 */
6
7#include <iostream>
8#include <llvm/IR/Function.h>
9#include <llvm/IR/Module.h>
10#include <llvm/ExecutionEngine/ExecutionEngine.h>
11#include <llvm/IR/Verifier.h>
12#include <llvm/Support/CommandLine.h>
13#include <toolchain/toolchain.h>
14#include <toolchain/cpudriver.h>
15#include <IR_Gen/idisa_target.h>
16#include <kernels/source_kernel.h>
17#include <kernels/streamset.h>
18#include <kernels/radix64.h>
19#include <kernels/stdout_kernel.h>
20#include <kernels/kernel_builder.h>
21#include <boost/interprocess/mapped_region.hpp>
22#include <boost/interprocess/anonymous_shared_memory.hpp>
23#include <boost/math/common_factor_rt.hpp>
24#include <sys/stat.h>
25#include <fcntl.h>
26#include <mutex>
27#include <kernels/pipeline_builder.h>
28
29
30using namespace llvm;
31using namespace codegen;
32
33static cl::OptionCategory base64Options("base64 Options",
34                                            "Transcoding control options.");
35
36static cl::list<std::string> inputFiles(cl::Positional, cl::desc("<input file ...>"), cl::OneOrMore, cl::cat(base64Options));
37
38static cl::opt<bool> mMapBuffering("mmap-buffering", cl::desc("Enable mmap buffering."), cl::cat(base64Options));
39static cl::opt<bool> memAlignBuffering("memalign-buffering", cl::desc("Enable posix_memalign buffering."), cl::cat(base64Options));
40static cl::opt<int> Threads("threads", cl::desc("Total number of threads."), cl::init(1));
41
42using namespace kernel;
43
44typedef void (*base64FunctionType)(const uint32_t fd);
45
46base64FunctionType base64PipelineGen(CPUDriver & pxDriver) {
47    auto & iBuilder = pxDriver.getBuilder();
48    Type * const int32Ty = iBuilder->getInt32Ty();
49    auto P = pxDriver.makePipeline({Binding{int32Ty, "fd"}});
50    Scalar * const fileDescriptor = P->getInputScalar("fd");
51    StreamSet * const ByteStream = P->CreateStreamSet(1, 8);
52    P->CreateKernelCall<MMapSourceKernel>(fileDescriptor, ByteStream);
53    StreamSet * const Expanded3_4Out = P->CreateStreamSet(1, 8);
54    P->CreateKernelCall<expand3_4Kernel>(ByteStream, Expanded3_4Out);
55    StreamSet * const Radix64out = P->CreateStreamSet(1, 8);
56    P->CreateKernelCall<radix64Kernel>(Expanded3_4Out, Radix64out);
57    StreamSet * const base64 = P->CreateStreamSet(1, 8);
58    P->CreateKernelCall<base64Kernel>(Radix64out, base64);
59    P->CreateKernelCall<StdOutKernel>(base64);
60    return reinterpret_cast<base64FunctionType>(P->compile());
61}
62
63size_t file_size(const int fd) {
64    struct stat st;
65    if (LLVM_UNLIKELY(fstat(fd, &st) != 0)) {
66        st.st_size = 0;
67    }
68    return st.st_size;
69}
70
71void base64(base64FunctionType fn_ptr, const std::string & fileName) {
72    const int fd = open(fileName.c_str(), O_RDONLY);
73    if (LLVM_UNLIKELY(fd == -1)) {
74        std::cerr << "Error: cannot open " << fileName << " for processing. Skipped.\n";
75        return;
76    }
77    fn_ptr(fd);
78    close(fd);
79}
80
81int main(int argc, char *argv[]) {
82    codegen::ParseCommandLineOptions(argc, argv, {&base64Options, codegen::codegen_flags()});
83
84    CPUDriver pxDriver("base64");
85    auto fn_ptr = base64PipelineGen(pxDriver);
86    for (unsigned i = 0; i != inputFiles.size(); ++i) {
87        base64(fn_ptr, inputFiles[i]);
88    }
89    return 0;
90}
91
Note: See TracBrowser for help on using the repository browser.