cuda-python icon indicating copy to clipboard operation
cuda-python copied to clipboard

[doc-only] Add developer guide for cuda.core

Open Andy-Jost opened this issue 2 months ago • 18 comments

Summary

This PR adds a developer guide for Python and Cython code in cuda/core. The guide establishes conventions and best practices to maintain code quality and consistency across the codebase.

What's Included

The guide covers 10 major areas:

  1. File Structure - Ordering of elements (SPDX headers, imports, __all__, classes, functions)
  2. Package Layout - Organization of .pyx, .pxd, and .py files
  3. Import Statements - Five-group organization with alphabetical sorting
  4. Class and Function Definitions - Ordering within classes (dunder methods, methods, properties)
  5. Naming Conventions - Project-specific patterns (Cython c_ prefix, type suffixes)
  6. Type Annotations and Declarations - Modern PEP 604 union syntax, Cython declarations
  7. Docstrings - NumPy docstring style with Sphinx cross-references
  8. Errors and Warnings - Custom CUDA exceptions, error handling patterns
  9. CUDA-Specific Patterns - GIL management for CUDA driver API calls
  10. Development Lifecycle - Two-phase development (Python first, then Cython optimization)

Key Principles

  • PEP 8 and PEP 257 Base: References these as normative standards, documenting only project-specific extensions
  • Guidelines, Not Rules: Emphasizes readability and maintainability over rigid enforcement
  • Codebase-Aligned: Examples reflect actual patterns from the codebase

File Added

  • cuda_core/docs/source/developer-guide.rst

Andy-Jost avatar Dec 04 '25 20:12 Andy-Jost

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.

copy-pr-bot[bot] avatar Dec 04 '25 20:12 copy-pr-bot[bot]

Link to rendered document: style-guide.md

Andy-Jost avatar Dec 04 '25 20:12 Andy-Jost

I'm interested in feedback on this idea. With a comprehensive style guide, aside from the other benefits listed in the description, we can use LLMs to help refactor, clean, and document the code. If the team is comfortable with this approach, I can begin to apply rules conservatively to the code base.

Andy-Jost avatar Dec 04 '25 20:12 Andy-Jost

Will look more closely asap.

Drive-by comment: I was surprised to see the new file under cuda_core/cuda/core/. I'd expect it to be under cuda_core/, like other meta-kind-of files, e.g. LICENSE, README.md, etc.

rwgk avatar Dec 05 '25 00:12 rwgk

Will look more closely asap.

Drive-by comment: I was surprised to see the new file under cuda_core/cuda/core/. I'd expect it to be under cuda_core/, like other meta-kind-of files, e.g. LICENSE, README.md, etc.

I thought about that, too. I agree it belongs at the root.

Andy-Jost avatar Dec 05 '25 00:12 Andy-Jost

Will look more closely asap. Drive-by comment: I was surprised to see the new file under cuda_core/cuda/core/. I'd expect it to be under cuda_core/, like other meta-kind-of files, e.g. LICENSE, README.md, etc.

I thought about that, too. I agree it belongs at the root.

Do we want this in the root? I'd expect it within a docs folder. That shouldn't impact an LLMs ability to discover and utilize it.

rparolin avatar Dec 05 '25 16:12 rparolin

Merging my offline comment to here. My 2c:

  • If possible I’d like to make part (or all) of this PR rendered as Sphinx docs, for both internal and external contributors to use as developer guide
  • I’d also like all LLM to be able to read it when working on the codebase, including but not limited to: Cursor, CodeRabbit, Copilot, …

leofang avatar Dec 09 '25 01:12 leofang

Moved to cuda_core/docs

Andy-Jost avatar Jan 08 '26 18:01 Andy-Jost

/ok to test 98a0a648baf0ea27f34e09b155947218f51600b0

Andy-Jost avatar Jan 08 '26 22:01 Andy-Jost

Doc Preview CI :---: |

:rocket: View preview at
https://nvidia.github.io/cuda-python/pr-preview/pr-1316/
|
https://nvidia.github.io/cuda-python/pr-preview/pr-1316/cuda-core/
|
https://nvidia.github.io/cuda-python/pr-preview/pr-1316/cuda-bindings/
|
https://nvidia.github.io/cuda-python/pr-preview/pr-1316/cuda-pathfinder/

|

Preview will be ready when the GitHub Pages deployment is complete.

github-actions[bot] avatar Jan 08 '26 22:01 github-actions[bot]

/ok to test f50b64fc016214cac8ad56c95e84f94997166e4a

Andy-Jost avatar Jan 09 '26 19:01 Andy-Jost

/ok to test f5dc2db684de438c56f04ba17c5a4a69a1c49bb3

Andy-Jost avatar Jan 09 '26 19:01 Andy-Jost

The doc is now included with the Sphinx docs. Link above but also here . Click through CUDA Core Developer Guide.

Andy-Jost avatar Jan 09 '26 20:01 Andy-Jost

/ok to test e72f8a0611b0749793094cfacc95b7a49ece21e1

Andy-Jost avatar Jan 09 '26 21:01 Andy-Jost

/ok to test 56e92b98d92ffa950ee18be8b4eeff55abf5c1f5

Andy-Jost avatar Jan 12 '26 17:01 Andy-Jost

/ok to test 3dc195932c215126bfe33751a2b017a538d739e0

Andy-Jost avatar Jan 12 '26 17:01 Andy-Jost

/ok to test 804910f31a4fcd29d69edc69a3e9d76501ceb7e4

Andy-Jost avatar Jan 13 '26 19:01 Andy-Jost

/ok to test 589b176dc2e2bc080e428e018f958fb41b4e35c4

Andy-Jost avatar Jan 14 '26 17:01 Andy-Jost