【OpenCL】获取设备上支持的imageFormats

在opencl中,imagebuffer是一个非常高效的操作图像的缓冲区。在定义imagebuffer的cl_image_format的时候,往往需要查询当前设备支持的image format。

查询函数:clGetSupportedImageFormats
官网API:https://www.khronos.org/registry/OpenCL/sdk/1.0/docs/man/xhtml/clGetSupportedImageFormats.html

clGetSupportedImageFormats查询用例如下:

	cl_uint uiNumSupportedFormats = 0;
	cl_uint uiRealNumSupportedFormats = 0;
	clGetSupportedImageFormats(context, CL_MEM_READ_ONLY, 
								CL_MEM_OBJECT_IMAGE2D,   
								0, NULL, &uiNumSupportedFormats);
	cl_image_format* ImageFormats = new cl_image_format[uiNumSupportedFormats];
	clGetSupportedImageFormats(context, CL_MEM_READ_ONLY, 
								CL_MEM_OBJECT_IMAGE2D,   
								uiNumSupportedFormats, ImageFormats, NULL);
	printf("  ---------------------------------\n");
	printf("  2D Image Formats Supported (%u)\n", uiNumSupportedFormats); 
	printf("  ---------------------------------\n");
	printf("  %-6s%-16s%-22s\n\n", "#", "Channel Order", "Channel Type"); 
	for(unsigned int i = 0; i < uiNumSupportedFormats; i++) 
	{  
		printf("  %-6u%-16s%-22s\n", (i + 1),
				oclImageFormatString(ImageFormats[i].image_channel_order), 
				oclImageFormatString(ImageFormats[i].image_channel_data_type));
	}
	printf("\n"); 
	delete [] ImageFormats;

	// 3D
	clGetSupportedImageFormats(context, CL_MEM_READ_ONLY, 
								CL_MEM_OBJECT_IMAGE3D,   
								0, NULL, &uiNumSupportedFormats);
	ImageFormats = new cl_image_format[uiNumSupportedFormats];
	clGetSupportedImageFormats(context, CL_MEM_READ_ONLY, 
								CL_MEM_OBJECT_IMAGE3D,   
								uiNumSupportedFormats, ImageFormats, NULL);
	printf("  ---------------------------------\n");
	printf("  3D Image Formats Supported (%u)\n", uiNumSupportedFormats); 
	printf("  ---------------------------------\n");
	printf("  %-6s%-16s%-22s\n\n", "#", "Channel Order", "Channel Type"); 
	for(unsigned int i = 0; i < uiNumSupportedFormats; i++) 
	{  
		printf("  %-6u%-16s%-22s\n", (i + 1),
				oclImageFormatString(ImageFormats[i].image_channel_order), 
				oclImageFormatString(ImageFormats[i].image_channel_data_type));
	}
	printf("\n"); 
	delete [] ImageFormats;

其中上文用到的oclImageFormatString函数如下:

const char* oclImageFormatString(cl_uint uiImageFormat){
    // cl_channel_order 
    if (uiImageFormat == CL_R)return "CL_R";  
    if (uiImageFormat == CL_A)return "CL_A";  
    if (uiImageFormat == CL_RG)return "CL_RG";  
    if (uiImageFormat == CL_RA)return "CL_RA";  
    if (uiImageFormat == CL_RGB)return "CL_RGB";
    if (uiImageFormat == CL_RGBA)return "CL_RGBA";  
    if (uiImageFormat == CL_BGRA)return "CL_BGRA";  
    if (uiImageFormat == CL_ARGB)return "CL_ARGB";  
    if (uiImageFormat == CL_INTENSITY)return "CL_INTENSITY";  
    if (uiImageFormat == CL_LUMINANCE)return "CL_LUMINANCE";  

    // cl_channel_type 
    if (uiImageFormat == CL_SNORM_INT8)return "CL_SNORM_INT8";
    if (uiImageFormat == CL_SNORM_INT16)return "CL_SNORM_INT16";
    if (uiImageFormat == CL_UNORM_INT8)return "CL_UNORM_INT8";
    if (uiImageFormat == CL_UNORM_INT16)return "CL_UNORM_INT16";
    if (uiImageFormat == CL_UNORM_SHORT_565)return "CL_UNORM_SHORT_565";
    if (uiImageFormat == CL_UNORM_SHORT_555)return "CL_UNORM_SHORT_555";
    if (uiImageFormat == CL_UNORM_INT_101010)return "CL_UNORM_INT_101010";
    if (uiImageFormat == CL_SIGNED_INT8)return "CL_SIGNED_INT8";
    if (uiImageFormat == CL_SIGNED_INT16)return "CL_SIGNED_INT16";
    if (uiImageFormat == CL_SIGNED_INT32)return "CL_SIGNED_INT32";
    if (uiImageFormat == CL_UNSIGNED_INT8)return "CL_UNSIGNED_INT8";
    if (uiImageFormat == CL_UNSIGNED_INT16)return "CL_UNSIGNED_INT16";
    if (uiImageFormat == CL_UNSIGNED_INT32)return "CL_UNSIGNED_INT32";
    if (uiImageFormat == CL_HALF_FLOAT)return "CL_HALF_FLOAT";
    if (uiImageFormat == CL_FLOAT)return "CL_FLOAT";

    // unknown constant
	return "Unknown";
}
  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值