Initialization and Cleanup#

NVML Methods that handle the NVML Library initialization and cleanup.

This chapter describes the methods that handle NVML initialization and cleanup. It is the user’s responsibility to call nvmlInit_v2() before calling any other methods, and nvmlShutdown() once NVML is no longer being used.

Macros#

NVML_INIT_FLAG_FORCE_INIT

Force device initialization even when a previous nvmlInit was called with the NO_GPUS and NO_ATTACH flags.

NVML_INIT_FLAG_NO_ATTACH

Initialize the NVML Library without attaching any discovered devices.

NVML_INIT_FLAG_NO_GPUS

Initialize the NVML Library even when no devices are found.

Functions#

nvmlReturn_t nvmlInitWithFlags(unsigned int flags)

Initialize the NVML Library lazily, without allocating any device state, with additional init flags.

nvmlReturn_t nvmlInit_v2(void)

Initialize the NVML Library lazily, without allocating any device state.

nvmlReturn_t nvmlShutdown(void)

Shut down and cleanup NVML Library state.

Macros#

NVML_INIT_FLAG_FORCE_INIT#

Force device initialization even when a previous nvmlInit was called with the NO_GPUS and NO_ATTACH flags.

NVML_INIT_FLAG_NO_ATTACH#

Initialize the NVML Library without attaching any discovered devices.

NVML_INIT_FLAG_NO_GPUS#

Initialize the NVML Library even when no devices are found.

Functions#

nvmlReturn_t nvmlInitWithFlags(unsigned int flags)#

Initialize the NVML Library lazily, without allocating any device state, with additional init flags.

A variant of nvmlInit_v2(), this will initialize the NVML Library state without enumerating any discovered devices. An option to pass in additional flags is provided to modify the behavior of NVML Library init. The usage of these flags can be obtained from NVML_INIT_FLAG_*. These flags can be combined together.

Other than the “flags” parameter, this method is completely identical to nvmlInit_v2().

For all products.

See also

nvmlShutdown()

Note

A reference count of the number of initializations is maintained, and a corresponding call to nvmlShutdown() needs to be issued once usage of the NVML Library is complete. Shutdown will only occur after the reference count reaches zero.

Parameters:

flags[in] NVML_INIT_FLAG_* flags that can modify NVML Init behavior.

Returns:

nvmlReturn_t nvmlInit_v2(void)#

Initialize the NVML Library lazily, without allocating any device state.

This will initialize the NVML Library state without enumerating any discovered devices. This will allow NVML to communicate with a device, even if other devices are in an unstable or bad state. Enumeration of a device can be done by obtaining the device handle via the nvmlDeviceGetHandleBy* class of APIs.

This method needs to be called once before any usage of NVML Library APIs.

For all products.

See also

nvmlShutdown()

Note

A reference count of the number of initializations is maintained, and a corresponding call to nvmlShutdown() needs to be issued once usage of the NVML Library is complete. Shutdown will only occur after the reference count reaches zero.

Returns:

nvmlReturn_t nvmlShutdown(void)#

Shut down and cleanup NVML Library state.

This will shut down and cleanup NVML Library state by releasing all device and library resources previously allocated with nvmlInit_v2() or nvmlInitWithFlags(). This should be called after all NVML work is done, and once for each call to nvmlInit_v2() or nvmlInitWithFlags().

Complete shutdown will only occur when the reference count of all prior NVML initializations reaches zero. No error will be reported if this is called more times than nvmlInit_v2() or nvmlInitWithFlags().

For all products.

Returns: