Function pointer parameters in PTX backend

Hi everybody,

I am trying to produce ptx code starting from OpenCL C.
I am experiencing a problem concerning pointer parameters.
Here follows an example:

kernel void function(__global float* parameter1) {}

NVIDIA NVCC Compiler:

.entry function(
.param .u32 .ptr .global .align 4 function_param_0
)
{
ret;
}

CLANG + LLVM PTX backend

// (skipping builtin functions definitions)

.entry function (.param .b32 __param_1) // @function
{

// BB#0: // %entry
exit;
}

As you can see the code generated by the LLVM backend lacks the kernel parameter attribute
.ptr, required to identify pointers [1]. I can understand that the address space attribute (.global)
is not defined since there is no agreement on how to represent them in the IR.

The command I use to compile is:
clang kernels/parameters.cl -include ocldef.h -include builtin_functions_ptx.cl -ccc-host-triple ptx32 -S -o -

where ocldef.h contains the definitions of OpenCL vector data types,
builtin_functions_ptx.cl is the file provided by Justin in a previous message [2].

Is this a bug? Or the .ptr attribute is just not supported yet ?

Thank you

Alberto

Hi everybody,

I am trying to produce ptx code starting from OpenCL C.
I am experiencing a problem concerning pointer parameters.
Here follows an example:

kernel void function(__global float* parameter1) {}

NVIDIA NVCC Compiler:

.entry function(
.param .u32 .ptr .global .align 4 function_param_0
)
{
ret;
}

CLANG + LLVM PTX backend

// (skipping builtin functions definitions)

.entry function (.param .b32 __param_1) // @function
{

// BB#0: // %entry
exit;
}

As you can see the code generated by the LLVM backend lacks the kernel parameter attribute
.ptr, required to identify pointers [1]. I can understand that the address space attribute (.global)
is not defined since there is no agreement on how to represent them in the IR.

This is actually a PTX version issue. The .ptr annotations were introduced in PTX in version 2.2, and the back-end defaults to version 2.0. The CUDA driver API does not really care about this, but the NVidia OpenCL run-time requires this pointer attribute.

Try adding -Xclang -target-feature -Xclang +ptx23 to your command line.

The command I use to compile is:
clang kernels/parameters.cl -include ocldef.h -include builtin_functions_ptx.cl -ccc-host-triple ptx32 -S -o -

where ocldef.h contains the definitions of OpenCL vector data types,
builtin_functions_ptx.cl is the file provided by Justin in a previous message [2].

You may want to look into libclc: http://www.pcc.me.uk/~peter/libclc/

It provides more functionality than the file I posted eariler, and will most likely be the “official” OpenCL run-time library for the PTX back-end.