Skip to content
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

[SYCL] Link and include LLVM utility headers in SYCL library #16763

Draft
wants to merge 8 commits into
base: sycl
Choose a base branch
from

Conversation

steffenlarsen
Copy link
Contributor

These changes propose that the SYCL runtime library privately links against LLVM to avoid the need for replicating common utility code. In the initial version we can use this to remove the property-set names, making it more safely consistent.

These changes intend to aid the implementation of loading SYCL-based kernel binary files at runtime.

These changes propose that the SYCL runtime library privately links
against LLVM to avoid the need for replicating common utility code. In
the initial version we can use this to remove the property-set names,
making it more safely consistent.

These changes intend to aid the implementation of loading SYCL-based
kernel binary files at runtime.

Signed-off-by: Larsen, Steffen <[email protected]>
@steffenlarsen
Copy link
Contributor Author

@jopperm @bader @sommerlukas @cperkinsintel @AlexeySachkov @uditagarwal97 @sergey-semenov @aelovikov-intel - I realize that this change can be somewhat controversial, so please raise any concerns and we can discuss them.

Signed-off-by: Larsen, Steffen <[email protected]>
Signed-off-by: Larsen, Steffen <[email protected]>
Signed-off-by: Larsen, Steffen <[email protected]>
@@ -147,6 +145,18 @@ function(add_sycl_rt_library LIB_NAME LIB_OBJ_NAME)
PRIVATE OpenCL-Headers
)

# Link with LLVMSupport and LLVMObject for shared utilities.
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm skeptical about linking LLVM libraries with SYCL RT. I had a similar discussion with @stdale-intel and @AlexeySachkov while implementing device image compression (like: #15124 (comment)) and one of the major concerns was potential version mismatch between LLVM libraries linked to SYCL RT and other components like ocloc.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I spoke to @AlexeySachkov about this and I agree that it could potentially be a problem if we were to link with it dynamically, but I doubt we would ever want to do that. We already ship enough libraries, and I don't imagine ocloc links dynamically with the LLVM libraries either. The only reason we want to link with these are to have some common utilities, so the binary size increase should also be minor as we link privately and won't leak any of the symbols from the libraries.

Copy link
Contributor

Choose a reason for hiding this comment

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

Linking LLVM libraries statically still can be a problem if we export any LLVM symbols from the SYCL runtime library. AFAIK, we have some measures to force SYCL runtime to export only explicitly marked symbols, but I would explicitly test compatibly with the projects linking against both SYCL runtime and LLVM libraries.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Linking LLVM libraries statically still can be a problem if we export any LLVM symbols from the SYCL runtime library. AFAIK, we have some measures to force SYCL runtime to export only explicitly marked symbols, but I would explicitly test compatibly with the projects linking against both SYCL runtime and LLVM libraries.

I do believe that should be avoided due to the PRIVATE linkage. We should also see it in our ABI symbols tests if there were any new symbols added to the binary after this link, but it seems to not be the case on neither Windows nor Linux.

@@ -147,6 +145,18 @@ function(add_sycl_rt_library LIB_NAME LIB_OBJ_NAME)
PRIVATE OpenCL-Headers
)

# Link with LLVMSupport and LLVMObject for shared utilities.
add_dependencies(${LIB_OBJ_NAME} LLVMSupport LLVMObject)
target_include_directories(${LIB_OBJ_NAME} PRIVATE ${LLVM_MAIN_INCLUDE_DIR})
Copy link
Contributor

Choose a reason for hiding this comment

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

Is using PRIVATE keyword here enough to protect us from accidentally including LLVM headers into SYCL headers?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Based on local testing, 384 check-sycl tests start failing with "fatal error: 'llvm/X.h' file not found" if I introduce an include of an LLVM header in the non-source headers.

@cperkinsintel
Copy link
Contributor

Besides PropertySetRegistry are there other LLVM utils you think we might/should leverage in the future?

@steffenlarsen
Copy link
Contributor Author

Besides PropertySetRegistry are there other LLVM utils you think we might/should leverage in the future?

A future extension is going to introduce a file-format that both the runtime and the compiler tooling will need to be able to read/write. Being able to share the logic will simplify the code immensely.

Copy link
Contributor

@sommerlukas sommerlukas left a comment

Choose a reason for hiding this comment

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

The general idea of sharing headers between compiler and runtime to avoid duplication that requires manual maintenance is good, I think.

Did you measure increase in library size? When we initially added sycl-jit, the library binary of libsycl.so was a concern, which is why we eventually switched to loading it dynamically.

target_link_libraries(${LIB_OBJ_NAME} PRIVATE LLVMSupport LLVMObject)
target_compile_definitions(${LIB_OBJ_NAME} PRIVATE LLVM_DISABLE_ABI_BREAKING_CHECKS_ENFORCING=1)

if (NOT MSVC)
Copy link
Contributor

Choose a reason for hiding this comment

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

IIRC, you can mark headers as SYSTEM in CMake to avoid warning being emitted for them. We do this with the LLVM headers in SYCL-JIT: https://github.com/intel/llvm/blob/sycl/sycl-jit/jit-compiler/CMakeLists.txt#L57-L63

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh neat! Much better. 😄

@steffenlarsen
Copy link
Contributor Author

Did you measure increase in library size? When we initially added sycl-jit, the library binary of libsycl.so was a concern, which is why we eventually switched to loading it dynamically.

I did initially try to, but must have failed. It does indeed seem like the library size increases quite a bit (~4x). However, if we add

    target_link_options(${LIB_NAME} PRIVATE -Wl,--gc-sections)

that seems to drop down to only an increase in size of about 8%. I can play with a few more options to see if there's more of it we can cut. I also need to check what the effect is on Windows and if there's a corresponding option there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants