Search code examples
visual-studiopowershellcudanvcccl

Building CUDA in platformio-ide-terminal


I would like to be able to compile and build CUDA C source code provided here using Windows 10 Powershell. I have no issue doing this using x64 Native Tools Command Prompt for VS 2017.

However, I have tried several ways suggested online to get Powershell to work, but no success. The reason is I want to be able to build my cuda codes in Atom, the editor, using its package platformio-ide-terminal that loads a Powershell inside Atom. So, if I figure out how to setup Visual Studio 2017 Community in a Powershell, I edit my code in Atom and conveniently build them using its Powershell integration.

I tried to set the environment as follows but still nvcc cannot find the path to cl.exe.

Could someone kindly help me?

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>

Solution

  • Open a Windows Powershell and run the following commands at the prompt:

    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>
    

    Automation

    To automate this, create a file named nvcc_setup_for_powershell.ps1 and place the following two commands in it.

    & '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}")
    

    the last two commands is to simulate hitting enter button, adopted from here.

    Open settings for platformio-ide-terminal under Core > Run Command place the path to the PowerShell script: & "C:\Path\To\Script\nvcc_setup_for_powershell.ps1".

    enter image description here You may need to open a PowerShell as administrator and run the following command

    Set-ExecutionPolicy RemoteSigned
    

    to allow you to execute nvcc_setup_for_powershell.ps1.