OpenCL 是一个为异构平台编写程序的框架,此异构平台可由CPU,GPU或其他类型的处理器组成。我们先来复习下CPU和GPU的相关知识:CPU的设计让其比较擅长于处理不规则数据结构和不可预测的存取模式,以及递归算法、分支密集型代码和单线程程序。这类程序任务拥有复杂的指令调度、循环、分支、逻辑判断以及执行等步骤。而GPU擅于处理规则数据结构和可预测存取模式。
这里只介绍LINUX下的安装。
sudo apt-get install python3-pyopencl
因此我们除了要获取系统里计算平台设备信息外,还要获取每个设备里面的计算核心信息,这样才可以对我们的程序进行最大优化。
import pyopencl as cl #显示OPENCL版本号,cl.h的版本号 print("CL_VERSION:",cl.VERSION) print("CL_HEADER_VERSION:",cl.get_cl_header_version()) print() #获取当前所有计算平台 platforms = cl.get_platforms() print("Platform num:",len(platforms)) #遍历所有平台中的所有计算设备,并显示它们的信息 for plat in platforms: print("--Platform Name:",plat.get_info(cl.platform_info.NAME)) #print("--Platform Extensions:",plat.get_info(cl.platform_info.EXTENSIONS)) print("--Platform Profile:",plat.get_info(cl.platform_info.PROFILE)) print("--Platform Vendor:",plat.get_info(cl.platform_info.VENDOR)) print("--Platform Version:",plat.get_info(cl.platform_info.VERSION)) devices = plat.get_devices(cl.device_type.ALL) print("--device num:",len(devices)) for device in devices: print("----Name:",device.get_info(cl.device_info.NAME)) print("----OpenCL_C_Version:",device.get_info(cl.device_info.OPENCL_C_VERSION)) print("----Vendor:",device.get_info(cl.device_info.VENDOR)) print("----Version:",device.get_info(cl.device_info.VERSION)) print("----Driver Version:",device.get_info(cl.device_info.DRIVER_VERSION)) print("----MAX_WORK_GROUP_SIZE:",device.get_info(cl.device_info.MAX_WORK_GROUP_SIZE)) print("----MAX_COMPUTE_UNITS:",device.get_info(cl.device_info.MAX_COMPUTE_UNITS)) print("----MAX_WORK_ITEM_SIZES:",device.get_info(cl.device_info.MAX_WORK_ITEM_SIZES)) print("----LOCAL_MEM_SIZE:",device.get_info(cl.device_info.LOCAL_MEM_SIZE))
桂ICP备11003301号-1 公安备案号:45040302000027 Copyright @ 2021- 2022 By Sun zi chao
阅读统计: 1.93W 文章数量: 76 运行天数: 416天 返回cmnsoft
● PyOpenCL示例-01.设备遍历
● PyOpenCL示例-02.向量与矩阵运算
● PyOpenCL示例-03.图片操作
● PyOpenCL示例-04.内存架构
● PyOpenCL示例-05.数值归并