hipfort icon indicating copy to clipboard operation
hipfort copied to clipboard

[Issue]: Hipfc doesn't appear to be passing on optimization level flags

Open drtpotter opened this issue 6 months ago • 2 comments

Problem Description

I noticed that when running a verbose compilation with hipfc it doesn't appear to be passing on desired optimization flags (-O1, -O2, -O3) to backend compilers.

Operating System

Ubuntu 22.04.4 LTS (Jammy Jellyfish)

CPU

AMD Ryzen 6800H

GPU

AMD Radeon Pro VII

ROCm Version

ROCm 6.2.0

ROCm Component

hipfort

Steps to Reproduce

Install rocm 6.2.0 then

git clone https://github.com/pelagos-consulting/Hipfort_Course.git cd Hipfort_Course/L4_Build_Hipfort_Software

Then do a dry run compilation with:

hipfc -vv -n hip_utils.f90 math_utils.f90 tensoradd_hip_fptr.f90 kernel_code.cpp -o tensoradd.exe

It produces this output

/opt/rocm-6.2.0/bin/hipcc -v -fno-gpu-rdc -fPIC --offload-arch=gfx1035 -c kernel_code.cpp -o /tmp/hipfc-tmp-12156/hipcc.o /opt/rocm-6.2.0/bin/../lib/llvm/bin/flang -v -cpp -I/opt/rocm-6.2.0/bin/..//include/hipfort/amdgcn hip_utils.f90 math_utils.f90 tensoradd_hip_fptr.f90 /tmp/hipfc-tmp-12156/hipcc.o -L/opt/rocm-6.2.0/bin/..//lib -lhipfort-amdgcn -L/opt/rocm-6.2.0/lib -lamdhip64 -Wl,-rpath=/opt/rocm-6.2.0/lib -lstdc++ -o tensoradd.exe #Info: Done

Despite the hipfc help string advertising this option, passing in -O3 to hipfc seems to make no difference to the flags being passed on to flang or hipcc. For example running

hipfc -O3 -vv -n hip_utils.f90 math_utils.f90 tensoradd_hip_fptr.f90 kernel_code.cpp -o tensoradd.exe

produces this output

/opt/rocm-6.2.0/bin/hipcc -v -fno-gpu-rdc -fPIC --offload-arch=gfx1035 -c kernel_code.cpp -o /tmp/hipfc-tmp-12226/hipcc.o /opt/rocm-6.2.0/bin/../lib/llvm/bin/flang -v -cpp -I/opt/rocm-6.2.0/bin/..//include/hipfort/amdgcn hip_utils.f90 math_utils.f90 tensoradd_hip_fptr.f90 /tmp/hipfc-tmp-12226/hipcc.o -L/opt/rocm-6.2.0/bin/..//lib -lhipfort-amdgcn -L/opt/rocm-6.2.0/lib -lamdhip64 -Wl,-rpath=/opt/rocm-6.2.0/lib -lstdc++ -o tensoradd.exe

This is a problem because in the absence of explicitly defined optimisation flags the default optimisation level for compilers is quite low ("e.g -O0" for gfortran). Users won't be able to benefit from code optimisations when compiling with hipfc. A check of the hipfc script shows that the optimisation level is being read in correctly into the variable FORTOPT, however nothing further is actually done with that variable in passing on the optimisation level to hipcc or flang or gfortran.

(Optional for Linux users) Output of /opt/rocm/bin/rocminfo --support

No response

Additional Information

No response

drtpotter avatar Aug 21 '24 03:08 drtpotter