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_MINDDATA_DATASET_UTIL_STATUS_H_ 17 #define MINDSPORE_CCSRC_MINDDATA_DATASET_UTIL_STATUS_H_ 18 19 #if defined(__GNUC__) || defined(__clang__) 20 #define DEPRECATED __attribute__((deprecated)) 21 #elif defined(_MSC_VER) 22 #define DEPRECATED __declspec(deprecated) 23 #else 24 #pragma message("WARNING: You need to implement DEPRECATED for this compiler") 25 #define DEPRECATED 26 #endif 27 28 #include <iostream> 29 #include <string> 30 #include <utility> 31 32 #include "include/api/status.h" 33 34 namespace mindspore { 35 namespace dataset { 36 #define RETURN_IF_NOT_OK(_s) \ 37 do { \ 38 Status __rc = (_s); \ 39 if (__rc.IsError()) { \ 40 return __rc; \ 41 } \ 42 } while (false) 43 44 #define RETURN_STATUS_UNEXPECTED(_e) \ 45 do { \ 46 return Status(StatusCode::kMDUnexpectedError, __LINE__, __FILE__, _e); \ 47 } while (false) 48 49 #define CHECK_FAIL_RETURN_UNEXPECTED(_condition, _e) \ 50 do { \ 51 if (!(_condition)) { \ 52 return Status(StatusCode::kMDUnexpectedError, __LINE__, __FILE__, _e); \ 53 } \ 54 } while (false) 55 56 #define CHECK_FAIL_RETURN_SYNTAX_ERROR(_condition, _e) \ 57 do { \ 58 if (!(_condition)) { \ 59 return Status(StatusCode::kMDSyntaxError, __LINE__, __FILE__, _e); \ 60 } \ 61 } while (false) 62 63 #define RETURN_UNEXPECTED_IF_NULL(_ptr) \ 64 do { \ 65 if ((_ptr) == nullptr) { \ 66 std::string err_msg = "The pointer[" + std::string(#_ptr) + "] is null."; \ 67 RETURN_STATUS_UNEXPECTED(err_msg); \ 68 } \ 69 } while (false) 70 71 #define RETURN_OK_IF_TRUE(_condition) \ 72 do { \ 73 if (_condition) { \ 74 return Status::OK(); \ 75 } \ 76 } while (false) 77 78 #define RETURN_STATUS_SYNTAX_ERROR(_e) \ 79 do { \ 80 return Status(StatusCode::kMDSyntaxError, __LINE__, __FILE__, _e); \ 81 } while (false) 82 83 #define RETURN_SECOND_IF_ERROR(_s, _r) \ 84 do { \ 85 Status __rc = (_s); \ 86 if (__rc.IsError()) { \ 87 MS_LOG(ERROR) << __rc; \ 88 return _r; \ 89 } \ 90 } while (false) 91 92 #if !defined(_WIN32) && !defined(_WIN64) 93 const float MAX_MEMORY_USAGE_THRESHOLD = 0.95; 94 float GetMemoryUsage(); 95 #endif 96 } // namespace dataset 97 } // namespace mindspore 98 #endif // MINDSPORE_CCSRC_MINDDATA_DATASET_UTIL_STATUS_H_ 99