Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(gpu): pass over all cuda bind #1514

Merged
merged 1 commit into from
Sep 6, 2024
Merged

Conversation

agnesLeroy
Copy link
Contributor

@agnesLeroy agnesLeroy commented Sep 6, 2024

closes:

PR content/description

I rewrote all the binding to be sure it's consistent with the c++ headers.

Check-list:

  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)
  • Relevant issues are marked as resolved/closed, related issues are linked in the description
  • Check for breaking changes (including serialization changes) and add them to commit message following the conventional commit specification

@@ -3,104 +3,58 @@ use std::ffi::c_void;
#[link(name = "tfhe_cuda_backend", kind = "static")]
extern "C" {
Copy link
Member

Choose a reason for hiding this comment

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

"stupid" question are we sure the C ABI is respected when the CUDA backend is compiled ? in the sense that C++ does not exactly have the C ABI and I don't know how both relate 🤔

Copy link
Member

Choose a reason for hiding this comment

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

(related to the potential launch failure stuff)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm I'm not totally sure no

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

this way you make sure in the C++ code base that you expose the C function as extern "C"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We should be alright, as all the entry points in the binding are actually "C compatible". Nothing C++-like is passed through the interface, only raw pointer types.

Copy link
Member

Choose a reason for hiding this comment

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

while I agree, I would not be against the "ceinture et bretelles" approach here :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

And we define all functions that go through the interface with "extern C" in the header files.

Copy link
Member

Choose a reason for hiding this comment

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

so then we are good on the ABI declaration, nothing else to do on the C++ side, just need to make sure definitions agree, do you want someone to double check function by function ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think this would be very troublesome and not so efficient: I already went through it thoroughly yesterday. But really at some point we should spend some time to figure out how to generate this API automatically, at least part of it.

@@ -8,7 +8,7 @@ extern std::mutex m;
extern bool p2p_enabled;

extern "C" {
int cuda_setup_multi_gpu();
int32_t cuda_setup_multi_gpu();
Copy link
Contributor

Choose a reason for hiding this comment

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

For curiosity, why do we want to have int32_t instead of int here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just to be sure with the types on any architecture, I prefer to always specify the size of the integer (as we do on the Rust side as well).

Copy link
Contributor

@pdroalves pdroalves 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. Just moving functions and removing unnecessary comments in the binding file helps a lot.

@agnesLeroy agnesLeroy merged commit 1d549df into main Sep 6, 2024
98 of 99 checks passed
@agnesLeroy agnesLeroy deleted the al/cuda_rust_binding branch September 6, 2024 15:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants