Package: gpulink
gpulinkA library and command-line tool for monitoring NVIDIA GPU stats.gpulinkusespynvml- a Python wrapper for
theNVIDIA Management Library(NVML).Current status⚠ gpulink is in a very early state - breaking changes between versions are possible!Requirementsgpulinkrequires the NVIDIA Management Library to be installed which is shipped together
withnvidia-smi.InstallationInstallation using PIPTo installgpulinkusing the Python Package Manager (PIP) run:pip install gpulinkUsing from sourcegpulinkcan also be used from source. For this, perform the following steps to create a Python environment and to
install the requirements:Create an environment:python -m venv envActivate the environment:.\env\Scripts\ActivateInstall requirements:pip install -r requirements.txtCommand-line usagegpulinkcan either be imported as a library or can be used from the command line:Usage: GPU-Link: Monitor NVIDIA GPUs [OPTIONS] COMMAND [ARGS]...

Options:
  --version  Show the version and exit.
  --help     Show this message and exit.

Commands:
  record   Record GPU properties.
  sensors  Fetch and print the GPU sensor status.ExamplesView GPU sensor status:gpulink sensorsWatch GPU sensor status:gpulink sensors -wRecord the memory usage over time, generate a plot and save it as a png image:gpulink record -o memory.png memoryLibrary usagegpulinkcan be easily used within applications. Just importgpulinkand create aDeviceCtx. This context manages
device access and provides an API for fetching GPU properties
(seeAPI example):importgpulinkasgpuwithgpu.DeviceCtx()asctx:print(f"Available GPUs:{ctx.gpus.names}")memory_information=ctx.get_memory_info(gpus=ctx.gpus.ids)Recording datagpulinkprovides aRecorderclass
for recording GPU properties. For simple instantiation use one of the provided factory methods, e.g.:recorder=gpu.Recorder.create_memory_recorder(ctx,ctx.gpus.ids)Afterwards a recording can be performed:Option 1: Usingstartandstopmethod (seeBasic example)recorder.start()...# Do some GPU stuffrecorder.stop(auto_join=True)Option 2: Using a context manager (seeContext-Manager example)withrecorder:...# Do some GPU stuffOption 3: Using a decorator (seeDecorator example)@record(factory=gpu.Recorder.create_memory_recorder)defmy_gpu_function():...# Do dome GPU stuffmy_gpu_function()Once a recording is finished its data can be accessed:recording=recording=recorder.get_recording()Plotting datagpulinkprovides aPlotclass for
visualizing recordings usingmatplotlib:frompathlibimportPath# Generate the plotplot=gpu.Plot(recording)# Display the plotplot.plot()# Save the plot as an imageplot.save(Path("memory.png"))# The generated Figure and Axis can also be accessed directlyfigure,axis=plot.generate_graph()Unit testingWhen usinggpulinkinside unit tests, create or use an already existing device mock,
e.g.DeviceMock.
To create a custom mock class just derive it from
theBaseDevice. Then during
creating
aDeviceCtxprovide the mock as follows:importgpulinkasgpuwithgpu.DeviceCtx(device=DeviceMock)asctx:...TroubleshootingIf you get the error message below, please ensure that the NVIDIA Management Library is installed on you system by
typingnvidia-smi --versioninto a terminal:pynvml.nvml.NVMLError_LibraryNotFound: NVML Shared Library Not Found.Planned featuresLive-plotting of GPU statsChangelog0.4.0Recording arbitrary GPU stats (clock, fan-speed, memory, power-usage, temp)Display GPU name and power usage withinsensorscommandReplacedarparselibrary byclickAborting awatchorrecordingcommand can be done by pressing any key instead ofctrl+c0.4.1Fix error when callingnvmlDeviceGetNameinpynvmlversion11.5.00.5.0Add context-manager-based recordingAdd decorator-based recording0.6.0Remove PlotOptions classFix imports and update unit tests