Skip to content

Commit 2d09d08

Browse files
committed
accelerator/cuda: Account for possibility that cuda will never be initialized
When the accelerator cuda component was first implemented, if cuda was not initialized, the component would not be selected. Therefore some logic was implemented with the assumption that the initialization would have already happened. After delayed initialization logic was added, the check addr functions could be entered and would return an error if cuda was not already initialized. Since cuda may never be initialized, this patch adds some assumptions that the buffers are host buffers if initialization does not pass. Signed-off-by: William Zhang <wilzhang@amazon.com>
1 parent 57ca47a commit 2d09d08

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

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)