/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
51 ComputeResource(const std::shared_ptr<opencl::Device> &device, const std::string &type)
52 : HiCR::ComputeResource(),
53 _device(device),
54 _type(type){};
55
59 ~ComputeResource() = default;
60
68 ComputeResource(const nlohmann::json &input)
69 : HiCR::ComputeResource()
70 {
71 deserialize(input);
72 }
73
74 __INLINE__ std::string getType() const override { return _type; }
75
81 __INLINE__ const std::weak_ptr<const opencl::Device> getDevice() const { return _device; }
82
83 private:
84
85 __INLINE__ void serializeImpl(nlohmann::json &output) const override { output["Compute Resource Type"] = _type; }
86
87 __INLINE__ void deserializeImpl(const nlohmann::json &input) override
88 {
89 std::string typeKey = "Compute Resource Type";
90 if (input.contains(typeKey) == false) HICR_THROW_LOGIC("The serialized object contains no '%s' key", typeKey.c_str());
91 if (input[typeKey].is_number() == false) HICR_THROW_LOGIC("The '%s' entry is not a number", typeKey.c_str());
92 _type = input[typeKey].get<std::string>();
93 }
94
100 std::weak_ptr<opencl::Device> _device;
101
102 std::string _type;
103};
104
105} // namespace HiCR::backend::opencl
Definition computeResource.hpp:39
__INLINE__ void deserialize(const nlohmann::json &input)
Definition computeResource.hpp:79
Definition computeResource.hpp:42
__INLINE__ const std::weak_ptr< const opencl::Device > getDevice() const
Definition computeResource.hpp:81
__INLINE__ std::string getType() const override
Definition computeResource.hpp:74
ComputeResource(const nlohmann::json &input)
Definition computeResource.hpp:68
ComputeResource(const std::shared_ptr< opencl::Device > &device, const std::string &type)
Definition computeResource.hpp:51
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