Ignore:
Timestamp:
Nov 2, 2018, 7:18:31 PM (10 months ago)
Author:
nmedfort
Message:

Initial version of PipelineKernel? + revised StreamSet? model.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/lz4/lz4_decompression_generator.cpp

    r6137 r6184  
    66#include <boost/iostreams/device/mapped_file.hpp>
    77#include <kernels/kernel_builder.h>
    8 #include <kernels/p2s_kernel.h>
    98#include <kernels/stdout_kernel.h>
    10 
    11 
     9#include <kernels/pipeline_builder.h>
    1210#include <llvm/Support/raw_ostream.h>
    1311
     
    1513
    1614using namespace llvm;
    17 using namespace parabix;
    1815using namespace kernel;
    1916
    20 LZ4DecompressionGenerator::LZ4DecompressionGenerator():LZ4BaseGenerator() {
     17LZ4DecompressionGenerator::LZ4DecompressionGenerator()
     18: LZ4BaseGenerator() {
     19    mPipeline = std::move(makeInternalPipeline());
     20}
     21
     22inline std::unique_ptr<kernel::PipelineBuilder> LZ4DecompressionGenerator::makeInternalPipeline() {
     23    Bindings inputs;
     24
     25    auto & b = mPxDriver.getBuilder();
     26
     27    Type * const int8PtrTy = b->getInt8PtrTy();
     28    Type * const sizeTy = b->getSizeTy();
     29    Type * const boolTy = b->getIntNTy(sizeof(bool) * 8);
     30
     31    inputs.emplace_back(int8PtrTy, "input");
     32    inputs.emplace_back(sizeTy, "headerSize");
     33    inputs.emplace_back(sizeTy, "fileSize");
     34    inputs.emplace_back(boolTy, "hasBlockChecksum");
     35    inputs.emplace_back(int8PtrTy, "outputFile");
     36
     37    return mPxDriver.makePipeline(inputs, Bindings{});
    2138}
    2239
     
    3956    boost::iostreams::mapped_file_source mappedFile;
    4057    mappedFile.open(inputFileName, lz4Frame.getBlocksLength() + lz4Frame.getBlocksStart());
    41     char *fileBuffer = const_cast<char *>(mappedFile.data());
     58    char * fileBuffer = const_cast<char *>(mappedFile.data());
    4259
    43     this->generateDecompressionPipeline(outputFileName);
     60    auto main = generateDecompressionPipeline();
    4461
    45     auto main = this->getMainFunc();
    46     main(fileBuffer, lz4Frame.getBlocksStart(), lz4Frame.getBlocksStart() + lz4Frame.getBlocksLength(), lz4Frame.hasBlockChecksum());
     62    main(fileBuffer, lz4Frame.getBlocksStart(), lz4Frame.getBlocksStart() + lz4Frame.getBlocksLength(), lz4Frame.hasBlockChecksum(), outputFileName.c_str());
    4763    mappedFile.close();
    4864    return 0;
    4965}
    5066
    51 
    52 MainFunctionType LZ4DecompressionGenerator::getMainFunc() {
    53     return reinterpret_cast<MainFunctionType>(mPxDriver.getMain());
     67MainFunctionType LZ4DecompressionGenerator::generateDecompressionPipeline() {
     68    StreamSet * compressedByteStream = loadByteStream();
     69    StreamSet * uncompressedByteStream = byteStreamDecompression(compressedByteStream);
     70    Scalar * outputFileName = mPipeline->getInputScalar("outputFile");
     71    mPipeline->CreateKernelCall<FileSink>(outputFileName, uncompressedByteStream);
     72    return reinterpret_cast<MainFunctionType>(mPipeline->compile());
    5473}
    55 
    56 void LZ4DecompressionGenerator::generateDecompressionPipeline(const std::string &outputFile) {
    57     auto & b = mPxDriver.getBuilder();
    58     this->generateMainFunc(b);
    59 
    60 
    61 
    62     StreamSetBuffer* compressedByteStream = this->loadByteStream();
    63     StreamSetBuffer* uncompressedByteStream = this->byteStreamDecompression(compressedByteStream);
    64 
    65     Kernel * outK = mPxDriver.addKernelInstance<FileSink>(b, 8);
    66     outK->setInitialArguments({b->GetString(outputFile)});
    67     mPxDriver.makeKernelCall(outK, {uncompressedByteStream}, {});
    68 
    69     mPxDriver.generatePipelineIR();
    70     mPxDriver.deallocateBuffers();
    71 
    72     b->CreateRetVoid();
    73 
    74     mPxDriver.finalizeObject();
    75 }
    76 
    77 
    78 void LZ4DecompressionGenerator::generateMainFunc(const std::unique_ptr<kernel::KernelBuilder> & iBuilder) {
    79     Module * M = iBuilder->getModule();
    80     Type * const sizeTy = iBuilder->getSizeTy();
    81     Type * const boolTy = iBuilder->getIntNTy(sizeof(bool) * 8);
    82     Type * const voidTy = iBuilder->getVoidTy();
    83     Type * const inputType = iBuilder->getInt8PtrTy();
    84 
    85     Function * const main = cast<Function>(M->getOrInsertFunction("Main", voidTy, inputType, sizeTy, sizeTy, boolTy, nullptr));
    86     main->setCallingConv(CallingConv::C);
    87     Function::arg_iterator args = main->arg_begin();
    88     mInputStream = &*(args++);
    89     mInputStream->setName("input");
    90 
    91     mHeaderSize = &*(args++);
    92     mHeaderSize->setName("mHeaderSize");
    93 
    94     mFileSize = &*(args++);
    95     mFileSize->setName("mFileSize");
    96 
    97     mHasBlockChecksum = &*(args++);
    98     mHasBlockChecksum->setName("mHasBlockChecksum");
    99     // TODO for now, we do not handle blockCheckSum
    100     mHasBlockChecksum = iBuilder->getInt1(false);
    101 
    102     iBuilder->SetInsertPoint(BasicBlock::Create(M->getContext(), "entry", main, 0));
    103 }
Note: See TracChangeset for help on using the changeset viewer.