• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ clGetPlatformInfo函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中clGetPlatformInfo函数的典型用法代码示例。如果您正苦于以下问题:C++ clGetPlatformInfo函数的具体用法?C++ clGetPlatformInfo怎么用?C++ clGetPlatformInfo使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了clGetPlatformInfo函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: clGetPlatformIDs

int
MemoryOptimizations::setupCL(void)
{
    cl_int status = 0;
    size_t deviceListSize;

    cl_device_type dType;
    
    if(deviceType.compare("cpu") == 0)
    {
        dType = CL_DEVICE_TYPE_CPU;
    }
    else //deviceType = "gpu" 
    {
        dType = CL_DEVICE_TYPE_GPU;
    }

    /*
     * Have a look at the available platforms and pick either
     * the AMD one if available or a reasonable default.
     */

    cl_uint numPlatforms;
    cl_platform_id platform = NULL;
    status = clGetPlatformIDs(0, NULL, &numPlatforms);
    if(!sampleCommon->checkVal(status,
                               CL_SUCCESS,
                               "clGetPlatformIDs failed."))
    {
        return SDK_FAILURE;
    }
    if (0 < numPlatforms) 
    {
        cl_platform_id* platforms = new cl_platform_id[numPlatforms];
        status = clGetPlatformIDs(numPlatforms, platforms, NULL);
        if(!sampleCommon->checkVal(status,
                                   CL_SUCCESS,
                                   "clGetPlatformIDs failed."))
        {
            return SDK_FAILURE;
        }
        for (unsigned i = 0; i < numPlatforms; ++i) 
        {
            char pbuf[100];
            status = clGetPlatformInfo(platforms[i],
                                       CL_PLATFORM_VENDOR,
                                       sizeof(pbuf),
                                       pbuf,
                                       NULL);

            if(!sampleCommon->checkVal(status,
                                       CL_SUCCESS,
                                       "clGetPlatformInfo failed."))
            {
                return SDK_FAILURE;
            }

            platform = platforms[i];
            if (!strcmp(pbuf, "Advanced Micro Devices, Inc.")) 
            {
                break;
            }
        }
        delete[] platforms;
    }

    if(NULL == platform)
    {
        sampleCommon->error("NULL platform found so Exiting Application.");
        return SDK_FAILURE;
    }

    // Display available devices.
    if(!sampleCommon->displayDevices(platform, dType))
    {
        sampleCommon->error("sampleCommon::displayDevices() failed");
        return SDK_FAILURE;
    }

    /*
     * If we could find our platform, use it. Otherwise use just available platform.
     */

    cl_context_properties cps[3] = 
    {
        CL_CONTEXT_PLATFORM, 
        (cl_context_properties)platform, 
        0
    };

    context = clCreateContextFromType(cps,
                                      dType,
                                      NULL,
                                      NULL,
                                      &status);
    if(!sampleCommon->checkVal(status, 
                               CL_SUCCESS,
                               "clCreateContextFromType failed."))
        return SDK_FAILURE;

//.........这里部分代码省略.........
开发者ID:pbains,项目名称:m2s-bench-amdapp-2.5,代码行数:101,代码来源:MemoryOptimizations.cpp


示例2: device_check

int device_check()
{

    
    cl_int err;
    cl_int i,j,cnt;
    
    cl_platform_id *platforms;
    cl_uint num_platforms;
    cl_platform_id platform;

    char* ext_data;
    size_t ext_size;
        
    cl_device_id *devs;
    size_t num_devs;
    cl_device_id device;
    
    /* Program data structures */
    cl_program program;
    FILE *program_handle;
    char *program_buffer[NUM_FILES];
    char *program_log;
    const char *file_name[] = {PROGRAM_FILE_1, PROGRAM_FILE_2};
    const char options[] = "-cl-finite-math-only -cl-no-signed-zeros";  
    size_t program_size[NUM_FILES];
    size_t log_size;
    
    /*kernel data*/
    cl_kernel *kernels;
    cl_uint num_kernels;
    

    /*枚举所有的平台,最多10个*/
    err = clGetPlatformIDs(10, NULL, &num_platforms);  /*参数1:要枚举的数量,参数2:返回结果的存放空间,参数3:返回结果的条数*/
    if(err < 0) {
        perror("Couldn't find any platforms");
        exit(1);
    }
    platforms=(cl_platform_id *)malloc( sizeof(cl_platform_id) * num_platforms );
    clGetPlatformIDs(num_platforms, platforms, NULL);

    /*现在num_platforms和platforms是平台的数量和数据指针*/
    /* Find infor of all platforms */
    for (i=0; i<num_platforms; i++)
    {
        /* Find size of extension data */
        /*clGetPlatformInfo*/
        /*
        参数1:平台
        参数2:所需信息的枚举
        参数3:返回值需要保存的长度
        参数4:返回值的存储空间
        参数5:所需数据的真实长度
        */

        
        platform = platforms[i]

        /*NAME*/
        err = clGetPlatformInfo(platform, CL_PLATFORM_NAME, 0, NULL, &ext_size);  
        if(err < 0) {
            perror("Couldn't read CL_PLATFORM_NAME data.");
        }
        ext_data = (char *)malloc(ext_size);
        clGetPlatformInfo(platform, CL_PLATFORM_NAME, ext_size, ext_data, NULL);
        printf("Platform %d name: %s\n", i, ext_data);
        free(ext_data);

        /*VRNDOR*/
        err = clGetPlatformInfo(platform, CL_PLATFORM_VENDER, 0, NULL, &ext_size);
        if(err < 0) {
            perror("Couldn't read CL_PLATFORM_VENDER data.");
        }
        ext_data = (char *)malloc(ext_size);
        clGetPlatformInfo(platform, CL_PLATFORM_VENDER, ext_size, ext_data, NULL);
        printf("Platform %d vender: %s\n", i, ext_data);
        free(ext_data)

        /*VERSION*/
        err = clGetPlatformInfo(platform, CL_PLATFORM_VERSION, 0, NULL, &ext_size);
        if(err < 0) {
            perror("Couldn't read CL_PLATFORM_VERSION data.");
        }
        ext_data = (char *)malloc(ext_size);
        clGetPlatformInfo(platform, CL_PLATFORM_VERSION, ext_size, ext_data, NULL);
        printf("Platform %d support OpenCL version: %s\n", i, ext_data);
        free(ext_data)
        
        /*PROFILE*/
        err = clGetPlatformInfo(platform, CL_PLATFORM_PROFILE, 0, NULL, &ext_size);
        if(err < 0) {
            perror("Couldn't read CL_PLATFORM_PROFILE data.");
        }
        ext_data = (char *)malloc(ext_size);
        clGetPlatformInfo(platform, CL_PLATFORM_PROFILE, ext_size, ext_data, NULL);
        printf("Platform %d support OpenCL profile: %s\n", i, ext_data);
        free(ext_data)
        
        /*EXTENSIONS*/
//.........这里部分代码省略.........
开发者ID:abednego1979,项目名称:tipster,代码行数:101,代码来源:device_check.c


示例3: main

int main() {
    // Get platform information
    err = clGetPlatformIDs(0, NULL, &numOfPlatforms);
    if (err) Error("Fail to get the number of platforms");
    printf("The machine has %d platform(s) for OpenCL.\n", numOfPlatforms);

    platformIDs = new cl_platform_id [numOfPlatforms];
    err = clGetPlatformIDs(numOfPlatforms, platformIDs, NULL);
    if (err) Error("Fail to get the platform list");

    int cudaPlatformID = -1;

    for (int i = 0; i < numOfPlatforms; i++) {
        char platformName[50];
        err = clGetPlatformInfo(platformIDs[i], CL_PLATFORM_NAME, 50, platformName, NULL);
        if (err) Error("Fail to get the platform name");
        printf("Platform %d is %s\n", i + 1, platformName);
        if (!strcmp(platformName, "NVIDIA CUDA")) cudaPlatformID = i;
    }
    printf("\n");

    if (cudaPlatformID == -1) Error("Fail to find an NVIDIA CUDA platform");

    printf("Platform %d (NVIDIA CUDA) is chosen for use.\n", cudaPlatformID + 1);
    printf("\n");

    // Get device information
    err = clGetDeviceIDs(platformIDs[cudaPlatformID], CL_DEVICE_TYPE_GPU, 0, NULL, &numOfDevices);
    if (err) Error("Fail to get the number of devices");
    printf("CUDA platform has %d device(s).\n", numOfDevices);

    deviceIDs = new cl_device_id [numOfDevices];
    err = clGetDeviceIDs(platformIDs[cudaPlatformID], CL_DEVICE_TYPE_GPU, numOfDevices, deviceIDs, NULL);
    if (err) Error("Fail to get the device list");
    for (int i = 0; i < numOfDevices; i++) {
        char deviceName[50];
        err = clGetDeviceInfo(deviceIDs[i], CL_DEVICE_NAME, 50, deviceName, NULL);
        if (err) Error("Fail to get the device name");
        printf("Device %d is %s\n", i + 1, deviceName);
    }
    printf("\n");

    // Create a context
    context = clCreateContext(NULL, numOfDevices, deviceIDs, NULL, NULL, &err);
    if (err) Error("Fail to create a context");

    printf("Device 1 is chosen for use.\n");
    printf("\n");

    // Create a command queue for the first device
    commandQueue = clCreateCommandQueue(context, deviceIDs[0],
                                        CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE | CL_QUEUE_PROFILING_ENABLE, &err);
    if (err) Error("Fail to create a command queue");

    // create the program
    cl_program program = CreateProgram(exclusiveScanKernels, "exclusive scan");

    // create two kernels
    cl_kernel scanKernel = clCreateKernel(program, "Scan", &err);
    if (err) Error("Fail to create the kernel for scan");

    cl_kernel reverseUpdateKernel = clCreateKernel(program, "ReverseUpdate", &err);
    if (err) Error("Fail to create the kernel for reverse update");

    // Get the work group size
    size_t maxWorkGroupSize;
    err = clGetKernelWorkGroupInfo(scanKernel, deviceIDs[0], CL_KERNEL_WORK_GROUP_SIZE,
                                   sizeof(size_t), &maxWorkGroupSize, NULL);
    printf("maxWorkGroupSize = %d\n", maxWorkGroupSize);

    err = clGetKernelWorkGroupInfo(reverseUpdateKernel, deviceIDs[0], CL_KERNEL_WORK_GROUP_SIZE,
                                   sizeof(size_t), &maxWorkGroupSize, NULL);
    printf("maxWorkGroupSize = %d\n", maxWorkGroupSize);

    // Set work group size to 64

    int workGroupSize = 512;

    int length = 2048000;
    int *arr = new int [length];
    for (int i = 0; i < length; i++)
        arr[i] = rand() % 100;

    int *prefixSum = new int [length];
    prefixSum[0] = 0;

    int t0 = clock();

    for (int i = 1; i < length; i++)
        prefixSum[i] = prefixSum[i - 1] + arr[i - 1];

    int t1 = clock();

    printf("time1: %lf\n", (t1 - t0) * 1.0 / CLOCKS_PER_SEC);

    cl_mem d_arr = clCreateBuffer(context, CL_MEM_READ_WRITE, sizeof(int) * length, NULL, &err);
    if (err) Error("Fail to create d_arr");

    err = clEnqueueWriteBuffer(commandQueue, d_arr, CL_TRUE, 0, sizeof(int) * length, arr, 0, NULL, NULL);
    if (err) Error("Fail to write d_arr");
//.........这里部分代码省略.........
开发者ID:linyufly,项目名称:FlowVC,代码行数:101,代码来源:ExclusiveScan.cpp


示例4: xcl_world_single

xcl_world xcl_world_single(cl_device_type device_type, char *target_vendor, char *target_device) {
	int err;
	xcl_world world;
	cl_uint num_platforms;

	err = clGetPlatformIDs(0, NULL, &num_platforms);
	if (err != CL_SUCCESS) {
		printf("Error: no platforms available or OpenCL install broken");
		printf("Test failed\n");
		exit(EXIT_FAILURE);
	}

	cl_platform_id *platform_ids = (cl_platform_id *) malloc(sizeof(cl_platform_id) * num_platforms);

	if (platform_ids == NULL) {
		printf("Error: Out of Memory\n");
		printf("Test failed\n");
		exit(EXIT_FAILURE);
	}

	err = clGetPlatformIDs(num_platforms, platform_ids, NULL);
	if (err != CL_SUCCESS) {
		printf("Error: Failed to find an OpenCL platform!\n");
		printf("Test failed\n");
		exit(EXIT_FAILURE);
	}

	int i;
        char cl_platform_vendor[1001];
        //find target vendor if target_vendor is specified
        if (target_vendor != NULL) {
                for(i = 0; i < num_platforms; i++) {
                        err = clGetPlatformInfo(platform_ids[i], CL_PLATFORM_VENDOR, 1000, (void *)cl_platform_vendor,NULL);
                        if (err != CL_SUCCESS) {
                                printf("Error: clGetPlatformInfo(CL_PLATFORM_VENDOR) failed!\n");
                                printf("Test failed\n");
                                exit(EXIT_FAILURE);
                        }
                        if ((target_vendor != NULL) && (strcmp(cl_platform_vendor, target_vendor) == 0)) {
                                printf("INFO: Selected platform %d from %s\n", i, cl_platform_vendor);
                                world.platform_id = platform_ids[i];
                                break;
                        }
                }
        } else {
                for(i = 0; i < num_platforms; i++) {
                        err = clGetDeviceIDs(platform_ids[i], device_type,
                                             1, &world.device_id, NULL);
                        if (err == CL_SUCCESS) {
                                world.platform_id = platform_ids[i];
                                break;
                        }
                }            
        }
	free(platform_ids);
	if (i == num_platforms) {
		printf("Error: Failed to find a platform\n");
		printf("Test failed\n");
		exit(EXIT_FAILURE);
	}

        if (target_device != NULL) {
                //find target device
                cl_device_id devices[16];  // compute device id 
                cl_uint num_devices;
                char cl_device_name[100];
                err = clGetDeviceIDs(world.platform_id, CL_DEVICE_TYPE_ACCELERATOR,
                                     16, devices, &num_devices);
                if (err != CL_SUCCESS) {
                        printf("Error: Failed to create a device group!\n");
                        printf("Test failed\n");
                        exit(EXIT_FAILURE);
                }

                //iterate all devices to select the target device. 
                for (i=0; i<num_devices; i++) {
                        err = clGetDeviceInfo(devices[i], CL_DEVICE_NAME, 100, cl_device_name, 0);
                        if (err != CL_SUCCESS) {
                                printf("Error: Failed to get device name for device %d!\n", i);
                                printf("Test failed\n");
                                exit(EXIT_FAILURE);
                        }
                        //printf("CL_DEVICE_NAME %s\n", cl_device_name);
                        if (strcmp(cl_device_name, target_device) == 0) {
                                world.device_id = devices[i];
                                printf("INFO: Selected %s as the target device\n", cl_device_name);
                                break;
                        }
                }

                if (i == num_devices) {
                        printf("Error: Failed to find target device %s\n", target_device);
                        printf("Test failed\n");
                        exit(EXIT_FAILURE);
                }
        }

	world.context = clCreateContext(0, 1, &world.device_id,
	                                NULL, NULL, &err);
	if (err != CL_SUCCESS) {
//.........这里部分代码省略.........
开发者ID:shvo,项目名称:Rodinia-FPGA,代码行数:101,代码来源:xcl.c


示例5: platforms

QT_BEGIN_NAMESPACE

/*!
    \class QCLPlatform
    \brief The QCLPlatform class represents an OpenCL platform definition.
    \since 4.7
    \ingroup opencl

    An OpenCL platform consists of the host CPU plus one or more
    devices, and manages memory resources and executable kernels.

    The platforms() function can be used to obtain the list of
    OpenCL platforms that are accessible to the host.  For each
    platform, QCLDevice::devices() can be used to enumerate the
    devices that are managed by the platform.

    QCLPlatform functions can be used to query information about
    the platform:

    \list
    \o profile() - describes the level of OpenCL support that
       is available; either \c{FULL_PROFILE} or \c{EMBEDDED_PROFILE}.
       The isFullProfile() and isEmbeddedProfile() convenience
       functions can be used to check for specific profile strings.
    \o version() - version of OpenCL supported by the platform;
       usually something like \c{OpenCL 1.0}.
    \o versionFlags() - flag bits indicating which versions of
       OpenCL are supported by this platform, in an easier to
       use form than the string from version().
    \o name() - name of the platform.
    \o vendor() - name of the vendor that created the platform.
    \o extensionSuffix() - the vendor extension suffix if the \c{cl_khr_icd}
       extension is supported; an empty string otherwise.
    \o extensions() - list of OpenCL extensions that are supported
       by the platform.  The hasExtension() function can be used
       to check for a specific extension.
    \endlist

    The \l{Querying OpenCL Device Capabilities}{clinfo} utility
    program can be used to dump all of the platforms that are
    supported by the system's OpenCL implementation.

    \sa QCLDevice
*/

/*!
    \fn QCLPlatform::QCLPlatform()

    Constructs a default OpenCL platform identifier.
*/

/*!
    \fn QCLPlatform::QCLPlatform(cl_platform_id id)

    Constructs an OpenCL platform identifier that corresponds to the
    native OpenCL value \a id.
*/

/*!
    \fn bool QCLPlatform::isNull() const

    Returns true if this OpenCL platform identifier is null.
*/

static QString qt_cl_platform_string(cl_platform_id id, cl_platform_info name)
{
    size_t size;
    if (!id || clGetPlatformInfo(id, name, 0, 0, &size) != CL_SUCCESS)
        return QString();
    QVarLengthArray<char> buf(size);
    clGetPlatformInfo(id, name, size, buf.data(), &size);
    return QString::fromLatin1(buf.data());
}
开发者ID:Dem0n3D,项目名称:qt-opencl,代码行数:73,代码来源:qclplatform.cpp


示例6: getPlatformInfo

static SEXP getPlatformInfo(cl_platform_id platform_id, cl_device_info di) {
    if ((last_ocl_error = clGetPlatformInfo(platform_id, di, sizeof(infobuf), &infobuf, NULL)) != CL_SUCCESS)
	ocl_err("clGetPlatformInfo");
    return Rf_mkString(infobuf);
}
开发者ID:mprymek,项目名称:OpenCL,代码行数:5,代码来源:ocl.c


示例7: initialize

/*
 * @brief sets up the OpenCL framework by detecting and initializing the available device
 * @param use_gpu flag denoting if the gpu is the desired platform
 */
static int initialize(int use_gpu) {
    cl_int result;
    size_t size;

    // create OpenCL context
    // you have to specify what platform you want to use
    // not uncommon for both NVIDIA and AMD to be installed
    cl_platform_id platform_id[2];

    cl_uint num_avail;
    cl_int err = clGetPlatformIDs(2, platform_id, &num_avail);
    if (err != CL_SUCCESS) {
        if (err == CL_INVALID_VALUE)printf("clGetPlatformIDs() returned invalid_value\n");
        printf("ERROR: clGetPlatformIDs(1,*,0) failed\n");
        return -1;
    }
    printf("number of available platforms:%d.\n",num_avail);
    char info[100];
    clGetPlatformInfo(platform_id[0], CL_PLATFORM_VENDOR, 100, info, NULL);
    printf("clGetPlatformInfo: %s\n", info);

    cl_context_properties ctxprop[] = {CL_CONTEXT_PLATFORM, (cl_context_properties) platform_id[0], 0};
    device_type = use_gpu ? CL_DEVICE_TYPE_GPU : CL_DEVICE_TYPE_CPU;
    context = clCreateContextFromType(ctxprop, device_type, NULL, NULL, &err);

    if (!context) {
        if (CL_INVALID_PLATFORM == err)
            printf("CL_INVALID_PLATFORM returned by clCreateContextFromType()\n");
        else if (CL_INVALID_VALUE == err)
            printf("CL_INVALID_VALUE returned by clCreateContextFromType()\n");
        else if (CL_INVALID_DEVICE_TYPE == err)
            printf("CL_INVALID_DEVICE_TYPE returned by clCreateContextFromType()\n");
        else if (CL_INVALID_OPERATION == err)
            printf("CL_INVALID_OPERATION returned by clCreateContextFromType()\n");
        else if (CL_DEVICE_NOT_AVAILABLE == err)
            printf("CL_DEVICE_NOT_AVAILABLE returned by clCreateContextFromType()\n");
        else if (CL_DEVICE_NOT_FOUND == err)
            printf("CL_DEVICE_NOT_FOUND returned by clCreateContextFromType()\n");
        else if (CL_OUT_OF_RESOURCES == err)
            printf("CL_OUT_OF_RESOURCES returned by clCreateContextFromType()\n");


        printf("ERROR: clCreateContextFromType(%s) failed\n", use_gpu ? "GPU" : "CPU");
        return -1;
    }

    // get the list of GPUs
    result = clGetContextInfo(context, CL_CONTEXT_DEVICES, 0, NULL, &size);
    num_devices = (int) (size / sizeof (cl_device_id));

    if (result != CL_SUCCESS || num_devices < 1) {
        printf("ERROR: clGetContextInfo() failed\n");
        return -1;
    }
    device_list = new cl_device_id[num_devices];
    if (!device_list) {
        printf("ERROR: new cl_device_id[] failed\n");
        return -1;
    }
    result = clGetContextInfo(context, CL_CONTEXT_DEVICES, size, device_list, NULL);
    if (result != CL_SUCCESS) {
        printf("ERROR: clGetContextInfo() failed\n");
        return -1;
    }
    size_t max_work_item_sizes[3];
    result = clGetDeviceInfo(device_list[0], CL_DEVICE_MAX_WORK_ITEM_SIZES,
                sizeof(max_work_item_sizes), (void*)max_work_item_sizes, NULL);
    if (result != CL_SUCCESS) {
        printf("ERROR: clGetDeviceInfo() failed\n");
        return -1;
    }
  if (max_work_item_sizes[0] < threads_per_block)
    threads_per_block = max_work_item_sizes[0];

   // create command queue for the first device
    cmd_queue = clCreateCommandQueue(context, device_list[0], 0, NULL);
    if (!cmd_queue) {
        printf("ERROR: clCreateCommandQueue() failed\n");
        return -1;
    }

    return 0;
}
开发者ID:dylanzika,项目名称:rodinia-1,代码行数:87,代码来源:ex_particle_OCL_double_seq.cpp


示例8: clGetPlatformIDs

int SDKSample::validatePlatfromAndDeviceOptions()
{
    cl_int status = CL_SUCCESS;
    cl_uint numPlatforms;
    cl_platform_id platform = NULL;
    status = clGetPlatformIDs(0, NULL, &numPlatforms);
    if(status != CL_SUCCESS)
    {
        std::cout<<"Error: clGetPlatformIDs failed. Error code : ";
        std::cout << streamsdk::getOpenCLErrorCodeStr(status) << std::endl;
        return 0;
    }

    if (0 < numPlatforms) 
    {
        // Validate platformId
        if(platformId >= numPlatforms)
        {
            if(numPlatforms - 1 == 0)
                std::cout << "platformId should be 0" << std::endl;
            else
                std::cout << "platformId should be 0 to " << numPlatforms - 1 << std::endl;
            usage();
            return 0;
        }

        // Get selected platform
        cl_platform_id* platforms = new cl_platform_id[numPlatforms];
        status = clGetPlatformIDs(numPlatforms, platforms, NULL);
        if(status != CL_SUCCESS)
        {
            std::cout<<"Error: clGetPlatformIDs failed. Error code : ";
            std::cout << streamsdk::getOpenCLErrorCodeStr(status) << std::endl;
            return 0;
        }

        // Print all platforms
        for (unsigned i = 0; i < numPlatforms; ++i) 
        {
            char pbuf[100];
            status = clGetPlatformInfo(platforms[i],
                                       CL_PLATFORM_VENDOR,
                                       sizeof(pbuf),
                                       pbuf,
                                       NULL);

            if(status != CL_SUCCESS)
            {
                std::cout<<"Error: clGetPlatformInfo failed. Error code : ";
                std::cout << streamsdk::getOpenCLErrorCodeStr(status) << std::endl;
                return 0;
            }

            std::cout << "Platform " << i << " : " << pbuf << std::endl;
        }

        // Get AMD platform
        for (unsigned i = 0; i < numPlatforms; ++i) 
        {
            char pbuf[100];
            status = clGetPlatformInfo(platforms[i],
                                       CL_PLATFORM_VENDOR,
                                       sizeof(pbuf),
                                       pbuf,
                                       NULL);

            if(status != CL_SUCCESS)
            {
                std::cout<<"Error: clGetPlatformInfo failed. Error code : ";
                std::cout << streamsdk::getOpenCLErrorCodeStr(status) << std::endl;
                return 0;
            }

            platform = platforms[i];
            if (!strcmp(pbuf, "Advanced Micro Devices, Inc.")) 
            {
                break;
            }
        }

        if(isPlatformEnabled())
            platform = platforms[platformId];

        cl_device_type dType = CL_DEVICE_TYPE_GPU;
        if(deviceType.compare("cpu") == 0)
            dType = CL_DEVICE_TYPE_CPU;
        if(deviceType.compare("gpu") == 0)
            dType = CL_DEVICE_TYPE_GPU;
        else
            dType = CL_DEVICE_TYPE_ALL;

        // Check for GPU
        if(dType == CL_DEVICE_TYPE_GPU)
        {
            cl_context_properties cps[3] = 
            {
                CL_CONTEXT_PLATFORM, 
                (cl_context_properties)platform, 
                0
            };
//.........这里部分代码省略.........
开发者ID:pbains,项目名称:m2s-bench-amdapp-2.5,代码行数:101,代码来源:SDKApplication.cpp


示例9: init_cladsyn

static int init_cladsyn(CSOUND *csound, CLADSYN *p){

  int asize, ipsize, fpsize, err;
  cl_device_id device_ids[32], device_id;             
  cl_context context;                
  cl_command_queue commands;          
  cl_program program;                
  cl_kernel kernel1, kernel2;                 
  cl_uint num = 0, nump =  0;
  cl_platform_id platforms[16];
    uint i;

  if(p->fsig->overlap > 1024)
     return csound->InitError(csound, "overlap is too large\n");



  err = clGetDeviceIDs(NULL, CL_DEVICE_TYPE_ALL, 32, device_ids, &num);
  if (err != CL_SUCCESS){
    clGetPlatformIDs(16, platforms, &nump);
    int devs = 0;
    for(i=0; i < nump && devs < 32; i++){
     char name[128];
     clGetPlatformInfo(platforms[i], CL_PLATFORM_NAME, 128, name, NULL);
     csound->Message(csound, "available platform[%d] %s\n",i, name);
     err = clGetDeviceIDs(platforms[i], CL_DEVICE_TYPE_ALL, 32-devs, &device_ids[devs], &num);
    if (err != CL_SUCCESS)
     csound->InitError(csound, "failed to find an OpenCL device! %s \n", cl_error_string(err));
    }
    devs += num;
  }

  
  for(i=0; i < num; i++){
  char name[128];
  cl_device_type type;
  clGetDeviceInfo(device_ids[i], CL_DEVICE_NAME, 128, name, NULL);
  clGetDeviceInfo(device_ids[i], CL_DEVICE_TYPE, sizeof(cl_device_type), &type, NULL);
  if(type & CL_DEVICE_TYPE_CPU)
  csound->Message(csound, "available CPU[device %d] %s\n",i, name);
  else  if(type & CL_DEVICE_TYPE_GPU)
  csound->Message(csound, "available GPU[device %d] %s\n",i, name);
  else  if(type & CL_DEVICE_TYPE_ACCELERATOR)
  csound->Message(csound, "available ACCELLERATOR[device %d] %s\n",i, name);
  else 
  csound->Message(csound, "available generic [device %d] %s\n",i, name);;
  }

  // SELECT THE GPU HERE
  if(*p->idev < num)
   device_id = device_ids[(int)*p->idev];
  else
   device_id = device_ids[num-1];

   context = clCreateContext(0, 1, &device_id, NULL, NULL, &err);
   if (!context)
     return csound->InitError(csound, "Failed to create a compute context! %s\n", 
                             cl_error_string(err));
  
    // Create a command commands
    //
    commands = clCreateCommandQueue(context, device_id, 0, &err);
    if (!commands)
       return csound->InitError(csound, "Failed to create a command commands! %s\n", 
                             cl_error_string(err));
    // Create the compute program from the source buffer
    //
    program = clCreateProgramWithSource(context, 1, (const char **) &code, NULL, &err);
    if (!program)
       return csound->InitError(csound, "Failed to create compute program! %s\n", 
                             cl_error_string(err));
  
    err = clBuildProgram(program, 0, NULL, NULL, NULL, NULL);
    if (err != CL_SUCCESS)
    {
        size_t len;
        char buffer[2048];
        csound->Message(csound, "Failed to build program executable! %s\n", 
                             cl_error_string(err));
        clGetProgramBuildInfo(program, device_id, CL_PROGRAM_BUILD_LOG, sizeof(buffer), buffer, &len);
        return csound->InitError(csound, "%s\n", buffer);
    }

    kernel1 = clCreateKernel(program, "sample", &err);
    if (!kernel1 || err != CL_SUCCESS)
      return csound->InitError(csound, "Failed to create sample compute kernel! %s\n", 
                             cl_error_string(err));

   kernel2 = clCreateKernel(program, "update", &err);
    if (!kernel2 || err != CL_SUCCESS)
      return csound->InitError(csound,"Failed to create update compute kernel! %s\n", 
                             cl_error_string(err));
 
  char name[128];
  clGetDeviceInfo(device_id, CL_DEVICE_NAME, 128, name, NULL);
  csound->Message(csound, "using device: %s\n",name);

  p->bins = (p->fsig->N)/2;

  if(*p->inum > 0 && *p->inum < p->bins) p->bins = *p->inum;
//.........这里部分代码省略.........
开发者ID:amitkumar3968,项目名称:csound,代码行数:101,代码来源:cladsynth.c


示例10: main

int main(int argc, char **argv)
{

	cl_int ret;


	/*
	 * Command line
	 */
	char *binary_path;
	if (argc != 2)
	{
		printf("syntax: %s <binary>\n", argv[0]);
		exit(1);
	}
	binary_path = argv[1];


	/*
	 * Platform
	 */

	/* Get platform */
	cl_platform_id platform;
	cl_uint num_platforms;
	ret = clGetPlatformIDs(1, &platform, &num_platforms);
	if (ret != CL_SUCCESS)
	{
		printf("error: second call to 'clGetPlatformIDs' failed\n");
		exit(1);
	}
	printf("Number of platforms: %d\n", num_platforms);

	/* Get platform name */
	char platform_name[100];
	ret = clGetPlatformInfo(platform, CL_PLATFORM_NAME, sizeof(platform_name), platform_name, NULL);
	if (ret != CL_SUCCESS)
	{
		printf("error: call to 'clGetPlatformInfo' failed\n");
		exit(1);
	}
	printf("platform.name='%s'\n", platform_name);
	printf("\n");



	/*
	 * Device
	 */

	/* Get device */
	cl_device_id device;
	cl_uint num_devices;
	ret = clGetDeviceIDs(platform, CL_DEVICE_TYPE_GPU, 1, &device, &num_devices);
	if (ret != CL_SUCCESS)
	{
		printf("error: call to 'clGetDeviceIDs' failed\n");
		exit(1);
	}
	printf("Number of devices: %d\n", num_devices);

	/* Get device name */
	char device_name[100];
	ret = clGetDeviceInfo(device, CL_DEVICE_NAME, sizeof(device_name), device_name, NULL);
	if (ret != CL_SUCCESS)
	{
		printf("error: call to 'clGetDeviceInfo' failed\n");
		exit(1);
	}
	printf("device.name='%s'\n", device_name);
	printf("\n");



	/*
	 * Context
	 */
	
	/* Create context */
	cl_context context;
	context = clCreateContext(NULL, 1, &device, NULL, NULL, &ret);
	if (ret != CL_SUCCESS)
	{
		printf("error: call to 'clCreateContext' failed\n");
		exit(1);
	}

	

	/*
	 * Command Queue
	 */
	
	/* Create command queue */
	cl_command_queue command_queue;
	command_queue = clCreateCommandQueue(context, device, 0, &ret);
	if (ret != CL_SUCCESS)
	{
		printf("error: call to 'clCreateCommandQueue' failed\n");
		exit(1);
//.........这里部分代码省略.........
开发者ID:multi2sim-upv,项目名称:multi2sim-tests,代码行数:101,代码来源:if.c


示例11: opencl_init

void opencl_init(void) {

	// get the platform

	cl_uint num_platforms;
	clError = clGetPlatformIDs(0, NULL, &num_platforms);
	checkErr(clError, "clGetPlatformIDs( 0, NULL, &num_platforms );");

	if (num_platforms <= 0) {
		std::cout << "No platform..." << std::endl;
		exit(1);
	}

	cl_platform_id* platforms = new cl_platform_id[num_platforms];
	clError = clGetPlatformIDs(num_platforms, platforms, NULL);
	checkErr(clError, "clGetPlatformIDs( num_platforms, &platforms, NULL );");
	if (num_platforms > 1) {
		char platformName[256];
		clError = clGetPlatformInfo(platforms[0], CL_PLATFORM_VENDOR,
				sizeof(platformName), platformName, NULL);
		std::cerr << "Multiple platforms found defaulting to: " << platformName
				<< std::endl;
	}
	platform_id = platforms[0];
	if (getenv("OPENCL_PLATEFORM"))
		platform_id = platforms[1];
	delete platforms;

	// Connect to a compute device
	//
	cl_uint device_count = 0;
	clError = clGetDeviceIDs(platform_id, CL_DEVICE_TYPE_ALL, 0, NULL,
			&device_count);
	checkErr(clError, "Failed to create a device group");
	cl_device_id* deviceIds = (cl_device_id*) malloc(
			sizeof(cl_device_id) * device_count);
	clError = clGetDeviceIDs(platform_id, CL_DEVICE_TYPE_ALL, device_count,
			deviceIds, NULL);
	if (device_count > 1) {
		char device_name[256];
		int compute_units;
		clError = clGetDeviceInfo(deviceIds[0], CL_DEVICE_NAME,
				sizeof(device_name), device_name, NULL);
		checkErr(clError, "clGetDeviceInfo failed");
		clError = clGetDeviceInfo(deviceIds[0], CL_DEVICE_MAX_COMPUTE_UNITS,
				sizeof(cl_uint), &compute_units, NULL);
		checkErr(clError, "clGetDeviceInfo failed");
		std::cerr << "Multiple devices found defaulting to: " << device_name;
		std::cerr << " with " << compute_units << " compute units" << std::endl;
	}
	device_id = deviceIds[0];
	delete deviceIds;
	// Create a compute context 
	//
	context = clCreateContext(0, 1, &device_id, NULL, NULL, &clError);
	checkErr(clError, "Failed to create a compute context!");

	// Create a command commands
	//
	commandQueue = clCreateCommandQueue(context, device_id, 0, &clError);
	checkErr(clError, "Failed to create a command commands!");

	// READ KERNEL FILENAME
	std::string filename = "NOTDEFINED.cl";
	char const* tmp_name = getenv("OPENCL_KERNEL");
	if (tmp_name) {
		filename = std::string(tmp_name);
	} else {
		filename = std::string(__FILE__);
		filename = filename.substr(0, filename.length() - 17);
		filename += "/kernels.cl";

	}

	// READ OPENCL_PARAMETERS
	std::string compile_parameters = "";
	char const* tmp_params = getenv("OPENCL_PARAMETERS");
	if (tmp_params) {
		compile_parameters = std::string(tmp_params);
	}

	std::ifstream kernelFile(filename.c_str(), std::ios::in);

	if (!kernelFile.is_open()) {
		std::cout << "Unable to open " << filename << ". " << __FILE__ << ":"
				<< __LINE__ << "Please set OPENCL_KERNEL" << std::endl;
		exit(1);
	}

	/*
	 * Read the kernel file into an output stream.
	 * Convert this into a char array for passing to OpenCL.
	 */
	std::ostringstream outputStringStream;
	outputStringStream << kernelFile.rdbuf();
	std::string srcStdStr = outputStringStream.str();
	const char* charSource = srcStdStr.c_str();

	kernelFile.close();
	// Create the compute program from the source buffer
//.........这里部分代码省略.........
开发者ID:lllandy,项目名称:DynamicFusion,代码行数:101,代码来源:common_opencl.cpp


示例12: clGetPlatformIDs

// SETUP
int CLContext::setupCL()
{
	cl_int status = CL_SUCCESS;

	cl_device_type dType;
	int gpu = 1;

	if(gpu == 0)
		dType = CL_DEVICE_TYPE_CPU;
	else //deviceType = "gpu" 
		dType = CL_DEVICE_TYPE_GPU;

	/*
	* Have a look at the available platforms and pick either
	* the AMD one if available or a reasonable default.      <----- LOL check out the amd propaganda
	*/

	cl_uint numPlatforms;
	cl_platform_id platform = NULL;
	status = clGetPlatformIDs(0, NULL, &numPlatforms);
	if(!checkVal(status, CL_SUCCESS, "clGetPlatformIDs failed."))
		return CL_FAILURE;
	if (0 < numPlatforms) 
	{
		cl_platform_id* platforms = new cl_platform_id[numPlatforms];
		status = clGetPlatformIDs(numPlatforms, platforms, NULL);
		if(!checkVal(status, CL_SUCCESS, "clGetPlatformIDs failed."))
			return CL_FAILURE;
		for (unsigned i = 0; i < numPlatforms; ++i) 
		{
			char pbuf[100];
			status = clGetPlatformInfo(platforms[i], CL_PLATFORM_VENDOR, sizeof(pbuf), pbuf, NULL);

			if(!checkVal(status, CL_SUCCESS, "clGetPlatformInfo failed."))
				return CL_FAILURE;

			platform = platforms[i];
			if (!strcmp(pbuf, "Advanced Micro Devices, Inc.")) 
				break;
		}
		delete[] platforms;
	}

	/*
	* If we could find our platform, use it. Otherwise pass a NULL and get whatever the
	* implementation thinks we should be using.
	*/

	cl_context_properties cps[3] = { CL_CONTEXT_PLATFORM,  (cl_context_properties)platform,  0 };
	/* Use NULL for backward compatibility */
	cl_context_properties* cprops = (NULL == platform) ? NULL : cps;

	context = clCreateContextFromType( cprops, dType, NULL, NULL, &status);
	if(!checkVal( status, CL_SUCCESS, "clCreateContextFromType failed."))
		return CL_FAILURE;

	size_t deviceListSize;

	/* First, get the size of device list data */
	status = clGetContextInfo( context,  CL_CONTEXT_DEVICES,  0,  NULL,  &deviceListSize);
	if(!checkVal( status,  CL_SUCCESS, "clGetContextInfo failed."))
		return CL_FAILURE;

	/* Now allocate memory for device list based on the size we got earlier */
	devices = (cl_device_id*)malloc(deviceListSize);
	if(devices==NULL)
	{
		cout << "Failed to allocate memory (devices)." << endl;
		return CL_FAILURE;
	}

	/* Now, get the device list data */
	status = clGetContextInfo( context,  CL_CONTEXT_DEVICES,  deviceListSize,  devices,  NULL);
	if(!checkVal( status, CL_SUCCESS,  "clGetContextInfo failed."))
		return CL_FAILURE;

	/* Create command queue */
	commandQueue = clCreateCommandQueue( context, devices[0], 0, &status);
	if(!checkVal( status, CL_SUCCESS, "clCreateCommandQueue failed."))
		return CL_FAILURE;

	/* Get Device specific Information */
	status = clGetDeviceInfo( devices[0], CL_DEVICE_MAX_WORK_GROUP_SIZE, sizeof(size_t), (void*)&maxWorkGroupSize, NULL);

	if(!checkVal( status, CL_SUCCESS,  "clGetDeviceInfo CL_DEVICE_MAX_WORK_GROUP_SIZE failed."))
		return CL_FAILURE;


	status = clGetDeviceInfo( devices[0], CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS, sizeof(cl_uint), (void*)&maxDimensions, NULL);
	if(!checkVal( status, CL_SUCCESS,  "clGetDeviceInfo CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS failed."))
		return CL_FAILURE;


	maxWorkItemSizes = (size_t *)malloc(maxDimensions * sizeof(unsigned int));

	status = clGetDeviceInfo( devices[0], CL_DEVICE_MAX_WORK_ITEM_SIZES, sizeof(size_t) * maxDimensions, (void*)maxWorkItemSizes, NULL);
	if(!checkVal( status, CL_SUCCESS,  "clGetDeviceInfo CL_DEVICE_MAX_WORK_ITEM_SIZES failed."))
		return CL_FAILURE;

//.........这里部分代码省略.........
开发者ID:ethicalfive,项目名称:critterding,代码行数:101,代码来源:clcontext.cpp


示例13: clGetPlatformIDs

	int XdevLComputeDeviceCL::init() {
		cl_int ret;

		cl_uint numPlatforms;
		ret = clGetPlatformIDs(1, &m_platformID, &numPlatforms);
		if(CL_SUCCESS != ret) {
			XDEVL_MODULEX_ERROR(XdevLComputeDeviceCL, "clGetPlatformIDs failed: " << clErrorAsString(ret) << std::endl);
			return -1;
		}

		std::vector<cl_platform_id> platformIDs(numPlatforms);

		ret = clGetPlatformIDs(1, platformIDs.data(), nullptr);

		for(auto platform : platformIDs) {
			XdevLPlatformInfo info;
			info.id = platform;

			std::size_t size;
			ret = clGetPlatformInfo(platform, CL_PLATFORM_PROFILE, sizeof(info.profile), (void*)info.profile, &size);
			ret = clGetPlatformInfo(platform, CL_PLATFORM_VERSION, sizeof(info.version), (void*)info.version, &size);
			ret = clGetPlatformInfo(platform, CL_PLATFORM_NAME, sizeof(info.name), (void*)info.name, &size);
			ret = clGetPlatformInfo(platform, CL_PLATFORM_VENDOR, sizeof(info.vendor), (void*)info.vendor, &size);

			if(CL_SUCCESS != ret) {
				XDEVL_MODULEX_ERROR(XdevLComputeDeviceCL, "clGetPlatformInfo failed: " << clErrorAsString(ret) << std::endl);
				return -1;
			}

			std::cout << "Platform Name       : " << info.name << std::endl;
			std::cout << "Platform Profile    : " << info.profile << std::endl;
			std::cout << "Platform Version    : " << info.version << std::endl;
			std::cout << "Platform Vendor     : " << info.vendor << std::endl;


			m_platforms.push_back(std::move(info));
		}

		for(auto platform : m_platforms) {
			cl_uint numDevices;
			ret = clGetDeviceIDs(platform.id, CL_DEVICE_TYPE_ALL, 1, &m_deviceID, &numDevices);
			if(CL_SUCCESS != ret) {
				XDEVL_MODULEX_ERROR(XdevLComputeDeviceCL, "clGetDeviceIDs failed: " << clErrorAsString(ret) << std::endl);
				return -1;
			}
			std::cout << "OpenCL Number of devices: " << numDevices << ", ID: " << m_deviceID << std::endl;

			XdevLDeviceInfo device;
			device.id = m_deviceID;

			std::size_t size;
			ret = clGetDeviceInfo(m_deviceID, CL_DEVICE_NAME, sizeof(device.name), (void*)device.name, &size);
			ret = clGetDeviceInfo(m_deviceID, CL_DEVICE_VENDOR, sizeof(device.vendor), (void*)device.vendor, &size);
			ret = clGetDeviceInfo(m_deviceID, CL_DRIVER_VERSION, sizeof(device.version), (void*)device.version, &size);
			ret = clGetDeviceInfo(m_deviceID, CL_DEVICE_PROFILE, sizeof(device.profile), (void*)device.profile, &size);

			if(CL_SUCCESS != ret) {
				return -1;
			}

			std::cout << "Device Profile    : " << device.profile << std::endl;
			std::cout << "Device Name       : " << device.name << std::endl;
			std::cout << "Device Version    : " << device.version << std::endl;
			std::cout << "Device Vendor     : " << device.vendor << std::endl;


			m_devices.push_back(std::move(device));
		}
		return 0;
	}
开发者ID:yaakuro,项目名称:XdevLSDK,代码行数:70,代码来源:XdevLComputeDeviceCL.cpp


示例14: dump_platform

static void dump_platform(int index, cl_platform_id platform_id)
{
	static struct {
		cl_platform_info info;
		size_t		size;
		void	   *addr;
	} catalog[] = {
		PLATFORM_ATTR(CL_PLATFORM_PROFILE, profile),
		PLATFORM_ATTR(CL_PLATFORM_VERSION, version),
        PLATFORM_ATTR(CL_PLATFORM_NAME, name),
        PLATFORM_ATTR(CL_PLATFORM_VENDOR, vendor),
        PLATFORM_ATTR(CL_PLATFORM_EXTENSIONS, extensions),
	};
	cl_device_id	device_ids[256];
	cl_uint			device_num;
	cl_int			i, rc;

	for (i=0; i < lengthof(catalog); i++)
	{
		rc = clGetPlatformInfo(platform_id,
							   catalog[i].info,
							   catalog[i].size,
							   catalog[i].addr,
							   NULL);
		if (rc != CL_SUCCESS)
		{
			fprintf(stderr, "failed on clGetPlatformInfo (%s)\n",
					opencl_strerror(rc));
			exit(1);
		}
	}

	rc = clGetDeviceIDs(platform_id,
						CL_DEVICE_TYPE_ALL,
						lengthof(device_ids),
						device_ids,
						&device_num);
	if (rc != CL_SUCCESS)
	{
		fprintf(stderr, "failed on clGetDeviceIDs (%s)\n",
				opencl_strerror(rc));
		exit(1);
	}

	if (only_list)
		printf("Platform-%02d: %s / %s - %s\n", index + 1,
			   platform_info.vendor,
			   platform_info.name,
			   platform_info.version);
	else
	{
		printf("platform-index:      %d\n", index + 1);
		printf("platform-vendor:     %s\n", platform_info.vendor);
		printf("platform-name:       %s\n", platform_info.name);
		printf("platform-version:    %s\n", platform_info.version);
		printf("platform-profile:    %s\n", platform_info.profile);
		printf("platform-extensions: %s\n", platform_info.extensions);
	}

	for (i=0; i < device_num; i++)
	{
		if (only_device < 0 || i + 1 == only_device)
			dump_device(i, device_ids[i]);
	}
	putchar('\n');
}
开发者ID:git2u,项目名称:gpuinfo,代码行数:66,代码来源:gpuinfo.c


示例15: main


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ clGetProgramBuildInfo函数代码示例发布时间:2022-05-30
下一篇:
C++ clGetPlatformIDs函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap