-
Notifications
You must be signed in to change notification settings - Fork 181
Fix kernel attribute query when cuLaunchKernel uses CUkernel handles #521
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: dev
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 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -34,6 +34,19 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #define TRACER_VERSION "5" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| static int get_attr_with_kernel_fallback(CUfunction func, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| CUfunction_attribute attr) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| int value = 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| CUresult res = cuFuncGetAttribute(&value, attr, func); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (res == CUDA_ERROR_INVALID_HANDLE) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| CUdevice dev = 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (cuCtxGetDevice(&dev) == CUDA_SUCCESS) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| cuKernelGetAttribute(&value, attr, (CUkernel)func, dev); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+41
to
+46
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (res == CUDA_ERROR_INVALID_HANDLE) { | |
| CUdevice dev = 0; | |
| if (cuCtxGetDevice(&dev) == CUDA_SUCCESS) { | |
| cuKernelGetAttribute(&value, attr, (CUkernel)func, dev); | |
| } | |
| } | |
| if (res == CUDA_SUCCESS) { | |
| return value; | |
| } | |
| if (res == CUDA_ERROR_INVALID_HANDLE) { | |
| CUdevice dev = 0; | |
| CUresult dev_res = cuCtxGetDevice(&dev); | |
| if (dev_res == CUDA_SUCCESS) { | |
| CUresult kern_res = cuKernelGetAttribute(&value, attr, (CUkernel)func, dev); | |
| if (kern_res != CUDA_SUCCESS) { | |
| fprintf(stderr, | |
| "tracer_tool: cuKernelGetAttribute failed (attr=%d) with error %d\n", | |
| (int)attr, (int)kern_res); | |
| } | |
| } else { | |
| fprintf(stderr, | |
| "tracer_tool: cuCtxGetDevice failed with error %d while getting attribute %d\n", | |
| (int)dev_res, (int)attr); | |
| } | |
| } else { | |
| fprintf(stderr, | |
| "tracer_tool: cuFuncGetAttribute failed (attr=%d) with error %d\n", | |
| (int)attr, (int)res); | |
| } | |
| /* On any failure, return the default value (0) */ |
Copilot
AI
Dec 29, 2025
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.
The function should document its behavior when both cuFuncGetAttribute and cuKernelGetAttribute fail. Currently, it silently returns 0 (the initialized value) without any indication that the attribute query failed. This differs from the original implementation which used CUDA_SAFECALL to enforce error handling. Consider adding a comment explaining that 0 is returned on failure, or adding optional error logging.
| } | |
| } | |
| /* If both attribute queries fail, this function returns 0 (the default | |
| * initialized value) without reporting an error. Callers should treat 0 | |
| * as a possible "attribute unavailable" result. */ |
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.
If
cuCtxGetDevicefails, the function skips thecuKernelGetAttributecall and returns 0. However, it's unclear whether this is the intended behavior. Consider checking ifcuCtxGetDevicecan legitimately fail in scenarios wherecuFuncGetAttributereturns INVALID_HANDLE, and whether silently returning 0 is appropriate in such cases.