Skip to content

Commit

Permalink
Merge branch 'google:main' into avxifma
Browse files Browse the repository at this point in the history
  • Loading branch information
TianyouLi authored Oct 8, 2024
2 parents a23a81e + 7a8174a commit 93b04bc
Show file tree
Hide file tree
Showing 21 changed files with 266 additions and 45 deletions.
35 changes: 35 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
###############################################################################
# Common flags that apply to all configurations.
# Use sparingly for things common to all compilers and platforms.
###############################################################################

# Enable Bzlmod for every Bazel command
common --enable_bzlmod

# Prevent invalid caching if input files are modified during a build.
build --experimental_guard_against_concurrent_changes

###############################################################################
# Options for continuous integration.
###############################################################################

# Speedup bazel using a ramdisk.
build:ci --sandbox_base=/dev/shm

# Show as many errors as possible.
build:ci --keep_going

# Show subcommands when building
build:ci --subcommands=true

# Make sure we test for C99 compliance when building the library
build:ci --conlyopt=-std=c99

# Show test errors.
test:ci --test_output=errors

###############################################################################

# The user.bazelrc file is not checked in but available for local mods.
# Always keep this at the end of the file so that user flags override.
try-import %workspace%/user.bazelrc
File renamed without changes.
3 changes: 2 additions & 1 deletion .github/workflows/amd64_macos_bazel.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# ref: https://github.com/actions/runner-images
name: amd64 MacOS Bazel

on:
Expand All @@ -10,7 +11,7 @@ on:
jobs:
# Building using the github runner environement directly.
bazel:
runs-on: macos-latest
runs-on: macos-13 # Using x86 processors, ref: https://github.com/actions/runner-images
steps:
- name: Check out repository code
uses: actions/checkout@v3
Expand Down
5 changes: 3 additions & 2 deletions .github/workflows/amd64_macos_cmake.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# ref: https://github.com/actions/runner-images
name: amd64 MacOS CMake

on:
Expand All @@ -10,7 +11,7 @@ on:
jobs:
# Building using the github runner environement directly.
xcode:
runs-on: macos-latest
runs-on: macos-13 # Using x86 processors, ref: https://github.com/actions/runner-images
env:
CTEST_OUTPUT_ON_FAILURE: 1
steps:
Expand All @@ -26,7 +27,7 @@ jobs:
- name: Install
run: cmake --build build --config Release --target install -v
make:
runs-on: macos-latest
runs-on: macos-13 # Using x86 processors, ref: https://github.com/actions/runner-images
env:
CTEST_OUTPUT_ON_FAILURE: 1
steps:
Expand Down
36 changes: 36 additions & 0 deletions .github/workflows/arm64_macos_bazel.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# ref: https://github.com/actions/runner-images
name: Arm64 MacOS Bazel

on:
push:
pull_request:
schedule:
# min hours day(month) month day(week)
- cron: '0 0 7,22 * *'

jobs:
# Building using the github runner environement directly.
bazel:
runs-on: macos-latest # Using M1 processors, ref: https://github.com/actions/runner-images
steps:
- name: Check out repository code
uses: actions/checkout@v3
- name: Install Bazel
run: |
brew update
brew unlink bazelisk
brew install bazel
- name: Check Bazel
run: bazel version
- name: Build
run: >
bazel build
-c opt
--subcommands=true
...
- name: Test
run: >
bazel test
-c opt
--test_output=errors
...
44 changes: 44 additions & 0 deletions .github/workflows/arm64_macos_cmake.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# ref: https://github.com/actions/runner-images
name: Arm64 MacOS CMake

on:
push:
pull_request:
schedule:
# min hours day(month) month day(week)
- cron: '0 0 7,22 * *'

jobs:
# Building using the github runner environement directly.
xcode:
runs-on: macos-latest # Using M1 processors, ref: https://github.com/actions/runner-images
env:
CTEST_OUTPUT_ON_FAILURE: 1
steps:
- uses: actions/checkout@v2
- name: Check cmake
run: cmake --version
- name: Configure
run: cmake -S. -Bbuild -G "Xcode" -DCMAKE_CONFIGURATION_TYPES=Release -DCMAKE_INSTALL_PREFIX:PATH=destination
- name: Build
run: cmake --build build --config Release --target ALL_BUILD -v
- name: Test
run: cmake --build build --config Release --target RUN_TESTS -v
- name: Install
run: cmake --build build --config Release --target install -v
make:
runs-on: macos-latest # Using M1 processors, ref: https://github.com/actions/runner-images
env:
CTEST_OUTPUT_ON_FAILURE: 1
steps:
- uses: actions/checkout@v2
- name: Check cmake
run: cmake --version
- name: Configure
run: cmake -S. -Bbuild -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX:PATH=destination
- name: Build
run: cmake --build build --target all -v
- name: Test
run: cmake --build build --target test -v
- name: Install
run: cmake --build build --target install -v
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ out/

