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_mul.h"
18 #include "abstract/utils.h"
19 #include "runtime/mem.h"
20 #include "backend/session/single_kernel_graph.h"
21 #include "frontend/parallel/context.h"
22
23 namespace mindspore::device::ascend {
FreeDeviceMem(void * addr)24 void AscendLaunchMul::FreeDeviceMem(void *addr) { AscendLaunchKernel::FreeDeviceMem(addr); }
25
AlignSizeForLaunchKernel(size_t size)26 size_t AscendLaunchMul::AlignSizeForLaunchKernel(size_t size) {
27 return AscendLaunchKernel::AlignSizeForLaunchKernel(size);
28 }
29
AllocDeviceMem(size_t size)30 uint8_t *AscendLaunchMul::AllocDeviceMem(size_t size) { return AscendLaunchKernel::AllocDeviceMem(size); }
31
KernelSelect(const std::shared_ptr<session::KernelGraph> & kernel_graph)32 void AscendLaunchMul::KernelSelect(const std::shared_ptr<session::KernelGraph> &kernel_graph) {
33 AscendLaunchKernel::KernelSelect(kernel_graph);
34 }
35
KernelBuild(const std::shared_ptr<session::KernelGraph> & kernel_graph)36 void AscendLaunchMul::KernelBuild(const std::shared_ptr<session::KernelGraph> &kernel_graph) {
37 AscendLaunchKernel::KernelBuild(kernel_graph);
38 }
39
LaunchOpKernel()40 void AscendLaunchMul::LaunchOpKernel() {
41 kernel_mod_ = ObtainLaunchMulKernelMod();
42 MS_EXCEPTION_IF_NULL(kernel_mod_);
43 // construct mul inputs addr
44 ObtainMulInputsAddr();
45 // launch mul
46 LaunchSingleKernel(inputs_addr_);
47 }
48
FreeLaunchDeviceMem()49 void AscendLaunchMul::FreeLaunchDeviceMem() {
50 FreeInputDeviceMemory();
51 FreeOutputAndWorkspaceDeviceMem();
52 }
53
CopyHostMemToDevice(size_t origin_size,size_t dst_size)54 void AscendLaunchMul::CopyHostMemToDevice(size_t origin_size, size_t dst_size) {
55 auto ret = rtMemcpyAsync(input2_addr_, dst_size, &input2_value_, origin_size, RT_MEMCPY_HOST_TO_DEVICE, stream_);
56 if (ret != RT_ERROR_NONE) {
57 MS_LOG(EXCEPTION) << "launch rtMemcpyAsync failed, ret:" << ret;
58 }
59 }
60 } // namespace mindspore::device::ascend
61