-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Try to compile and run send_recv_usm.cpp to determine whether the MPI implementation is GPU-aware. Enable building the MPI_with_SYCL examples only if at least one backend is found to work with MPI over GPU.
- Loading branch information
Showing
2 changed files
with
65 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,69 @@ | ||
function(run_mpi_test) | ||
cmake_parse_arguments(RUN_MPI_TEST "" "BINARY;BACKEND_SELECTOR" "" ${ARGN}) | ||
execute_process( | ||
COMMAND bash -c "! ONEAPI_DEVICE_SELECTOR=${RUN_MPI_TEST_BACKEND_SELECTOR}:gpu mpirun -n 2 ${RUN_MPI_TEST_BINARY}" | ||
RESULT_VARIABLE MPI_TEST_SUCCEEDED | ||
OUTPUT_QUIET | ||
ERROR_QUIET) | ||
set(MPI_TEST_SUCCEEDED ${MPI_TEST_SUCCEEDED} PARENT_SCOPE) | ||
endfunction() | ||
|
||
function(test_mpi_gpu_support) | ||
set(MPI_TEST_COMPILE_ARGS ${SYCL_FLAGS}) | ||
list(APPEND MPI_TEST_COMPILE_ARGS ${MPI_CXX_COMPILE_OPTIONS} -I${MPI_CXX_INCLUDE_DIRS} ${MPI_CXX_LINK_FLAGS} ${MPI_LIBRARIES}) | ||
list(JOIN MPI_TEST_COMPILE_ARGS " " MPI_TEST_COMPILE_ARGS) | ||
set(MPI_TEST_BINARY ${CMAKE_CURRENT_BINARY_DIR}/test-mpi-gpu) | ||
set(MPI_TEST_COMPILE_CMD "${CMAKE_CXX_COMPILER} ${MPI_TEST_COMPILE_ARGS} -o ${MPI_TEST_BINARY} ${CMAKE_CURRENT_SOURCE_DIR}/send_recv_usm.cpp") | ||
execute_process( | ||
COMMAND bash -c "! ${MPI_TEST_COMPILE_CMD}" | ||
RESULT_VARIABLE MPI_TEST_COMPILE_SUCCEEDED | ||
OUTPUT_QUIET | ||
ERROR_QUIET) | ||
set(MPI_GPU_AWARE 0) | ||
if (${MPI_TEST_COMPILE_SUCCEEDED}) | ||
if (${ENABLE_CUDA}) | ||
run_mpi_test(BINARY ${MPI_TEST_BINARY} BACKEND_SELECTOR "cuda") | ||
if (MPI_TEST_SUCCEEDED) | ||
set(MPI_GPU_AWARE 1) | ||
list(APPEND MPI_AVAILABLE_BACKENDS "CUDA") | ||
endif() | ||
endif() | ||
|
||
if (${ENABLE_HIP}) | ||
run_mpi_test(BINARY ${MPI_TEST_BINARY} BACKEND_SELECTOR "hip") | ||
if (MPI_TEST_SUCCEEDED) | ||
set(MPI_GPU_AWARE 1) | ||
list(APPEND MPI_AVAILABLE_BACKENDS "HIP") | ||
endif() | ||
endif() | ||
|
||
if (${ENABLE_SPIR}) | ||
run_mpi_test(BINARY ${MPI_TEST_BINARY} BACKEND_SELECTOR "level_zero") | ||
if (MPI_TEST_SUCCEEDED) | ||
set(MPI_GPU_AWARE 1) | ||
list(APPEND MPI_AVAILABLE_BACKENDS "Level Zero") | ||
endif() | ||
endif() | ||
endif() | ||
|
||
set(MPI_GPU_AWARE ${MPI_GPU_AWARE} PARENT_SCOPE) | ||
set(MPI_AVAILABLE_BACKENDS ${MPI_AVAILABLE_BACKENDS} PARENT_SCOPE) | ||
endfunction() | ||
|
||
find_package(MPI) | ||
if(NOT MPI_FOUND) | ||
message(STATUS "MPI not found, skipping the MPI_with_SYCL demo") | ||
else() | ||
message(STATUS "Found MPI, configuring the MPI_with_SYCL demo") | ||
foreach(TARGET send_recv_usm send_recv_buff scatter_reduce_gather) | ||
add_executable(${TARGET} ${TARGET}.cpp) | ||
target_compile_options(${TARGET} PUBLIC ${SYCL_FLAGS} ${MPI_INCLUDE_DIRS}) | ||
target_link_options(${TARGET} PUBLIC ${SYCL_FLAGS} ${MPI_LIBRARIES}) | ||
endforeach() | ||
test_mpi_gpu_support() | ||
if (MPI_GPU_AWARE) | ||
list(JOIN MPI_AVAILABLE_BACKENDS ", " MPI_AVAILABLE_BACKENDS) | ||
message(STATUS "Found GPU-aware MPI, configuring the MPI_with_SYCL demo. Available backends: ${MPI_AVAILABLE_BACKENDS}") | ||
foreach(TARGET send_recv_usm send_recv_buff scatter_reduce_gather) | ||
add_executable(${TARGET} ${TARGET}.cpp) | ||
target_compile_options(${TARGET} PUBLIC ${SYCL_FLAGS} -I${MPI_CXX_INCLUDE_DIRS}) | ||
target_link_options(${TARGET} PUBLIC ${SYCL_FLAGS} ${MPI_LIBRARIES}) | ||
endforeach() | ||
else() | ||
message(STATUS "Found MPI which is not GPU-aware - skipping the MPI_with_SYCL demo") | ||
endif() | ||
endif() |