13
13
* Copyright (c) 2006-2010 QLogic Corporation. All rights reserved.
14
14
* Copyright (c) 2012-2017 Los Alamos National Security, LLC. All rights
15
15
* reserved.
16
- * Copyright (c) 2013-2015 Intel, Inc. All rights reserved
16
+ * Copyright (c) 2013-2017 Intel, Inc. All rights reserved
17
17
* Copyright (c) 2017 Research Organization for Information Science
18
18
* and Technology (RIST). All rights reserved.
19
19
* $COPYRIGHT$
28
28
#include "opal/mca/event/event.h"
29
29
#include "opal/util/output.h"
30
30
#include "opal/util/show_help.h"
31
+ #include "opal/util/opal_environ.h"
31
32
#include "ompi/proc/proc.h"
32
33
33
34
#include "mtl_psm2.h"
43
44
44
45
static int param_priority ;
45
46
47
+ #if OPAL_CUDA_SUPPORT
48
+ static int cuda_envvar_set ;
49
+ #endif
50
+
46
51
static int ompi_mtl_psm2_component_open (void );
47
52
static int ompi_mtl_psm2_component_close (void );
48
53
static int ompi_mtl_psm2_component_query (mca_base_module_t * * module , int * priority );
@@ -199,9 +204,6 @@ static int
199
204
ompi_mtl_psm2_component_register (void )
200
205
{
201
206
int num_local_procs , num_total_procs ;
202
- #if OPAL_CUDA_SUPPORT
203
- char * cuda_env ;
204
- #endif
205
207
206
208
ompi_mtl_psm2 .connect_timeout = 180 ;
207
209
(void ) mca_base_component_var_register (& mca_mtl_psm2_component .super .mtl_version ,
@@ -226,30 +228,6 @@ ompi_mtl_psm2_component_register(void)
226
228
param_priority = 40 ;
227
229
}
228
230
229
- #if OPAL_CUDA_SUPPORT
230
- /*
231
- * If using CUDA enabled OpenMPI, the user likely intends to
232
- * run with CUDA buffers. So, force-set the envvar here if user failed
233
- * to set it.
234
- */
235
- cuda_env = getenv ("PSM2_CUDA" );
236
- if (!cuda_env ) {
237
- opal_show_help ("help-mtl-psm2.txt" ,
238
- "no psm2 cuda env" , true,
239
- "not set" ,
240
- "Host buffers,\nthere will be a performance penalty"
241
- " due to OMPI force setting this variable now.\n"
242
- "Set environment variable to 0 if using Host buffers" );
243
- setenv ("PSM2_CUDA" , "1" , 0 );
244
- } else if (strcmp (cuda_env , "0" ) == 0 ) {
245
- opal_show_help ("help-mtl-psm2.txt" ,
246
- "no psm2 cuda env" , true,
247
- "set to 0" ,
248
- "CUDA buffers,\nthe execution will SEGFAULT."
249
- " Set environment variable to 1 if using CUDA buffers" );
250
- }
251
- #endif
252
-
253
231
(void ) mca_base_component_var_register (& mca_mtl_psm2_component .super .mtl_version ,
254
232
"priority" , "Priority of the PSM2 MTL component" ,
255
233
MCA_BASE_VAR_TYPE_INT , NULL , 0 , 0 ,
@@ -334,6 +312,10 @@ ompi_mtl_psm2_component_query(mca_base_module_t **module, int *priority)
334
312
static int
335
313
ompi_mtl_psm2_component_close (void )
336
314
{
315
+ #if OPAL_CUDA_SUPPORT
316
+ if (cuda_envvar_set )
317
+ opal_unsetenv ("PSM2_CUDA" , & environ );
318
+ #endif
337
319
return OMPI_SUCCESS ;
338
320
}
339
321
@@ -360,6 +342,9 @@ ompi_mtl_psm2_component_init(bool enable_progress_threads,
360
342
int verno_major = PSM2_VERNO_MAJOR ;
361
343
int verno_minor = PSM2_VERNO_MINOR ;
362
344
int local_rank = -1 , num_local_procs = 0 ;
345
+ #if OPAL_CUDA_SUPPORT
346
+ char * cuda_env ;
347
+ #endif
363
348
364
349
/* Compute the total number of processes on this host and our local rank
365
350
* on that node. We need to provide PSM2 with these values so it can
@@ -387,6 +372,26 @@ ompi_mtl_psm2_component_init(bool enable_progress_threads,
387
372
ompi_mtl_psm2_set_shadow_env (ompi_mtl_psm2_shadow_variables + i );
388
373
}
389
374
375
+ #if OPAL_CUDA_SUPPORT
376
+ /*
377
+ * If using CUDA enabled OpenMPI, the user likely intends to
378
+ * run with CUDA buffers. So, force-set the envvar here if user failed
379
+ * to set it.
380
+ */
381
+ cuda_env = getenv ("PSM2_CUDA" );
382
+ if (!cuda_env ) {
383
+ opal_show_help ("help-mtl-psm2.txt" ,
384
+ "no psm2 cuda env" , true,
385
+ ompi_process_info .nodename );
386
+ opal_setenv ("PSM2_CUDA" , "1" , false, & environ );
387
+ cuda_envvar_set = 1 ;
388
+ } else if (strcmp (cuda_env , "0" ) == 0 ) {
389
+ opal_show_help ("help-mtl-psm2.txt" ,
390
+ "psm2 cuda env zero" , true,
391
+ ompi_process_info .nodename );
392
+ }
393
+ #endif
394
+
390
395
err = psm2_init (& verno_major , & verno_minor );
391
396
if (err ) {
392
397
opal_show_help ("help-mtl-psm2.txt" ,
0 commit comments