Skip to content

[Offload] Add MPI Plugin #90890

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion offload/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ if (NOT LIBOMPTARGET_LLVM_INCLUDE_DIRS)
message(FATAL_ERROR "Missing definition for LIBOMPTARGET_LLVM_INCLUDE_DIRS")
endif()

set(LIBOMPTARGET_ALL_PLUGIN_TARGETS amdgpu cuda host)
set(LIBOMPTARGET_ALL_PLUGIN_TARGETS amdgpu cuda mpi host)
set(LIBOMPTARGET_PLUGINS_TO_BUILD "all" CACHE STRING
"Semicolon-separated list of plugins to use: cuda, amdgpu, host or \"all\".")

Expand Down Expand Up @@ -182,6 +182,7 @@ set (LIBOMPTARGET_ALL_TARGETS "${LIBOMPTARGET_ALL_TARGETS} powerpc64-ibm-linux-g
set (LIBOMPTARGET_ALL_TARGETS "${LIBOMPTARGET_ALL_TARGETS} powerpc64-ibm-linux-gnu-LTO")
set (LIBOMPTARGET_ALL_TARGETS "${LIBOMPTARGET_ALL_TARGETS} x86_64-pc-linux-gnu")
set (LIBOMPTARGET_ALL_TARGETS "${LIBOMPTARGET_ALL_TARGETS} x86_64-pc-linux-gnu-LTO")
set (LIBOMPTARGET_ALL_TARGETS "${LIBOMPTARGET_ALL_TARGETS} x86_64-pc-linux-gnu-mpi")
set (LIBOMPTARGET_ALL_TARGETS "${LIBOMPTARGET_ALL_TARGETS} nvptx64-nvidia-cuda")
set (LIBOMPTARGET_ALL_TARGETS "${LIBOMPTARGET_ALL_TARGETS} nvptx64-nvidia-cuda-LTO")
set (LIBOMPTARGET_ALL_TARGETS "${LIBOMPTARGET_ALL_TARGETS} nvptx64-nvidia-cuda-JIT-LTO")
Expand Down
96 changes: 96 additions & 0 deletions offload/plugins-nextgen/mpi/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
##===----------------------------------------------------------------------===##
#
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
# See https://llvm.org/LICENSE.txt for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#
##===----------------------------------------------------------------------===##
#
# Build a plugin for a MPI machine if available.
#
##===----------------------------------------------------------------------===##

# Looking for MPI...
find_package(MPI QUIET)


if(NOT(CMAKE_SYSTEM_PROCESSOR MATCHES "(x86_64)|(ppc64le)$" AND CMAKE_SYSTEM_NAME MATCHES "Linux"))
libomptarget_say("Not building MPI offloading plugin: only support MPI in Linux x86_64 or ppc64le hosts.")
return()
elseif(NOT LIBOMPTARGET_DEP_LIBFFI_FOUND)
libomptarget_say("Not building MPI offloading plugin: libffi dependency not found.")
return()
elseif(NOT MPI_CXX_FOUND)
libomptarget_say("Not building MPI offloading plugin: MPI not found in system.")
return()
endif()

libomptarget_say("Building MPI NextGen offloading plugin.")

# Create the library and add the default arguments.
add_target_library(omptarget.rtl.mpi MPI)

target_sources(omptarget.rtl.mpi PRIVATE
src/EventSystem.cpp
src/rtl.cpp
)

if(FFI_STATIC_LIBRARIES)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really want to be rid of libffi #88738. I ran into a snag doing it but I think it's better to just hack around what I have and try to improve it later.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we even use ffi here anywhere?

target_link_libraries(omptarget.rtl.mpi PRIVATE FFI::ffi_static)
else()
target_link_libraries(omptarget.rtl.mpi PRIVATE FFI::ffi)
endif()

target_link_libraries(omptarget.rtl.mpi PRIVATE
MPI::MPI_CXX
)

# Add include directories
target_include_directories(omptarget.rtl.mpi PRIVATE
${LIBOMPTARGET_INCLUDE_DIR})

# Set C++20 as the target standard for this plugin.
set_target_properties(omptarget.rtl.mpi
PROPERTIES
CXX_STANDARD 20
CXX_STANDARD_REQUIRED ON)

# Configure testing for the MPI plugin.
list(APPEND LIBOMPTARGET_TESTED_PLUGINS "omptarget.rtl.mpi")
# Report to the parent scope that we are building a plugin for MPI.
set(LIBOMPTARGET_TESTED_PLUGINS "${LIBOMPTARGET_TESTED_PLUGINS}" PARENT_SCOPE)

# Define the target specific triples and ELF machine values.
set(LIBOMPTARGET_SYSTEM_TARGETS
"${LIBOMPTARGET_SYSTEM_TARGETS} x86_64-pc-linux-gnu-mpi" PARENT_SCOPE)

# MPI Device Binary
llvm_add_tool(OPENMP llvm-offload-mpi-device src/EventSystem.cpp src/MPIDeviceMain.cpp)

llvm_update_compile_flags(llvm-offload-mpi-device)

target_link_libraries(llvm-offload-mpi-device PRIVATE
MPI::MPI_CXX
LLVMSupport
omp
)

if(FFI_STATIC_LIBRARIES)
target_link_libraries(llvm-offload-mpi-device PRIVATE FFI::ffi_static)
else()
target_link_libraries(llvm-offload-mpi-device PRIVATE FFI::ffi)
endif()

target_include_directories(llvm-offload-mpi-device PRIVATE
${LIBOMPTARGET_INCLUDE_DIR}
)


set_target_properties(llvm-offload-mpi-device
PROPERTIES
CXX_STANDARD 20
CXX_STANDARD_REQUIRED ON
)

target_compile_definitions(llvm-offload-mpi-device PRIVATE
DEBUG_PREFIX="OFFLOAD MPI DEVICE")
Loading