cancel
Showing results for 
Search instead for 
Did you mean: 

OpenCL

set
Adept II

AMD OpenCL runtime breaks locale environment

System: Windows 10

GPU: Radeon RX 6900 XT

System locale is set to 'ru-RU', but decimal separator (sDecimal) is set to '.' (usually it is ',' in this locale).

Using AMD OpenCL runtime breaks the process locale environment after calling clCreateCommandQueue: decimal separator becomes ','

Here is minimal code to reproduce the issue:

#include <stdio.h>
#include <locale.h>
#include <stdlib.h>
#include <Cl/cl.h>

int main(void)
{
	volatile double v = 0.5;
	setlocale(LC_ALL, ""); // <- important, no issue if not called

	printf("1: %.1lf\n", v); // <- prints 0.5

	cl_uint platforms_num;
	clGetPlatformIDs(0, NULL, &platforms_num);
	cl_platform_id *platforms = malloc(sizeof(cl_platform_id)*platforms_num);
	clGetPlatformIDs(platforms_num, platforms, NULL);
	for (cl_uint i = 0; i < platforms_num; i++)
	{
		char platform_name[0x40];
		if (clGetPlatformInfo(platforms[i], CL_PLATFORM_VENDOR, sizeof(platform_name), platform_name, NULL) || strcmp(platform_name, "Advanced Micro Devices, Inc."))
			continue;
		cl_uint devices_num;
		if (clGetDeviceIDs(platforms[i], CL_DEVICE_TYPE_ALL, 0, NULL, &devices_num) || !devices_num)
			continue;
		cl_device_id *devices = malloc(sizeof(cl_device_id)*devices_num);
		clGetDeviceIDs(platforms[i], CL_DEVICE_TYPE_ALL, devices_num, devices, NULL);
		cl_context context = clCreateContext(NULL, 1, &devices[0], NULL, NULL, NULL);

		printf("2: %.1lf\n", v); // <- prints 0.5

		cl_command_queue command_queue = clCreateCommandQueue(context, devices[0], 0, NULL);

		printf("3: %.1lf\n", v); // <- prints 0,5

		clReleaseCommandQueue(command_queue);
		clReleaseContext(context);
		free(devices);
		break;
	}
	free(platforms);

	return 0;
}

 

The issue is present when compiled with latest VisualStudio 2022 and 'Runtime Library' is set to 'Multi-threaded DLL'. No issue for debug or static runtimes.

0 Likes
0 Replies