This patch fixes bug #3293 - OpenCL kernel argument problem with some locales #3294
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Short Description:
There is a problem when the locale is non C when rendering the arguments to OpenCL kernels.
Short description of the change:
The patch is pretty simple, it changes the toString() function to use the stringstream imbued with C locale in src/backend/common/TemplateArg.cpp and changed the to_string calls to this toString function in types.cpp.
Description
The arguments provided to OpenCL uses the C++ standard library function std::to_string(). This function uses the locale to render it's argument to a string.
It is a problem when arrayfire is used in a
software initialised with non "C" locale.
For instance, on a French computer, to_string(1.0) will output the string "1,0000000".
This string is provided to OpenCL kernels, generating a syntax error.
The most portable way to fix this problem is to use a local ostringstream imbued withe "C" locale.
An Other way would be to use C++17 to_chars function, as it only renders it argument with "C" locale, without impact from the application or system locale.
I did not use this latest solution as it would force the use of C++17.