From 9d0f1663b0874dd3d9557fbe6bff2287c68dacb1 Mon Sep 17 00:00:00 2001 From: AOYAMA Kazuharu Date: Sun, 10 Nov 2024 11:54:35 +0900 Subject: [PATCH] updated README, add a test code. --- .github/workflows/actions.yml | 15 +++++++---- .github/workflows/build-relase.yml | 2 +- README.md | 41 ++++++++++++++++++++++++++++++ tests/dgemm.cpp | 29 +++++++++++++++++++++ 4 files changed, 81 insertions(+), 6 deletions(-) create mode 100644 tests/dgemm.cpp diff --git a/.github/workflows/actions.yml b/.github/workflows/actions.yml index 1b8f816..70bd044 100644 --- a/.github/workflows/actions.yml +++ b/.github/workflows/actions.yml @@ -12,7 +12,7 @@ jobs: steps: - uses: actions/checkout@main - name: Homebrew - run: brew install qt6 + run: brew install qt6 pkg-config - name: build run: | qmake CONFIG+=release @@ -25,6 +25,7 @@ jobs: ./cpi tests/unique_ptr.cpp ./cpi tests/optional.cpp ./cpi tests/if_initializer.cpp + ./cpi test/dgemm.cpp - name: error tests run: | ./cpi tests/error_code.cpp @@ -38,7 +39,7 @@ jobs: - name: apt run: | sudo apt-get update -qq - sudo apt-get install -y --no-install-recommends g++ make qmake6 qt6-base-dev qt6-base-dev-tools + sudo apt-get install -y --no-install-recommends g++ make qmake6 qt6-base-dev qt6-base-dev-tools pkg-config - name: build run: | qmake6 CONFIG+=release @@ -53,6 +54,7 @@ jobs: ./cpi tests/if_initializer.cpp ./cpi tests/ranges.cpp ./cpi tests/concept_add.cpp + ./cpi test/dgemm.cpp - name: error tests run: | ./cpi tests/error_code.cpp @@ -66,7 +68,7 @@ jobs: run: | sudo apt-get update -qq sudo apt purge -y gcc g++ - sudo apt-get install -y --no-install-recommends clang make qmake6 qt6-base-dev qt6-base-dev-tools + sudo apt-get install -y --no-install-recommends clang make qmake6 qt6-base-dev qt6-base-dev-tools pkg-config - name: build run: | qmake6 -spec linux-clang CONFIG+=release @@ -79,6 +81,7 @@ jobs: ./cpi tests/unique_ptr.cpp ./cpi tests/optional.cpp ./cpi tests/if_initializer.cpp + ./cpi test/dgemm.cpp - name: error tests run: | ./cpi tests/error_code.cpp @@ -91,7 +94,7 @@ jobs: - name: apt run: | sudo apt-get update -qq - sudo apt-get install -y --no-install-recommends g++ make qmake6 qt6-base-dev qt6-base-dev-tools + sudo apt-get install -y --no-install-recommends g++ make qmake6 qt6-base-dev qt6-base-dev-tools pkg-config - name: build run: | qmake6 CONFIG+=release @@ -106,6 +109,7 @@ jobs: ./cpi tests/if_initializer.cpp ./cpi tests/ranges.cpp ./cpi tests/concept_add.cpp + ./cpi test/dgemm.cpp - name: error tests run: | ./cpi tests/error_code.cpp @@ -119,7 +123,7 @@ jobs: run: | sudo apt-get update -qq sudo apt purge -y gcc g++ - sudo apt-get install -y --no-install-recommends clang make qmake6 qt6-base-dev qt6-base-dev-tools + sudo apt-get install -y --no-install-recommends clang make qmake6 qt6-base-dev qt6-base-dev-tools pkg-config - name: build run: | qmake6 -spec linux-clang CONFIG+=release @@ -132,6 +136,7 @@ jobs: ./cpi tests/unique_ptr.cpp ./cpi tests/optional.cpp ./cpi tests/if_initializer.cpp + ./cpi test/dgemm.cpp - name: error tests run: | ./cpi tests/error_code.cpp diff --git a/.github/workflows/build-relase.yml b/.github/workflows/build-relase.yml index c808885..6402b42 100644 --- a/.github/workflows/build-relase.yml +++ b/.github/workflows/build-relase.yml @@ -58,7 +58,7 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: tag_name: ${{ github.ref }} - release_name: Release ${{ github.ref }} + release_name: Cpi version ${{ github.ref }} release draft: false prerelease: false diff --git a/README.md b/README.md index d926a58..ae85fa6 100644 --- a/README.md +++ b/README.md @@ -139,6 +139,47 @@ int main(int argc, char *argv[]) 1.7320 ``` +Furthermore, pkg-config command can be used for *CompileOptions*. + +```cpp +#include +#include + +int main() +{ + // 2x2 Matrix + int M = 2, N = 2, K = 2; + double A[4] = {1.0, 2.0, 3.0, 4.0}; + double B[4] = {5.0, 6.0, 7.0, 8.0}; + double C[4]; + + // General Matrix-Matrix multiplication + cblas_dgemm(CblasRowMajor, CblasNoTrans, CblasNoTrans, + M, N, K, + 1.0, A, K, B, N, + 0.0, C, N); + + // Print results + std::cout << "Result of A * B = C:" << std::endl; + for (int i = 0; i < 2; ++i) { + for (int j = 0; j < 2; ++j) { + std::cout << C[i * 2 + j] << " "; + } + std::cout << std::endl; + } + return 0; +} + +// CompileOptions: `pkg-config --cflags --libs openblas` +``` + +```sh + $ cpi dgemm.cpp + Result of A * B = C: + 19 22 + 43 50 +``` + #### Running like a scripting language Adding a shebang, save as *hello.cpps*. No longer compiled in a C++ compiler successfully. diff --git a/tests/dgemm.cpp b/tests/dgemm.cpp new file mode 100644 index 0000000..3b0bdda --- /dev/null +++ b/tests/dgemm.cpp @@ -0,0 +1,29 @@ +#include +#include + +int main() +{ + // 2x2 Matrix + int M = 2, N = 2, K = 2; + double A[4] = {1.0, 2.0, 3.0, 4.0}; + double B[4] = {5.0, 6.0, 7.0, 8.0}; + double C[4]; + + // General Matrix-Matrix multiplication + cblas_dgemm(CblasRowMajor, CblasNoTrans, CblasNoTrans, + M, N, K, + 1.0, A, K, B, N, + 0.0, C, N); + + // Print results + std::cout << "Result of A * B = C:" << std::endl; + for (int i = 0; i < 2; ++i) { + for (int j = 0; j < 2; ++j) { + std::cout << C[i * 2 + j] << " "; + } + std::cout << std::endl; + } + return 0; +} + +// CompileOptions: `pkg-config --cflags --libs openblas`