- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我使用安装此包时附带的示例中的 HelloWorld 示例
问题是由于错误我无法运行任何示例。
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
我找不到足够的资源来解决错误。请帮助我。
/**********************************************************************
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 32bit、nVIDIA 和 VS2010 下遇到了同样的问题。 (在具有相同返回码的相同函数中出现完全相同的错误)
我不知道是什么原因造成的,但是以管理员身份运行应用程序并启用 Windows XP 兼容性解决了这个问题。
我认为是对操作系统/驱动程序的某种权限。或者可能与 VS2010 相关的内容,以及它们与 DLL 的关系??
关于c++ - OpenCL clGetPlatformIDs 异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19080471/
我正在使用 NVIDIA 硬件在 Ubuntu 12.04 上测试我的代码。 没有实际的 OpenCL 处理发生;但我的初始化代码仍在运行。此代码调用 clGetPlatformIDs。但是,Valg
我一直在努力学习 OpenCl,但每次我输入这个命令时,我的代码都会出错,这是一个简单的代码,我已经隔离了错误:clGetPlatformIDs 引起以下错误: OpenCl-OpenGl.exe 中
我正在尝试学习一些 OpenCL 以在我的 OpenGL 项目中使用以帮助加快一切,但我目前无法启动 OpenCL。当我从 Visual Studio 2015 启动程序时,代码在 clGetPlat
要创建 opencl 应用程序,第一步是通过使用获取平台 clGetPlatformIDs 我对从函数返回的平台有问题;函数返回我有 2 个平台,但当我检查它们时,我发现我有一个平台,但它是重复的!!
我使用安装此包时附带的示例中的 HelloWorld 示例 AMD PACKAGE 问题是由于错误我无法运行任何示例。 cl_uint numPlatforms; //the NO. of
我是 OpenCL 的新手。在配备 Intel(R) HD Graphics 4000、运行 Windows 7 的 Core i5 机器上工作。我安装了支持 OpenCL 的最新 Intel 驱动程
我有一个用于测试 OpenCL 的简单源代码(2 个向量之和),问题如下:当我运行可执行文件时出现此错误: Error: clGetPlatformIDs(-1001) 此外,如果我运行命令 clin
编辑:错误代码如下 CL_INVALID_PROPERTY if context property name in properties is not a supported property nam
这对我来说很奇怪。我目前正在从我最近迁移到 VS2015 的旧仓库中提取一个项目。解决方案仍然构建并且可执行文件有效,但是在 visual studio 中运行时,我在尝试从 0x000008E0 读
我正在尝试编写一个将在 PostgreSQL 中执行的 OpenCL 函数。为此,我从我的 OpenCL 代码创建 DLL,并使用用户定义函数机制将其链接到 postgres。一切顺利,直到调用 cl
我已经安装了英特尔 OpenCL SDK。我能够找到 header 并链接库,但这些功能都不起作用。在 OpenCL 程序中调用的第一个函数 clGetPlatformIDs() 返回 -1001 -
在 Ubuntu 中对一组 Python 程序进行 nosetests 时发生错误: devices = [ d for d in cl.get_platforms()[0].get_devices(
在最终设法让我的代码用 OpenCL 编译之后,我似乎无法让输出二进制文件运行!这是在我运行 Kubuntu 13.10 x64 的 Linux 笔记本电脑上 我得到的错误是(打印自 cl::Erro
代码: // g++ -std=c++17 -O0 -g -Wall -Wextra -lOpenCL query.cpp -o query // valgrind --leak-check=full
最近我一直在我的 Ubuntu 12.04 机器上使用 OpenCL。当我调用 cl::Platform::get 时,我收到错误代码 -1001。经过一些研究,我发现当 c 调用 getPlatfo
我是一名优秀的程序员,十分优秀!