-
Notifications
You must be signed in to change notification settings - Fork 11.2k
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
[Offload] Do not link every target for JIT #92013
Conversation
@llvm/pr-subscribers-backend-amdgpu Author: Joseph Huber (jhuber6) ChangesSummary: Full diff: https://github.com/llvm/llvm-project/pull/92013.diff 4 Files Affected:
diff --git a/offload/plugins-nextgen/CMakeLists.txt b/offload/plugins-nextgen/CMakeLists.txt
index d1079f8a3e9cc..b8426b7816518 100644
--- a/offload/plugins-nextgen/CMakeLists.txt
+++ b/offload/plugins-nextgen/CMakeLists.txt
@@ -13,10 +13,10 @@
# Common interface to handle creating a plugin library.
set(common_dir ${CMAKE_CURRENT_SOURCE_DIR}/common)
add_subdirectory(common)
-function(add_target_library target_name lib_name)
+function(add_target_library target_name lib_name llvm_components)
add_llvm_library(${target_name} STATIC
LINK_COMPONENTS
- ${LLVM_TARGETS_TO_BUILD}
+ ${llvm_components}
AggressiveInstCombine
Analysis
BinaryFormat
diff --git a/offload/plugins-nextgen/amdgpu/CMakeLists.txt b/offload/plugins-nextgen/amdgpu/CMakeLists.txt
index 738183f8945ed..968532907b28c 100644
--- a/offload/plugins-nextgen/amdgpu/CMakeLists.txt
+++ b/offload/plugins-nextgen/amdgpu/CMakeLists.txt
@@ -28,7 +28,11 @@ if(NOT (CMAKE_SYSTEM_PROCESSOR MATCHES "(x86_64)|(ppc64le)|(aarch64)$" AND CMAKE
endif()
# Create the library and add the default arguments.
-add_target_library(omptarget.rtl.amdgpu AMDGPU)
+if("AMDGPU" IN_LIST LLVM_TARGETS_TO_BUILD)
+ add_target_library(omptarget.rtl.amdgpu AMDGPU AMDGPU)
+else()
+ add_target_library(omptarget.rtl.amdgpu AMDGPU "")
+endif()
target_sources(omptarget.rtl.amdgpu PRIVATE src/rtl.cpp)
target_include_directories(omptarget.rtl.amdgpu PRIVATE
diff --git a/offload/plugins-nextgen/cuda/CMakeLists.txt b/offload/plugins-nextgen/cuda/CMakeLists.txt
index dd684bb223431..d56eaa43c374d 100644
--- a/offload/plugins-nextgen/cuda/CMakeLists.txt
+++ b/offload/plugins-nextgen/cuda/CMakeLists.txt
@@ -24,7 +24,11 @@ endif()
libomptarget_say("Building CUDA NextGen offloading plugin.")
# Create the library and add the default arguments.
-add_target_library(omptarget.rtl.cuda CUDA)
+if("NVPTX" IN_LIST LLVM_TARGETS_TO_BUILD)
+ add_target_library(omptarget.rtl.cuda CUDA NVPTX)
+else()
+ add_target_library(omptarget.rtl.cuda CUDA "")
+endif()
target_sources(omptarget.rtl.cuda PRIVATE src/rtl.cpp)
diff --git a/offload/plugins-nextgen/host/CMakeLists.txt b/offload/plugins-nextgen/host/CMakeLists.txt
index 72b5681283fe2..92f2677e8a855 100644
--- a/offload/plugins-nextgen/host/CMakeLists.txt
+++ b/offload/plugins-nextgen/host/CMakeLists.txt
@@ -14,7 +14,7 @@ if(CMAKE_SYSTEM_PROCESSOR MATCHES "ppc64le$")
endif()
# Create the library and add the default arguments.
-add_target_library(omptarget.rtl.host ${machine})
+add_target_library(omptarget.rtl.host ${machine} "")
target_sources(omptarget.rtl.host PRIVATE src/rtl.cpp)
|
@llvm/pr-subscribers-offload Author: Joseph Huber (jhuber6) ChangesSummary: Full diff: https://github.com/llvm/llvm-project/pull/92013.diff 4 Files Affected:
diff --git a/offload/plugins-nextgen/CMakeLists.txt b/offload/plugins-nextgen/CMakeLists.txt
index d1079f8a3e9cc..b8426b7816518 100644
--- a/offload/plugins-nextgen/CMakeLists.txt
+++ b/offload/plugins-nextgen/CMakeLists.txt
@@ -13,10 +13,10 @@
# Common interface to handle creating a plugin library.
set(common_dir ${CMAKE_CURRENT_SOURCE_DIR}/common)
add_subdirectory(common)
-function(add_target_library target_name lib_name)
+function(add_target_library target_name lib_name llvm_components)
add_llvm_library(${target_name} STATIC
LINK_COMPONENTS
- ${LLVM_TARGETS_TO_BUILD}
+ ${llvm_components}
AggressiveInstCombine
Analysis
BinaryFormat
diff --git a/offload/plugins-nextgen/amdgpu/CMakeLists.txt b/offload/plugins-nextgen/amdgpu/CMakeLists.txt
index 738183f8945ed..968532907b28c 100644
--- a/offload/plugins-nextgen/amdgpu/CMakeLists.txt
+++ b/offload/plugins-nextgen/amdgpu/CMakeLists.txt
@@ -28,7 +28,11 @@ if(NOT (CMAKE_SYSTEM_PROCESSOR MATCHES "(x86_64)|(ppc64le)|(aarch64)$" AND CMAKE
endif()
# Create the library and add the default arguments.
-add_target_library(omptarget.rtl.amdgpu AMDGPU)
+if("AMDGPU" IN_LIST LLVM_TARGETS_TO_BUILD)
+ add_target_library(omptarget.rtl.amdgpu AMDGPU AMDGPU)
+else()
+ add_target_library(omptarget.rtl.amdgpu AMDGPU "")
+endif()
target_sources(omptarget.rtl.amdgpu PRIVATE src/rtl.cpp)
target_include_directories(omptarget.rtl.amdgpu PRIVATE
diff --git a/offload/plugins-nextgen/cuda/CMakeLists.txt b/offload/plugins-nextgen/cuda/CMakeLists.txt
index dd684bb223431..d56eaa43c374d 100644
--- a/offload/plugins-nextgen/cuda/CMakeLists.txt
+++ b/offload/plugins-nextgen/cuda/CMakeLists.txt
@@ -24,7 +24,11 @@ endif()
libomptarget_say("Building CUDA NextGen offloading plugin.")
# Create the library and add the default arguments.
-add_target_library(omptarget.rtl.cuda CUDA)
+if("NVPTX" IN_LIST LLVM_TARGETS_TO_BUILD)
+ add_target_library(omptarget.rtl.cuda CUDA NVPTX)
+else()
+ add_target_library(omptarget.rtl.cuda CUDA "")
+endif()
target_sources(omptarget.rtl.cuda PRIVATE src/rtl.cpp)
diff --git a/offload/plugins-nextgen/host/CMakeLists.txt b/offload/plugins-nextgen/host/CMakeLists.txt
index 72b5681283fe2..92f2677e8a855 100644
--- a/offload/plugins-nextgen/host/CMakeLists.txt
+++ b/offload/plugins-nextgen/host/CMakeLists.txt
@@ -14,7 +14,7 @@ if(CMAKE_SYSTEM_PROCESSOR MATCHES "ppc64le$")
endif()
# Create the library and add the default arguments.
-add_target_library(omptarget.rtl.host ${machine})
+add_target_library(omptarget.rtl.host ${machine} "")
target_sources(omptarget.rtl.host PRIVATE src/rtl.cpp)
|
@@ -28,7 +28,11 @@ if(NOT (CMAKE_SYSTEM_PROCESSOR MATCHES "(x86_64)|(ppc64le)|(aarch64)$" AND CMAKE | |||
endif() | |||
|
|||
# Create the library and add the default arguments. | |||
add_target_library(omptarget.rtl.amdgpu AMDGPU) | |||
if("AMDGPU" IN_LIST LLVM_TARGETS_TO_BUILD) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why don't we put this logic into add_target_library
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because we shouldn't link against AMDGPU if the user didn't request to build the amdgpu
plugin.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd make this same as the argument LINK_COMPONENTS
of add_llvm_library
, since it is not always required. Besides, given add_target_library
is only for plugin, and only "host" plugin doesn't require that, we can assume almost all plugins need the corresponding target. add_target_library(omptarget.rtl.amdgpu AMDGPU "")
isn't really beautiful. We can even force lib_name
to be the target name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Honestly we should probably rename the amdgpu
plugin to hsa
anyway? Since the important distinction is the runtime, not the target architecture. Potentially in the future we'll have things like OpenCL or Vulkan I guess? Which are supposed to be generic in their own right.
So, what we could do is just target_library(libomptarget.amdgpu AMDGPU)
or something, but I think that might require something else.
You could potentially do this in
In this way, there is no need for changes of each target. Technically it should have been done on |
Thanks for pointing that out, this logic should be updated as well. I want to do this in the plugins individually because we shouldn't link |
But this doesn't work as your expectation because the AMDGPU code is there when you turn the macro on, no matter whether you build it for AMDGPU or NVPTX. If you want to do that, one solution would be to add |
I suppose that's fair. It's easier to just put it there than it is to rework that bit. |
Summary: The offload library supports basic JIT functionality, however we currently link against every single target even though only AMDGPU and NVPTX are supported. This somewhat bloats the dynamic library list, so we should constrain it to what's actually used.
The problem with this patch is, you will end up with undefined symbols if you just link the corresponding target. For example, the LLVM was built with target AMDGPU and NVPTX. So when |
I don't understand, it builds perfectly fine after a clean build? |
Hmm, I was referring to the previous version. The current one looks good. |
Summary:
The offload library supports basic JIT functionality, however we
currently link against every single target even though only AMDGPU and
NVPTX are supported. This somewhat bloats the dynamic library list, so
we should constrain it to what's actually used.