/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 {
53 _type = "RAM";
54 };
55
59 ~MemorySpace() override = default;
60
66 [[nodiscard]] __INLINE__ hwloc::LocalMemorySlot::binding_type getSupportedBindingType() const { return _bindingSupport; }
67
73 [[nodiscard]] __INLINE__ const hwloc_obj_t getHWLocObject() const { return _hwlocObject; }
74
75 private:
76
77 __INLINE__ void serializeImpl(nlohmann::json &output) const override
78 {
79 // Writing HWLoc-specific information into the serialized object
80 output["Binding Support"] = _bindingSupport;
81 }
82
83 __INLINE__ void deserializeImpl(const nlohmann::json &input) override
84 {
85 // Checking whether the type is correct
86 if (_type != "RAM") HICR_THROW_LOGIC("The passed memory space type '%s' is not compatible with this topology manager", _type.c_str());
87
88 std::string key = "Binding Support";
89 if (input.contains(key) == false) HICR_THROW_LOGIC("The serialized object contains no '%s' key", key.c_str());
90 if (input[key].is_number() == false) HICR_THROW_LOGIC("The '%s' entry is not a number", key.c_str());
91 _bindingSupport = input[key].get<hwloc::LocalMemorySlot::binding_type>();
92 }
93
97 hwloc_obj_t _hwlocObject{};
98
103};
104
105} // namespace HiCR::backend::hwloc
Definition memorySpace.hpp:45
std::string _type
Definition memorySpace.hpp:197
binding_type
Definition localMemorySlot.hpp:44
@ strict_binding
Definition localMemorySlot.hpp:48
Definition memorySpace.hpp:38
__INLINE__ hwloc::LocalMemorySlot::binding_type getSupportedBindingType() const
Definition memorySpace.hpp:66
__INLINE__ const hwloc_obj_t getHWLocObject() const
Definition memorySpace.hpp:73
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