• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright 2021 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 #include "runtime/device/ascend/ascend_launch_kernel.h"
18 #include "runtime/device/memory_manager.h"
19 #include "runtime/device/ascend/ascend_memory_pool.h"
20 #include "runtime/device/ascend/kernel_build_ascend.h"
21 #include "runtime/device/ascend/kernel_select_ascend.h"
22 
23 namespace mindspore::device::ascend {
FreeDeviceMem(void * addr)24 void AscendLaunchKernel::FreeDeviceMem(void *addr) { AscendMemoryPool::GetInstance().FreeTensorMem(addr); }
25 
AlignSizeForLaunchKernel(size_t size)26 size_t AscendLaunchKernel::AlignSizeForLaunchKernel(size_t size) { return MemoryManager::GetCommonAlignSize(size); }
27 
AllocDeviceMem(size_t size)28 uint8_t *AscendLaunchKernel::AllocDeviceMem(size_t size) {
29   auto device_memory = AscendMemoryPool::GetInstance().AllocTensorMem(size);
30   MS_EXCEPTION_IF_NULL(device_memory);
31   return static_cast<uint8_t *>(device_memory);
32 }
33 
KernelSelect(const std::shared_ptr<session::KernelGraph> & kernel_graph)34 void AscendLaunchKernel::KernelSelect(const std::shared_ptr<session::KernelGraph> &kernel_graph) {
35   MS_EXCEPTION_IF_NULL(kernel_graph);
36   auto node_list = kernel_graph->execution_order();
37   for (size_t i = 0; i < node_list.size(); ++i) {
38     auto status = device::ascend::SelectKernelInfo(node_list[i]);
39     if (status == ascend::kNoMatched) {
40       MS_LOG(ERROR) << "Cnode name : " << node_list[i]->fullname_with_scope() << " kernel select failed";
41     }
42   }
43 }
44 
KernelBuild(const std::shared_ptr<session::KernelGraph> & kernel_graph)45 void AscendLaunchKernel::KernelBuild(const std::shared_ptr<session::KernelGraph> &kernel_graph) {
46   MS_EXCEPTION_IF_NULL(kernel_graph);
47   auto ret = device::ascend::KernelBuild(kernel_graph->execution_order());
48   if (!ret) {
49     MS_LOG(ERROR) << "kernel build failed";
50   }
51 }
52 }  // namespace mindspore::device::ascend
53