Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions src/uct/cuda/base/cuda_ctx.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ ucs_status_t uct_cuda_ctx_primary_retain(CUdevice cuda_device, int force,
CUcontext cuda_ctx;

if (!force) {
status = UCT_CUDADRV_FUNC_LOG_ERR(
cuDevicePrimaryCtxGetState(cuda_device, &flags, &active));
status = UCT_CUDADRV_FUNC_LOG_ERR(cuDevicePrimaryCtxGetState,
cuda_device, &flags, &active);
if (status != UCS_OK) {
return status;
}
Expand All @@ -33,8 +33,8 @@ ucs_status_t uct_cuda_ctx_primary_retain(CUdevice cuda_device, int force,
}
}

status = UCT_CUDADRV_FUNC_LOG_ERR(
cuDevicePrimaryCtxRetain(&cuda_ctx, cuda_device));
status = UCT_CUDADRV_FUNC_LOG_ERR(cuDevicePrimaryCtxRetain, &cuda_ctx,
cuda_device);
if (status != UCS_OK) {
return status;
}
Expand All @@ -49,14 +49,14 @@ ucs_status_t uct_cuda_ctx_primary_push_first_active(CUdevice *cuda_device_p)
ucs_status_t status;
CUdevice cuda_device;

status = UCT_CUDADRV_FUNC_LOG_ERR(cuDeviceGetCount(&num_devices));
status = UCT_CUDADRV_FUNC_LOG_ERR(cuDeviceGetCount, &num_devices);
if (status != UCS_OK) {
return status;
}

for (device_index = 0; device_index < num_devices; ++device_index) {
status = UCT_CUDADRV_FUNC_LOG_ERR(
cuDeviceGet(&cuda_device, device_index));
status = UCT_CUDADRV_FUNC_LOG_ERR(cuDeviceGet, &cuda_device,
device_index);
if (status != UCS_OK) {
return status;
}
Expand Down Expand Up @@ -85,9 +85,9 @@ ucs_status_t uct_cuda_ctx_primary_push(CUdevice cuda_device, int retain_inactive
return status;
}

status = UCT_CUDADRV_FUNC(cuCtxPushCurrent(primary_ctx), log_level);
status = UCT_CUDADRV_FUNC(log_level, cuCtxPushCurrent, primary_ctx);
if (status != UCS_OK) {
(void)UCT_CUDADRV_FUNC(cuDevicePrimaryCtxRelease(cuda_device), log_level);
(void)UCT_CUDADRV_FUNC_LOG_WARN(cuDevicePrimaryCtxRelease, cuda_device);
}

return status;
Expand All @@ -102,7 +102,7 @@ ucs_status_t uct_cuda_ctx_primary_push_avail(int retain_inactive,
ucs_status_t status;
int dev_ordinal, num_devices;

status = UCT_CUDADRV_FUNC_LOG_DEBUG(cuCtxGetDevice(cuda_device_p));
status = UCT_CUDADRV_FUNC_LOG_DEBUG(cuCtxGetDevice, cuda_device_p);
if (status != UCS_OK) {
*cuda_device_p = CU_DEVICE_INVALID;
}
Expand Down Expand Up @@ -137,15 +137,15 @@ ucs_status_t uct_cuda_ctx_primary_push_avail(int retain_inactive,
return UCS_OK;
}

status = UCT_CUDADRV_FUNC(cuDeviceGetCount(&num_devices), UCS_LOG_LEVEL_DIAG);
status = UCT_CUDADRV_FUNC_LOG_DIAG(cuDeviceGetCount, &num_devices);
if (status != UCS_OK) {
return UCS_ERR_INVALID_PARAM;
}

/* Use the first active cuda device for allocation */
for (dev_ordinal = 0; dev_ordinal < num_devices; dev_ordinal++) {
if (UCT_CUDADRV_FUNC_LOG_DEBUG(cuDeviceGet(avail_cuda_device_p,
dev_ordinal)) != UCS_OK) {
if (UCT_CUDADRV_FUNC_LOG_DEBUG(cuDeviceGet, avail_cuda_device_p,
dev_ordinal) != UCS_OK) {
continue;
}

Expand All @@ -162,6 +162,6 @@ ucs_status_t uct_cuda_ctx_primary_push_avail(int retain_inactive,

void uct_cuda_ctx_primary_pop_and_release(CUdevice cuda_device)
{
(void)UCT_CUDADRV_FUNC_LOG_WARN(cuCtxPopCurrent(NULL));
(void)UCT_CUDADRV_FUNC_LOG_WARN(cuDevicePrimaryCtxRelease(cuda_device));
(void)UCT_CUDADRV_FUNC_LOG_WARN(cuCtxPopCurrent, NULL);
(void)UCT_CUDADRV_FUNC_LOG_WARN(cuDevicePrimaryCtxRelease, cuda_device);
}
4 changes: 2 additions & 2 deletions src/uct/cuda/base/cuda_ctx.inl
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ uct_cuda_ctx_pop_and_release(CUdevice cuda_device, CUcontext cuda_context)
return;
}

UCT_CUDADRV_FUNC_LOG_WARN(cuCtxPopCurrent(NULL));
(void)UCT_CUDADRV_FUNC_LOG_WARN(cuCtxPopCurrent, NULL);
if (cuda_device == CU_DEVICE_INVALID) {
return;
}

UCT_CUDADRV_FUNC_LOG_WARN(cuDevicePrimaryCtxRelease(cuda_device));
(void)UCT_CUDADRV_FUNC_LOG_WARN(cuDevicePrimaryCtxRelease, cuda_device);
}

#endif
28 changes: 13 additions & 15 deletions src/uct/cuda/base/cuda_iface.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (c) NVIDIA CORPORATION & AFFILIATES, 2019. ALL RIGHTS RESERVED.
* Copyright (c) NVIDIA CORPORATION & AFFILIATES, 2019-2026. ALL RIGHTS RESERVED.
*
* See file LICENSE for terms.
*/
Expand Down Expand Up @@ -28,7 +28,7 @@ uct_cuda_base_query_devices_common(
ucs_status_t status;

if (uct_cuda_ctx_is_active()) {
status = UCT_CUDADRV_FUNC_LOG_ERR(cuCtxGetDevice(&cuda_device));
status = UCT_CUDADRV_FUNC_LOG_ERR(cuCtxGetDevice, &cuda_device);
if (status != UCS_OK) {
return status;
}
Expand Down Expand Up @@ -141,15 +141,13 @@ ucs_status_t uct_cuda_base_iface_event_fd_arm(uct_iface_h tl_iface,
if (!ucs_queue_is_empty(event_q)) {
status =
#if (__CUDACC_VER_MAJOR__ >= 100000)
UCT_CUDADRV_FUNC_LOG_ERR(
cuLaunchHostFunc(*stream,
uct_cuda_base_iface_stream_cb_fxn,
iface));
UCT_CUDADRV_FUNC_LOG_ERR(cuLaunchHostFunc, *stream,
uct_cuda_base_iface_stream_cb_fxn,
iface);
#else
UCT_CUDADRV_FUNC_LOG_ERR(
cuStreamAddCallback(*stream,
uct_cuda_base_iface_stream_cb_fxn,
iface, 0));
UCT_CUDADRV_FUNC_LOG_ERR(cuStreamAddCallback, *stream,
uct_cuda_base_iface_stream_cb_fxn,
iface, 0);
#endif
if (UCS_OK != status) {
return status;
Expand Down Expand Up @@ -318,7 +316,7 @@ ucs_status_t uct_cuda_base_iface_flush(uct_iface_h tl_iface, unsigned flags,
void uct_cuda_base_stream_destroy(CUstream *stream)
{
if (*stream != NULL) {
(void)UCT_CUDADRV_FUNC_LOG_WARN(cuStreamDestroy(*stream));
(void)UCT_CUDADRV_FUNC_LOG_WARN(cuStreamDestroy, *stream);
}
}

Expand All @@ -327,15 +325,15 @@ uct_cuda_base_event_desc_init(ucs_mpool_t *mp, void *obj, void *chunk)
{
uct_cuda_event_desc_t *event_desc = obj;

UCT_CUDADRV_FUNC_LOG_ERR(cuEventCreate(&event_desc->event,
CU_EVENT_DISABLE_TIMING));
UCT_CUDADRV_FUNC_LOG_ERR(cuEventCreate, &event_desc->event,
CU_EVENT_DISABLE_TIMING);
}

static void uct_cuda_base_event_desc_cleanup(ucs_mpool_t *mp, void *obj)
{
uct_cuda_event_desc_t *event_desc = obj;

(void)UCT_CUDADRV_FUNC_LOG_WARN(cuEventDestroy(event_desc->event));
(void)UCT_CUDADRV_FUNC_LOG_WARN(cuEventDestroy, event_desc->event);
}

void uct_cuda_base_queue_desc_init(uct_cuda_queue_desc_t *qdesc)
Expand Down Expand Up @@ -375,7 +373,7 @@ ucs_status_t uct_cuda_base_ctx_rsc_create(uct_cuda_iface_t *iface,
uct_cuda_ctx_rsc_t *ctx_rsc;
ucs_mpool_params_t mp_params;

status = UCT_CUDADRV_FUNC_LOG_ERR(cuCtxGetCurrent(&ctx));
status = UCT_CUDADRV_FUNC_LOG_ERR(cuCtxGetCurrent, &ctx);
if (status != UCS_OK) {
return status;
} else if (ctx == NULL) {
Expand Down
6 changes: 3 additions & 3 deletions src/uct/cuda/base/cuda_iface.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (c) NVIDIA CORPORATION & AFFILIATES, 2018. ALL RIGHTS RESERVED.
* Copyright (c) NVIDIA CORPORATION & AFFILIATES, 2018-2026. ALL RIGHTS RESERVED.
* See file LICENSE for terms.
*/

Expand Down Expand Up @@ -166,8 +166,8 @@ uct_cuda_base_init_stream(CUstream *stream)
return UCS_OK;
}

return UCT_CUDADRV_FUNC_LOG_ERR(
cuStreamCreate(stream, CU_STREAM_NON_BLOCKING));
return UCT_CUDADRV_FUNC_LOG_ERR(cuStreamCreate, stream,
CU_STREAM_NON_BLOCKING);
}

#endif
9 changes: 4 additions & 5 deletions src/uct/cuda/base/cuda_md.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (c) NVIDIA CORPORATION & AFFILIATES, 2018-2019. ALL RIGHTS RESERVED.
* Copyright (c) NVIDIA CORPORATION & AFFILIATES, 2018-2026. ALL RIGHTS RESERVED.
* See file LICENSE for terms.
*/

Expand Down Expand Up @@ -27,14 +27,13 @@ uct_cuda_base_query_md_resources(uct_component_t *component,
char device_name[10];
int i, num_gpus;

status = UCT_CUDADRV_FUNC(cuDeviceGetCount(&num_gpus), UCS_LOG_LEVEL_DIAG);
status = UCT_CUDADRV_FUNC_LOG_DIAG(cuDeviceGetCount, &num_gpus);
if ((status != UCS_OK) || (num_gpus == 0)) {
return uct_md_query_empty_md_resource(resources_p, num_resources_p);
}

for (i = 0; i < num_gpus; ++i) {
status = UCT_CUDADRV_FUNC(cuDeviceGet(&cuda_device, i),
UCS_LOG_LEVEL_DIAG);
status = UCT_CUDADRV_FUNC_LOG_DIAG(cuDeviceGet, &cuda_device, i);
if (status != UCS_OK) {
continue;
}
Expand All @@ -57,7 +56,7 @@ uct_cuda_base_query_md_resources(uct_component_t *component,

UCS_STATIC_INIT
{
UCT_CUDADRV_FUNC_LOG_DEBUG(cuInit(0));
UCT_CUDADRV_FUNC_LOG_DEBUG(cuInit, 0);
}

UCS_STATIC_CLEANUP
Expand Down
27 changes: 16 additions & 11 deletions src/uct/cuda/base/cuda_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,44 +7,49 @@
#ifndef UCT_CUDA_UTIL_H
#define UCT_CUDA_UTIL_H

#include <ucs/sys/topo/base/topo.h>
#include <ucs/debug/log.h>
#include <ucs/profile/profile_defs.h>
#include <ucs/sys/topo/base/topo.h>

#include <cuda.h>


const char *uct_cuda_cu_get_error_string(CUresult result);


#define UCT_CUDADRV_LOG(_func, _log_level, _result) \
#define UCT_CUDADRV_LOG(_log_level, _func, _result) \
ucs_log((_log_level), "%s failed: %s", UCS_PP_MAKE_STRING(_func), \
uct_cuda_cu_get_error_string(_result))


#define UCT_CUDADRV_FUNC(_func, _log_level) \
#define UCT_CUDADRV_FUNC(_log_level, _func, ...) \
({ \
CUresult _result = (_func); \
CUresult _result = UCS_PROFILE_CALL_ALWAYS(_func, ##__VA_ARGS__); \
ucs_status_t _status; \
if (ucs_likely(_result == CUDA_SUCCESS)) { \
_status = UCS_OK; \
} else { \
UCT_CUDADRV_LOG(_func, _log_level, _result); \
UCT_CUDADRV_LOG(_log_level, _func, _result); \
_status = UCS_ERR_IO_ERROR; \
} \
_status; \
})


#define UCT_CUDADRV_FUNC_LOG_ERR(_func) \
UCT_CUDADRV_FUNC(_func, UCS_LOG_LEVEL_ERROR)
#define UCT_CUDADRV_FUNC_LOG_ERR(_func, ...) \
UCT_CUDADRV_FUNC(UCS_LOG_LEVEL_ERROR, _func, ##__VA_ARGS__)


#define UCT_CUDADRV_FUNC_LOG_WARN(_func, ...) \
UCT_CUDADRV_FUNC(UCS_LOG_LEVEL_WARN, _func, ##__VA_ARGS__)


#define UCT_CUDADRV_FUNC_LOG_WARN(_func) \
UCT_CUDADRV_FUNC(_func, UCS_LOG_LEVEL_WARN)
#define UCT_CUDADRV_FUNC_LOG_DIAG(_func, ...) \
UCT_CUDADRV_FUNC(UCS_LOG_LEVEL_DIAG, _func, ##__VA_ARGS__)


#define UCT_CUDADRV_FUNC_LOG_DEBUG(_func) \
UCT_CUDADRV_FUNC(_func, UCS_LOG_LEVEL_DEBUG)
#define UCT_CUDADRV_FUNC_LOG_DEBUG(_func, ...) \
UCT_CUDADRV_FUNC(UCS_LOG_LEVEL_DEBUG, _func, ##__VA_ARGS__)


/**
Expand Down
24 changes: 12 additions & 12 deletions src/uct/cuda/cuda_copy/cuda_copy_ep.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (c) NVIDIA CORPORATION & AFFILIATES, 2017-2019. ALL RIGHTS RESERVED.
* Copyright (c) NVIDIA CORPORATION & AFFILIATES, 2017-2026. ALL RIGHTS RESERVED.
* See file LICENSE for terms.
*/

Expand Down Expand Up @@ -142,9 +142,9 @@ static ucs_status_t uct_cuda_copy_ep_push_memory_ctx(CUdeviceptr cuda_deviceptr,
CUcontext cuda_context;
ucs_status_t status;

status = UCT_CUDADRV_FUNC_LOG_ERR(
cuPointerGetAttribute(&cuda_context, CU_POINTER_ATTRIBUTE_CONTEXT,
cuda_deviceptr));
status = UCT_CUDADRV_FUNC_LOG_ERR(cuPointerGetAttribute, &cuda_context,
CU_POINTER_ATTRIBUTE_CONTEXT,
cuda_deviceptr);
if (status != UCS_OK) {
return status;
}
Expand All @@ -154,7 +154,7 @@ static ucs_status_t uct_cuda_copy_ep_push_memory_ctx(CUdeviceptr cuda_deviceptr,
return UCS_ERR_UNSUPPORTED;
}

status = UCT_CUDADRV_FUNC_LOG_ERR(cuCtxPushCurrent(cuda_context));
status = UCT_CUDADRV_FUNC_LOG_ERR(cuCtxPushCurrent, cuda_context);
if (status != UCS_OK) {
return status;
}
Expand Down Expand Up @@ -230,7 +230,7 @@ static UCS_F_ALWAYS_INLINE ucs_status_t uct_cuda_copy_ctx_rsc_get(

result = uct_cuda_ctx_get_id(NULL, &ctx_id);
if (result != CUDA_SUCCESS) {
UCT_CUDADRV_LOG(cuCtxGetId, UCS_LOG_LEVEL_ERROR, result);
UCT_CUDADRV_LOG(UCS_LOG_LEVEL_ERROR, cuCtxGetId, result);
status = UCS_ERR_IO_ERROR;
goto err_pop_and_release;
}
Expand Down Expand Up @@ -323,14 +323,14 @@ uct_cuda_copy_post_cuda_async_copy(uct_ep_h tl_ep, void *dst, void *src,
goto out_pop_and_release;
}

status = UCT_CUDADRV_FUNC_LOG_ERR(
cuMemcpyAsync((CUdeviceptr)dst, (CUdeviceptr)src, length, *stream));
status = UCT_CUDADRV_FUNC_LOG_ERR(cuMemcpyAsync, (CUdeviceptr)dst,
(CUdeviceptr)src, length, *stream);
if (ucs_unlikely(UCS_OK != status)) {
goto err_mpool_put;
}

status = UCT_CUDADRV_FUNC_LOG_ERR(
cuEventRecord(cuda_event->event, *stream));
status = UCT_CUDADRV_FUNC_LOG_ERR(cuEventRecord, cuda_event->event,
*stream);
if (ucs_unlikely(UCS_OK != status)) {
goto err_mpool_put;
}
Expand Down Expand Up @@ -422,12 +422,12 @@ static UCS_F_ALWAYS_INLINE ucs_status_t uct_cuda_copy_ep_rma_short(
goto out_pop_and_release;
}

status = UCT_CUDADRV_FUNC_LOG_ERR(cuMemcpyAsync(dst, src, length, *stream));
status = UCT_CUDADRV_FUNC_LOG_ERR(cuMemcpyAsync, dst, src, length, *stream);
if (ucs_unlikely(status != UCS_OK)) {
goto out_pop_and_release;
}

status = UCT_CUDADRV_FUNC_LOG_ERR(cuStreamSynchronize(*stream));
status = UCT_CUDADRV_FUNC_LOG_ERR(cuStreamSynchronize, *stream);

out_pop_and_release:
uct_cuda_ctx_pop_and_release(ctx.cuda_device, ctx.cuda_context);
Expand Down
Loading
Loading