Skip to content

Commit 93f70d8

Browse files
committed
Add multiprocess IPC test for CUDA provider
1 parent 87ec365 commit 93f70d8

File tree

6 files changed

+152
-2
lines changed

6 files changed

+152
-2
lines changed

test/CMakeLists.txt

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -455,8 +455,6 @@ if(LINUX)
455455
add_umf_ipc_test(TEST ipc_file_prov_fsdax)
456456
endif()
457457

458-
# TODO add IPC tests for CUDA
459-
460458
if(UMF_BUILD_GPU_TESTS AND UMF_BUILD_LEVEL_ZERO_PROVIDER)
461459
build_umf_test(
462460
NAME
@@ -486,6 +484,36 @@ if(LINUX)
486484
PRIVATE ${LEVEL_ZERO_INCLUDE_DIRS})
487485
add_umf_ipc_test(TEST ipc_level_zero_prov SRC_DIR providers)
488486
endif()
487+
488+
if(UMF_BUILD_GPU_TESTS AND UMF_BUILD_CUDA_PROVIDER)
489+
build_umf_test(
490+
NAME
491+
ipc_cuda_prov_consumer
492+
SRCS
493+
providers/ipc_cuda_prov_consumer.c
494+
common/ipc_common.c
495+
providers/ipc_cuda_prov_common.c
496+
providers/cuda_helpers.cpp
497+
LIBS
498+
cuda
499+
${UMF_UTILS_FOR_TEST})
500+
build_umf_test(
501+
NAME
502+
ipc_cuda_prov_producer
503+
SRCS
504+
providers/ipc_cuda_prov_producer.c
505+
common/ipc_common.c
506+
providers/ipc_cuda_prov_common.c
507+
providers/cuda_helpers.cpp
508+
LIBS
509+
cuda
510+
${UMF_UTILS_FOR_TEST})
511+
target_include_directories(umf_test-ipc_cuda_prov_producer
512+
PRIVATE ${CUDA_INCLUDE_DIRS})
513+
target_include_directories(umf_test-ipc_cuda_prov_consumer
514+
PRIVATE ${CUDA_INCLUDE_DIRS})
515+
add_umf_ipc_test(TEST ipc_cuda_prov SRC_DIR providers)
516+
endif()
489517
else()
490518
message(STATUS "IPC tests are supported on Linux only - skipping")
491519
endif()

test/providers/ipc_cuda_prov.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#
2+
# Copyright (C) 2024 Intel Corporation
3+
#
4+
# Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT.
5+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
#
7+
8+
#!/bin/bash
9+
10+
set -e
11+
12+
# port should be a number from the range <1024, 65535>
13+
PORT=$(( 1024 + ( $$ % ( 65535 - 1024 ))))
14+
15+
UMF_LOG_VAL="level:debug;flush:debug;output:stderr;pid:yes"
16+
17+
echo "Starting ipc_cuda_prov CONSUMER on port $PORT ..."
18+
UMF_LOG=$UMF_LOG_VAL ./umf_test-ipc_cuda_prov_consumer $PORT &
19+
20+
echo "Waiting 1 sec ..."
21+
sleep 1
22+
23+
echo "Starting ipc_cuda_prov PRODUCER on port $PORT ..."
24+
UMF_LOG=$UMF_LOG_VAL ./umf_test-ipc_cuda_prov_producer $PORT

test/providers/ipc_cuda_prov_common.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* Copyright (C) 2024 Intel Corporation
3+
*
4+
* Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT.
5+
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
*/
7+
8+
#include "ipc_cuda_prov_common.h"
9+
#include "cuda_helpers.h"
10+
11+
#include <umf/providers/provider_cuda.h>
12+
13+
#include <stdio.h>
14+
15+
void memcopy(void *dst, const void *src, size_t size, void *context) {
16+
cuda_memory_provider_params_t *cu_params =
17+
(cuda_memory_provider_params_t *)context;
18+
int ret = cuda_copy(cu_params->cuda_context_handle,
19+
cu_params->cuda_device_handle, dst, src, size);
20+
if (ret != 0) {
21+
fprintf(stderr, "cuda_copy failed with error %d\n", ret);
22+
}
23+
}

test/providers/ipc_cuda_prov_common.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/*
2+
* Copyright (C) 2024 Intel Corporation
3+
*
4+
* Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT.
5+
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
*/
7+
8+
#ifndef UMF_TEST_IPC_CUDA_PROV_COMMON_H
9+
#define UMF_TEST_IPC_CUDA_PROV_COMMON_H
10+
11+
#include <stddef.h>
12+
13+
void memcopy(void *dst, const void *src, size_t size, void *context);
14+
15+
#endif // UMF_TEST_IPC_CUDA_PROV_COMMON_H
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Copyright (C) 2024 Intel Corporation
3+
*
4+
* Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT.
5+
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
*/
7+
8+
#include <stdio.h>
9+
#include <stdlib.h>
10+
11+
#include <umf/providers/provider_cuda.h>
12+
13+
#include "cuda_helpers.h"
14+
#include "ipc_common.h"
15+
#include "ipc_cuda_prov_common.h"
16+
17+
int main(int argc, char *argv[]) {
18+
if (argc < 2) {
19+
fprintf(stderr, "usage: %s <port> [shm_name]\n", argv[0]);
20+
return -1;
21+
}
22+
23+
int port = atoi(argv[1]);
24+
25+
cuda_memory_provider_params_t cu_params =
26+
create_cuda_prov_params(UMF_MEMORY_TYPE_DEVICE);
27+
28+
return run_consumer(port, umfCUDAMemoryProviderOps(), &cu_params, memcopy,
29+
&cu_params);
30+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Copyright (C) 2024 Intel Corporation
3+
*
4+
* Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT.
5+
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
*/
7+
8+
#include <stdio.h>
9+
#include <stdlib.h>
10+
11+
#include <umf/providers/provider_cuda.h>
12+
13+
#include "cuda_helpers.h"
14+
#include "ipc_common.h"
15+
#include "ipc_cuda_prov_common.h"
16+
17+
int main(int argc, char *argv[]) {
18+
if (argc < 2) {
19+
fprintf(stderr, "usage: %s <port> [shm_name]\n", argv[0]);
20+
return -1;
21+
}
22+
23+
int port = atoi(argv[1]);
24+
25+
cuda_memory_provider_params_t cu_params =
26+
create_cuda_prov_params(UMF_MEMORY_TYPE_DEVICE);
27+
28+
return run_producer(port, umfCUDAMemoryProviderOps(), &cu_params, memcopy,
29+
&cu_params);
30+
}

0 commit comments

Comments
 (0)