Skip to content

Commit fac99de

Browse files
authored
Merge pull request #50 from Algebraic-Programming/feat/channelsVarSizeHelper
Feat: channels var size helper
2 parents af8c830 + cd1a84a commit fac99de

4 files changed

Lines changed: 16 additions & 5 deletions

File tree

examples/channels/variableSize/spsc/include/consumer.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ void consumerFc(HiCR::MemoryManager &coordinationMemoryManager,
3636
auto sizesBufferSlot = coordinationMemoryManager.allocateLocalMemorySlot(coordinationMemorySpace, sizesBufferSize);
3737

3838
// Allocating payload buffer as a local memory slot
39-
auto payloadBufferSlot = payloadMemoryManager.allocateLocalMemorySlot(payloadMemorySpace, PAYLOAD_CAPACITY * 2);
39+
auto payloadBufferSlot = payloadMemoryManager.allocateLocalMemorySlot(payloadMemorySpace, HiCR::channel::variableSize::SPSC::Consumer::getPayloadBufferSize(PAYLOAD_CAPACITY));
4040

4141
// Getting required buffer size
4242
auto coordinationBufferSize = HiCR::channel::variableSize::Base::getCoordinationBufferSize();

include/hicr/backends/pthreads/core.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@ class Core
4545
/**
4646
* Constructor
4747
*
48-
* \param[in] fenceCount barrier size. Indicates how many threads should reach the barrier before continuing
48+
* \param[in] instanceCount how many instances will be in the application
4949
*/
50-
Core(const size_t fenceCount)
51-
: _fenceCount(fenceCount),
50+
Core(const size_t instanceCount)
51+
: _fenceCount(instanceCount),
5252
_currentInstanceId(0)
5353
{
5454
// Init barrier

include/hicr/frontends/channel/variableSize/spsc/consumer.hpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,16 @@ class Consumer final : public variableSize::Base
134134
return bufferPos;
135135
}
136136

137+
/**
138+
* This function can be used to check the size of the payload buffer that needs to be provided
139+
* in the creation of the channel. The returned size might differ based on the specific channle implementation
140+
*
141+
* \param[in] payloadSize the desired payload buffer size
142+
*
143+
* \return Size (bytes) of the payload buffer
144+
*/
145+
__INLINE__ static size_t getPayloadBufferSize(const size_t payloadSize) noexcept { return payloadSize * 2; }
146+
137147
/**
138148
* This function gets the (starting position, size) pair for a given element in the consumer channel
139149
* @param[in] pos The payload position required. \p pos = 0 indicates earliest payload that

tests/frontends/channel/variableSize/spsc/include/channelFixture.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,8 @@ class ChannelFixture : public ::testing::Test
102102
auto sizesBufferSlot = coordinationMemoryManager.allocateLocalMemorySlot(coordinationMemorySpace, sizesBufferSize);
103103

104104
// Allocating payload buffer as a local memory slot
105-
auto payloadBufferSlot = payloadMemoryManager.allocateLocalMemorySlot(payloadMemorySpace, 2 * CHANNEL_CAPACITY * sizeof(ELEMENT_TYPE));
105+
auto payloadBufferSlot =
106+
payloadMemoryManager.allocateLocalMemorySlot(payloadMemorySpace, HiCR::channel::variableSize::SPSC::Consumer::getPayloadBufferSize(CHANNEL_CAPACITY * sizeof(ELEMENT_TYPE)));
106107

107108
// Getting required buffer size
108109
auto coordinationBufferSize = HiCR::channel::variableSize::Base::getCoordinationBufferSize();

0 commit comments

Comments
 (0)