【问题标题】:Building CUDA in platformio-ide-terminal在 platformio-ide-terminal 中构建 CUDA
【发布时间】:2020-02-22 10:06:52
【问题描述】:

我希望能够使用 Windows 10 Powershell 编译和构建提供 here 的 CUDA C 源代码。我使用 x64 Native Tools Command Prompt for VS 2017 没有问题。

但是,我尝试了几种在线建议的方法来让 Powershell 工作,但没有成功。原因是我希望能够在编辑器 Atom 中构建我的 cuda 代码,使用它的包platformio-ide-terminal 在 Atom 中加载一个 Powershell。因此,如果我知道如何在 Powershell 中设置 Visual Studio 2017 社区,我会在 Atom 中编辑我的代码并使用其 Powershell 集成方便地构建它们。

我尝试如下设置环境,但nvcc仍然找不到cl.exe的路径。

有人可以帮助我吗?

Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.

Try the new cross-platform PowerShell https://aka.ms/pscore6

PS C:\Users\AFP\Downloads\cuda_by_example> cd "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\"

PS C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build> .\vcvarsall.bat amd64
**********************************************************************
** Visual Studio 2017 Developer Command Prompt v15.7.3
** Copyright (c) 2017 Microsoft Corporation
**********************************************************************
[vcvarsall.bat] Environment initialized for: 'x64'

PS C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build> cd C:\Users\AFP\Downloads\cuda_by_example\

PS C:\Users\AFP\Downloads\cuda_by_example> nvcc .\chapter03\hello_world.cu
nvcc fatal   : Cannot find compiler 'cl.exe' in PATH

PS C:\Users\AFP\Downloads\cuda_by_example>

【问题讨论】:

    标签: visual-studio powershell cuda nvcc cl


    【解决方案1】:

    您可以将cl.exe的路径添加到环境变量中:

    control panel > view advanced system settings > Environment variables > Path > New.

    然后添加C:\Program Files (x86)\Microsoft Visual Studio\<year >\Community\VC\Tools\MSVC\<toolset>\bin\Hostx64\x64

    或者使用这个命令编译:nvcc x.cu .\chapter03\hello_world.cu -ccbin "C:\Program Files (x86)\Microsoft Visual Studio\<year >\Community\VC\Tools\MSVC\<toolset>\bin\Hostx64\x64"

    【讨论】:

    • 为了让它工作,我把它的路径改为:C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.14.26428\bin\Hostx64\x64
    【解决方案2】:

    打开 Windows Powershell 并在提示符下运行以下命令:

    Windows PowerShell
    Copyright (C) Microsoft Corporation. All rights reserved.
    
    Try the new cross-platform PowerShell https://aka.ms/pscore6
    
    PS C:\Users\AFP\Downloads\cuda_by_example> & 'C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvarsall.bat' amd64
    **********************************************************************
    ** Visual Studio 2017 Developer Command Prompt v15.7.3
    ** Copyright (c) 2017 Microsoft Corporation
    **********************************************************************
    [vcvarsall.bat] Environment initialized for: 'x64'
    PS C:\Users\AFP\Downloads\cuda_by_example> $ENV:PATH="$ENV:PATH;C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.14.26428\bin\Hostx64\x64"
    PS C:\Users\AFP\Downloads\cuda_by_example> nvcc .\chapter03\hello_world.cu
    hello_world.cu
       Creating library a.lib and object a.exp
    PS C:\Users\falah\Downloads\cuda_by_example> .\a.exe
    Hello, World!
    PS C:\Users\falah\Downloads\cuda_by_example>
    

    自动化

    要自动执行此操作,请创建一个名为 nvcc_setup_for_powershell.ps1 的文件并将以下两个命令放入其中。

    & 'C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvarsall.bat' amd64
    $ENV:PATH="$ENV:PATH;C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.14.26428\bin\Hostx64\x64"
    Write-Output "Configured PowerShell for NVCC Using Visual Studio 2019 Community x64"
    $myshell = New-Object -com "Wscript.Shell"
    $myshell.sendkeys("{ENTER}")
    

    最后两个命令是模拟敲击回车键,借鉴自here

    Core > Run Command 下打开platformio-ide-terminal 的设置,放置PowerShell 脚本的路径:& "C:\Path\To\Script\nvcc_setup_for_powershell.ps1"

    您可能需要以管理员身份打开 PowerShell 并运行以下命令

    Set-ExecutionPolicy RemoteSigned
    

    允许你执行nvcc_setup_for_powershell.ps1

    【讨论】:

      猜你喜欢
      • 2020-08-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-02-10
      • 2020-07-23
      • 2017-09-30
      • 1970-01-01
      相关资源
      最近更新 更多