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

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

前準備

Build Tools for Visual Studio 2026(ビルドツール)のインストール

Build Tools for Visual Studio 2026(ビルドツール)のインストールを行い、C/C++ コードのビルド環境を整える。

[Build Tools for Visual Studio 2026(ビルドツール)のインストール手順を見るには、ここをクリック]

Windows での Build Tools for Visual Studio 2026 のインストール

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

以下のコマンドは、Build Tools が未インストールの場合は winget で新規インストールし、インストール済みの場合は setup.exe modify でコンポーネントを追加する(バージョンは変更しない)。

インストールコマンドの実行方法

管理者権限コマンドプロンプトを起動する(手順: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 ============================================================
REM Visual Studio Build Tools + Desktop development with C++
REM (VCTools、MSBuildTools、CMake連携、Clang、Windows 11 SDK)
REM ============================================================
REM 進行中のインストーラーを停止(ロック競合回避)
taskkill /F /IM vs_setup.exe /T >nul 2>&1
taskkill /F /IM vs_installer.exe /T >nul 2>&1
taskkill /F /IM vs_installerservice.exe /T >nul 2>&1

REM 未インストール時: winget で新規インストール
REM インストール済み時: setup.exe modify でコンポーネント追加(バージョンは変更しない)
winget list --id Microsoft.VisualStudio.BuildTools 2>nul | findstr /i "BuildTools" >nul 2>&1
if %ERRORLEVEL% EQU 0 (
    for /f "usebackq delims=" %P in (`"C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe" -products Microsoft.VisualStudio.Product.BuildTools -property installationPath`) do start /wait "" "C:\Program Files (x86)\Microsoft Visual Studio\Installer\setup.exe" modify --installPath "%P" --add Microsoft.VisualStudio.Workload.VCTools --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 --includeRecommended --quiet --norestart --nocache
) else (
    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"
)

REM 破損時の修復(任意、動作がおかしくなった場合)
REM "C:\Program Files (x86)\Microsoft Visual Studio\Installer\setup.exe" repair --installPath "C:\Program Files (x86)\Microsoft Visual Studio\18\BuildTools" --quiet --norestart

REM 導入確認(インストールパスが表示されれば正常)
"C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe" -products * -requires Microsoft.VisualStudio.Workload.VCTools -property installationPath

上記のコマンドでは、Build Tools 本体と Visual C++ 再頒布可能パッケージをインストールし、続いて以下のコンポーネントを追加している。

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

インストール完了の確認

winget list Microsoft.VisualStudio.BuildTools

Visual Studio を必要とするとき

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

NVIDIA CUDA Toolkit 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 2026」の下の「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 にはインストール済みのツールセット(Build Tools for Visual Studio 2026 の場合は v145),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=v145 /p:WindowsTargetPlatformVersion=10.0
  4. 終了の確認

    ビルドが「Build succeeded.」で終了することを確認する.また,次のコマンドでビルド生成物(nccl.dll)が作成されていることを確認できる.

    dir c:\NCCL\windows\x64\Debug\nccl.dll
  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\")"