Skip to content

Commit c990986

Browse files
committed
Add multiprocess test for L0 IPC
1 parent af74d76 commit c990986

9 files changed

+938
-350
lines changed

test/CMakeLists.txt

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,14 +219,14 @@ if(UMF_BUILD_GPU_TESTS AND UMF_BUILD_LEVEL_ZERO_PROVIDER)
219219
# dlopen)
220220
add_umf_test(
221221
NAME provider_level_zero
222-
SRCS providers/provider_level_zero.cpp
222+
SRCS providers/provider_level_zero.cpp providers/level_zero_helpers.cpp
223223
LIBS ${UMF_UTILS_FOR_TEST} ze_loader)
224224
target_include_directories(umf_test-provider_level_zero
225225
PRIVATE ${LEVEL_ZERO_INCLUDE_DIRS})
226226

227227
add_umf_test(
228228
NAME provider_level_zero_dlopen
229-
SRCS providers/provider_level_zero.cpp
229+
SRCS providers/provider_level_zero.cpp providers/level_zero_helpers.cpp
230230
LIBS ${UMF_UTILS_FOR_TEST})
231231
target_compile_definitions(umf_test-provider_level_zero_dlopen
232232
PUBLIC USE_DLOPEN=1)
@@ -322,6 +322,35 @@ if(LINUX)
322322
common/ipc_os_prov_common.c)
323323
add_umf_ipc_test(TEST ipc_os_prov_anon_fd)
324324
add_umf_ipc_test(TEST ipc_os_prov_shm)
325+
if(UMF_BUILD_GPU_TESTS AND UMF_BUILD_LEVEL_ZERO_PROVIDER)
326+
build_umf_test(
327+
NAME
328+
ipc_level_zero_prov_consumer
329+
SRCS
330+
providers/ipc_level_zero_prov_consumer.c
331+
common/ipc_common.c
332+
providers/ipc_level_zero_prov_common.c
333+
providers/level_zero_helpers.cpp
334+
LIBS
335+
ze_loader
336+
${UMF_UTILS_FOR_TEST})
337+
build_umf_test(
338+
NAME
339+
ipc_level_zero_prov_producer
340+
SRCS
341+
providers/ipc_level_zero_prov_producer.c
342+
common/ipc_common.c
343+
providers/ipc_level_zero_prov_common.c
344+
providers/level_zero_helpers.cpp
345+
LIBS
346+
ze_loader
347+
${UMF_UTILS_FOR_TEST})
348+
target_include_directories(umf_test-ipc_level_zero_prov_producer
349+
PRIVATE ${LEVEL_ZERO_INCLUDE_DIRS})
350+
target_include_directories(umf_test-ipc_level_zero_prov_consumer
351+
PRIVATE ${LEVEL_ZERO_INCLUDE_DIRS})
352+
add_umf_ipc_test(TEST ipc_level_zero_prov SRC_DIR providers)
353+
endif()
325354
else()
326355
message(STATUS "IPC tests are supported on Linux only - skipping")
327356
endif()

test/providers/ipc_level_zero_prov.sh

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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+
# The ipc_level_zero_prov test requires using pidfd_getfd(2)
16+
# to obtain a duplicate of another process's file descriptor.
17+
# Permission to duplicate another process's file descriptor
18+
# is governed by a ptrace access mode PTRACE_MODE_ATTACH_REALCREDS check (see ptrace(2))
19+
# that can be changed using the /proc/sys/kernel/yama/ptrace_scope interface.
20+
PTRACE_SCOPE_FILE="/proc/sys/kernel/yama/ptrace_scope"
21+
VAL=0
22+
if [ -f $PTRACE_SCOPE_FILE ]; then
23+
PTRACE_SCOPE_VAL=$(cat $PTRACE_SCOPE_FILE)
24+
if [ $PTRACE_SCOPE_VAL -ne $VAL ]; then
25+
echo "SKIP: ptrace_scope is not set to 0 (classic ptrace permissions) - skipping the test"
26+
exit 125 # skip code defined in CMakeLists.txt
27+
fi
28+
fi
29+
30+
UMF_LOG_VAL="level:debug;flush:debug;output:stderr;pid:yes"
31+
32+
echo "Starting ipc_level_zero_prov CONSUMER on port $PORT ..."
33+
UMF_LOG=$UMF_LOG_VAL ./umf_test-ipc_level_zero_prov_consumer $PORT &
34+
35+
echo "Waiting 1 sec ..."
36+
sleep 1
37+
38+
echo "Starting ipc_level_zero_prov PRODUCER on port $PORT ..."
39+
UMF_LOG=$UMF_LOG_VAL ./umf_test-ipc_level_zero_prov_producer $PORT
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+
#include "ipc_level_zero_prov_common.h"
9+
#include "level_zero_helpers.h"
10+
11+
#include <umf/providers/provider_level_zero.h>
12+
13+
#include <stdio.h>
14+
15+
void memcopy(void *dst, const void *src, size_t size, void *context) {
16+
level_zero_memory_provider_params_t *l0_params =
17+
(level_zero_memory_provider_params_t *)context;
18+
int ret =
19+
level_zero_copy(l0_params->level_zero_context_handle,
20+
l0_params->level_zero_device_handle, dst, src, size);
21+
if (ret != 0) {
22+
fprintf(stderr, "level_zero_copy failed with error %d\n", ret);
23+
}
24+
}
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 IPC_LEVEL_ZERO_PROV_COMMON_H
9+
#define IPC_LEVEL_ZERO_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 // IPC_LEVEL_ZERO_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_level_zero.h>
12+
13+
#include "ipc_common.h"
14+
#include "ipc_level_zero_prov_common.h"
15+
#include "level_zero_helpers.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+
level_zero_memory_provider_params_t l0_params =
26+
create_level_zero_prov_params(UMF_MEMORY_TYPE_DEVICE);
27+
28+
return run_consumer(port, umfLevelZeroMemoryProviderOps(), &l0_params,
29+
memcopy, &l0_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_level_zero.h>
12+
13+
#include "ipc_common.h"
14+
#include "ipc_level_zero_prov_common.h"
15+
#include "level_zero_helpers.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+
level_zero_memory_provider_params_t l0_params =
26+
create_level_zero_prov_params(UMF_MEMORY_TYPE_DEVICE);
27+
28+
return run_producer(port, umfLevelZeroMemoryProviderOps(), &l0_params,
29+
memcopy, &l0_params);
30+
}

0 commit comments

Comments
 (0)