Skip to content

Commit f020b3f

Browse files
committed
UCT/CUDA: Added UCS_PROFILE for CUDA Driver API calls.
1 parent 2faf305 commit f020b3f

15 files changed

Lines changed: 289 additions & 294 deletions

File tree

src/uct/cuda/base/cuda_ctx.c

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ ucs_status_t uct_cuda_ctx_primary_retain(CUdevice cuda_device, int force,
2020
CUcontext cuda_ctx;
2121

2222
if (!force) {
23-
status = UCT_CUDADRV_FUNC_LOG_ERR(
24-
cuDevicePrimaryCtxGetState(cuda_device, &flags, &active));
23+
status = UCT_CUDADRV_FUNC_LOG_ERR(cuDevicePrimaryCtxGetState,
24+
cuda_device, &flags, &active);
2525
if (status != UCS_OK) {
2626
return status;
2727
}
@@ -33,8 +33,8 @@ ucs_status_t uct_cuda_ctx_primary_retain(CUdevice cuda_device, int force,
3333
}
3434
}
3535

36-
status = UCT_CUDADRV_FUNC_LOG_ERR(
37-
cuDevicePrimaryCtxRetain(&cuda_ctx, cuda_device));
36+
status = UCT_CUDADRV_FUNC_LOG_ERR(cuDevicePrimaryCtxRetain, &cuda_ctx,
37+
cuda_device);
3838
if (status != UCS_OK) {
3939
return status;
4040
}
@@ -49,14 +49,14 @@ ucs_status_t uct_cuda_ctx_primary_push_first_active(CUdevice *cuda_device_p)
4949
ucs_status_t status;
5050
CUdevice cuda_device;
5151

52-
status = UCT_CUDADRV_FUNC_LOG_ERR(cuDeviceGetCount(&num_devices));
52+
status = UCT_CUDADRV_FUNC_LOG_ERR(cuDeviceGetCount, &num_devices);
5353
if (status != UCS_OK) {
5454
return status;
5555
}
5656

5757
for (device_index = 0; device_index < num_devices; ++device_index) {
58-
status = UCT_CUDADRV_FUNC_LOG_ERR(
59-
cuDeviceGet(&cuda_device, device_index));
58+
status = UCT_CUDADRV_FUNC_LOG_ERR(cuDeviceGet, &cuda_device,
59+
device_index);
6060
if (status != UCS_OK) {
6161
return status;
6262
}
@@ -85,9 +85,9 @@ ucs_status_t uct_cuda_ctx_primary_push(CUdevice cuda_device, int retain_inactive
8585
return status;
8686
}
8787

88-
status = UCT_CUDADRV_FUNC(cuCtxPushCurrent(primary_ctx), log_level);
88+
status = UCT_CUDADRV_FUNC(log_level, cuCtxPushCurrent, primary_ctx);
8989
if (status != UCS_OK) {
90-
(void)UCT_CUDADRV_FUNC(cuDevicePrimaryCtxRelease(cuda_device), log_level);
90+
(void)UCT_CUDADRV_FUNC_LOG_WARN(cuDevicePrimaryCtxRelease, cuda_device);
9191
}
9292

9393
return status;
@@ -102,7 +102,7 @@ ucs_status_t uct_cuda_ctx_primary_push_avail(int retain_inactive,
102102
ucs_status_t status;
103103
int dev_ordinal, num_devices;
104104

105-
status = UCT_CUDADRV_FUNC_LOG_DEBUG(cuCtxGetDevice(cuda_device_p));
105+
status = UCT_CUDADRV_FUNC_LOG_DEBUG(cuCtxGetDevice, cuda_device_p);
106106
if (status != UCS_OK) {
107107
*cuda_device_p = CU_DEVICE_INVALID;
108108
}
@@ -137,15 +137,15 @@ ucs_status_t uct_cuda_ctx_primary_push_avail(int retain_inactive,
137137
return UCS_OK;
138138
}
139139

140-
status = UCT_CUDADRV_FUNC(cuDeviceGetCount(&num_devices), UCS_LOG_LEVEL_DIAG);
140+
status = UCT_CUDADRV_FUNC_LOG_DIAG(cuDeviceGetCount, &num_devices);
141141
if (status != UCS_OK) {
142142
return UCS_ERR_INVALID_PARAM;
143143
}
144144

145145
/* Use the first active cuda device for allocation */
146146
for (dev_ordinal = 0; dev_ordinal < num_devices; dev_ordinal++) {
147-
if (UCT_CUDADRV_FUNC_LOG_DEBUG(cuDeviceGet(avail_cuda_device_p,
148-
dev_ordinal)) != UCS_OK) {
147+
if (UCT_CUDADRV_FUNC_LOG_DEBUG(cuDeviceGet, avail_cuda_device_p,
148+
dev_ordinal) != UCS_OK) {
149149
continue;
150150
}
151151

@@ -162,6 +162,6 @@ ucs_status_t uct_cuda_ctx_primary_push_avail(int retain_inactive,
162162

163163
void uct_cuda_ctx_primary_pop_and_release(CUdevice cuda_device)
164164
{
165-
(void)UCT_CUDADRV_FUNC_LOG_WARN(cuCtxPopCurrent(NULL));
166-
(void)UCT_CUDADRV_FUNC_LOG_WARN(cuDevicePrimaryCtxRelease(cuda_device));
165+
(void)UCT_CUDADRV_FUNC_LOG_WARN(cuCtxPopCurrent, NULL);
166+
(void)UCT_CUDADRV_FUNC_LOG_WARN(cuDevicePrimaryCtxRelease, cuda_device);
167167
}

src/uct/cuda/base/cuda_ctx.inl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@ uct_cuda_ctx_pop_and_release(CUdevice cuda_device, CUcontext cuda_context)
3838
return;
3939
}
4040

41-
UCT_CUDADRV_FUNC_LOG_WARN(cuCtxPopCurrent(NULL));
41+
(void)UCT_CUDADRV_FUNC_LOG_WARN(cuCtxPopCurrent, NULL);
4242
if (cuda_device == CU_DEVICE_INVALID) {
4343
return;
4444
}
4545

46-
UCT_CUDADRV_FUNC_LOG_WARN(cuDevicePrimaryCtxRelease(cuda_device));
46+
(void)UCT_CUDADRV_FUNC_LOG_WARN(cuDevicePrimaryCtxRelease, cuda_device);
4747
}
4848

4949
#endif

src/uct/cuda/base/cuda_iface.c

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright (c) NVIDIA CORPORATION & AFFILIATES, 2019. ALL RIGHTS RESERVED.
2+
* Copyright (c) NVIDIA CORPORATION & AFFILIATES, 2019-2026. ALL RIGHTS RESERVED.
33
*
44
* See file LICENSE for terms.
55
*/
@@ -28,7 +28,7 @@ uct_cuda_base_query_devices_common(
2828
ucs_status_t status;
2929

3030
if (uct_cuda_ctx_is_active()) {
31-
status = UCT_CUDADRV_FUNC_LOG_ERR(cuCtxGetDevice(&cuda_device));
31+
status = UCT_CUDADRV_FUNC_LOG_ERR(cuCtxGetDevice, &cuda_device);
3232
if (status != UCS_OK) {
3333
return status;
3434
}
@@ -141,15 +141,13 @@ ucs_status_t uct_cuda_base_iface_event_fd_arm(uct_iface_h tl_iface,
141141
if (!ucs_queue_is_empty(event_q)) {
142142
status =
143143
#if (__CUDACC_VER_MAJOR__ >= 100000)
144-
UCT_CUDADRV_FUNC_LOG_ERR(
145-
cuLaunchHostFunc(*stream,
146-
uct_cuda_base_iface_stream_cb_fxn,
147-
iface));
144+
UCT_CUDADRV_FUNC_LOG_ERR(cuLaunchHostFunc, *stream,
145+
uct_cuda_base_iface_stream_cb_fxn,
146+
iface);
148147
#else
149-
UCT_CUDADRV_FUNC_LOG_ERR(
150-
cuStreamAddCallback(*stream,
151-
uct_cuda_base_iface_stream_cb_fxn,
152-
iface, 0));
148+
UCT_CUDADRV_FUNC_LOG_ERR(cuStreamAddCallback, *stream,
149+
uct_cuda_base_iface_stream_cb_fxn,
150+
iface, 0);
153151
#endif
154152
if (UCS_OK != status) {
155153
return status;
@@ -318,7 +316,7 @@ ucs_status_t uct_cuda_base_iface_flush(uct_iface_h tl_iface, unsigned flags,
318316
void uct_cuda_base_stream_destroy(CUstream *stream)
319317
{
320318
if (*stream != NULL) {
321-
(void)UCT_CUDADRV_FUNC_LOG_WARN(cuStreamDestroy(*stream));
319+
(void)UCT_CUDADRV_FUNC_LOG_WARN(cuStreamDestroy, *stream);
322320
}
323321
}
324322

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

330-
UCT_CUDADRV_FUNC_LOG_ERR(cuEventCreate(&event_desc->event,
331-
CU_EVENT_DISABLE_TIMING));
328+
UCT_CUDADRV_FUNC_LOG_ERR(cuEventCreate, &event_desc->event,
329+
CU_EVENT_DISABLE_TIMING);
332330
}
333331

334332
static void uct_cuda_base_event_desc_cleanup(ucs_mpool_t *mp, void *obj)
335333
{
336334
uct_cuda_event_desc_t *event_desc = obj;
337335

338-
(void)UCT_CUDADRV_FUNC_LOG_WARN(cuEventDestroy(event_desc->event));
336+
(void)UCT_CUDADRV_FUNC_LOG_WARN(cuEventDestroy, event_desc->event);
339337
}
340338

341339
void uct_cuda_base_queue_desc_init(uct_cuda_queue_desc_t *qdesc)
@@ -375,7 +373,7 @@ ucs_status_t uct_cuda_base_ctx_rsc_create(uct_cuda_iface_t *iface,
375373
uct_cuda_ctx_rsc_t *ctx_rsc;
376374
ucs_mpool_params_t mp_params;
377375

378-
status = UCT_CUDADRV_FUNC_LOG_ERR(cuCtxGetCurrent(&ctx));
376+
status = UCT_CUDADRV_FUNC_LOG_ERR(cuCtxGetCurrent, &ctx);
379377
if (status != UCS_OK) {
380378
return status;
381379
} else if (ctx == NULL) {

src/uct/cuda/base/cuda_iface.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright (c) NVIDIA CORPORATION & AFFILIATES, 2018. ALL RIGHTS RESERVED.
2+
* Copyright (c) NVIDIA CORPORATION & AFFILIATES, 2018-2026. ALL RIGHTS RESERVED.
33
* See file LICENSE for terms.
44
*/
55

@@ -166,8 +166,8 @@ uct_cuda_base_init_stream(CUstream *stream)
166166
return UCS_OK;
167167
}
168168

169-
return UCT_CUDADRV_FUNC_LOG_ERR(
170-
cuStreamCreate(stream, CU_STREAM_NON_BLOCKING));
169+
return UCT_CUDADRV_FUNC_LOG_ERR(cuStreamCreate, stream,
170+
CU_STREAM_NON_BLOCKING);
171171
}
172172

173173
#endif

src/uct/cuda/base/cuda_md.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright (c) NVIDIA CORPORATION & AFFILIATES, 2018-2019. ALL RIGHTS RESERVED.
2+
* Copyright (c) NVIDIA CORPORATION & AFFILIATES, 2018-2026. ALL RIGHTS RESERVED.
33
* See file LICENSE for terms.
44
*/
55

@@ -27,14 +27,13 @@ uct_cuda_base_query_md_resources(uct_component_t *component,
2727
char device_name[10];
2828
int i, num_gpus;
2929

30-
status = UCT_CUDADRV_FUNC(cuDeviceGetCount(&num_gpus), UCS_LOG_LEVEL_DIAG);
30+
status = UCT_CUDADRV_FUNC_LOG_DIAG(cuDeviceGetCount, &num_gpus);
3131
if ((status != UCS_OK) || (num_gpus == 0)) {
3232
return uct_md_query_empty_md_resource(resources_p, num_resources_p);
3333
}
3434

3535
for (i = 0; i < num_gpus; ++i) {
36-
status = UCT_CUDADRV_FUNC(cuDeviceGet(&cuda_device, i),
37-
UCS_LOG_LEVEL_DIAG);
36+
status = UCT_CUDADRV_FUNC_LOG_DIAG(cuDeviceGet, &cuda_device, i);
3837
if (status != UCS_OK) {
3938
continue;
4039
}
@@ -57,7 +56,7 @@ uct_cuda_base_query_md_resources(uct_component_t *component,
5756

5857
UCS_STATIC_INIT
5958
{
60-
UCT_CUDADRV_FUNC_LOG_DEBUG(cuInit(0));
59+
UCT_CUDADRV_FUNC_LOG_DEBUG(cuInit, 0);
6160
}
6261

6362
UCS_STATIC_CLEANUP

src/uct/cuda/base/cuda_util.h

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,44 +7,49 @@
77
#ifndef UCT_CUDA_UTIL_H
88
#define UCT_CUDA_UTIL_H
99

10-
#include <ucs/sys/topo/base/topo.h>
1110
#include <ucs/debug/log.h>
11+
#include <ucs/profile/profile_defs.h>
12+
#include <ucs/sys/topo/base/topo.h>
1213

1314
#include <cuda.h>
1415

1516

1617
const char *uct_cuda_cu_get_error_string(CUresult result);
1718

1819

19-
#define UCT_CUDADRV_LOG(_func, _log_level, _result) \
20+
#define UCT_CUDADRV_LOG(_log_level, _func, _result) \
2021
ucs_log((_log_level), "%s failed: %s", UCS_PP_MAKE_STRING(_func), \
2122
uct_cuda_cu_get_error_string(_result))
2223

2324

24-
#define UCT_CUDADRV_FUNC(_func, _log_level) \
25+
#define UCT_CUDADRV_FUNC(_log_level, _func, ...) \
2526
({ \
26-
CUresult _result = (_func); \
27+
CUresult _result = UCS_PROFILE_CALL_ALWAYS(_func, ##__VA_ARGS__); \
2728
ucs_status_t _status; \
2829
if (ucs_likely(_result == CUDA_SUCCESS)) { \
2930
_status = UCS_OK; \
3031
} else { \
31-
UCT_CUDADRV_LOG(_func, _log_level, _result); \
32+
UCT_CUDADRV_LOG(_log_level, _func, _result); \
3233
_status = UCS_ERR_IO_ERROR; \
3334
} \
3435
_status; \
3536
})
3637

3738

38-
#define UCT_CUDADRV_FUNC_LOG_ERR(_func) \
39-
UCT_CUDADRV_FUNC(_func, UCS_LOG_LEVEL_ERROR)
39+
#define UCT_CUDADRV_FUNC_LOG_ERR(_func, ...) \
40+
UCT_CUDADRV_FUNC(UCS_LOG_LEVEL_ERROR, _func, ##__VA_ARGS__)
41+
42+
43+
#define UCT_CUDADRV_FUNC_LOG_WARN(_func, ...) \
44+
UCT_CUDADRV_FUNC(UCS_LOG_LEVEL_WARN, _func, ##__VA_ARGS__)
4045

4146

42-
#define UCT_CUDADRV_FUNC_LOG_WARN(_func) \
43-
UCT_CUDADRV_FUNC(_func, UCS_LOG_LEVEL_WARN)
47+
#define UCT_CUDADRV_FUNC_LOG_DIAG(_func, ...) \
48+
UCT_CUDADRV_FUNC(UCS_LOG_LEVEL_DIAG, _func, ##__VA_ARGS__)
4449

4550

46-
#define UCT_CUDADRV_FUNC_LOG_DEBUG(_func) \
47-
UCT_CUDADRV_FUNC(_func, UCS_LOG_LEVEL_DEBUG)
51+
#define UCT_CUDADRV_FUNC_LOG_DEBUG(_func, ...) \
52+
UCT_CUDADRV_FUNC(UCS_LOG_LEVEL_DEBUG, _func, ##__VA_ARGS__)
4853

4954

5055
/**

src/uct/cuda/cuda_copy/cuda_copy_ep.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright (c) NVIDIA CORPORATION & AFFILIATES, 2017-2019. ALL RIGHTS RESERVED.
2+
* Copyright (c) NVIDIA CORPORATION & AFFILIATES, 2017-2026. ALL RIGHTS RESERVED.
33
* See file LICENSE for terms.
44
*/
55

@@ -142,9 +142,9 @@ static ucs_status_t uct_cuda_copy_ep_push_memory_ctx(CUdeviceptr cuda_deviceptr,
142142
CUcontext cuda_context;
143143
ucs_status_t status;
144144

145-
status = UCT_CUDADRV_FUNC_LOG_ERR(
146-
cuPointerGetAttribute(&cuda_context, CU_POINTER_ATTRIBUTE_CONTEXT,
147-
cuda_deviceptr));
145+
status = UCT_CUDADRV_FUNC_LOG_ERR(cuPointerGetAttribute, &cuda_context,
146+
CU_POINTER_ATTRIBUTE_CONTEXT,
147+
cuda_deviceptr);
148148
if (status != UCS_OK) {
149149
return status;
150150
}
@@ -154,7 +154,7 @@ static ucs_status_t uct_cuda_copy_ep_push_memory_ctx(CUdeviceptr cuda_deviceptr,
154154
return UCS_ERR_UNSUPPORTED;
155155
}
156156

157-
status = UCT_CUDADRV_FUNC_LOG_ERR(cuCtxPushCurrent(cuda_context));
157+
status = UCT_CUDADRV_FUNC_LOG_ERR(cuCtxPushCurrent, cuda_context);
158158
if (status != UCS_OK) {
159159
return status;
160160
}
@@ -230,7 +230,7 @@ static UCS_F_ALWAYS_INLINE ucs_status_t uct_cuda_copy_ctx_rsc_get(
230230

231231
result = uct_cuda_ctx_get_id(NULL, &ctx_id);
232232
if (result != CUDA_SUCCESS) {
233-
UCT_CUDADRV_LOG(cuCtxGetId, UCS_LOG_LEVEL_ERROR, result);
233+
UCT_CUDADRV_LOG(UCS_LOG_LEVEL_ERROR, cuCtxGetId, result);
234234
status = UCS_ERR_IO_ERROR;
235235
goto err_pop_and_release;
236236
}
@@ -323,14 +323,14 @@ uct_cuda_copy_post_cuda_async_copy(uct_ep_h tl_ep, void *dst, void *src,
323323
goto out_pop_and_release;
324324
}
325325

326-
status = UCT_CUDADRV_FUNC_LOG_ERR(
327-
cuMemcpyAsync((CUdeviceptr)dst, (CUdeviceptr)src, length, *stream));
326+
status = UCT_CUDADRV_FUNC_LOG_ERR(cuMemcpyAsync, (CUdeviceptr)dst,
327+
(CUdeviceptr)src, length, *stream);
328328
if (ucs_unlikely(UCS_OK != status)) {
329329
goto err_mpool_put;
330330
}
331331

332-
status = UCT_CUDADRV_FUNC_LOG_ERR(
333-
cuEventRecord(cuda_event->event, *stream));
332+
status = UCT_CUDADRV_FUNC_LOG_ERR(cuEventRecord, cuda_event->event,
333+
*stream);
334334
if (ucs_unlikely(UCS_OK != status)) {
335335
goto err_mpool_put;
336336
}
@@ -422,12 +422,12 @@ static UCS_F_ALWAYS_INLINE ucs_status_t uct_cuda_copy_ep_rma_short(
422422
goto out_pop_and_release;
423423
}
424424

425-
status = UCT_CUDADRV_FUNC_LOG_ERR(cuMemcpyAsync(dst, src, length, *stream));
425+
status = UCT_CUDADRV_FUNC_LOG_ERR(cuMemcpyAsync, dst, src, length, *stream);
426426
if (ucs_unlikely(status != UCS_OK)) {
427427
goto out_pop_and_release;
428428
}
429429

430-
status = UCT_CUDADRV_FUNC_LOG_ERR(cuStreamSynchronize(*stream));
430+
status = UCT_CUDADRV_FUNC_LOG_ERR(cuStreamSynchronize, *stream);
431431

432432
out_pop_and_release:
433433
uct_cuda_ctx_pop_and_release(ctx.cuda_device, ctx.cuda_context);

0 commit comments

Comments
 (0)