Skip to content

Commit

Permalink
Regards #670: Can now get a kernel's name using its handle
Browse files Browse the repository at this point in the history
  • Loading branch information
eyalroz committed Sep 5, 2024
1 parent c1725d7 commit b926805
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
11 changes: 11 additions & 0 deletions examples/by_api_module/execution_control.cu
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,17 @@ int main(int argc, char **argv)

auto kernel = cuda::kernel::get(device, kernel_function);

#if CUDA_VERSION >= 12030
cuda::kernel_t const& base_ref = kernel;
auto name_from_kernel = base_ref.name();
if (strcmp(name_from_kernel, kernel_name) != 0) {
std::cout
<< "CUDA reports a different name for kernel \"" << kernel_name
<< "\" via its handle: \"" << name_from_kernel << "\"" << std::endl;
return EXIT_FAILURE;
}
#endif

// ------------------------------------------
// Attributes without a specific API call
// ------------------------------------------
Expand Down
20 changes: 20 additions & 0 deletions src/cuda/api/kernel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,22 @@ inline void set_attribute_in_current_context(handle_t handle, attribute_t attrib
#endif
}

#if CUDA_VERSION >= 12030
inline const char * get_name_in_current_context(handle_t handle)
{
const char* result;
auto status = cuFuncGetName(&result, handle);
throw_if_error_lazy(status, "Failed obtaining the name for " + identify(handle));
return result;
}

inline const char * get_name(context::handle_t context_handle, handle_t kernel_handle)
{
CAW_SET_SCOPE_CONTEXT(context_handle);
return get_name_in_current_context(kernel_handle);
}
#endif // CUDA_VERSION >= 12300

} // namespace detail_

inline attribute_value_t get_attribute(const kernel_t& kernel, attribute_t attribute);
Expand Down Expand Up @@ -159,6 +175,10 @@ class kernel_t {
}
#endif

#if CUDA_VERSION >= 12030
const char *name() const { return cuda::kernel::detail_::get_name(context_handle_, handle_); }
#endif

public: // operators

kernel_t& operator=(const kernel_t&) = delete;
Expand Down

0 comments on commit b926805

Please sign in to comment.