4.11. 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.
Defines
- #define NVML_INIT_FLAG_NO_ATTACH 2
- Don't attach GPUs.
- #define NVML_INIT_FLAG_NO_GPUS 1
- Don't fail nvmlInit() when no GPUs are found.
Functions
- nvmlReturn_t nvmlInitWithFlags ( unsigned int flags )
- nvmlReturn_t nvmlInit_v2 ( void )
- nvmlReturn_t nvmlShutdown ( void )
Functions
- nvmlReturn_t nvmlInitWithFlags ( unsigned int flags )
-
Parameters
- flags
- behaviour modifier flags
Returns
- NVML_SUCCESS if NVML has been properly initialized
- NVML_ERROR_DRIVER_NOT_LOADED if NVIDIA driver is not running
- NVML_ERROR_NO_PERMISSION if NVML does not have permission to talk to the driver
- NVML_ERROR_UNKNOWN on any unexpected error
Description
nvmlInitWithFlags is a variant of nvmlInit(), that allows passing a set of boolean values modifying the behaviour of nvmlInit(). Other than the "flags" parameter it is completely similar to nvmlInit_v2.
For all products.
- nvmlReturn_t nvmlInit_v2 ( void )
-
Returns
- NVML_SUCCESS if NVML has been properly initialized
- NVML_ERROR_DRIVER_NOT_LOADED if NVIDIA driver is not running
- NVML_ERROR_NO_PERMISSION if NVML does not have permission to talk to the driver
- NVML_ERROR_UNKNOWN on any unexpected error
Description
Initialize NVML, but don't initialize any GPUs yet.
Note:-
nvmlInit_v3 introduces a "flags" argument, that allows passing boolean values modifying the behaviour of nvmlInit().
-
In NVML 5.319 new nvmlInit_v2 has replaced nvmlInit"_v1" (default in NVML 4.304 and older) that did initialize all GPU devices in the system.
This allows NVML to communicate with a GPU when other GPUs in the system are unstable or in a bad state. When using this API, GPUs are discovered and initialized in nvmlDeviceGetHandleBy* functions instead.
Note:To contrast nvmlInit_v2 with nvmlInit"_v1", NVML 4.304 nvmlInit"_v1" will fail when any detected GPU is in a bad or unstable state.
For all products.
This method, should be called once before invoking any other methods in the library. A reference count of the number of initializations is maintained. Shutdown only occurs when the reference count reaches zero.
- nvmlReturn_t nvmlShutdown ( void )
-
Returns
- NVML_SUCCESS if NVML has been properly shut down
- NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized
- NVML_ERROR_UNKNOWN on any unexpected error
Description
Shut down NVML by releasing all GPU resources previously allocated with nvmlInit_v2().
For all products.
This method should be called after NVML work is done, once for each call to nvmlInit_v2() A reference count of the number of initializations is maintained. Shutdown only occurs when the reference count reaches zero. For backwards compatibility, no error is reported if nvmlShutdown() is called more times than nvmlInit().