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.

util.cc 1.9 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /**
  2. * Copyright 2022 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 "include/transform/graph_ir/util.h"
  17. #include <utility>
  18. #include <map>
  19. #include "securec/include/securec.h"
  20. #include "include/common/utils/convert_utils.h"
  21. #include "include/common/utils/utils.h"
  22. namespace mindspore {
  23. namespace transform {
  24. const size_t kErrorSize = 0;
  25. static std::map<MeDataType, size_t> datatype_size_map = {
  26. {MeDataType::kNumberTypeFloat16, sizeof(float) / 2}, {MeDataType::kNumberTypeFloat32, sizeof(float)}, // 1/2 of float
  27. {MeDataType::kNumberTypeFloat64, sizeof(double)}, {MeDataType::kNumberTypeInt8, sizeof(int8_t)},
  28. {MeDataType::kNumberTypeInt16, sizeof(int16_t)}, {MeDataType::kNumberTypeInt32, sizeof(int32_t)},
  29. {MeDataType::kNumberTypeInt64, sizeof(int64_t)}, {MeDataType::kNumberTypeUInt8, sizeof(uint8_t)},
  30. {MeDataType::kNumberTypeUInt16, sizeof(uint16_t)}, {MeDataType::kNumberTypeUInt32, sizeof(uint32_t)},
  31. {MeDataType::kNumberTypeUInt64, sizeof(uint64_t)}, {MeDataType::kNumberTypeBool, sizeof(bool)}};
  32. size_t TransformUtil::GetDataTypeSize(const MeDataType &type) {
  33. if (datatype_size_map.find(type) != datatype_size_map.end()) {
  34. return datatype_size_map[type];
  35. } else {
  36. MS_LOG(ERROR) << "Illegal tensor data type!";
  37. return kErrorSize;
  38. }
  39. }
  40. } // namespace transform
  41. } // namespace mindspore