0
点赞
收藏
分享

微信扫一扫

OpenCL列举平台列表以及平台属性信息


摘自《OpenCL异构并行计算原理、机制与优化实践》

// Platform.cpp : Defines the entry point for the console application.
//

#include "stdafx.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);

}



return 0;
}

OpenCL列举平台列表以及平台属性信息_异构


举报

相关推荐

0 条评论