source: icGREP/icgrep-devel/icgrep/base64.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: 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
29using namespace llvm;
30using namespace codegen;
31
32static cl::OptionCategory base64Options("base64 Options",
33                                            "Transcoding control options.");
34
35static cl::list<std::string> inputFiles(cl::Positional, cl::desc("<input file ...>"), cl::OneOrMore, cl::cat(base64Options));
36
37static cl::opt<bool> mMapBuffering("mmap-buffering", cl::desc("Enable mmap buffering."), cl::cat(base64Options));
38static cl::opt<bool> memAlignBuffering("memalign-buffering", cl::desc("Enable posix_memalign buffering."), cl::cat(base64Options));
39static cl::opt<int> Threads("threads", cl::desc("Total number of threads."), cl::init(1));
40
41using namespace kernel;
42
43typedef void (*base64FunctionType)(const uint32_t fd);
44
45base64FunctionType base64PipelineGen(CPUDriver & pxDriver) {
46    auto & iBuilder = pxDriver.getBuilder();
47    Type * const int32Ty = iBuilder->getInt32Ty();
48    auto P = pxDriver.makePipeline({Binding{int32Ty, "fd"}});
49    Scalar * const fileDescriptor = P->getInputScalar("fd");
50    StreamSet * const ByteStream = P->CreateStreamSet(1, 8);
51    P->CreateKernelCall<MMapSourceKernel>(fileDescriptor, ByteStream);
52    StreamSet * const Expanded3_4Out = P->CreateStreamSet(1, 8);
53    P->CreateKernelCall<expand3_4Kernel>(ByteStream, Expanded3_4Out);
54    StreamSet * const Radix64out = P->CreateStreamSet(1, 8);
55    P->CreateKernelCall<radix64Kernel>(Expanded3_4Out, Radix64out);
56    StreamSet * const base64 = P->CreateStreamSet(1, 8);
57    P->CreateKernelCall<base64Kernel>(Radix64out, base64);
58    P->CreateKernelCall<StdOutKernel>(base64);
59    return reinterpret_cast<base64FunctionType>(P->compile());
60}
61
62size_t file_size(const int fd) {
63    struct stat st;
64    if (LLVM_UNLIKELY(fstat(fd, &st) != 0)) {
65        st.st_size = 0;
66    }
67    return st.st_size;
68}
69
70void base64(base64FunctionType fn_ptr, const std::string & fileName) {
71    const int fd = open(fileName.c_str(), O_RDONLY);
72    if (LLVM_UNLIKELY(fd == -1)) {
73        std::cerr << "Error: cannot open " << fileName << " for processing. Skipped.\n";
74        return;
75    }
76    fn_ptr(fd);
77    close(fd);   
78}
79
80int main(int argc, char *argv[]) {
81    codegen::ParseCommandLineOptions(argc, argv, {&base64Options, codegen::codegen_flags()});
82
83    CPUDriver pxDriver("base64");
84    auto fn_ptr = base64PipelineGen(pxDriver);
85    for (unsigned i = 0; i != inputFiles.size(); ++i) {
86        base64(fn_ptr, inputFiles[i]);
87    }
88    return 0;
89}
90
Note: See TracBrowser for help on using the repository browser.