11// Copyright (c) Microsoft Corporation. All rights reserved.
22// Licensed under the MIT License.
33
4+ #ifdef _WIN32
5+ #include < winsock.h>
6+ #else
47#include < unistd.h>
5- #include < string.h >
6- # include < miopen/miopen.h >
7- #include < rocblas/rocblas.h >
8+ #endif
9+
10+ #include < string >
811#include " core/common/common.h"
912#include " core/common/status.h"
1013#include " core/providers/shared_library/provider_api.h"
@@ -34,16 +37,20 @@ std::conditional_t<THRW, void, Status> RocmCall(
3437 ERRTYPE retCode, const char * exprString, const char * libName, ERRTYPE successCode, const char * msg, const char * file, const int line) {
3538 if (retCode != successCode) {
3639 try {
37- char hostname[HOST_NAME_MAX];
38- if (gethostname (hostname, HOST_NAME_MAX) != 0 )
39- strcpy (hostname, " ?" );
40+ #ifdef _WIN32
41+ // According to the POSIX spec, 255 is the safe minimum value.
42+ static constexpr int HOST_NAME_MAX = 255 ;
43+ #endif
44+ std::string hostname (HOST_NAME_MAX, 0 );
45+ if (gethostname (hostname.data (), HOST_NAME_MAX) != 0 )
46+ hostname = " ?" ;
4047 int currentHipDevice;
4148 (void )hipGetDevice (¤tHipDevice);
4249 (void )hipGetLastError (); // clear last HIP error
4350 static char str[1024 ];
4451 snprintf (str, 1024 , " %s failure %d: %s ; GPU=%d ; hostname=%s ; file=%s ; line=%d ; expr=%s; %s" ,
4552 libName, (int )retCode, RocmErrString (retCode), currentHipDevice,
46- hostname,
53+ hostname. c_str () ,
4754 file, line, exprString, msg);
4855 if constexpr (THRW) {
4956 // throw an exception with the error info
@@ -68,9 +75,5 @@ std::conditional_t<THRW, void, Status> RocmCall(
6875
6976template Status RocmCall<hipError_t, false >(hipError_t retCode, const char * exprString, const char * libName, hipError_t successCode, const char * msg, const char * file, const int line);
7077template void RocmCall<hipError_t, true >(hipError_t retCode, const char * exprString, const char * libName, hipError_t successCode, const char * msg, const char * file, const int line);
71- template Status RocmCall<rocblas_status, false >(rocblas_status retCode, const char * exprString, const char * libName, rocblas_status successCode, const char * msg, const char * file, const int line);
72- template void RocmCall<rocblas_status, true >(rocblas_status retCode, const char * exprString, const char * libName, rocblas_status successCode, const char * msg, const char * file, const int line);
73- template Status RocmCall<miopenStatus_t, false >(miopenStatus_t retCode, const char * exprString, const char * libName, miopenStatus_t successCode, const char * msg, const char * file, const int line);
74- template void RocmCall<miopenStatus_t, true >(miopenStatus_t retCode, const char * exprString, const char * libName, miopenStatus_t successCode, const char * msg, const char * file, const int line);
7578
7679} // namespace onnxruntime
0 commit comments