mirror of
https://github.com/saymrwulf/onnxruntime.git
synced 2026-05-22 22:01:08 +00:00
Don't use free to satisfy Prefast requirements (#14354)
### Description Don't use free to satisfy Prefast requirements ### Motivation and Context Fix ADO#9004
This commit is contained in:
parent
4d9ddb5193
commit
3b8dfe2e27
2 changed files with 22 additions and 28 deletions
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
#include "core/providers/shared_library/provider_api.h"
|
||||
#include "shared_inc/cuda_call.h"
|
||||
#include <core/platform/env.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
#else // POSIX
|
||||
|
|
@ -86,19 +87,15 @@ const char* CudaErrString<ncclResult_t>(ncclResult_t e) {
|
|||
|
||||
template <typename ERRTYPE, bool THRW>
|
||||
std::conditional_t<THRW, void, Status> CudaCall(
|
||||
ERRTYPE retCode, const char* exprString, const char* libName, ERRTYPE successCode, const char* msg) {
|
||||
ERRTYPE retCode, const char* exprString, const char* libName, ERRTYPE successCode, const char* msg) {
|
||||
if (retCode != successCode) {
|
||||
try {
|
||||
#ifdef _WIN32
|
||||
auto del = [](char* p) { free(p); };
|
||||
std::unique_ptr<char, decltype(del)> hostname_ptr(nullptr, del);
|
||||
size_t hostname_len = 0;
|
||||
char* hostname = nullptr;
|
||||
//TODO: avoid using const_cast
|
||||
if (-1 == _dupenv_s(&hostname, &hostname_len, "COMPUTERNAME"))
|
||||
hostname = const_cast<char*>("?");
|
||||
else
|
||||
hostname_ptr.reset(hostname);
|
||||
std::string hostname_str = GetEnvironmentVar("COMPUTERNAME");
|
||||
if (hostname_str.empty()) {
|
||||
hostname_str = "?";
|
||||
}
|
||||
const char* hostname = hostname_str.c_str();
|
||||
#else
|
||||
char hostname[HOST_NAME_MAX];
|
||||
if (gethostname(hostname, HOST_NAME_MAX) != 0)
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
#include "core/providers/shared_library/provider_api.h"
|
||||
#include "shared_inc/rocm_call.h"
|
||||
#include <core/platform/env.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
#else // POSIX
|
||||
|
|
@ -25,13 +26,13 @@ const char* RocmErrString(ERRTYPE) {
|
|||
|
||||
template <>
|
||||
const char* RocmErrString<hipError_t>(hipError_t x) {
|
||||
(void)hipDeviceSynchronize(); // void to silence nodiscard
|
||||
ORT_IGNORE_RETURN_VALUE(hipDeviceSynchronize()); // void to silence nodiscard
|
||||
return hipGetErrorString(x);
|
||||
}
|
||||
|
||||
template <>
|
||||
const char* RocmErrString<rocblas_status>(rocblas_status e) {
|
||||
(void)hipDeviceSynchronize(); // void to silence nodiscard
|
||||
ORT_IGNORE_RETURN_VALUE(hipDeviceSynchronize()); // void to silence nodiscard
|
||||
|
||||
switch (e) {
|
||||
CASE_ENUM_TO_STR(rocblas_status_success);
|
||||
|
|
@ -54,19 +55,19 @@ const char* RocmErrString<rocblas_status>(rocblas_status e) {
|
|||
|
||||
template <>
|
||||
const char* RocmErrString<hiprandStatus_t>(hiprandStatus_t) {
|
||||
(void)hipDeviceSynchronize(); // void to silence nodiscard
|
||||
ORT_IGNORE_RETURN_VALUE(hipDeviceSynchronize()); // void to silence nodiscard
|
||||
return "(see hiprand.h & look for hiprandStatus_t or HIPRAND_STATUS_xxx)";
|
||||
}
|
||||
|
||||
template <>
|
||||
const char* RocmErrString<miopenStatus_t>(miopenStatus_t e) {
|
||||
(void)hipDeviceSynchronize(); // void to silence nodiscard
|
||||
ORT_IGNORE_RETURN_VALUE(hipDeviceSynchronize()); // void to silence nodiscard
|
||||
return miopenGetErrorString(e);
|
||||
}
|
||||
|
||||
template <>
|
||||
const char* RocmErrString<hipfftResult>(hipfftResult e) {
|
||||
(void)hipDeviceSynchronize(); // void to silence nodiscard
|
||||
ORT_IGNORE_RETURN_VALUE(hipDeviceSynchronize()); // void to silence nodiscard
|
||||
switch (e) {
|
||||
CASE_ENUM_TO_STR(HIPFFT_SUCCESS);
|
||||
CASE_ENUM_TO_STR(HIPFFT_ALLOC_FAILED);
|
||||
|
|
@ -82,34 +83,30 @@ const char* RocmErrString<hipfftResult>(hipfftResult e) {
|
|||
#ifdef ORT_USE_NCCL
|
||||
template <>
|
||||
const char* RocmErrString<ncclResult_t>(ncclResult_t e) {
|
||||
(void)hipDeviceSynchronize(); // void to silence nodiscard
|
||||
ORT_IGNORE_RETURN_VALUE(hipDeviceSynchronize()); // void to silence nodiscard
|
||||
return ncclGetErrorString(e);
|
||||
}
|
||||
#endif
|
||||
|
||||
template <typename ERRTYPE, bool THRW>
|
||||
std::conditional_t<THRW, void, Status> RocmCall(
|
||||
ERRTYPE retCode, const char* exprString, const char* libName, ERRTYPE successCode, const char* msg) {
|
||||
ERRTYPE retCode, const char* exprString, const char* libName, ERRTYPE successCode, const char* msg) {
|
||||
if (retCode != successCode) {
|
||||
try {
|
||||
#ifdef _WIN32
|
||||
auto del = [](char* p) { free(p); };
|
||||
std::unique_ptr<char, decltype(del)> hostname_ptr(nullptr, del);
|
||||
size_t hostname_len = 0;
|
||||
char* hostname = nullptr;
|
||||
//TODO: avoid using const_cast
|
||||
if (-1 == _dupenv_s(&hostname, &hostname_len, "COMPUTERNAME"))
|
||||
hostname = const_cast<char*>("?");
|
||||
else
|
||||
hostname_ptr.reset(hostname);
|
||||
std::string hostname_str = GetEnvironmentVar("COMPUTERNAME");
|
||||
if (hostname_str.empty()) {
|
||||
hostname_str = "?";
|
||||
}
|
||||
const char* hostname = hostname_str.c_str();
|
||||
#else
|
||||
char hostname[HOST_NAME_MAX];
|
||||
if (gethostname(hostname, HOST_NAME_MAX) != 0)
|
||||
strcpy(hostname, "?");
|
||||
#endif
|
||||
int currentHipDevice;
|
||||
(void)hipGetDevice(¤tHipDevice); // void to silence nodiscard
|
||||
(void)hipGetLastError(); // clear last ROCM error; void to silence nodiscard
|
||||
ORT_IGNORE_RETURN_VALUE(hipGetDevice(¤tHipDevice)); // void to silence nodiscard
|
||||
ORT_IGNORE_RETURN_VALUE(hipGetLastError()); // clear last ROCM error; void to silence nodiscard
|
||||
static char str[1024];
|
||||
snprintf(str, 1024, "%s failure %d: %s ; GPU=%d ; hostname=%s ; expr=%s; %s",
|
||||
libName, (int)retCode, RocmErrString(retCode), currentHipDevice,
|
||||
|
|
|
|||
Loading…
Reference in a new issue