Skip to content

[BUG]: cuda-core: attributes.ptx_version() returns .target field, not .version from ptx file #627

Open

Description

@capybara-club

Is this a duplicate?

Type of Bug

Something else

Component

cuda.core

Describe the bug

test.ptx

.version 8.8
.target sm_86
.address_size 64

.visible .entry test_kernel()
{
	ret;
}

main.py

from cuda.core.experimental import Device, LaunchConfig, Program, ProgramOptions, launch, ObjectCode

dev = Device()
dev.set_current()
s = dev.create_stream()

mod = ObjectCode.from_ptx('test.ptx')

print(mod.get_kernel('test_kernel').attributes.num_regs())
print(mod.get_kernel('test_kernel').attributes.ptx_version())
print(mod.get_kernel('test_kernel').attributes.binary_version())

Prints

4
86
89

An aside, I am so excited for this library!

How to Reproduce

Run the above code

Expected behavior

I would expect ptx_version() to return the .version field from the ptx source.

Operating System

Ubuntu Linux 24.04

nvidia-smi output

+-----------------------------------------------------------------------------------------+
| NVIDIA-SMI 575.51.03              Driver Version: 576.28         CUDA Version: 12.9     |
|-----------------------------------------+------------------------+----------------------+
| GPU  Name                 Persistence-M | Bus-Id          Disp.A | Volatile Uncorr. ECC |
| Fan  Temp   Perf          Pwr:Usage/Cap |           Memory-Usage | GPU-Util  Compute M. |
|                                         |                        |               MIG M. |
|=========================================+========================+======================|
|   0  NVIDIA GeForce RTX 4090        On  |   00000000:01:00.0  On |                  Off |
|  0%   45C    P3             72W /  450W |    2921MiB /  24564MiB |      1%      Default |
|                                         |                        |                  N/A |
+-----------------------------------------+------------------------+----------------------+

+-----------------------------------------------------------------------------------------+
| Processes:                                                                              |
|  GPU   GI   CI              PID   Type   Process name                        GPU Memory |
|        ID   ID                                                               Usage      |
|=========================================================================================|
|  No running processes found                                                             |
+-----------------------------------------------------------------------------------------+

Activity

  1. leofang commented on May 12, 2025

    @leofang
    Member

    Hi @capybara-club

    An aside, I am so excited for this library!

    Thank you for your kind words! 🙏

    I would expect ptx_version() to return the .version field from the ptx source.

    I made the same mistake due to this admittedly confusing naming earlier. The underlying C attribute doc for .ptx_version() is not super clear about this, but it is the compute capability (-arch=compute_XX) used to generate the PTX. This corresponds to the .target field in your PTX.

    We could consider renaming .ptx_version() to .target_architecture() or .compute_capability() as suggested in NVIDIA/cccl#4081. Let me know what you think.

    AFAIK (others from our team can correct me if I am mistaken), there is no programmatic way to retrieve the PTX ISA version (.version 8.8 in your case). This bits of the PTX ISA doc is relevant: https://docs.nvidia.com/cuda/parallel-thread-execution/#ptx-module-directives.

    FWIW, since you use RTX 4090 the CC for which the PTX was loaded/JIT'd is 89, which is given by .binary_version().

  2. added
    triageNeeds the team's attention
    cuda.coreEverything related to the cuda.core module
    and removed
    bugSomething isn't working
    on May 12, 2025
  3. capybara-club commented on May 13, 2025

    @capybara-club
    Author

    Yeah, that's hard because even target_architecture might be a better name for binary_version knowing that binary_version comes from the device and not the ObjectCode object (i.e. 89 could be the architecture you're targeting).

    I do have a strange case just to maybe give you an anecdote. I'm going to try to avoid CUDAExtension and wheels and cu310,cu311 etc... So I'm planning on just precompiling ptx for sm80 to hit 11.8, 12.x and then use this to keep a pure python library for a user. I think this means I need to build it with ptx version 7.8 (from 11.8). Anyway that's why I tried to access ptx_version() expecting 8.8 or 8.0 or 7.8.

    It's a shame there might be a new generation of users using this library that never try setuptools, pybind11 and CUDAExtension that just have no idea what fun they're missing.

  4. removed this from the cuda.core backlog milestone on Apr 2, 2026
  5. github-actions commented on Nov 4, 2026

    @github-actions
    Contributor

    This issue has waited 7 days for the information we asked for. It will close in 7 days unless there is a reply. Comment here to keep it open.

  6. leofang commented on Nov 4, 2026

    @leofang
    Member

    Keep this.

  7. added this to the cuda.core 2.0.0 milestone on Nov 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    awaiting-responseFurther information is requestedbugSomething isn't workingcuda.coreEverything related to the cuda.core modulestale

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions