Cross-compilation with NVIDIA Compilers

Hey folks,
I am trying to use NVIDIA compilers to build Docker image on 2 platforms - amd64 and arm64. The build is done on Apple Silicon (arm64):

# Use nvidia/nvhpc as base image
FROM nvcr.io/nvidia/nvhpc:23.7-devel-cuda12.2-ubuntu22.04

# Install of utilities and libraries
RUN apt-get update && apt-get install -y \
    build-essential \
    wget \
    unzip \
    vim \
    curl

# Install of Git, OpenSSH, python, pip and make
RUN apt-get update && apt-get install -y git openssh-client make  python3-pip

#install parallel hdf5
WORKDIR /opt
RUN wget https://support.hdfgroup.org/ftp/HDF5/releases/hdf5-1.12/hdf5-1.12.0/src/hdf5-1.12.0.tar.gz && \
    tar -xzf hdf5-1.12.0.tar.gz && \
    cd hdf5-1.12.0 && \
    CC=nvc CXX=nvc++ FC=nvfortran F90=nvfortran ./configure \
    --prefix=/opt/hdf5 --enable-fortran --enable-shared \
    CFLAGS="-O3 -fPIC" FFLAGS="-O3 -fPIC" CXXFLAGS="-O3 -fPIC" FCFLAGS="-O3 -fPIC" --host=x86_64-linux-gnu && \
    make -j 8 && \
    make install && \
    rm ../hdf5-1.12.0.tar.gz

As a result, I get the following error during compilation: checking maximum decimal

precision for C... configure: error: in `/opt/hdf5-1.12.0':
configure: error: cannot run test program while cross compiling
See `config.log' for more details

The error occurs only for the amd64 platform, everything works fine for arm64.
I assume it’s a compiler issue and not a specific application issue (I’ve run cross-compilation on the same scheme before with other compilers and no problems occurred).
Do you have any suggestions as to what might be wrong and how to fix it?

Hi skliavin,

Having no experience with what you’re doing, I’m not sure how much I can help, but can you give more details from the config.log on what configure is doing when it’s getting the error?

Is it trying to run the amd64 binary on arm64? I wouldn’t expect this to work unless it rsh’s the binary to a different system. Does the HDF5 configure do something different for the other compilers?

Now we don’t support fat binaries (i.e. when both targets are merged into a single binary). So if that’s how the other compilers are working, this method probably wont with with the NVHPC compilers.

-Mat

Hey Mat,
Thanks for the response!
I’m sorry, I can’t provide the config.log. the problem is that when I try to perform the same actions inside a running Docker container, I have everything running fine (which makes sense - it’s running the arm64). And if we run the config with cross-compilation (i.e. via docker buildx), then config.log cannot be accessed because the compilation is failed (or I don’t know how to do it). So below I provide you with a file with the output I get during the configuration (hope this will be useful).
I have a feeling that it is trying to run some tests, but it fails because of cross-compilation. As far as I understand, there should be no differences between the compilers, in the sense that HDF5 configure does the same operations. Here is the configure file itself.
I also provide a link to the hdf5 project itself (you might find it useful as well).
About fat binaries, unfortunately I can’t say because I don’t know if it’s used or not.
config_output (24.0 KB)
configure (1.1 MB)

Best,
Sergei

Hi Sergei,

Since I’ve never tried cross-compiling, I did a web search and found a similar issue posted on HDF5’s user forum:

Granted, the post is a bit old so I don’t know if the issue is still current, but it does indicate that during the configuration, HDF runs programs to gather systems information. So if you build a binary for amd64 but are on a arm64 platform, it’s not going to run. Look like you need either set some environment variables to work around the issue, or have configure run the binaries remotely on a system with the same target architecture.

Hopefully this post gives you some answers.

-Mat

Hey Mat,
Thanks so much for the link. After searching some more, it turns out that it might be due to cross-compilation issues with HDF5 itself - maybe they haven’t fully customized everything to work with NVIDIA compilers yet (based on HDF5 1.14.1-1.5.9 is missing arm64 · Issue #1370 · bytedeco/javacpp-presets · GitHub). Thank you for your help, I’ll post to this discussion if I learn anything new (might be helpful to someone).

1 Like