验证opencl
测试代码:
#define CL_TARGET_OPENCL_VERSION 220
#include <opencl.h>
//#include <CL/cl.h>
#include<stdio.h>
#include<string.h>
#include<malloc.h>
int main() {
cl_platform_id *platform;
cl_uint num_platform;
cl_int err;
err = clGetPlatformIDs(0, NULL, &num_platform);
platform = (cl_platform_id *)malloc(sizeof(cl_platform_id) * num_platform);
err = clGetPlatformIDs(num_platform, platform, NULL);
for (int i = 0; i < num_platform; i++)
{
size_t size;
// get name
err = clGetPlatformInfo(platform[i], CL_PLATFORM_NAME, 0, NULL, &size);
char *name = (char *)malloc(size);
err = clGetPlatformInfo(platform[i], CL_PLATFORM_NAME, size, name, NULL);
printf("CL_PLATFORM_NAME:%s\n", name);
// vendor
err = clGetPlatformInfo(platform[i], CL_PLATFORM_VENDOR, 0, NULL, &size);
char *vendor = (char *)malloc(size);
err = clGetPlatformInfo(platform[i], CL_PLATFORM_VENDOR, size, vendor, NULL);
printf("CL_PLATFORM_VENDOR:%s\n", vendor);
// version
err = clGetPlatformInfo(platform[i], CL_PLATFORM_VERSION, 0, NULL, &size);
char *version = (char *)malloc(size);
err = clGetPlatformInfo(platform[i], CL_PLATFORM_VERSION, size, version, NULL);
printf("CL_PLATFORM_VERSION:%s\n", version);
// profile
err = clGetPlatformInfo(platform[i], CL_PLATFORM_PROFILE, 0, NULL, &size);
char *profile = (char *)malloc(size);
err = clGetPlatformInfo(platform[i], CL_PLATFORM_PROFILE, size, profile, NULL);
printf("CL_PLATFORM_PROFILE:%s\n", profile);
// extensions
err = clGetPlatformInfo(platform[i], CL_PLATFORM_EXTENSIONS, 0, NULL, &size);
char *extensions = (char *)malloc(size);
err = clGetPlatformInfo(platform[i], CL_PLATFORM_EXTENSIONS, size, extensions, NULL);
printf("CL_PLATFORM_EXTENSIONS:%s\n", extensions);
printf("\n\n");
// clean
free(name);
free(vendor);
free(version);
free(profile);
free(extensions);
free(platform);
return 0;
}
编译命令
gcc test.cpp -o opencl_test -lmali -L/usr/lib/aarch64-linux-gnu/ -I/usr/include/CL/
结果
firefly@firefly:~$ ./opencl_test
CL_PLATFORM_NAME:ARM Platform
CL_PLATFORM_VENDOR:ARM
CL_PLATFORM_VERSION:OpenCL 2.1 v1.g6p0-01eac0.2819f9d4dbe0b5a2f89c835d8484f9cd
CL_PLATFORM_PROFILE:FULL_PROFILE
CL_PLATFORM_EXTENSIONS:cl_khr_global_int32_base_atomics cl_khr_global_int32_extended_atomics cl_khr_local_int32_base_atomics cl_khr_local_int32_extended_atomics cl_khr_byte_addressable_store cl_khr_3d_image_writes cl_khr_int64_base_atomics cl_khr_int64_extended_atomics cl_khr_fp16 cl_khr_icd cl_khr_egl_image cl_khr_image2d_from_buffer cl_khr_depth_images cl_khr_subgroups cl_khr_subgroup_extended_types cl_khr_subgroup_non_uniform_vote cl_khr_subgroup_ballot cl_khr_il_program cl_khr_priority_hints cl_khr_create_command_queue cl_khr_spirv_no_integer_wrap_decoration cl_khr_extended_versioning cl_khr_device_uuid cl_arm_core_id cl_arm_printf cl_arm_non_uniform_work_group_size cl_arm_import_memory cl_arm_import_memory_dma_buf cl_arm_import_memory_host cl_arm_integer_dot_product_int8 cl_arm_integer_dot_product_accumulate_int8 cl_arm_integer_dot_product_accumulate_saturate_int8 cl_arm_scheduling_controls cl_arm_controlled_kernel_termination cl_ext_cxx_for_opencl
参考:
https://blog.csdn.net/BV12345/article/details/106466511