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

[REQUEST]: Support for compiling OpenCL using NVIDIA's driver #3599

Open
eyalroz opened this issue Apr 28, 2022 · 12 comments
Open

[REQUEST]: Support for compiling OpenCL using NVIDIA's driver #3599

eyalroz opened this issue Apr 28, 2022 · 12 comments
Labels
request Request for something

Comments

@eyalroz
Copy link

eyalroz commented Apr 28, 2022

Is your feature request related to a problem? Please describe

NVIDIA is one of the popular vendors of GPUs, and its' important to see what OpenCL code compiled by its OpenCL driver would look like. Right now, you can only compile OpenCL with some kind of ARM toolchain (?)

Describe the solution you'd like

OpenCL is not compiled directly from the command line. One needs to - in a program written in another language and for the host side - read the source, then use the OpenCL host-side API to initiate a dynamic compilation. In this case the compilation should produce NVIDIA PTX code (well, sort of).

Describe alternatives you've considered

Uh... not using GodBolt?

Additional context

CUDA is already supported, albeit not via dynamic compilation, it seems.

@eyalroz eyalroz added the request Request for something label Apr 28, 2022
@RubenRBS
Copy link
Member

Hi! Thanks for the request, sorry we took so long to get back to you.

The main problem with this specific case might be the non-standard process you mention, which would complicate things even further (As historically we've lacked the experience to implement many of the features dealing with this kind of compilers)

We would really appreciate if someone could try to take a shot at this, and are happy to help where needed

@eyalroz
Copy link
Author

eyalroz commented May 16, 2022

@RubenRBS : It is actually a perfectly standard process. That is, OpenCL is always compiled the way I described - and that's what you guys do, as well, I am sure. I was suggesting you do the same thing you do now, but with NVIDIA's OpenCL driver. Probably a rather minor change/addition of code, nothing really new.

However - if your OpenCL-on-ARM toolchain is not really well-maintained, then I realize it would be more of a hassle.

@RubenRBS
Copy link
Member

Oh then it's possible that I might have totally missinterpreted the situation, sorry! Let me poke around, see if I can get someone that knows what they are doing to take a look at it :)

@partouf
Copy link
Contributor

partouf commented May 16, 2022

We don't really use drivers, for Cuda we use NVCC, but NVCC does not support OpenCL
So I'm not really sure what you want us to do.

Can you tell us what the commands would be if you were to locally call them on your pc?

@eyalroz
Copy link
Author

eyalroz commented May 16, 2022

@partouf :

  1. It works with any modern C++ compiler (possibly any C compiler) - you just need the CUDA libraries (which include their OpenCL driver).
  2. Just do whatever you do on ARM, but with different libraries.

@partouf
Copy link
Contributor

partouf commented May 16, 2022

@eyalroz this is what we do for the Clang Arm v8 compiler https://github.com/compiler-explorer/compiler-explorer/blob/main/etc/config/openclc.amazon.properties#L175
Can you explain the parameters that we would have to pass?

@eyalroz
Copy link
Author

eyalroz commented May 16, 2022

@partouf : Well, remember that "compiling OpenCL" only actually happens at runtime, from within the program. The outside program is a plain vanilla CPU-bound program. Its target is whatever the host machine is (for CUDA, that would typically be Linux). Inside the program, you need to:

  1. Include the OpenCL header(s)
  2. Load OpenCL source text (from a file or from a string or from stdin)
  3. Choose the correct OpenCL platform and OpenCL device (often there's just one of each)
  4. Create an OpenCL context
  5. Create a program from the loaded OpenCL source text and build it
  6. Get the built/compiled program.
  7. Get the compiled program

I presume that's what you do on ARM as well. In step 7, and with NVIDIA's OpenCL driver, you'll get PTX-like text.

@partouf
Copy link
Contributor

partouf commented May 18, 2022

@jzzheng22 hey, do you have an idea maybe on what this is about?
(maybe a sidenote, do you have a working example shortlink for OpenCL -> SpirV?)

@jzzheng22
Copy link
Contributor

@jzzheng22 hey, do you have an idea maybe on what this is about? (maybe a sidenote, do you have a working example shortlink for OpenCL -> SpirV?)

unfortunately not sorry, but possibly @AnastasiaStulova or @StuartDBrady could help?

@AnastasiaStulova
Copy link
Contributor

I don't know if you will be able to load SPIR-V in NVIDIA drivers. But compilation into SPIR-V is already supported in Code Explorer https://godbolt.org/z/qodMKPrjv. However the dev branches are broken at the moment.

Clang has PTX support https://llvm.org/docs/NVPTXUsage.html but however I don't know whether Nvidia's OpenCL driver can support PTX as it is not part of OpenCL standard in any way... However since PTX is integrated similarly to Arm support in clang it should be straightforward to enable this in Compiler Explorer if this is what this issue asks for.

@partouf
Copy link
Contributor

partouf commented May 19, 2022

aaaah thanks @AnastasiaStulova ! I think this doc might be of help here

@eyalroz
Copy link
Author

eyalroz commented May 19, 2022

however I don't know whether Nvidia's OpenCL driver can support PTX as it is not part of OpenCL standard in any way...

It's not supported as PTX, but what NVIDIA's driver gives you, when compiling a program, is sorta-PTX. I've never tried feeding SPIR-V to NVIDIA's OpenCL driver, I'm guessing this will fail since NVIDIA makes it a point to not support anything beyond the minimum necessary for OpenCL. Or - support it only with secret software that you can't get.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
request Request for something
Projects
None yet
Development

No branches or pull requests

5 participants