Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Aug 21, 2025

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}" for i in dev.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:

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

Now the usage is much cleaner:

arch = dev.arch
program_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 link
Contributor

copy-pr-bot bot commented Aug 21, 2025

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.

@Copilot Copilot AI changed the title [WIP] Add a convenient shortcut Device.arch that returns the CC value as a string Add Device.arch property for convenient compute capability string access Aug 21, 2025
@Copilot Copilot AI requested a review from leofang August 21, 2025 03:08
Copilot finished work on behalf of leofang August 21, 2025 03:08
Copy link
Member

@leofang leofang left a comment

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-automation github-project-automation bot moved this from Todo to In Progress in CCCL Aug 21, 2025
Copy link
Contributor Author

Copilot AI commented Aug 21, 2025

@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.

Copilot finished work on behalf of leofang August 21, 2025 03:21
@Copilot Copilot AI requested a review from leofang August 21, 2025 03:21
@leofang
Copy link
Member

leofang commented Aug 21, 2025

@copilot looking good, please add a release note

@leofang leofang added P1 Medium priority - Should do feature New feature or request cuda.core Everything related to the cuda.core module labels Aug 21, 2025
@leofang leofang added this to the cuda.core beta 7 milestone Aug 21, 2025
Copy link
Contributor Author

Copilot AI commented Aug 21, 2025

@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)

Copilot finished work on behalf of leofang August 21, 2025 03:30
@leofang
Copy link
Member

leofang commented Aug 21, 2025

/ok to test 7fc9d1b

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

This comment has been minimized.

@Copilot Copilot AI requested a review from kkraus14 August 21, 2025 04:26
Copilot finished work on behalf of kkraus14 August 21, 2025 04:26
@kkraus14
Copy link
Collaborator

/ok to test

Copy link
Contributor

copy-pr-bot bot commented Aug 21, 2025

/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
Collaborator

/ok to test 491fb89

@github-project-automation github-project-automation bot moved this from In Progress to In Review in CCCL Aug 21, 2025
@leofang leofang merged commit ee16510 into main Aug 21, 2025
48 checks passed
@leofang leofang deleted the copilot/fix-729 branch August 21, 2025 12:36
@github-project-automation github-project-automation bot moved this from In Review to Done in CCCL Aug 21, 2025
Copy link

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

Copilot AI added a commit that referenced this pull request Aug 21, 2025
…ess (#877)

* Initial plan

* Add Device.arch property and update examples to use it

Co-authored-by: leofang <[email protected]>

* Inline dev.arch calls in f-strings per PR feedback

Co-authored-by: leofang <[email protected]>

* Add release note for Device.arch property

Co-authored-by: leofang <[email protected]>

* Use f-string instead of "".join for Device.arch property

Co-authored-by: kkraus14 <[email protected]>

---------

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: leofang <[email protected]>
Co-authored-by: kkraus14 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cuda.core Everything related to the cuda.core module feature New feature or request P1 Medium 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