# Bazel artifacts
**/bazel-*
MODULE.bazel.lock

# Per-user bazelrc files
user.bazelrc
15 changes: 9 additions & 6 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ exports_files(["LICENSE"])
INCLUDES = ["include"]

C99_FLAGS = [
"-std=c99",
"-Wall",
"-Wextra",
"-Wmissing-declarations",
Expand Down Expand Up @@ -56,7 +55,7 @@ cc_test(
includes = INCLUDES,
deps = [
":bit_utils",
"@com_google_googletest//:gtest_main",
"@googletest//:gtest_main",
],
)

Expand Down Expand Up @@ -90,7 +89,7 @@ cc_test(
includes = INCLUDES,
deps = [
":string_view",
"@com_google_googletest//:gtest_main",
"@googletest//:gtest_main",
],
)

Expand Down Expand Up @@ -148,7 +147,7 @@ cc_test(
":cpu_features_macros",
":filesystem_for_testing",
":string_view",
"@com_google_googletest//:gtest_main",
"@googletest//:gtest_main",
],
)

Expand Down Expand Up @@ -312,7 +311,7 @@ cc_library(
PLATFORM_CPU_ARM: ["include/cpuinfo_arm.h"],
PLATFORM_CPU_ARM64: [
"include/cpuinfo_aarch64.h",
"include/internal/cpuid_aarch64.h"
"include/internal/cpuid_aarch64.h",
],
PLATFORM_CPU_MIPS: ["include/cpuinfo_mips.h"],
PLATFORM_CPU_PPC: ["include/cpuinfo_ppc.h"],
Expand All @@ -322,6 +321,10 @@ cc_library(
copts = C99_FLAGS,
defines = selects.with_or({
PLATFORM_CPU_X86_64: ["CPU_FEATURES_MOCK_CPUID_X86"],
PLATFORM_CPU_ARM64: [
"CPU_FEATURES_MOCK_CPUID_AARCH64",
"CPU_FEATURES_MOCK_SYSCTL_AARCH64",
],
"//conditions:default": [],
}) + selects.with_or({
PLATFORM_OS_MACOS: ["HAVE_SYSCTLBYNAME"],
Expand Down Expand Up @@ -365,7 +368,7 @@ cc_test(
":filesystem_for_testing",
":hwcaps_for_testing",
":string_view",
"@com_google_googletest//:gtest_main",
"@googletest//:gtest_main",
],
)

Expand Down
17 changes: 17 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
###############################################################################
# Bazel now uses Bzlmod by default to manage external dependencies.
# Please consider migrating your external dependencies from WORKSPACE to MODULE.bazel.
#
# For more details, please check https://github.com/bazelbuild/bazel/issues/18958
###############################################################################

CPU_FEATURES_VERSION = "0.9.0"

module(
name = "cpu_features",
repo_name = "com_google_cpufeatures",
version = CPU_FEATURES_VERSION,
)

bazel_dep(name = "bazel_skylib", version = "1.7.1")
bazel_dep(name = "googletest", version = "1.15.2")
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ instructions) at runtime.

| | Linux | FreeBSD | MacOS | Windows |
| :-- | --: | --: | --: | --: |
| amd64 | [![CMake][i1a0]][l1a0]<br/>[![Bazel][i1a1]][l1a1] | [![CMake][i2a0]][l2a0]<br/>![Bazel][d1] | [![CMake][i3a0]][l3a0]<br/>[![Bazel][i3a1]][l3a1] | [![CMake][i4a0]][l4a0]<br/>![Bazel][d1] |
| amd64 | [![CMake][i1a0]][l1a0]<br/>[![Bazel][i1a1]][l1a1] | ![CMake][d0]<br/>![Bazel][d1] | [![CMake][i3a0]][l3a0]<br/>[![Bazel][i3a1]][l3a1] | [![CMake][i4a0]][l4a0]<br/>![Bazel][d1] |
| AArch64 | [![CMake][i1b0]][l1b0]<br/>[![Bazel][i1b1]][l1b1] | ![CMake][d0]<br/>![Bazel][d1] | ![CMake][d0]<br/>![Bazel][d1] | ![CMake][d0]<br/>![Bazel][d1] |
| ARM | [![CMake][i1c0]][l1c0]<br/>![Bazel][d1] | ![CMake][d0]<br/>![Bazel][d1] | ![CMake][d0]<br/>![Bazel][d1] | ![CMake][d0]<br/>![Bazel][d1] |
| MIPS | [![CMake][i1d0]][l1d0]<br/>![Bazel][d1] | ![CMake][d0]<br/>![Bazel][d1] | ![CMake][d0]<br/>![Bazel][d1] | ![CMake][d0]<br/>![Bazel][d1] |
Expand All @@ -29,7 +29,6 @@ instructions) at runtime.
[i1e0]: https://img.shields.io/github/actions/workflow/status/google/cpu_features/power_linux_cmake.yml?branch=main&event=push&label=&logo=cmake
[i1f0]: https://img.shields.io/github/actions/workflow/status/google/cpu_features/riscv_linux_cmake.yml?branch=main&event=push&label=&logo=cmake
[i1h0]: https://img.shields.io/github/actions/workflow/status/google/cpu_features/s390x_linux_cmake.yml?branch=main&event=push&label=&logo=cmake
[i2a0]: https://img.shields.io/github/actions/workflow/status/google/cpu_features/amd64_freebsd_cmake.yml?branch=main&event=push&label=&logo=cmake
[i3a0]: https://img.shields.io/github/actions/workflow/status/google/cpu_features/amd64_macos_cmake.yml?branch=main&event=push&label=&logo=cmake
[i3a1]: https://img.shields.io/github/actions/workflow/status/google/cpu_features/amd64_macos_bazel.yml?branch=main&event=push&label=&logo=data:image/svg%2bxml;base64,PHN2ZyByb2xlPSJpbWciIHZpZXdCb3g9IjAgMCAyNCAyNCIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj48cGF0aCBkPSJNNiAuMTZsNS43ODYgNS43ODZMNiAxMS43MzIuMjE0IDUuOTQ2IDYgLjE2MXpNMCA2LjIxNFYxMmw1Ljc4NiA1Ljc4NlYxMkwwIDYuMjE0ek0xOCAuMTZsNS43ODYgNS43ODZMMTggMTEuNzMybC01Ljc4Ni01Ljc4NkwxOCAuMTYxek0yNCA2LjIxNFYxMmwtNS43ODYgNS43ODZWMTJMMjQgNi4yMTR6TTEyIDYuMTZsNS43ODYgNS43ODZMMTIgMTcuNzMybC01Ljc4Ni01Ljc4NkwxMiA2LjE2MXpNMTEuODQgMTguMDU0djUuNzg1bC01Ljc4Ni01Ljc4NXYtNS43ODZsNS43ODUgNS43ODZ6TTEyLjE2IDE4LjA1NGw1Ljc4Ni01Ljc4NnY1Ljc4NmwtNS43ODUgNS43ODV2LTUuNzg1eiIgc3Ryb2tlPSJ0cmFuc3BhcmVudCIgZmlsbD0id2hpdGUiLz48L3N2Zz4=
[i4a0]: https://img.shields.io/github/actions/workflow/status/google/cpu_features/amd64_windows_cmake.yml?branch=main&event=push&label=&logo=cmake
Expand All @@ -42,7 +41,6 @@ instructions) at runtime.
[l1e0]: https://github.com/google/cpu_features/actions/workflows/power_linux_cmake.yml
[l1f0]: https://github.com/google/cpu_features/actions/workflows/riscv_linux_cmake.yml
[l1h0]: https://github.com/google/cpu_features/actions/workflows/s390x_linux_cmake.yml
[l2a0]: https://github.com/google/cpu_features/actions/workflows/amd64_freebsd_cmake.yml
[l3a0]: https://github.com/google/cpu_features/actions/workflows/amd64_macos_cmake.yml
[l3a1]: https://github.com/google/cpu_features/actions/workflows/amd64_macos_bazel.yml
[l4a0]: https://github.com/google/cpu_features/actions/workflows/amd64_windows_cmake.yml
Expand Down
21 changes: 3 additions & 18 deletions WORKSPACE
Original file line number Diff line number Diff line change
@@ -1,19 +1,4 @@
workspace(name = "com_google_cpufeatures")

