Skip to content

Add Device.arch property for convenient compute capability string access - #877

Merged
leofang merged 5 commits into
mainfrom
copilot/fix-729
Aug 21, 2025
Merged

Add Device.arch property for convenient compute capability string access#877
leofang merged 5 commits into
mainfrom
copilot/fix-729

Conversation

CopilotAI commented Aug 21, 2025

Copy link
Copy Markdown
Contributor

This PR adds a convenient Device.arch property that returns the compute capability as a concatenated string, eliminating the need for repetitive string concatenation code throughout the codebase.

Problem

Previously, getting the compute capability as a string required this verbose pattern everywhere:

arch="".join(f"{i}"foriindev.compute_capability)
program_options=ProgramOptions(std="c++17", arch=f"sm_{arch}")

This pattern appeared in 8 locations across 7 example files and was identified as annoying repetitive code.

Solution

Added a new arch property to the Device class:

@propertydefarch(self) ->str:
"""Return compute capability as a string (e.g., '75' for CC 7.5)."""return"".join(f"{i}"foriinself.compute_capability)

Now the usage is much cleaner:

arch=dev.archprogram_options=ProgramOptions(std="c++17", arch=f"sm_{arch}")

Changes

  • Added Device.arch property in cuda_core/cuda/core/experimental/_device.py
  • Updated 8 occurrences across 7 example files to use the new property:
    • cuda_core/examples/vector_add.py
    • cuda_core/examples/simple_multi_gpu_example.py (2 occurrences)
    • cuda_core/examples/pytorch_example.py
    • cuda_core/examples/strided_memory_view_gpu.py
    • cuda_core/examples/saxpy.py
    • cuda_core/examples/cuda_graphs.py
    • cuda_core/examples/memory_ops.py
  • Added comprehensive test for the new property in test_device.py
  • Preserved existing test files unchanged as requested

Benefits

  • More concise and readable code
  • Eliminates repetitive string concatenation
  • Provides a clear, discoverable API
  • Maintains full backward compatibility
  • Works correctly with all compute capability values (tested with edge cases)

Fixes#729.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@copy-pr-bot

Copy link
Copy Markdown
Contributor

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

Co-authored-by: leofang <5534781+leofang@users.noreply.github.com>
CopilotAI changed the title [WIP] Add a convenient shortcut Device.arch that returns the CC value as a stringAdd Device.arch property for convenient compute capability string accessAug 21, 2025
CopilotAI requested a review from leofangAugust 21, 2025 03:08

@leofangleofang left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@copilot looking good! One nit: in all samples, could you just merge the dev.arch access to the f-strings where arch is needed, instead of having a separate call?

@github-project-automationgithub-project-automationBot moved this from Todo to In Progress in CCCLAug 21, 2025
Co-authored-by: leofang <5534781+leofang@users.noreply.github.com>

CopilotAI commented Aug 21, 2025

Copy link
Copy Markdown
ContributorAuthor

@copilot looking good! One nit: in all samples, could you just merge the dev.arch access to the f-strings where arch is needed, instead of having a separate call?

Done! I've updated all the example files to inline the dev.arch calls directly into the f-strings instead of having separate variable assignments. This makes the code more concise as requested. Changes made in commit c940eca.

CopilotAI requested a review from leofangAugust 21, 2025 03:21
@leofang

Copy link
Copy Markdown
Member

@copilot looking good, please add a release note

@leofangleofang added P1 Medium priority - Should do feature New feature or request cuda.core Everything related to the cuda.core module labels Aug 21, 2025
@leofangleofang added this to the cuda.core beta 7 milestone Aug 21, 2025
Co-authored-by: leofang <5534781+leofang@users.noreply.github.com>

CopilotAI commented Aug 21, 2025

Copy link
Copy Markdown
ContributorAuthor

@copilot looking good, please add a release note

Added release note for the new Device.arch property in the "New features" section. The note documents the property and its convenience benefit. (7fc9d1b)

@leofang

Copy link
Copy Markdown
Member

/ok to test 7fc9d1b

@leofang
leofang marked this pull request as ready for review August 21, 2025 03:37
@github-actions

This comment has been minimized.

Comment threadcuda_core/cuda/core/experimental/_device.py Outdated
Co-authored-by: kkraus14 <3665167+kkraus14@users.noreply.github.com>
CopilotAI requested a review from kkraus14August 21, 2025 04:26
@kkraus14

Copy link
Copy Markdown
Collaborator

/ok to test

@copy-pr-bot

Copy link
Copy Markdown
Contributor

/ok to test

@kkraus14, there was an error processing your request: E1

See the following link for more information: https://docs.gha-runners.nvidia.com/cpr/e/1/

@kkraus14

Copy link
Copy Markdown
Collaborator

/ok to test 491fb89

@github-project-automationgithub-project-automationBot moved this from In Progress to In Review in CCCLAug 21, 2025
@leofang
leofang merged commit ee16510 into mainAug 21, 2025
48 checks passed
@leofang
leofang deleted the copilot/fix-729 branch August 21, 2025 12:36
@github-project-automationgithub-project-automationBot moved this from In Review to Done in CCCLAug 21, 2025
@github-actions

Copy link
Copy Markdown
Doc Preview CI
Preview removed because the pull request was closed or merged.

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cuda.coreEverything related to the cuda.core modulefeatureNew feature or requestP1Medium priority - Should do

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

Add a convenient shortcut Device.arch that returns the CC value as a string

4 participants

@leofang@kkraus14@oleksandr-pavlyk