Skip to content

Commit

Permalink
TOOLS: use separate cuda alloc in perftest
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergei-Lebedev committed Nov 7, 2023
1 parent 21a424f commit 0124bbd
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
24 changes: 24 additions & 0 deletions tools/perf/ucc_pt_coll.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,29 @@
*/

#include "ucc_pt_coll.h"
#include "ucc_pt_cuda.h"

ucc_status_t ucc_pt_alloc(ucc_mc_buffer_header_t **h_ptr, size_t len,
ucc_memory_type_t mem_type)
{
ucc_status_t status;
int cuda_st;

if (mem_type == UCC_MEMORY_TYPE_CUDA) {
*h_ptr = new ucc_mc_buffer_header_t;
(*h_ptr)->mt = UCC_MEMORY_TYPE_CUDA;
cuda_st = ucc_pt_cudaMalloc(&((*h_ptr)->addr), len);
if (cuda_st != 0) {
return UCC_ERR_NO_RESOURCE;
}
cuda_st = ucc_pt_cudaMemset((*h_ptr)->addr, 0, len);
if (cuda_st != 0) {
ucc_pt_cudaFree((*h_ptr)->addr);
delete *h_ptr;
return UCC_ERR_NO_RESOURCE;
}
return UCC_OK;
}

status = ucc_mc_alloc(h_ptr, len, mem_type);
if (status != UCC_OK) {
Expand All @@ -26,6 +44,12 @@ ucc_status_t ucc_pt_alloc(ucc_mc_buffer_header_t **h_ptr, size_t len,

ucc_status_t ucc_pt_free(ucc_mc_buffer_header_t *h_ptr)
{
if (h_ptr->mt == UCC_MEMORY_TYPE_CUDA) {
ucc_pt_cudaFree(h_ptr->addr);
delete h_ptr;
return UCC_OK;
}

return ucc_mc_free(h_ptr);
}

Expand Down
3 changes: 3 additions & 0 deletions tools/perf/ucc_pt_cuda.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ void ucc_pt_cuda_init(void)
LOAD_CUDA_SYM("cudaGetErrorString", getErrorString);
LOAD_CUDA_SYM("cudaStreamCreateWithFlags", streamCreateWithFlags);
LOAD_CUDA_SYM("cudaStreamDestroy", streamDestroy);
LOAD_CUDA_SYM("cudaMalloc", cudaMalloc);
LOAD_CUDA_SYM("cudaFree", cudaFree);
LOAD_CUDA_SYM("cudaMemset", cudaMemset);

ucc_pt_cuda_iface.available = 1;
}
30 changes: 30 additions & 0 deletions tools/perf/ucc_pt_cuda.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ typedef struct ucc_pt_cuda_iface {
int (*streamCreateWithFlags)(cudaStream_t *stream, unsigned int flags);
int (*streamDestroy)(cudaStream_t stream);
char* (*getErrorString)(int err);
int (*cudaMalloc)(void **devptr, size_t size);
int (*cudaFree)(void *devptr);
int (*cudaMemset)(void *devptr, int value, size_t count);
} ucc_pt_cuda_iface_t;

extern ucc_pt_cuda_iface_t ucc_pt_cuda_iface;
Expand Down Expand Up @@ -74,4 +77,31 @@ static inline int ucc_pt_cudaStreamDestroy(cudaStream_t stream)
return 0;
}

static inline int ucc_pt_cudaMalloc(void **devptr, size_t size)
{
if (!ucc_pt_cuda_iface.available) {
return 1;
}
CUDA_CHECK(ucc_pt_cuda_iface.cudaMalloc(devptr, size));
return 0;
}

static inline int ucc_pt_cudaFree(void *devptr)
{
if (!ucc_pt_cuda_iface.available) {
return 1;
}
CUDA_CHECK(ucc_pt_cuda_iface.cudaFree(devptr));
return 0;
}

static inline int ucc_pt_cudaMemset(void *devptr, int value, size_t count)
{
if (!ucc_pt_cuda_iface.available) {
return 1;
}
CUDA_CHECK(ucc_pt_cuda_iface.cudaMemset(devptr, value, count));
return 0;
}

#endif

0 comments on commit 0124bbd

Please sign in to comment.