/home/runner/work/HiCR/HiCR/include/hicr/backends/hwloc/memorySpace.hpp Source File

HiCR: /home/runner/work/HiCR/HiCR/include/hicr/backends/hwloc/memorySpace.hpp Source File
HiCR
memorySpace.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 <hwloc.h>
27#include <hicr/core/definitions.hpp>
29#include "localMemorySlot.hpp"
30
31namespace HiCR::backend::hwloc
32{
33
37class MemorySpace final : public HiCR::MemorySpace
38{
39 public:
40
48 MemorySpace(const size_t size, const hwloc_obj_t hwlocObject, const hwloc::LocalMemorySlot::binding_type bindingSupport)
49 : HiCR::MemorySpace(size),
50 _hwlocObject(hwlocObject),
51 _bindingSupport(bindingSupport){};
52
61 MemorySpace(const nlohmann::json &input)
62 : HiCR::MemorySpace()
63 {
64 deserialize(input);
65 }
66
70 ~MemorySpace() override = default;
71
77 [[nodiscard]] __INLINE__ hwloc::LocalMemorySlot::binding_type getSupportedBindingType() const { return _bindingSupport; }
78
84 [[nodiscard]] __INLINE__ const hwloc_obj_t getHWLocObject() const { return _hwlocObject; }
85
86 [[nodiscard]] __INLINE__ std::string getType() const override { return "RAM"; }
87
88 private:
89
90 __INLINE__ void serializeImpl(nlohmann::json &output) const override
91 {
92 // Writing HWLoc-specific information into the serialized object
93 output["Binding Support"] = _bindingSupport;
94 }
95
96 __INLINE__ void deserializeImpl(const nlohmann::json &input) override
97 {
98 std::string key = "Binding Support";
99 if (input.contains(key) == false) HICR_THROW_LOGIC("The serialized object contains no '%s' key", key.c_str());
100 if (input[key].is_number() == false) HICR_THROW_LOGIC("The '%s' entry is not a number", key.c_str());
101 _bindingSupport = input[key].get<hwloc::LocalMemorySlot::binding_type>();
102 }
103
107 hwloc_obj_t _hwlocObject{};
108
113};
114
115} // namespace HiCR::backend::hwloc
Definition memorySpace.hpp:44
__INLINE__ void deserialize(const nlohmann::json &input)
Definition memorySpace.hpp:132
binding_type
Definition localMemorySlot.hpp:44
@ strict_binding
Definition localMemorySlot.hpp:48
Definition memorySpace.hpp:38
MemorySpace(const nlohmann::json &input)
Definition memorySpace.hpp:61
__INLINE__ hwloc::LocalMemorySlot::binding_type getSupportedBindingType() const
Definition memorySpace.hpp:77
__INLINE__ const hwloc_obj_t getHWLocObject() const
Definition memorySpace.hpp:84
__INLINE__ std::string getType() const override
Definition memorySpace.hpp:86
MemorySpace(const size_t size, const hwloc_obj_t hwlocObject, const hwloc::LocalMemorySlot::binding_type bindingSupport)
Definition memorySpace.hpp:48
Provides a definition for a HiCR Local Memory Slot class.
Provides a base definition for a HiCR MemorySpace class.
#define HICR_THROW_LOGIC(...)
Definition exceptions.hpp:67