Skip to content
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

[UR][Layer] Add Sanitizer Layer #1074

Merged
merged 78 commits into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
78 commits
Select commit Hold shift + click to select a range
4c9fe03
Add UR Sanitizer Layer
AllanZyne Nov 1, 2023
d6e589b
UR Sanitizer: Add shadow memory alloc & memset
AllanZyne Nov 1, 2023
67fcd5e
[UR][CUDA][L0][HIP] Add virtual memory adapter implementations
steffenlarsen Oct 9, 2023
1096b0f
Remove duplicate CUDA UR_DEVICE_INFO_VIRTUAL_MEMORY_SUPPORT case
steffenlarsen Oct 9, 2023
c36bd72
Fix return of check error
steffenlarsen Oct 9, 2023
6ba94ac
Fix common include in cuda device.hpp
steffenlarsen Oct 10, 2023
9ae8a99
Zero-initialize CUmemAccessDesc
steffenlarsen Oct 11, 2023
9f90e43
Add missing newline
steffenlarsen Oct 11, 2023
336ce89
Fix wrongful use of UR_ASSERT in cuda implementation
steffenlarsen Oct 13, 2023
84a3afa
an -> a
steffenlarsen Oct 13, 2023
a8dadc1
UR Sanitizer: fix bug
AllanZyne Nov 2, 2023
4d63350
UR Sanitizer: Add membuffer
AllanZyne Nov 3, 2023
25b1183
UR Sanitizer: Add membuffer red zone marker
AllanZyne Nov 3, 2023
e6bc306
UR Sanitizer: add membuffer check
AllanZyne Nov 6, 2023
23fb1b3
UR log
AllanZyne Nov 9, 2023
cb8a761
UR change directory
AllanZyne Nov 13, 2023
5c44b1d
UR refactor code
AllanZyne Nov 13, 2023
a377c94
UR refactor code
AllanZyne Nov 13, 2023
96eea7a
UR: WIP partition membuffer
AllanZyne Nov 14, 2023
0a72ea9
UR: clean code
AllanZyne Nov 14, 2023
8fa86dd
UR: clean code
AllanZyne Nov 14, 2023
d9a51a7
Revert "an -> a"
AllanZyne Nov 14, 2023
730bf45
Revert "Fix wrongful use of UR_ASSERT in cuda implementation"
AllanZyne Nov 14, 2023
fed541a
UR: refactor
AllanZyne Nov 14, 2023
ad2b1a7
Revert "Add missing newline"
AllanZyne Nov 14, 2023
dec5f32
Revert "Zero-initialize CUmemAccessDesc"
AllanZyne Nov 14, 2023
ca58886
Revert "Fix common include in cuda device.hpp"
AllanZyne Nov 14, 2023
11cca13
Revert "Fix return of check error"
AllanZyne Nov 14, 2023
3e6194e
Revert "Remove duplicate CUDA UR_DEVICE_INFO_VIRTUAL_MEMORY_SUPPORT c…
AllanZyne Nov 14, 2023
89febf0
Revert "[UR][CUDA][L0][HIP] Add virtual memory adapter implementations"
AllanZyne Nov 14, 2023
1b81df9
UR: revert gitignore
AllanZyne Nov 14, 2023
030400d
UR: cmake option
AllanZyne Nov 14, 2023
7208518
UR: clean code
AllanZyne Nov 14, 2023
668a11e
UR: clean code
AllanZyne Nov 14, 2023
f623135
UR: clean code
AllanZyne Nov 14, 2023
7be8667
UR: clean code
AllanZyne Nov 14, 2023
e4a47ac
UR: clean code
AllanZyne Nov 14, 2023
61c0ca9
UR: llvm license
AllanZyne Nov 14, 2023
0ad1bb1
UR: llvm license
AllanZyne Nov 14, 2023
cc4402a
UR: once
AllanZyne Nov 14, 2023
bf358c1
UR: clean code
AllanZyne Nov 14, 2023
d5e7946
UR: clean includes
AllanZyne Nov 14, 2023
50666b7
UR: clean comment
AllanZyne Nov 14, 2023
de03096
UR: rename files
AllanZyne Nov 14, 2023
b47ca29
UR: update readme
AllanZyne Nov 14, 2023
1e2b6a0
UR: fix according to PR comments
AllanZyne Nov 15, 2023
42f6755
UR: UR_ENABLE_SANITIZER=ON default
AllanZyne Nov 15, 2023
5aaba09
ignore VS clangd files
AllanZyne Nov 21, 2023
8dc90fd
fix comments
AllanZyne Nov 21, 2023
3b819f6
resolve comments
AllanZyne Nov 21, 2023
54220e9
resolve comments
AllanZyne Nov 21, 2023
2328b48
Merge branch 'main' into sanitizer-pr
AllanZyne Dec 8, 2023
e59d7c7
fix build errors
AllanZyne Dec 8, 2023
bba6f82
add basic test
AllanZyne Dec 8, 2023
a084650
fix warning & remove tests
AllanZyne Dec 9, 2023
1148ccb
fix warning
AllanZyne Dec 10, 2023
fa92f72
Merge branch 'main' into sanitizer-pr
AllanZyne Dec 10, 2023
524a83d
fix warning
AllanZyne Dec 10, 2023
e9a2093
fix fprintf
AllanZyne Dec 12, 2023
a1c4ddc
add some comments
AllanZyne Dec 12, 2023
71d8657
Merge branch 'main' into sanitizer-pr
AllanZyne Dec 13, 2023
40b5ef6
fix logger
AllanZyne Dec 19, 2023
0b00798
improve logger
AllanZyne Dec 19, 2023
b29930b
Merge branch 'main' into sanitizer-pr
AllanZyne Dec 19, 2023
c42bd9a
don't print prefix when logger::Level::QUIET
AllanZyne Dec 21, 2023
bc8cdb2
small fix
AllanZyne Dec 21, 2023
3bede09
small fix
AllanZyne Dec 21, 2023
5dc2d5c
fix KernelNameBuf
AllanZyne Dec 21, 2023
30c0bc1
follow the review comments
AllanZyne Jan 2, 2024
86d4056
fix build
AllanZyne Jan 2, 2024
49e2f4f
follow the review comments
AllanZyne Jan 2, 2024
79998b9
follow the review comments
AllanZyne Jan 2, 2024
6cc4913
fix urEnqueueKernelLaunch & remove host deviceinfo
AllanZyne Jan 4, 2024
577ddd3
fix build
AllanZyne Jan 5, 2024
4ee0e10
Merge branch 'main' into sanitizer-pr
AllanZyne Jan 5, 2024
dc127d5
fix build
AllanZyne Jan 9, 2024
b59d931
Merge branch 'main' into sanitizer-pr
AllanZyne Jan 16, 2024
28315db
fix build error
AllanZyne Jan 17, 2024
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
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,7 @@ out/

