Ignore:
Timestamp:
Oct 17, 2017, 8:59:21 AM (20 months ago)
Author:
cameron
Message:

Unified FDsource kernel; filename - now interpreted as stdin

File:
1 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/kernels/source_kernel.cpp

    r5634 r5693  
    331331
    332332ReadSourceKernel::ReadSourceKernel(const std::unique_ptr<kernel::KernelBuilder> & kb, unsigned blocksPerSegment, unsigned codeUnitWidth)
    333 : SegmentOrientedKernel("read_source"
     333: SegmentOrientedKernel("read_source"  + std::to_string(blocksPerSegment) + "@" + std::to_string(codeUnitWidth)
    334334, {}
    335335, {Binding{kb->getStreamSetTy(1, codeUnitWidth), "sourceBuffer"}}
     
    342342}
    343343
     344// Hybrid MMap/Read source kernel
     345   
     346FDSourceKernel::FDSourceKernel(const std::unique_ptr<kernel::KernelBuilder> & kb, unsigned blocksPerSegment, unsigned codeUnitWidth)
     347: SegmentOrientedKernel("FD_source" + std::to_string(blocksPerSegment) + "@" + std::to_string(codeUnitWidth)
     348, {}
     349, {Binding{kb->getStreamSetTy(1, codeUnitWidth), "sourceBuffer"}}
     350, {Binding{kb->getInt32Ty(), "fileDescriptor"}}
     351, {}
     352, {Binding{IntegerType::get(kb->getContext(), codeUnitWidth)->getPointerTo(), "buffer"}, Binding{kb->getSizeTy(), "capacity"},
     353    Binding{kb->getSizeTy(), "fileSize"}, Binding{kb->getInt8PtrTy(), "readableBuffer"}})
     354, mSegmentBlocks(blocksPerSegment)
     355, mCodeUnitWidth(codeUnitWidth)
     356, mFileSizeFunction(nullptr) {
     357   
     358}
     359
     360void FDSourceKernel::generateFinalizeMethod(const std::unique_ptr<KernelBuilder> & kb) {
     361    BasicBlock * finalizeRead = kb->CreateBasicBlock("finalizeRead");
     362    BasicBlock * finalizeMMap = kb->CreateBasicBlock("finalizeMMap");
     363    BasicBlock * finalizeDone = kb->CreateBasicBlock("finalizeDone");
     364    // if the fileDescriptor is 0, the file is stdin, use readSource kernel logic, otherwise use mmap logic.
     365    kb->CreateCondBr(kb->CreateICmpEQ(kb->getScalarField("fileDescriptor"), kb->getInt32(0)), finalizeRead, finalizeMMap);
     366    kb->SetInsertPoint(finalizeRead);
     367    reinterpret_cast<ReadSourceKernel *>(this)->ReadSourceKernel::generateFinalizeMethod(kb);
     368    kb->CreateBr(finalizeDone);
     369    kb->SetInsertPoint(finalizeMMap);
     370    reinterpret_cast<MMapSourceKernel *>(this)->MMapSourceKernel::generateFinalizeMethod(kb);
     371    kb->CreateBr(finalizeDone);
     372    kb->SetInsertPoint(finalizeDone);
     373}
     374
     375void FDSourceKernel::generateInitializeMethod(const std::unique_ptr<KernelBuilder> & kb) {
     376    BasicBlock * initializeRead = kb->CreateBasicBlock("initializeRead");
     377    BasicBlock * initializeMMap = kb->CreateBasicBlock("initializeMMap");
     378    BasicBlock * initializeDone = kb->CreateBasicBlock("initializeDone");
     379    // if the fileDescriptor is 0, the file is stdin, use readSource kernel logic, otherwise use MMap logic.
     380    kb->CreateCondBr(kb->CreateICmpEQ(kb->getScalarField("fileDescriptor"), kb->getInt32(0)), initializeRead, initializeMMap);
     381    kb->SetInsertPoint(initializeRead);
     382    reinterpret_cast<ReadSourceKernel *>(this)->ReadSourceKernel::generateInitializeMethod(kb);
     383    kb->CreateBr(initializeDone);
     384    kb->SetInsertPoint(initializeMMap);
     385    reinterpret_cast<MMapSourceKernel *>(this)->MMapSourceKernel::generateInitializeMethod(kb);
     386    kb->CreateBr(initializeDone);
     387    kb->SetInsertPoint(initializeDone);
     388}
     389
     390void FDSourceKernel::generateDoSegmentMethod(const std::unique_ptr<KernelBuilder> & kb) {
     391    BasicBlock * DoSegmentRead = kb->CreateBasicBlock("DoSegmentRead");
     392    BasicBlock * DoSegmentMMap = kb->CreateBasicBlock("DoSegmentMMap");
     393    BasicBlock * DoSegmentDone = kb->CreateBasicBlock("DoSegmentDone");
     394    // if the fileDescriptor is 0, the file is stdin, use readSource kernel logic, otherwise use MMap logic.
     395    kb->CreateCondBr(kb->CreateICmpEQ(kb->getScalarField("fileDescriptor"), kb->getInt32(0)), DoSegmentRead, DoSegmentMMap);
     396    kb->SetInsertPoint(DoSegmentRead);
     397    reinterpret_cast<ReadSourceKernel *>(this)->ReadSourceKernel::generateDoSegmentMethod(kb);
     398    kb->CreateBr(DoSegmentDone);
     399    kb->SetInsertPoint(DoSegmentMMap);
     400    reinterpret_cast<MMapSourceKernel *>(this)->MMapSourceKernel::generateDoSegmentMethod(kb);
     401    kb->CreateBr(DoSegmentDone);
     402    kb->SetInsertPoint(DoSegmentDone);
     403}
     404
     405
     406void FDSourceKernel::linkExternalMethods(const std::unique_ptr<kernel::KernelBuilder> & kb) {
     407    mFileSizeFunction = kb->LinkFunction("file_size", &file_size);
     408}
     409   
     410   
    344411/// MEMORY SOURCE KERNEL
    345412
Note: See TracChangeset for help on using the changeset viewer.