金子邦彦研究室インストール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 のプログラムをコンパイルし,実行する

Windows での OpenBLAS のインストール(サイト内のページ)】

複数の方法がある.方法を問わない場合には,Build Tools for Visual Studio を利用するのが簡単である.

サイト内の関連ページ

謝辞

OpenBLAS の作者に感謝します


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

前準備

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

関連する外部ページ

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

Windows での Git のインストール: 別ページ »で説明

関連する外部ページ

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

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

Windows での cmake のインストール: 別ページ »で説明

関連する外部ページ

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

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

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

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

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

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

    https://www.openblas.net/

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

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

    [image]
  3. Windowsコマンドプロンプトを実行する.
  4. OpenBLAS の作業ディレクトリを削除する(以前作業したときのものが残っていたら削除したいため)
    C:
    cd %HOMEPATH%
    rmdir /s /q OpenBLAS
    
  5. ソースコードのダウンロード
    cd %HOMEPATH%
    git clone --recursive https://github.com/xianyi/OpenBLAS.git
    

    [image]
  6. cmake の実行

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

    cd %HOMEPATH%
    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]
  7. cmake の結果の確認

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

    [image]
  8. インストール

    終わるまでしばらく待つ

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

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

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

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

    これ以降の作業は, 管理者として実行したコマンドプロンプトで行う.

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

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

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

    call powershell -command "[System.Environment]::SetEnvironmentVariable(\"OpenBLAS\", \"C:\OpenBLAS\", \"Machine\")"
    call 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]