Skip to content

Conversation

@wizenink
Copy link
Contributor

@wizenink wizenink commented Nov 1, 2025

Adds support for querying CUDA kernel/function properties like register usage, memory requirements, and compilation info.

Changes

  • Result layer: Added function::get_function_attribute() wrapper for cuFuncGetAttribute
  • Safe API: Added CudaFunction::get_attribute() and convenience methods:
    • num_regs() - registers per thread
    • shared_size_bytes() - static shared memory size
    • const_size_bytes() - constant memory size
    • local_size_bytes() - local memory per thread
    • max_threads_per_block() - thread limit
    • ptx_version() / binary_version() - compilation versions
  • Example: Added 10-function-attributes.rs demonstrating kernel introspection

Usage

let kernel = module.load_function("my_kernel")?;
println!("Registers: {}", kernel.num_regs()?);
println!("Shared mem: {} bytes", kernel.shared_size_bytes()?);

Useful for kernel optimization, debugging, and runtime capability checking.

@wizenink wizenink requested a review from coreylowman as a code owner November 1, 2025 12:22
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a safe API for querying CUDA function attributes, which is a valuable addition for kernel introspection. The implementation includes a low-level wrapper in result.rs, a high-level safe API in core.rs, and a clear example demonstrating the new functionality. The code is well-structured, but I've identified a significant thread-safety issue in the new CudaFunction::get_attribute method. It fails to bind the CUDA context to the calling thread, which can lead to errors in multi-threaded applications. I've provided a comment with a suggested fix to ensure correctness and thread-safety.

wizenink and others added 2 commits November 1, 2025 13:33
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
@wizenink
Copy link
Contributor Author

wizenink commented Nov 1, 2025

Should now pass cargo fmt

@coreylowman coreylowman merged commit 3f08f4f into coreylowman:main Nov 1, 2025
33 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants