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 platform

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值