Showing results for 
Show  only  | Search instead for 
Did you mean: 
Registered: ‎06-01-2018

printf in opencl kernel using Vivado HLS c Simulation

Hi I trying to debug a kernel in Vivado HLS 2017.4.1 using opencl (.cl) file

When I put printf in the cl kernel function I get this error during compilation when trying to run the c simulation


INFO: [SIM 2] *************** CSIM start ***************
INFO: [SIM 4] CSIM will launch GCC as the compiler.
Compiling ../../../test_vadd.c in debug mode
Compiling vadd.c in debug mode
Compiling tb_stub.c in debug mode
vadd.c:178:1: warning: initialization discards 'const' qualifier from pointer target type [enabled by default]
tb_stub.c: In function 'hls_run_kernel':
tb_stub.c:34:78: error: expected expression before ')' token
make: *** [obj/tb_stub.o] Error 1
CRITICAL WARNING: [SIM 100] CSim file generation failed: compilation error(s).
INFO: [SIM 3] *************** CSIM finish ***************


I have tried some stuff that did not work

- Without the printf the code works as expected 

- adding include <stdio.h> caused missing file error

- I have also tried it in Vivado 2018.2 and got the same error

- The printf does work in test bench file but I am trying to see whats is going on the Kernel


Please advise how to solve this or suggest another way to debug the cl code


This is the Kernel code that cause the error


#include <clc.h>

__kernel void __attribute__ ((reqd_work_group_size(16,1,1)))
vadd( __global int *a, __global int *b, __global int *c) {
int i = get_global_id(0);
printf("%s\n", "this is a test string\n");
c[i] = a[i] + b[i];


The test bench file test_vadd.c:


#include <stdio.h>

int main(int argc, char** argv)
int errors=0, i;

int a[] = {1};
int b[] = {1};
int hw_c[] = {0};
hls_run_kernel("vadd", a, 1, b, 1, hw_c, 1 );
return errors;



0 Kudos
2 Replies
Xilinx Employee
Xilinx Employee
Registered: ‎09-08-2011

Hi Natanr123


    If you are using an openCL Kernel, then printf should work in sw_emu (And actually all three modes: sw_emu, hw_emu, hw)


It looks like there is an issue in the current SDx release when running sw_emu with printf on Ubuntu machines.


It's due to the objcopy located in the <SDx_install>/gnu/binutils.


You can replace the objcopy in the sdx install with the one on your system (Make sure to keep a copy of the sdx install version) to see if that objcopy doesn't return the error on being called that prevents printf on Ubuntu from running.


If you are willing to be patient for hw_emu runs to finish, you should still be able to get the intended printf debug there without making any changes. This might be a good test to verify it is in fact the sw_emu on Ubuntu only that is hanging.


Please give that a try, and let me know if it helps.







If at first you don't succeed, try redefining success?
0 Kudos
Registered: ‎06-01-2018

Thanks but this does not really answer my question.

I should have mentioned that I am using Windows 10.

Also I I am using Vivado HLS not SDAccel

I have attached a screenshot hoping it will make the problem clearer

0 Kudos