金子邦彦研究室インストールWindows の種々のソフトウェア(インストール)OpenBLAS (BLAS, CBLAS, LAPACK, LAPACKE)のインストール(ソースコードを使用)(Build Tools for Visual Studio を利用)(Windows 上)

OpenBLAS (BLAS, CBLAS, LAPACK, LAPACKE)のインストール(ソースコードを使用)(Build Tools for Visual Studio を利用)(Windows 上)

BLAS(Basic Linear Algebra Subprograms)は,行列演算,ベクトル演算の機能をもったプログラム群である.

Windows で,OpenBLAS をソースコードからビルドしてインストールする. このとき, FORTRAN は使わないように設定してインストールする

目次

  1. 前準備
  2. OpenBLAS のインストール(Windows 上)
  3. BLAS のプログラムをコンパイルし,実行する
  4. LAPACK のプログラムをコンパイルし,実行する

サイト内の関連ページ

下に書いているように,vcpkg を利用してインストールすることができる. 特に問題がない場合には vcpkg の利用してのインストールを検討しよう. vcpkg使わずにインストールする必要がある場合は,このページの手順によりインストールを行うことができる.

OpenBlas のインストール(vcpkg を利用)(Windows 上)

  1. Git のインストール

    Windows での Git のインストール: 別ページ »で説明している.

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

    Windows での Build Tools for Visual Studio 2022 (ビルドツール for Visual Studio 2022) のインストール: 別ページ »で説明している.

  3. vckpg のインストール

    Windows で,コマンドプロンプト管理者として実行.

    次のコマンドを実行

    if not exist c:\vcpkg (
      cd c:\
      rmdir /s /q vcpkg
      git clone https://github.com/microsoft/vcpkg
      cd c:\vcpkg
      git pull
      .\bootstrap-vcpkg.bat
      .\vcpkg update
      .\vcpkg integrate install  
      powershell -command "[System.Environment]::SetEnvironmentVariable(\"VCPKG_ROOT\", \"c:\vcpkg\", \"Machine\")"
      powershell -command "[System.Environment]::SetEnvironmentVariable(\"VCPKG_DEFAULT_TRIPLET\", \"x64-windows\", \"Machine\")"
      powershell -command "[System.Environment]::SetEnvironmentVariable(\"CMAKE_TOOLCHAIN_FILE\", \"c:/vcpkg/scripts/buildsystems/vcpkg.cmake\", \"Machine\")"
      powershell -command "$oldpath = [System.Environment]::GetEnvironmentVariable(\"LIB\", \"Machine\"); $oldpath += \";c:\vcpkg\installed\x64-windows\lib\"; [System.Environment]::SetEnvironmentVariable(\"LIB\", $oldpath, \"Machine\")"
      powershell -command "$oldpath = [System.Environment]::GetEnvironmentVariable(\"INCLUDE\", \"Machine\"); $oldpath += \";c:\vcpkg\installed\x64-windows\include\"; [System.Environment]::SetEnvironmentVariable(\"INCLUDE\", $oldpath, \"Machine\")"
      powershell -command "$oldpath = [System.Environment]::GetEnvironmentVariable(\"Path\", \"Machine\"); $oldpath += \";c:\vcpkg\"; [System.Environment]::SetEnvironmentVariable(\"Path\", $oldpath, \"Machine\")"
      powershell -command "$oldpath = [System.Environment]::GetEnvironmentVariable(\"Path\", \"Machine\"); $oldpath += \";c:\vcpkg\installed\x64-windows\bin\"; [System.Environment]::SetEnvironmentVariable(\"Path\", $oldpath, \"Machine\")"
    )
    
  4. OpenBlas のインストール

    次のコマンドを実行

    c:\vcpkg\vcpkg search openblas
    c:\vcpkg\vcpkg install --triplet x64-windows openblas[threads]
    powershell -command "$oldpath = [System.Environment]::GetEnvironmentVariable(\"Path\", \"Machine\"); $oldpath += \";C:\vcpkg\installed\x64-windows\lib\"; [System.Environment]::SetEnvironmentVariable(\"Path\", $oldpath, \"Machine\")"
    powershell -command "[System.Environment]::SetEnvironmentVariable(\"OpenBLAS\", \"C:\vcpkg\installed\x64-windows\", \"Machine\")"
    powershell -command "[System.Environment]::SetEnvironmentVariable(\"OpenBLAS_ROOT\", \"C:\vcpkg\installed\x64-windows\", \"Machine\")"
    

BLAS の主な機能(ごく一部を紹介)

前準備

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

Gitは,バージョン管理システム.ソースコードの管理や複数人での共同に役立つ.

