Skip to content

Commit 2546ba4

Browse files
GuilhermeValarinicl3to
authored andcommitted
[Offload] Fix queryAsyncImpl to match MPI progress model
This commit also refactors the MPI dependency in CMakeLists
1 parent ef4f22e commit 2546ba4

File tree

2 files changed

+24
-34
lines changed

2 files changed

+24
-34
lines changed

offload/plugins-nextgen/mpi/CMakeLists.txt

Lines changed: 6 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -13,26 +13,14 @@
1313
# Looking for MPI...
1414
find_package(MPI QUIET)
1515

16-
set(LIBOMPTARGET_DEP_MPI_FOUND ${MPI_CXX_FOUND})
17-
set(LIBOMPTARGET_DEP_MPI_LIBRARIES ${MPI_CXX_LIBRARIES})
18-
set(LIBOMPTARGET_DEP_MPI_INCLUDE_DIRS ${MPI_CXX_INCLUDE_DIRS})
19-
set(LIBOMPTARGET_DEP_MPI_COMPILE_FLAGS ${MPI_CXX_COMPILE_FLAGS})
20-
set(LIBOMPTARGET_DEP_MPI_LINK_FLAGS ${MPI_CXX_LINK_FLAGS})
21-
22-
mark_as_advanced(
23-
LIBOMPTARGET_DEP_MPI_FOUND
24-
LIBOMPTARGET_DEP_MPI_LIBRARIES
25-
LIBOMPTARGET_DEP_MPI_INCLUDE_DIRS
26-
LIBOMPTARGET_DEP_MPI_COMPILE_FLAGS
27-
LIBOMPTARGET_DEP_MPI_LINK_FLAGS)
2816

2917
if(NOT(CMAKE_SYSTEM_PROCESSOR MATCHES "(x86_64)|(ppc64le)$" AND CMAKE_SYSTEM_NAME MATCHES "Linux"))
3018
libomptarget_say("Not building MPI offloading plugin: only support MPI in Linux x86_64 or ppc64le hosts.")
3119
return()
3220
elseif(NOT LIBOMPTARGET_DEP_LIBFFI_FOUND)
3321
libomptarget_say("Not building MPI offloading plugin: libffi dependency not found.")
3422
return()
35-
elseif(NOT LIBOMPTARGET_DEP_MPI_FOUND)
23+
elseif(NOT MPI_CXX_FOUND)
3624
libomptarget_say("Not building MPI offloading plugin: MPI not found in system.")
3725
return()
3826
endif()
@@ -53,9 +41,8 @@ else()
5341
target_link_libraries(omptarget.rtl.mpi PRIVATE FFI::ffi)
5442
endif()
5543

56-
target_link_libraries(omptarget.rtl.mpi PRIVATE
57-
${LIBOMPTARGET_DEP_MPI_LIBRARIES}
58-
${LIBOMPTARGET_DEP_MPI_LINK_FLAGS}
44+
target_link_libraries(omptarget.rtl.mpi PRIVATE
45+
MPI::MPI_CXX
5946
)
6047

6148
# Add include directories
@@ -65,13 +52,9 @@ target_include_directories(omptarget.rtl.mpi PRIVATE
6552
# Install plugin under the lib destination folder.
6653
install(TARGETS omptarget.rtl.mpi
6754
LIBRARY DESTINATION "${OFFLOAD_INSTALL_LIBDIR}")
68-
set_target_properties(omptarget.rtl.mpi PROPERTIES
55+
set_target_properties(omptarget.rtl.mpi PROPERTIES
6956
INSTALL_RPATH "$ORIGIN" BUILD_RPATH "$ORIGIN:${CMAKE_CURRENT_BINARY_DIR}/..")
7057

71-
if(LIBOMPTARGET_DEP_MPI_COMPILE_FLAGS)
72-
set_target_properties(omptarget.rtl.mpi PROPERTIES
73-
COMPILE_FLAGS "${LIBOMPTARGET_DEP_MPI_COMPILE_FLAGS}")
74-
endif()
7558

7659
# Set C++20 as the target standard for this plugin.
7760
set_target_properties(omptarget.rtl.mpi
@@ -94,8 +77,7 @@ llvm_add_tool(OPENMP llvm-offload-mpi-device src/EventSystem.cpp src/MPIDeviceMa
9477
llvm_update_compile_flags(llvm-offload-mpi-device)
9578

9679
target_link_libraries(llvm-offload-mpi-device PRIVATE
97-
${LIBOMPTARGET_DEP_MPI_LIBRARIES}
98-
${LIBOMPTARGET_DEP_MPI_LINK_FLAGS}
80+
MPI::MPI_CXX
9981
LLVMSupport
10082
omp
10183
)
@@ -108,20 +90,14 @@ endif()
10890

10991
target_include_directories(llvm-offload-mpi-device PRIVATE
11092
${LIBOMPTARGET_INCLUDE_DIR}
111-
${LIBOMPTARGET_DEP_MPI_INCLUDE_DIRS}
11293
)
11394

114-
if(LIBOMPTARGET_DEP_MPI_COMPILE_FLAGS)
115-
set_target_properties(llvm-offload-mpi-device PROPERTIES
116-
COMPILE_FLAGS "${LIBOMPTARGET_DEP_MPI_COMPILE_FLAGS}"
117-
)
118-
endif()
11995

12096
set_target_properties(llvm-offload-mpi-device
12197
PROPERTIES
12298
CXX_STANDARD 20
12399
CXX_STANDARD_REQUIRED ON
124100
)
125101

126-
target_compile_definitions(llvm-offload-mpi-device PRIVATE
102+
target_compile_definitions(llvm-offload-mpi-device PRIVATE
127103
DEBUG_PREFIX="OFFLOAD MPI DEVICE")

offload/plugins-nextgen/mpi/src/rtl.cpp

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <cstring>
1717
#include <optional>
1818
#include <string>
19+
#include <list>
1920

2021
#include "GlobalHandler.h"
2122
#include "OpenMP/OMPT/Callback.h"
@@ -40,7 +41,7 @@ struct MPIKernelTy;
4041
class MPIGlobalHandlerTy;
4142

4243
// TODO: Should this be defined inside the EventSystem?
43-
using MPIEventQueue = SmallVector<EventTy>;
44+
using MPIEventQueue = std::list<EventTy>;
4445
using MPIEventQueuePtr = MPIEventQueue *;
4546

4647
/// Class implementing the MPI device images properties.
@@ -489,9 +490,22 @@ struct MPIDeviceTy : public GenericDeviceTy {
489490
Error queryAsyncImpl(__tgt_async_info &AsyncInfo) override {
490491
auto *Queue = reinterpret_cast<MPIEventQueue *>(AsyncInfo.Queue);
491492

492-
// Returns success when there are pending operations in the AsyncInfo.
493-
if (!Queue->empty() && !Queue->back().done())
494-
return Plugin::success();
493+
// Returns success when there are pending operations in AsyncInfo, moving
494+
// forward through the events on the queue until it is fully completed.
495+
while (!Queue->empty()) {
496+
auto &Event = Queue->front();
497+
498+
Event.resume();
499+
500+
if (!Event.done())
501+
return Plugin::success();
502+
503+
if (auto Error = Event.getError(); Error)
504+
return Plugin::error("Event failed during query. %s\n",
505+
toString(std::move(Error)).c_str());
506+
507+
Queue->pop_front();
508+
}
495509

496510
// Once the queue is synchronized, return it to the pool and reset the
497511
// AsyncInfo. This is to make sure that the synchronization only works

0 commit comments

Comments
 (0)