@@ -265,8 +265,6 @@ static int mca_btl_smcuda_component_open(void)
265265 OBJ_CONSTRUCT (& mca_btl_smcuda_component .sm_frags_user , opal_free_list_t );
266266 OBJ_CONSTRUCT (& mca_btl_smcuda_component .pending_send_fl , opal_free_list_t );
267267
268- opal_finalize_register_cleanup (mca_btl_smcuda_component_fini );
269-
270268 return OPAL_SUCCESS ;
271269}
272270
@@ -283,6 +281,8 @@ static void mca_btl_smcuda_component_fini(void)
283281{
284282 int rc ;
285283
284+ mca_btl_smcuda_accelerator_fini ();
285+
286286 OBJ_DESTRUCT (& mca_btl_smcuda_component .sm_lock );
287287 /**
288288 * We don't have to destroy the fragment lists. They are allocated
@@ -892,6 +892,22 @@ mca_btl_smcuda_component_init(int *num_btls, bool enable_progress_threads, bool
892892 mca_btl_base_active_message_trigger [MCA_BTL_TAG_SMCUDA ].cbfunc = btl_smcuda_control ;
893893 mca_btl_base_active_message_trigger [MCA_BTL_TAG_SMCUDA ].cbdata = NULL ;
894894
895+ /*
896+ * add smcuda component fini code to opal's list of cleanup functions.
897+ * Cleanups are called before all the MCA frameworks are closed, so by
898+ * of the closing of the BTL framework with the accelerator framework, etc. etc.
899+ * We add it here in the btl_init routine as its possible under
900+ * certain scenarios that one of the steps above in this routine will fail,
901+ * resulting in a NULL return value, and the btl component selector to close
902+ * the btl. This can also happen in normal operation, for instance for singleton
903+ * where the smcuda is closed during mpi initialization. We don't want
904+ * to add a cleanup callback if no btls were returned.
905+ */
906+
907+ if (NULL != btls ) {
908+ opal_finalize_register_cleanup (mca_btl_smcuda_component_fini );
909+ }
910+
895911 return btls ;
896912}
897913
0 commit comments