【问题标题】:On Mac OS X 10.11 nvcc doesn't like complex if used with .cu extension在 Mac OS X 10.11 上,如果与 .cu 扩展名一起使用,nvcc 不喜欢复杂
【发布时间】:2016-03-21 05:08:25
【问题描述】:

我有一个简单的代码,它的编译方式不同,具体取决于它是使用 .c 还是 .cu 扩展名保存的:

#include <stdio.h>
#include <complex.h>

int main()
{
    float num;
    float eps_i, eps_s, tau_d, sigma;
    float pi, wave_freq, eps_0;

    eps_i = 43.0;
    eps_s = 2.4;
    tau_d = 0.3;
    sigma = 4.75;
    pi = 3.14;
    wave_freq = 0.015;
    eps_0 = 40.234;

    float complex c1 = 0.0 + 2.0 * pi * wave_freq * tau_d * I;
    float complex c2 = 0.0 + sigma / (2.0 * pi * wave_freq * eps_0) * I;

    num = creal(eps_i + (eps_s - eps_i) / (1.0 + (0.0 + 2.0 * pi * wave_freq * tau_d * I)) -
    (0.0 + sigma / (2.0 * pi * wave_freq * eps_0) * I));

    printf("%g\n", num);
}

如果我使用nvcc test.c 编译它,它会完全按照我的预期工作。但是,如果我运行 nvcc test.cu 我会得到:

test.cu(18): error: expected a ";"

test.cu(19): error: "complex" has already been declared in the current scope

test.cu(19): error: expected a ";"

test.cu(21): error: identifier "I" is undefined

test.cu(21): error: identifier "creal" is undefined

test.cu(18): warning: variable "complex" was declared but never referenced

test.cu(19): warning: variable "complex" was declared but never referenced

5 errors detected in the compilation of "/var/folders/3z/8bl4b3yx0c3_5tgf35dr_z180000gp/T//tmpxft_00015a75_00000000-9_test.cpp1.ii".

我知道 .cu 被视为包含 CUDA 代码的代码,而 .c 只是主机代码,但我希望它们在这种情况下表现相同。请注意,它根本不会抱怨#include &lt;complex.h&gt;。我错过了什么?

【问题讨论】:

  • 当我用nvcc program.cu 编译它时没有错误/警告,我只是修复了警告并且工作正常。
  • 当我使用 CUDA 4.2、5.0、5.5、6.0、6.5、7.0 和 7.5 中的每一个使用 .cu 扩展名编译它时,不会产生任何错误
  • 我没有。我有 Ubuntu 15.04 (64BIT) 和 Cuda compilation tools, release 6.5, V6.5.12
  • @Rafal:没有旗帜,什么都没有。我拥有的主机编译器是 gcc 4.6.3
  • 如果我是你,我会提交错误报告

标签: c macos cuda nvcc


【解决方案1】:

从 cmets 来看,这个问题似乎是在 OS X El Capitan 上使用最新 XCode 的 CUDA 7.5 所特有的。提供的复制案例似乎适用于它测试过的所有其他平台。建议向 NVIDIA 提出错误报告。

[此答案已添加为社区 wiki 条目,以将此问题从未回答列表中删除]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-10-05
    • 2016-05-10
    • 2016-12-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多