Skip to content

User utility along with non-privileged user installation script #134

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
172 changes: 37 additions & 135 deletions README.markdown
Original file line number Diff line number Diff line change
@@ -1,175 +1,77 @@
NVTOP
NVTOP-Local
=====

What is this repository about?
-----------------

This repository provides the packed nvtop along with its dependency (`ncurses 6.3`) and the installation script for non-privileged users.


Moreover, I added the user utility so that the user could specify the users to monitor. For detail, please refer to the following content.

Note that this repo doesn't provide the *NVML* and the CUDA driver as both require root access.


What is NVTOP?
--------------

Nvtop stands for NVidia TOP, a (h)top like task monitor for NVIDIA GPUs. It can
handle multiple GPUs and print information about them in a htop familiar way.

Because a picture is worth a thousand words:
For detailed introduction, please refer to the original [site](https://github.com/Syllo/nvtop/blob/master/README.markdown)

![NVTOP interface](/screenshot/NVTOP_ex1.png)

Table of Contents
-----------------

- [NVTOP Options and Interactive Commands](#nvtop-options-and-interactive-commands)
- [Interactive Setup Window](#interactive-setup-window)
- [Saving Preferences](#saving-preferences)
- [NVTOP Manual and Command line Options](#nvtop-manual-and-command-line-options)
- [GPU Support](#gpu-support)
- [Build](#build)
- [Distribution Specific Installation Process](#distribution-specific-installation-process)
- [Ubuntu / Debian](#ubuntu--debian)
- [Ubuntu disco (19.04) / Debian buster (stable)](#ubuntu-disco-1904--debian-buster-stable)
- [Fedora / RedHat / CentOS](#fedora--redhat--centos)
- [OpenSUSE](#opensuse)
- [Arch Linux](#arch-linux)
- [Docker](#docker)
- [NVTOP Build](#nvtop-build)
- [Troubleshoot](#troubleshoot)
- [Installation](#installation)
- [Function](#function)
- [License](#license)

NVTOP Options and Interactive Commands
--------------------------------------
### Interactive Setup Window

NVTOP has a builtin setup utility that provides a way to specialize the interface to your needs.
Simply press ``F2`` and select the options that are the best for you.

![NVTOP Setup Window](/screenshot/Nvtop-config.png)

### Saving Preferences

You can save the preferences set in the setup window by pressing ``F12``.
The preferences will be loaded the next time you run ``nvtop``.

### NVTOP Manual and Command line Options

NVTOP comes with a manpage!
```bash
man nvtop
```
For quick command line arguments help
```bash
nvtop -h
nvtop --help
```

GPU Support
-----------

The *NVML library* does not support some of the queries for GPUs coming before the
Kepler microarchitecture. Anything starting at GeForce 600, GeForce 800M and
successor should work fine. For more information about supported GPUs please
take a look at the [NVML documentation](http://docs.nvidia.com/deploy/nvml-api/nvml-api-reference.html#nvml-api-reference).

Build
-----

Two libraries are required in order for NVTOP to display GPU information:

* The *NVIDIA Management Library* (*NVML*) which comes with the GPU driver.
* This queries the GPU for information.
* Ask the administrator if you do not have it installed nor do you have privileged access.
* The *ncurses* library driving the user interface.
* This makes the screen look beautiful.
* Provided in this repository.

## Distribution Specific Installation Process

### Ubuntu / Debian

#### Ubuntu disco (19.04) / Debian buster (stable)

- ```bash
sudo apt install nvtop
```

#### Older

- NVIDIA drivers (see [Ubuntu Wiki](https://help.ubuntu.com/community/BinaryDriverHowto/Nvidia) or [Ubuntu PPA](https://launchpad.net/~graphics-drivers/+archive/ubuntu/ppa) or [Debian Wiki](https://wiki.debian.org/NvidiaGraphicsDrivers#NVIDIA_Proprietary_Driver))
- CMake, ncurses and git
```bash
sudo apt install cmake libncurses5-dev libncursesw5-dev git
```
- NVTOP
- Follow the [NVTOP Build](#nvtop-build)

### Fedora / RedHat / CentOS

- NVIDIA drivers, **CUDA required for nvml libraries** (see [RPM Fusion](https://rpmfusion.org/Howto/NVIDIA))
- CMake, ncurses and git
```bash
sudo dnf install cmake ncurses-devel git
```
- NVTOP
- Follow the [NVTOP Build](#nvtop-build)

### OpenSUSE

- NVIDIA drivers (see [SUSE Support Database](https://en.opensuse.org/SDB:NVIDIA_drivers))
- CMake, ncurses and git
```bash
sudo zypper install cmake ncurses-devel git
```
- NVTOP
- Follow the [NVTOP Build](#nvtop-build)

### Arch Linux

- ```bash
sudo pacman -S nvtop
```

### Gentoo

- ```bash
sudo layman -a guru && sudo emerge -av nvtop
```

### Docker

- NVIDIA drivers (same as above)

- [nvidia-docker](https://github.com/NVIDIA/nvidia-docker) (See [Container Toolkit Installation Guide](https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/install-guide.html#docker))

- ```bash
git clone https://github.com/Syllo/nvtop.git && cd nvtop
sudo docker build --tag nvtop .
sudo docker run -it --rm --runtime=nvidia --gpus=all --pid=host nvtop
```

## NVTOP Build
## Installation

To install under the home directory (`$HOME/bin`), simply run
```bash
git clone https://github.com/Syllo/nvtop.git
mkdir -p nvtop/build && cd nvtop/build
cmake ..
make
bash install.sh
```

# Install globally on the system
sudo make install
As some workstations may require the users to move their exectuables to specific location (such as `/tmp2`), you could specify the path where you want to install by
```bash
bash install.sh $PATH_TO_INSTALLATION
```

# Alternatively, install without privileges at a location of your choosing
# make DESTDIR="/your/install/path" install
After running the script, remember to add the path to the `PATH` environment variable. For example,
```bash
echo export PATH=/tmp2/`whoami`/bin:$PATH >> ~/.zshrc
source ~/.zshrc
```

If you use **conda** as environment manager and encounter an error while building nvtop, try `conda deactivate` before invoking `cmake`.

The build system supports multiple build type (e.g. -DCMAKE_BUILD_TYPE=RelWithDebInfo):

* Release: Binary without debug information
* RelWithDebInfo: Binary with debug information
* Debug: Compile with warning flags and address/undefined sanitizers enabled (for development purposes)
Function
-------
## User selection

Troubleshoot
------------
In the terminal, one could select the user by `-u` or `--user` and provide the username in a colon-separated manner. For example,
```bash
nvtop -u ntuser:ubuntu_user:arch_user
```
If the argument following `-u` or `--user` is not provided, the user to be monitored will be set to the current user only by default.

- The plot looks bad:
- Verify that you installed the wide character version of the NCurses library (libncurses**w**5-dev for Debian / Ubuntu), clean the build directory
and restart the build process.
- **Putty**: Tell putty not to lie about its capabilities (`$TERM`) by setting the field ``Terminal-type string`` to ``putty`` in the menu
``Connection > Data > Terminal Details``.

License
-------
Expand Down
2 changes: 1 addition & 1 deletion include/nvtop/extract_gpuinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ bool gpuinfo_populate_static_infos(unsigned device_count, gpu_info *devices);

bool gpuinfo_refresh_dynamic_info(unsigned device_count, gpu_info *devices);

bool gpuinfo_refresh_processes(unsigned device_count, gpu_info *devices);
bool gpuinfo_refresh_processes(unsigned device_count, user *users, gpu_info *devices);

void gpuinfo_clean(unsigned device_count, gpu_info *devices);

Expand Down
9 changes: 9 additions & 0 deletions include/nvtop/extract_gpuinfo_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <limits.h>
#include <stdlib.h>
#include <sys/types.h>
#include <uthash.h>

#define IS_VALID(x, y) ((y)[(x) / CHAR_BIT] & (1 << ((x) % CHAR_BIT)))
#define SET_VALID(x, y) ((y)[(x) / CHAR_BIT] |= (1 << ((x) % CHAR_BIT)))
Expand All @@ -41,6 +42,7 @@ enum gpuinfo_static_info_valid {

#define MAX_DEVICE_NAME 128


typedef struct gpuinfo_static_info_struct {
char device_name[MAX_DEVICE_NAME];
unsigned max_pcie_gen;
Expand Down Expand Up @@ -133,4 +135,11 @@ typedef struct gpu_process_struct {
unsigned char valid[gpuinfo_process_info_count / CHAR_BIT + 1];
} gpu_process;


typedef struct {
char name[128];
int id;
UT_hash_handle hh;
} user;

#endif // EXTRACT_GPUINFO_COMMON_H__
2 changes: 1 addition & 1 deletion include/nvtop/extract_gpuinfo_nvidia.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,6 @@ void gpuinfo_nvidia_refresh_dynamic_info(gpuinfo_nvidia_device_handle device,

void gpuinfo_nvidia_get_running_processes(
gpuinfo_nvidia_device_handle device, gpuinfo_nvidia_internal_data *internal,
unsigned *num_processes_recovered, gpu_process **processes_info);
unsigned *num_processes_recovered, gpu_process **processes_info, user *users);

#endif // EXTRACT_GPUINFO_NVIDIA_H_
1 change: 1 addition & 0 deletions include/nvtop/get_process_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ struct process_cpu_usage {
nvtop_time timestamp;
};

#define MAX_USER_NAME 128
void get_username_from_pid(pid_t pid, char **buffer);

void get_command_from_pid(pid_t pid, char **buffer);
Expand Down
2 changes: 2 additions & 0 deletions include/nvtop/version.h.in

Large diffs are not rendered by default.

42 changes: 42 additions & 0 deletions install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/bin/bash
doc="Usage: $0 prefix\n\tprefix: Path to directory you want to install nvtop and ncurses, default is \$HOME/bin"
reminder="Remember to add $path to PATH to your shell configuration file. For example,\n (1) echo export PATH=$path:\$PATH >> ~/.bashrc, if you are using bash.\n (2) echo export PATH=$path:\$PATH >> ~/.zshrc, if you are using zsh.\nYou could either reopen the shell afterwards, or simple use\n\tsource ~/\$PATH_TO_SH_CONFIG"
# test if -h or --help is present
for i in "$@"; do
if [[ $i == "-h" || $i == "--help" ]]; then
echo -e $doc
exit 1
fi
done

path=$HOME/.bin
home=`pwd`

if [ $# -gt 0 ]; then
path=$1
fi

if [ -f $path ]; then
echo $path exists. Please specify another path.
exit
fi

mkdir -p $path

if [ ! -d $path/ncurses ]; then
cd ./ncurses-6.3
./configure --prefix=$path/ncurses
make && make install
ln -s $path/ncurses/include/ncurses/ncurses.h $path/ncurses/include/ncurses.h
fi

cd $home
mkdir build && cd build
cmake -D CURSES_LIBRARY=$path/ncurses/lib/libncurses.a -D CURSES_INCLUDE_PATH=$path/ncurses/include ..
make
make DESTDIR=$path install

mv $path/usr/local/bin/nvtop $path
echo -e $reminder


5 changes: 5 additions & 0 deletions manpage/nvtop.in
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ nvtop \- NVIDIA GPU top
.B nvtop
\fR[\fB\-hv\fR]
\fR[\fB\-si\fR \fIid1:id2:...\fR]
\fR[\fB\-u\fR \fIname1:name2:...\fR]
\fR[\fB\-d\fR \fIdelay\fR]

.SH DESCRIPTION
Expand All @@ -29,6 +30,10 @@ Colon separated list of GPU IDs to be monitored by nvtop.
.BR \-i ", " \-\-gpu\-ignore =\fIid1:...\fR
Colon separated list of GPU IDs to be ignored by nvtop.
.TP
.BR \-u ", " \-\-user =\fIusername1:...\fR
Colon separated list of usernames to be ignored by nvtop.
Default, current user.
.TP
.BR \-C ", " \-\-no\-color
Monochrome mode.
.TP
Expand Down
Loading