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.

task_stream.h 2.2 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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_KERNEL_TASK_STREAM_H_
  17. #define MINDSPORE_CCSRC_KERNEL_TASK_STREAM_H_
  18. #include <new>
  19. #include <unordered_map>
  20. #include <vector>
  21. #include <memory>
  22. #include "runtime/base.h"
  23. #include "utils/log_adapter.h"
  24. namespace mindspore {
  25. namespace kernel {
  26. class TaskStream {
  27. public:
  28. TaskStream() = default;
  29. ~TaskStream() = default;
  30. static std::shared_ptr<TaskStream> GetInstance() {
  31. static const std::shared_ptr<TaskStream> instance = std::make_shared<TaskStream>();
  32. return instance;
  33. }
  34. void set_gen_stream_list(const std::vector<rtStream_t> &stream_list) { gen_stream_list_ = stream_list; }
  35. void set_run_stream_list(const std::vector<rtStream_t> &stream_list) { run_stream_list_ = stream_list; }
  36. void SetGenStreamIndex(uint32_t stream_id, uint32_t index) { gen_stream_index_map_[stream_id] = index; }
  37. std::unordered_map<uint32_t, uint32_t> GetGenStreamIndexMap() { return gen_stream_index_map_; }
  38. uint32_t GetGenStreamIndex(uint32_t stream_id) {
  39. auto iter = gen_stream_index_map_.find(stream_id);
  40. if (iter == gen_stream_index_map_.end()) {
  41. MS_LOG(EXCEPTION) << "stream_id not in gen_stream_index_map_";
  42. }
  43. return iter->second;
  44. }
  45. const std::vector<rtStream_t> &gen_stream_list() const { return gen_stream_list_; }
  46. const std::vector<rtStream_t> &run_stream_list() const { return run_stream_list_; }
  47. private:
  48. std::vector<rtStream_t> gen_stream_list_;
  49. std::vector<rtStream_t> run_stream_list_;
  50. std::unordered_map<uint32_t, uint32_t> gen_stream_index_map_;
  51. };
  52. } // namespace kernel
  53. } // namespace mindspore
  54. #endif // MINDSPORE_CCSRC_KERNEL_TASK_STREAM_H_