Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Add API logging to validation layer #270

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,19 @@ user's home directory.

This feature is in early development and is preview only.

# Logging API calls
The Level Zero Loader will log all API calls whenever logging level is set to `trace` and
validation layer is enabled. Following variables need to be set to enable API logging:

`ZEL_ENABLE_LOADER_LOGGING=1`

`ZEL_LOADER_LOGGING_LEVEL=trace`

`ZE_ENABLE_VALIDATION_LAYER=1`

By default logs will be written to the log file, as described above. To print the logs
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Though not incorrect in this review, we may need to update the filename above at line 56 as it appears no longer valid according to current behavior. This may be a good time to update.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are they incorrect? From what I see, we still have LOADER_LOG_FILE_DIRECTORY defined as ".oneapi_logs" and LOADER_LOG_FILE as "ze_loader.log"

to stderr instead, `ZEL_LOADER_LOG_CONSOLE=1` needs to be set.

# Driver/Device Sorting

As of v1.20.3 of the Loader, Drivers and Devices reported to the user are sorted to enable the first device to be the best available device.
Expand Down
19 changes: 14 additions & 5 deletions scripts/templates/validation/valddi.cpp.mako
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ from templates import helper as th

namespace validation_layer
{
static ze_result_t logAndPropagateResult(const char* fname, ze_result_t result) {
if (result != ${X}_RESULT_SUCCESS) {
context.logger->log_trace("Error (" + loader::to_string(result) + ") in " + std::string(fname));
}
return result;
}

%for obj in th.extract_objs(specs, r"function"):
///////////////////////////////////////////////////////////////////////////////
/// @brief Intercept function for ${th.make_func_name(n, tags, obj)}
Expand All @@ -35,10 +42,12 @@ namespace validation_layer
%endfor
)
{
context.logger->log_trace("${th.make_func_name(n, tags, obj)}(${", ".join(th.make_param_lines(n, tags, obj, format=["name", "local"]))})");

auto ${th.make_pfn_name(n, tags, obj)} = context.${n}DdiTable.${th.get_table_name(n, tags, obj)}.${th.make_pfn_name(n, tags, obj)};

if( nullptr == ${th.make_pfn_name(n, tags, obj)} )
return ${X}_RESULT_ERROR_UNSUPPORTED_FEATURE;
return logAndPropagateResult("${th.make_func_name(n, tags, obj)}", ${X}_RESULT_ERROR_UNSUPPORTED_FEATURE);

auto numValHandlers = context.validationHandlers.size();
for (size_t i = 0; i < numValHandlers; i++) {
Expand All @@ -47,7 +56,7 @@ namespace validation_layer
${line} \
%endfor
);
if(result!=${X}_RESULT_SUCCESS) return result;
if(result!=${X}_RESULT_SUCCESS) return logAndPropagateResult("${th.make_func_name(n, tags, obj)}", result);
}


Expand All @@ -65,7 +74,7 @@ ${line} \
${line} \
%endfor
);
if(result!=${X}_RESULT_SUCCESS) return result;
if(result!=${X}_RESULT_SUCCESS) return logAndPropagateResult("${th.make_func_name(n, tags, obj)}", result);
}

auto driver_result = ${th.make_pfn_name(n, tags, obj)}( ${", ".join(th.make_param_lines(n, tags, obj, format=["name"]))} );
Expand All @@ -76,7 +85,7 @@ ${line} \
${line} \
%endfor
,driver_result);
if(result!=${X}_RESULT_SUCCESS) return result;
if(result!=${X}_RESULT_SUCCESS) return logAndPropagateResult("${th.make_func_name(n, tags, obj)}", result);
}

%if generate_post_call:
Expand Down Expand Up @@ -111,7 +120,7 @@ ${line} \
%endfor
}
%endif
return driver_result;
return logAndPropagateResult("${th.make_func_name(n, tags, obj)}", driver_result);
}
%if 'condition' in obj:
#endif // ${th.subt(n, tags, obj['condition'])}
Expand Down
3 changes: 3 additions & 0 deletions source/layers/validation/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,11 @@ target_include_directories(${TARGET_NAME}
${CMAKE_CURRENT_SOURCE_DIR}/handle_lifetime_tracking
${CMAKE_CURRENT_SOURCE_DIR}/checkers/parameter_validation
${CMAKE_CURRENT_SOURCE_DIR}/checkers/template
${CMAKE_CURRENT_SOURCE_DIR}/../../utils
)

target_link_libraries(${TARGET_NAME} PRIVATE level_zero_utils)

if(UNIX)
set(GCC_COVERAGE_COMPILE_FLAGS "-fvisibility=hidden -fvisibility-inlines-hidden")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GCC_COVERAGE_COMPILE_FLAGS}")
Expand Down
Loading
Loading