Skip to content

Commit 119aa97

Browse files
committed
Move examples to their own subdirectories
Ref: #427 Signed-off-by: Lukasz Dorau <[email protected]>
1 parent 9be120a commit 119aa97

File tree

14 files changed

+160
-145
lines changed

14 files changed

+160
-145
lines changed

CMakeLists.txt

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -521,16 +521,7 @@ endif()
521521
install(FILES ${CMAKE_SOURCE_DIR}/LICENSE.TXT
522522
DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/doc/${PROJECT_NAME}/")
523523

524-
install(
525-
FILES examples/basic/gpu_shared_memory.c
526-
examples/basic/utils_level_zero.h
527-
examples/basic/basic.c
528-
examples/basic/ipc_level_zero.c
529-
examples/basic/ipc_ipcapi_anon_fd.sh
530-
examples/basic/ipc_ipcapi_consumer.c
531-
examples/basic/ipc_ipcapi_producer.c
532-
examples/basic/ipc_ipcapi_shm.sh
533-
DESTINATION "${CMAKE_INSTALL_DOCDIR}/examples")
524+
install(DIRECTORY examples DESTINATION "${CMAKE_INSTALL_DOCDIR}")
534525

535526
# Add the include directory and the headers target to the install.
536527
install(DIRECTORY "${PROJECT_SOURCE_DIR}/include/"

examples/CMakeLists.txt

Lines changed: 8 additions & 130 deletions
Original file line numberDiff line numberDiff line change
@@ -2,73 +2,14 @@
22
# Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT.
33
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
44

5-
# NOTE: the basic example is always built, even if the TBB required by the
6-
# Scalable Pool is not detected by CMake. If the TBB is not detected during the
7-
# execution of the basic example, the user will receive a corresponding error
8-
# message.
9-
if(NOT UMF_POOL_SCALABLE_ENABLED)
10-
message(
11-
WARNING
12-
"The Basic Example is built but TBB required by Scalable Pool it "
13-
"uses was not found by CMake. Make sure TBB is added to the default "
14-
"library search path before running it.")
15-
endif()
16-
set(EXAMPLE_NAME umf_example_basic)
17-
18-
add_umf_executable(
19-
NAME ${EXAMPLE_NAME}
20-
SRCS basic/basic.c
21-
LIBS umf hwloc)
22-
23-
target_include_directories(
24-
${EXAMPLE_NAME} PRIVATE ${UMF_CMAKE_SOURCE_DIR}/src/utils
25-
${UMF_CMAKE_SOURCE_DIR}/include)
26-
27-
target_link_directories(${EXAMPLE_NAME} PRIVATE ${LIBHWLOC_LIBRARY_DIRS})
28-
29-
if(UMF_POOL_SCALABLE_ENABLED)
30-
add_test(
31-
NAME ${EXAMPLE_NAME}
32-
COMMAND ${EXAMPLE_NAME}
33-
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
34-
35-
set_tests_properties(${EXAMPLE_NAME} PROPERTIES LABELS "example")
36-
37-
if(WINDOWS)
38-
# append PATH to DLLs
39-
set_property(TEST ${EXAMPLE_NAME} PROPERTY ENVIRONMENT_MODIFICATION
40-
"${DLL_PATH_LIST}")
41-
endif()
42-
endif()
5+
# basic example
6+
add_subdirectory(basic)
437

8+
# gpu_shared_memory example
449
if(UMF_BUILD_GPU_EXAMPLES
4510
AND UMF_BUILD_LIBUMF_POOL_DISJOINT
4611
AND UMF_BUILD_LEVEL_ZERO_PROVIDER)
47-
set(EXAMPLE_NAME umf_example_gpu_shared_memory)
48-
49-
add_umf_executable(
50-
NAME ${EXAMPLE_NAME}
51-
SRCS basic/gpu_shared_memory.c
52-
LIBS disjoint_pool ze_loader umf)
53-
54-
target_include_directories(
55-
${EXAMPLE_NAME} PRIVATE ${UMF_CMAKE_SOURCE_DIR}/src/utils
56-
${UMF_CMAKE_SOURCE_DIR}/include)
57-
58-
target_link_directories(${EXAMPLE_NAME} PRIVATE ${LIBHWLOC_LIBRARY_DIRS})
59-
60-
add_test(
61-
NAME ${EXAMPLE_NAME}
62-
COMMAND ${EXAMPLE_NAME}
63-
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
64-
65-
set_tests_properties(${EXAMPLE_NAME} PROPERTIES LABELS "example")
66-
67-
if(WINDOWS)
68-
# append PATH to DLLs
69-
set_property(TEST ${EXAMPLE_NAME} PROPERTY ENVIRONMENT_MODIFICATION
70-
"${DLL_PATH_LIST}")
71-
endif()
12+
add_subdirectory(gpu_shared_memory)
7213
else()
7314
message(
7415
STATUS
@@ -77,85 +18,22 @@ else()
7718
"to be turned ON - skipping")
7819
endif()
7920

80-
# TODO: it looks like there is some problem with IPC implementation in Level
81-
# Zero on windows
21+
# ipc_level_zero example TODO: it looks like there is some problem with IPC
22+
# implementation in Level Zero on windows
8223
if(UMF_BUILD_GPU_EXAMPLES
8324
AND UMF_BUILD_LIBUMF_POOL_DISJOINT
8425
AND UMF_BUILD_LEVEL_ZERO_PROVIDER
8526
AND LINUX)
86-
set(EXAMPLE_NAME umf_example_ipc_level_zero)
87-
88-
add_umf_executable(
89-
NAME ${EXAMPLE_NAME}
90-
SRCS basic/ipc_level_zero.c
91-
LIBS disjoint_pool ze_loader umf)
92-
93-
target_include_directories(
94-
${EXAMPLE_NAME}
95-
PRIVATE ${LEVEL_ZERO_INCLUDE_DIRS} ${UMF_CMAKE_SOURCE_DIR}/src/utils
96-
${UMF_CMAKE_SOURCE_DIR}/include)
97-
98-
target_link_directories(${EXAMPLE_NAME} PRIVATE ${LIBHWLOC_LIBRARY_DIRS})
99-
100-
add_test(
101-
NAME ${EXAMPLE_NAME}
102-
COMMAND ${EXAMPLE_NAME}
103-
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
104-
105-
set_tests_properties(${EXAMPLE_NAME} PROPERTIES LABELS "example")
106-
107-
if(WINDOWS)
108-
# append PATH to DLLs
109-
set_property(TEST ${EXAMPLE_NAME} PROPERTY ENVIRONMENT_MODIFICATION
110-
"${DLL_PATH_LIST}")
111-
endif()
27+
add_subdirectory(ipc_level_zero)
11228
else()
11329
message(
11430
STATUS
11531
"IPC Level 0 example requires UMF_BUILD_GPU_EXAMPLES, UMF_BUILD_LEVEL_ZERO_PROVIDER and UMF_BUILD_LIBUMF_POOL_DISJOINT to be turned ON - skipping"
11632
)
11733
endif()
11834

119-
function(build_umf_ipc_example name)
120-
set(BASE_NAME ${name})
121-
set(EXAMPLE_NAME umf_example_${BASE_NAME})
122-
123-
foreach(loop_var IN ITEMS "producer" "consumer")
124-
set(EX_NAME ${EXAMPLE_NAME}_${loop_var})
125-
add_umf_executable(
126-
NAME ${EX_NAME}
127-
SRCS basic/${BASE_NAME}_${loop_var}.c
128-
LIBS umf)
129-
130-
target_include_directories(
131-
${EX_NAME} PRIVATE ${UMF_CMAKE_SOURCE_DIR}/src/utils
132-
${UMF_CMAKE_SOURCE_DIR}/include)
133-
134-
target_link_directories(${EX_NAME} PRIVATE ${LIBHWLOC_LIBRARY_DIRS})
135-
endforeach(loop_var)
136-
endfunction()
137-
138-
function(add_umf_ipc_example script)
139-
set(EXAMPLE_NAME umf_example_${script})
140-
141-
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/basic/${script}.sh
142-
DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
143-
144-
add_test(
145-
NAME ${EXAMPLE_NAME}
146-
COMMAND ${script}.sh
147-
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
148-
149-
set_tests_properties(${EXAMPLE_NAME} PROPERTIES LABELS "example")
150-
if(NOT UMF_TESTS_FAIL_ON_SKIP)
151-
set_tests_properties(${EXAMPLE_NAME} PROPERTIES SKIP_RETURN_CODE 125)
152-
endif()
153-
endfunction()
154-
15535
if(LINUX)
156-
build_umf_ipc_example(ipc_ipcapi)
157-
add_umf_ipc_example(ipc_ipcapi_anon_fd)
158-
add_umf_ipc_example(ipc_ipcapi_shm)
36+
add_subdirectory(ipc_ipcapi)
15937
else()
16038
message(
16139
STATUS

examples/basic/CMakeLists.txt

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Copyright (C) 2024 Intel Corporation
2+
# Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT.
3+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4+
5+
# NOTE: the basic example is always built, even if the TBB required by the
6+
# Scalable Pool is not detected by CMake. If the TBB is not detected during the
7+
# execution of the basic example, the user will receive a corresponding error
8+
# message.
9+
if(NOT UMF_POOL_SCALABLE_ENABLED)
10+
message(
11+
WARNING
12+
"The Basic Example is built but TBB required by Scalable Pool it "
13+
"uses was not found by CMake. Make sure TBB is added to the default "
14+
"library search path before running it.")
15+
endif()
16+
set(EXAMPLE_NAME umf_example_basic)
17+
18+
add_umf_executable(
19+
NAME ${EXAMPLE_NAME}
20+
SRCS basic.c
21+
LIBS umf hwloc)
22+
23+
target_include_directories(
24+
${EXAMPLE_NAME} PRIVATE ${UMF_CMAKE_SOURCE_DIR}/src/utils
25+
${UMF_CMAKE_SOURCE_DIR}/include)
26+
27+
target_link_directories(${EXAMPLE_NAME} PRIVATE ${LIBHWLOC_LIBRARY_DIRS})
28+
29+
if(UMF_POOL_SCALABLE_ENABLED)
30+
add_test(
31+
NAME ${EXAMPLE_NAME}
32+
COMMAND ${EXAMPLE_NAME}
33+
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
34+
35+
set_tests_properties(${EXAMPLE_NAME} PROPERTIES LABELS "example")
36+
37+
if(WINDOWS)
38+
# append PATH to DLLs
39+
set_property(TEST ${EXAMPLE_NAME} PROPERTY ENVIRONMENT_MODIFICATION
40+
"${DLL_PATH_LIST}")
41+
endif()
42+
endif()
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Copyright (C) 2024 Intel Corporation
2+
# Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT.
3+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4+
5+
set(EXAMPLE_NAME umf_example_gpu_shared_memory)
6+
7+
add_umf_executable(
8+
NAME ${EXAMPLE_NAME}
9+
SRCS gpu_shared_memory.c
10+
LIBS disjoint_pool ze_loader umf)
11+
12+
target_include_directories(
13+
${EXAMPLE_NAME} PRIVATE ${UMF_CMAKE_SOURCE_DIR}/src/utils
14+
${UMF_CMAKE_SOURCE_DIR}/include)
15+
16+
target_link_directories(${EXAMPLE_NAME} PRIVATE ${LIBHWLOC_LIBRARY_DIRS})
17+
18+
add_test(
19+
NAME ${EXAMPLE_NAME}
20+
COMMAND ${EXAMPLE_NAME}
21+
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
22+
23+
set_tests_properties(${EXAMPLE_NAME} PROPERTIES LABELS "example")
24+
25+
if(WINDOWS)
26+
# append PATH to DLLs
27+
set_property(TEST ${EXAMPLE_NAME} PROPERTY ENVIRONMENT_MODIFICATION
28+
"${DLL_PATH_LIST}")
29+
endif()
File renamed without changes.

examples/ipc_ipcapi/CMakeLists.txt

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Copyright (C) 2024 Intel Corporation
2+
# Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT.
3+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4+
5+
function(build_umf_ipc_example name)
6+
set(BASE_NAME ${name})
7+
set(EXAMPLE_NAME umf_example_${BASE_NAME})
8+
9+
foreach(loop_var IN ITEMS "producer" "consumer")
10+
set(EX_NAME ${EXAMPLE_NAME}_${loop_var})
11+
add_umf_executable(
12+
NAME ${EX_NAME}
13+
SRCS ${BASE_NAME}_${loop_var}.c
14+
LIBS umf)
15+
16+
target_include_directories(
17+
${EX_NAME} PRIVATE ${UMF_CMAKE_SOURCE_DIR}/src/utils
18+
${UMF_CMAKE_SOURCE_DIR}/include)
19+
20+
target_link_directories(${EX_NAME} PRIVATE ${LIBHWLOC_LIBRARY_DIRS})
21+
endforeach(loop_var)
22+
endfunction()
23+
24+
function(add_umf_ipc_example script)
25+
set(EXAMPLE_NAME umf_example_${script})
26+
27+
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/${script}.sh
28+
DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
29+
30+
add_test(
31+
NAME ${EXAMPLE_NAME}
32+
COMMAND ${script}.sh
33+
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
34+
35+
set_tests_properties(${EXAMPLE_NAME} PROPERTIES LABELS "example")
36+
if(NOT UMF_TESTS_FAIL_ON_SKIP)
37+
set_tests_properties(${EXAMPLE_NAME} PROPERTIES SKIP_RETURN_CODE 125)
38+
endif()
39+
endfunction()
40+
41+
build_umf_ipc_example(ipc_ipcapi)
42+
add_umf_ipc_example(ipc_ipcapi_anon_fd)
43+
add_umf_ipc_example(ipc_ipcapi_shm)

0 commit comments

Comments
 (0)