source: icGREP/icgrep-devel/icgrep/kernels/multiblock_kernel.cpp @ 6184

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

Initial version of PipelineKernel? + revised StreamSet? model.

File size: 3.6 KB
Line 
1/*
2 *  Copyright (c) 2018 International Characters.
3 *  This software is licensed to the public under the Open Software License 3.0.
4 */
5#include <kernels/kernel.h>
6
7#include <toolchain/toolchain.h>
8#include <kernels/streamset.h>
9#include <kernels/kernel_builder.h>
10#include <llvm/IR/Constants.h>
11#include <llvm/IR/Function.h>
12#include <llvm/IR/Instructions.h>
13#include <llvm/IR/MDBuilder.h>
14#include <llvm/IR/Module.h>
15#include <llvm/Support/raw_ostream.h>
16#if LLVM_VERSION_INTEGER < LLVM_VERSION_CODE(4, 0, 0)
17#include <llvm/Bitcode/ReaderWriter.h>
18#else
19#include <llvm/Bitcode/BitcodeWriter.h>
20#endif
21#include <llvm/Transforms/Utils/Local.h>
22#include <sstream>
23
24using namespace llvm;
25
26namespace kernel {
27
28using Port = Kernel::Port;
29using StreamPort = Kernel::StreamSetPort;
30using AttrId = Attribute::KindId;
31using RateId = ProcessingRate::KindId;
32using RateValue = ProcessingRate::RateValue;
33
34/** ------------------------------------------------------------------------------------------------------------- *
35 * @brief generateKernelMethod
36 ** ------------------------------------------------------------------------------------------------------------- */
37void MultiBlockKernel::generateKernelMethod(const std::unique_ptr<KernelBuilder> & b) {
38
39    Value * const numOfStrides = b->CreateSelect(mIsFinal, b->getSize(1), mNumOfStrides);
40
41    generateMultiBlockLogic(b, numOfStrides);
42
43    BasicBlock * const exit = b->CreateBasicBlock();
44    if (LLVM_UNLIKELY(hasAttribute(AttrId::CanTerminateEarly) || hasAttribute(AttrId::MustExplicitlyTerminate))) {
45        Value * const terminated = b->getTerminationSignal();
46        BasicBlock * const regularExit = b->CreateBasicBlock("regularExit", exit);
47        b->CreateUnlikelyCondBr(terminated, exit, regularExit);
48
49        b->SetInsertPoint(regularExit);
50    }
51    incrementItemCountsOfCountableRateStreams(b);
52    b->CreateBr(exit);
53
54    b->SetInsertPoint(exit);
55}
56
57/** ------------------------------------------------------------------------------------------------------------- *
58 * @brief incrementItemCountsOfCountableRateStreams
59 ** ------------------------------------------------------------------------------------------------------------- */
60inline void MultiBlockKernel::incrementItemCountsOfCountableRateStreams(const std::unique_ptr<KernelBuilder> & b) {
61
62    const auto numOfInputs = getNumOfStreamInputs();
63    for (unsigned i = 0; i < numOfInputs; i++) {
64        const Binding & input = getInputStreamSetBinding(i);
65        if (isCountable(input)) {
66            Value * avail = getAvailableInputItems(i);
67            b->setNonDeferredProcessedItemCount(input, avail);
68        }
69    }
70
71    const auto numOfOutputs = getNumOfStreamOutputs();
72    for (unsigned i = 0; i < numOfOutputs; i++) {
73        const Binding & output = getOutputStreamSetBinding(i);
74        if (isCountable(output)) {
75            Value * avail = b->getCapacity(output.getName());
76            b->setNonDeferredProducedItemCount(output, avail);
77        }
78    }
79}
80
81// MULTI-BLOCK KERNEL CONSTRUCTOR
82MultiBlockKernel::MultiBlockKernel(std::string && kernelName,
83                                   Bindings && stream_inputs,
84                                   Bindings && stream_outputs,
85                                   Bindings && scalar_parameters,
86                                   Bindings && scalar_outputs,
87                                   Bindings && internal_scalars)
88: Kernel(std::move(kernelName),
89         std::move(stream_inputs),
90         std::move(stream_outputs),
91         std::move(scalar_parameters),
92         std::move(scalar_outputs),
93         std::move(internal_scalars)) {
94
95}
96
97}
Note: See TracBrowser for help on using the repository browser.