OpenCL clGetPlatformIDs 异常

2024-02-28

我使用此包安装附带的示例中的 HelloWorld 示例

AMD 套件 http://developer.amd.com/tools-and-sdks/heterogeneous-computing/amd-accelerated-parallel-processing-app-sdk/downloads/

问题是由于错误我无法运行任何示例。

    cl_uint numPlatforms;   //the NO. of platforms
    cl_platform_id platform = NULL; //the chosen platform
    cl_int  status = clGetPlatformIDs(0, NULL, &numPlatforms);

以下代码块会产生错误。在此语句末尾,状态设置为 -858993460。抛出异常说

"Unhandled exception at 0x7429C9F5 in AtomicCounters.exe: 0xC0000005: Access violation executing location 0x00000000."

我使用的是 Visual Studio 2012、Windows 7 64 位和 AMD GPU

我找不到足够的资源来解决该错误。请帮我。


HelloWorld.cpp完整源代码

/**********************************************************************
Copyright ©2013 Advanced Micro Devices, Inc. All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

•   Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
•   Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or
 other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
 OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
********************************************************************/

// For clarity,error checking has been omitted.

#include <CL/cl.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <string>
#include <fstream>

#define SUCCESS 0
#define FAILURE 1

using namespace std;

/* convert the kernel file into a string */
int convertToString(const char *filename, std::string& s)
{
    size_t size;
    char*  str;
    std::fstream f(filename, (std::fstream::in | std::fstream::binary));

    if(f.is_open())
    {
        size_t fileSize;
        f.seekg(0, std::fstream::end);
        size = fileSize = (size_t)f.tellg();
        f.seekg(0, std::fstream::beg);
        str = new char[size+1];
        if(!str)
        {
            f.close();
            return 0;
        }

        f.read(str, fileSize);
        f.close();
        str[size] = '\0';
        s = str;
        delete[] str;
        return 0;
    }
    cout<<"Error: failed to open file\n:"<<filename<<endl;
    return FAILURE;
}

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

    /*Step1: Getting platforms and choose an available one.*/
    cl_uint numPlatforms;   //the NO. of platforms
    cl_platform_id platform = NULL; //the chosen platform
    cl_int  status = clGetPlatformIDs(0, NULL, &numPlatforms);
    if (status != CL_SUCCESS)
    {
        cout << "Error: Getting platforms!" << endl;
        return FAILURE;
    }

    /*For clarity, choose the first available platform. */
    if(numPlatforms > 0)
    {
        cl_platform_id* platforms = (cl_platform_id* )malloc(numPlatforms* sizeof(cl_platform_id));
        status = clGetPlatformIDs(numPlatforms, platforms, NULL);
        platform = platforms[0];
        free(platforms);
    }

    /*Step 2:Query the platform and choose the first GPU device if has one.Otherwise use the CPU as device.*/
    cl_uint             numDevices = 0;
    cl_device_id        *devices;
    status = clGetDeviceIDs(platform, CL_DEVICE_TYPE_GPU, 0, NULL, &numDevices);    
    if (numDevices == 0)    //no GPU available.
    {
        cout << "No GPU device available." << endl;
        cout << "Choose CPU as default device." << endl;
        status = clGetDeviceIDs(platform, CL_DEVICE_TYPE_CPU, 0, NULL, &numDevices);    
        devices = (cl_device_id*)malloc(numDevices * sizeof(cl_device_id));
        status = clGetDeviceIDs(platform, CL_DEVICE_TYPE_CPU, numDevices, devices, NULL);
    }
    else
    {
        devices = (cl_device_id*)malloc(numDevices * sizeof(cl_device_id));
        status = clGetDeviceIDs(platform, CL_DEVICE_TYPE_GPU, numDevices, devices, NULL);
    }


    /*Step 3: Create context.*/
    cl_context context = clCreateContext(NULL,1, devices,NULL,NULL,NULL);

    /*Step 4: Creating command queue associate with the context.*/
    cl_command_queue commandQueue = clCreateCommandQueue(context, devices[0], 0, NULL);

    /*Step 5: Create program object */
    const char *filename = "HelloWorld_Kernel.cl";
    string sourceStr;
    status = convertToString(filename, sourceStr);
    const char *source = sourceStr.c_str();
    size_t sourceSize[] = {strlen(source)};
    cl_program program = clCreateProgramWithSource(context, 1, &source, sourceSize, NULL);

    /*Step 6: Build program. */
    status=clBuildProgram(program, 1,devices,NULL,NULL,NULL);

    /*Step 7: Initial input,output for the host and create memory objects for the kernel*/
    const char* input = "GdkknVnqkc";
    size_t strlength = strlen(input);
    cout << "input string:" << endl;
    cout << input << endl;
    char *output = (char*) malloc(strlength + 1);

    cl_mem inputBuffer = clCreateBuffer(context, CL_MEM_READ_ONLY|CL_MEM_COPY_HOST_PTR, (strlength + 1) * sizeof(char),(void *) input, NULL);
    cl_mem outputBuffer = clCreateBuffer(context, CL_MEM_WRITE_ONLY , (strlength + 1) * sizeof(char), NULL, NULL);

    /*Step 8: Create kernel object */
    cl_kernel kernel = clCreateKernel(program,"helloworld", NULL);

    /*Step 9: Sets Kernel arguments.*/
    status = clSetKernelArg(kernel, 0, sizeof(cl_mem), (void *)&inputBuffer);
    status = clSetKernelArg(kernel, 1, sizeof(cl_mem), (void *)&outputBuffer);

    /*Step 10: Running the kernel.*/
    size_t global_work_size[1] = {strlength};
    status = clEnqueueNDRangeKernel(commandQueue, kernel, 1, NULL, global_work_size, NULL, 0, NULL, NULL);

    /*Step 11: Read the cout put back to host memory.*/
    status = clEnqueueReadBuffer(commandQueue, outputBuffer, CL_TRUE, 0, strlength * sizeof(char), output, 0, NULL, NULL);

    output[strlength] = '\0';   //Add the terminal character to the end of output.
    cout << "\noutput string:" << endl;
    cout << output << endl;

    /*Step 12: Clean the resources.*/
    status = clReleaseKernel(kernel);               //Release kernel.
    status = clReleaseProgram(program);             //Release the program object.
    status = clReleaseMemObject(inputBuffer);       //Release mem object.
    status = clReleaseMemObject(outputBuffer);
    status = clReleaseCommandQueue(commandQueue);   //Release  Command queue.
    status = clReleaseContext(context);             //Release context.

    if (output != NULL)
    {
        free(output);
        output = NULL;
    }

    if (devices != NULL)
    {
        free(devices);
        devices = NULL;
    }

    std::cout<<"Passed!\n";
    return SUCCESS;
}

