[Libclc-dev] AMD and libclc (progress)

Tom Stellard via Libclc-dev libclc-dev at lists.llvm.org
Wed May 18 15:11:24 PDT 2016

On Tue, Apr 26, 2016 at 08:59:40PM +0100, Ricardo Nobre via Libclc-dev wrote:
> I compiled and installed the latest 'libclc' from the repository and I
> successfully generated AMD GCN ASM from the GEMM kernel of the
> polybench-gpu benchmark (
> http://web.cse.ohio-state.edu/~pouchet/software/polybench/GPU/) executing
> the following commands:
> /opt/clang+llvm-3.7.1-x86_64-linux-gnu-ubuntu-15.10/bin/clang
> -Dcl_clang_storage_class_specifiers -isystem /opt/libclc/include -include
> clc/clc.h -target amdgcn -S -emit-llvm -xcl -o gemm.ll gemm.cl
> /opt/clang-3.9/bin/llvm-link gemm.ll /opt/libclc/lib/clc/verde-amdgcn--.bc
> -o gemm.linked.bc
> /opt/clang-3.9/bin/clang -target amdgcn gemm.linked.bc -S -o gemm.verde.s
> Now what should I do with the assembly file (i.e., 'gemm.verde.s')?
> Can I use an assembler such as GCNASM (https://github.com/balidani/gcnasm)
> or CLRadeonExtender (http://clrx.nativeboinc.org/) to generate a binary
> compatible with AMD Catalyst?
> I tried using both assemblers and they both complained with many of the
> instructing generated by Clang.
> Can you give me some pointers on how to progress?


clang uses an integrated assembler for the amdgcn target so you can
compile directly to binary with clang.

These binaries are not compatible with catalyst.

If you have one of the GPU/CPU/Motherboard combinations supported by the
Radeon Open Compute (ROC) driver (which can be found here:
http://gpuopen.com/compute-product/rocm/), then you can use the
ROC apis to upload an execute code.

You can find driver installation instructions for ROC here:

There are a few examples here that demonstrate how to use the API
to upload code:

You can actually combine all the commands you used into a single
invocation, like this:

${CLANG} -x cl -Dcl_clang_storage_class_specifiers -target
amdgcn--amdhsa -mcpu=fiji -B -Xclang -mlink-bitcode-file -Xclang

Since you are using a tonga, which isn't officially supported by ROC,
the only way you can execute the code is by using the Open Source
OpenCL implementation known as clover, which is part of Mesa.
For more details see here: https://dri.freedesktop.org/wiki/GalliumCompute/
Also, if you want to compile code using clang for clover, you
need to use the amdgcn-- triple instead of amdgcn--amdhsa.

However, the binary format accepted by this implementation is
a container which includes the code output by clang in addition
to some other information.  If you do want to use clover, it will
be easier to just to use the OpenCL APIs to compile the kernel
for you.

Note that clover is not a complete implementation, so there may be
things that don't work if you try it.

Let me know if you have any other questions.


> Ricardo

> _______________________________________________
> Libclc-dev mailing list
> Libclc-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/libclc-dev

More information about the Libclc-dev mailing list