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.

ascend_kernel_mod.h 2.5 kB

4 years ago
4 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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_BACKEND_KERNEL_COMPILER_ASCEND_KERNEL_MOD_H_
  17. #define MINDSPORE_CCSRC_BACKEND_KERNEL_COMPILER_ASCEND_KERNEL_MOD_H_
  18. #include <vector>
  19. #include <memory>
  20. #include "plugin/device/ascend/hal/device/ge_runtime/task_info.h"
  21. #include "kernel/kernel.h"
  22. #include "runtime/device/executor/dynamic_kernel.h"
  23. #ifndef ENABLE_SECURITY
  24. #include "debug/data_dump/dump_json_parser.h"
  25. #endif
  26. using TaskInfoPtr = std::shared_ptr<mindspore::ge::model_runner::TaskInfo>;
  27. namespace mindspore {
  28. namespace kernel {
  29. class AscendKernelMod : public KernelMod {
  30. public:
  31. AscendKernelMod() = default;
  32. explicit AscendKernelMod(const AnfNodePtr &anf_node_ptr) : KernelMod(anf_node_ptr) {}
  33. virtual std::vector<TaskInfoPtr> GenTask(const std::vector<AddressPtr> &, const std::vector<AddressPtr> &,
  34. const std::vector<AddressPtr> &, uint32_t) = 0;
  35. uint32_t block_dim() const { return block_dim_; }
  36. uint32_t stream_id() const { return stream_id_; }
  37. virtual bool NeedDump() {
  38. #ifndef ENABLE_SECURITY
  39. const auto &dump_json = DumpJsonParser::GetInstance();
  40. return dump_json.NeedDump(fullname_) && dump_json.async_dump_enabled() && dump_json.op_debug_mode() == 0 &&
  41. !is_monad_;
  42. #else
  43. return false;
  44. #endif
  45. }
  46. void UpdateOp() override;
  47. bool IsNeedUpdateOp() override;
  48. void InitDynamicKernel(const CNodePtr &cnode_ptr, void *stream) {
  49. if (dynamic_kernel_ == nullptr) {
  50. stream_ = stream;
  51. dynamic_kernel_ = GenDynamicKernel(cnode_ptr, stream);
  52. dynamic_kernel_->Initialize();
  53. }
  54. }
  55. device::DynamicKernelPtr DynamicKernel() const { return dynamic_kernel_; }
  56. protected:
  57. uint32_t block_dim_{1};
  58. uint32_t stream_id_{0};
  59. device::DynamicKernelPtr dynamic_kernel_{nullptr};
  60. };
  61. } // namespace kernel
  62. } // namespace mindspore
  63. #endif // MINDSPORE_CCSRC_BACKEND_KERNEL_COMPILER_ASCEND_KERNEL_MOD_H_