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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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/rts/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, void *stream_ptr) {
  39. MS_LOG(INFO) << "Stream active op launch start";
  40. if (active_streams_index_.empty()) {
  41. MS_LOG(ERROR) << "activeStreamList_ is empty!";
  42. return false;
  43. }
  44. rtStream_t act_stream;
  45. rtError_t status;
  46. for (auto index : active_streams_index_) {
  47. act_stream = kernel::TaskStream::GetInstance()->gen_stream_list()[index];
  48. status = rtStreamActive(act_stream, stream_ptr);
  49. if (status != RT_ERROR_NONE) {
  50. MS_LOG(ERROR) << "Stream active failed!";
  51. return false;
  52. }
  53. }
  54. return true;
  55. }
  56. std::vector<TaskInfoPtr> StreamActiveKernel::GenTask(const std::vector<AddressPtr> &, const std::vector<AddressPtr> &,
  57. const std::vector<AddressPtr> &, uint32_t stream_id) {
  58. MS_LOG(INFO) << "StreamActiveKernel GenTask active stream size:" << active_streams_index_.size()
  59. << ", stream id:" << stream_id;
  60. stream_id_ = stream_id;
  61. std::vector<TaskInfoPtr> task_info_list;
  62. for (auto &index : active_streams_index_) {
  63. std::shared_ptr<StreamActiveTaskInfo> task_info_ptr = std::make_shared<StreamActiveTaskInfo>(stream_id, index);
  64. MS_EXCEPTION_IF_NULL(task_info_ptr);
  65. task_info_list.emplace_back(task_info_ptr);
  66. MS_LOG(INFO) << "StreamActiveKernel GenTask: streamId:" << stream_id << ", Active streamId:" << index;
  67. }
  68. return task_info_list;
  69. }
  70. } // namespace kernel
  71. } // namespace mindspore