【问题标题】:Cl has no member vectorCl 没有成员向量
【发布时间】: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&lt; cl::Platform &gt; platformList,当我输入 cl:: 时,我看不到向量类。

编辑

如果我手动将 cl.hpp 的内容复制到 main.cpp 中,我在 IntelliSense 中看到了向量,但仍然无法编译项目。

【问题讨论】:

  • 只是猜测,因为我不知道 OpenCL... 但应该将 cl::vector 改为 cl::Vectorstd::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


【解决方案1】:

请改用std::vector&lt;cl:XXXX&gt;。 这就是我使用的,atm 完全没有问题,而且我有非常复杂的 OpenCL C++ 应用程序。

您还可以通过在#include &lt;cl.hpp&gt; #define __NO_STD_VECTOR 之前定义来启用内部cl::vector 类。但我不推荐,因为功能比标准差。

示例: 如果您有事件向量,则可以在 std 中选择性地删除事件。但在 cl::vector 中,您必须手动完成。

【讨论】:

  • 补充一点:$AMD_OpenCL_DIR/include/cl.hpp 中有一个示例代码,它使用std::vector 而不是cl::vector
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-01-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多