/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
53 MemorySpace(const std::weak_ptr<opencl::Device> device, const std::string &type, const size_t size)
54 : HiCR::MemorySpace(size),
55 _device(device),
56 _type(type){};
57
61 ~MemorySpace() = default;
62
70 MemorySpace(const nlohmann::json &input)
71 : HiCR::MemorySpace()
72 {
73 deserialize(input);
74 }
75
76 __INLINE__ std::string getType() const override { return _type; }
77
83 __INLINE__ const std::weak_ptr<const opencl::Device> getDevice() const { return _device; }
84
85 private:
86
87 __INLINE__ void serializeImpl(nlohmann::json &output) const override { output["Memory Space Type"] = _type; }
88
89 __INLINE__ void deserializeImpl(const nlohmann::json &input) override
90 {
91 std::string typeKey = "Memory Space Type";
92 if (input.contains(typeKey) == false) HICR_THROW_LOGIC("The serialized object contains no '%s' key", typeKey.c_str());
93 if (input[typeKey].is_number() == false) HICR_THROW_LOGIC("The '%s' entry is not a number", typeKey.c_str());
94 _type = input[typeKey].get<std::string>();
95 }
96
102 std::weak_ptr<opencl::Device> _device;
103
107 std::string _type;
108};
109
110} // namespace HiCR::backend::opencl
Provides a definition for the local memory slot class for the OpenCL backend.
Definition memorySpace.hpp:44
__INLINE__ void deserialize(const nlohmann::json &input)
Definition memorySpace.hpp:132
Definition memorySpace.hpp:43
MemorySpace(const nlohmann::json &input)
Definition memorySpace.hpp:70
__INLINE__ const std::weak_ptr< const opencl::Device > getDevice() const
Definition memorySpace.hpp:83
__INLINE__ std::string getType() const override
Definition memorySpace.hpp:76
MemorySpace(const std::weak_ptr< opencl::Device > device, const std::string &type, const size_t size)
Definition memorySpace.hpp:53
Provides a base definition for a HiCR MemorySpace class.
#define HICR_THROW_LOGIC(...)
Definition exceptions.hpp:67