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

HiCR: /home/runner/work/HiCR/HiCR/include/hicr/core/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
23#pragma once
24
25#include <string>
26#include <nlohmann_json/json.hpp>
27#include <nlohmann_json/parser.hpp>
28#include <hicr/core/definitions.hpp>
29
30namespace HiCR
31{
32
40{
41 public:
42
46 ComputeResource() = default;
47
56 ComputeResource(const nlohmann::json &input) { deserialize(input); }
57
61 virtual ~ComputeResource() = default;
62
68 [[nodiscard]] __INLINE__ std::string getType() const { return _type; };
69
75 [[nodiscard]] __INLINE__ nlohmann::json serialize() const
76 {
77 // Storage for newly created serialized output
78 nlohmann::json output;
79
80 // Getting information from the derived class
81 serializeImpl(output);
82
83 // Getting compute resource type
84 output["Type"] = _type;
85
86 // Returning serialized information
87 return output;
88 }
89
95 __INLINE__ void deserialize(const nlohmann::json &input)
96 {
97 // Setting compute resource type
98 _type = hicr::json::getString(input, "Type");
99
100 // Then call the backend-specific deserialization function
101 deserializeImpl(input);
102 };
103
104 protected:
105
109 std::string _type;
110
117 __INLINE__ virtual void serializeImpl(nlohmann::json &output) const {}
118
124 __INLINE__ virtual void deserializeImpl(const nlohmann::json &input)
125 {
126 // Setting device type
127 _type = hicr::json::getString(input, "Type");
128 }
129};
130
131} // namespace HiCR
Definition computeResource.hpp:40
virtual ~ComputeResource()=default
virtual __INLINE__ void deserializeImpl(const nlohmann::json &input)
Definition computeResource.hpp:124
virtual __INLINE__ void serializeImpl(nlohmann::json &output) const
Definition computeResource.hpp:117
__INLINE__ std::string getType() const
Definition computeResource.hpp:68
std::string _type
Definition computeResource.hpp:109
ComputeResource(const nlohmann::json &input)
Definition computeResource.hpp:56
__INLINE__ nlohmann::json serialize() const
Definition computeResource.hpp:75
__INLINE__ void deserialize(const nlohmann::json &input)
Definition computeResource.hpp:95