Skip to content

Latest commit

 

History

History

fortran

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 

AMD Next Gen Fortran Compiler - User Guide

Overview

This user guide provides instructions for obtaining the pre-production build of the AMD Next Generation Fortran Compiler as well as general information like usage, known issues, and system requirements. The latest preview of the compiler is available through the following link:

https://repo.radeon.com/rocm/misc/flang/

The latest release is drop 4.2.0. You may obtain any of the supported OS through wget:

wget https://repo.radeon.com/rocm/misc/flang/rocm-afar-6405-drop-4.2.0-rhel.tar.bz2
wget https://repo.radeon.com/rocm/misc/flang/rocm-afar-6405-drop-4.2.0-sles.tar.bz2
wget https://repo.radeon.com/rocm/misc/flang/rocm-afar-6405-drop-4.2.0-ubuntu.tar.bz2

System requirements

The Fortran compiler drops have similar requirements to the official ROCm releases. They can be used on any of the following OS:

CPUs Operating Systems ROCm™ Driver
X86_64 CPU(s) Ubuntu (version >= 22.04)
RHEL 8.x
SLES 15
ROCm Latest

For ROCm installation procedures and validation checks, see:

NOTE: For best performance we recommend ROCm 6.1.2, however we are backward compatible with ROCm 5.7.0 from a functionality standpoint.

Setting up the compiler

Download and untar the desired rocm-afar-<latest version>-<OS>.tar.bz2 file anywhere onto your system:

tar jxf rocm-afar-<latest version>-<OS>.tar.bz2 -C <path to install>

It is then recommended to add <path to install>/rocm-afar-<version>/bin to your PATH and <path to install>/rocm-afar-<version>/lib to LD_LIBRARY_PATH. Setting these allows the prebuilt compiler to work seamlessly with an existing ROCm installation on the system.

Using hipfort

In order to use hipfort, it must be built from source using amdflang since the build provided with ROCm is not compatible with the AMD Next Gen Fortran Compiler. The following set of commands will build hipfort using amdflang.

git clone https://github.com/ROCm/hipfort.git
cd hipfort
mkdir build && cd build
cmake ../ -DHIPFORT_INSTALL_DIR=<install path> -DHIPFORT_BUILD_TYPE=RELEASE -DHIPFORT_COMPILER=$(which amdflang) \
          -DHIPFORT_COMPILER_FLAGS="-ffree-form -cpp" -DHIPFORT_AR=$(which ar) -DHIPFORT_RANLIB=$(which ranlib)
make -j install

NOTE: amdflang in the preproduction release of the AMD Next Gen Fortran Compiler is distinct from amdflang in ROCm, which corresponds to amdflang-legacy in the preproduction release.

The hipfort library can be easily incorporated into GNU Make or CMake build systems. A file Makefile.hipfort is provided in the install at <install path>/share/hipfort/Makefile.hipfort that is intended to be included by other Makefiles. It sets a number of relevant variables for building and linking with hipfort. See the comments in that file for usage instructions. The following CMake targets are provided following find_package(hipfort):

  • hipfort::hip
  • hipfort::roctx
  • hipfort::rocblas
  • hipfort::hipblas
  • hipfort::rocfft
  • hipfort::hipfft
  • hipfort::rocrand
  • hipfort::hiprand
  • hipfort::rocsolver
  • hipfort::hipsolver
  • hipfort::rocsparse
  • hipfort::hipsparse

These can be used to set the correct include paths and link lines via target_include_directories and target_link_libraries. Use the library interface target corresponding to each hipfort API that is required.

Usage

  • Compiler driver located in bin/amdflang.
  • Compiler flags are generally gfortran compatible. Use --help to see full list of supported flags.

AMD GPU related flags:

-fopenmp --offload-arch=gfx90a      Compile OpenMP target directives for a given GPU (e.g. gfx90a/MI250)
-fdo-concurrent-parallel=<value>    Try to map `do concurrent` loops to OpenMP (on host or device)
                                        value: none, host, device
-fopenmp-force-usm                  Force behavior as if the user specified pragma omp requires unified_shared_memory

Default data precision/conversion:

-fdefault-double-8              Set the default double precision kind to an 8 byte wide type
-fdefault-integer-8             Set the default integer and logical kind to an 8 byte wide type
-fdefault-real-8                Set the default real kind to an 8 byte wide type
-fconvert=<value>               Set endian conversion of data for unformatted files
                                    value: big-endian, little-endian, native

Source form (determined by file extension by default):

-ffree-form                     Process source files in free form
-ffixed-form                    Process source files in fixed form
-ffixed-line-length=<value>     Use <value> as character line width in fixed mode

Alternate directory selection:

--gcc-toolchain=...             Specify a directory where Clang can find 'include' and 'lib*'
--gcc-install-dir=...           Use GCC installation in the specified directory.
--rocm-path=...                 ROCm installation path.
-frtlib-add-rpath               Add -rpath with architecture-specific resource directory to the linker flags.
-fno-rtlib-add-rpath            Don't add -rpath with architecture-specific resource directory to the linker flags.
-resource-dir=...               Resource directory for use with -frtlib-add-rpath

Other:

--help                          See all supported options

Known issues

  • OpenMP atomic on complex operations currently not supported (work in progress)
  • REAL kind=2,3,10,16 types are not yet supported (work in progress)
  • When compiling for offload, add -lFortranRuntimeHostDevice if you see unresolved symbols such as:
error: undefined symbol: _FortranAAssign

Note that this is not added to the link line by default as calling too much of the runtime from device can result in lower performance. Seeing these undefined symbols gives the user an indication that the target region is calling something in the Fortran runtime which could result in performance issues. Adding the FortranRuntimeHostDevice library will allow the program to link and run without further modification to the user's program.

Reporting issues

Bugs and other issues can be reported to AMD's fork of the LLVM project. When reporting an issue please create a minimal reproducer and clearly describe the cause. A good reproducer often has the following characteristics:

  1. Dependencies on external libraries are removed
  2. Code exists in a single or small number of files

All bug reports should also include:

  1. The version of the compiler where the issue can be reproduced
  2. The complete output of any error (an additional abbreviated message may be added for clarity)
  3. Directions capturing all compiler and executable invocations that reproduce the issue

Disclaimer

PRE-PRODUCTION SOFTWARE: The software accessible on this page may be a pre-production version, intended to provide advance access to features that may or may not eventually be included into production version of the software. Accordingly, pre-production software may not be fully functional, may contain errors, and may have reduced or different security, privacy, accessibility, availability, and reliability standards relative to production versions of the software. Use of pre-production software may result in unexpected results, loss of data, project delays or other unpredictable damage or loss. Pre-production software is not intended for use in production, and your use of pre-production software is at your own risk.

Notices and Attribution

© 2022-2024 Advanced Micro Devices, Inc. All rights reserved. AMD, the AMD Arrow logo, Instinct, Radeon Instinct, ROCm, and combinations thereof are trademarks of Advanced Micro Devices, Inc.

All other trademarks and copyrights are property of their respective owners and are only mentioned for informative purposes.