gpt4 book ai didi

c++ - 为什么 nvcc 对仿函数不满意

转载 作者:行者123 更新时间:2023-11-30 02:57:40 28 4
gpt4 key购买 nike

hc.cu代码:

//patch for g++4.7
#ifdef _GLIBCXX_ATOMIC_BUILTINS
#undef _GLIBCXX_ATOMIC_BUILTINS
#endif
#ifdef _GLIBCXX_USE_INT128
#undef _GLIBCXX_USE_INT128
#endif

struct pi_
{
double operator()() const
{
return 3.141592653589793;
}
};

#include <iostream>

int main()
{
std::cout << pi_()();

return 0;
}

编译会导致两个(不是一个)错误:

$nvcc -c hc.cu
hc.cu: In function ‘int main()’:
hc.cu:21:22: error: ‘type name’ declared as function returning a function
hc.cu:21:22: error: ‘type name’ declared as function returning a function

有人可以告诉我问题吗?我是使用 g++ 4.7 的 archlinux 用户,我必须取消定义两个宏才能使 nvcc 工作;这两个 undefs 在编译错误中有什么作用吗?

一些关于cuda的信息:

$ pacman -Qi cuda
Name : cuda
Version : 5.0.35-3
URL : http://www.nvidia.com/object/cuda_home.html
Licenses : custom
Groups : None
Provides : cuda-toolkit cuda-sdk
Depends On : gcc-libs opencl-nvidia
Optional Deps : gdb: for cuda-gdb
Required By : cuda-z cula cusp
Conflicts With : None
Replaces : cuda-toolkit cuda-sdk
Installed Size : 1464880.00 KiB
Packager : Sven-Hendrik Haase <sh@lutzhaase.com>
Architecture : x86_64
Build Date : Tue 30 Oct 2012 12:51:49 PM CET
Install Date : Wed 09 Jan 2013 02:38:26 PM CET
Install Reason : Explicitly installed
Install Script : Yes
Description : NVIDIA's GPU programming toolkit

和g++

pacman -Qi gcc-multilib
Name : gcc-multilib
Version : 4.7.2-3
URL : http://gcc.gnu.org
Licenses : GPL LGPL FDL custom
Groups : multilib-devel
Provides : gcc=4.7.2-3
Depends On : gcc-libs-multilib=4.7.2-3 binutils-multilib>=2.23 libmpc cloog ppl
Optional Deps : None
Required By : boost-build chicken clang dkms gcc-fortran-multilib gcc-objc-multilib ghc htmldoc libreoffice-sdk libtool virtualbox-host-dkms
Conflicts With : gcc
Replaces : None
Installed Size : 81560.00 KiB
Packager : Jan Alexander Steffens (heftig) <jan.steffens@gmail.com>
Architecture : x86_64
Build Date : Wed 26 Dec 2012 01:22:52 PM CET
Install Date : Mon 31 Dec 2012 03:40:26 PM CET
Install Reason : Installed as a dependency for another package
Install Script : Yes
Description : The GNU Compiler Collection - C and C++ frontends for multilib

最佳答案

我可以在 CUDA 5.0 中用我的 nvcc 重复你的错误。

看起来像是nvcc的bug。

pi_()() 在 g++ 中有效,但在 nvcc 中无效。

要让它在nvcc中工作,你必须这样写。

pi_ p;
std::cout<<p()<<std::endl;

在 nvcc 中使用 (pi_())() 时出现此错误。似乎 nvcc 错误地将 pi_ 视为类型转换。

a.cu(14): error: cast to type "pi_ ()" is not allowed

a.cu(14): error: expected an expression

2 errors detected in the compilation of "/tmp/tmpxft_00003006_00000000-6_a.cpp1.ii".

关于c++ - 为什么 nvcc 对仿函数不满意,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14360558/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com