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.

stream_active.cc 3.1 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. #include "kernel/mng/stream_active.h"
  17. #include <asm-generic/param.h>
  18. #include <memory>
  19. #include "runtime/stream.h"
  20. #include "framework/ge_runtime/task_info.h"
  21. #include "session/anf_runtime_algorithm.h"
  22. #include "common/utils.h"
  23. using ge::model_runner::StreamActiveTaskInfo;
  24. using StreamActiveTaskInfoPtr = std::shared_ptr<StreamActiveTaskInfo>;
  25. namespace mindspore {
  26. namespace kernel {
  27. StreamActiveKernel::StreamActiveKernel() { active_streams_index_ = {}; }
  28. StreamActiveKernel::~StreamActiveKernel() {}
  29. bool StreamActiveKernel::Init(const AnfNodePtr &anf_node) {
  30. MS_EXCEPTION_IF_NULL(anf_node);
  31. MS_LOG(INFO) << "stream active op init start";
  32. auto primitive = AnfAlgo::GetCNodePrimitive(anf_node);
  33. MS_EXCEPTION_IF_NULL(primitive);
  34. active_streams_index_ = GetValue<std::vector<uint32_t>>(primitive->GetAttr(kAttrActiveStreamList));
  35. return true;
  36. }
  37. bool StreamActiveKernel::Launch(const std::vector<AddressPtr> &inputs, const std::vector<AddressPtr> &workspace,
  38. const std::vector<AddressPtr> &outputs, uintptr_t stream_ptr) {
  39. MS_LOG(INFO) << "Stream active op launch start";
  40. auto stream = reinterpret_cast<rtStream_t>(stream_ptr);
  41. if (active_streams_index_.empty()) {
  42. MS_LOG(ERROR) << "activeStreamList_ is empty!";
  43. return false;
  44. }
  45. rtStream_t act_stream;
  46. rtError_t status;
  47. for (auto index : active_streams_index_) {
  48. act_stream = kernel::TaskStream::GetInstance()->gen_stream_list()[index];
  49. status = rtStreamActive(act_stream, stream);
  50. if (status != RT_ERROR_NONE) {
  51. MS_LOG(ERROR) << "Stream active failed!";
  52. return false;
  53. }
  54. }
  55. return true;
  56. }
  57. std::vector<TaskInfoPtr> StreamActiveKernel::GenTask(const std::vector<AddressPtr> &, const std::vector<AddressPtr> &,
  58. const std::vector<AddressPtr> &, uint32_t stream_id) {
  59. MS_LOG(INFO) << "StreamActiveKernel GenTask active stream size:" << active_streams_index_.size()
  60. << ", stream id:" << stream_id;
  61. stream_id_ = stream_id;
  62. std::vector<TaskInfoPtr> task_info_list;
  63. for (auto &index : active_streams_index_) {
  64. std::shared_ptr<StreamActiveTaskInfo> task_info_ptr = std::make_shared<StreamActiveTaskInfo>(stream_id, index);
  65. MS_EXCEPTION_IF_NULL(task_info_ptr);
  66. task_info_list.emplace_back(task_info_ptr);
  67. MS_LOG(INFO) << "StreamActiveKernel GenTask: streamId:" << stream_id << ", Active streamId:" << index;
  68. }
  69. return task_info_list;
  70. }
  71. } // namespace kernel
  72. } // namespace mindspore