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.

launch_kernel.h 2.4 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. #ifndef MINDSPORE_MINDSPORE_CCSRC_RUNTIME_DEVICE_LAUNCH_KERNEL_H_
  17. #define MINDSPORE_MINDSPORE_CCSRC_RUNTIME_DEVICE_LAUNCH_KERNEL_H_
  18. #include <vector>
  19. #include <memory>
  20. #include "backend/session/kernel_graph.h"
  21. namespace mindspore::device {
  22. class LaunchKernel {
  23. public:
  24. explicit LaunchKernel(void *stream) : stream_(stream), kernel_mod_(nullptr) {}
  25. virtual ~LaunchKernel() = default;
  26. std::vector<uint8_t *> GetKernelOutputAddr() { return outputs_addr_; }
  27. void LaunchSingleKernel(const std::vector<uint8_t *> &inputs_addr);
  28. void FreeOutputAndWorkspaceDeviceMem();
  29. virtual void FreeDeviceMem(void *addr) = 0;
  30. virtual size_t AlignSizeForLaunchKernel(size_t size) = 0;
  31. virtual uint8_t *AllocDeviceMem(size_t size) = 0;
  32. virtual void KernelSelect(std::shared_ptr<session::KernelGraph> kernel_graph) = 0;
  33. virtual void KernelBuild(std::shared_ptr<session::KernelGraph> kernel_graph) = 0;
  34. virtual void SetInputAddr(uint8_t *input_addr) = 0;
  35. virtual void LaunchOpKernel() = 0;
  36. virtual void FreeLaunchDeviceMem() = 0;
  37. protected:
  38. void *stream_;
  39. kernel::KernelMod *kernel_mod_;
  40. std::vector<uint8_t *> outputs_addr_;
  41. std::vector<uint8_t *> workspaces_addr_;
  42. std::vector<kernel::AddressPtr> ObtainKernelAddress(const std::vector<size_t> &list, std::vector<uint8_t *> *addr);
  43. std::vector<kernel::AddressPtr> ObtainKernelInputs(const std::vector<size_t> &inputs_list,
  44. const std::vector<uint8_t *> &inputs_addr);
  45. std::vector<kernel::AddressPtr> ObtainKernelOutputs(const std::vector<size_t> &outputs_list);
  46. std::vector<kernel::AddressPtr> ObtainKernelWorkspaces(const std::vector<size_t> &workspaces_list);
  47. };
  48. } // namespace mindspore::device
  49. #endif // MINDSPORE_MINDSPORE_CCSRC_RUNTIME_DEVICE_LAUNCH_KERNEL_H_