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.

gpu_common.h 6.8 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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_DEVICE_GPU_GPU_COMMON_H_
  17. #define MINDSPORE_CCSRC_DEVICE_GPU_GPU_COMMON_H_
  18. #include <iostream>
  19. #include <vector>
  20. #include <algorithm>
  21. #include "utils/log_adapter.h"
  22. namespace mindspore {
  23. namespace device {
  24. namespace gpu {
  25. #define CHECK_OP_RET_WITH_EXCEPT(expression, message) \
  26. { \
  27. bool success = (expression); \
  28. if (!success) { \
  29. MS_LOG(EXCEPTION) << "Op Error: " << message << " | Error Number: " << success; \
  30. } \
  31. }
  32. #define CHECK_OP_RET_WITH_ERROR(expression, message) \
  33. { \
  34. bool success = (expression); \
  35. if (!success) { \
  36. MS_LOG(ERROR) << "Op Error: " << message << " | Error Number: " << success; \
  37. } \
  38. }
  39. #define CHECK_CUDA_RET_WITH_ERROR(expression, message) \
  40. { \
  41. cudaError_t status = (expression); \
  42. if (status != cudaSuccess) { \
  43. MS_LOG(ERROR) << "CUDA Error: " << message << " | Error Number: " << status << " " \
  44. << cudaGetErrorString(status); \
  45. } \
  46. }
  47. #define CHECK_CUDA_RET_WITH_EXCEPT(expression, message) \
  48. { \
  49. cudaError_t status = (expression); \
  50. if (status != cudaSuccess) { \
  51. MS_LOG(EXCEPTION) << "CUDA Error: " << message << " | Error Number: " << status << " " \
  52. << cudaGetErrorString(status); \
  53. } \
  54. }
  55. #define CHECK_CUDNN_RET_WITH_EXCEPT(expression, message) \
  56. { \
  57. cudnnStatus_t status = (expression); \
  58. if (status != CUDNN_STATUS_SUCCESS) { \
  59. MS_LOG(EXCEPTION) << "cuDNN Error: " << message << " | Error Number: " << status << " " \
  60. << cudnnGetErrorString(status); \
  61. } \
  62. }
  63. #define CHECK_CUDNN_RET_WITH_ERROR(expression, message) \
  64. { \
  65. cudnnStatus_t status = (expression); \
  66. if (status != CUDNN_STATUS_SUCCESS) { \
  67. MS_LOG(ERROR) << "cuDNN Error: " << message << " | Error Number: " << status << " " \
  68. << cudnnGetErrorString(status); \
  69. } \
  70. }
  71. #define CHECK_CUBLAS_RET_WITH_EXCEPT(expression, message) \
  72. { \
  73. cublasStatus_t status = (expression); \
  74. if (status != CUBLAS_STATUS_SUCCESS) { \
  75. MS_LOG(EXCEPTION) << "cuBLAS Error: " << message << " | Error Number: " << status; \
  76. } \
  77. }
  78. #define CHECK_CUBLAS_RET_WITH_ERROR(expression, message) \
  79. { \
  80. cublasStatus_t status = (expression); \
  81. if (status != CUBLAS_STATUS_SUCCESS) { \
  82. MS_LOG(ERROR) << "cuBLAS Error: " << message << " | Error Number: " << status; \
  83. } \
  84. }
  85. #define CHECK_NCCL_RET_WITH_EXCEPT(expression, message) \
  86. { \
  87. int result = (expression); \
  88. if (result != ncclSuccess) { \
  89. MS_LOG(EXCEPTION) << "NCCL Error: " << message << " | Error Number: " << result; \
  90. } \
  91. }
  92. #define VARIABLE_NOT_USED(var) \
  93. { (void)(var); }
  94. inline bool CheckNullInput(std::vector<size_t> input_shape) {
  95. // If input_shape.size() == 0, it means a scalar input; If input_shape.size() != 0 and input_shape contains 0,
  96. // it means a null input. Just return a null output.
  97. if (input_shape.size() != 0) {
  98. if (std::any_of(input_shape.begin(), input_shape.end(), [](size_t i) { return i == 0; })) {
  99. return true;
  100. }
  101. }
  102. return false;
  103. }
  104. #define CHECK_NULL_INPUT(input_shape) mindspore::device::gpu::CheckNullInput(input_shape)
  105. } // namespace gpu
  106. } // namespace device
  107. } // namespace mindspore
  108. #endif // MINDSPORE_CCSRC_DEVICE_GPU_GPU_COMMON_H_