I try to write some code using OpenCL to test Mali GPU:
err = clGetPlatformIDs(0, NULL, &num_platforms); check_error(err, "clGetPlatformIDs"); if (num_platforms > 0) { printf("Number of platforms: %d\n", num_platforms); } else { fprintf(stderr, "No OpenCL platforms found.\n"); exit(-1); } platforms = (cl_platform_id *)malloc(num_platforms * sizeof(cl_platform_id)); err = clGetPlatformIDs(num_platforms, platforms, NULL); check_error(err, "clGetPlatformIDs"); for (int i = 0; i < num_platforms; i++) { cl_platform_id platform = platforms[i]; char name[128]; err = clGetPlatformInfo(platform, CL_PLATFORM_NAME, 128, name, NULL); check_error(err, "clGetPlatformInfo"); printf("Platform %d: %s\n", i, name); char profile[128]; err = clGetPlatformInfo(platform, CL_PLATFORM_PROFILE, 128, profile, NULL); check_error(err, "clGetPlatformInfo"); printf("Platform %d: %s\n", i, profile); char version[128]; err = clGetPlatformInfo(platform, CL_PLATFORM_VERSION, 128, version, NULL); check_error(err, "clGetPlatformInfo"); printf("Platform %d: %s\n", i, version); status = clGetDeviceIDs(platform, CL_DEVICE_TYPE_ALL, 0, NULL, &num_devices); check_error(status, "clGetDeviceIDs"); if (num_devices > 0) { printf("Number of devices: %d\n", num_devices); } else { fprintf(stderr, "No OpenCL devices found.\n"); continue; } devices = (cl_device_id *)malloc(num_devices * sizeof(cl_device_id)); err = clGetDeviceIDs(platform, CL_DEVICE_TYPE_ALL, num_devices, devices, NULL); check_error(err, "clGetDeviceIDs"); for (int j = 0; j < num_devices; j++) { cl_device_id device = devices[j]; char device_name[128]; err = clGetDeviceInfo(device, CL_DEVICE_NAME, 128, device_name, NULL); check_error(err, "clGetDeviceInfo"); printf("Device %d: %s\n", j, device_name); cl_uint max_compute_units; err = clGetDeviceInfo(device, CL_DEVICE_MAX_COMPUTE_UNITS, sizeof(cl_uint), &max_compute_units, NULL); check_error(err, "clGetDeviceInfo"); printf("Device %d: Max compute units: %d\n", j, max_compute_units); cl_ulong global_mem_size; err = clGetDeviceInfo(device, CL_DEVICE_GLOBAL_MEM_SIZE, sizeof(cl_ulong), &global_mem_size, NULL); check_error(err, "clGetDeviceInfo"); printf("Device %d: Global memory size: %ld\n", j, (uint64_t)global_mem_size); } } free(devices); free(platforms);
But it returns `CL_OUT_OF_HOST_MEMORY` (-6):
Number of platforms: 1 Platform 0: ARM Platform Platform 0: FULL_PROFILE Platform 0: OpenCL 2.0 v1.r9p0-01rel0.37c12a13c46b4c2d9d736e0d5ace2e5e Number of devices: 1 Failed creating base context during opening of kernel driver. Kernel module may not have been loaded Error during operation 'clGetDeviceInfo': -6
I don't know what's wrong with my code.
Sorry for disturbing, I have replaced the kernel and forgot to compile the mali driver...
No problem, I am glad you found the solution to your question. Please visit again if you have any further questions :)
Oli
Arm Community Manager