Changeset 5441


Ignore:
Timestamp:
May 11, 2017, 10:44:09 AM (22 months ago)
Author:
cameron
Message:

Reimplement StdoutKernel? using MultiBlockKernel?

Location:
icGREP/icgrep-devel/icgrep/kernels
Files:
4 edited

Legend:

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

    r5440 r5441  
    621621    auto args = multiBlockFunction->arg_begin();
    622622    args->setName("self");
     623    (++args)->setName("itemsToDo");
    623624    for (auto binding : mStreamSetInputs) {
    624625        (++args)->setName(binding.name + "BufPtr");
    625626    }
    626627    for (auto binding : mStreamSetOutputs) {
    627         (args++)->setName(binding.name + "BufPtr");
     628        (++args)->setName(binding.name + "BufPtr");
    628629    }
    629630
     
    633634    iBuilder->SetInsertPoint(BasicBlock::Create(iBuilder->getContext(), "multiBlockEntry", multiBlockFunction, 0));
    634635
    635     generateMultiBlockLogic();
     636    generateMultiBlockLogic(kb);
    636637
    637638    iBuilder->CreateRetVoid();
     
    801802
    802803    std::vector<Value *> doMultiBlockArgs;
     804    doMultiBlockArgs.push_back(getInstance());
    803805    doMultiBlockArgs.push_back(linearlyAvailItems);
    804806    for (unsigned i = 0; i < mStreamSetInputs.size(); i++) {
     
    879881    // Begin constructing the doMultiBlock args.
    880882    std::vector<Value *> tempArgs;
     883    tempArgs.push_back(getInstance());
    881884    tempArgs.push_back(tempBlockItems);
    882885
     
    10111014
    10121015// CONSTRUCTOR
     1016MultiBlockKernel::MultiBlockKernel(std::string && kernelName,
     1017                                     std::vector<Binding> && stream_inputs,
     1018                                     std::vector<Binding> && stream_outputs,
     1019                                     std::vector<Binding> && scalar_parameters,
     1020                                     std::vector<Binding> && scalar_outputs,
     1021                                             std::vector<Binding> && internal_scalars)
     1022: Kernel(std::move(kernelName), std::move(stream_inputs), std::move(stream_outputs), std::move(scalar_parameters), std::move(scalar_outputs), std::move(internal_scalars)) {
     1023   
     1024}
     1025
     1026// CONSTRUCTOR
    10131027SegmentOrientedKernel::SegmentOrientedKernel(std::string && kernelName,
    10141028                                             std::vector<Binding> && stream_inputs,
     
    10181032                                             std::vector<Binding> && internal_scalars)
    10191033: Kernel(std::move(kernelName), std::move(stream_inputs), std::move(stream_outputs), std::move(scalar_parameters), std::move(scalar_outputs), std::move(internal_scalars)) {
    1020 
    1021 }
    1022 
    1023 }
     1034   
     1035}
     1036   
     1037}
  • icGREP/icgrep-devel/icgrep/kernels/kernel.h

    r5440 r5441  
    371371    // exit the RetVoid instruction will be added to complete the method.
    372372    //
    373     virtual void generateMultiBlockLogic() = 0;
     373    virtual void generateMultiBlockLogic(const std::unique_ptr<KernelBuilder> & idb) = 0;
    374374
    375375private:
  • icGREP/icgrep-devel/icgrep/kernels/stdout_kernel.cpp

    r5440 r5441  
    1919// However, if the segment spans two memory areas (e.g., because of wraparound),
    2020// then two write calls are made.
    21 void StdOutKernel::generateDoSegmentMethod(const std::unique_ptr<KernelBuilder> & iBuilder) {
     21void StdOutKernel::generateMultiBlockLogic(const std::unique_ptr<KernelBuilder> & iBuilder) {
    2222    PointerType * i8PtrTy = iBuilder->getInt8PtrTy();
     23    Constant * itemBytes = iBuilder->getSize(mCodeUnitWidth / 8);
     24   
     25    Function::arg_iterator args = mCurrentMethod->arg_begin();
     26    Value * self = &*(args++);
     27    Value * itemsToDo = &*(args++);
     28    Value * codeUnitBuffer = &*(args++);
    2329
    24     Constant * blockItems = iBuilder->getSize(iBuilder->getBitBlockWidth() - 1);
    25     Constant * itemBytes = iBuilder->getSize(mCodeUnitWidth / 8);
    26     Value * processed = iBuilder->getProcessedItemCount("codeUnitBuffer");
    27     Value * itemsToDo = iBuilder->CreateSub(mAvailableItemCount[0], processed);
    28     // There may be two memory areas if we are at the physical end of a circular buffer.
    29     const auto b  = getInputStreamSetBuffer("codeUnitBuffer");
    30     Value * wraparound = nullptr;
    31     if (isa<CircularBuffer>(b) || isa<CircularCopybackBuffer>(b)) {
    32         Value * accessible = iBuilder->getLinearlyAccessibleItems("codeUnitBuffer", processed);
    33         wraparound = iBuilder->CreateICmpULT(accessible, itemsToDo);
    34         itemsToDo = iBuilder->CreateSelect(wraparound, accessible, itemsToDo);
    35     }
    36    
    37     Value * byteOffset = iBuilder->CreateMul(iBuilder->CreateAnd(processed, blockItems), itemBytes);
    38     Value * bytePtr = iBuilder->CreatePointerCast(iBuilder->getInputStreamBlockPtr("codeUnitBuffer", iBuilder->getInt32(0)), i8PtrTy);
    39     bytePtr = iBuilder->CreateGEP(bytePtr, byteOffset);
    40 
    41     iBuilder->CreateWriteCall(iBuilder->getInt32(1), bytePtr, iBuilder->CreateMul(itemsToDo, itemBytes));
    42 
    43     processed = iBuilder->CreateAdd(processed, itemsToDo);
    44     iBuilder->setProcessedItemCount("codeUnitBuffer", processed);
    45    
    46     // Now we may process the second area (if required).
    47     if (isa<CircularBuffer>(b) || isa<CircularCopybackBuffer>(b)) {
    48         BasicBlock * wrapAroundWrite = iBuilder->CreateBasicBlock("wrapAroundWrite");
    49         BasicBlock * stdoutExit = iBuilder->CreateBasicBlock("stdoutExit");
    50         iBuilder->CreateCondBr(wraparound, wrapAroundWrite, stdoutExit);
    51         iBuilder->SetInsertPoint(wrapAroundWrite);
    52        
    53         // Calculate from the updated value of processed;
    54         byteOffset = iBuilder->CreateMul(iBuilder->CreateAnd(processed, blockItems), itemBytes);
    55         Value * bytePtr = iBuilder->CreatePointerCast(iBuilder->getInputStreamBlockPtr("codeUnitBuffer", iBuilder->getInt32(0)), i8PtrTy);
    56         bytePtr = iBuilder->CreateGEP(bytePtr, byteOffset);
    57 
    58         itemsToDo = iBuilder->CreateSub(mAvailableItemCount[0], processed);
    59         iBuilder->CreateWriteCall(iBuilder->getInt32(1), bytePtr, iBuilder->CreateMul(itemsToDo, itemBytes));
    60         processed = iBuilder->CreateAdd(processed, itemsToDo);
    61         iBuilder->setProcessedItemCount("codeUnitBuffer", mAvailableItemCount[0]);
    62         iBuilder->CreateBr(stdoutExit);
    63         iBuilder->SetInsertPoint(stdoutExit);
    64     }
     30    Value * bytesToDo = mCodeUnitWidth == 8 ? itemsToDo : iBuilder->CreateMul(itemsToDo, itemBytes);
     31    Value * bytePtr = iBuilder->CreatePointerCast(codeUnitBuffer, i8PtrTy);
     32    iBuilder->CreateWriteCall(iBuilder->getInt32(1), bytePtr, bytesToDo);
    6533}
    6634
    6735StdOutKernel::StdOutKernel(const std::unique_ptr<kernel::KernelBuilder> & iBuilder, unsigned codeUnitWidth)
    68 : SegmentOrientedKernel("stdout", {Binding{iBuilder->getStreamSetTy(1, codeUnitWidth), "codeUnitBuffer"}}, {}, {}, {}, {})
     36: MultiBlockKernel("stdout", {Binding{iBuilder->getStreamSetTy(1, codeUnitWidth), "codeUnitBuffer"}}, {}, {}, {}, {})
    6937, mCodeUnitWidth(codeUnitWidth) {
    7038    setNoTerminateAttribute(true);
  • icGREP/icgrep-devel/icgrep/kernels/stdout_kernel.h

    r5440 r5441  
    1212namespace kernel {
    1313
    14 class StdOutKernel final : public SegmentOrientedKernel {
     14class StdOutKernel final : public MultiBlockKernel {
    1515public:
    1616    StdOutKernel(const std::unique_ptr<kernel::KernelBuilder> & iBuilder, unsigned codeUnitWidth);
    1717private:
    18     void generateDoSegmentMethod(const std::unique_ptr<KernelBuilder> & iBuilder) override;
     18    void generateMultiBlockLogic(const std::unique_ptr<KernelBuilder> & iBuilder) override;
    1919private:
    2020    const unsigned mCodeUnitWidth;
Note: See TracChangeset for help on using the changeset viewer.