Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using LLVM 3.3 backend to compile OpenCL for AMD

How exactly does one use the new R600 backend inside LLVM 3.3 to generate a binary suitable for passing to the OpenCL clCreateProgramWithBinary API on an AMD card? Are there any code samples for how to do this?

I have seen a clang command line for how to compile for AMD, but I havent seen anywhere how to use the output with the driver.

Thanks very much.

like image 315
user2531350 Avatar asked Jun 28 '13 09:06

user2531350


1 Answers

You can read the test cases in the 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 just directly use the output through clCreateProgramWithBinary.

like image 155
shining Avatar answered Sep 29 '22 23:09

shining