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_ASCEND_ASCEND_LAUNCH_ATOMIC_CLEAN_H_ 18 #define MINDSPORE_MINDSPORE_CCSRC_RUNTIME_DEVICE_ASCEND_ASCEND_LAUNCH_ATOMIC_CLEAN_H_ 19 20 #include <vector> 21 #include <memory> 22 #include "runtime/device/ascend/ascend_launch_kernel.h" 23 24 namespace mindspore::device::ascend { 25 class AscendLaunchAtomicClean : public AscendLaunchKernel { 26 public: AscendLaunchAtomicClean(void * stream,TypeId dtype,size_t total_size)27 AscendLaunchAtomicClean(void *stream, TypeId dtype, size_t total_size) 28 : AscendLaunchKernel(stream), 29 dtype_(dtype), 30 total_size_(total_size), 31 atomic_clean_graph_(nullptr), 32 input_addr_(nullptr) {} 33 ~AscendLaunchAtomicClean() override = default; 34 SetInputAddr(uint8_t * input_addr)35 void SetInputAddr(uint8_t *input_addr) override { input_addr_ = input_addr; } 36 void FreeDeviceMem(void *addr) override; 37 size_t AlignSizeForLaunchKernel(size_t size) override; 38 uint8_t *AllocDeviceMem(size_t size) override; 39 void KernelSelect(const std::shared_ptr<session::KernelGraph> &kernel_graph) override; 40 void KernelBuild(const std::shared_ptr<session::KernelGraph> &kernel_graph) override; 41 42 void LaunchOpKernel() override; 43 void FreeLaunchDeviceMem() override; 44 45 protected: 46 TypeId dtype_; 47 size_t total_size_; 48 std::shared_ptr<session::KernelGraph> atomic_clean_graph_; 49 uint8_t *input_addr_; 50 51 private: 52 std::shared_ptr<session::KernelGraph> ObtainAtomicCleanKernelGraph(); 53 void ConstructKernelGraphAndSetAttr(); 54 }; 55 } // namespace mindspore::device::ascend 56 57 #endif // MINDSPORE_MINDSPORE_CCSRC_RUNTIME_DEVICE_ASCEND_ASCEND_LAUNCH_ATOMIC_CLEAN_H_ 58