how to use cl_half2

I want to use the cl_half2 datatype in my program but the compiler doesn’t recognize it (error: unknown type name ‘cl_half2’)
I tried to add #pragma OPENCL EXTENSION cl_khr_fp16 : enable but it is the same (error: unknown type name ‘cl_half2’)
What’s wrong?

To compile I use
gcc -O3 -o prog prog.c -lOpenCL

Do you enable it in kernel code?

cl_half2 is on host side. I use the corresponding half2 on kernel side

Oh, my bad. I did not realize you cannot complile the whole project. You should include cl_ext.h header to your program. But keep in mind, C++ does not support half natively so you should google a library for float <-> half conversion if you need to submit data from or load it to host.

:slight_smile:
Yes, it is strange a grep cl_half2 /usr/include/CL/*.h gave me no results… I don’t understand where is defined this cl_half2…
I use basic C language, not C++… :slight_smile:

Does your device even support halves for that matter? I fp16 is on the list, merely define struct { short data[2] } cl_half2.

I use basic C language, not C++…

It doesn’t change anything.

This is a bug in the Khronos OpenCL headers. We have this on our internal bug tracking system, so it should be fixed in a future release of the headers.

In the meantime, you could produce your own typedefs as necessary:

typedef cl_half[2] cl_half2;

If you want the usual vector accessors (.x, .y, .s0, .s1, .hi, .lo etc), you could copy the definitions for cl_ushort2 and modify as appropriate.

Well… extension cl_khr_fp16 is not on the device list, thanks salabar