clBuildProgram crashes with varying kernel args

I have a kernel which I have defined by

Filename: kernel.cl

__kernel void ptop(__global int *a, __global int *b, __global int *c)
{
size_t global_id = get_global_id(0);

    a[global_id] = a[global_id] + b[global_id]

}

if I try to build this program, I get a crash at clBuildProgram().

If I modify the kernel by removing the 3rd argument “__global int *c”, or if I change the statement
a[global_id] = a[global_id] + b[global_id]

to

    a[global_id] = a[global_id] + b[global_id] + c[global_id]

clBuildProgram() works fine.

My initial guess was the build reporting an usused variable, since I was not using the 3rd argument “c”. The trouble is, it shouldn’t crash for something like that, and moreover if the compiler sees that as an issue, I should be getting a build warning in the build logs. The trouble is I am not even able to get a build log, since the crash is fatal at clBuildProgram().

Crash info-

clCreateProgramWithSource created successfully
building program
*** glibc detected *** ./a.out: free(): invalid next size (fast): 0x0805e8a8 ***
======= Backtrace: =========
/lib/libc.so.6[0xb79f38c4]
/lib/libc.so.6(cfree+0x90)[0xb79f7370]
/usr/lib/libnvcompiler.so[0xb74e1db1]
/usr/lib/libnvcompiler.so[0xb6ef5eae]
/usr/lib/libnvcompiler.so[0xb6ef5e92]
/usr/lib/libnvcompiler.so[0xb6ef5e92]
/usr/lib/libnvcompiler.so[0xb6ef5e92]
/usr/lib/libnvcompiler.so[0xb6ef1b8f]
/usr/lib/libnvcompiler.so[0xb6ed6e93]
/usr/lib/libnvcompiler.so(NvCliCompileProgram+0x8fb)[0xb6e2bd7b]
/usr/lib/libOpenCL.so.1(clBuildProgram+0x457)[0xb7b91037]
./a.out[0x8048e5a]
/lib/libc.so.6(__libc_start_main+0xe0)[0xb799e390]
./a.out[0x8048821]
======= Memory map: ========
08048000-0804a000 r-xp 00000000 03:08 1167003 /root/development/opencl/a.out
0804a000-0804b000 rw-p 00001000 03:08 1167003 /root/development/opencl/a.out
0804b000-08087000 rw-p 0804b000 00:00 0 [heap]
b6000000-b6021000 rw-p b6000000 00:00 0
b6021000-b6100000 —p b6021000 00:00 0
b6191000-b6192000 rw-p b6191000 00:00 0
b6192000-b6292000 rw-s 113cd000 00:0d 9801 /dev/nvidia0
b6292000-b6392000 rw-s 0f5ca000 00:0d 9801 /dev/nvidia0
b6392000-b6492000 rw-s 112c6000 00:0d 9801 /dev/nvidia0
b6492000-b6592000 rw-s 1eefc000 00:0d 9801 /dev/nvidia0
b6592000-b6593000 rw-s 1eef9000 00:0d 9801 /dev/nvidia0
b6593000-b6594000 rw-s cfc04000 00:0d 9801 /dev/nvidia0
b6594000-b6595000 rw-s 1eef8000 00:0d 9801 /dev/nvidia0
b6595000-b6997000 rw-s 10de0000 00:0d 9801 /dev/nvidia0
b6997000-b6d99000 rw-s 0f459000 00:0d 9801 /dev/nvidia0
b6d99000-b6d9a000 rw-p b6d99000 00:00 0
b6d9a000-b6da4000 r-xp 00000000 03:08 1403618 /usr/lib/libgcc_s.so.1
b6da4000-b6da5000 rw-p 00009000 03:08 1403618 /usr/lib/libgcc_s.so.1
b6da5000-b6dc9000 r-xp 00000000 03:08 383594 /lib/libm-2.7.so
b6dc9000-b6dcb000 rw-p 00023000 03:08 383594 /lib/libm-2.7.so
b6dcb000-b6dcd000 r-xp 00000000 03:08 383593 /lib/libdl-2.7.so
b6dcd000-b6dcf000 rw-p 00001000 03:08 383593 /lib/libdl-2.7.so
b6dcf000-b6dd0000 rw-p b6dcf000 00:00 0
b6dd0000-b6de3000 r-xp 00000000 03:08 1403601 /usr/lib/libz.so.1.2.3
b6de3000-b6de4000 rw-p 00012000 03:08 1403601 /usr/lib/libz.so.1.2.3
b6de4000-b6df7000 r-xp 00000000 03:08 383604 /lib/libpthread-2.7.so
b6df7000-b6df9000 rw-p 00013000 03:08 383604 /lib/libpthread-2.7.so
b6df9000-b6dfb000 rw-p b6df9000 00:00 0
b6dfb000-b758d000 r-xp 00000000 03:08 875337 /usr/lib/libnvcompiler.so.190.29
b758d000-b797f000 rw-p 00791000 03:08 875337 /usr/lib/libnvcompiler.so.190.29
b797f000-b7988000 rw-p b797f000 00:00 0
b7988000-b7ace000 r-xp 00000000 03:08 383590 /lib/libc-2.7.so
b7ace000-b7acf000 r–p 00146000 03:08 383590 /lib/libc-2.7.so
b7acf000-b7ad1000 rw-p 00147000 03:08 383590 /lib/libc-2.7.so
b7ad1000-b7ad4000 rw-p b7ad1000 00:00 0
b7ad4000-b7ed3000 r-xp 00000000 03:08 875332 /usr/lib/libOpenCL.so.1.0.0
b7ed3000-b7ed8000 rw-p 003ff000 03:08 875332 /usr/lib/libOpenCL.so.1.0.0
b7ed8000-b7efe000 rw-p b7ed8000 00:00 0
b7f08000-b7f09000 rw-s cfc02000 00:0d 9801 /dev/nvidia0
b7f09000-b7f0a000 rw-s 10e1b000 00:0d 9801 /dev/nvidia0
b7f0a000-b7f1b000 rw-s 1ee5e000 00:0d 9801 /dev/nvidia0
b7f1b000-b7f1c000 r–s cf009000 00:0d 9801 /dev/nvidia0
b7f1c000-b7f1d000 rw-p b7f1c000 00:00 0
b7f1d000-b7f39000 r-xp 00000000 03:08 383632 /lib/ld-2.7.so
b7f39000-b7f3b000 rw-p 0001b000 03:08 383632 /lib/ld-2.7.so
bfcfb000-bfd0e000 rwxp bffeb000 00:00 0 [stack]
bfd0e000-bfd10000 rw-p bfffe000 00:00 0
ffffe000-fffff000 r-xp 00000000 00:00 0 [vdso]
Aborted

Sounds like a bug in that particular implementation. What implementation? And you should probably file it as a bug report with them.

I just checked my code and it looked like I was setting just a memory of size bytes instead of size + 1, for the code retrieved from the program source file. Changed it to size + 1 and it worked fine. Thanks a lot