Skip to content

Adds a sharedmem CuHandle + python bindings#954

Merged
gbin merged 2 commits into
masterfrom
gbin/pyO3-sharedmem
Mar 26, 2026
Merged

Adds a sharedmem CuHandle + python bindings#954
gbin merged 2 commits into
masterfrom
gbin/pyO3-sharedmem

Conversation

@gbin

@gbin gbin commented Mar 25, 2026

Copy link
Copy Markdown
Collaborator

Summary

This adds a new type of CuHandle that is sharedmem type. This helps for sharing safely 0 copy large buffers with other processes like python tasks.

Related issues

  • Closes #

Changes

Testing

  • just fmt
  • just lint
  • just test
  • optional full just std-ci (if std/runtime paths are impacted)
  • optional full just nostd-ci (if embedded/no_std paths are impacted)
  • Other (please specify):

pro-tip: just with no parameters in the root defaults to just fmt, just lint, and just test.

Checklist

  • I have updated docs or examples where needed
  • I have added or updated tests where needed
  • I have considered platform impact (Linux/macOS/Windows/embedded)
  • I have considered config/logging changes (if applicable)
  • This change is not a breaking change (or I documented it below)

Breaking changes (if any)

Additional context

@gbin gbin added enhancement New feature or request include in changelog labels Mar 25, 2026
@gbin

gbin commented Mar 25, 2026

Copy link
Copy Markdown
Collaborator Author

@neilmacintyre An alternative idea: simply use a new type of CuHandle that can be shared over a memory pool:

reasoning, most of the copy overhead will be over large memory buffers (images, point clouds) and having them over cuhandles allow us to safely share them. Python on its side can recover a view & use it in numpy.

Comment on lines +1856 to +1857
"def process(ctx, inp, state, output):\n\
\x20\x20\x20\x20view = inp.data.memoryview()\n\

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Not exactly related to this PR but does the python ctx have a well defined python dataclass?

Also for input and output ideally there would be a interop struct (probably a flatbuffer?) that we could pass into the inp and output types as a generic. In the copperconfig.ron python tasks would be annotated with the expected input and output types.

Ideally there would be some sort of handshake when the cu runtime starts the python subprocesses to make sure that the python process methods agree with the flatbuffer struct specified in the copperconfig.ron.

def process(ctx:Context, inp: Input<Generic_Type>, state: State<Generic_Type>, output):

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

this is a little bit orthogonal to this PR. The python types are contructed from cu29-values in the passed message if they are out of process, I'll see if I can infer the actual python type annotation.

@gbin gbin merged commit a1d74c2 into master Mar 26, 2026
23 checks passed
@gbin gbin deleted the gbin/pyO3-sharedmem branch March 26, 2026 16:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants