You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

gpu_kernel_runtime.h 3.1 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /**
  2. * Copyright 2019 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. #ifndef MINDSPORE_CCSRC_DEVICE_GPU_GPU_KERNEL_RUNTIME_H_
  17. #define MINDSPORE_CCSRC_DEVICE_GPU_GPU_KERNEL_RUNTIME_H_
  18. #include <string>
  19. #include <memory>
  20. #include <vector>
  21. #include <utility>
  22. #include <unordered_map>
  23. #include "device/kernel_runtime.h"
  24. #include "device/kernel_runtime_manager.h"
  25. namespace mindspore {
  26. namespace device {
  27. namespace gpu {
  28. class GPUKernelRuntime : public KernelRuntime {
  29. public:
  30. GPUKernelRuntime() = default;
  31. ~GPUKernelRuntime() override = default;
  32. bool Init() override;
  33. void ReleaseDeviceRes() override;
  34. void AssignMemory(session::KernelGraph *graph) override;
  35. bool Run(session::KernelGraph *graph) override;
  36. protected:
  37. DeviceAddressPtr CreateDeviceAddress(void *device_ptr, size_t device_size, const string &format,
  38. TypeId type_id) override;
  39. bool SyncStream() override;
  40. private:
  41. GPUKernelRuntime(const GPUKernelRuntime &);
  42. GPUKernelRuntime &operator=(const GPUKernelRuntime &);
  43. bool InitDevice();
  44. bool device_init_{false};
  45. // The related functions and members for using dynamic memory pool.
  46. void InitKernelRefCount(const session::KernelGraph *graph);
  47. void InitKernelOutputAddress(const session::KernelGraph *graph);
  48. bool LaunchKernelDynamic(const session::KernelGraph *graph);
  49. void AllocKernelDynamicRes(const mindspore::kernel::KernelMod &kernel_mod, const mindspore::AnfNodePtr &kernel,
  50. AddressPtrList *kernel_inputs, AddressPtrList *kernel_workspaces,
  51. AddressPtrList *kernel_outputs);
  52. void AllocCommunicationOpDynamicRes(const session::KernelGraph *graph);
  53. void AllocCommunicationOpInputDynamicRes(const mindspore::AnfNodePtr &kernel);
  54. void AllocCommunicationOpOutputDynamicRes(const mindspore::AnfNodePtr &kernel);
  55. void AllocCommunicationOpMemory(bool is_need_alloc_memory, bool is_need_free_memory,
  56. const DeviceAddressPtrList addr_list, size_t total_size,
  57. std::vector<size_t> size_list);
  58. void FreeKernelDynamicRes(const mindspore::AnfNodePtr &kernel, const AddressPtrList &kernel_workspaces,
  59. uint32_t graph_id);
  60. std::unordered_map<uint32_t, MemReuseUtilPtr> mem_reuse_util_map_;
  61. };
  62. MS_REG_KERNEL_RUNTIME(kGPUDevice, GPUKernelRuntime);
  63. } // namespace gpu
  64. } // namespace device
  65. } // namespace mindspore
  66. #endif // MINDSPORE_CCSRC_DEVICE_GPU_GPU_KERNEL_RUNTIME_H_