From 6de86751dcc2d29956331916ca5a00b9d61cb91f Mon Sep 17 00:00:00 2001 From: Marat Dukhan Date: Mon, 27 May 2024 15:18:31 -0700 Subject: [PATCH] Add GitHub Actions CI for Mac --- .github/workflows/cmake.yml | 24 +++++++++++++++++++++++- bench/from-ieee-array.cc | 6 ++++-- bench/to-ieee-array.cc | 6 ++++-- cmake/DownloadGoogleBenchmark.cmake | 4 ++-- 4 files changed, 33 insertions(+), 7 deletions(-) diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index 7242d6e..4bbc045 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -21,8 +21,30 @@ jobs: - name: Install ninja run: sudo apt install ninja-build - name: Configure - run: cmake -Bbuild -S. -GNinja -DCMAKE_BUILD_TYPE=Release -DFP16_BUILD_COMPARATIVE_BENCHMARKS=ON + run: cmake -Bbuild -S. -G Ninja -DCMAKE_BUILD_TYPE=Release -DFP16_BUILD_COMPARATIVE_BENCHMARKS=ON - name: Build run: cmake --build build - name: Test run: ctest --test-dir build + cmake-macos-x86_64: + runs-on: macos-12 + timeout-minutes: 15 + steps: + - uses: actions/checkout@v4 + - name: Configure + run: cmake -Bbuild -S. -G Xcode -DCMAKE_CONFIGURATION_TYPES=Release -DHAVE_STD_REGEX=TRUE -DFP16_BUILD_COMPARATIVE_BENCHMARKS=ON -DCMAKE_OSX_ARCHITECTURES=x86_64 + - name: Build + run: cmake --build build --config Release --parallel $(sysctl -n hw.ncpu) -- -quiet + - name: Test + run: ctest --test-dir build + cmake-macos-arm64: + runs-on: macos-14 + timeout-minutes: 15 + steps: + - uses: actions/checkout@v4 + - name: Configure + run: cmake -Bbuild -S. -G Xcode -DCMAKE_CONFIGURATION_TYPES=Release -DHAVE_STD_REGEX=TRUE -DFP16_BUILD_COMPARATIVE_BENCHMARKS=ON -DCMAKE_OSX_ARCHITECTURES=arm64e + - name: Build + run: cmake --build build --config Release --parallel $(sysctl -n hw.ncpu) -- -quiet + - name: Test + run: ctest --test-dir build diff --git a/bench/from-ieee-array.cc b/bench/from-ieee-array.cc index 67a11b1..b7bf44e 100644 --- a/bench/from-ieee-array.cc +++ b/bench/from-ieee-array.cc @@ -148,9 +148,11 @@ BENCHMARK(fp16_ieee_to_fp32_value)->RangeMultiplier(2)->Range(1<<10, 64<<20); float* output = fp32.data(); const size_t n = state.range(0); #if defined(__aarch64__) - const unsigned int fpcr = __builtin_aarch64_get_fpcr(); + unsigned int fpcr; + __asm__ __volatile__("MRS %[fpcr], fpcr" : [fpcr] "=r" (fpcr)); /* Disable flush-to-zero (bit 24) and Alternative FP16 format (bit 26) */ - __builtin_aarch64_set_fpcr(fpcr & 0xF6FFFFFFu); + __asm__ __volatile__("MSR fpcr, %[fpcr]" : + : [fpcr] "r" (fpcr & 0xF6FFFFFFu)); #else unsigned int fpscr; __asm__ __volatile__ ("VMRS %[fpscr], fpscr" : [fpscr] "=r" (fpscr)); diff --git a/bench/to-ieee-array.cc b/bench/to-ieee-array.cc index ffdb77f..3f7d315 100644 --- a/bench/to-ieee-array.cc +++ b/bench/to-ieee-array.cc @@ -119,9 +119,11 @@ BENCHMARK(fp16_ieee_from_fp32_value)->RangeMultiplier(2)->Range(1<<10, 64<<20); uint16_t* output = fp16.data(); const size_t n = state.range(0); #if defined(__aarch64__) - const unsigned int fpcr = __builtin_aarch64_get_fpcr(); + unsigned int fpcr; + __asm__ __volatile__("MRS %[fpcr], fpcr" : [fpcr] "=r" (fpcr)); /* Disable flush-to-zero (bit 24) and Alternative FP16 format (bit 26) */ - __builtin_aarch64_set_fpcr(fpcr & 0xF6FFFFFFu); + __asm__ __volatile__("MSR fpcr, %[fpcr]" : + : [fpcr] "r" (fpcr & 0xF6FFFFFFu)); #else unsigned int fpscr; __asm__ __volatile__ ("VMRS %[fpscr], fpscr" : [fpscr] "=r" (fpscr)); diff --git a/cmake/DownloadGoogleBenchmark.cmake b/cmake/DownloadGoogleBenchmark.cmake index 0b082ba..46e5ea0 100644 --- a/cmake/DownloadGoogleBenchmark.cmake +++ b/cmake/DownloadGoogleBenchmark.cmake @@ -4,8 +4,8 @@ PROJECT(googlebenchmark-download NONE) INCLUDE(ExternalProject) ExternalProject_Add(googlebenchmark - URL https://github.com/google/benchmark/archive/v1.2.0.zip - URL_HASH SHA256=cc463b28cb3701a35c0855fbcefb75b29068443f1952b64dd5f4f669272e95ea + URL https://github.com/google/benchmark/archive/refs/tags/v1.8.4.zip + URL_HASH SHA256=84c49c4c07074f36fbf8b4f182ed7d75191a6fa72756ab4a17848455499f4286 SOURCE_DIR "${CMAKE_BINARY_DIR}/googlebenchmark-source" BINARY_DIR "${CMAKE_BINARY_DIR}/googlebenchmark" CONFIGURE_COMMAND ""