Skip to content

Commit 53e9fba

Browse files
authored
Merge pull request #11308 from wckzhang/delayedinitfix
accelerator/cuda: Account for possibility that cuda will never be ini…
2 parents 6c1e9f7 + c42d916 commit 53e9fba

File tree

5 files changed

+36
-7
lines changed

5 files changed

+36
-7
lines changed

ompi/mca/pml/ob1/pml_ob1.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ int mca_pml_ob1_enable(bool enable)
197197
mca_pml_ob1.free_list_inc,
198198
NULL, 0, NULL, NULL, NULL);
199199

200-
mca_pml_ob1_accelerator_init();
200+
mca_pml_ob1.accelerator_enabled = (0 == mca_pml_ob1_accelerator_init()) ? true : false;
201201

202202
mca_pml_ob1.enabled = true;
203203

ompi/mca/pml/ob1/pml_ob1.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ struct mca_pml_ob1_t {
8686
char* allocator_name;
8787
mca_allocator_base_module_t* allocator;
8888
unsigned int unexpected_limit;
89+
/* Accelerator support initialized */
90+
bool accelerator_enabled;
8991
};
9092
typedef struct mca_pml_ob1_t mca_pml_ob1_t;
9193

ompi/mca/pml/ob1/pml_ob1_component.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,9 @@ int mca_pml_ob1_component_fini(void)
363363
OBJ_DESTRUCT(&mca_pml_ob1.lock);
364364
OBJ_DESTRUCT(&mca_pml_ob1.send_ranges);
365365

366-
mca_pml_ob1_accelerator_fini();
366+
if (mca_pml_ob1.accelerator_enabled) {
367+
mca_pml_ob1_accelerator_fini();
368+
}
367369

368370
if( NULL != mca_pml_ob1.allocator ) {
369371
(void)mca_pml_ob1.allocator->alc_finalize(mca_pml_ob1.allocator);

opal/datatype/opal_datatype_copy.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,24 @@
5555
} \
5656
} while (0)
5757

58+
static bool opal_datatype_is_accel(void *dest, const void *src) {
59+
int dev_id;
60+
uint64_t flags;
61+
if (opal_accelerator.check_addr(dest, &dev_id, &flags)) {
62+
return true;
63+
}
64+
if (opal_accelerator.check_addr(src, &dev_id, &flags)) {
65+
return true;
66+
}
67+
return false;
68+
}
69+
5870
static void *opal_datatype_accelerator_memcpy(void *dest, const void *src, size_t size)
5971
{
6072
int res;
73+
if (!opal_datatype_is_accel(dest, src)) {
74+
return memcpy(dest, src, size);
75+
}
6176
res = opal_accelerator.mem_copy(MCA_ACCELERATOR_NO_DEVICE_ID, MCA_ACCELERATOR_NO_DEVICE_ID,
6277
dest, src, size, MCA_ACCELERATOR_TRANSFER_UNSPEC);
6378
if (OPAL_SUCCESS != res) {
@@ -70,6 +85,9 @@ static void *opal_datatype_accelerator_memcpy(void *dest, const void *src, size_
7085
static void *opal_datatype_accelerator_memmove(void *dest, const void *src, size_t size)
7186
{
7287
int res;
88+
if (!opal_datatype_is_accel(dest, src)) {
89+
return memmove(dest, src, size);
90+
}
7391
res = opal_accelerator.mem_move(MCA_ACCELERATOR_NO_DEVICE_ID, MCA_ACCELERATOR_NO_DEVICE_ID,
7492
dest, src, size, MCA_ACCELERATOR_TRANSFER_UNSPEC);
7593
if (OPAL_SUCCESS != res) {

opal/mca/accelerator/cuda/accelerator_cuda.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,12 @@ static int accelerator_cuda_check_addr(const void *addr, int *dev_id, uint64_t *
109109
*flags |= MCA_ACCELERATOR_FLAGS_UNIFIED_MEMORY;
110110
}
111111
if (CUDA_SUCCESS != result) {
112-
/* Cannot identify, return an error */
113-
return -1;
112+
/* If cuda is not initialized, assume it is a host buffer. */
113+
if (CUDA_ERROR_NOT_INITIALIZED == result) {
114+
return 0;
115+
} else {
116+
return OPAL_ERROR;
117+
}
114118
} else if (CU_MEMORYTYPE_HOST == mem_type) {
115119
/* Host memory, nothing to do here */
116120
return 0;
@@ -123,9 +127,12 @@ static int accelerator_cuda_check_addr(const void *addr, int *dev_id, uint64_t *
123127
#else /* OPAL_CUDA_GET_ATTRIBUTES */
124128
result = cuPointerGetAttribute(&mem_type, CU_POINTER_ATTRIBUTE_MEMORY_TYPE, dbuf);
125129
if (CUDA_SUCCESS != result) {
126-
/* If we cannot determine it is device pointer,
127-
* just assume it is not. */
128-
return 0;
130+
/* If cuda is not initialized, assume it is a host buffer. */
131+
if (CUDA_ERROR_NOT_INITIALIZED == result) {
132+
return 0;
133+
} else {
134+
return OPAL_ERROR;
135+
}
129136
} else if (CU_MEMORYTYPE_HOST == mem_type) {
130137
/* Host memory, nothing to do here */
131138
return 0;

0 commit comments

Comments
 (0)