void free_gpu(const gmx_device_info_t *deviceInfo)
{
+ // One should only attempt to clear the device context when
+ // it has been used, but currently the only way to know that a GPU
+ // device was used is that deviceInfo will be non-null.
+ if (deviceInfo == nullptr)
+ {
+ return;
+ }
+
cudaError_t stat;
if (debug)
fprintf(stderr, "Cleaning up context on GPU ID #%d\n", gpuid);
}
- if (deviceInfo != nullptr)
+ if (!reset_gpu_application_clocks(deviceInfo))
{
- if (!reset_gpu_application_clocks(deviceInfo))
- {
- gmx_warning("Failed to reset GPU application clocks on GPU #%d", deviceInfo->id);
- }
+ gmx_warning("Failed to reset GPU application clocks on GPU #%d", deviceInfo->id);
}
stat = cudaDeviceReset();
/*! \brief Frees up the CUDA GPU used by the active context at the time of calling.
*
- * The context is explicitly destroyed and therefore all data uploaded to the GPU
- * is lost. This should only be called when none of this data is required anymore.
+ * If \c deviceInfo is nullptr, then it is understood that no device
+ * was selected so no context is active to be freed. Otherwise, the
+ * context is explicitly destroyed and therefore all data uploaded to
+ * the GPU is lost. This must only be called when none of this data is
+ * required anymore, because subsequent attempts to free memory
+ * associated with the context will otherwise fail.
*
* Calls gmx_warning upon errors.
*