Skip to content

Expose CUDA function properties for Warp kernels #1805

Description

@shi-eric

Description

CUDA exposes properties of a compiled function through cuFuncGetAttribute(). Two of those properties are especially useful when inspecting generated kernel code:

  • CU_FUNC_ATTRIBUTE_NUM_REGS: registers used by each thread
  • CU_FUNC_ATTRIBUTE_LOCAL_SIZE_BYTES: local-memory bytes used by each thread

These are also available as numRegs and localSizeBytes in the CUDA Runtime API's cudaFuncAttributes structure.

Add public Warp functions for querying these properties:

  • wp.get_cuda_kernel_register_count(kernel, device=None, block_dim=None) -> int
  • wp.get_cuda_kernel_local_memory_size(kernel, device=None, block_dim=None) -> int

Both functions should query the forward CUDA function for the module variant selected by device and block_dim. Warp should compile and load the variant lazily if needed.

The queries should return the values reported by CUDA without launching the kernel or changing its launch attributes. The local-memory result includes compiler-generated spills and other thread-local storage, so it is not a spill-only metric.

Context

CUDA function properties depend on the compiled function and the device where it is loaded. They can change with the CUDA toolchain, compilation options, target architecture, Warp version, or block_dim.

Warp currently has no public way to read these properties. Exposing them would let users compare compiled kernel variants without relying on external CUDA tools or Warp internals.

The APIs would also provide useful measurements for the register-tuning options proposed in #1671.

Activity

  1. self-assigned this
    on Aug 14, 2026
  2. added this to the 1.17.0 milestone on Aug 14, 2026
  3. shi-eric commented on Aug 19, 2026

    @shi-eric
    ContributorAuthor

    This is addressed by 7336503.

    The implementation consolidates the two proposed scalar queries into wp.get_cuda_kernel_properties(), which returns register_count and local_memory_size in one extensible dictionary. It queries the compiled forward CUDA entry point for the requested device and block-dimension variant, compiling and loading that variant lazily when necessary, without launching the kernel or applying launch configuration.

    Public API behavior

    • Python scope: wp.get_cuda_kernel_properties(kernel, device=None, block_dim=None) returns the CUDA-reported register count and local-memory bytes per thread.
    • The two scalar functions proposed in the issue were replaced by one dictionary-returning function so future CUDA properties can be added without introducing another public function for each attribute.
    • Concrete generic-kernel overloads returned by wp.overload() are supported. Generic parent kernels, CPU devices, invalid kernels, and invalid block dimensions produce contextual errors.

    Test coverage

    • New warp/tests/cuda/test_kernel_attributes.py: TestKernelAttributes covers the returned property dictionary, the batched native query, block-dimension variant selection, module defaults, lazy compilation, and supported kernel forms.
    • The same test class checks validation and error reporting, forward-entry-point selection, module lifetime, and the absence of shared-memory or cluster configuration during inspection.
    • Modified warp/tests/cuda/test_occupancy.py: test_suggested_block_size_rejects_generic_parent covers the new generic-kernel error, while test_suggested_block_size_cpu confirms that generic kernels retain the existing CPU fallback.

    Behavioral verification

    An issue-shaped CUDA probe queried an unlaunched kernel at block_dim=64 and block_dim=128. Both variants returned valid properties and were loaded independently without executing the kernel or configuring shared-memory or cluster attributes. A subsequent explicit launch produced the expected output.

    Follow-up to consider

    • Add a positive CUDA test with device=None to cover the documented default-device path explicitly. This does not block closure because the implementation delegates to Warp's standard default-device resolver.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

feature requestRequest for something to be added

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions