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

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

Buffer class hierarchy; s2p kernel demonstrates specialization for different buffer strategies

File size: 2.2 KB
RevLine 
[5044]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   
[5100]12using namespace parabix;
[5044]13
14llvm::Type * StreamSetType::getStreamSetBlockType(IDISA::IDISA_Builder * iBuilder) {
15    llvm::Type * streamType = mFieldWidth == 1 ? iBuilder->getBitBlockType() : ArrayType::get(iBuilder->getBitBlockType(), mFieldWidth);
16    return ArrayType::get(streamType, mStreamCount);
17}
[5076]18
[5044]19llvm::Type * StreamSetBuffer::getStreamSetBlockType() {
20    return mStreamSetType.getStreamSetBlockType(iBuilder);
21}
22
[5100]23// Single Block Buffer
24
25uint64_t SingleBlockBuffer::getBufferSize() {
26    return 1; //iBuilder->getBitBlockWidth();
[5076]27}
28
[5100]29llvm::Value * SingleBlockBuffer::allocateBuffer() {
30    mStreamSetBufferPtr = iBuilder->CreateAlloca(getStreamSetBlockType());
[5044]31    return mStreamSetBufferPtr;
32}
33
[5100]34// For a single block buffer, the block pointer is always the buffer base pointer.
35llvm::Value * SingleBlockBuffer::getStreamSetBlockPointer(llvm::Value * bufferBasePtr, llvm::Value * blockNo) {
36    return bufferBasePtr;
[5044]37}
38
[5100]39
40// External Unbounded Buffer
41
42uint64_t ExternalUnboundedBuffer::getBufferSize() {
43    return 0;
44}
45
46llvm::Value * ExternalUnboundedBuffer::allocateBuffer() {
47    throw std::runtime_error("External buffers cannot be allocated.");
48}
49
50llvm::Value * ExternalUnboundedBuffer::getStreamSetBlockPointer(llvm::Value * bufferBasePtr, llvm::Value * blockNo) {
51    return iBuilder->CreateGEP(getStreamSetBlockType(), bufferBasePtr, {blockNo});
52}
53
54
55// Circular Stack Allocated Buffer
56
57uint64_t CircularBuffer::getBufferSize() {
58    return mBufferBlocks; // * iBuilder->getBitBlockWidth();
59}
60
61llvm::Value * CircularBuffer::allocateBuffer() {
62    mStreamSetBufferPtr = iBuilder->CreateAlloca(getStreamSetBlockType(), iBuilder->getInt64(mBufferBlocks));
63    return mStreamSetBufferPtr;
64}
65
66llvm::Value * CircularBuffer::getStreamSetBlockPointer(llvm::Value * bufferBasePtr, llvm::Value * blockNo) {
67    return iBuilder->CreateGEP(getStreamSetBlockType(), bufferBasePtr, {iBuilder->CreateAnd(blockNo, iBuilder->getInt64(mBufferBlocks-1))});
68}
69
Note: See TracBrowser for help on using the repository browser.