how can i use printf in opencl correctly?

Viewed 110

I use Intel FPGA SDK for OpenCL with OpenCL 1.0. I defined several vector data int8 in the kernel, and I found from PrintFunction that I can use printf("data_vec_wr1: %10v8hld\n",data_vec_wr1); to show the value.

Console with One printf

data_vec_wr1: %10v8hld

Finally, it did not correctly display the value, so i want to know how to use printf to print the value of the Vector Data

1 Answers

From what I understand, OpenCL 1.0 does not support printf except perhaps by extension. I ran into a similar problem when testing my OpenCL code on some graphics cards. The compiler accepts it without complaint, but the implementation is broken because it is not officially supported. The documentation you linked to is from OpenCL 1.2

As an alternative, You might consider passing in an additional buffer which you can then write your values into to be printed by the cpu after the kernel executes if possible.

Also, I suspect that a printf implementation on an fpga would use up a lot of nodes and thus limit the usefullness of the fpga, so it would actually surprise me if they would include it in an opencl implementation for an fpga.

Related