Skip to content

[Flang][OpenMP] Support PRINT or WRITE() from an offloaded/target region #166338

@hakostra

Description

@hakostra

OpenMP offloading support in Flang is maturing rapidly, and one thing I really miss is the support for writing to the terminal form a target region (for debugging purposes). Most OpenMP-Fortran compilers support at least the PRINT *, Nvidia nvfortran can also do WRITE(*, *) from a target region.

As of now this simple example fails in flang (targeting and Nvidia platform):

PROGRAM reproducer
    IMPLICIT NONE

    !$omp target
    PRINT *, "Hello, world!"
    !$omp end target
END PROGRAM reproducer

This does not link, and the error is:

$ flang -O2 -fopenmp -fopenmp-targets=nvptx64 -fopenmp-version=52 print-test-simple.F90 
warning: OpenMP support for version 52 in flang is still incomplete
warning: OpenMP support for version 52 in flang is still incomplete
warning: OpenMP support for version 52 in flang is still incomplete
nvlink warning : Stack size for entry function '__omp_offloading_10301_3200092__QQmain_l4' cannot be statically determined
nvlink error   : Undefined reference to 'abort' in '/tmp/a.out.nvptx64.sm_89-1a481e-a037f4.cubin'
nvlink error   : Undefined reference to '_ZNSt8__detail9__variant12__gen_vtableIvOZNS0_16_Variant_storageILb0EJSt9monostateN7Fortran7runtime2io18OpenStatementStateENS6_19CloseStatementStateENS6_33ExternalFormattedIoStatementStateILNS6_9DirectionE0EcEENS9_ILSA_1EcEENS6_28ExternalListIoStatementStateILSA_0EEENSD_ILSA_1EEENS6_35ExternalUnformattedIoStatementStateILSA_0EEENSG_ILSA_1EEENS6_16InquireUnitStateENS6_28ExternalMiscIoStatementStateENS6_25ErroneousIoStatementStateEEE8_M_resetEvEUlOT_E_JRSt7variantIJS3_S7_S8_SB_SC_SE_SF_SH_SI_SJ_SK_SL_EEEE9_S_vtableE' in '/tmp/a.out.nvptx64.sm_89-1a481e-a037f4.cubin'
/opt/llvm/llvm-project/install/bin/clang-nvlink-wrapper: error: 'nvlink' failed
clang: error: nvlink command failed with exit code 1 (use -v to see invocation)
/opt/llvm/llvm-project/install/bin/clang-linker-wrapper: error: 'clang' failed
flang-22: error: linker command failed with exit code 1 (use -v to see invocation)

I use the following flang version pulled and built from Git today:

$ flang --version
flang version 22.0.0git (https://github.com/llvm/llvm-project.git 25a592cc63f0a252b8ae980271d0767a342a0a77)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /opt/llvm/llvm-project/install/bin

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions