显示所有CPU和GPU的OpenCL代码

效果如图:
显示所有CPU和GPU的OpenCL代码


#include <CL/cl.h>

#include <stdio.h>

 

int main()

{

          unsigned int i, j;                                //iterator variables for loops

          cl_int err;

          cl_platform_id platforms[32];                     //an array to hold the IDs of all the platforms, hopefuly there won't be more than 32

          cl_uint num_platforms;                                      //this number will hold the number of platforms on this machine

          char vendor[1024];                                //this strirng will hold a platforms vendor

         

          cl_device_id devices[16];          //this variable holds the number of devices for each platform, hopefully it won't be more than 32 per platform

                                                                                //32 devices doesn't work with TDM-GCC 4.9.2 64bit

          cl_uint num_devices;                                        //this number will hold the number of devices on this machine

          char deviceName[1024];                                      //this string will hold the devices name

          cl_uint numberOfCores;                                      //this variable holds the number of cores of on a device

          cl_long amountOfMemory;                                     //this variable holds the amount of memory on a device

          cl_uint clockFreq;                                //this variable holds the clock frequency of a device

          cl_ulong maxAlocatableMem;                        //this variable holds the maximum allocatable memory

          cl_ulong localMem;                                //this variable holds local memory for a device

          cl_bool   available;                                        //this variable holds if the device is available

         

          char buildinkernels[1024];

          //get the number of platforms

          clGetPlatformIDs (32, platforms, &num_platforms);

         

          printf("\nNumber of platforms:\t%u\n\n", num_platforms);

         

          //this is a loop for platforms

          for(i = 0; i < num_platforms; i++)

          {

                    printf("Platform:\t\t%u\n\n", i);

                    err=clGetPlatformInfo (platforms[i], CL_PLATFORM_VENDOR, sizeof(vendor), vendor, NULL);

                    printf("\tPlatform Vendor:\t%s (err==%d,%d)\n", vendor, err, CL_SUCCESS);

                   

                    err=clGetDeviceIDs (platforms[i], CL_DEVICE_TYPE_ALL, sizeof(devices), devices, &num_devices);

                    printf("\tNumber of devices:\t%u  (err==%d,%d) \n\n", num_devices, err, CL_SUCCESS);

                    //this is a loop for devices

                    for(j = 0; j < num_devices; j++)

                    {

                              //scan in device information

                              clGetDeviceInfo(devices[j], CL_DEVICE_NAME, sizeof(deviceName), deviceName, NULL);

                              clGetDeviceInfo(devices[j], CL_DEVICE_VENDOR, sizeof(vendor), vendor, NULL);

                              clGetDeviceInfo(devices[j], CL_DEVICE_MAX_COMPUTE_UNITS, sizeof(numberOfCores), &numberOfCores, NULL);

                              clGetDeviceInfo(devices[j], CL_DEVICE_GLOBAL_MEM_SIZE, sizeof(amountOfMemory), &amountOfMemory, NULL);

                              clGetDeviceInfo(devices[j], CL_DEVICE_MAX_CLOCK_FREQUENCY, sizeof(clockFreq), &clockFreq, NULL);

                              clGetDeviceInfo(devices[j], CL_DEVICE_MAX_MEM_ALLOC_SIZE, sizeof(maxAlocatableMem), &maxAlocatableMem, NULL);

                              clGetDeviceInfo(devices[j], CL_DEVICE_LOCAL_MEM_SIZE, sizeof(localMem), &localMem, NULL);

                              clGetDeviceInfo(devices[j], CL_DEVICE_AVAILABLE, sizeof(available), &available, NULL);

                             

                              clGetDeviceInfo(devices[j], CL_DEVICE_BUILT_IN_KERNELS, sizeof(buildinkernels), &buildinkernels, NULL);

                              //print out device information

                              printf("\tDevice: %u\n", j);

                              printf("\t\tName:\t\t\t\t%s\n", deviceName);

                              printf("\t\tVendor:\t\t\t\t%s\n", vendor);

                              printf("\t\tAvailable:\t\t\t%s\n", available ? "Yes" : "No");

                              printf("\t\tCompute Units:\t\t\t%u\n", numberOfCores);

                              printf("\t\tClock Frequency:\t\t%u mHz\n", clockFreq);

                              printf("\t\tGlobal Memory:\t\t\t%0.00f mb\n", (double)amountOfMemory/1048576);

                              printf("\t\tMax Allocateable Memory:\t%0.00f mb\n", (double)maxAlocatableMem/1048576);

                              printf("\t\tLocal Memory:\t\t\t%u kb\n", (unsigned int)localMem);

                             

                              printf("\t\tBuild In Kernels:\t\t%s\n",buildinkernels);

                             

                              clGetDeviceInfo(devices[j], CL_DEVICE_OPENCL_C_VERSION, sizeof(buildinkernels), &buildinkernels, NULL);

                              printf("\t\tOpenCL Version:\t\t\t%s\n",buildinkernels);

                              clGetDeviceInfo(devices[j], CL_DEVICE_PROFILE, sizeof(buildinkernels), &buildinkernels, NULL);

                              printf("\t\tDevice profile:\t\t\t%s\n",buildinkernels);

                             

                              clGetDeviceInfo(devices[j], CL_DEVICE_VERSION, sizeof(buildinkernels), &buildinkernels, NULL);

                              printf("\t\tDevice version:\t\t\t%s\n",buildinkernels);

                             

                              clGetDeviceInfo(devices[j], CL_DRIVER_VERSION , sizeof(buildinkernels), &buildinkernels, NULL);

                              printf("\t\tDriver version:\t\t\t%s\n",buildinkernels);

                             

                              printf("\n");

                    }

          }

          system("PAUSE");

          return 0;

}

 


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值