Skip to content

Conversation

@DominikAdamski
Copy link

@DominikAdamski DominikAdamski commented Oct 21, 2025

Motivation

Reduce linking time by embedding GPU LLVM IR code for Flang runtime.

Technical Details

Modified Flang runtime (added ifdefs to eliminate host-specific code from GPU compilation).

Test Plan

Checked smoke-fort-dev tests with new GPU Flang RT and the old flang_rt.hostdevice.

Test Result

I was able to compile and successfully run tests without flang_rt.hostdevice flag together with: ROCm/aomp#1595

@DominikAdamski DominikAdamski marked this pull request as draft October 21, 2025 12:36
@skganesan008
Copy link
Collaborator

@skganesan008
Copy link
Collaborator

!PSDB

@skganesan008
Copy link
Collaborator

@dpalermo
Copy link

Looks like there are smoke-fort failures in the PSDB related to stop/abort emissary support

[2025-10-21T17:55:32.127Z] flang-gpu-abort: Make Failed
[2025-10-21T17:55:32.127Z] flang-gpu-stop-integer: Make Failed
[2025-10-21T17:55:32.127Z] flang-gpu-stop-string: Make Failed
[2025-10-21T17:55:32.127Z] tgt-abort: Make Failed
[2025-10-21T17:55:32.127Z] tgt-stop: Make Failed
ld.lld: error: undefined symbol: _FortranAAbort
ld.lld: error: undefined symbol: _FortranAStopStatement
ld.lld: error: undefined symbol: _FortranAStopStatementText
ld.lld: error: undefined symbol: _FortranAAbort
ld.lld: error: undefined symbol: _FortranAStopStatement

@skganesan008
Copy link
Collaborator

@z1-cciauto
Copy link
Collaborator

@z1-cciauto
Copy link
Collaborator

@z1-cciauto
Copy link
Collaborator

@z1-cciauto
Copy link
Collaborator

@z1-cciauto
Copy link
Collaborator

def : Flag<["-"], "nocudalib">, Alias<no_offloadlib>;
def gpulibc : Flag<["-"], "gpulibc">, Visibility<[ClangOption, CC1Option, FlangOption, FC1Option]>,
HelpText<"Link the LLVM C Library for GPUs">;
def nogpuflangrt : Flag<["-"], "nogpuflangrt">, Visibility<[ClangOption, CC1Option, FlangOption, FC1Option]>;
Copy link
Collaborator

Choose a reason for hiding this comment

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

could we use the -f form of the flag ? and have both
-fno-gpuflangrt and -fgpurflangrt ?

Copy link
Author

Choose a reason for hiding this comment

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

done

@z1-cciauto
Copy link
Collaborator

@z1-cciauto
Copy link
Collaborator

option(FLANG_RT_ENABLE_STATIC "Build Flang-RT as a static library." ON)
option(FLANG_RT_EMBED_GPU_LLVM_IR "Build Flang-RT as GPU LLVM IR library" ON)
if (FLANG_RT_EMBED_GPU_LLVM_IR)
add_compile_definitions(EMBED_FLANG_RT_GPU_LLVM_IR)

Choose a reason for hiding this comment

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

Prefer 'target_compile_defintions' in 'add_flangrt_library' which is preferred in "modern CMake" style because it avoids global changes.

Copy link
Author

Choose a reason for hiding this comment

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

done

@DominikAdamski DominikAdamski marked this pull request as ready for review December 3, 2025 13:14
@DominikAdamski DominikAdamski changed the title [WIP] Changes required for embedded GPU LLVM IR Flang runtime [Flang-RT] Changes required for embedded GPU LLVM IR Flang runtime Dec 3, 2025
Copy link

@Meinersbur Meinersbur left a comment

Choose a reason for hiding this comment

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

LGTM

target_link_libraries(PluginCommon PRIVATE flang_rt.runtime
-L${CMAKE_BINARY_DIR}/../../lib -L${CMAKE_INSTALL_PREFIX}/lib)
endif()

Choose a reason for hiding this comment

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

[nit] please keep the diff to upstream as small as possible

if (LLVM_INCLUDE_EXAMPLES)
add_subdirectory(examples)
endif ()

Choose a reason for hiding this comment

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

[nit] please keep the diff to upstream as small as possible

@DominikAdamski
Copy link
Author

Patch merged as: #757 .

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.

6 participants