diff --git a/src/mpi/datatype/typerep/yaksa/src/backend/cuda/hooks/yaksuri_cuda_init_hooks.c b/src/mpi/datatype/typerep/yaksa/src/backend/cuda/hooks/yaksuri_cuda_init_hooks.c index 1fe592da9f4..f3984acee1e 100644 --- a/src/mpi/datatype/typerep/yaksa/src/backend/cuda/hooks/yaksuri_cuda_init_hooks.c +++ b/src/mpi/datatype/typerep/yaksa/src/backend/cuda/hooks/yaksuri_cuda_init_hooks.c @@ -73,9 +73,9 @@ static int finalize_hook(void) int rc = YAKSA_SUCCESS; cudaError_t cerr; - for (int i = 0; i < yaksuri_cudai_global.ndevices; i++) { + for (unsigned i = 0; i < yaksuri_cudai_global.ndevices; i++) { if (yaksuri_cudai_global.streams[i].created) { - cerr = cudaSetDevice(i); + cerr = cudaSetDevice((int) i); YAKSURI_CUDAI_CUDA_ERR_CHKANDJUMP(cerr, rc, fn_fail); cerr = cudaStreamDestroy(yaksuri_cudai_global.streams[i].stream); @@ -93,7 +93,7 @@ static int finalize_hook(void) goto fn_exit; } -static int get_num_devices(int *ndevices) +static int get_num_devices(unsigned *ndevices) { *ndevices = yaksuri_cudai_global.ndevices; @@ -169,21 +169,24 @@ int yaksuri_cuda_init_hook(yaksur_gpudriver_hooks_s ** hooks) int rc = YAKSA_SUCCESS; cudaError_t cerr; - cerr = cudaGetDeviceCount(&yaksuri_cudai_global.ndevices); + int ndevices; + cerr = cudaGetDeviceCount(&ndevices); if (cerr == cudaErrorNoDevice || cerr == cudaErrorInsufficientDriver) { /* both codes can indicate no devices available on the system */ goto fn_exit; } YAKSURI_CUDAI_CUDA_ERR_CHKANDJUMP(cerr, rc, fn_fail); + YAKSU_ERR_CHKANDJUMP(ndevices < 0, rc, YAKSA_ERR__INTERNAL, fn_fail); + yaksuri_cudai_global.ndevices = (unsigned) ndevices; if (getenv("CUDA_VISIBLE_DEVICES") == NULL) { /* user did not do any filtering for us; if any of the devices * is in exclusive mode, disable GPU support to avoid * incorrect device sharing */ bool excl = false; - for (int i = 0; i < yaksuri_cudai_global.ndevices; i++) { + for (unsigned i = 0; i < yaksuri_cudai_global.ndevices; i++) { int mode; - cerr = cudaDeviceGetAttribute(&mode, cudaDevAttrComputeMode, i); + cerr = cudaDeviceGetAttribute(&mode, cudaDevAttrComputeMode, (int) i); YAKSURI_CUDAI_CUDA_ERR_CHKANDJUMP(cerr, rc, fn_fail); if (mode != cudaComputeModeDefault) { @@ -207,20 +210,20 @@ int yaksuri_cuda_init_hook(yaksur_gpudriver_hooks_s ** hooks) yaksuri_cudai_global.streams = calloc(yaksuri_cudai_global.ndevices, sizeof(cudai_stream)); yaksuri_cudai_global.p2p = (int **) malloc(yaksuri_cudai_global.ndevices * sizeof(int *)); - for (int i = 0; i < yaksuri_cudai_global.ndevices; i++) { + for (unsigned i = 0; i < yaksuri_cudai_global.ndevices; i++) { if (yaksuri_global.has_wait_kernel) { /* The stream creation will deadlock with wait kernel. Create them now. */ - yaksuri_cudai_get_stream(i); + yaksuri_cudai_get_stream((int) i); } yaksuri_cudai_global.p2p[i] = (int *) malloc(yaksuri_cudai_global.ndevices * sizeof(int)); /* mark as unchecked with -1. We will check access and cache the value * in check_p2p_comm */ - for (int j = 0; j < yaksuri_cudai_global.ndevices; j++) { + for (unsigned j = 0; j < yaksuri_cudai_global.ndevices; j++) { yaksuri_cudai_global.p2p[i][j] = -1; } } /* mark self entries */ - for (int i = 0; i < yaksuri_cudai_global.ndevices; i++) { + for (unsigned i = 0; i < yaksuri_cudai_global.ndevices; i++) { yaksuri_cudai_global.p2p[i][i] = 1; } diff --git a/src/mpi/datatype/typerep/yaksa/src/backend/cuda/include/yaksuri_cudai_base.h b/src/mpi/datatype/typerep/yaksa/src/backend/cuda/include/yaksuri_cudai_base.h index df1504771c4..8bef18c6663 100644 --- a/src/mpi/datatype/typerep/yaksa/src/backend/cuda/include/yaksuri_cudai_base.h +++ b/src/mpi/datatype/typerep/yaksa/src/backend/cuda/include/yaksuri_cudai_base.h @@ -24,7 +24,7 @@ typedef struct cudai_stream_s { } cudai_stream; typedef struct { - int ndevices; + unsigned ndevices; cudai_stream *streams; /* array of lazily created streams, one for each device */ int **p2p; /* p2p[sdev][ddev] */ } yaksuri_cudai_global_s; diff --git a/src/mpi/datatype/typerep/yaksa/src/backend/hip/hooks/yaksuri_hip_init_hooks.c b/src/mpi/datatype/typerep/yaksa/src/backend/hip/hooks/yaksuri_hip_init_hooks.c index b51665f6f83..0e1e6f10ce8 100644 --- a/src/mpi/datatype/typerep/yaksa/src/backend/hip/hooks/yaksuri_hip_init_hooks.c +++ b/src/mpi/datatype/typerep/yaksa/src/backend/hip/hooks/yaksuri_hip_init_hooks.c @@ -64,8 +64,8 @@ static int finalize_hook(void) int rc = YAKSA_SUCCESS; hipError_t cerr; - for (int i = 0; i < yaksuri_hipi_global.ndevices; i++) { - cerr = hipSetDevice(i); + for (unsigned i = 0; i < yaksuri_hipi_global.ndevices; i++) { + cerr = hipSetDevice((int) i); YAKSURI_HIPI_HIP_ERR_CHKANDJUMP(cerr, rc, fn_fail); cerr = hipStreamDestroy(yaksuri_hipi_global.stream[i]); @@ -82,7 +82,7 @@ static int finalize_hook(void) goto fn_exit; } -static int get_num_devices(int *ndevices) +static int get_num_devices(unsigned *ndevices) { *ndevices = yaksuri_hipi_global.ndevices; @@ -107,21 +107,24 @@ int yaksuri_hip_init_hook(yaksur_gpudriver_hooks_s ** hooks) int rc = YAKSA_SUCCESS; hipError_t cerr; - cerr = hipGetDeviceCount(&yaksuri_hipi_global.ndevices); + int ndevices; + cerr = hipGetDeviceCount(&ndevices); if (cerr == hipErrorNoDevice) { goto fn_exit; } YAKSURI_HIPI_HIP_ERR_CHKANDJUMP(cerr, rc, fn_fail); + YAKSU_ERR_CHKANDJUMP(ndevices < 0, rc, YAKSA_ERR__INTERNAL, fn_fail); + yaksuri_hipi_global.ndevices = (unsigned) ndevices; if (getenv("HIP_VISIBLE_DEVICES") == NULL) { /* user did not do any filtering for us; if any of the devices * is in exclusive mode, disable GPU support to avoid * incorrect device sharing */ bool excl = false; - for (int i = 0; i < yaksuri_hipi_global.ndevices; i++) { + for (unsigned i = 0; i < yaksuri_hipi_global.ndevices; i++) { struct hipDeviceProp_t prop; - cerr = hipGetDeviceProperties(&prop, i); + cerr = hipGetDeviceProperties(&prop, (int) i); YAKSURI_HIPI_HIP_ERR_CHKANDJUMP(cerr, rc, fn_fail); if (prop.computeMode != hipComputeModeDefault) { @@ -146,7 +149,7 @@ int yaksuri_hip_init_hook(yaksur_gpudriver_hooks_s ** hooks) malloc(yaksuri_hipi_global.ndevices * sizeof(hipStream_t)); yaksuri_hipi_global.p2p = (bool **) malloc(yaksuri_hipi_global.ndevices * sizeof(bool *)); - for (int i = 0; i < yaksuri_hipi_global.ndevices; i++) { + for (unsigned i = 0; i < yaksuri_hipi_global.ndevices; i++) { yaksuri_hipi_global.p2p[i] = (bool *) malloc(yaksuri_hipi_global.ndevices * sizeof(bool)); } @@ -154,23 +157,23 @@ int yaksuri_hip_init_hook(yaksur_gpudriver_hooks_s ** hooks) cerr = hipGetDevice(&cur_device); YAKSURI_HIPI_HIP_ERR_CHKANDJUMP(cerr, rc, fn_fail); - for (int i = 0; i < yaksuri_hipi_global.ndevices; i++) { - cerr = hipSetDevice(i); + for (unsigned i = 0; i < yaksuri_hipi_global.ndevices; i++) { + cerr = hipSetDevice((int) i); YAKSURI_HIPI_HIP_ERR_CHKANDJUMP(cerr, rc, fn_fail); cerr = hipStreamCreateWithFlags(&yaksuri_hipi_global.stream[i], hipStreamNonBlocking); YAKSURI_HIPI_HIP_ERR_CHKANDJUMP(cerr, rc, fn_fail); - for (int j = 0; j < yaksuri_hipi_global.ndevices; j++) { + for (unsigned j = 0; j < yaksuri_hipi_global.ndevices; j++) { if (i == j) { yaksuri_hipi_global.p2p[i][j] = 1; } else { int val; - cerr = hipDeviceCanAccessPeer(&val, i, j); + cerr = hipDeviceCanAccessPeer(&val, (int) i, (int) j); YAKSURI_HIPI_HIP_ERR_CHKANDJUMP(cerr, rc, fn_fail); if (val) { - cerr = hipDeviceEnablePeerAccess(j, 0); + cerr = hipDeviceEnablePeerAccess((int) j, 0); if (cerr != hipErrorPeerAccessAlreadyEnabled) { YAKSURI_HIPI_HIP_ERR_CHKANDJUMP(cerr, rc, fn_fail); } diff --git a/src/mpi/datatype/typerep/yaksa/src/backend/hip/include/yaksuri_hipi_base.h b/src/mpi/datatype/typerep/yaksa/src/backend/hip/include/yaksuri_hipi_base.h index 6d4b6e4c401..18cf38bd331 100644 --- a/src/mpi/datatype/typerep/yaksa/src/backend/hip/include/yaksuri_hipi_base.h +++ b/src/mpi/datatype/typerep/yaksa/src/backend/hip/include/yaksuri_hipi_base.h @@ -19,7 +19,7 @@ } while (0) typedef struct { - int ndevices; + unsigned ndevices; hipStream_t *stream; bool **p2p; } yaksuri_hipi_global_s; diff --git a/src/mpi/datatype/typerep/yaksa/src/backend/src/yaksur_hooks.c b/src/mpi/datatype/typerep/yaksa/src/backend/src/yaksur_hooks.c index e89b1e0ce8d..99dc66af6c7 100644 --- a/src/mpi/datatype/typerep/yaksa/src/backend/src/yaksur_hooks.c +++ b/src/mpi/datatype/typerep/yaksa/src/backend/src/yaksur_hooks.c @@ -22,7 +22,7 @@ static void *malloc_fn(uintptr_t size, void *state) if (state == &yaksuri_global.gpudriver[id].host) { return yaksuri_global.gpudriver[id].hooks->host_malloc(size); - } else { + } else if (yaksuri_global.gpudriver[id].ndevices > 0) { uintptr_t start = (uintptr_t) yaksuri_global.gpudriver[id].device; uintptr_t end = (uintptr_t) & yaksuri_global.gpudriver[id].device[yaksuri_global. @@ -49,7 +49,7 @@ static void free_fn(void *buf, void *state) if (state == &yaksuri_global.gpudriver[id].host) { yaksuri_global.gpudriver[id].hooks->host_free(buf); return; - } else { + } else if (yaksuri_global.gpudriver[id].ndevices > 0) { uintptr_t start = (uintptr_t) yaksuri_global.gpudriver[id].device; uintptr_t end = (uintptr_t) & yaksuri_global.gpudriver[id].device[yaksuri_global. @@ -109,13 +109,13 @@ int yaksur_init_hook(yaksi_info_s * info) &yaksuri_global.gpudriver[id].host); YAKSU_ERR_CHECK(rc, fn_fail); - int ndevices; + unsigned ndevices; rc = yaksuri_global.gpudriver[id].hooks->get_num_devices(&ndevices); YAKSU_ERR_CHECK(rc, fn_fail); yaksuri_global.gpudriver[id].device = (yaksu_buffer_pool_s *) malloc(ndevices * sizeof(yaksu_buffer_pool_s)); - for (int i = 0; i < ndevices; i++) { + for (unsigned i = 0; i < ndevices; i++) { rc = yaksu_buffer_pool_alloc(YAKSURI_TMPBUF_EL_SIZE, 1, YAKSURI_TMPBUF_NUM_EL, malloc_fn, free_fn, &yaksuri_global.gpudriver[id].device[i], @@ -153,8 +153,8 @@ int yaksur_finalize_hook(void) rc = yaksu_buffer_pool_free(yaksuri_global.gpudriver[id].host); YAKSU_ERR_CHECK(rc, fn_fail); - int ndevices = yaksuri_global.gpudriver[id].ndevices; - for (int i = 0; i < ndevices; i++) { + unsigned ndevices = yaksuri_global.gpudriver[id].ndevices; + for (unsigned i = 0; i < ndevices; i++) { rc = yaksu_buffer_pool_free(yaksuri_global.gpudriver[id].device[i]); YAKSU_ERR_CHECK(rc, fn_fail); } diff --git a/src/mpi/datatype/typerep/yaksa/src/backend/src/yaksur_pre.h b/src/mpi/datatype/typerep/yaksa/src/backend/src/yaksur_pre.h index e18f0e35d83..e1965dc3edb 100644 --- a/src/mpi/datatype/typerep/yaksa/src/backend/src/yaksur_pre.h +++ b/src/mpi/datatype/typerep/yaksa/src/backend/src/yaksur_pre.h @@ -55,7 +55,7 @@ typedef void (*yaksur_hostfn_t) (void *userData); typedef struct yaksur_gpudriver_hooks_s { /* miscellaneous */ - int (*get_num_devices) (int *ndevices); + int (*get_num_devices) (unsigned *ndevices); /* *INDENT-OFF* */ bool (*check_p2p_comm) (int sdev, int ddev); /* *INDENT-ON* */ diff --git a/src/mpi/datatype/typerep/yaksa/src/backend/src/yaksuri.h b/src/mpi/datatype/typerep/yaksa/src/backend/src/yaksuri.h index 42f93eceb97..fe821fff145 100644 --- a/src/mpi/datatype/typerep/yaksa/src/backend/src/yaksuri.h +++ b/src/mpi/datatype/typerep/yaksa/src/backend/src/yaksuri.h @@ -31,7 +31,7 @@ typedef struct { yaksu_buffer_pool_s host; yaksu_buffer_pool_s *device; yaksur_gpudriver_hooks_s *hooks; - int ndevices; + unsigned ndevices; } gpudriver[YAKSURI_GPUDRIVER_ID__LAST]; } yaksuri_global_s; extern yaksuri_global_s yaksuri_global; diff --git a/src/mpi/datatype/typerep/yaksa/src/backend/ze/hooks/yaksuri_ze_init_hooks.c b/src/mpi/datatype/typerep/yaksa/src/backend/ze/hooks/yaksuri_ze_init_hooks.c index b9944abe244..3cb04c2029c 100644 --- a/src/mpi/datatype/typerep/yaksa/src/backend/ze/hooks/yaksuri_ze_init_hooks.c +++ b/src/mpi/datatype/typerep/yaksa/src/backend/ze/hooks/yaksuri_ze_init_hooks.c @@ -96,7 +96,7 @@ static int finalize_hook(void) goto fn_exit; } -static int get_num_devices(int *ndevices) +static int get_num_devices(unsigned *ndevices) { *ndevices = yaksuri_zei_global.ndevices;