Skip to content

Commit ab346c3

Browse files
Adrien-Tabtretre91pzehnerPaulGannay
authored
CPU and GPU identification data (#6)
* Initial version for CPU + OS for Unix Signed-off-by: Adrien Taberner <adrien.taberner@cea.fr> * Hip Gpu info + fallback values from cmake Signed-off-by: Adrien Taberner <adrien.taberner@cea.fr> * CUDA GPU Signed-off-by: Adrien Taberner <adrien.taberner@cea.fr> * Add a cmake option to enable the tests - add a CEXA_ARCHINFO_ENABLE_TESTS option - try to find gtest before calling FetchContent - link to gtest instead of gtest_main - Use the PRE_TEST test discovery mode * Dispatch to the platform specific impls at compile time - Use macros to choose between the platform specific functions instead of doing it at configure time * Add windows specific functions * Use nvml to get the driver version * Implement sycl functions * Make the platform specific functions non-inline * Add macos specific functions - Remove the compilInfo.hpp * Small changes in the gpu functions * Add a proper installation mechanism - Properly install the library - Do not install gtest alongside the library - Add an install test subdirectory * Add a CI - Only ubuntu and macos for the moment * ci: install kokkos outside of the github workspace * ci: checkout the code before installing kokkos * Remove the call to the print functions in the tests * Return "ERROR" if the file open failed for macos get_sys_name * Rename the functions * Update the README * Remove unnecessary backslashes in the README * Use the right install path for the cmake target files * Update the README * Update the linux functions - /proc/cpuinfo is not reliable on arm, replace it with lscpu or reading values from /sys/ - make the functions return optional * Run the CI on arm ubuntu * Redirect lscpu's sterr to /dev/null * Add a comment aying that cpuid won't work on arm windows * First try at integrating a windows ci * ci: Remove ARCH_NATIVE as MSVC doesn't support it * Remove warning flags set in the CMakeLists * ci: Remove Kokkos_ENABLE_COMPILER_WARNINGS * Fix the windows CI * Apply suggestions from review Co-authored-by: Adrien Taberner <adrien.taberner@cea.fr> * Place the functions in the cexa:: namespace - move the other functions to cexa::impl * Update the README * Change the output's formatting * ci: Simplify the declaration of paths triggering the ci * Add comments as advised in code review Co-authored-by: Paul Zehner <paul.zehner@cea.fr> * Use std::size_t instead of size_t Co-authored-by: Paul Zehner <paul.zehner@cea.fr> * Simplify some if conditions Co-authored-by: Paul Zehner <paul.zehner@cea.fr> * Use a more modern CMake installation mechanism Co-authored-by: Paul Zehner <paul.zehner@cea.fr> * Add check_required_components to the cmake Config file * Add OpenACC support * Rename the include guard for cexa_ArchInfo.hpp * Read the cpu name from the registry on windows * Add a windows arm ci * ci: set the extra flags for the windows arm runner * Remove a useless target_include_directories * Add the copyright notice * Update archInfo/src/cexa_ArchInfo.cpp Co-authored-by: PaulGannay <paul.gannay@cea.fr> * Update archInfo/CMakeLists.txt Co-authored-by: Paul Zehner <paul.zehner@alumni.enseeiht.fr> * CPU Name detection on GH200, rename 'Error' to 'Unknown' Signed-off-by: Adrien Taberner <adrien.taberner@cea.fr> * RAII: FILE* Signed-off-by: Adrien Taberner <adrien.taberner@cea.fr> * Use ubuntu 24 Signed-off-by: Adrien Taberner <adrien.taberner@cea.fr> * Use source files instead of headers for the cpu info functions * Correctly call find_dependency * move functions from cexa::impl to cexa:: Signed-off-by: Adrien Taberner <adrien.taberner@cea.fr> * Fix Tests Signed-off-by: Adrien Taberner <adrien.taberner@cea.fr> * Add check for nvml call Signed-off-by: Adrien Taberner <adrien.taberner@cea.fr> --------- Signed-off-by: Adrien Taberner <adrien.taberner@cea.fr> Co-authored-by: Trévis Morvany <trevis.morvany@cea.fr> Co-authored-by: Paul Zehner <paul.zehner@cea.fr> Co-authored-by: Trévis Morvany <trevismorvany@gmail.com> Co-authored-by: PaulGannay <paul.gannay@cea.fr> Co-authored-by: Paul Zehner <paul.zehner@alumni.enseeiht.fr>
1 parent 2cf6968 commit ab346c3

14 files changed

Lines changed: 1208 additions & 0 deletions

.github/workflows/arch-info.yml

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
# SPDX-FileCopyrightText: 2026 CExA-project
2+
# SPDX-License-Identifier: MIT or Apache-2.0 with LLVM-exception
3+
4+
name: ArchInfo Tests
5+
6+
on:
7+
pull_request:
8+
paths:
9+
- '.github/workflows/arch-info.yml'
10+
- 'archInfo/**'
11+
- '!archInfo/README.md'
12+
push:
13+
branches:
14+
- main
15+
16+
concurrency:
17+
group: ${{ github.event_name }}-${{ github.workflow }}-${{ github.ref }}
18+
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
19+
20+
jobs:
21+
archinfo-ci:
22+
continue-on-error: true
23+
strategy:
24+
matrix:
25+
backend: ["SERIAL"]
26+
kokkos-version: ["5.0.2"]
27+
runner: ["windows-2025", "windows-11-arm", "ubuntu-22.04", "ubuntu-24.04-arm", "macos-15", "macos-15-intel"]
28+
include:
29+
- extra_cmake_build_flags: ""
30+
- extra_ctest_flags: ""
31+
- install_test_exe: "./build/main"
32+
- extra_cmake_build_flags: "--config RelWithDebInfo"
33+
runner: "windows-2025"
34+
- extra_ctest_flags: "--build-config RelWithDebInfo"
35+
runner: "windows-2025"
36+
- install_test_exe: "./build/RelWithDebInfo/main.exe"
37+
runner: "windows-2025"
38+
- extra_cmake_build_flags: "--config RelWithDebInfo"
39+
runner: "windows-11-arm"
40+
- extra_ctest_flags: "--build-config RelWithDebInfo"
41+
runner: "windows-11-arm"
42+
- install_test_exe: "./build/RelWithDebInfo/main.exe"
43+
runner: "windows-11-arm"
44+
45+
runs-on: ${{ matrix.runner }}
46+
47+
steps:
48+
- name: Checkout Code
49+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
50+
- uses: actions/cache@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5.0.3
51+
id: cache-kokkos
52+
with:
53+
path: opt/kokkos
54+
key: archinfo-kokkos-${{ matrix.backend }}-${{ matrix.kokkos-version }}-${{ matrix.runner }}
55+
# We need to use cygpath on Windows to avoid the '\' in github.workspace
56+
# leading to incorrect paths in bash
57+
- name: Setup Windows env variables
58+
shell: bash
59+
if: ${{ contains(matrix.runner, 'windows') }}
60+
run: |
61+
echo "Kokkos_ROOT=$(cygpath "${{ github.workspace }}/opt/kokkos")" >> $GITHUB_ENV
62+
echo "CexaArchInfo_ROOT=$(cygpath "${{ github.workspace }}/archInfo/install")" >> $GITHUB_ENV
63+
- name: Setup Unix env variables
64+
shell: bash
65+
if: ${{ !contains(matrix.runner, 'windows') }}
66+
run: |
67+
echo "Kokkos_ROOT=${{ github.workspace }}/opt/kokkos" >> $GITHUB_ENV
68+
echo "CexaArchInfo_ROOT=${{ github.workspace }}/archInfo/install" >> $GITHUB_ENV
69+
- name: Checkout Kokkos
70+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
71+
if: steps.cache-kokkos.outputs.cache-hit != 'true'
72+
with:
73+
repository: kokkos/kokkos
74+
ref: ${{ matrix.kokkos-version }}
75+
path: kokkos
76+
- name: Install kokkos
77+
if: steps.cache-kokkos.outputs.cache-hit != 'true'
78+
shell: bash
79+
run: |
80+
cmake -S kokkos -B kokkos/build \
81+
-DKokkos_ENABLE_${{ matrix.backend }}=ON \
82+
-DCMAKE_BUILD_TYPE=RelWithDebInfo \
83+
-DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded \
84+
-DCMAKE_INSTALL_PREFIX="$Kokkos_ROOT"
85+
cmake --build kokkos/build ${{ matrix.extra_cmake_build_flags }} -j --target install
86+
- name: Configure
87+
working-directory: ${{ github.workspace }}/archInfo
88+
shell: bash
89+
run:
90+
cmake -S . -B build
91+
-DCMAKE_BUILD_TYPE=RelWithDebInfo
92+
-DCEXA_ARCHINFO_ENABLE_TESTS=ON
93+
-DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded
94+
-DCMAKE_INSTALL_PREFIX="$CexaArchInfo_ROOT"
95+
- name: Build
96+
working-directory: ${{ github.workspace }}/archInfo
97+
shell: bash
98+
run: cmake --build build ${{ matrix.extra_cmake_build_flags }} -j
99+
- name: Run tests
100+
working-directory: ${{ github.workspace }}/archInfo
101+
shell: bash
102+
run: ctest --test-dir build ${{ matrix.extra_ctest_flags }}
103+
- name: Install
104+
working-directory: ${{ github.workspace }}/archInfo
105+
shell: bash
106+
run: cmake --install build ${{ matrix.extra_cmake_build_flags }}
107+
- name: Test install
108+
working-directory: ${{ github.workspace }}/archInfo/test/install_test
109+
shell: bash
110+
run: |
111+
cmake -S . -B build \
112+
-DCMAKE_BUILD_TYPE=RelWithDebInfo \
113+
-DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded
114+
cmake --build build ${{ matrix.extra_cmake_build_flags }} -j
115+
${{ matrix.install_test_exe }}

archInfo/CMakeLists.txt

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# SPDX-FileCopyrightText: 2026 CExA-project
2+
# SPDX-License-Identifier: MIT or Apache-2.0 with LLVM-exception
3+
4+
cmake_minimum_required(VERSION 3.23)
5+
6+
project(cexa-experimental-archInfo LANGUAGES CXX VERSION 0.1.0)
7+
8+
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/../cmake/modules")
9+
find_package(Kokkos REQUIRED)
10+
11+
option(CEXA_ARCHINFO_ENABLE_TESTS "Build the unit tests" OFF)
12+
13+
add_subdirectory(src)
14+
15+
if (CEXA_ARCHINFO_ENABLE_TESTS)
16+
enable_testing()
17+
add_subdirectory(test/unit_test)
18+
endif()
19+
20+
include(GNUInstallDirs)
21+
include(CMakePackageConfigHelpers)
22+
23+
write_basic_package_version_file(
24+
CexaArchInfoConfigVersion.cmake
25+
COMPATIBILITY SameMajorVersion
26+
)
27+
28+
configure_package_config_file(
29+
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/CexaArchInfoConfig.cmake.in"
30+
"${CMAKE_CURRENT_BINARY_DIR}/CexaArchInfoConfig.cmake"
31+
INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/CexaArchInfo"
32+
)
33+
34+
install(
35+
EXPORT CexaArchInfoTargets
36+
FILE CexaArchInfoTargets.cmake
37+
NAMESPACE cexa::
38+
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/CexaArchInfo"
39+
)
40+
41+
install(FILES
42+
"${CMAKE_CURRENT_BINARY_DIR}/CexaArchInfoConfig.cmake"
43+
"${CMAKE_CURRENT_BINARY_DIR}/CexaArchInfoConfigVersion.cmake"
44+
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/CexaArchInfo")
45+

archInfo/README.md

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
<!--
2+
SPDX-FileCopyrightText: 2026 CExA-project
3+
4+
SPDX-License-Identifier: MIT OR Apache-2.0 WITH LLVM-exception
5+
-->
6+
7+
# ArchInfo
8+
9+
A small utility library for printing useful information about the system a
10+
Kokkos program runs on.
11+
12+
## Build
13+
14+
The library can be built using CMake, it depends on Kokkos
15+
```bash
16+
git clone https://github.com/CExA-project/CExA-Experimental
17+
cd CExA-Experimental/archInfo
18+
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release -DKokkos_ROOT=<path/to/kokkos/install>
19+
cmake --build build
20+
cmake --install
21+
```
22+
23+
The tests can be enabled by adding the option `-DCEXA_ARCHINFO_ENABLE_TESTS=ON`
24+
to CMake.
25+
26+
## Usage
27+
28+
The library can be included in a CMake project using `find_package`
29+
```cmake
30+
find_package(Kokkos REQUIRED)
31+
find_package(CexaArchInfo 0.1.0 REQUIRED)
32+
33+
add_executable(main)
34+
target_link_libraries(main PRIVATE cexa::archInfo Kokkos::kokkos)
35+
```
36+
37+
### API
38+
39+
#### Information about the operating system
40+
41+
```cpp
42+
cexa::print_os_info(std::cout);
43+
```
44+
45+
Possible output on a Linux system:
46+
```
47+
OS:
48+
- Type: Linux
49+
- Name: Red Hat Enterprise Linux 9.6 (Plow)
50+
- Kernel: 5.14.0-570.69.1.el9_6.x86_64
51+
```
52+
53+
#### Information about the CPU
54+
55+
```cpp
56+
cexa::print_host_info(std::cout);
57+
```
58+
59+
Possible output:
60+
```
61+
HOST:
62+
- Model: AMD EPYC 7A53 64-Core Processor
63+
- Cores per socket: 64
64+
- Threads per socket: 128
65+
- Sockets: 1
66+
- Kokkos Concurrency: 1
67+
```
68+
69+
#### Information about the GPU
70+
71+
```cpp
72+
cexa::print_device_info(std::cout);
73+
```
74+
75+
Possible output:
76+
```
77+
DEVICE:
78+
- Model: AMD Instinct MI300A
79+
- Arch: gfx942:sramecc+:xnack-
80+
- Runtime Version: 6.3.42134
81+
- Driver Version: 6.3.42134
82+
```
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# SPDX-FileCopyrightText: 2026 CExA-project
2+
# SPDX-License-Identifier: MIT or Apache-2.0 with LLVM-exception
3+
4+
@PACKAGE_INIT@
5+
6+
include(CMakeFindDependencyMacro)
7+
8+
find_dependency(Kokkos)
9+
10+
include("${CMAKE_CURRENT_LIST_DIR}/CexaArchInfoTargets.cmake")
11+
12+
check_required_components(CexaArchInfo)

archInfo/src/CMakeLists.txt

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# SPDX-FileCopyrightText: 2026 CExA-project
2+
# SPDX-License-Identifier: MIT or Apache-2.0 with LLVM-exception
3+
4+
include(GNUInstallDirs)
5+
6+
add_library(archInfo)
7+
add_library(cexa::ArchInfo ALIAS archInfo)
8+
9+
target_sources(
10+
archInfo
11+
PUBLIC
12+
FILE_SET HEADERS
13+
FILES
14+
cexa_ArchInfo.hpp
15+
PRIVATE
16+
cexa_ArchInfo.cpp
17+
cexa_unixArchInfo.cpp
18+
cexa_windowsArchInfo.cpp
19+
cexa_macosArchInfo.cpp
20+
)
21+
22+
target_compile_features(archInfo PUBLIC cxx_std_17)
23+
target_link_libraries(archInfo PUBLIC Kokkos::kokkos)
24+
if ("${Kokkos_ENABLE_CUDA}")
25+
find_package(CUDAToolkit REQUIRED)
26+
target_link_libraries(archInfo PRIVATE CUDA::nvml)
27+
endif()
28+
29+
install(
30+
TARGETS archInfo
31+
EXPORT CexaArchInfoTargets
32+
FILE_SET HEADERS
33+
)

0 commit comments

Comments
 (0)