@@ -19,6 +19,7 @@ from templates import helper as th
1919 *
2020 */
2121# include "${x}_validation_layer.h"
22+ # include <sstream>
2223
2324namespace validation_layer
2425{
@@ -33,12 +34,68 @@ namespace validation_layer
3334 );
3435
3536%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- }
37+ // Generate specific logAndPropagateResult functions for each API function
38+ % for obj in th.extract_objs(specs, r " function" ):
39+ <%
40+ func_name = th.make_func_name(n, tags, obj)
41+ param_lines = [line for line in th.make_param_lines(n, tags, obj, format = [' name' ,' delim' ])]
42+ param_names = [line for line in th.make_param_lines(n, tags, obj, format = [' name' ])]
43+ is_void_params = len (param_lines) == 0
44+ %> \
45+ % if ' condition' in obj:
46+ # if ${th.subt(n, tags, obj['condition'])}
47+ %endif
48+ __attribute__((unused)) static ze_result_t logAndPropagateResult_${ func_name} (
49+ ze_result_t result\
50+ % if not is_void_params:
51+ ,
52+ % for line in th.make_param_lines(n, tags, obj):
53+ ${ line}
54+ %endfor
55+ %endif
56+ ) {
57+ std::string status = (result == ${ X} _RESULT_SUCCESS) ? "SUCCESS" : "ERROR";
58+ % if is_void_params:
59+ context.logger->log_trace(status + " (" + loader::to_string(result) + ") in ${ func_name} ()");
60+ % else :
61+ std::ostringstream oss;
62+ oss << status << " (" << loader::to_string(result) << ") in ${ func_name} (";
63+ % for i, param in enumerate ([p for p in th.make_param_lines(n, tags, obj, format = [' name' ])]):
64+ % if i > 0 :
65+ oss << ", ";
66+ %endif
67+ oss << "${ param} =" << loader::to_string(${ param} );
68+ %endfor
69+ oss << ")";
70+ context.logger->log_trace(oss.str());
71+ %endif
4072 return result;
4173 }
74+ % if ' condition' in obj:
75+ # endif // ${th.subt(n, tags, obj['condition'])}
76+ %endif
77+ %endfor
78+ \
79+ % if n == ' ze' :
80+ // Special function for zexCounterBasedEventCreate2
81+ __attribute__((unused)) static ze_result_t logAndPropagateResult_zexCounterBasedEventCreate2(
82+ ze_result_t result,
83+ ze_context_handle_t hContext,
84+ ze_device_handle_t hDevice,
85+ const void* desc,
86+ ze_event_handle_t* phEvent
87+ ) {
88+ std::string status = (result == ${ X} _RESULT_SUCCESS) ? "SUCCESS" : "ERROR";
89+ std::ostringstream oss;
90+ oss << status << " (" << loader::to_string(result) << ") in zexCounterBasedEventCreate2("
91+ << "hContext=" << static_cast<const void* >(hContext) << ", "
92+ << "hDevice=" << static_cast<const void* >(hDevice) << ", "
93+ << "desc=" << desc << ", "
94+ << "phEvent=" << static_cast<const void* >(phEvent) << ")";
95+ context.logger->log_trace(oss.str());
96+ return result;
97+ }
98+ %endif
4299
43100 % for obj in th.extract_objs(specs, r " function" ):
44101 <%
@@ -66,7 +123,7 @@ namespace validation_layer
66123
67124 if( nullptr == ${ th.make_pfn_name(n, tags, obj)} )
68125 % if ret_type == " ze_result_t" :
69- return logAndPropagateResult(" ${ th.make_func_name(n, tags, obj)} ", ${ X} _RESULT_ERROR_UNSUPPORTED_FEATURE);
126+ 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 " ])) } );
70127 % else :
71128 return ${ failure_return} ;
72129 %endif
@@ -80,7 +137,7 @@ ${line} \
80137);
81138 if(result!=${ X} _RESULT_SUCCESS) \
82139% if ret_type == " ze_result_t" :
83- return logAndPropagateResult(" ${ th.make_func_name(n, tags, obj)} ", result );
140+ 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 " ])) } );
84141% else :
85142return ${ failure_return} ;
86143%endif
@@ -103,7 +160,7 @@ ${line} \
103160);
104161 if(result!=${ X} _RESULT_SUCCESS) \
105162% if ret_type == " ze_result_t" :
106- return logAndPropagateResult(" ${ th.make_func_name(n, tags, obj)} ", result );
163+ 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 " ])) } );
107164% else :
108165return ${ failure_return} ;
109166%endif
@@ -134,7 +191,7 @@ driver_result );
134191%endif
135192 if(result!=${ X} _RESULT_SUCCESS) \
136193% if ret_type == " ze_result_t" :
137- return logAndPropagateResult(" ${ th.make_func_name(n, tags, obj)} ", result );
194+ 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 " ])) } );
138195% else :
139196return ${ failure_return} ;
140197%endif
@@ -173,7 +230,7 @@ return ${failure_return};
173230 }
174231 %endif
175232 % if ret_type == " ze_result_t" :
176- return logAndPropagateResult(" ${ th.make_func_name(n, tags, obj)} ", driver_result );
233+ 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 " ])) } );
177234 % else :
178235 return driver_result;
179236 %endif
@@ -203,7 +260,7 @@ return ${failure_return};
203260 auto numValHandlers = context.validationHandlers.size();
204261 for (size_t i = 0; i < numValHandlers; i++) {
205262 auto result = context.validationHandlers[i]->zeValidation->zexCounterBasedEventCreate2Prologue( hContext, hDevice, desc, phEvent );
206- if(result!=ZE_RESULT_SUCCESS) return logAndPropagateResult("zexCounterBasedEventCreate2", result );
263+ if(result!=ZE_RESULT_SUCCESS) return logAndPropagateResult_zexCounterBasedEventCreate2(result, hContext, hDevice, desc, phEvent );
207264 }
208265
209266 if(context.enableThreadingValidation){
@@ -212,7 +269,7 @@ return ${failure_return};
212269
213270 if(context.enableHandleLifetime){
214271 auto result = context.handleLifetime->zeHandleLifetime.zexCounterBasedEventCreate2Prologue( hContext, hDevice, desc, phEvent );
215- if(result!=ZE_RESULT_SUCCESS) return logAndPropagateResult("zexCounterBasedEventCreate2", result );
272+ if(result!=ZE_RESULT_SUCCESS) return logAndPropagateResult_zexCounterBasedEventCreate2(result, hContext, hDevice, desc, phEvent );
216273 }
217274
218275 // This is an experimental function that must be accessed through the extension mechanism
@@ -254,7 +311,7 @@ return ${failure_return};
254311
255312 for (size_t i = 0; i < numValHandlers; i++) {
256313 auto result = context.validationHandlers[i]->zeValidation->zexCounterBasedEventCreate2Epilogue( hContext, hDevice, desc, phEvent, driver_result);
257- if(result!=ZE_RESULT_SUCCESS) return logAndPropagateResult("zexCounterBasedEventCreate2", result );
314+ if(result!=ZE_RESULT_SUCCESS) return logAndPropagateResult_zexCounterBasedEventCreate2(result, hContext, hDevice, desc, phEvent );
258315 }
259316
260317 if(driver_result == ZE_RESULT_SUCCESS && context.enableHandleLifetime){
@@ -263,7 +320,7 @@ return ${failure_return};
263320 // Note: counter-based events may not have a traditional event pool dependency
264321 }
265322 }
266- return logAndPropagateResult("zexCounterBasedEventCreate2", driver_result );
323+ return logAndPropagateResult_zexCounterBasedEventCreate2(driver_result, hContext, hDevice, desc, phEvent );
267324 }
268325%endif
269326} // namespace validation_layer
0 commit comments