/home/runner/work/HiCR/HiCR/include/hicr/backends/acl/computeManager.hpp Source File

HiCR: /home/runner/work/HiCR/HiCR/include/hicr/backends/acl/computeManager.hpp Source File
HiCR
computeManager.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
17/*
18 * Copyright Huawei Technologies Switzerland AG
19 * All rights reserved.
20 */
21
29#pragma once
30
31#include <acl/acl.h>
32#include <memory>
37
38namespace HiCR::backend::acl
39{
40
47{
48 public:
49
54 : HiCR::ComputeManager(){};
55
56 ~ComputeManager() override = default;
57
62
70 __INLINE__ std::shared_ptr<HiCR::ExecutionUnit> createExecutionUnit(const std::vector<std::shared_ptr<acl::Kernel>> &kernelOperations)
71 {
72 return std::make_shared<ExecutionUnit>(kernelOperations);
73 }
74
83 __INLINE__ std::unique_ptr<HiCR::ExecutionState> createExecutionState(std::shared_ptr<HiCR::ExecutionUnit> executionUnit, void *const argument = nullptr) const override
84 {
85 return std::make_unique<acl::ExecutionState>(executionUnit);
86 }
87
95 __INLINE__ std::unique_ptr<HiCR::ProcessingUnit> createProcessingUnit(std::shared_ptr<HiCR::ComputeResource> resource) const override
96 {
97 return std::make_unique<ProcessingUnit>(resource);
98 }
99
100 protected:
101
107 __INLINE__ void initializeImpl(std::unique_ptr<HiCR::ProcessingUnit> &processingUnit) override
108 {
109 auto p = getACLPointer(processingUnit);
110 p->initialize();
111 }
112
119 __INLINE__ void startImpl(std::unique_ptr<HiCR::ProcessingUnit> &processingUnit, std::unique_ptr<HiCR::ExecutionState> &executionState) override
120 {
121 auto p = getACLPointer(processingUnit);
122 p->start(executionState);
123 }
124
130 __INLINE__ void suspendImpl(std::unique_ptr<HiCR::ProcessingUnit> &processingUnit) override { HICR_THROW_RUNTIME("Suspend functionality not supported by acl backend"); }
131
137 __INLINE__ void resumeImpl(std::unique_ptr<HiCR::ProcessingUnit> &processingUnit) override { HICR_THROW_RUNTIME("Resume functionality not supported by acl backend"); }
138
144 __INLINE__ void terminateImpl(std::unique_ptr<HiCR::ProcessingUnit> &processingUnit) override {}
145
151 __INLINE__ void awaitImpl(std::unique_ptr<HiCR::ProcessingUnit> &processingUnit) override
152 {
153 auto p = getACLPointer(processingUnit);
154 p->await();
155 }
156
157 private:
158
166 [[nodiscard]] __INLINE__ acl::ProcessingUnit *getACLPointer(std::unique_ptr<HiCR::ProcessingUnit> &processingUnit)
167 {
168 // We can only handle processing units of acl type. Make sure we got the correct one
169 // To make it fast and avoid string comparisons, we use the dynamic cast method
170 auto p = dynamic_cast<acl::ProcessingUnit *>(processingUnit.get());
171
172 // If the processing unit is not recognized, throw error. We can use the processing unit's type (string) now.
173 if (p == nullptr) HICR_THROW_LOGIC("This compute manager cannot handle processing units of type '%s'", processingUnit->getType().c_str());
174
175 // Returning converted pointer
176 return p;
177 }
178};
179
180} // namespace HiCR::backend::acl
This file implements the Kernel class for the acl backend.
This file implements the execution unit class for the acl backend.
Implements the processing unit class for the acl backend.
Definition computeManager.hpp:48
virtual __INLINE__ std::shared_ptr< HiCR::ExecutionUnit > createExecutionUnit(const replicableFc_t &function)
Definition computeManager.hpp:63
Definition computeManager.hpp:47
__INLINE__ void resumeImpl(std::unique_ptr< HiCR::ProcessingUnit > &processingUnit) override
Definition computeManager.hpp:137
__INLINE__ std::unique_ptr< HiCR::ProcessingUnit > createProcessingUnit(std::shared_ptr< HiCR::ComputeResource > resource) const override
Definition computeManager.hpp:95
__INLINE__ std::shared_ptr< HiCR::ExecutionUnit > createExecutionUnit(const std::vector< std::shared_ptr< acl::Kernel > > &kernelOperations)
Definition computeManager.hpp:70
__INLINE__ void suspendImpl(std::unique_ptr< HiCR::ProcessingUnit > &processingUnit) override
Definition computeManager.hpp:130
__INLINE__ std::unique_ptr< HiCR::ExecutionState > createExecutionState(std::shared_ptr< HiCR::ExecutionUnit > executionUnit, void *const argument=nullptr) const override
Definition computeManager.hpp:83
__INLINE__ void initializeImpl(std::unique_ptr< HiCR::ProcessingUnit > &processingUnit) override
Definition computeManager.hpp:107
~ComputeManager() override=default
__INLINE__ void terminateImpl(std::unique_ptr< HiCR::ProcessingUnit > &processingUnit) override
Definition computeManager.hpp:144
__INLINE__ void startImpl(std::unique_ptr< HiCR::ProcessingUnit > &processingUnit, std::unique_ptr< HiCR::ExecutionState > &executionState) override
Definition computeManager.hpp:119
ComputeManager()
Definition computeManager.hpp:53
__INLINE__ void awaitImpl(std::unique_ptr< HiCR::ProcessingUnit > &processingUnit) override
Definition computeManager.hpp:151
Definition processingUnit.hpp:49
Provides a definition for the abstract compute manager class.
#define HICR_THROW_RUNTIME(...)
Definition exceptions.hpp:74
#define HICR_THROW_LOGIC(...)
Definition exceptions.hpp:67