source: icGREP/icgrep-devel/icgrep/kernels/streamset.cpp @ 5122

Last change on this file since 5122 was 5122, checked in by cameron, 3 years ago

AddrSpace? parameter for external buffers

File size: 2.6 KB
Line 
1/*
2 *  Copyright (c) 2016 International Characters.
3 *  This software is licensed to the public under the Open Software License 3.0.
4 */
5
6   
7#include <kernels/streamset.h>
8#include <vector>
9#include <IDISA/idisa_builder.h>
10#include <llvm/IR/Type.h>
11#include <iostream>
12   
13using namespace parabix;
14
15llvm::Type * StreamSetType::getStreamSetBlockType(IDISA::IDISA_Builder * iBuilder) {
16    llvm::Type * streamType = mFieldWidth == 1 ? iBuilder->getBitBlockType() : ArrayType::get(iBuilder->getBitBlockType(), mFieldWidth);
17    return ArrayType::get(streamType, mStreamCount);
18}
19
20llvm::Type * StreamSetBuffer::getStreamSetBlockType() {
21    return mStreamSetType.getStreamSetBlockType(iBuilder);
22}
23
24// Single Block Buffer
25
26size_t SingleBlockBuffer::getBufferSize() {
27    return 1; //iBuilder->getBitBlockWidth();
28}
29
30llvm::Value * SingleBlockBuffer::allocateBuffer() {
31    mStreamSetBufferPtr = iBuilder->CreateAlloca(getStreamSetBlockType());
32    return mStreamSetBufferPtr;
33}
34
35// For a single block buffer, the block pointer is always the buffer base pointer.
36llvm::Value * SingleBlockBuffer::getStreamSetBlockPointer(llvm::Value * bufferBasePtr, llvm::Value * blockNo) {
37    return bufferBasePtr;
38}
39
40
41// External Unbounded Buffer
42
43size_t ExternalUnboundedBuffer::getBufferSize() {
44    return 0;
45}
46
47void ExternalUnboundedBuffer::setStreamSetBuffer(llvm::Value * ptr) {
48    PointerType * t = PointerType::get(getStreamSetBlockType(), mAddrSpace);
49   
50    mStreamSetBufferPtr = iBuilder->CreatePointerBitCastOrAddrSpaceCast(ptr, t);
51    std::cerr << "mStreamSetBufferPtr\n";
52}
53
54llvm::Value * ExternalUnboundedBuffer::allocateBuffer() {
55    throw std::runtime_error("External buffers cannot be allocated.");
56}
57
58llvm::Value * ExternalUnboundedBuffer::getStreamSetBlockPointer(llvm::Value * bufferBasePtr, llvm::Value * blockNo) {
59    PointerType * t = PointerType::get(getStreamSetBlockType(), mAddrSpace);
60    return iBuilder->CreateGEP(iBuilder->CreatePointerBitCastOrAddrSpaceCast(bufferBasePtr, t), {blockNo});
61}
62
63
64// Circular Stack Allocated Buffer
65
66size_t CircularBuffer::getBufferSize() {
67    return mBufferBlocks; // * iBuilder->getBitBlockWidth();
68}
69
70llvm::Value * CircularBuffer::allocateBuffer() {
71    mStreamSetBufferPtr = iBuilder->CreateAlloca(getStreamSetBlockType(), ConstantInt::get(iBuilder->getSizeTy(), mBufferBlocks));
72    return mStreamSetBufferPtr;
73}
74
75llvm::Value * CircularBuffer::getStreamSetBlockPointer(llvm::Value * bufferBasePtr, llvm::Value * blockNo) {
76    return iBuilder->CreateGEP(getStreamSetBlockType(), bufferBasePtr, {iBuilder->CreateAnd(blockNo, ConstantInt::get(iBuilder->getSizeTy(), mBufferBlocks-1))});
77}
78
Note: See TracBrowser for help on using the repository browser.