/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 <hicr/core/definitions.hpp>
28
29namespace HiCR
30{
31
39{
40 public:
41
47 [[nodiscard]] virtual std::string getType() const = 0;
48
52 virtual ~ComputeResource() = default;
53
59 [[nodiscard]] __INLINE__ nlohmann::json serialize() const
60 {
61 // Storage for newly created serialized output
62 nlohmann::json output;
63
64 // Getting information from the derived class
65 serializeImpl(output);
66
67 // Getting compute resource type
68 output["Type"] = getType();
69
70 // Returning serialized information
71 return output;
72 }
73
79 __INLINE__ void deserialize(const nlohmann::json &input)
80 {
81 // Then call the backend-specific deserialization function
82 deserializeImpl(input);
83 };
84
85 protected:
86
87 ComputeResource() = default;
88
95 virtual void serializeImpl(nlohmann::json &output) const = 0;
96
102 virtual void deserializeImpl(const nlohmann::json &input) = 0;
103};
104
105} // namespace HiCR
Definition computeResource.hpp:39
virtual std::string getType() const =0
virtual ~ComputeResource()=default
virtual void serializeImpl(nlohmann::json &output) const =0
virtual void deserializeImpl(const nlohmann::json &input)=0
__INLINE__ nlohmann::json serialize() const
Definition computeResource.hpp:59
__INLINE__ void deserialize(const nlohmann::json &input)
Definition computeResource.hpp:79