load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")

git_repository(
name = "com_google_googletest",
tag = "release-1.11.0",
remote = "https://github.com/google/googletest.git",
)
# This file marks the root of the Bazel workspace.
# See MODULE.bazel for external dependencies setup.

git_repository(
name = "bazel_skylib",
tag = "1.2.0",
remote = "https://github.com/bazelbuild/bazel-skylib.git",
)

load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace")

bazel_skylib_workspace()
workspace(name = "com_google_cpufeatures")
10 changes: 2 additions & 8 deletions bazel/ci/docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,7 @@ COPY . .

FROM devel AS build
RUN bazel version
RUN bazel build \
-c opt \
--subcommands=true \
...
RUN bazel build --config=ci ...

FROM build AS test
RUN bazel test \
-c opt \
--test_output=errors \
...
RUN bazel test --config=ci ...
2 changes: 1 addition & 1 deletion cmake/ci/docker/amd64/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ LABEL maintainer="corentinl@google.com"
ENV PATH=/usr/local/bin:$PATH
RUN apt-get update -qq \
&& DEBIAN_FRONTEND=noninteractive apt-get install -yq git wget libssl-dev build-essential \
ninja-build python3 pkgconf libglib2.0-dev \
ninja-build python3 python3-venv pkgconf libglib2.0-dev \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
ENTRYPOINT ["/usr/bin/bash", "-c"]
Expand Down
2 changes: 1 addition & 1 deletion cmake/ci/docker/toolchain/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ LABEL maintainer="corentinl@google.com"
ENV PATH=/usr/local/bin:$PATH
RUN apt-get update -qq \
&& DEBIAN_FRONTEND=noninteractive apt-get install -yq git wget libssl-dev build-essential \
ninja-build python3 pkgconf libglib2.0-dev \
ninja-build python3 python3-venv pkgconf libglib2.0-dev \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
ENTRYPOINT ["/usr/bin/bash", "-c"]
Expand Down
6 changes: 4 additions & 2 deletions include/cpu_features_macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -235,11 +235,13 @@
#endif // defined(CPU_FEATURES_ARCH_X86)

