【问题标题】:cuda Texture declaration compile-time errorcuda 纹理声明编译时错误
【发布时间】:2012-10-25 22:28:25
【问题描述】:

我正在尝试编译以下代码:

#include <stdio.h>
#include <time.h>
#include <cuda.h>
#include <cuda_runtime_api.h>

texture<float, 2, cudaReadModeElementType> tex;

int main () { ... }

然而,nvcc 给了我以下错误:

main.c:6:8: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘<’ token

我对 CUDA 很陌生,所以我想我在这里遗漏了一些东西。

【问题讨论】:

  • 你只能在.cu文件中使用CUDA语法。
  • 是的,我从main.c 切换到main.cu,现在它可以工作了。非常感谢!

标签: cuda textures


【解决方案1】:

您只能在 .cu 文件中使用 CUDA 语法。

【讨论】:

  • 实际上,纹理声明只是一个 C++ 模板实例化,而不是任何特定于 CUDA 的东西。如果使用 C++ 而不是 C 编译器,代码将编译,在这种特殊情况下不需要 nvcc 或 .cu 扩展名。
猜你喜欢
  • 1970-01-01
  • 2020-12-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-02-21
相关资源
最近更新 更多