KhronosGroup / OpenCL-Docs

OpenCL API, OpenCL C, Extensions, SPIR-V Environment Specs, Ref page, and C++ for OpenCL doc sources.
Other
356 stars 113 forks source link

printf z format qualifier #654

Open alycm opened 3 years ago

alycm commented 3 years ago

OpenCL C has a size_t type, but the OpenCL C printf excludes the z format qualifier. This makes it slightly harder to use printf to print things such as get_global_id(...) values.

The ll, j, z, t, and L length modifiers are not supported by OpenCL C but are reserved.

This can't be changed in an an existing version of OpenCL, but it is a small issue that could be considered in the future.

In terms of specification I think it would just be necessary to drop the restriction from the OpenCL C spec, and extend a few modifier lists. The SPIR-V extension instruction just takes a format string as well, so no additional changes.

For implementations that implement printf by sending a buffer of data back to the host that makes the size of the contents of the buffer device-dependent, but that is already the case for the p format qualifier.

bashbaug commented 3 years ago

To save others a search:

https://en.wikipedia.org/wiki/Printf_format_string#Length_field

I can see value in supporting t and z for sure, since we support ptrdiff_t and size_t in OpenCL C.

I'm less sure about ll, j, and L since we currently do not support long long, intmax_t, or long double in OpenCL C. long long and long double are officially reserved. We don't say anything about intmax_t (though we could):

https://www.khronos.org/registry/OpenCL/specs/3.0-unified/html/OpenCL_C.html#reserved-data-types

To be clear, I'm not opposed to adding these but they need a bit more thought.

I also think it would be valuable to support the platform-independent macros from inttypes.h, e.g. PRId32.