サイト内の関連ページ

Windows での Git のインストール: 別ページ »で説明している.

関連する外部ページ

Git の公式ページ: https://git-scm.com/

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

CMake はビルドツールである.

サイト内の関連ページ

Windows での cmake のインストール: 別ページ »で説明している.

関連する外部ページ

CMake の公式ダウンロードページ: https://cmake.org/download/

Build Tools for Visual Studio 2022 (ビルドツール for Visual Studio 2022),Visual Studio 2022 のインストール(Windows 上)

サイト内の関連ページ

関連する外部ページ

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

関連する外部ページhttps://github.com/xianyi/OpenBLAS/wiki/Installation-Guide

前もって,OpenBLAS をインストールするディレクトリを決めておく

このページでは,c:\OpenBLAS 下にインストールするものとして説明する.

  1. OpenBLAS のウェブページを開く

    https://www.openblas.net/

  2. このウェブページで利用条件などを確認

    必ず、最新情報を確認すること

    [image]
  3. Windows で,コマンドプロンプト管理者として実行.

    コマンドプロンプトを管理者として実行: 別ページ »で説明

  4. ソースコードのダウンロード,cmake の実行

    https://github.com/xianyi/OpenBLAS/wiki/Installation-Guide の記述を参考にした.

    cd c:\
    rmdir /s /q OpenBLAS
    git clone --recursive https://github.com/xianyi/OpenBLAS.git
    cd OpenBLAS
    rmdir /s /q build
    mkdir build
    cd build
    del CMakeCache.txt
    cmake .. -G "Visual Studio 17 2022" -A x64 -T host=x64 ^
        -DNOFORTRAN=ON ^
        -DDYNAMIC_ARCH=OFF ^
        -DCMAKE_INSTALL_PREFIX="c:/OpenBLAS" ^
        -DCMAKE_BUILD_TYPE=Release
    

    [image]
  5. cmake の結果の確認

    エラーメッセージが出なければ OK.

    [image]
  6. インストール

    終わるまでしばらく待つ

    cmake --build. --config RELEASE
    cmake --build. --config RELEASE --target INSTALL
    
  7. 結果の確認

    エラーメッセージが出なければ OK.

    [image]
  8. C:\OpenBLAS の下にファイルができるので確認する
    dir C:\OpenBLAS
    dir C:\OpenBLAS\include
    dir C:\OpenBLAS\lib
    

    [image]
  9. Windowsシステム環境変数 Path に次の値を追加することにより,パスを通す
    powershell -command "$oldpath = [System.Environment]::GetEnvironmentVariable(\"Path\", \"Machine\"); $oldpath += \";C:\OpenBLAS\lib\"; [System.Environment]::SetEnvironmentVariable(\"Path\", $oldpath, \"Machine\")"
    

    [image]
  10. Windowsシステム環境変数 OpenBLAS, OpenBLAS_ROOTC:\OpenBLAS を設定

    これは OpenCV のビルドのときに利用される環境変数

    powershell -command "[System.Environment]::SetEnvironmentVariable(\"OpenBLAS\", \"C:\OpenBLAS\", \"Machine\")"
    powershell -command "[System.Environment]::SetEnvironmentVariable(\"OpenBLAS_ROOT\", \"C:\OpenBLAS\", \"Machine\")"
    

    [image]

BLAS のプログラムをコンパイルし,実行する

https://gist.github.com/xianyi/6930656 に掲載の プログラムを利用

Build Tools for Visual Studio による動作確認

Windows での確認手順と結果は次の通り

  1. Windows では,Visual Studio の x64 Native Tools コマンドプロンプトを使う.(Windows のスタートメニューで起動できる).
  2. プログラムの準備

    https://gist.github.com/xianyi/6930656 に掲載の プログラムを利用. hoge.cのようなファイル名で保存.

  3. ビルドして実行
    cl /I"C:\OpenBLAS\include\openblas" hoge.c /link /LIBPATH:"C:\OpenBLAS\lib" openblas.lib
    .\hoge.exe
    

    [image]

LAPACK のプログラムをコンパイルし,実行する

eig_lapack.c を使用

Build Tools for Visual Studio による動作確認

Windows での確認手順と結果は次の通り

  1. Windows では,Visual Studio の x64 Native Tools コマンドプロンプトを使う.(Windows のスタートメニューで起動できる).
  2. プログラムの準備

    eig_lapack.c を使用

  3. ビルドして実行
    cl /I"C:\OpenBLAS\include\openblas" eig_lapack.c /link /LIBPATH:"C:\OpenBLAS\lib" openblas.lib
    .\eig_lapack.exe
    

    [image]