V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
xiaopanzi
V2EX  ›  NVIDIA

为什么官网上的 add.cu 程序不需要 cuda 相关头文件

  •  
  •   xiaopanzi · 210 天前 · 1304 次点击
    这是一个创建于 210 天前的主题,其中的信息可能已经有所发展或是发生改变。

    今天开始学习 CUDA 编程,有个疑问:

    比如官网上的入门程序add.cu,为什么它不需要使用任何 cuda 相关的头文件?

    我的猜测:nvcc编译器实际上在编译之前会自动插入头文件再完成编译。

    请大佬解答疑惑。

    3 条回复    2023-09-30 18:30:29 +08:00
    learningman
        1
    learningman  
       210 天前 via Android
    __global__是 CUDA C++的关键字,实际上是另外一种语言
    xiaopanzi
        2
    xiaopanzi  
    OP
       210 天前
    @learningman 按我理解,它只是扩展了 C/C++,像头文件这些内容肯定是保留的。比如`cudaMallocManaged`函数,没有头文件就能编译成功,这该如何理解?
    xiaopanzi
        3
    xiaopanzi  
    OP
       210 天前   ❤️ 1
    好像和我的猜测是一致的,

    > nvcc automatically includes CUDA-specific header files when handling code in .cu files. You still need to include the standard C/C++ header files and header files for any libraries delivered with CUDA, if you use functions exported by these header files.

    参考[Does NVCC include header files automatically?]( https://forums.developer.nvidia.com/t/does-nvcc-include-header-files-automatically/48972)
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2847 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 12:26 · PVG 20:26 · LAX 05:26 · JFK 08:26
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.