0
votes

I am trying to load a SPIR binary i created with clang+llvm 6.0.1.

Created a few different files with :

clang -target spir-unknown-unknown -cl-std=CL1.2 -c -emit-llvm -Xclang -finclude-default-header OCLkernel.cl  
clang -target amdgcn-amd-amdhsa -cl-std=CL1.2 -c -emit-llvm -Xclang -finclude-default-header OCLkernel.cl  
clang -cc1 -emit-llvm-bc -triple spir-unknown-unknown -cl-std=CL1.2 -include "include\opencl-c.h" OCLkernel.cl

This is all happening on windows, installed AMD APP SDK 3 and Adrenalin 18.6.1 drivers.

After this i try to create a program from the binary :

clCreateProgramWithBinary(context, 1, &device, &programSrcSize, (const unsigned char**)&programSrc, 0 , &status)

This all goes OK, i don't get any errors here, but i do when trying to build it afterwards :

clBuildProgram(program, 1, &device, " –x spir -spir-std=1.2", NULL, NULL);

The error i get is :

Error CL_INVALID_COMPILER_OPTIONS when calling clBuildProgram

I tried without the "-x spir..." stuff too, but then i just get a :

error: Invalid value (Producer: 'LLVM6.0.1' Reader: 'LLVM 3.9.0svn')

EDIT:

CL_DEVICE_NAME: gfx900
CL_DEVICE_VERSION: OpenCL 2.0 AMD-APP (2580.6)
CL_DEVICE_OPENCL_C_VERSION: OpenCL C 2.0
CL_DRIVER_VERSION: 2580.6 (PAL,HSAIL)
CL_DEVICE_SPIR_VERSIONS: 1.2

After running clCreateProgramWithBinary i query the device with clGetProgramBuildInfo and get :
CL_PROGRAM_BINARY_TYPE = [CL_PROGRAM_BINARY_TYPE_INTERMEDIATE]

So that should mean the binary is being recognised, else i guess it would return CL_PROGRAM_BINARY_TYPE_NONE

EDIT2:

I think clang isn't creating a 'good' binary, but how to create it then?

Appreciate your help!

1
Could you check the device info for CL_DEVICE_SPIR_VERSIONS to ensure SPIR is supported? - apetranzilla
Yes, i edited my post. I have a Vega56. Thanks - DasWas
Have you tried the Khronos clang github.com/KhronosGroup/SPIR ? - w-m

1 Answers

1
votes

Unfortunately the support for SPIR was silently removed from AMD drivers, see dipak answers in this thread of AMD community forum:

https://community.amd.com/thread/232093

Regarding your second question: general clang+LLVM (not the secret version tuned by AMD and included in their proprietary drivers) still cannot produce binaries compatible with general-purpose Windows AMD drivers, however it is possible for Linux: all new AMD’s ROCm, AMD PAL and Mesa 3D runtime are covered.

It is a mystery for me why LLVM AMDGPU backend developers do not prioritize the task to produce binaries for Windows drivers, as there is a couple of GCN assembler projects that provide such a functionality through Windows OpenCL interface, to name a few: CLRadeonExtender, ASM4GCN, HepPas, etc. Moreover I know an undocumented fork of clang+LLVM that (as its author states) produce such OpenCL binaries! "There are more things in heaven and earth, Horatio, Than are dreamt of in your philosophy."