printf() with get_global_id uses wrong placeholder

printf() with get_global_id uses wrong placeholder

Hi everyone,

I stumbled over a weird behavior that I cannot explain:

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

__kernel void foo() {
    printf("global id %un", get_global_id(0));
        // returns global id 0
    printf("global size %un", get_global_size(0));
        // returns global size 1
    printf("global id: %u global size: %un", 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: %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?
    printf("%u %un", 0, 1);
        // return 0 1 - that is what I would be expecting
}

Am I missing something here?

Cheers,
Markus

5 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

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

Versions:

[@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

Hi Markus,

I was able to reproduce this behavior. I will get back to you after analysis.

Thanks,
Yuri

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

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

Leave a Comment

Please sign in to add a comment. Not a member? Join today