NCCL のインストール(Windows 上)

Windows上でNCCL(NVIDIA Collective Communications Library)をインストールする手順を説明している.主な手順としては,GitHubからのソースコードのクローン,Visual Studioを使用したプロジェクトの再ターゲット,x64 Native Toolsコマンドプロンプトを用いたビルド,そしてシステム環境変数へのパス追加である.インストールでは,Visual Studioでのプロジェクト設定や,CUDAツールキットとの連携に関して注意する必要がある.また,ビルド時に発生する可能性のあるエラーとその解決方法についても説明している.インストールの各ステップについて,具体的なコマンドラインの操作を示している.インストールは,管理者権限で行う.

前準備

Build Tools for Visual Studio 2026 のインストール(Windows 上) [クリックして展開]

Build Tools for Visual Studio は,Visual Studio の IDE を含まない C/C++ コンパイラ,ライブラリ,ビルドツール等のコマンドライン向け開発ツールセットである。インストール済みの場合、この手順は不要である。

管理者権限コマンドプロンプトで以下を実行する。管理者権限のコマンドプロンプトを起動するには、Windows キーまたはスタートメニューから「cmd」と入力し、表示された「コマンドプロンプト」を右クリックして「管理者として実行」を選択する。

REM VC++ ランタイム
winget install --scope machine --id Microsoft.VCRedist.2015+.x64 -e --silent --disable-interactivity --force --accept-source-agreements --accept-package-agreements --override "/quiet /norestart"

REM Build Tools + Desktop development with C++(VCTools)+ 追加コンポーネント(一括)
winget install --scope machine --id Microsoft.VisualStudio.BuildTools -e --silent --disable-interactivity --force --accept-source-agreements --accept-package-agreements --override "--quiet --wait --norestart --nocache --add Microsoft.VisualStudio.Workload.VCTools --includeRecommended --add Microsoft.VisualStudio.Workload.MSBuildTools --add Microsoft.VisualStudio.Component.VC.CMake.Project --add Microsoft.VisualStudio.Component.VC.Llvm.Clang --add Microsoft.VisualStudio.Component.VC.Llvm.ClangToolset --add Microsoft.VisualStudio.Component.Windows11SDK.26100"

--add で追加されるコンポーネント

上記のコマンドでは,まず Build Tools 本体と Visual C++ 再頒布可能パッケージをインストールし,次に setup.exe を用いて以下のコンポーネントを追加している。

インストール完了の確認

winget list Microsoft.VisualStudio.BuildTools

上記以外の追加のコンポーネントが必要になった場合は Visual Studio Installer で個別にインストールできる。

Visual Studio の機能を必要とする場合は、追加インストールできる。

NVIDIA CUDA Tooklit 12.3のインストール

以下のコマンドを管理者権限コマンドプロンプトで実行する (手順:Windowsキーまたはスタートメニュー → cmd と入力 → 右クリック → 「管理者として実行」)。

REM NVIDIA CUDA Toolkit 12.3 をシステム領域にインストール
winget install --scope machine --id Nvidia.CUDA -e -v 12.3 -h --custom "-n" --accept-package-agreements --accept-source-agreements --force --uninstall-previous

REM 環境変数TEMP, TMPの設定(一時ファイルの保存先を短いパスに変更)
mkdir C:\TEMP
set "TEMP_PATH=C:\TEMP"
setx TEMP "%TEMP_PATH%" /M >nul
setx TMP "%TEMP_PATH%" /M >nul

NCCL のインストール(Windows 上)

https://github.com/MyCaffe/NCCLを使用する.

https://github.com/MyCaffe/NCCL/blob/master/INSTALL.mdの説明に従い,インストールを行う.

  1. 以下の操作を管理者権限x64 Native Tools コマンドプロンプト (x64 Native Tools Command Prompt)で実行する(手順:スタートメニュー >「Visual Studio Build Tools 2022」の下の「x64 Native Tools コマンドプロンプト (x64 Native Tools Command Prompt)」を右クリック > 「管理者として実行」)。
  2. ダウンロード
    cd c:\
    rmdir /s /q NCCL
    git clone https://github.com/MyCaffe/NCCL
    
  3. ビルドの実行

    msbuild の /p:PlatformToolset および /p:WindowsTargetPlatformVersion オプションにより,ビルド時にターゲットの再設定(再ターゲット)を行う.PlatformToolset にはインストール済みのツールセット(例:v143),WindowsTargetPlatformVersion にはインストール済みの Windows SDK のバージョン(例:10.0)を指定する.

    cd c:\
    cd NCCL
    
    REM CUDA BuildCustomizations ファイルをMSBuildの参照先へコピー
    mkdir "C:\Program Files (x86)\Microsoft Visual Studio\18\BuildTools\MSBuild\Microsoft\VC\v180\BuildCustomizations" 2>nul
    copy /Y "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.3\extras\visual_studio_integration\MSBuildExtensions\*" "C:\Program Files (x86)\Microsoft Visual Studio\18\BuildTools\MSBuild\Microsoft\VC\v180\BuildCustomizations\"
    
    msbuild windows\nccl.12.3.vcxproj /p:Platform=x64 /p:PlatformToolset=v143 /p:WindowsTargetPlatformVersion=10.0
  4. 終了の確認
  5. パスの設定

    Windowsシステム環境変数 Pathc:\NCCL\windows\x64\Debug を追加することにより,パスを通す

    Windows で,管理者権限コマンドプロンプトを起動する(手順:Windowsキーまたはスタートメニュー > cmd と入力 > 右クリック > 「管理者として実行」)。

    次のコマンドを実行する.

    powershell -command "$oldpath = [System.Environment]::GetEnvironmentVariable(\"Path\", \"Machine\"); $oldpath += \";c:\NCCL\windows\x64\Debug\"; [System.Environment]::SetEnvironmentVariable(\"Path\", $oldpath, \"Machine\")"