# External content
*/**/external

# VS clangd
/.cache
/compile_commands.json
AllanZyne marked this conversation as resolved.
Show resolved Hide resolved
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ option(UR_USE_UBSAN "enable UndefinedBehaviorSanitizer" OFF)
option(UR_USE_MSAN "enable MemorySanitizer" OFF)
option(UR_USE_TSAN "enable ThreadSanitizer" OFF)
option(UR_ENABLE_TRACING "enable api tracing through xpti" OFF)
option(UR_ENABLE_SANITIZER "enable device sanitizer" ON)
Copy link
Contributor

Choose a reason for hiding this comment

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

the names UR_ENABLE_SANITIZER and UR_USE_ASAN might be a little confusing in the sense that former is for device only and the latter is for host only. The difference isn't shown in the names.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I follow the same naming style as the tracing layer.

Copy link
Contributor

@wenju-he wenju-he Jan 2, 2024

Choose a reason for hiding this comment

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

I follow the same naming style as the tracing layer.

I think the confusing still exists even if it is the same naming style.

Copy link
Contributor Author

@AllanZyne AllanZyne Jan 2, 2024

Choose a reason for hiding this comment

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

I agree. IMO, the flag to enable layers needs a new naming style. @pbalcer

Copy link
Contributor

Choose a reason for hiding this comment

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

hmm, UR_ENABLE_LAYER_XYZ ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hmm, UR_ENABLE_LAYER_XYZ ?

Yes, this style is very similar to "UR_BUILD_ADAPTER_XYZ"

option(UMF_BUILD_SHARED_LIBRARY "Build UMF as shared library" OFF)
option(UMF_ENABLE_POOL_TRACKING "Build UMF with pool tracking" ON)
option(UR_BUILD_ADAPTER_L0 "Build the Level-Zero adapter" OFF)
Expand Down Expand Up @@ -121,6 +122,10 @@ if(UR_ENABLE_TRACING)
endif()
endif()

if(UR_ENABLE_SANITIZER)
add_compile_definitions(UR_ENABLE_SANITIZER)
endif()

