【发布时间】:2013-11-20 13:49:45
【问题描述】:
我正在尝试使用 AMD 的 OpenCL 实现来编写 Hello World 应用程序。 http://developer.amd.com/tools-and-sdks/heterogeneous-computing/amd-accelerated-parallel-processing-app-sdk/introductory-tutorial-to-opencl/
我已经设置好目录、lib等as here
以下编译:
#include "stdafx.h"
#include <CL/cl.h>
int _tmain(int argc, _TCHAR* argv[])
{
cl_platform_id test;
cl_uint num;
cl_uint ok = 1;
clGetPlatformIDs(ok, &test, &num);
return 0;
}
然而,
#include "stdafx.h"
#include <utility>
#include <CL/cl.hpp>
int _tmain(int argc, _TCHAR* argv[])
{
cl::vector< cl::Platform > platformList;
return 0;
}
没有。
我收到以下错误:
Error 1 error C2039: 'vector' : is not a member of 'cl' D:\Documents\Projects\Visual Studio\C++\cl_helloworld\cl_helloworld\cl_helloworld.cpp 12 1 cl_helloworld
Error 2 error C2065: 'vector' : undeclared identifier D:\Documents\Projects\Visual Studio\C++\cl_helloworld\cl_helloworld\cl_helloworld.cpp 12 1 cl_helloworld
Error 3 error C2275: 'cl::Platform' : illegal use of this type as an expression D:\Documents\Projects\Visual Studio\C++\cl_helloworld\cl_helloworld\cl_helloworld.cpp 12 1 cl_helloworld
Error 4 error C2065: 'platformList' : undeclared identifier D:\Documents\Projects\Visual Studio\C++\cl_helloworld\cl_helloworld\cl_helloworld.cpp 12 1 cl_helloworld
IntelliSense 下划线vector< cl::Platform > platformList,当我输入 cl:: 时,我看不到向量类。
编辑
如果我手动将 cl.hpp 的内容复制到 main.cpp 中,我在 IntelliSense 中看到了向量,但仍然无法编译项目。
【问题讨论】:
-
只是猜测,因为我不知道 OpenCL... 但应该将
cl::vector改为cl::Vector或std::vector吗? -
根据示例,我应该 #define __NO_STD_VECTOR // 使用 cl::vector 而不是 STL 版本,但我仍然得到错误。 std::vector 有效,但我必须使用 cl::vector。
-
根据规范,
cl::vector已被弃用,取而代之的是std::vector或您自己的类似于std::vector的向量类型。 (khronos.org/registry/cl/specs/opencl-cplusplus-1.2.pdf,第 5 节) -
好的,谢谢,那我就用std::vector。
-
@cHao:很高兴 AMD 在他们的 OpenCL 教程中使用了已弃用的代码(顺便说一句,这似乎也是唯一的 OpenCL 教程)。当我的代码中仍然有
#define __NO_STD_VECTOR行时,我的应用程序甚至无法编译,所以必须删除。
标签: c++ visual-studio-2012 opencl gpu amd-processor