/** * Copyright 2021 Huawei Technologies Co., Ltd * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef MINDSPORE_MINDSPORE_CCSRC_RUNTIME_DEVICE_LAUNCH_KERNEL_H_ #define MINDSPORE_MINDSPORE_CCSRC_RUNTIME_DEVICE_LAUNCH_KERNEL_H_ #include #include #include "backend/session/kernel_graph.h" namespace mindspore::device { class LaunchKernel { public: explicit LaunchKernel(void *stream) : stream_(stream), kernel_mod_(nullptr) {} virtual ~LaunchKernel() = default; std::vector GetKernelOutputAddr() { return outputs_addr_; } void LaunchSingleKernel(const std::vector &inputs_addr); void FreeOutputAndWorkspaceDeviceMem(); virtual void FreeDeviceMem(void *addr) = 0; virtual size_t AlignSizeForLaunchKernel(size_t size) = 0; virtual uint8_t *AllocDeviceMem(size_t size) = 0; virtual void KernelSelect(std::shared_ptr kernel_graph) = 0; virtual void KernelBuild(std::shared_ptr kernel_graph) = 0; virtual void LaunchOpKernel() = 0; virtual void FreeLaunchDeviceMem() = 0; protected: void *stream_; kernel::KernelMod *kernel_mod_; std::vector outputs_addr_; std::vector workspaces_addr_; private: std::vector ObtainKernelAddress(const std::vector &list, std::vector *addr); std::vector ObtainKernelInputs(const std::vector &inputs_list, const std::vector &inputs_addr); std::vector ObtainKernelOutputs(const std::vector &outputs_list); std::vector ObtainKernelWorkspaces(const std::vector &workspaces_list); }; } // namespace mindspore::device #endif // MINDSPORE_MINDSPORE_CCSRC_RUNTIME_DEVICE_LAUNCH_KERNEL_H_