Using LLVM 3.3 to compile OpenCL for AMD

How to use the new R600 server inside LLVM 3.3 to generate a binary file suitable for switching to the OpenCL clCreateProgramWithBinary API on an AMD card? Are there code examples for how to do this?

I saw the clang command line to compile for AMD, but I have never seen how to use the output with the driver.

Thank you very much.

+6
source share
2 answers

You can read the test cases at llvm/test/CodeGen/R600 .

For example: add.ll

 ;RUN: llc < %s -march=r600 -mcpu=redwood | FileCheck %s ;CHECK: ADD_INT T{{[0-9]+\.[XYZW], T[0-9]+\.[XYZW], T[0-9]+\.[XYZW]}} ;CHECK: ADD_INT * T{{[0-9]+\.[XYZW], T[0-9]+\.[XYZW], T[0-9]+\.[XYZW]}} ;CHECK: ADD_INT * T{{[0-9]+\.[XYZW], T[0-9]+\.[XYZW], T[0-9]+\.[XYZW]}} ;CHECK: ADD_INT * T{{[0-9]+\.[XYZW], T[0-9]+\.[XYZW], T[0-9]+\.[XYZW]}} define void @test(<4 x i32> addrspace(1)* %out, <4 x i32> addrspace(1)* %in) { %b_ptr = getelementptr <4 x i32> addrspace(1)* %in, i32 1 %a = load <4 x i32> addrspace(1) * %in %b = load <4 x i32> addrspace(1) * %b_ptr %result = add <4 x i32> %a, %b store <4 x i32> %result, <4 x i32> addrspace(1)* %out ret void } 

Then you can directly use the output through clCreateProgramWithBinary.

+1
source

Perhaps you should use libclc to use the built-in functions of OpenCL. ( https://libclc.llvm.org/ )
Unfortunately, LLVM requires 3.7 or higher.
This is because LLVM 3.7 and later only support the AMD GPU brand. LLVM 3.3 lacks the opencl interface in clang, as well as amd-gpu backend in llvm.
(clang 3.3: http://releases.llvm.org/3.3/tools/clang/docs/UsersManual.html )
(LLVM 3.3: http://releases.llvm.org/3.3/docs/index.html )
(LLVM 3.7: http://releases.llvm.org/3.7.0/docs/AMDGPUUsage.html )
(I don't know why AMD GPU support is missing in the release note.)

So, if you want to compile the OpenCL kernel for an AMD GPU, you will need to use the LLVM version version 3.7 or later.

If you can't afford to use LLVM 3.3, take a look at the R600 backend. I don’t know for sure, but the former name AMDGPU Backend is the R600 Backend. ( https://www.phoronix.com/scan.php?page=news_item&px=amd-r600-amdgpu-llvm )

0
source

Source: https://habr.com/ru/post/948308/


All Articles