source: icGREP/icgrep-devel/icgrep/lzparabix/LZParabixCompressorGenerator.cpp @ 6114

Last change on this file since 6114 was 6114, checked in by xwa163, 13 months ago

Init check in for new compression format (lzparabix) related kernels and pipelines, including compressor, decoder and grep

File size: 3.5 KB
Line 
1//
2// Created by wxy325 on 2018/6/24.
3//
4
5#include "LZParabixCompressorGenerator.h"
6
7#include <boost/filesystem.hpp>
8#include <boost/iostreams/device/mapped_file.hpp>
9
10
11#include <cc/cc_compiler.h>
12
13#include <kernels/cc_kernel.h>
14#include <kernels/s2p_kernel.h>
15#include <kernels/p2s_kernel.h>
16#include <kernels/source_kernel.h>
17#include <kernels/stdout_kernel.h>
18#include <kernels/kernel_builder.h>
19#include <kernels/lzparabix/LZParabixCompressionKernel.h>
20
21
22namespace re { class CC; }
23
24using namespace llvm;
25using namespace parabix;
26using namespace kernel;
27
28
29LZParabixCompressorGenerator::LZParabixCompressorGenerator(): mPxDriver("lzParabixCompressor"), mLzParabixBlockSize(4 * 1024 * 1024) {
30
31}
32
33CompressorMainFunctionType LZParabixCompressorGenerator::getMainFunc() {
34    return reinterpret_cast<CompressorMainFunctionType>(mPxDriver.getMain());
35}
36
37void LZParabixCompressorGenerator::generatePipeline(const std::string &outputFile) {
38    auto & iBuilder = mPxDriver.getBuilder();
39    this->generateMainFunc(iBuilder);
40
41    this->generateLoadByteStreamAndBitStream(iBuilder);
42
43
44    parabix::StreamSetBuffer* outputStream = mPxDriver.addBuffer<StaticBuffer>(iBuilder, iBuilder->getStreamSetTy(1, 8), this->getInputBufferBlocks(iBuilder));
45    Kernel * compressionKernel = mPxDriver.addKernelInstance<LZParabixCompressionKernel>(iBuilder);
46    compressionKernel->setInitialArguments({mFileSize});
47    mPxDriver.makeKernelCall(compressionKernel, {mCompressedByteStream}, {outputStream});
48
49    // --------------------------------------------------------
50    // End
51    Kernel * outK = mPxDriver.addKernelInstance<FileSink>(iBuilder, 8);
52    outK->setInitialArguments({iBuilder->GetString(outputFile)});
53    mPxDriver.makeKernelCall(outK, {outputStream}, {});
54
55
56    mPxDriver.generatePipelineIR();
57    mPxDriver.deallocateBuffers();
58
59    iBuilder->CreateRetVoid();
60
61    mPxDriver.finalizeObject();
62}
63
64void LZParabixCompressorGenerator::generateLoadByteStreamAndBitStream(
65        const std::unique_ptr<kernel::KernelBuilder> &iBuilder) {
66    mCompressedByteStream = mPxDriver.addBuffer<ExternalBuffer>(iBuilder, iBuilder->getStreamSetTy(1, 8));
67    mCompressedBasisBits = mPxDriver.addBuffer<StaticBuffer>(iBuilder, iBuilder->getStreamSetTy(8, 1), this->getInputBufferBlocks(iBuilder));
68
69    kernel::Kernel * sourceK = mPxDriver.addKernelInstance<MemorySourceKernel>(iBuilder);
70    sourceK->setInitialArguments({mInputStream, mFileSize});
71    mPxDriver.makeKernelCall(sourceK, {}, {mCompressedByteStream});
72//    Kernel * s2pk = mPxDriver.addKernelInstance<S2PKernel>(iBuilder, cc::BitNumbering::LittleEndian);
73//    mPxDriver.makeKernelCall(s2pk, {mCompressedByteStream}, {mCompressedBasisBits});
74
75}
76
77void LZParabixCompressorGenerator::generateMainFunc(const std::unique_ptr<kernel::KernelBuilder> &iBuilder) {
78    Module * M = iBuilder->getModule();
79    Type * const sizeTy = iBuilder->getSizeTy();
80    Type * const voidTy = iBuilder->getVoidTy();
81    Type * const inputType = iBuilder->getInt8PtrTy();
82
83    Function * const main = cast<Function>(M->getOrInsertFunction("Main", voidTy, inputType, sizeTy, nullptr));
84    main->setCallingConv(CallingConv::C);
85    Function::arg_iterator args = main->arg_begin();
86    mInputStream = &*(args++);
87    mInputStream->setName("input");
88
89    mFileSize = &*(args++);
90    mFileSize->setName("mFileSize");
91
92
93    iBuilder->SetInsertPoint(BasicBlock::Create(M->getContext(), "entry", main, 0));
94}
95
96size_t LZParabixCompressorGenerator::getInputBufferBlocks(const std::unique_ptr<kernel::KernelBuilder> &iBuilder) {
97    return mLzParabixBlockSize / codegen::BlockSize * 2;
98}
99
100
101
102
103
104
Note: See TracBrowser for help on using the repository browser.