source: icGREP/icgrep-devel/icgrep/toolchain/driver.cpp @ 6209

Last change on this file since 6209 was 6209, checked in by nmedfort, 11 months ago

Initial cache janitor daemon test

File size: 4.0 KB
Line 
1#include "driver.h"
2#include <kernels/kernel_builder.h>
3#include <kernels/pipeline_builder.h>
4#include <llvm/IR/Module.h>
5#include <toolchain/toolchain.h>
6#include <toolchain/object_cache.h>
7#include <llvm/Support/raw_ostream.h>
8
9using namespace kernel;
10
11using RelationshipAllocator = Relationship::Allocator;
12
13/** ------------------------------------------------------------------------------------------------------------- *
14 * @brief makePipelineWithIO
15 ** ------------------------------------------------------------------------------------------------------------- */
16std::unique_ptr<PipelineBuilder> BaseDriver::makePipelineWithIO(Bindings stream_inputs, Bindings stream_outputs, Bindings scalar_inputs, Bindings scalar_outputs) {
17    return llvm::make_unique<PipelineBuilder>(*this, std::move(stream_inputs), std::move(stream_outputs), std::move(scalar_inputs), std::move(scalar_outputs));
18}
19
20/** ------------------------------------------------------------------------------------------------------------- *
21 * @brief makePipeline
22 ** ------------------------------------------------------------------------------------------------------------- */
23std::unique_ptr<kernel::PipelineBuilder> BaseDriver::makePipeline(Bindings scalar_inputs, Bindings scalar_outputs) {
24    return llvm::make_unique<PipelineBuilder>(*this, Bindings{}, Bindings{}, std::move(scalar_inputs), std::move(scalar_outputs));
25}
26
27/** ------------------------------------------------------------------------------------------------------------- *
28 * @brief CreateStreamSet
29 ** ------------------------------------------------------------------------------------------------------------- */
30StreamSet * BaseDriver::CreateStreamSet(const unsigned NumElements, const unsigned FieldWidth) {
31    RelationshipAllocator A(mAllocator);
32    return new (A) StreamSet(getContext(), NumElements, FieldWidth);
33}
34
35/** ------------------------------------------------------------------------------------------------------------- *
36 * @brief CreateConstant
37 ** ------------------------------------------------------------------------------------------------------------- */
38Scalar * BaseDriver::CreateScalar(llvm::Type * scalarType) {
39    RelationshipAllocator A(mAllocator);
40    return new (A) Scalar(scalarType);
41}
42
43/** ------------------------------------------------------------------------------------------------------------- *
44 * @brief CreateConstant
45 ** ------------------------------------------------------------------------------------------------------------- */
46Scalar * BaseDriver::CreateConstant(llvm::Constant * const value) {
47    RelationshipAllocator A(mAllocator);
48    return new (A) ScalarConstant(value);
49}
50
51/** ------------------------------------------------------------------------------------------------------------- *
52 * @brief makeCache
53 ** ------------------------------------------------------------------------------------------------------------- */
54void BaseDriver::addKernel(Kernel * const kernel) {
55    if (ParabixObjectCache::checkForCachedKernel(iBuilder, kernel)) {
56        assert (kernel->getModule());
57        mCachedKernel.emplace_back(kernel);
58    } else {
59        if (kernel->getModule() == nullptr) {
60            kernel->makeModule(iBuilder);
61        }
62        mUncachedKernel.emplace_back(kernel);
63    }
64}
65
66/** ------------------------------------------------------------------------------------------------------------- *
67 * @brief constructor
68 ** ------------------------------------------------------------------------------------------------------------- */
69BaseDriver::BaseDriver(std::string && moduleName)
70: mContext(new llvm::LLVMContext())
71, mMainModule(new llvm::Module(moduleName, *mContext))
72, iBuilder(nullptr) {
73    ParabixObjectCache::initializeCacheSystems();
74}
75
76/** ------------------------------------------------------------------------------------------------------------- *
77 * @brief deconstructor
78 ** ------------------------------------------------------------------------------------------------------------- */
79BaseDriver::~BaseDriver() {
80
81}
Note: See TracBrowser for help on using the repository browser.