ROCm / clang-ocl

OpenCL compilation with clang compiler.
Other
26 stars 12 forks source link

Compile binary on Linux and load it on windows? #4

Closed behindthepixels closed 1 month ago

behindthepixels commented 6 years ago

I am trying to use this script to compile a kernel on linux and load the binary in my windows program with clCreateProgramWithBinary. Will this work?

I already get the ROCm compiler, and this clang-ocl script built on my linux system, and have successfully used it to compile my kernel into binaries.

However, when loading in on windows program, I got an error when creating kernels with :clCreateKernel, error code is -46.

Wondering if I missed something. For example, I am trying to use a RX580, should I compile for 580 explicitly when calling clang-ocl? Or will the script build binaries for all architectures and the correct one will be selected based on actual GPU?

Another question is, the default TARGET_TRIPLE of clang-ocl build is amdgcn-amd-amdhsa-amdgizcl, instead of amdgcn-amd-amdhsa-opencl. I wonder why? And which one is preferable, and lastly what do I need to do so that the compiler will target amdgcn-amd-amdhsa-opencl instead?

Thanks!

behindthepixels commented 6 years ago

I have tried switching to use R9 Fury, whose compiling target is gfx803 according to: https://llvm.org/docs/AMDGPUUsage.html, and it matches with the parameter in my clang-ocl script.

However I still got an error of clCreateKernel -46 when creating kernels directly from binaries. Any idea what I am missing?

behindthepixels commented 6 years ago

Update: I just realize that I still need to call clBuildProgram after reading the binaries. I tried dumping the binaries that I built on windows with clCreateProgramWithSource and it worked.

However, when loading binaries built from clang-ocl on linux, I got this error in clBuildProgram:

Build info:Error: The binary is incorrect or incomplete. Finalization to ISA couldn't be performed.

yxsamliu commented 6 years ago

The binary you got on linux may not work on windows, probably due to different metadata format used by the binary. However it should work with the OpenCL runtime on Rocm (https://github.com/RadeonOpenCompute/ROCm-OpenCL-Runtime).

behindthepixels commented 6 years ago

Thanks! I actually managed to get the ROCm Opencl compiler building yesterday on windows. I also found https://github.com/GPUOpen-Tools/RGA, which can be used to compile ROCm OpenCL on windows. However, even with binaries generated on Windows I still have this error: Build info:Error: The binary is incorrect or incomplete. Finalization to ISA couldn't be performed.

I wonder is AMDAPPSDK and Rocm opencl just not compatible. I knew it would work for ROCm OCL runtime, but does the runtime run at all on windows? @yxsamliu

Thanks,

yxsamliu commented 6 years ago

The ISA binary compiled by Rocm OpenCL compiler is not compatible with APPSDK or windows display driver.

Currently Rocm OpenCL runtime only runs on linux.

behindthepixels commented 6 years ago

Oh that’s a bummer. Is there anything else I can use if I want to use the swizzle instructions on Windows then? The default OpenCL compiler in appsdk provides no such intrinsic and this is not exposed by OpenCL standards.

TechnikEmpire commented 6 years ago

@yxsamliu So rocm opencl doesn't work on about 88.53% of all desktop computers on the planet. That's unfortunate.

gstoner commented 6 years ago

Yes ROCm is compatible with 90%+ of the server that run GPU on the market today. Note they use Linux.

On MS Windows, for Vega10 and forward GPU's since it uses the new PAL base system runtime foundation. We are bringing over LC compiler support from ROCm to Windows OpenCL stack. We are also bringing over HIP to Windows.

The team has been testing this to make sure it clean on Windows.

TechnikEmpire commented 6 years ago

@gstoner I'm glad to see that Windows is somewhere in the pipe. While I can appreciate your defense and server land, I'm looking for solutions that can be made available to the general public though and not private corps and universities with multi-million-dollar GPGPU rackspace, hence my lamentation about 88% of the global consumer market being unreachable here. Thanks.

gstoner commented 6 years ago

It all about how restrictive the MS Windows is for System Software, it why we try new Ideas on Linux first. ALso for Consumer class system, you can via Ubuntu, low-end Ryzen and Intel I3 with Polaris GPU get access to this if you want to try it out.

Also, the OpenCL support on Windows supports the same Compiler frontend so and it uses the same Language Runtime. Only really missing today on Windows in In-line ASM support and native compiler foundation. But you find right now both compilers have there strength and weakness. The new LC Native compiler is much younger compiler and still has room to go on broader market codes. For example, right now Ray Tracers are better on the SC based compiler.

schung-amd commented 1 month ago

Closing this as the guidance provided is still accurate: binaries compiled on Linux are not guaranteed to work on Windows.