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

Last change on this file was 6241, checked in by nmedfort, 4 months ago

Bug fix for kernel state malloc; minor optimization of pipeline state; grep printing bug fix

File size: 2.9 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 <toolchain/toolchain.h>
8#include <toolchain/cpudriver.h>
9#include <kernels/source_kernel.h>
10#include <kernels/radix64.h>
11#include <kernels/stdout_kernel.h>
12#include <kernels/kernel_builder.h>
13#include <kernels/pipeline_builder.h>
14#include <llvm/Support/CommandLine.h>
15#include <iostream>
16#include <sys/stat.h>
17#include <fcntl.h>
18
19
20using namespace llvm;
21using namespace codegen;
22
23static cl::OptionCategory base64Options("base64 Options",
24                                            "Transcoding control options.");
25
26static cl::list<std::string> inputFiles(cl::Positional, cl::desc("<input file ...>"), cl::OneOrMore, cl::cat(base64Options));
27
28static cl::opt<bool> mMapBuffering("mmap-buffering", cl::desc("Enable mmap buffering."), cl::cat(base64Options));
29static cl::opt<bool> memAlignBuffering("memalign-buffering", cl::desc("Enable posix_memalign buffering."), cl::cat(base64Options));
30static cl::opt<int> Threads("threads", cl::desc("Total number of threads."), cl::init(1));
31
32using namespace kernel;
33
34typedef void (*base64FunctionType)(const uint32_t fd);
35
36base64FunctionType base64PipelineGen(CPUDriver & pxDriver) {
37    auto & iBuilder = pxDriver.getBuilder();
38    Type * const int32Ty = iBuilder->getInt32Ty();
39    auto P = pxDriver.makePipeline({Binding{int32Ty, "fd"}});
40    Scalar * const fileDescriptor = P->getInputScalar("fd");
41    StreamSet * const ByteStream = P->CreateStreamSet(1, 8);
42    P->CreateKernelCall<MMapSourceKernel>(fileDescriptor, ByteStream);
43    StreamSet * const Expanded3_4Out = P->CreateStreamSet(1, 8);
44    P->CreateKernelCall<expand3_4Kernel>(ByteStream, Expanded3_4Out);
45    StreamSet * const Radix64out = P->CreateStreamSet(1, 8);
46    P->CreateKernelCall<radix64Kernel>(Expanded3_4Out, Radix64out);
47    StreamSet * const base64 = P->CreateStreamSet(1, 8);
48    P->CreateKernelCall<base64Kernel>(Radix64out, base64);
49    P->CreateKernelCall<StdOutKernel>(base64);
50    return reinterpret_cast<base64FunctionType>(P->compile());
51}
52
53size_t file_size(const int fd) {
54    struct stat st;
55    if (LLVM_UNLIKELY(fstat(fd, &st) != 0)) {
56        st.st_size = 0;
57    }
58    return st.st_size;
59}
60
61void base64(base64FunctionType fn_ptr, const std::string & fileName) {
62    const int fd = open(fileName.c_str(), O_RDONLY);
63    if (LLVM_UNLIKELY(fd == -1)) {
64        std::cerr << "Error: cannot open " << fileName << " for processing. Skipped.\n";
65        return;
66    }
67    fn_ptr(fd);
68    close(fd);
69}
70
71int main(int argc, char *argv[]) {
72    codegen::ParseCommandLineOptions(argc, argv, {&base64Options, codegen::codegen_flags()});
73
74    CPUDriver pxDriver("base64");
75    auto fn_ptr = base64PipelineGen(pxDriver);
76    for (unsigned i = 0; i != inputFiles.size(); ++i) {
77        base64(fn_ptr, inputFiles[i]);
78    }
79    return 0;
80}
81
Note: See TracBrowser for help on using the repository browser.