/home/runner/work/HiCR/HiCR/include/hicr/core/localMemorySlot.hpp Source File

HiCR: /home/runner/work/HiCR/HiCR/include/hicr/core/localMemorySlot.hpp Source File
HiCR
localMemorySlot.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
23#pragma once
24
25#include <memory>
26#include <hicr/core/definitions.hpp>
28#include <utility>
29
30namespace HiCR
31{
32class CommunicationManager;
33}
34
35namespace HiCR
36{
37
44{
45 friend class HiCR::CommunicationManager;
46
47 public:
48
56 LocalMemorySlot(void *const pointer, const size_t size, std::shared_ptr<HiCR::MemorySpace> memorySpace = nullptr)
57 : _pointer(pointer),
58 _size(size),
59 _memorySpace(std::move(memorySpace))
60 {
61 _messagesRecv = &_messagesRecvStorage;
62 _messagesSent = &_messagesSentStorage;
63 }
64
68 virtual ~LocalMemorySlot() = default;
69
74 __INLINE__ void *&getPointer() noexcept { return _pointer; }
75
80 [[nodiscard]] __INLINE__ size_t getSize() const noexcept { return _size; }
81
86 [[nodiscard]] __INLINE__ std::shared_ptr<HiCR::MemorySpace> getMemorySpace() const noexcept { return _memorySpace; }
87
92 [[nodiscard]] __INLINE__ size_t getMessagesRecv() const noexcept { return *_messagesRecv; }
93
98 [[nodiscard]] __INLINE__ size_t getMessagesSent() const noexcept { return *_messagesSent; }
99
100 private:
101
105 __INLINE__ void increaseMessagesRecv() noexcept { *_messagesRecv = *_messagesRecv + 1; }
106
110 __INLINE__ void increaseMessagesSent() noexcept { *_messagesSent = *_messagesSent + 1; }
111
116 __INLINE__ __volatile__ size_t *&getMessagesRecvPointer() noexcept { return _messagesRecv; }
117
122 __INLINE__ __volatile__ size_t *&getMessagesSentPointer() noexcept { return _messagesSent; }
123
128 __INLINE__ void setMessagesRecv(const size_t count) noexcept { *_messagesRecv = count; }
129
134 __INLINE__ void setMessagesSent(const size_t count) noexcept { *_messagesSent = count; }
135
139 void *_pointer;
140
144 const size_t _size;
145
149 std::shared_ptr<MemorySpace> const _memorySpace;
150
154 __volatile__ size_t *_messagesRecv;
155
159 __volatile__ size_t *_messagesSent;
160
164 __volatile__ size_t _messagesRecvStorage{0};
165
169 __volatile__ size_t _messagesSentStorage{0};
170};
171
172} // namespace HiCR
Definition communicationManager.hpp:54
Definition localMemorySlot.hpp:44
__INLINE__ size_t getMessagesRecv() const noexcept
Definition localMemorySlot.hpp:92
__INLINE__ std::shared_ptr< HiCR::MemorySpace > getMemorySpace() const noexcept
Definition localMemorySlot.hpp:86
virtual ~LocalMemorySlot()=default
__INLINE__ size_t getMessagesSent() const noexcept
Definition localMemorySlot.hpp:98
__INLINE__ size_t getSize() const noexcept
Definition localMemorySlot.hpp:80
LocalMemorySlot(void *const pointer, const size_t size, std::shared_ptr< HiCR::MemorySpace > memorySpace=nullptr)
Definition localMemorySlot.hpp:56
__INLINE__ void *& getPointer() noexcept
Definition localMemorySlot.hpp:74
Provides a base definition for a HiCR MemorySpace class.