/home/runner/work/HiCR/HiCR/include/hicr/frontends/channel/variableSize/base.hpp Source File

HiCR: /home/runner/work/HiCR/HiCR/include/hicr/frontends/channel/variableSize/base.hpp Source File
HiCR
base.hpp
Go to the documentation of this file.
1/*
2 * Copyright 2025 Huawei Technologies Co., Ltd.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
24#pragma once
25
26#include <memory>
27#include <cstring>
28#include <hicr/core/definitions.hpp>
32#include <hicr/frontends/channel/base.hpp>
33
34namespace HiCR::channel::variableSize
35{
36
40class Base : public channel::Base
41{
42 protected:
43
58 Base(CommunicationManager &communicationManager,
59 const std::shared_ptr<LocalMemorySlot> &coordinationBufferForCounts,
60 const std::shared_ptr<LocalMemorySlot> &coordinationBufferForPayloads,
61 const size_t capacity,
62 const size_t payloadCapacity)
63 : channel::Base(communicationManager, coordinationBufferForCounts, sizeof(size_t), capacity),
64 _coordinationBufferForCounts(coordinationBufferForCounts),
65 _coordinationBufferForPayloads(coordinationBufferForPayloads)
66 {
67 if (capacity == 0) HICR_THROW_LOGIC("Attempting to create a channel with zero capacity \n");
68
69 // Checking that the provided coordination buffers have the right size
70 auto requiredCoordinationBufferSize = 4 * sizeof(_HICR_CHANNEL_COORDINATION_BUFFER_ELEMENT_TYPE);
71 auto providedCoordinationBufferSize = coordinationBufferForPayloads->getSize() + coordinationBufferForCounts->getSize();
72 if (providedCoordinationBufferSize < requiredCoordinationBufferSize)
73 HICR_THROW_LOGIC("Attempting to create a channel with a local coordination buffer size (%lu) smaller than the required size (%lu).\n",
74 providedCoordinationBufferSize,
75 requiredCoordinationBufferSize);
76
77 // Creating internal circular buffer
78 _circularBufferForCounts = std::make_unique<channel::CircularBuffer>(
79 capacity,
80 &static_cast<_HICR_CHANNEL_COORDINATION_BUFFER_ELEMENT_TYPE *>(coordinationBufferForCounts->getPointer())[_HICR_CHANNEL_HEAD_ADVANCE_COUNT_IDX],
81 &static_cast<_HICR_CHANNEL_COORDINATION_BUFFER_ELEMENT_TYPE *>(coordinationBufferForCounts->getPointer())[_HICR_CHANNEL_TAIL_ADVANCE_COUNT_IDX]);
82
83 _circularBufferForPayloads = std::make_unique<channel::CircularBuffer>(
84 payloadCapacity,
85 &static_cast<_HICR_CHANNEL_COORDINATION_BUFFER_ELEMENT_TYPE *>(coordinationBufferForPayloads->getPointer())[_HICR_CHANNEL_HEAD_ADVANCE_COUNT_IDX],
86 &static_cast<_HICR_CHANNEL_COORDINATION_BUFFER_ELEMENT_TYPE *>(coordinationBufferForPayloads->getPointer())[_HICR_CHANNEL_TAIL_ADVANCE_COUNT_IDX]);
87 }
88
93 [[nodiscard]] __INLINE__ auto getCircularBufferForCounts() const { return _circularBufferForCounts.get(); }
94
99 [[nodiscard]] __INLINE__ auto getCircularBufferForPayloads() const { return _circularBufferForPayloads.get(); }
100
105 [[nodiscard]] __INLINE__ auto getCoordinationBufferForCounts() const { return _coordinationBufferForCounts; }
106
111 [[nodiscard]] __INLINE__ auto getCoordinationBufferForPayloads() const { return _coordinationBufferForPayloads; }
112
113 private:
114
118 std::unique_ptr<channel::CircularBuffer> _circularBufferForCounts;
122 std::unique_ptr<channel::CircularBuffer> _circularBufferForPayloads;
126 const std::shared_ptr<LocalMemorySlot> _coordinationBufferForCounts;
130 const std::shared_ptr<LocalMemorySlot> _coordinationBufferForPayloads;
131};
132
133} // namespace HiCR::channel::variableSize
Definition communicationManager.hpp:54
Definition base.hpp:70
Definition base.hpp:41
__INLINE__ auto getCircularBufferForPayloads() const
Definition base.hpp:99
__INLINE__ auto getCoordinationBufferForPayloads() const
Definition base.hpp:111
__INLINE__ auto getCoordinationBufferForCounts() const
Definition base.hpp:105
Base(CommunicationManager &communicationManager, const std::shared_ptr< LocalMemorySlot > &coordinationBufferForCounts, const std::shared_ptr< LocalMemorySlot > &coordinationBufferForPayloads, const size_t capacity, const size_t payloadCapacity)
Definition base.hpp:58
__INLINE__ auto getCircularBufferForCounts() const
Definition base.hpp:93
Provides a definition for the base backend's communication manager class.
Provides a definition for a HiCR Global Memory Slot class.
Provides a failure model and corresponding exception classes.
#define HICR_THROW_LOGIC(...)
Definition exceptions.hpp:67