File: CMakeLists.txt
cmake_minimum_required(VERSION 3.18)
#///////////////////////////////////////////////////////////////////#
PROJECT
#///////////////////////////////////////////////////////////////////#
project(nvtop VERSION 3.3.2
LANGUAGES C CXX)
set(default_build_type "Release")
Default build type
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
message(STATUS "Setting build type to '${default_build_type}' as none was specified.")
set(CMAKE_BUILD_TYPE "${default_build_type}" CACHE
STRING "Choose the type of build." FORCE)
endif()
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS
"Debug" "Release" "MinSizeRel" "RelWithDebInfo")
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
#///////////////////////////////////////////////////////////////////#
DEPENDENCIES
#///////////////////////////////////////////////////////////////////#
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
set(CURSES_NEED_NCURSES TRUE)
Try to find ncurses with unicode support first
set(CURSES_NEED_WIDE TRUE)
find_package(Curses QUIET)
if (NOT CURSE_FOUND)
Fallback to regular ncurses library, which may also support unicode!
set(CURSES_NEED_WIDE FALSE)
find_package(Curses REQUIRED)
endif()
add_library(ncurses INTERFACE IMPORTED)
set_property(TARGET ncurses PROPERTY
INTERFACE_INCLUDE_DIRECTORIES ${CURSES_INCLUDE_DIRS})
set_property(TARGET ncurses PROPERTY
INTERFACE_LINK_LIBRARIES ${CURSES_LIBRARIES})
add_compile_definitions(NCURSES_ENABLE_STDBOOL_H=1)
#///////////////////////////////////////////////////////////////////#
COMPILATION OPTIONS
#///////////////////////////////////////////////////////////////////#
Use full RPATH on build tree
set(CMAKE_SKIP_BUILD_RPATH FALSE)
Do not build with install RPATH
set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
Set the RPATH when install
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
Only set RPATH if the installation directory is not a system directory
LIST(FIND
CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_PREFIX}/lib"
isSystemDir)
if("${isSystemDir}" STREQUAL "-1")
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
else()
set(CMAKE_INSTALL_RPATH "")
endif()
if(APPLE)
set(APPLE_SUPPORT_DEFAULT ON)
set(NVIDIA_SUPPORT_DEFAULT OFF)
set(AMDGPU_SUPPORT_DEFAULT OFF)
set(RADEON_SUPPORT_DEFAULT OFF)
set(INTEL_SUPPORT_DEFAULT OFF)
set(MSM_SUPPORT_DEFAULT OFF)
set(PANFROST_SUPPORT_DEFAULT OFF)
set(PANTHOR_SUPPORT_DEFAULT OFF)
set(ASCEND_SUPPORT_DEFAULT OFF)
set(METAX_SUPPORT_DEFAULT OFF)
set(IXML_SUPPORT_DEFAULT OFF)
elseif(ASCEND_SUPPORT)
set(APPLE_SUPPORT_DEFAULT OFF)
set(NVIDIA_SUPPORT_DEFAULT OFF)
set(AMDGPU_SUPPORT_DEFAULT OFF)
set(RADEON_SUPPORT_DEFAULT OFF)
set(INTEL_SUPPORT_DEFAULT OFF)
set(MSM_SUPPORT_DEFAULT OFF)
set(PANFROST_SUPPORT_DEFAULT OFF)
set(PANTHOR_SUPPORT_DEFAULT OFF)
set(ASCEND_SUPPORT_DEFAULT ON)
set(METAX_SUPPORT_DEFAULT OFF)
set(IXML_SUPPORT_DEFAULT OFF)
else()
set(APPLE_SUPPORT_DEFAULT OFF)
set(NVIDIA_SUPPORT_DEFAULT ON)
set(AMDGPU_SUPPORT_DEFAULT ON)
set(RADEON_SUPPORT_DEFAULT ON)
set(INTEL_SUPPORT_DEFAULT ON)
set(V3D_SUPPORT_DEFAULT ON)
set(MSM_SUPPORT_DEFAULT ON)
set(PANFROST_SUPPORT_DEFAULT ON)
set(PANTHOR_SUPPORT_DEFAULT ON)
set(ASCEND_SUPPORT_DEFAULT OFF)
set(METAX_SUPPORT_DEFAULT ON)
set(IXML_SUPPORT_DEFAULT ON)
endif()
TPU and Enflame GCU support is only available on Linux
if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
Check for libtpuinfo.so to set the default for TPU support
find_library(LIBTPUINFO
NAMES libtpuinfo.so
PATHS /usr/lib /usr/lib64 /usr/local/lib /usr/local/lib64
HINTS ${CMAKE_INSTALL_PREFIX}/lib ${CMAKE_INSTALL_PREFIX}/lib64 lib lib64
)
if (NOT LIBTPUINFO)
set(TPU_SUPPORT_DEFAULT OFF)
else()
set(TPU_SUPPORT_DEFAULT ON)
endif()
set(ENFLAME_SUPPORT_DEFAULT ON)
else()
set(TPU_SUPPORT_DEFAULT OFF)
set(ENFLAME_SUPPORT_DEFAULT OFF)
endif()
Rockchip support is only available on Linux on arm
Enable Rockchip support only on ARM Linux
if (CMAKE_SYSTEM_NAME STREQUAL "Linux" AND
(CMAKE_SYSTEM_PROCESSOR MATCHES "armv7" OR CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64"))
set(ROCKCHIP_SUPPORT_DEFAULT ON)
else()
set(ROCKCHIP_SUPPORT_DEFAULT OFF)
endif()
Tenstorrent support is only available on Linux
if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
set(TENSTORRENT_SUPPORT_DEFAULT ON)
else()
set(TENSTORRENT_SUPPORT_DEFAULT OFF)
endif()
option(NVIDIA_SUPPORT "Build support for NVIDIA GPUs through libnvml" ${NVIDIA_SUPPORT_DEFAULT})
option(AMDGPU_SUPPORT "Build support for AMD GPUs through amdgpu driver" ${AMDGPU_SUPPORT_DEFAULT})
option(RADEON_SUPPORT "Build support for ATI/AMD GPUs through radeon driver" ${RADEON_SUPPORT_DEFAULT})
option(INTEL_SUPPORT "Build support for Intel GPUs through i915 or xe driver" ${INTEL_SUPPORT_DEFAULT})
option(MSM_SUPPORT "Build support for Adreno GPUs through msm driver" ${MSM_SUPPORT_DEFAULT})
option(APPLE_SUPPORT "Build support for Apple GPUs through Metal" ${APPLE_SUPPORT_DEFAULT})
option(PANFROST_SUPPORT "Build support for Mali GPUs through panfrost driver" ${PANFROST_SUPPORT_DEFAULT})
option(PANTHOR_SUPPORT "Build support for Mali GPUs through panthor driver" ${PANTHOR_SUPPORT_DEFAULT})
option(ASCEND_SUPPORT "Build support for Ascend NPUs through Ascend DCMI" ${ASCEND_SUPPORT_DEFAULT})
option(V3D_SUPPORT "Build support for Raspberrypi through v3d" ${V3D_SUPPORT_DEFAULT})
option(TPU_SUPPORT "Build support for Google TPUs through GRPC" ${TPU_SUPPORT_DEFAULT})
option(ROCKCHIP_SUPPORT "Enable support for Rockchip NPU" ${ROCKCHIP_SUPPORT_DEFAULT})
option(METAX_SUPPORT "Build support for MetaX GPUs through libmxsml" ${METAX_SUPPORT_DEFAULT})
option(ENFLAME_SUPPORT "Build support for Enflame GCUs through libefml" ${ENFLAME_SUPPORT_DEFAULT})
option(TENSTORRENT_SUPPORT "Build support for Tenstorrent accelerators through tt-kmd" ${TENSTORRENT_SUPPORT_DEFAULT})
option(IXML_SUPPORT "Build support for Iluvatar CoreX GPUs through libixml" ${IXML_SUPPORT_DEFAULT})
add_subdirectory(src)
#///////////////////////////////////////////////////////////////////#
INSTALL
#///////////////////////////////////////////////////////////////////#
string(TIMESTAMP TODAY_MANPAGE "%B %Y")
string(TIMESTAMP TODAY_ISO_8601 "%Y-%m-%d")
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/manpage/nvtop.in"
"${CMAKE_CURRENT_BINARY_DIR}/manpage/nvtop"
IMMEDIATE @ONLY)
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/desktop/nvtop.metainfo.xml.in"
"${CMAKE_CURRENT_BINARY_DIR}/desktop/io.github.syllo.nvtop.metainfo.xml"
IMMEDIATE @ONLY)
install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/manpage/nvtop"
DESTINATION share/man/man1/
PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ
RENAME nvtop.1)
install(FILES
"${CMAKE_CURRENT_SOURCE_DIR}/desktop/nvtop.svg"
DESTINATION share/icons/hicolor/scalable/apps
PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ)
install(FILES
"${CMAKE_CURRENT_SOURCE_DIR}/desktop/nvtop.desktop"
DESTINATION share/applications
PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ)
install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/desktop/io.github.syllo.nvtop.metainfo.xml"
DESTINATION share/metainfo
PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ)
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
IMMEDIATE @ONLY)
add_custom_target(uninstall
COMMAND ${CMAKE_COMMAND} -P
${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)
#///////////////////////////////////////////////////////////////////#
TESTING
#///////////////////////////////////////////////////////////////////#
if (NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
option(BUILD_TESTING "Build tests" OFF)
endif()
include(CTest)
add_subdirectory(tests)
File: AppImage/README.md
Build the AppImage
podman pull ubuntu:18.04
podman run --interactive --tty --rm --volume $PWD:/nvtop ubuntu:24.04
cd nvtop
./AppImage/make_appimage.shFile: snap/snapcraft.yaml
name: nvtop
base: core22
adopt-info: nvtop
summary: 'GPUs monitoring tool for AMD, Intel and NVIDIA'
Nvtop stands for Neat Videocard TOP, a (h)top like task monitor for AMD, Intel and NVIDIA GPUs. It can handle multiple GPUs and print information about them in a htop familiar way.
license: GPL-3.0-or-later
issues: https://github.com/Syllo/nvtop/issues
icon: desktop/nvtop.svg
grade: stable
confinement: strict
architectures:
- build-on: amd64
- build-on: arm64
- build-on: armhf
- build-on: ppc64el
- build-on: s390x
compression: lzo
apps:
nvtop:
command: usr/bin/nvtop
desktop: usr/share/applications/nvtop.desktop
plugs:- opengl
- home
- hardware-observe
- process-control
- system-observe
- kubernetes-support # Temporarily required for nvtop to display AMD GPU processes. Once apparmor rule to allow access to @{PROC}/[0-9]*/fdinfo/ is added to system-observe, this can be removed.
environment:
# The staged terminfo db is not in ncurses' compiled-in search path, so
# point TERMINFO_DIRS at it; ncurses still searches the base snap's
# locations afterwards.
TERMINFO_DIRS: $SNAP/usr/share/terminfo
layout:
/usr/share/libdrm:
symlink: $SNAP/usr/share/libdrm
parts:
ghostty-terminfo:
# Upstream Ghostty publishes only a terminfo generator, not a file, and
# core22's ncurses 6.3 predates the entry. The Ubuntu "ghostty" package
# ships the compiled xterm-ghostty entry; the terminfo payload is
# architecture-independent data, so the amd64 binary package is used for
# every build target.
#
# The terminfo data is MIT-licensed:
# Copyright (c) 2024 Mitchell Hashimoto, Ghostty contributors.
# The license text is installed by the terminfo-licenses part.
plugin: nil
source: http://archive.ubuntu.com/ubuntu/pool/universe/g/ghostty/ghostty_1.3.0~us1-0ubuntu1_amd64.deb
source-type: deb
source-checksum: sha256/5b597b97a13e7fab6e25b2c9c0f713e206c16ff9c629293c3459d1ecac39a2f7
build-packages:
- ncurses-bin
override-build: |
set -eux
terminfo_dir="$CRAFT_PART_INSTALL/usr/share/terminfo"
mkdir -p "$terminfo_dir"
# Decompile with core22's ncurses, then recompile with the same version so
# the entry is in the base's native format and the "ghostty" alias is
# created alongside "xterm-ghostty".
TERMINFO="$CRAFT_PART_SRC/usr/share/terminfo"
infocmp -x -1 xterm-ghostty > ghostty.terminfo
tic -x -o "$terminfo_dir" ghostty.terminfo
wezterm-terminfo:
# WezTerm publishes its terminfo as a plain source file; pin the commit and
# let the build verify the checksum.
#
# termwiz/data/wezterm.terminfo, last changed 2025-05-03 ("Advertize the Su
# capability too"). The newest tagged release predates that commit, so pin
# the commit rather than the tag.
#
# The terminfo data is MIT-licensed:
# Copyright (c) 2018-Present Wez Furlong.
# The license text is installed by the terminfo-licenses part.
plugin: nil
source: https://raw.githubusercontent.com/wezterm/wezterm/52c3515037518b826f32609179383948217d5a33/termwiz/data/wezterm.terminfo
source-type: file
source-checksum: sha256/5e386fb149b2a16b71b4d9a373c54737c9e5694eb67fe38d93b24705b93437ed
build-packages:
- ncurses-bin
override-build: |
set -eux
terminfo_dir="$CRAFT_PART_INSTALL/usr/share/terminfo"
mkdir -p "$terminfo_dir"
tic -x -o "$terminfo_dir" wezterm.terminfo
terminfo-licenses:
# MIT license texts for the bundled third-party terminfo entries. The MIT
# license asks that the copyright and permission notice be included with
# copies, so they are installed into the snap under usr/share/doc.
#
# ghostty.txt matches Ghostty's LICENSE at the packaged version (1.3.0);
# wezterm.txt matches LICENSE.md at the pinned WezTerm commit above.
plugin: nil
source: snap/local/licenses
override-build: |
set -eux
install -Dm644 ghostty.txt
"$CRAFT_PART_INSTALL/usr/share/doc/ghostty-terminfo/copyright"
install -Dm644 wezterm.txt
"$CRAFT_PART_INSTALL/usr/share/doc/wezterm-terminfo/copyright"
libdrm:
source: https://gitlab.freedesktop.org/mesa/drm.git
source-tag: libdrm-2.4.113
plugin: meson
meson-parameters:
- --prefix=/usr
- --sysconfdir=/etc
- --libdir=lib/$CRAFT_ARCH_TRIPLET
- -Dradeon=enabled
- -Damdgpu=enabled
- -Dudev=true
- -Dnouveau=enabled
- -Dintel=enabled
build-packages:
- meson
- pkg-config
- libudev-dev
- libpciaccess-dev
stage-packages:
- libpciaccess0
prime:
- -usr/include
- -usr/lib/$CRAFT_ARCH_TRIPLET/pkgconfig
nvtop:
after: [ libdrm ]
source: .
plugin: cmake
cmake-parameters:
- -DCMAKE_INSTALL_PREFIX=/usr
- -DNVIDIA_SUPPORT=ON
- -DAMDGPU_SUPPORT=ON
- -DINTEL_SUPPORT=ON
override-pull: |
set -eux
craftctl default
VERSION="$(git describe --tags $(git rev-list --tags --max-count=1))"
craftctl set version=$VERSION
git checkout $VERSION
build-snaps:
- cmake
build-packages:
- gcc
- libncurses-dev
- libsystemd-dev
stage-packages:
- libncurses6
- libncursesw6
- libsystemd0
- ncurses-base
- ncurses-term
- kitty-terminfo
- foot-terminfo
prime:
- -usr/share/doc
File: snap/local/licenses/ghostty.txt
MIT License
Copyright (c) 2024 Mitchell Hashimoto, Ghostty contributors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
File: snap/local/licenses/wezterm.txt
MIT License
Copyright (c) 2018-Present Wez Furlong
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
File: src/CMakeLists.txt
include(CheckCSourceCompiles)
configure_file(
"${PROJECT_SOURCE_DIR}/include/nvtop/version.h.in"
"${PROJECT_BINARY_DIR}/include/nvtop/version.h"
IMMEDIATE @ONLY)
add_executable(nvtop
nvtop.c
interface.c
interface_layout_selection.c
interface_options.c
interface_setup_win.c
interface_ring_buffer.c
extract_gpuinfo.c
pcie_utilization.c
time.c
plot.c
ini.c
)
check_c_source_compiles(
"
#include <stdlib.h>
int main() {
int *buf = NULL;
buf = reallocarray(buf, 15, sizeof(*buf));
return EXIT_SUCCESS;
}
"
HAS_REALLOCARRAY
)
if(HAS_REALLOCARRAY)
target_compile_definitions(nvtop PRIVATE HAS_REALLOCARRAY)
endif()
find_package(UDev)
find_package(Systemd)
option(USE_LIBUDEV_OVER_LIBSYSTEMD "Use libudev, even if libsystemd is present" OFF)
if(UNIX AND NOT APPLE)
target_sources(nvtop PRIVATE
get_process_info_linux.c
extract_processinfo_fdinfo.c
info_messages_linux.c)
elseif(APPLE)
target_sources(nvtop PRIVATE
get_process_info_mac.c
extract_processinfo_mac.c
info_messages_mac.c)
endif()
if(NVIDIA_SUPPORT)
target_sources(nvtop PRIVATE extract_gpuinfo_nvidia.c)
else()
target_sources(nvtop PRIVATE nvlink_nvidia_disabled.c)
endif()
if(ASCEND_SUPPORT)
target_sources(nvtop PRIVATE extract_gpuinfo_ascend.c)
find_package(Threads REQUIRED)
set(ASCEND_ROOT "" CACHE PATH "Ascend toolkit/driver root (for example /usr/local/Ascend)")
set(ASCEND_DCMI_HINTS
"/usr/local/Ascend/driver/lib64/driver"
"/usr/local/Ascend/driver/lib64"
"/usr/local/Ascend/lib64")
if(ASCEND_ROOT)
list(PREPEND ASCEND_DCMI_HINTS
"${ASCEND_ROOT}/driver/lib64/driver"
"${ASCEND_ROOT}/driver/lib64"
"${ASCEND_ROOT}/lib64")
endif()
find_library(DCMI_LIBRARY
NAMES dcmi
HINTS ${ASCEND_DCMI_HINTS}
PATH_SUFFIXES driver lib64)
if(NOT DCMI_LIBRARY)
message(FATAL_ERROR "Ascend support enabled, but libdcmi.so was not found. Set ASCEND_ROOT to the Ascend installation root.")
endif()
message(STATUS "Found Ascend DCMI: ${DCMI_LIBRARY}")
target_link_libraries(nvtop PRIVATE "${DCMI_LIBRARY}" Threads::Threads)
endif()
if(AMDGPU_SUPPORT OR RADEON_SUPPORT OR INTEL_SUPPORT OR V3D_SUPPORT)
if((SYSTEMD_FOUND AND UDEV_FOUND AND USE_LIBUDEV_OVER_LIBSYSTEMD) OR(NOT SYSTEMD_FOUND AND UDEV_FOUND))
target_compile_definitions(nvtop PRIVATE USING_LIBUDEV)
target_link_libraries(nvtop PRIVATE udev)
elseif(SYSTEMD_FOUND)
target_compile_definitions(nvtop PRIVATE USING_LIBSYSTEMD)
target_link_libraries(nvtop PRIVATE systemd)
else()
message(FATAL_ERROR "Neither libsystemd nor libudev were found; These are required for AMDGPU, INTEL and V3D support")
endif()
target_sources(nvtop PRIVATE device_discovery_linux.c)
endif()
if(AMDGPU_SUPPORT OR RADEON_SUPPORT OR INTEL_SUPPORT OR MSM_SUPPORT OR PANFROST_SUPPORT OR PANTHOR_SUPPORT)
Search for libdrm for AMDGPU and radeon support
find_package(Libdrm)
if(Libdrm_FOUND)
message(STATUS "Found libdrm; Enabling support")
target_include_directories(nvtop PRIVATE ${Libdrm_INCLUDE_DIRS})
else()
message(FATAL_ERROR "libdrm not found; This library is required for AMDGPU, INTEL, MSM, PANFROST and PANTHOR support")
# CMake will exit if libdrm is not found
endif()
endif()
if (AMDGPU_SUPPORT)
target_sources(nvtop PRIVATE extract_gpuinfo_amdgpu.c)
target_sources(nvtop PRIVATE extract_gpuinfo_amdgpu_utils.c)
endif()
if (RADEON_SUPPORT)
target_sources(nvtop PRIVATE extract_gpuinfo_radeon.c)
endif()
if (MSM_SUPPORT)
target_sources(nvtop PRIVATE extract_gpuinfo_msm.c)
target_sources(nvtop PRIVATE extract_gpuinfo_msm_utils.c)
pkg_check_modules(NPUPERF qcnpuperf)
if (NPUPERF_FOUND)
target_include_directories(nvtop
PRIVATE
${NPUPERF_INCLUDE_DIRS}
)
target_link_libraries(nvtop
PRIVATE
${NPUPERF_LIBRARIES}
)
target_sources(nvtop PRIVATE extract_npuinfo_qualcomm.c) else()
message(STATUS "libqcnpuperf not found: Qualcomm NPU monitoring disabled")
endif()
endif()
if(INTEL_SUPPORT)
target_sources(nvtop PRIVATE extract_gpuinfo_intel.c)
target_sources(nvtop PRIVATE extract_gpuinfo_intel_i915.c)
target_sources(nvtop PRIVATE extract_gpuinfo_intel_xe.c)
endif()
if(V3D_SUPPORT)
target_sources(nvtop PRIVATE extract_gpuinfo_v3d.c)
target_sources(nvtop PRIVATE extract_gpuinfo_v3d_utils.c)
endif()
if(APPLE_SUPPORT)
target_sources(nvtop PRIVATE extract_gpuinfo_apple.m)
target_link_libraries(nvtop PRIVATE
"-framework Metal"
"-framework AppKit"
"-framework Foundation"
"-framework QuartzCore"
"-framework IOKit")
endif()
if (PANFROST_SUPPORT)
target_sources(nvtop PRIVATE extract_gpuinfo_panfrost.c)
target_sources(nvtop PRIVATE extract_gpuinfo_panfrost_utils.c)
endif()
if (PANTHOR_SUPPORT)
target_sources(nvtop PRIVATE extract_gpuinfo_panthor.c)
target_sources(nvtop PRIVATE extract_gpuinfo_panthor_utils.c)
endif()
if ((PANFROST_SUPPORT) OR (PANTHOR_SUPPORT))
target_sources(nvtop PRIVATE extract_gpuinfo_mali_common.c)
endif()
if(TPU_SUPPORT)
find_library(LIBTPUINFO
NAMES libtpuinfo.so
PATHS /usr/lib /usr/lib64 /usr/local/lib /usr/local/lib64
HINTS ${CMAKE_INSTALL_PREFIX}/lib ${CMAKE_INSTALL_PREFIX}/lib64 lib lib64
)
if (NOT LIBTPUINFO)
message(WARNING "TPU Support enabled, but libtpuinfo.so not found in ldconfig path, we will not be able to read TPU usage")
set(TPU_SUPPORT_DEFAULT OFF)
endif()
target_sources(nvtop PRIVATE extract_gpuinfo_tpu.c)
endif()
if(ROCKCHIP_SUPPORT)
message(STATUS "Building with Rockchip NPU support")
target_sources(nvtop PRIVATE extract_npuinfo_rockchip.c)
endif()
if(METAX_SUPPORT)
target_sources(nvtop PRIVATE extract_gpuinfo_metax.c)
endif()
if(ENFLAME_SUPPORT)
message(STATUS "Building with Enflame GCU support")
target_sources(nvtop PRIVATE extract_gcuinfo_enflame.c)
endif()
if(TENSTORRENT_SUPPORT)
target_sources(nvtop PRIVATE extract_gpuinfo_tenstorrent.c)
endif()
if(IXML_SUPPORT)
message(STATUS "Building with Iluvatar CoreX GPU support")
target_sources(nvtop PRIVATE extract_gpuinfo_ixml.c)
endif()
target_include_directories(nvtop PRIVATE
${PROJECT_SOURCE_DIR}/include
${PROJECT_BINARY_DIR}/include)
find_package(Sanitizers)
add_sanitizers(nvtop)
set_property(TARGET nvtop PROPERTY C_STANDARD 11)
target_compile_definitions(nvtop PRIVATE _GNU_SOURCE)
target_link_libraries(nvtop
PRIVATE ncurses m ${CMAKE_DL_LIBS})
install(TARGETS nvtop
RUNTIME DESTINATION bin)
include(compile-flags-helpers)
include(${PROJECT_SOURCE_DIR}/cmake/optimization_flags.cmake)
add_compiler_option_to_target_type(nvtop Debug PRIVATE ${ADDITIONAL_DEBUG_COMPILE_OPTIONS})
add_linker_option_to_all_but_target_type(nvtop dummy PRIVATE ${ADDITIONAL_RELEASE_LINK_OPTIONS})
File: tests/CMakeLists.txt
find_package(GTest)
if (BUILD_TESTING AND GTest_FOUND)
option(THOROUGH_TESTING "Enable extensive testing (takes hours, e.g., use once per release)" OFF)
Create a library for testing
add_library(testLib
${PROJECT_SOURCE_DIR}/src/interface_layout_selection.c
${PROJECT_SOURCE_DIR}/src/extract_processinfo_fdinfo.c
${PROJECT_SOURCE_DIR}/src/interface_options.c
${PROJECT_SOURCE_DIR}/src/pcie_utilization.c
${PROJECT_SOURCE_DIR}/src/ini.c
)
target_include_directories(testLib PUBLIC
${PROJECT_SOURCE_DIR}/include
${PROJECT_BINARY_DIR}/include)
Tests
add_executable(
interfaceTests
interfaceTests.cpp
)
target_link_libraries(interfaceTests PRIVATE testLib GTest::gtest_main)
gtest_discover_tests(interfaceTests)
if (THOROUGH_TESTING)
target_compile_definitions(interfaceTests PRIVATE THOROUGH_TESTING)
endif()
endif()
File: .github/workflows/compile.yml
name: Compile Ubuntu
on:
- push
- pull_request
jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, ubuntu-24.04, ubuntu-22.04]
env:
BUILD_DIR: build
DEBIAN_FRONTEND: noninteractive
steps:
- uses: actions/checkout@v4
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y libncurses5-dev libncursesw5-dev libdrm-dev libsystemd-dev
- name: Configure CMake
run: cmake -S . -B $BUILD_DIR
- name: Build
run: cmake --build $BUILD_DIR
- name: Install
run: DESTDIR="$PWD/build/install" cmake --build $BUILD_DIR --target install
- name: Upload
uses: actions/upload-artifact@v4
with:
name: nvtop ${{ matrix.os }}
path: ${{ env.BUILD_DIR }}/install