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 #ifndef MINDSPORE_MINDSPORE_CCSRC_RUNTIME_DEVICE_LAUNCH_MUL_H_ 18 #define MINDSPORE_MINDSPORE_CCSRC_RUNTIME_DEVICE_LAUNCH_MUL_H_ 19 20 #include <vector> 21 #include <memory> 22 #include "backend/session/kernel_graph.h" 23 24 namespace mindspore::device { 25 class LaunchMul { 26 public: LaunchMul(TypeId dtype,size_t total_size)27 LaunchMul(TypeId dtype, size_t total_size) 28 : dtype_(dtype), 29 total_size_(total_size), 30 input1_addr_(nullptr), 31 input2_addr_(nullptr), 32 input2_value_(0), 33 mul_graph_(nullptr) {} 34 virtual ~LaunchMul() = default; 35 36 virtual void FreeDeviceMem(void *addr) = 0; 37 virtual size_t AlignSizeForLaunchKernel(size_t size) = 0; 38 virtual uint8_t *AllocDeviceMem(size_t size) = 0; 39 virtual void KernelSelect(const std::shared_ptr<session::KernelGraph> &kernel_graph) = 0; 40 virtual void KernelBuild(const std::shared_ptr<session::KernelGraph> &kernel_graph) = 0; 41 virtual void CopyHostMemToDevice(size_t origin_size, size_t dst_size) = 0; 42 43 std::shared_ptr<session::KernelGraph> ObtainMulKernelGraph(); 44 kernel::KernelMod *ObtainLaunchMulKernelMod(); 45 void ObtainMulInputsAddr(); 46 void FreeInputDeviceMemory(); 47 48 protected: 49 TypeId dtype_; 50 size_t total_size_; 51 uint8_t *input1_addr_; 52 uint8_t *input2_addr_; 53 float input2_value_; 54 std::shared_ptr<session::KernelGraph> mul_graph_; 55 std::vector<uint8_t *> inputs_addr_; 56 }; 57 } // namespace mindspore::device 58 59 #endif // MINDSPORE_MINDSPORE_CCSRC_RUNTIME_DEVICE_LAUNCH_MUL_H_ 60