#if defined(CPU_FEATURES_ARCH_ANY_ARM)
#if defined(__ARM_NEON__)
// Note: MSVC targeting ARM does not define `__ARM_NEON` but Windows on ARM
// requires it. In that case we force NEON detection.
#if defined(__ARM_NEON) || defined(CPU_FEATURES_COMPILER_MSC)
#define CPU_FEATURES_COMPILED_ANY_ARM_NEON 1
#else
#define CPU_FEATURES_COMPILED_ANY_ARM_NEON 0
#endif // defined(__ARM_NEON__)
#endif // defined(__ARM_NEON) || defined(CPU_FEATURES_COMPILER_MSC)
#endif // defined(CPU_FEATURES_ARCH_ANY_ARM)

#if defined(CPU_FEATURES_ARCH_MIPS)
Expand Down
43 changes: 43 additions & 0 deletions include/cpuinfo_aarch64.h
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,31 @@ typedef struct {
int smef16f16 : 1; // FP16 to FP16 outer product.
int mops : 1; // Standardized memory operations.
int hbc : 1; // Hinted conditional branches.
int sveb16b16 : 1; // Non-widening BFloat16 to BFloat16 arithmetic for SVE2
// and SME2.
int lrcpc3 : 1; // Load-Acquire RCpc instructions version 3.
int lse128 : 1; // 128-bit Atomics.
int fpmr : 1; // Floating-point Mode Register.
int lut : 1; // Lookup table instructions with 2-bit and 4-bit indices.
int faminmax : 1; // Maximum and minimum absolute value instructions.
int f8cvt : 1; // FP scaling instructions and FP8 convert instructions.
int f8fma : 1; // FP8 to single-precision and half-precision
// multiply-accumulate instructions.
int f8dp4 : 1; // FP8 to single-precision 4-way dot product FDOT (4-way)
// instructions.
int f8dp2 : 1; // FP8 to half-precision 2-way dot product FDOT (2-way)
// instructions.
int f8e4m3 : 1; // Arm FP8 E4M3 format.
int f8e5m2 : 1; // Arm FP8 E5M2 format.
int smelutv2 : 1; // SME2 lookup table LUTI4 and MOVT instructions.
int smef8f16 : 1; // SME2 F8F16 instructions.
int smef8f32 : 1; // SME2 F8F32 instructions.
int smesf8fma : 1; // SVE2 FP8 to single-precision and half-precision
// multiply-accumulate instructions.
int smesf8dp4 : 1; // SVE2 FP8 to single-precision 4-way dot product FDOT
// (4-way) instructions.
int smesf8dp2 : 1; // SVE2 FP8 to half-precision 2-way dot product FDOT
// (2-way) instructions.

// Make sure to update Aarch64FeaturesEnum below if you add a field here.
} Aarch64Features;
Expand Down Expand Up @@ -288,6 +313,24 @@ typedef enum {
AARCH64_SME_F16F16,
AARCH64_MOPS,
AARCH64_HBC,
AARCH64_SVE_B16B16,
AARCH64_LRCPC3,
AARCH64_LSE128,
AARCH64_FPMR,
AARCH64_LUT,
AARCH64_FAMINMAX,
AARCH64_F8CVT,
AARCH64_F8FMA,
AARCH64_F8DP4,
AARCH64_F8DP2,
AARCH64_F8E4M3,
AARCH64_F8E5M2,
AARCH64_SME_LUTV2,
AARCH64_SME_F8F16,
AARCH64_SME_F8F32,
AARCH64_SME_SF8FMA,
AARCH64_SME_SF8DP4,
AARCH64_SME_SF8DP2,
AARCH64_LAST_,
} Aarch64FeaturesEnum;

Expand Down
Loading

0 comments on commit 93b04bc

Please sign in to comment.