@@ -19,6 +19,18 @@ from templates import helper as th
1919 *
2020 */
2121# include "${x}_validation_layer.h"
22+ # include <sstream>
23+
24+ // Define a macro for marking potentially unused functions
25+ # if defined(_MSC_VER)
26+ // MSVC doesn't support __attribute__((unused)), just omit the marking
27+ #define VALIDATION_MAYBE_UNUSED
28+ # elif defined(__GNUC__) || defined(__clang__)
29+ // GCC and Clang support __attribute__((unused))
30+ #define VALIDATION_MAYBE_UNUSED __attribute__((unused))
31+ # else
32+ #define VALIDATION_MAYBE_UNUSED
33+ # endif
2234
2335namespace validation_layer
2436{
@@ -33,12 +45,68 @@ namespace validation_layer
3345 );
3446
3547%endif
36- static ze_result_t logAndPropagateResult(const char* fname, ze_result_t result) {
37- if (result != ${ X} _RESULT_SUCCESS) {
38- context.logger->log_trace("Error (" + loader::to_string(result) + ") in " + std::string(fname));
39- }
48+ // Generate specific logAndPropagateResult functions for each API function
49+ % for obj in th.extract_objs(specs, r " function" ):
50+ <%
51+ func_name = th.make_func_name(n, tags, obj)
52+ param_lines = [line for line in th.make_param_lines(n, tags, obj, format = [' name' ,' delim' ])]
53+ param_names = [line for line in th.make_param_lines(n, tags, obj, format = [' name' ])]
54+ is_void_params = len (param_lines) == 0
55+ %> \
56+ % if ' condition' in obj:
57+ # if ${th.subt(n, tags, obj['condition'])}
58+ %endif
59+ VALIDATION_MAYBE_UNUSED static ze_result_t logAndPropagateResult_${ func_name} (
60+ ze_result_t result\
61+ % if not is_void_params:
62+ ,
63+ % for line in th.make_param_lines(n, tags, obj):
64+ ${ line}
65+ %endfor
66+ %endif
67+ ) {
68+ std::string status = (result == ${ X} _RESULT_SUCCESS) ? "SUCCESS" : "ERROR";
69+ % if is_void_params:
70+ context.logger->log_trace(status + " (" + loader::to_string(result) + ") in ${ func_name} ()");
71+ % else :
72+ std::ostringstream oss;
73+ oss << status << " (" << loader::to_string(result) << ") in ${ func_name} (";
74+ % for i, param in enumerate ([p for p in th.make_param_lines(n, tags, obj, format = [' name' ])]):
75+ % if i > 0 :
76+ oss << ", ";
77+ %endif
78+ oss << "${ param} =" << loader::to_string(${ param} );
79+ %endfor
80+ oss << ")";
81+ context.logger->log_trace(oss.str());
82+ %endif
83+ return result;
84+ }
85+ % if ' condition' in obj:
86+ # endif // ${th.subt(n, tags, obj['condition'])}
87+ %endif
88+ %endfor
89+ \
90+ % if n == ' ze' :
91+ // Special function for zexCounterBasedEventCreate2
92+ VALIDATION_MAYBE_UNUSED static ze_result_t logAndPropagateResult_zexCounterBasedEventCreate2(
93+ ze_result_t result,
94+ ze_context_handle_t hContext,
95+ ze_device_handle_t hDevice,
96+ const void* desc,
97+ ze_event_handle_t* phEvent
98+ ) {
99+ std::string status = (result == ${ X} _RESULT_SUCCESS) ? "SUCCESS" : "ERROR";
100+ std::ostringstream oss;
101+ oss << status << " (" << loader::to_string(result) << ") in zexCounterBasedEventCreate2("
102+ << "hContext=" << static_cast<const void* >(hContext) << ", "
103+ << "hDevice=" << static_cast<const void* >(hDevice) << ", "
104+ << "desc=" << desc << ", "
105+ << "phEvent=" << static_cast<const void* >(phEvent) << ")";
106+ context.logger->log_trace(oss.str());
40107 return result;
41108 }
109+ %endif
42110
43111 % for obj in th.extract_objs(specs, r " function" ):
44112 <%
@@ -66,7 +134,7 @@ namespace validation_layer
66134
67135 if( nullptr == ${ th.make_pfn_name(n, tags, obj)} )
68136 % if ret_type == " ze_result_t" :
69- return logAndPropagateResult(" ${ th.make_func_name(n, tags, obj)} ", ${ X} _RESULT_ERROR_UNSUPPORTED_FEATURE);
137+ return logAndPropagateResult_ ${ th.make_func_name(n, tags, obj)} ( ${ X} _RESULT_ERROR_UNSUPPORTED_FEATURE${ ' , ' if not is_void_params else ' ' }${ ' , ' .join(th.make_param_lines(n, tags, obj, format = [ " name " ])) } );
70138 % else :
71139 return ${ failure_return} ;
72140 %endif
@@ -80,7 +148,7 @@ ${line} \
80148);
81149 if(result!=${ X} _RESULT_SUCCESS) \
82150% if ret_type == " ze_result_t" :
83- return logAndPropagateResult(" ${ th.make_func_name(n, tags, obj)} ", result );
151+ return logAndPropagateResult_ ${ th.make_func_name(n, tags, obj)} (result ${ ' , ' if not is_void_params else ' ' }${ ' , ' .join(th.make_param_lines(n, tags, obj, format = [ " name " ])) } );
84152% else :
85153return ${ failure_return} ;
86154%endif
@@ -103,7 +171,7 @@ ${line} \
103171);
104172 if(result!=${ X} _RESULT_SUCCESS) \
105173% if ret_type == " ze_result_t" :
106- return logAndPropagateResult(" ${ th.make_func_name(n, tags, obj)} ", result );
174+ return logAndPropagateResult_ ${ th.make_func_name(n, tags, obj)} (result ${ ' , ' if not is_void_params else ' ' }${ ' , ' .join(th.make_param_lines(n, tags, obj, format = [ " name " ])) } );
107175% else :
108176return ${ failure_return} ;
109177%endif
@@ -134,7 +202,7 @@ driver_result );
134202%endif
135203 if(result!=${ X} _RESULT_SUCCESS) \
136204% if ret_type == " ze_result_t" :
137- return logAndPropagateResult(" ${ th.make_func_name(n, tags, obj)} ", result );
205+ return logAndPropagateResult_ ${ th.make_func_name(n, tags, obj)} (result ${ ' , ' if not is_void_params else ' ' }${ ' , ' .join(th.make_param_lines(n, tags, obj, format = [ " name " ])) } );
138206% else :
139207return ${ failure_return} ;
140208%endif
@@ -173,7 +241,7 @@ return ${failure_return};
173241 }
174242 %endif
175243 % if ret_type == " ze_result_t" :
176- return logAndPropagateResult(" ${ th.make_func_name(n, tags, obj)} ", driver_result );
244+ return logAndPropagateResult_ ${ th.make_func_name(n, tags, obj)} (driver_result ${ ' , ' if not is_void_params else ' ' }${ ' , ' .join(th.make_param_lines(n, tags, obj, format = [ " name " ])) } );
177245 % else :
178246 return driver_result;
179247 %endif
@@ -203,7 +271,7 @@ return ${failure_return};
203271 auto numValHandlers = context.validationHandlers.size();
204272 for (size_t i = 0; i < numValHandlers; i++) {
205273 auto result = context.validationHandlers[i]->zeValidation->zexCounterBasedEventCreate2Prologue( hContext, hDevice, desc, phEvent );
206- if(result!=ZE_RESULT_SUCCESS) return logAndPropagateResult("zexCounterBasedEventCreate2", result );
274+ if(result!=ZE_RESULT_SUCCESS) return logAndPropagateResult_zexCounterBasedEventCreate2(result, hContext, hDevice, desc, phEvent );
207275 }
208276
209277 if(context.enableThreadingValidation){
@@ -212,7 +280,7 @@ return ${failure_return};
212280
213281 if(context.enableHandleLifetime){
214282 auto result = context.handleLifetime->zeHandleLifetime.zexCounterBasedEventCreate2Prologue( hContext, hDevice, desc, phEvent );
215- if(result!=ZE_RESULT_SUCCESS) return logAndPropagateResult("zexCounterBasedEventCreate2", result );
283+ if(result!=ZE_RESULT_SUCCESS) return logAndPropagateResult_zexCounterBasedEventCreate2(result, hContext, hDevice, desc, phEvent );
216284 }
217285
218286 // This is an experimental function that must be accessed through the extension mechanism
@@ -254,7 +322,7 @@ return ${failure_return};
254322
255323 for (size_t i = 0; i < numValHandlers; i++) {
256324 auto result = context.validationHandlers[i]->zeValidation->zexCounterBasedEventCreate2Epilogue( hContext, hDevice, desc, phEvent, driver_result);
257- if(result!=ZE_RESULT_SUCCESS) return logAndPropagateResult("zexCounterBasedEventCreate2", result );
325+ if(result!=ZE_RESULT_SUCCESS) return logAndPropagateResult_zexCounterBasedEventCreate2(result, hContext, hDevice, desc, phEvent );
258326 }
259327
260328 if(driver_result == ZE_RESULT_SUCCESS && context.enableHandleLifetime){
@@ -263,7 +331,7 @@ return ${failure_return};
263331 // Note: counter-based events may not have a traditional event pool dependency
264332 }
265333 }
266- return logAndPropagateResult("zexCounterBasedEventCreate2", driver_result );
334+ return logAndPropagateResult_zexCounterBasedEventCreate2(driver_result, hContext, hDevice, desc, phEvent );
267335 }
268336%endif
269337} // namespace validation_layer
0 commit comments