我在 W7 32 位、nVIDIA 和 VS2010 下也遇到同样的问题。 (同一函数中具有相同返回码的完全相同的错误)

我不知道是什么原因造成的,但是以管理员身份运行应用程序并启用 Windows XP 兼容性修复了该问题.

我认为是操作系统/驱动程序上的某种权限。或者也许是与 VS2010 相关的东西,以及它们与 DLL 的关系?

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

OpenCL clGetPlatformIDs 异常 的相关文章

随机推荐

  • 如何自定义 Eclipse 的 getter 和 setter 生成?

    如何配置 Eclipse 来生成带有参数变量前缀的 getter 和 setter Example private String someVariable public void setSomeVariable String aSomeVa
  • 有没有适用于 Android 传真的本机应用程序?

    我想开发一个传真应用程序 我在谷歌上搜索并找到了一些链接 用于在android上开发传真应用程序的应用程序 但是我想使用android的本机应用程序开发应用程序 在一些网站上 我读到免费的网络服务可用于发送 使用Android移动应用程序接
  • Rcpp 公开类的序列化

    我在 R 包中编写了一个 C 类 并将其暴露给 R 命名空间RCPP EXPOSED CLASS and RCPP MODULE 一切都很好 gt index An object of class Index Slot index C ob
  • 我使用 PyPy 是否错误?它比标准 Python 慢 10 倍

    我听说过有关 PyPy 的好消息 特别是我听说它非常快 这让我想知道它是否可用于我的嵌入式项目 我下载了PyPy 2 6 for my Windows 7PC 并将内容解压到一个目录中 我编写了一个小型测试程序来进行基准测试 import
  • 有关电话号码的信息

    node js 是否有任何库可以接收电话号码 任何格式 将其转换为默认格式 并告诉我有关该号码的信息 例如 国家 地区 城市等 我不知道 我也搜索过npm 注册表 http search npmjs org 谷歌有库电话号码 http co
  • 如何将左右系统键发送到SendKeys.Send()?

    我主要研究了几个选项 Sendkeys Send 用于右 alt 键 有什么替代方案吗 https stackoverflow com questions 9330498 sendkeys send for right alt key an
  • 我想在所有内容图像上应用 css class(bootstrap) .img-responsive

    我正在 bootstrap 的帮助下开发一个 Wordpress 主题 因此我手动将案例应用于所有内容图像 如下所示 img src images logo 03 png class img responsive 有没有办法自动应用相同的类
  • std::function 复制参数?

    My code include
  • C++中如何设计一个可以容纳任意类型函数的容器?

    我希望服务器支持注册任何功能 可能是这样的 server register Add int a int b cout lt lt a b lt lt endl server register Echo string str cout lt
  • 通过 Facebook 分享 Android 果冻豆的意图

    我想通过 Facebook 分享 Android jelly bean 的一些图像和文本 它适用于除 Android 果冻豆之外的所有设备 任何人请帮助我如何解决这个问题 my code Intent shareIntent new Int
  • ASPX 页面中“当前上下文中不存在该名称”

    我看过类似的问题 1 https stackoverflow com questions 706603 the name controlname does not exist in the current context 2 https s
  • URL 的编码参数

    我有一个正在构建 URL 的 Silverlight 应用程序 此 URL 是对基于 REST 的服务的调用 该服务需要一个代表位置的参数 位置的形式为 城市 州 为了构建此 URL 我调用以下代码 string url http www
  • AutoMapper 在映射子对象时传递父引用

    我正在尝试使用 AutoMapper 将从 Web 服务接收到的一些 DTO 数据契约 对象映射到我的业务对象中 根 DTO 对象包含子对象的集合 我的业务对象还有一个子业务对象的子集合 为了让 AutoMapper 工作 我必须在业务对象
  • 浏览器对 CSS :first-child 和 :last-child 的支持

    有谁知道哪些浏览器 版本支持它们 使用它们是否安全 或者我应该诉诸 PHP javascript 来生成第一个 最后一个类 first child and last child http www quirksmode org css fir
  • PHP 5.3 中自动加载命名空间?

    如何在 PHP 5 3 中使用 autoload 和命名空间 我在与脚本分开的命名空间中有一个主要的自动加载函数 我还调用具有不同名称空间的类 这并不奇怪 但是 它没有找到自动加载功能 我是否必须为每个命名空间重新创建自动加载函数 这似乎不
  • “Office 2010 加载项:图标库” - 如何从后台选项卡中提取图标 (docx)

    我下载了 Office 2010 加载项 图标库 https www microsoft com en in download confirmation aspx id 21103 这是一个 docx 文件 有两个包含图标的后台选项卡 如何
  • 在c#中将bool表达式转换为char

    当我遇到如下问题时 我通过了 NET 测验 Char ch Convert ToChar a e c a 在控制台中我们可以看到输出ch变量是g 有人可以描述发生了什么吗 谢谢 是二元或运算符 a binary representation
  • 将重复值复制粘贴到大型 Excel 文件的列中

    我遇到了一个问题 希望得到一些帮助 这是我现在正在处理的内容 我想要的是 B C 和 D 列复制到其下面的空白行 直到它到达新客户端 如下所示 非常感谢任何和所有的帮助 Thanks 非VBA解决方案 Select entire range
  • 使用 jQuery 按住 Shift + 鼠标悬停

    我试图检测当光标移动到特定元素上时是否按下了 Shift 键 该函数会触发 但仅after我首先单击另一个元素 有什么方法可以解决这个问题吗 我尝试将焦点设置为文档和元素 并尝试创建伪单击功能 但到目前为止没有任何效果 例如 以下代码仅在我
  • OpenCL clGetPlatformIDs 异常

    我使用此包安装附带的示例中的 HelloWorld 示例 AMD 套件 http developer amd com tools and sdks heterogeneous computing amd accelerated parall