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

HiCR: /home/runner/work/HiCR/HiCR/include/hicr/backends/opencl/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 <nlohmann_json/json.hpp>
27#include <hicr/core/definitions.hpp>
30
31namespace HiCR::backend::opencl
32{
33
37class Device;
38
42class MemorySpace final : public HiCR::MemorySpace
43{
44 public:
45
52 MemorySpace(const std::weak_ptr<opencl::Device> device, const size_t size)
53 : HiCR::MemorySpace(size),
54 _device(device)
55 {
56 _type = "OpenCL Device RAM";
57 };
58
63 : HiCR::MemorySpace()
64 {
65 _type = "OpenCL Device RAM";
66 }
67
71 ~MemorySpace() = default;
72
80 MemorySpace(const nlohmann::json &input)
81 : HiCR::MemorySpace()
82 {
83 deserialize(input);
84 }
85
91 __INLINE__ const std::weak_ptr<const opencl::Device> getDevice() const { return _device; }
92
93 private:
94
95 __INLINE__ void serializeImpl(nlohmann::json &output) const override { output["Memory Space Type"] = _type; }
96
97 __INLINE__ void deserializeImpl(const nlohmann::json &input) override
98 {
99 std::string typeKey = "Memory Space Type";
100 if (input.contains(typeKey) == false) HICR_THROW_LOGIC("The serialized object contains no '%s' key", typeKey.c_str());
101 if (input[typeKey].is_number() == false) HICR_THROW_LOGIC("The '%s' entry is not a number", typeKey.c_str());
102 _type = input[typeKey].get<std::string>();
103 }
104
110 std::weak_ptr<opencl::Device> _device;
111
115 std::string _type;
116};
117
118} // namespace HiCR::backend::opencl
Provides a definition for the local memory slot class for the OpenCL backend.
Definition memorySpace.hpp:45
__INLINE__ void deserialize(const nlohmann::json &input)
Definition memorySpace.hpp:143
Definition memorySpace.hpp:43
MemorySpace(const nlohmann::json &input)
Definition memorySpace.hpp:80
MemorySpace(const std::weak_ptr< opencl::Device > device, const size_t size)
Definition memorySpace.hpp:52
MemorySpace()
Definition memorySpace.hpp:62
__INLINE__ const std::weak_ptr< const opencl::Device > getDevice() const
Definition memorySpace.hpp:91
Provides a base definition for a HiCR MemorySpace class.
#define HICR_THROW_LOGIC(...)
Definition exceptions.hpp:67