nvmlUnitGetHandleByIndex

Example codes are really sparse for the nvml API.

nvmlReturn_t nvmlUnitGetHandleByIndex (unsigned int
index, nvmlUnit_t *unit)
Parameters
index
The index of the target unit, >= 0 and < unitCount
unit
Reference in which to return the unit handle
Returns
‣ NVML_SUCCESS if unit has been set
‣ NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized
‣ NVML_ERROR_INVALID_ARGUMENT if index is invalid or unit is NULL
‣ NVML_ERROR_UNKNOWN on any unexpected error

Code snippet:

#include <nvml.h>

    nvmlReturn_t result;
    unsigned int temp;
    nvmlDevice_t device;

    result = nvmlInit();
    nvmlUnit_t unit;
    unsigned int myint;
    result = nvmlUnitGetHandleByIndex(0, &unit);

Is kicking NVML_ERROR_INVALID_ARGUMENT…

I found that I had to set CMAKE with:
target_link_libraries(04_nvml_testing “/usr/lib/x86_64-linux-gnu/libnvidia-ml.so”)

Before it could even do any nvml calls at all…

The reason is I am looking to make a manager set of C functions that will slow the GPU clock down as some of the algorithims I am running will burn out the PCI bus, so I am looking for some GPU speed auto adjusters, and logging management.