source: icGREP/icgrep-devel/icgrep/lz4/lz4_base_generator.cpp @ 6184

Last change on this file since 6184 was 6184, checked in by nmedfort, 9 months ago

Initial version of PipelineKernel? + revised StreamSet? model.

File size: 5.1 KB
Line 
1
2
3#include "lz4_base_generator.h"
4#include <kernels/lz4/lz4_block_decoder.h>
5#include <kernels/kernel_builder.h>
6#include <kernels/source_kernel.h>
7#include <kernels/s2p_kernel.h>
8#include <kernels/p2s_kernel.h>
9#include <kernels/swizzle.h>
10#include <kernels/lz4/twist_kernel.h>
11#include <kernels/lz4/untwist_kernel.h>
12#include <kernels/lz4/decompression/lz4_bytestream_decompression.h>
13#include <kernels/lz4/decompression/lz4_swizzled_decompression.h>
14#include <kernels/lz4/decompression/lz4_twist_decompression.h>
15#include <kernels/lz4/decompression/lz4_bitstream_decompression.h>
16#include <kernels/pipeline_builder.h>
17
18using namespace llvm;
19using namespace kernel;
20
21LZ4BaseGenerator::LZ4BaseGenerator()
22: mPxDriver("lz4")
23, mLz4BlockSize(4 * 1024 * 1024) {
24
25}
26
27StreamSet* LZ4BaseGenerator::loadByteStream() {
28    StreamSet * const byteStream = mPipeline->CreateStreamSet(1, 8);
29    mPipeline->CreateKernelCall<MemorySourceKernel>(mInputStream, mFileSize, byteStream);
30    return byteStream;
31}
32
33StreamSet* LZ4BaseGenerator::s2p(StreamSet* byteStream) {
34    StreamSet * const basisBits = mPipeline->CreateStreamSet(8, 1);
35    mPipeline->CreateKernelCall<S2PKernel>(byteStream, basisBits, cc::BitNumbering::BigEndian);
36    return basisBits;
37}
38
39StreamSet* LZ4BaseGenerator::p2s(StreamSet* bitStream) {
40    StreamSet * const byteStream = mPipeline->CreateStreamSet(1, 8);
41    mPipeline->CreateKernelCall<P2SKernel>(bitStream, byteStream, cc::BitNumbering::BigEndian);
42    return byteStream;
43}
44
45std::pair<StreamSet*, StreamSet*>  LZ4BaseGenerator::loadByteStreamAndBitStream() {
46    StreamSet * const byteStream = loadByteStream();
47    StreamSet * const basisBits = s2p(byteStream);
48    return std::make_pair(byteStream, basisBits);
49}
50
51LZ4BlockInfo LZ4BaseGenerator::getBlockInfo(StreamSet* compressedByteStream) {
52    if (mBlockInfo.isCompress) {
53        return mBlockInfo;
54    }
55
56    mBlockInfo.isCompress =  mPipeline->CreateStreamSet(1, 8);
57    mBlockInfo.blockStart = mPipeline->CreateStreamSet(1, 64);
58    mBlockInfo.blockEnd = mPipeline->CreateStreamSet(1, 64);
59
60    mPipeline->CreateKernelCall<LZ4BlockDecoderKernel>(
61                // arguments
62                mHasBlockChecksum, mHeaderSize, mFileSize,
63                // inputs
64                compressedByteStream,
65                // outputs
66                mBlockInfo.isCompress,
67                mBlockInfo.blockStart,
68                mBlockInfo.blockEnd);
69
70    return mBlockInfo;
71}
72
73StreamSet * LZ4BaseGenerator::byteStreamDecompression(StreamSet* compressedByteStream) {
74    LZ4BlockInfo blockInfo = getBlockInfo(compressedByteStream);
75    StreamSet * const decompressionByteStream = mPipeline->CreateStreamSet(1, 8);
76    mPipeline->CreateKernelCall<LZ4ByteStreamDecompressionKernel>(mFileSize, compressedByteStream, blockInfo, nullptr, decompressionByteStream );
77    return decompressionByteStream;
78}
79
80StreamSet * LZ4BaseGenerator::swizzledDecompression(StreamSet* compressedByteStream, StreamSet* compressedBasisBits) {
81    LZ4BlockInfo blockInfo = getBlockInfo(compressedByteStream);
82
83    // Produce unswizzled bit streams
84    StreamSet * const u16Swizzle0 = mPipeline->CreateStreamSet(4);
85    StreamSet * const u16Swizzle1 = mPipeline->CreateStreamSet(4);
86    mPipeline->CreateKernelCall<SwizzleGenerator>(StreamSets{compressedBasisBits}, StreamSets{u16Swizzle0, u16Swizzle1});
87
88    StreamSet * const uncompressedSwizzled0 = mPipeline->CreateStreamSet(4);
89    StreamSet * const uncompressedSwizzled1 = mPipeline->CreateStreamSet(4);
90
91    mPipeline->CreateKernelCall<LZ4SwizzledDecompressionKernel>(
92        mFileSize,
93        // inputs
94        compressedByteStream, blockInfo,
95        StreamSets{ u16Swizzle0, u16Swizzle1 },
96        // outputs
97        StreamSets{ uncompressedSwizzled0, uncompressedSwizzled1 } );
98
99    StreamSet * const decompressionBitStream = mPipeline->CreateStreamSet(8);
100
101    mPipeline->CreateKernelCall<SwizzleGenerator>(StreamSets{uncompressedSwizzled0, uncompressedSwizzled1}, StreamSets{decompressionBitStream});
102
103    return decompressionBitStream;
104}
105
106StreamSet * LZ4BaseGenerator::bitStreamDecompression(StreamSet* compressedByteStream, StreamSet * compressedBasisBits) {
107    return convertCompressedBitsStreamWithBitStreamAioApproach(compressedByteStream, {compressedBasisBits})[0];
108}
109
110StreamSets LZ4BaseGenerator::convertCompressedBitsStreamWithBitStreamAioApproach(StreamSet * compressedByteStream, StreamSets compressedBitStreams) {
111    LZ4BlockInfo blockInfo = getBlockInfo(compressedByteStream);
112    StreamSets outputStreams;
113    outputStreams.reserve(compressedBitStreams.size());
114    for (const auto & bitStream : compressedBitStreams) {
115        outputStreams.push_back(mPipeline->CreateStreamSet(bitStream->getNumElements(), bitStream->getFieldWidth()));
116    }
117    mPipeline->CreateKernelCall<LZ4BitStreamDecompressionKernel>(mFileSize, compressedByteStream, blockInfo, compressedBitStreams, outputStreams);
118    return outputStreams;
119}
120
121unsigned LZ4BaseGenerator::getBlockSizeBufferBlocks() {
122    return mLz4BlockSize / codegen::BlockSize;
123}
124
125unsigned LZ4BaseGenerator::getDefaultBufferBlocks() {
126    return getBlockSizeBufferBlocks() * 2; // buffer 2 LZ4 Block By Default
127}
128
129LZ4BaseGenerator::~LZ4BaseGenerator() {
130
131}
Note: See TracBrowser for help on using the repository browser.