source: icGREP/icgrep-devel/icgrep/kernels/instance.h @ 4981

Last change on this file since 4981 was 4974, checked in by nmedfort, 4 years ago

Added the kernel instance class; removed original mmap file access in favour of the boost mmap system. corrected PrintRegister? routine.

File size: 2.3 KB
Line 
1#ifndef INSTANCE_H
2#define INSTANCE_H
3
4#include <llvm/IR/Instructions.h>
5#include <kernels/kernel.h>
6#include <slab_allocator.h>
7
8namespace kernel {
9
10class Instance {
11    friend class KernelBuilder;
12    using Allocator = SlabAllocator<Instance>;
13public:
14
15    void call(llvm::Value * inputStreams) {
16        assert (inputStreams);
17        return mDefinition->call(mMemory, inputStreams);
18    }
19
20    llvm::Value * getInternalState(const std::string & name) {
21        return mDefinition->getInternalState(mMemory, name);
22    }
23
24    void setInternalState(const std::string & name, llvm::Value * value) {
25        mDefinition->setInternalState(mMemory, name, value);
26    }
27
28    llvm::Value * getInternalState(const unsigned index) {
29        return mDefinition->getInternalState(mMemory, index);
30    }
31
32    void setInternalState(const unsigned index, llvm::Value * value) {
33        mDefinition->setInternalState(mMemory, index, value);
34    }
35
36    llvm::Value * getInputStream(const unsigned index, const unsigned streamOffset = 0) {
37        return mDefinition->getInputStream(mMemory, index, streamOffset);
38    }
39
40    llvm::Type * getInputStreamType() const {
41        return mDefinition->getInputStreamType();
42    }
43
44    llvm::Value * getInputScalar(const unsigned index) {
45        return mDefinition->getInputScalar(mMemory, index);
46    }
47
48    llvm::Value * getOutputStream(const unsigned index, const unsigned streamOffset = 0) {
49        return mDefinition->getOutputStream(mMemory, index, streamOffset);
50    }
51
52    llvm::Value * getOutputStreamSet(const unsigned streamOffset = 0) {
53        return mDefinition->getOutputStreamSet(mMemory, streamOffset);
54    }
55
56    llvm::Value * getOutputScalar(const unsigned index) {
57        return mDefinition->getOutputScalar(mMemory, index);
58    }
59
60    llvm::Value * getBlockNo() {
61        return mDefinition->getBlockNo(mMemory);
62    }
63
64    void* operator new (std::size_t size) noexcept {
65        return mAllocator.allocate(size);
66    }
67
68    void operator delete (void * ptr) {
69        mAllocator.deallocate(static_cast<Allocator::value_type *>(ptr));
70    }
71
72protected:
73
74    Instance(KernelBuilder * definition, llvm::AllocaInst * space)
75    : mDefinition(definition)
76    , mMemory(space) {
77
78    }
79
80private:
81    KernelBuilder * const mDefinition;
82    llvm::AllocaInst * const mMemory;
83    static Allocator mAllocator;
84};
85
86}
87
88#endif // INSTANCE_H
Note: See TracBrowser for help on using the repository browser.