-
Notifications
You must be signed in to change notification settings - Fork 69
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
Make the state structs accessible directly from C. #21
Comments
As far as I know name mangling applies to C++ (which has namespaces, overloading etc.), not to C, I guess you meant disabling name mangling. I think I know what is the basic requirement here. Edit: You may also have a C++ function with C API which takes
Yes, I guess user can add
Can you provide test case or a link to a library which does that?
You can notice that in rocRAND/hipRAND there is no There are two reasons behind this: 1. you can't write |
Yes, but only btw. |
In that header you have functions like curand() that has multiple overloads. C compiler should complain about that. |
This header also includes templates. |
@jszuppe So essentially, you'd create a header like this where only the structs are defined. https://github.com/Geof23/Gklee/blob/master/Gklee/include/cuda/curand_mtgp32.h Hope this makes sense! Edit: So let me explain why the headers have C++ code :) Check this out: https://github.com/Geof23/Gklee/blob/master/Gklee/include/cuda/curand_kernel.h#L86
As we both know, NVCC compiler parses out the kernel code and the host code and sends them to different compilers. All the C++ style code you both were talking about had QUALIFIERS prepended it, so they were device code. The NVCC compiler would not include such code when sending it to the host compiler (which could be a C compiler). If you pay attention, the structs don't have QUALIFIERS prepended to them, so they're host code. In our case, we should use IF/DEFs in order to determine whether a block of code should be compiled or not. You'll see that this practice is already been performed correctly in the HIP API. The way CUDA's API works is that you should be able to interoperate with all of their APIs (curand, e.g.) entirely through the C language, so it's not a coincidence at all that the states are defined as struct objects. |
If you have something like
You can do something like Like I said before, it [forward declaration of |
Anyway, now that I know what you need I'll look into it and try to find for the simplest solution that will enable you to write |
@jszuppe Thanks. Yeah I agree. The usage of typedefs makes forward declaring really difficult here. A good solution would require a spoonful of creativity : ) (And yeah NVCC will compile the host code using a C++ compiler, but since the header only had structs on host side, it would interleave nicely with C. This helps turn the opaque type hiprandStateMtgp32 into a real type.) |
@Jorghi12 Can you try branch fix_21_and_test? In It also includes fixes for other issues, and that's why now you have to add |
@jszuppe Awesome! I'll give this a go. |
When you confirm it works for you, I'll push this and other changes into |
@jszuppe ROCm 1.8.2 would be a great target but unlikely unless you notify releng here about this. If it works, I'd be in favor since PyTorch depends on it. Thanks! |
@jszuppe just talked to releng. If you merge to master and let them know today that it is in, we can make the window. |
@iotamudelta Ah, I didn't know ROCm 1.8.2 will be released so soon (this week?). I'm sure I won't be able to merge this into |
@jszuppe we are in the release candidates. what is a realistic time line for landing in master from your side? I can check if we can make it work. |
I can do that tomorrow, before 2pm CEST. But most likely without #22. We also have plans to remove some very minor warnings on CUDA environment, that would also be excluded. |
#22 is not a blocker from what I can see. and thanks - will forward. |
@jszuppe The branch works. Feel free to merge to master 👍 . |
You can take a look at CUDA headers and you'll see that state is designed as a struct: https://github.com/Geof23/Gklee/blob/master/Gklee/include/cuda/curand_mtgp32.h#L194
rocRAND however has its state defined as a class with member functions. This is not supported in C and thus it's not possible to obtain C style linkage.
Why is this important? Many deep learning frameworks interface with Python and C via Python C Extensions.
I suggest two possible solutions would be either
OR
The text was updated successfully, but these errors were encountered: