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.

dataset_utils.cc 1.7 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /**
  2. * Copyright 2020 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/gpu/data/dataset_utils.h"
  17. namespace mindspore {
  18. namespace kernel {
  19. size_t UnitSizeInBytes(const mindspore::TypeId &t) {
  20. size_t bytes = 0;
  21. switch (t) {
  22. case kNumberTypeBool:
  23. case kNumberTypeInt8:
  24. case kNumberTypeUInt8:
  25. bytes = 1;
  26. break;
  27. case kNumberTypeInt16:
  28. case kNumberTypeUInt16:
  29. case kNumberTypeFloat16:
  30. bytes = 2;
  31. break;
  32. case kNumberTypeInt:
  33. case kNumberTypeUInt:
  34. case kNumberTypeInt32:
  35. case kNumberTypeUInt32:
  36. case kNumberTypeFloat:
  37. case kNumberTypeFloat32:
  38. bytes = 4;
  39. break;
  40. case kNumberTypeUInt64:
  41. case kNumberTypeInt64:
  42. case kNumberTypeFloat64:
  43. bytes = 8;
  44. break;
  45. default:
  46. MS_LOG(EXCEPTION) << "Invalid types " << t;
  47. break;
  48. }
  49. return bytes;
  50. }
  51. int ElementNums(const std::vector<int> &shape) {
  52. if (shape.size() == 0) {
  53. return 0;
  54. }
  55. int nums = 1;
  56. for (size_t i = 0; i < shape.size(); i++) {
  57. nums *= shape[i];
  58. }
  59. return nums;
  60. }
  61. } // namespace kernel
  62. } // namespace mindspore