if(UR_USE_ASAN)
add_sanitizer_flag(address)
endif()
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ List of options provided by CMake:
| UR_USE_UBSAN | Enable UndefinedBehavior Sanitizer | ON/OFF | OFF |
| UR_USE_MSAN | Enable MemorySanitizer (clang only) | ON/OFF | OFF |
| UR_ENABLE_TRACING | Enable XPTI-based tracing layer | ON/OFF | OFF |
| UR_ENABLE_SANITIZER | Enable device sanitizer layer | ON/OFF | ON |
| UR_CONFORMANCE_TARGET_TRIPLES | SYCL triples to build CTS device binaries for | Comma-separated list | spir64 |
| UR_BUILD_ADAPTER_L0 | Build the Level-Zero adapter | ON/OFF | OFF |
| UR_BUILD_ADAPTER_OPENCL | Build the OpenCL adapter | ON/OFF | OFF |
Expand Down
15 changes: 15 additions & 0 deletions scripts/core/INTRO.rst
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,15 @@ Unified Runtime loader implements tracing support through the `XPTI framework <h
| **user_data**: A pointer to `function_with_args_t` object, that includes function ID, name, arguments, and return value.
- None

Sanitizers
---------------------

Unified Runtime loader implements the runtime part of device-side sanitizers: AddressSanitizer (`UR_LAYER_ASAN`), MemorySanitizer (`UR_LAYER_MSAN`, planned), and ThreadSanitizer (`UR_LAYER_TSAN`, planned).

This layer shouldn't be enabled explicitly, for example, by the environment variable `UR_ENABLE_LAYERS`, but is enabled by program's runtime (e.g. SYCL/OpenMP Runtime) when the device code is compiled with flag `-fsanitize=address|memory|thread`.

Currently, AddressSanitizer only supports some of the devices on OpenCL and Level-Zero adapters, and this could be extended to support other devices and adapters if UR virtual memory APIs and shadow memory mapping in libdevice are supported.

Logging
---------------------

Expand Down Expand Up @@ -260,6 +269,8 @@ Layers currently included with the runtime are as follows:
- Enables UR_LAYER_PARAMETER_VALIDATION and UR_LAYER_LEAK_CHECKING.
* - UR_LAYER_TRACING
- Enables the XPTI tracing layer, see Tracing_ for more detail.
* - UR_LAYER_ASAN \| UR_LAYER_MSAN \| UR_LAYER_TSAN
- Enables the device-side sanitizer layer, see Sanitizers_ for more detail.

Environment Variables
---------------------
Expand All @@ -274,6 +285,10 @@ Specific environment variables can be set to control the behavior of unified run

Holds parameters for setting Unified Runtime null adapter logging. The syntax is described in the Logging_ section.

.. envvar:: UR_LOG_SANITIZER

Holds parameters for setting Unified Runtime sanitizer logging. The syntax is described in the Logging_ section.

.. envvar:: UR_LOG_VALIDATION

Holds parameters for setting Unified Runtime validation logging. The syntax is described in the Logging_ section.
Expand Down
5 changes: 5 additions & 0 deletions source/common/logger/ur_logger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ inline void error(const char *format, Args &&...args) {
get_logger().log(logger::Level::ERR, format, std::forward<Args>(args)...);
}

template <typename... Args>
inline void always(const char *format, Args &&...args) {
get_logger().always(format, std::forward<Args>(args)...);
}

inline void setLevel(logger::Level level) { get_logger().setLevel(level); }

inline void setFlushLevel(logger::Level level) {
Expand Down
8 changes: 8 additions & 0 deletions source/common/logger/ur_logger_details.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@ class Logger {
log(logger::Level::ERR, format, std::forward<Args>(args)...);
}

template <typename... Args>
void always(const char *format, Args &&...args) {
if (sink) {
sink->log(logger::Level::QUIET, format,
std::forward<Args>(args)...);
}
}

template <typename... Args>
void log(logger::Level level, const char *format, Args &&...args) {
if (level < this->level) {
Expand Down
2 changes: 1 addition & 1 deletion source/common/logger/ur_sinks.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class Sink {
template <typename... Args>
void log(logger::Level level, const char *fmt, Args &&...args) {
std::ostringstream buffer;
if (!skip_prefix) {
if (!skip_prefix && level != logger::Level::QUIET) {
buffer << "<" << logger_name << ">"
<< "[" << level_to_str(level) << "]: ";
}
Expand Down
17 changes: 17 additions & 0 deletions source/loader/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,23 @@ if(UR_ENABLE_TRACING)
)
endif()

if(UR_ENABLE_SANITIZER)
target_sources(ur_loader
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/../ur/ur.cpp
${CMAKE_CURRENT_SOURCE_DIR}/layers/sanitizer/asan_interceptor.cpp
${CMAKE_CURRENT_SOURCE_DIR}/layers/sanitizer/asan_interceptor.hpp
${CMAKE_CURRENT_SOURCE_DIR}/layers/sanitizer/common.hpp
${CMAKE_CURRENT_SOURCE_DIR}/layers/sanitizer/device_sanitizer_report.hpp
${CMAKE_CURRENT_SOURCE_DIR}/layers/sanitizer/ur_sanitizer_layer.cpp
${CMAKE_CURRENT_SOURCE_DIR}/layers/sanitizer/ur_sanitizer_layer.hpp
${CMAKE_CURRENT_SOURCE_DIR}/layers/sanitizer/ur_sanddi.cpp
)
target_include_directories(ur_loader PRIVATE
"${CMAKE_CURRENT_SOURCE_DIR}/../"
)
endif()


# link validation backtrace dependencies
if(UNIX)
Expand Down
Loading