函数clGetContextInfo提供了关于上下文的信息。
其函数原型如下:
clGetContextInfo(cl_context context, cl_context_info param_name,
size_t param_value_size, void* param_value, size_t * param_value_size_ret);
cl_context_info是枚举类型,可以枚举下列值:
cl_uint ref_count;
cl_uint num_devices;
cl_context_properties* properties;
err = clGetContextInfo(context, CL_CONTEXT_NUM_DEVICES, sizeof(num_devices), &num_devices, NULL);
err = clGetContextInfo(context, CL_CONTEXT_REFERENCE_COUNT, sizeof(ref_count), &ref_count, NULL);
printf("num_devices : %d\n", num_devices);
printf("ref_count : %d \n", ref_count);
clRetainContext(context);
err = clGetContextInfo(context, CL_CONTEXT_REFERENCE_COUNT, sizeof(ref_count), &ref_count, NULL);
printf("ref_count : %d \n", ref_count);
clReleaseContext(context);
err = clGetContextInfo(context, CL_CONTEXT_REFERENCE_COUNT, sizeof(ref_count), &ref_count, NULL);
printf("ref_count : %d \n", ref_count);
其中,OpenCL需要对cl_context被访问的次数进行管理。在创建cl_context时,这个计数被初始化为1,而当计数为0时,程序会释放相应的空间。改变引用计数的方式有两种,clRetainContext和clReleaseContext。