Skip to content

Comments

refactor(examples): wrap logic in main() functions#1664

Open
OfficialSerge wants to merge 1 commit intoNVIDIA:mainfrom
OfficialSerge:feat/refactor-examples-to-modules
Open

refactor(examples): wrap logic in main() functions#1664
OfficialSerge wants to merge 1 commit intoNVIDIA:mainfrom
OfficialSerge:feat/refactor-examples-to-modules

Conversation

@OfficialSerge
Copy link

@OfficialSerge OfficialSerge commented Feb 20, 2026

Description

This PR is the second half of the response to the following TODO item in cuda_core/tests/example_tests/utils.py.

see part 1

# TODO: Refactor the examples to give them a common callable `main()` to avoid needing to use exec here?
exec(script, env if env else {})

Key Changes

  • refactor any remaining non-module examples into Python modules.
  • os.path.join(cuda_path, "include") refactor to Path(cuda_path) / "include" in thread_block_cluster.py.
  • os.path.isdir(cuda_include) refactor to cuda_include.is_dir() in thread_block_cluster.py.
  • some indenting of the code blocks, they now have leading white space technically, this shouldn't break anything.
  • tried keeping everything else the same.

Next Steps

  • consider using contextlib.closing for Stream and Buffer objects, current failed assertions will halt the execution of the example before .close() is called, thus cleanup is now the garbage collector's problem, this is non-deterministic though; since the Python's garbage collector is lazy, cleanup isn't immediate, not the end of the world but Streams or Buffers linger in the GPU drivers. I imagine many failed tests due to assertion errors may cause unneeded strain on GPU resources.

Let me know if this sounds good (seems okay but not critical imo).

@copy-pr-bot
Copy link
Contributor

copy-pr-bot bot commented Feb 20, 2026

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.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant