加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Windows > 正文

可以在Windows7x64(MSVC)和Linux64(GCC4.8.2)中的.cu文件(CUDA5.

发布时间:2020-12-13 20:52:36 所属栏目:Windows 来源:网络整理
导读:当我编译包含设计C 11的以下代码时,在Windows7x64(MSVS2012 Nsight 2.0 CUDA5.5)中,我不会收到错误,并且所有的编译和运行良好: #include thrust/device_vector.hint main() { thrust::device_vectorint dv(10); auto iter = dv.begin(); return 0;} 但是
当我编译包含设计C 11的以下代码时,在Windows7x64(MSVS2012 Nsight 2.0 CUDA5.5)中,我不会收到错误,并且所有的编译和运行良好:
#include <thrust/device_vector.h>

int main() {
    thrust::device_vector<int> dv(10);
    auto iter = dv.begin();

    return 0;
}

但是当我尝试在Linux64(Debian 7 Wheezey Nsight Eclipse从CUDA5.5)下编译它时,我收到错误:

../src/CudaCpp11.cu(5): error: explicit type is missing (“int”
assumed)

../src/CudaCpp11.cu(5): error: no suitable conversion function from

“thrust::detail::normal_iterator>” to “int”
exists

2 errors detected in the compilation of
“/tmp/tmpxft_00001520_00000000-6_CudaCpp11.cpp1.ii”. make: *
[src/CudaCpp11.o] Error 2

当我添加行:-stdc 11

在属性 – >建设 – >设置 – >工具设置 – >构建阶段 – >预处理器选项(-Xcompiler)

我得到更多的错误:

/usr/lib/gcc/x86_64-linux-gnu/4.8/include/stddef.h(432): error:
identifier “nullptr” is undefined

/usr/lib/gcc/x86_64-linux-gnu/4.8/include/stddef.h(432): error:
expected a “;”

/usr/include/c++/4.8/bits/cpp_type_traits.h(314): error: namespace
“std::__gnu_cxx” has no member

“__normal_iterator”

/usr/include/c++/4.8/bits/cpp_type_traits.h(314): error: expected a
“>”

nvcc error : ‘cudafe’ died due to signal 11 (Invalid memory
reference) make: * [src/CudaCpp11.o] Error 11

只有当我使用推力:: device_vector< int> :: iterator iter = dv.begin();在Linux-GCC中,我没有收到错误。但是在Windows MSVS2012中,所有c 11功能都可以正常工作!

可以在Windows7x64(MSVC)和Linux64(GCC4.8.2)中的.cu文件(CUDA5.5)中使用C 11吗?

你可能不得不将这个main.cpp从你的others.cu中分离出来:

others.hpp:

void others();

others.cu:

#include "others.hpp"
#include <boost/typeof/std/utility.hpp>
#include <thrust/device_vector.h>

void others() {
    thrust::device_vector<int> dv(10);
    BOOST_AUTO(iter,dv.begin()); // regular C++
}

main.cpp中:

#include "others.hpp"

int main() {
    others();

    return 0;
}

This particular answer显示,使用正式支持的gcc版本(如Robert Crovella正确表示)的编译应至少应用于main.cpp文件中的c 11代码:

g++ -std=c++0x -c main.cpp
nvcc -arch=sm_20 -c others.cu 
nvcc -lcudart -o test main.o others.o

(在Debian 8上使用nvcc 5.5和gcc 4.7.3进行测试)。

回答你的根本问题:我不知道可以在Linux中使用CUDA 5.5的.cu文件中的C11(而且我不知道主机端C11的显示示例在MSVC下被正确地去除了)。我甚至提交了一个仍然开放的constexpr支持的功能请求。

CUDA 5.5 CUDA programming指南说明:

For the host code,nvcc supports whatever part of the C++ ISO/IEC
14882:2003 specification the host c++ compiler supports.

For the device code,nvcc supports the features illustrated in Code
Samples with some restrictions described in Restrictions; it does not
support run time type information (RTTI),exception handling,and the
C++ Standard Library.

无论如何,可以使用一些C 11功能,如内核中的自动,例如。与boost :: auto。
作为一个展望,其他C 11功能(如线程)可能不太可能在CUDA中结束,我没有听到关于它们的官方计划(截至supercomputing 2013)。

无耻的插件:如果您对这些tweek更多的兴趣,请随时查看我们的图书馆libPMacc,它为模拟提供了多GPU网格和粒子抽象。我们为1-3D矩阵和其他有用的东西实现了lambda,一个类似STL的访问概念。

祝一切顺利,
阿克塞尔

更新:自CUDA 7.0 C++11内核支持已正式添加。正如BenC正确指出的那样,这个功能的部分功能已经在CUDA 6.5中默默添加。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读