c - 在 Mac OS X 10.11 上,如果与 .cu 扩展名一起使用,nvcc 不喜欢复杂

标签 c macos cuda nvcc

我有一个简单的代码,它的编译方式有所不同,具体取决于它是使用 .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 <complex.h>根本不。我错过了什么?

最佳答案

从评论来看,此问题似乎特定于 OS X El Capitan 上具有最新 XCode 的 CUDA 7.5。提供的重现案例似乎适用于测试过的所有其他平台。建议向 NVIDIA 提交错误报告。

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

关于c - 在 Mac OS X 10.11 上,如果与 .cu 扩展名一起使用,nvcc 不喜欢复杂,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34288725/

相关文章:

c - fgets() 不保留 '\n' 作为数组大小的输入

比较 C 中的 2 个字符值

macos - brew 或 pip - 安装 credstash - 错误 - 在 taps/OSErr 中找不到命名公式 六-1.4.1-py2.7.egg-info 操作不允许

cuda - cudaStreamWaitEvent 会阻塞主机吗?

c++ - 设备内存空间中的cuda程序内核代码

cuda - 如何在CUBLAS中计算复数幂?

c++ - 如何知道 IntegerLiteral 是来自 Clang 的十进制还是八进制表示?

android - 在 "flutter doctor"中显示关于 Android 工具链的错误

macos - 如何从歌曲文件中获取歌曲的歌词

c - 在某些使用 C 等编程语言的软件中是否存在间接寻址的实际应用?