OpenCL* for CPU
Ask questions and share information on Intel® SDK for OpenCL™ Applications and OpenCL™ implementations for Intel® CPU
Announcements
This forum covers OpenCL* for CPU only. OpenCL* for GPU questions can be asked in the GPU Compute Software forum. Intel® FPGA SDK for OpenCL™ questions can be ask in the FPGA Intel® High Level Design forum.
1663 Discussions

printf() with get_global_id uses wrong placeholder

Markus_Dreseler
Beginner
313 Views

Hi everyone,

I stumbled over a weird behavior that I cannot explain:

[cpp]
size_t global_work_sizes[2] = {1, 1};
ret = clEnqueueNDRangeKernel(command_queue, kernel, 2, NULL, global_work_sizes, NULL, 0, NULL, NULL); CHECK(ret);
[/cpp]

[cpp]
__kernel void foo() {
    printf("global id %u\n", get_global_id(0));
        // returns global id 0

    printf("global size %u\n", get_global_size(0));
        // returns global size 1

    printf("global id: %u global size: %u\n", get_global_id(0), get_global_size(0));
        // returns global id: 0 global size: 0 - why is get_global_size(0) = 0?

    printf("global id: %u global size: %u unused var: %u\n", get_global_id(0), get_global_size(0));
        // returns global id: 0 global size: 0 unused var: 1 - where does that 1 come from?

    printf("%u %u\n", 0, 1);
        // return 0 1 - that is what I would be expecting
}
[/cpp]

Am I missing something here?

Cheers,
Markus

0 Kudos
5 Replies
Markus_Dreseler
Beginner
313 Views

(The forum killed my newline escape character - of course I mean %u[backslash]n instead of %un)

Versions:
[bash]
[@memphis:~] $ cat /etc/SuSE-release
SUSE Linux Enterprise Server 11 (x86_64)
VERSION = 11
PATCHLEVEL = 2
[@memphis:~] $ uname -a
Linux memphis 3.0.13-0.27-default #1 SMP Wed Feb 15 13:33:49 UTC 2012 (d73692b) x86_64 x86_64 x86_64 GNU/Linux
[@memphis:~] 1 $ rpm -qa |grep intel
intel-mic-2.1.6720-15.suse
intel-mic-mpm-2.1.6720-15.suse
opencl-1.2-intel-mic-3.0.67279-1
intel-mic-sysmgmt-2.1.6720-15.suse
intel-mic-kmod-2.1.6720-15.3.0.13.0.suse
intel-mic-gdb-2.1.6720-15.suse
intel-mic-flash-2.1.386-3.suse
intel-mic-cdt-2.1.6720-15.suse
opencl-1.2-intel-devel-3.0.67279-1
intel-mic-micmgmt-2.1.6720-15.3.0.13.0.suse
opencl-1.2-intel-cpu-3.0.67279-1
intel-mic-gpl-2.1.6720-15.suse
intel-mic-crashmgr-2.1.6720-15.suse
[/bash]

Yuri_K_Intel
Employee
313 Views
Hi Markus, I was able to reproduce this behavior. I will get back to you after analysis. Thanks, Yuri
Yuri_K_Intel
Employee
313 Views
Markus, Regarding first issue: printf("global id: %u global size: %u\\n", get_global_id(0), get_global_size(0)); // returns global id: 0 global size: 0 - why is get_global_size(0) = 0? I think you need to specify %zu instead of just %u, since get_global_id and get_global_size functions return size_t type. The output becomes correct for me in this case. Regarding second issue: printf("global id: %u global size: %u unused var: %un", get_global_id(0), get_global_size(0)); // returns global id: 0 global size: 0 unused var: 1 - where does that 1 come from? I have compiled a similar C program and its output was exactly the same. Per Microsoft's documentation (http://msdn.microsoft.com/en-us/library/vstudio/wc7014hz.aspx) - The results are undefined if there are not enough arguments for all the format specifications. So, I guess this is not a real issue for OpenCL implementation as well. Thanks, Yuri
Markus_Dreseler
Beginner
313 Views

Hi Yuri,

Thank you for looking into it. Your explanation makes perfect sense. I never ran into %u returning wrong results, so I made a wrong assumption here.

Best,
Markus

LSolis
Beginner
313 Views

Hi,

I had the same problem, but the %zu was the solution.
Thanks for this post. Saved my day!

Reply