gpt4 book ai didi

debugging - Nvidia Visual Studio Nsight CPU 和 GPU 调试

转载 作者:行者123 更新时间:2023-12-04 23:23:15 24 4
gpt4 key购买 nike

NVIDIA Nsight Visual Studio Edition 似乎无法同时调试 CPU(主机代码)和 GPU(cuda 代码)。使用 Nsight Eclipse Edition(或 cuda-gdb),这非常简单,例如,您可以从主机执行“步入”到 CUDA 内核。如何使用 Visual Studio 做同样的事情?

最佳答案

来自 Nsight manual

它说

Use a separate Visual Studio instance to debug the host portion of a target application. If you wish to debug the host portion of your CUDA application while the CUDA Debugger is attached, you must attach using a different Visual Studio instance. Attaching the same instance of Visual Studio to debug both the host portion and the device portion of a target application will cause the debuggers to conflict. The result is that the target application and the CUDA Debugger hang while being blocked by operations of the native debugger.



因此,调试 CUDA 应用程序的步骤如下:
  • 打开 Visual Studio(VS 实例 #1)并在 CUDA 内核中设置断点,然后单击“启动 CUDA 调试”。这将启动应用程序实例并在您设置断点的地方停止。
  • 打开另一个 Visual Studio 实例(VS 实例 #2)(出于某种原因需要以管理员身份运行)并附加到您在步骤 1 中启动的进程。
  • 在 VS 实例 #2 中,浏览到您希望进行 CPU 调试的文件并设置断点。
  • 在 VS 实例 #1 中继续执行(应该脱离当前的 CUDA 内核)。此时应命中您在 VS 实例 #2 中设置的 CPU 断点。


  • 加分:远程调试您的 CUDA 应用程序。
    脚步:
  • 在目标机器上以管理员身份运行 msvsmon.exe(远程调试器)。这可以在
    C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\Remote Debugger\x64。
  • 在主机(您要控制调试的主机)上,打开 VS 并确保 Nsight 调试器指向远程机器(Nsight 用户属性 > 启动 > 连接名称)。注意:Nvidia Nsight 监视器必须在目标机器上运行才能正常工作。
  • 执行前面(非远程调试)部分中的步骤 1 和 2。在第 2 步中,您需要指向远程机器进行 CPU 调试(Debug>Attach to Process>Qualifier 应设置为目标机器名称或 IP)。
  • 非远程调试步骤 3 和 4 也适用于此。

  • 注意 : 看来VS的远程CPU调试不如本地CPU调试。例如,当您将鼠标悬停在 CPU 变量上时,某些值不会像您在进行本地调试时预期的那样显示。

    仍未答复 :是否可以在遇到 CUDA 断点之前开始调试主机代码?您只能在第一个 CUDA 内核之后调试主机代码,这似乎是一个很大的限制。如果您想在第一个 CUDA 内核之前调试主机代码怎么办?

    关于debugging - Nvidia Visual Studio Nsight CPU 和 GPU 调试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18515933/

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