Skip to content

Refactor Python CUDA IPC API#1002

Merged
haixuanTao merged 3 commits intodora-rs:mainfrom
Mivik:cuda
May 26, 2025
Merged

Refactor Python CUDA IPC API#1002
haixuanTao merged 3 commits intodora-rs:mainfrom
Mivik:cuda

Conversation

@Mivik
Copy link
Copy Markdown
Contributor

@Mivik Mivik commented May 12, 2025

As noted in #978, the current Python CUDA IPC API fails when sending specific tensors.

My investigation suggests that pyarrow.cuda (used by dora.cuda), is likely the source of this failure. During testing with two processes (sender and receiver), the receiver receives pyarrow.CudaBuffer with corrupted content, and it appears that there's nothing we can do about this.

However, I found that the numba.cuda module is a suitable alternative for implementing CUDA IPC. As we already depend on numba, no new dependencies are introduced. I have refactored the API to use numba.cuda, and it has passed the tests proposed in #978.

Example & docstrings are updated accordingly.

Note: this change is not backward compatible.

@haixuanTao
Copy link
Copy Markdown
Collaborator

Thanks for this investigation and this looks really cool!

However, would it be possible to not depend on pickle as it would reduce GPU 0-copy to python only project.

The idea behind using cuda ipc handle was to be able to read this in like C/C++ or Rust.

@Mivik
Copy link
Copy Markdown
Contributor Author

Mivik commented May 13, 2025

However, would it be possible to not depend on pickle as it would reduce GPU 0-copy to python only project.

I refactored the encoding part and now removed pickle.

Copy link
Copy Markdown
Collaborator

@haixuanTao haixuanTao left a comment

Choose a reason for hiding this comment

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

Looks good to me!

I think uint8 would be more resilient!

But thanks for everything!

"source_info": json.dumps(source_info),
}
return pa.array(handle_buffer, type=pa.uint8()), metadata
return pa.array(handle, pa.int8()), metadata
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.

This should be uint8 right?

Suggested change
return pa.array(handle, pa.int8()), metadata
return pa.array(handle, pa.uint8()), metadata

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

handle is actually a int8 array (ranged from -128 to 127), since its underlying c type is char

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.

ah ok

@haixuanTao haixuanTao merged commit 3aea1c7 into dora-rs:main May 26, 2025
150 of 277 checks passed
@Mivik Mivik deleted the cuda branch November 17, 2025 05:44
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.

2 participants