10
10
11
11
#include " common.hpp"
12
12
#include " logger/ur_logger.hpp"
13
+ #include " ur_api.h"
13
14
14
15
#include < cuda.h>
15
16
16
17
#include < sstream>
18
+ #include < string.h>
17
19
18
20
ur_result_t mapErrorUR (CUresult Result) {
19
21
switch (Result) {
@@ -105,6 +107,7 @@ void detail::ur::assertion(bool Condition, const char *Message) {
105
107
// Global variables for ZER_EXT_RESULT_ADAPTER_SPECIFIC_ERROR
106
108
thread_local ur_result_t ErrorMessageCode = UR_RESULT_SUCCESS;
107
109
thread_local char ErrorMessage[MaxMessageSize];
110
+ thread_local int32_t ErrorAdapterNativeCode = 0 ;
108
111
109
112
// Utility function for setting a message and warning
110
113
[[maybe_unused]] void setErrorMessage (const char *pMessage,
@@ -114,16 +117,24 @@ thread_local char ErrorMessage[MaxMessageSize];
114
117
ErrorMessageCode = ErrorCode;
115
118
}
116
119
117
- void setPluginSpecificMessage (CUresult cu_res) {
120
+ [[maybe_unused]] void setAdapterSpecificMessage (CUresult cu_res) {
121
+ ErrorAdapterNativeCode = static_cast <int32_t >(cu_res);
122
+ // according to the documentation of the cuGetErrorName and cuGetErrorString
123
+ // CUDA driver APIs, both error_name and error_string are null-terminated.
118
124
const char *error_string;
119
125
const char *error_name;
120
126
cuGetErrorName (cu_res, &error_name);
121
127
cuGetErrorString (cu_res, &error_string);
122
- char *message = (char *)malloc (strlen (error_string) + strlen (error_name) + 2 );
123
- strcpy (message, error_name);
124
- strcat (message, " \n " );
125
- strcat (message, error_string);
128
+ static constexpr char new_line[] = " \n " ;
129
+ // non-null-terminated sizes
130
+ const size_t error_string_size = std::strlen (error_string);
131
+ const size_t error_name_size = std::strlen (error_name);
132
+ char *message = reinterpret_cast <char *>(
133
+ std::malloc (error_string_size + error_name_size + sizeof (new_line)));
134
+ std::strcpy (message, error_name);
135
+ std::strcat (message, new_line);
136
+ std::strncat (message, error_string, error_string_size);
126
137
127
138
setErrorMessage (message, UR_RESULT_ERROR_ADAPTER_SPECIFIC);
128
- free (message);
139
+ std:: free (message);
129
140
}
0 commit comments