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.

tensor_load.h 2.2 kB

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_DEBUG_TENSOR_LOAD_H_
  17. #define MINDSPORE_CCSRC_DEBUG_TENSOR_LOAD_H_
  18. #include <memory>
  19. #include <vector>
  20. #include <map>
  21. #include <tuple>
  22. #include <string>
  23. #include "debug/tensor_data.h"
  24. namespace mindspore {
  25. class TensorLoader {
  26. public:
  27. TensorLoader() : iter_num(-1) {}
  28. ~TensorLoader() {}
  29. bool LoadNewTensor(std::shared_ptr<TensorData> tensor) {
  30. tensor_list.push_back(tensor);
  31. tensor_list_map.insert({tensor->GetName(), tensor});
  32. return true;
  33. }
  34. std::vector<std::shared_ptr<TensorData>> GetTensor() { return tensor_list; }
  35. uint32_t GetIterNum() { return iter_num; }
  36. std::map<std::string, std::shared_ptr<TensorData>> GetTensorMap() { return tensor_list_map; }
  37. void SearchTensors(const std::vector<std::string> &search_list,
  38. std::vector<std::tuple<std::string, std::shared_ptr<TensorData>>> *result_list) {
  39. for (auto i : search_list) {
  40. std::map<std::string, std::shared_ptr<TensorData>>::iterator iter;
  41. iter = tensor_list_map.find(i);
  42. if (iter != tensor_list_map.end()) {
  43. result_list->push_back(std::make_tuple(i, iter->second));
  44. } else {
  45. result_list->push_back(std::make_tuple(i, nullptr));
  46. }
  47. }
  48. }
  49. bool EmptyTensor() {
  50. tensor_list_map.clear();
  51. tensor_list.clear();
  52. return true;
  53. }
  54. void set_iter_num(uint32_t iter_num) { this->iter_num = iter_num; }
  55. private:
  56. std::vector<std::shared_ptr<TensorData>> tensor_list;
  57. std::map<std::string, std::shared_ptr<TensorData>> tensor_list_map;
  58. uint32_t iter_num;
  59. };
  60. } // namespace mindspore
  61. #endif // MINDSPORE_CCSRC_DEBUG_TENSOR_LOAD_H_