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

HiCR: /home/runner/work/HiCR/HiCR/include/hicr/backends/opencl/computeResource.hpp Source File
HiCR
computeResource.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{
36class Device;
37
42{
43 public:
44
50 ComputeResource(const std::shared_ptr<opencl::Device> &device)
51 : HiCR::ComputeResource(),
52 _device(device)
53 {
54 _type = "OpenCL Processor";
55 };
56
61 : HiCR::ComputeResource()
62 {
63 _type = "OpenCL Processor";
64 }
65
69 ~ComputeResource() = default;
70
78 ComputeResource(const nlohmann::json &input)
79 : HiCR::ComputeResource()
80 {
81 deserialize(input);
82 }
83
89 __INLINE__ const std::weak_ptr<const opencl::Device> getDevice() const { return _device; }
90
91 private:
92
93 __INLINE__ void serializeImpl(nlohmann::json &output) const override { output["Compute Resource Type"] = _type; }
94
95 __INLINE__ void deserializeImpl(const nlohmann::json &input) override
96 {
97 std::string typeKey = "Compute Resource Type";
98 if (input.contains(typeKey) == false) HICR_THROW_LOGIC("The serialized object contains no '%s' key", typeKey.c_str());
99 if (input[typeKey].is_number() == false) HICR_THROW_LOGIC("The '%s' entry is not a number", typeKey.c_str());
100 _type = input[typeKey].get<std::string>();
101 }
102
108 std::weak_ptr<opencl::Device> _device;
109
110 std::string _type;
111};
112
113} // namespace HiCR::backend::opencl
Definition computeResource.hpp:40
__INLINE__ void deserialize(const nlohmann::json &input)
Definition computeResource.hpp:95
Definition computeResource.hpp:42
__INLINE__ const std::weak_ptr< const opencl::Device > getDevice() const
Definition computeResource.hpp:89
ComputeResource()
Definition computeResource.hpp:60
ComputeResource(const std::shared_ptr< opencl::Device > &device)
Definition computeResource.hpp:50
ComputeResource(const nlohmann::json &input)
Definition computeResource.hpp:78
Provides a base definition for a HiCR ComputeResource class.
Provides a failure model and corresponding exception classes.
#define HICR_THROW_LOGIC(...)
Definition exceptions.hpp:67