-
Notifications
You must be signed in to change notification settings - Fork 495
UCT/GDA/TEST: Add runtime config for device debug logs #10917
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| /** | ||
| * Copyright (c) NVIDIA CORPORATION & AFFILIATES, 2025. ALL RIGHTS RESERVED. | ||
| * | ||
| * See file LICENSE for terms. | ||
| */ | ||
|
|
||
| #ifndef UCS_CUDA_DEVICE_CUH | ||
| #define UCS_CUDA_DEVICE_CUH | ||
|
|
||
| #include <stdint.h> | ||
|
|
||
|
|
||
| /* Device function */ | ||
| #define UCS_F_DEVICE __device__ __forceinline__ static | ||
|
|
||
|
|
||
| /* Device library function */ | ||
| #define UCS_F_DEVICE_LIB __device__ | ||
|
|
||
|
|
||
| /* | ||
| * Read a 64-bit atomic value from a global memory address. | ||
| */ | ||
| UCS_F_DEVICE uint64_t ucs_device_atomic64_read(const uint64_t *ptr) | ||
| { | ||
| uint64_t ret; | ||
| asm volatile("ld.acquire.sys.global.u64 %0, [%1];" : "=l"(ret) : "l"(ptr)); | ||
| return ret; | ||
| } | ||
|
|
||
|
|
||
| /* | ||
| * Write a 64-bit value to counter global memory address. | ||
| */ | ||
| UCS_F_DEVICE void ucs_device_atomic64_write(uint64_t *ptr, uint64_t value) | ||
| { | ||
| asm volatile("st.release.sys.u64 [%0], %1;" | ||
| : | ||
| : "l"(ptr), "l"(value) | ||
| : "memory"); | ||
| } | ||
|
|
||
|
|
||
| /* | ||
| * Read the 64-bit GPU global nanosecond timer | ||
| */ | ||
| UCS_F_DEVICE uint64_t ucs_device_get_time_ns(void) | ||
| { | ||
| uint64_t globaltimer; | ||
| /* 64-bit GPU global nanosecond timer */ | ||
| asm volatile("mov.u64 %0, %globaltimer;" : "=l"(globaltimer)); | ||
| return globaltimer; | ||
| } | ||
|
|
||
| /* | ||
| * Load a constant from global memory. | ||
| */ | ||
| template<typename T> UCS_F_DEVICE T ucs_device_load_const(const T *ptr) | ||
| { | ||
| return __ldg(ptr); | ||
| } | ||
|
|
||
| template<> inline __device__ void *ucs_device_load_const(void *const *ptr) | ||
| { | ||
| return (void*)__ldg((uint64_t*)ptr); | ||
| } | ||
|
|
||
| #endif /* UCS_CUDA_DEVICE_CUH */ |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| /** | ||
| * Copyright (c) NVIDIA CORPORATION & AFFILIATES, 2025. ALL RIGHTS RESERVED. | ||
| * | ||
| * See file LICENSE for terms. | ||
| */ | ||
|
|
||
| #ifdef HAVE_CONFIG_H | ||
| #include "config.h" | ||
| #endif | ||
|
|
||
| #include "device_common.h" | ||
|
|
||
| #include <ucs/config/global_opts.h> | ||
|
|
||
| const char *ucs_device_level_names[] = {"thread", "warp", "block", "grid"}; | ||
|
|
||
| void ucs_device_log_config_init(ucs_device_log_config_t *config) | ||
| { | ||
| config->level = ucs_global_opts.device_log_level; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| /** | ||
| * Copyright (c) NVIDIA CORPORATION & AFFILIATES, 2025. ALL RIGHTS RESERVED. | ||
| * | ||
| * See file LICENSE for terms. | ||
| */ | ||
|
|
||
| #ifndef UCS_DEVICE_COMMON_H | ||
| #define UCS_DEVICE_COMMON_H | ||
|
|
||
| #include <ucs/config/types.h> | ||
| #include <stdint.h> | ||
|
|
||
| #ifdef __NVCC__ | ||
| #include "cuda_device.cuh" | ||
| #else | ||
| #include "stub_device.h" | ||
| #endif /* __NVCC__ */ | ||
|
|
||
| BEGIN_C_DECLS | ||
|
|
||
| /* Logging configuration for device functions */ | ||
| typedef struct { | ||
| uint8_t level; | ||
| } ucs_device_log_config_t; | ||
|
|
||
|
|
||
| /** | ||
| * @brief Cooperation level when calling device functions. | ||
| */ | ||
| typedef enum { | ||
| UCS_DEVICE_LEVEL_THREAD = 0, | ||
| UCS_DEVICE_LEVEL_WARP = 1, | ||
| UCS_DEVICE_LEVEL_BLOCK = 2, | ||
| UCS_DEVICE_LEVEL_GRID = 3 | ||
| } ucs_device_level_t; | ||
|
|
||
|
|
||
| /** Names for @ref ucs_device_level_t */ | ||
| extern const char *ucs_device_level_names[]; | ||
|
|
||
|
|
||
| /* Number of threads in a warp */ | ||
| #define UCS_DEVICE_NUM_THREADS_IN_WARP 32 | ||
|
|
||
|
|
||
| /* Initialize the logging configuration for device functions */ | ||
| void ucs_device_log_config_init(ucs_device_log_config_t *config); | ||
|
|
||
| END_C_DECLS | ||
|
|
||
| #endif /* UCS_DEVICE_COMMON_H */ |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,77 @@ | ||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||
| * Copyright (c) NVIDIA CORPORATION & AFFILIATES, 2025. ALL RIGHTS RESERVED. | ||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||
| * See file LICENSE for terms. | ||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| #ifndef UCS_DEVICE_LOG_H | ||||||||||||||||||||||||||
| #define UCS_DEVICE_LOG_H | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| #include "device_common.h" | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| #include <ucs/sys/compiler_def.h> | ||||||||||||||||||||||||||
| #include <ucs/config/types.h> | ||||||||||||||||||||||||||
| #include <stddef.h> | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| /* Maximal log level for which the logging code is compiled in. | ||||||||||||||||||||||||||
| Application kernels can override this value by defining | ||||||||||||||||||||||||||
| UCS_DEVICE_MAX_LOG_LEVEL before including this file. */ | ||||||||||||||||||||||||||
| #ifndef UCS_DEVICE_MAX_LOG_LEVEL | ||||||||||||||||||||||||||
| #define UCS_DEVICE_MAX_LOG_LEVEL UCS_LOG_LEVEL_DEBUG | ||||||||||||||||||||||||||
| #endif | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| /* Helper macro to print a message from a device function including the | ||||||||||||||||||||||||||
| * thread and block indices */ | ||||||||||||||||||||||||||
| #define ucs_device_log(_level, _log_config, _fmt, ...) \ | ||||||||||||||||||||||||||
| do { \ | ||||||||||||||||||||||||||
| if ((UCS_LOG_LEVEL_##_level <= UCS_DEVICE_MAX_LOG_LEVEL) && \ | ||||||||||||||||||||||||||
| (UCS_LOG_LEVEL_##_level <= (_log_config)->level)) { \ | ||||||||||||||||||||||||||
| const uint64_t _ts = ucs_device_get_time_ns(); \ | ||||||||||||||||||||||||||
| printf("[%06lu.%06lu] (%4d:%-3d) %10s:%-4d %-6s " _fmt "\n", \ | ||||||||||||||||||||||||||
| _ts / 1000000000ul, (_ts % 1000000000ul) / 1000ul, \ | ||||||||||||||||||||||||||
| threadIdx.x, blockIdx.x, \ | ||||||||||||||||||||||||||
| ucs_device_log_source_file(__FILE__), __LINE__, \ | ||||||||||||||||||||||||||
| UCS_LOG_LEVEL_NAME_##_level, ##__VA_ARGS__); \ | ||||||||||||||||||||||||||
| } \ | ||||||||||||||||||||||||||
| } while (0) | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| /* Log level names */ | ||||||||||||||||||||||||||
| #define UCS_LOG_LEVEL_NAME_ERROR "ERROR" | ||||||||||||||||||||||||||
| #define UCS_LOG_LEVEL_NAME_WARN "WARN" | ||||||||||||||||||||||||||
| #define UCS_LOG_LEVEL_NAME_DIAG "DIAG" | ||||||||||||||||||||||||||
| #define UCS_LOG_LEVEL_NAME_INFO "INFO" | ||||||||||||||||||||||||||
| #define UCS_LOG_LEVEL_NAME_DEBUG "DEBUG" | ||||||||||||||||||||||||||
| #define UCS_LOG_LEVEL_NAME_TRACE "TRACE" | ||||||||||||||||||||||||||
| #define UCS_LOG_LEVEL_NAME_TRACE_DATA "DATA" | ||||||||||||||||||||||||||
| #define UCS_LOG_LEVEL_NAME_TRACE_POLL "POLL" | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| static UCS_F_DEVICE_LIB const char *ucs_device_basename(const char *path) | ||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||
| const char *basename = path; | ||||||||||||||||||||||||||
| const char *p; | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| for (p = path; *p != '\0'; p++) { | ||||||||||||||||||||||||||
| if (*p == '/') { | ||||||||||||||||||||||||||
| basename = p + 1; | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| return basename; | ||||||||||||||||||||||||||
|
Comment on lines
+53
to
+62
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe use standard lib:
Suggested change
|
||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| UCS_F_DEVICE const char *ucs_device_log_source_file(const char *file) | ||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||
| static const char *cached_source_file = NULL; | ||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure if this caching is always safe |
||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| if (cached_source_file == NULL) { | ||||||||||||||||||||||||||
| cached_source_file = ucs_device_basename(file); | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| return cached_source_file; | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| #endif /* UCS_DEVICE_LOG_H */ | ||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we keep
errormacro for convinience?