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

HiCR: /home/runner/work/HiCR/HiCR/include/hicr/backends/ascend/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>
33#include <unordered_map>
38
39namespace HiCR::backend::ascend
40{
41
48{
49 public:
50
55 : HiCR::ComputeManager(){};
56
57 ~ComputeManager() override = default;
58
66 __INLINE__ std::shared_ptr<HiCR::ExecutionUnit> createExecutionUnit(const std::vector<std::shared_ptr<ascend::Kernel>> &kernelOperations)
67 {
68 return std::make_shared<ExecutionUnit>(kernelOperations);
69 }
70
79 __INLINE__ std::unique_ptr<HiCR::ExecutionState> createExecutionState(std::shared_ptr<HiCR::ExecutionUnit> executionUnit, void *const argument = nullptr) const override
80 {
81 return std::make_unique<ascend::ExecutionState>(executionUnit);
82 }
83
91 __INLINE__ std::unique_ptr<HiCR::ProcessingUnit> createProcessingUnit(std::shared_ptr<HiCR::ComputeResource> resource) const override
92 {
93 return std::make_unique<ProcessingUnit>(resource);
94 }
95
96 protected:
97
103 __INLINE__ void initializeImpl(std::unique_ptr<HiCR::ProcessingUnit> &processingUnit) override
104 {
105 auto p = getAscendPointer(processingUnit);
106 p->initialize();
107 }
108
115 __INLINE__ void startImpl(std::unique_ptr<HiCR::ProcessingUnit> &processingUnit, std::unique_ptr<HiCR::ExecutionState> &executionState) override
116 {
117 auto p = getAscendPointer(processingUnit);
118 p->start(executionState);
119 }
120
126 __INLINE__ void suspendImpl(std::unique_ptr<HiCR::ProcessingUnit> &processingUnit) override { HICR_THROW_RUNTIME("Suspend functionality not supported by Ascend backend"); }
127
133 __INLINE__ void resumeImpl(std::unique_ptr<HiCR::ProcessingUnit> &processingUnit) override { HICR_THROW_RUNTIME("Resume functionality not supported by Ascend backend"); }
134
140 __INLINE__ void terminateImpl(std::unique_ptr<HiCR::ProcessingUnit> &processingUnit) override {}
141
147 __INLINE__ void awaitImpl(std::unique_ptr<HiCR::ProcessingUnit> &processingUnit) override
148 {
149 auto p = getAscendPointer(processingUnit);
150 p->await();
151 }
152
153 private:
154
162 [[nodiscard]] __INLINE__ ascend::ProcessingUnit *getAscendPointer(std::unique_ptr<HiCR::ProcessingUnit> &processingUnit)
163 {
164 // We can only handle processing units of Ascend type. Make sure we got the correct one
165 // To make it fast and avoid string comparisons, we use the dynamic cast method
166 auto p = dynamic_cast<ascend::ProcessingUnit *>(processingUnit.get());
167
168 // If the processing unit is not recognized, throw error. We can use the processing unit's type (string) now.
169 if (p == nullptr) HICR_THROW_LOGIC("This compute manager cannot handle processing units of type '%s'", processingUnit->getType());
170
171 // Returning converted pointer
172 return p;
173 }
174};
175
176} // namespace HiCR::backend::ascend
This file implements the Kernel class for the Ascend backend.
This file implements the execution unit class for the Ascend backend.
Implements the processing unit class for the Ascend backend.
Definition computeManager.hpp:48
Definition computeManager.hpp:48
__INLINE__ void startImpl(std::unique_ptr< HiCR::ProcessingUnit > &processingUnit, std::unique_ptr< HiCR::ExecutionState > &executionState) override
Definition computeManager.hpp:115
__INLINE__ std::unique_ptr< HiCR::ProcessingUnit > createProcessingUnit(std::shared_ptr< HiCR::ComputeResource > resource) const override
Definition computeManager.hpp:91
__INLINE__ void terminateImpl(std::unique_ptr< HiCR::ProcessingUnit > &processingUnit) override
Definition computeManager.hpp:140
__INLINE__ void initializeImpl(std::unique_ptr< HiCR::ProcessingUnit > &processingUnit) override
Definition computeManager.hpp:103
__INLINE__ std::unique_ptr< HiCR::ExecutionState > createExecutionState(std::shared_ptr< HiCR::ExecutionUnit > executionUnit, void *const argument=nullptr) const override
Definition computeManager.hpp:79
__INLINE__ void suspendImpl(std::unique_ptr< HiCR::ProcessingUnit > &processingUnit) override
Definition computeManager.hpp:126
__INLINE__ void resumeImpl(std::unique_ptr< HiCR::ProcessingUnit > &processingUnit) override
Definition computeManager.hpp:133
__INLINE__ void awaitImpl(std::unique_ptr< HiCR::ProcessingUnit > &processingUnit) override
Definition computeManager.hpp:147
ComputeManager()
Definition computeManager.hpp:54
__INLINE__ std::shared_ptr< HiCR::ExecutionUnit > createExecutionUnit(const std::vector< std::shared_ptr< ascend::Kernel > > &kernelOperations)
Definition computeManager.hpp:66
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