| 1 |
#!/bin/bash |
| 2 |
# |
| 3 |
# hipfc: Wrapper to call fortran compiler with the hipfort interface |
| 4 |
# |
| 5 |
PROGVERSION=X.Y-Z |
| 6 |
|
| 7 |
# Copyright (c) 2020-2022 Advanced Micro Devices, Inc. All rights reserved. |
| 8 |
# [MITx11 License] |
| 9 |
|
| 10 |
# Permission is hereby granted, free of charge, to any person obtaining a copy |
| 11 |
# of this software and associated documentation files (the "Software"), to deal |
| 12 |
# in the Software without restriction, including without limitation the rights |
| 13 |
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 14 |
# copies of the Software, and to permit persons to whom the Software is |
| 15 |
# furnished to do so, subject to the following conditions: |
| 16 |
# |
| 17 |
# The above copyright notice and this permission notice shall be included in |
| 18 |
# all copies or substantial portions of the Software. |
| 19 |
# |
| 20 |
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 21 |
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 22 |
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 23 |
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 24 |
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 25 |
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 26 |
# THE SOFTWARE. |
| 27 |
|
| 28 |
function usage(){ |
| 29 |
/bin/cat 2>&1 <<"EOF" |
| 30 |
|
| 31 |
hipfc: A deprecated wrapper to call Fortran compiler with hipfort |
| 32 |
This script also calls hipcc for non Fortran files. |
| 33 |
|
| 34 |
Users of hipfc are encourged to migrate to a build system |
| 35 |
such as CMake to link with the hipfort libraries, and to |
| 36 |
directly invoke the appropriate compiler for Fortran or HIP |
| 37 |
language source files. |
| 38 |
|
| 39 |
Usage: hipfc [ options ] input-files |
| 40 |
|
| 41 |
Options without values: |
| 42 |
-g Generate debug information |
| 43 |
-version Display version of hipfc then exit |
| 44 |
-v Verbose, just print commands |
| 45 |
-vv Very verbose, pass -v to commands |
| 46 |
-n Dryrun, do nothing, show commands that would execute |
| 47 |
-h Print this help message |
| 48 |
-k Keep temporary files |
| 49 |
-c Compile to object code only |
| 50 |
-lrocsolver Link to rocsolver library |
| 51 |
-lrocsparse Link to rocsparse library |
| 52 |
-lrocblas Link to rocblas library |
| 53 |
-lrocfft Link to rocfft library |
| 54 |
-lrocrand Link to rocrand library |
| 55 |
-lroctx64 Link to roctx library |
| 56 |
-lhipblas Link to hipblas library |
| 57 |
-lhipsparse Link to hipsparse library |
| 58 |
-lhipsolver Link to hipsolver library |
| 59 |
-lhipfft Link to hipfft library |
| 60 |
-lhiprand Link to hiprand library |
| 61 |
-lcusolver Link to cusolver library |
| 62 |
-lcusparse Link to cusparse library |
| 63 |
-lcublas Link to cublas library |
| 64 |
-lcufft Link to cufft library |
| 65 |
-lcurand Link to curand library |
| 66 |
|
| 67 |
Options with values: Defaults |
| 68 |
-hipfort-compiler <bin> $HIPFORT_COMPILER or gfortran |
| 69 |
-hipfort <path> $HIPFORT or _HIPFORT_INSTALL_DIR_ |
| 70 |
-cuda-path <path> $CUDA_PATH or /usr/local/cuda |
| 71 |
-rocm-path <path> $ROCM_PATH or /opt/rocm |
| 72 |
-I <include dir> Provide one directory per -I option |
| 73 |
-O <LLVM opt> LLVM optimization level |
| 74 |
-o <outfilename> Default=a.out |
| 75 |
-t <tdir> Temporary directory for intermediate files |
| 76 |
Default=/tmp/hipfc-tmp-$$ |
| 77 |
--offload-arch=<gputype> Default=<value returned by mygpu utility> |
| 78 |
|
| 79 |
Examples: |
| 80 |
hipfc myapp.f -o myapp /* Compile FORTRAN to create myapp */ |
| 81 |
hipfc myapp.f -o myapp -lrocblas /* Compile FORTRAN with rocblas */ |
| 82 |
hipfc myapp.f kernels.cpp -o myapp /* Compile FORTRAN and c++ and link */ |
| 83 |
hipfc --offload-arch=sm_70 myapp.f -o myapp /* Compile for NVPTX target */ |
| 84 |
|
| 85 |
Instead of these command line options: |
| 86 |
-hipfort, -cuda-path, -hipfort-compiler -rocm-path |
| 87 |
you may alternatively set these environment variables, respectively: |
| 88 |
HIPFORT, CUDA_PATH, HIPFORT_COMPILER, ROCM_PATH |
| 89 |
Command line options take precedence over environment variables. |
| 90 |
|
| 91 |
Copyright (c) 2020-2022 ADVANCED MICRO DEVICES, INC. |
| 92 |
|
| 93 |
EOF |
| 94 |
exit 0 |
| 95 |
} |
| 96 |
|
| 97 |
DEADRC=12 |
| 98 |
|
| 99 |
# Utility Functions |
| 100 |
function do_err(){ |
| 101 |
if [ $NEWTMPDIR ] ; then |
| 102 |
if [ $KEEPTDIR ] ; then |
| 103 |
cp -rp $TMPDIR $OUTDIR |
| 104 |
[ $VERBOSE ] && echo "#Info: Temp files copied to $OUTDIR/$TMPNAME" |
| 105 |
fi |
| 106 |
rm -rf $TMPDIR |
| 107 |
else |
| 108 |
if [ $KEEPTDIR ] ; then |
| 109 |
[ $VERBOSE ] && echo "#Info: Temp files kept in $TMPDIR" |
| 110 |
fi |
| 111 |
fi |
| 112 |
[ $VV ] && echo "#Info: Done" |
| 113 |
exit $1 |
| 114 |
} |
| 115 |
|
| 116 |
function version(){ |
| 117 |
echo $PROGVERSION |
| 118 |
exit 0 |
| 119 |
} |
| 120 |
|
| 121 |
function runcmd(){ |
| 122 |
THISCMD=$1 |
| 123 |
if [ $DRYRUN ] ; then |
| 124 |
echo "$THISCMD" |
| 125 |
else |
| 126 |
[ $VERBOSE ] && echo "$THISCMD" |
| 127 |
$THISCMD |
| 128 |
rc=$? |
| 129 |
if [ $rc != 0 ] ; then |
| 130 |
echo "ERROR: The following command failed with return code $rc." |
| 131 |
echo " $THISCMD" |
| 132 |
do_err $rc |
| 133 |
fi |
| 134 |
fi |
| 135 |
} |
| 136 |
|
| 137 |
function getdname(){ |
| 138 |
local __DIRN=`dirname "$1"` |
| 139 |
if [ "$__DIRN" = "." ] ; then |
| 140 |
__DIRN=$PWD; |
| 141 |
else |
| 142 |
if [ ${__DIRN:0:1} != "/" ] ; then |
| 143 |
if [ ${__DIRN:0:2} == ".." ] ; then |
| 144 |
__DIRN=`dirname $PWD`/${__DIRN:3} |
| 145 |
else |
| 146 |
if [ ${__DIRN:0:1} = "." ] ; then |
| 147 |
__DIRN=$PWD/${__DIRN:2} |
| 148 |
else |
| 149 |
__DIRN=$PWD/$__DIRN |
| 150 |
fi |
| 151 |
fi |
| 152 |
fi |
| 153 |
fi |
| •154 |
echo $__DIRN |
| 155 |
} |
| 156 |
|
| 157 |
function addrocmlib(){ |
| 158 |
name=${1} |
| 159 |
libdir="" |
| 160 |
for dir in "${ROCM_PATH}/lib" "${ROCM_PATH}/lib64" "${ROCM_PATH}/${name}/lib"; do |
| 161 |
for ext in "so" "a"; do |
| 162 |
if [ -f "${dir}/lib${name}.${ext}" ]; then |
| •163 |
libdir=${dir} |
| 164 |
break 2 |
| 165 |
fi |
| 166 |
done |
| 167 |
done |
| 168 |
if [[ -z ${libdir} ]]; then |
| 169 |
echo "ERROR: Library $name could not be found in $ROCM_PATH/lib/ $ROCM_PATH/lib64/ or $ROCM_PATH/$name/lib/" |
| 170 |
echo " Please install $name" |
| 171 |
exit $DEADRC |
| 172 |
fi |
| 173 |
LINKOPTS="$LINKOPTS -L${libdir} -l$name" |
| 174 |
} |
| 175 |
|
| 176 |
function addcudalib(){ |
| 177 |
name=$1 |
| 178 |
libdir=$CUDA_PATH/targets/x86_64-linux/lib |
| 179 |
if [ ! -d ${libdir} ] ; then |
| 180 |
echo "ERROR: Directory $libdir does not exist" |
| 181 |
echo " Please install CUDA" |
| 182 |
exit ${DEADRC} |
| 183 |
fi |
| 184 |
LINKOPTS="${LINKOPTS} -L${libdir} -l${name}" |
| 185 |
} |
| 186 |
|
| 187 |
# -------- The main code starts here ----- |
| 188 |
INCLUDES="" |
| 189 |
PASSTHRUARGS="" |
| 190 |
INPUTFILES="" |
| 191 |
ROCM_LIBS="" |
| 192 |
CUDA_LIBS="" |
| 193 |
# Argument processing |
| 194 |
while [ $# -gt 0 ] ; do |
| 195 |
case "$1" in |
| 196 |
-q) QUIET=true;; |
| 197 |
--quiet) QUIET=true;; |
| 198 |
-k) KEEPTDIR=true;; |
| 199 |
-n) DRYRUN=true;; |
| 200 |
-c) GEN_OBJECT_ONLY=true;; |
| 201 |
-g) GEN_DEBUG=true;; |
| 202 |
-noshared) NOSHARED=true;; |
| 203 |
-cuopts) CUOPTS=$2; shift ;; |
| 204 |
-I) INCLUDES="$INCLUDES -I $2"; shift ;; |
| 205 |
-O) FORTOPT=$2; shift ;; |
| 206 |
-O3) FORTOPT=3 ;; |
| 207 |
-O2) FORTOPT=2 ;; |
| 208 |
-O1) FORTOPT=1 ;; |
| 209 |
-O0) FORTOPT=0 ;; |
| 210 |
-o) OUTFILE=$2; shift ;; |
| 211 |
-t) TMPDIR=$2; shift ;; |
| 212 |
-lrocsolver) ROCM_LIBS+=" rocsolver" ;; |
| 213 |
-lrocsparse) ROCM_LIBS+=" rocsparse" ;; |
| 214 |
-lrocblas) ROCM_LIBS+=" rocblas" ;; |
| 215 |
-lrocfft) ROCM_LIBS+=" rocfft" ;; |
| 216 |
-lhipsparse) ROCM_LIBS+=" hipsparse" ;; |
| 217 |
-lhipblas) ROCM_LIBS+=" hipblas" ;; |
| 218 |
-lhipsolver) ROCM_LIBS+=" hipsolver" ;; |
| 219 |
-lhipfft) ROCM_LIBS+=" hipfft" ;; |
| 220 |
-lhiprand) ROCM_LIBS+=" hiprand" ;; |
| 221 |
-lcusolver) CUDA_LIBS+=" cusolver" ;; |
| 222 |
-lcusparse) CUDA_LIBS+=" cusparse" ;; |
| 223 |
-lcufft) CUDA_LIBS+=" cufft" ;; |
| 224 |
-lcublas) CUDA_LIBS+=" cublas" ;; |
| 225 |
-lcurand) CUDA_LIBS+=" curand" ;; |
| 226 |
-triple) TARGET_TRIPLE=$2; shift ;; |
| 227 |
-cuda-path) CUDA_PATH=$2; shift ;; |
| 228 |
-rocm-path) ROCM_PATH=$2; shift ;; |
| 229 |
-hipfort) HIPFORT=$2; shift ;; |
| 230 |
-hipfort-compiler) HIPFORT_COMPILER=$2; shift ;; |
| 231 |
-h) usage ;; |
| 232 |
-help) usage ;; |
| 233 |
--help) usage ;; |
| 234 |
-version) version ;; |
| 235 |
--version) version ;; |
| 236 |
-v) VERBOSE=true;; |
| 237 |
-vv) VV=true;; |
| 238 |
--) shift ;; |
| 239 |
*) |
| 240 |
if [[ $1 == --offload-arch=* ]]; then |
| 241 |
HIPFORT_GPU=${1/--offload-arch=/}; |
| 242 |
else |
| 243 |
dash=${1:0:1} |
| 244 |
if [ $dash == "-" ] ; then |
| 245 |
PASSTHRUARGS+=" $1" |
| 246 |
else |
| 247 |
INPUTFILES+=" $1" |
| 248 |
fi |
| 249 |
fi |
| 250 |
esac |
| 251 |
shift |
| 252 |
done |
| 253 |
|
| 254 |
fcount=0 |
| 255 |
for __input_file in `echo $INPUTFILES` ; do |
| 256 |
fcount=$(( fcount + 1 )) |
| 257 |
if [ $fcount == 1 ] ; then |
| 258 |
FIRST_INPUT_FILE_NAME=$__input_file |
| 259 |
fi |
| 260 |
if [ ! -e "$__input_file" ] ; then |
| 261 |
echo "ERROR: The file $__input_file does not exist." |
| 262 |
exit $DEADRC |
| 263 |
fi |
| 264 |
done |
| 265 |
if [ -z "$FIRST_INPUT_FILE_NAME" ] ; then |
| 266 |
echo "ERROR: No File specified." |
| 267 |
exit $DEADRC |
| 268 |
fi |
| •269 |
|
| 270 |
cdir=$(getdname $0) |
| 271 |
[ ! -L "$cdir/hipfc" ] || cdir="$(getdname "$(realpath "$cdir/hipfc")")" |
| 272 |
HOW_CALLED=${0##*/} |
| 273 |
|
| 274 |
CUDA_PATH=${CUDA_PATH:-/usr/local/cuda} |
| 275 |
if [ -z ${ROCM_PATH} ]; then |
| 276 |
# No one has set the ROCm path yet |
| 277 |
if [ -d /opt/rocm ]; then |
| 278 |
# A usual place |
| 279 |
ROCM_PATH=/opt/rocm |
| 280 |
else |
| 281 |
# Assume hipconfig is in the PATH |
| 282 |
try_ROCM_PATH=`hipconfig -R` |
| 283 |
if [ $? = 0 ] && [ -d $try_ROCm_PATH ]; then |
| 284 |
ROCM_PATH=$try_ROCM_PATH |
| 285 |
fi |
| 286 |
fi |
| 287 |
fi |
| 288 |
HIP_PLATFORM=${HIP_PLATFORM:-amd} |
| 289 |
|
| 290 |
HIPFORT=${HIPFORT:-$cdir/_HIPFORT_INSTALL_DIR_} |
| 291 |
if [ ! -d $HIPFORT ] ; then |
| 292 |
HIPFORT="$ROCM_PATH/hipfort" |
| 293 |
fi |
| 294 |
if [ ! -d $HIPFORT ] ; then |
| 295 |
HIPFORT="/tmp/hipfort" |
| 296 |
fi |
| 297 |
if [ ! -d $HIPFORT ] ; then |
| 298 |
echo "ERROR: HIPFORT installation not found at $HIPFORT" |
| 299 |
echo " Please install HIPFORT or set environment variable HIPFORT" |
| 300 |
exit 1 |
| 301 |
fi |
| 302 |
|
| 303 |
HIPFORT_COMPILER=${HIPFORT_COMPILER:-$cdir/gfortran} |
| 304 |
if [ ! -f $HIPFORT_COMPILER ] ; then |
| 305 |
HIPFORT_COMPILER=`which $HIPFORT_COMPILER` |
| 306 |
fi |
| 307 |
if [ ! -f $HIPFORT_COMPILER ] ; then |
| 308 |
echo "ERROR: HIPFORT_COMPILER not found at $HIPFORT_COMPILER" |
| 309 |
echo " Please install $HIPFORT_COMPILER" |
| 310 |
exit 1 |
| 311 |
fi |
| •312 |
|
| 313 |
# Determine which gfx processor to use, fall back to rocm_agent_enumerator |
| 314 |
if [ ! $HIPFORT_GPU ] ; then |
| 315 |
# Use the mygpu in pair with this script, not the pre-installed one. |
| 316 |
HIPFORT_GPU=`$cdir/../libexec/hipfort/mygpu` |
| 317 |
if [ "$HIPFORT_GPU" == "unknown" ] ; then |
| 318 |
# Pick the first one of highest arch |
| 319 |
HIPFORT_GPU=$(rocm_agent_enumerator | sort -rn | sed '/gfx000/d' | head -n1) |
| 320 |
fi |
| 321 |
fi |
| 322 |
|
| 323 |
# Handle all differences between amdgcn and nvidia here |
| 324 |
if [ "${HIPFORT_GPU:0:3}" == "sm_" ] ; then |
| 325 |
TARGET_ARCH="nvptx" |
| 326 |
TARGET_TRIPLE=${TARGET_TRIPLE:-nvptx64-nvidia-cuda} |
| 327 |
TARGET_LIBS="-L$CUDA_PATH/targets/x86_64-linux/lib -lcudart" |
| 328 |
HIPCC_ENV="HIP_PLATFORM=nvidia" |
| 329 |
HIPCC_OPTS="--gpu-architecture=$HIPFORT_GPU -x cu $CUOPTS" |
| 330 |
# fixme: add test for minimum cuda version here |
| 331 |
else |
| 332 |
if [ ! -f $ROCM_PATH/bin/hipconfig ] ; then |
| 333 |
echo "ERROR: hipconfig not found at $ROCM_PATH/bin/hipconfig" |
| 334 |
echo " Please install ROCm hip" |
| 335 |
exit 1 |
| 336 |
fi |
| 337 |
hipversion=`$ROCM_PATH/bin/hipconfig -v` |
| 338 |
hipver=`echo $hipversion | cut -d"." -f1` |
| 339 |
hiprel=`echo $hipversion | cut -d"." -f2` |
| 340 |
if [ $hipver -lt 3 ] || ( [ $hipver == 3 ] && [ $hiprel -lt 5 ] ) ; then |
| •341 |
echo "ERROR: Minimum required version of hip is in ROCm 3.5" |
| 342 |
echo " Please update your hip installation" |
| 343 |
exit 1 |
| 344 |
fi |
| 345 |
TARGET_TRIPLE=${TARGET_TRIPLE:-amdgcn-amd-amdhsa} |
| 346 |
TARGET_ARCH="amdgcn" |
| 347 |
if [ -f $ROCM_PATH/lib64/libamdhip64.a ] || [ -f $ROCM_PATH/lib64/libamdhip64.so ]; then |
| •348 |
TARGET_LIBS="-L$ROCM_PATH/lib64 -lamdhip64 -Wl,-rpath=$ROCM_PATH/lib64 " |
| 349 |
else |
| 350 |
TARGET_LIBS="-L$ROCM_PATH/lib -lamdhip64 -Wl,-rpath=$ROCM_PATH/lib " |
| 351 |
fi |
| 352 |
HIPCC_ENV="HIP_PLATFORM=$HIP_PLATFORM" |
| 353 |
if [ -z ${HIP_CLANG_PATH+x} ]; then |
| 354 |
if [ -d $ROCM_PATH/llvm/bin ]; then |
| 355 |
HIPCC_ENV+=" HIP_CLANG_PATH=$ROCM_PATH/llvm/bin" |
| 356 |
else |
| 357 |
try_HIP_CLANG_PATH=`$ROCM_PATH/bin/hipconfig -l` |
| 358 |
if [ -d $try_HIP_CLANG_PATH ]; then |
| 359 |
HIPCC_ENV+=" HIP_CLANG_PATH=$try_HIP_CLANG_PATH" |
| 360 |
fi |
| 361 |
fi |
| •362 |
fi |
| 363 |
if [ -z ${DEVICE_LIB_PATH+x} ]; then |
| 364 |
# Future versions of ROCm will install the device library in ROCM_PATH/amdgcn/bitcode |
| 365 |
if [ -d $ROCM_PATH/amdgcn/bitcode ] ; then |
| 366 |
HIPCC_ENV+=" DEVICE_LIB_PATH=$ROCM_PATH/amdgcn/bitcode" |
| 367 |
else |
| 368 |
if [ -f $ROCM_PATH/lib/hip.bc ]; then |
| 369 |
HIPCC_ENV+=" DEVICE_LIB_PATH=$ROCM_PATH/lib" |
| 370 |
else |
| 371 |
# Look in the clang resource dir |
| 372 |
try_HIP_CLANG_PATH=`$ROCM_PATH/bin/hipconfig -l` |
| 373 |
if [ -x ${try_HIP_CLANG_PATH}/clang ]; then |
| 374 |
resource_dir=`${try_HIP_CLANG_PATH}/clang -print-resource-dir` |
| 375 |
if [ -d $resource_dir/amdgcn/bitcode ]; then |
| 376 |
HIPCC_ENV+=" DEVICE_LIB_PATH=$resource_dir/amdgcn/bitcode" |
| 377 |
fi |
| 378 |
fi |
| 379 |
fi |
| 380 |
fi |
| 381 |
fi |
| 382 |
HIPCC_OPTS="-fno-gpu-rdc -fPIC" |
| 383 |
for arch in "$HIPFORT_GPU" ; do |
| 384 |
HIPCC_OPTS+=" --offload-arch=$arch " |
| 385 |
done |
| 386 |
fi |
| 387 |
|
| 388 |
FORTOPT=${FORTOPT:-2} |
| 389 |
|
| 390 |
if [ $VV ] ; then |
| 391 |
VERBOSE=true |
| 392 |
fi |
| 393 |
|
| 394 |
RUNDATE=`date` |
| 395 |
|
| 396 |
# Parse FIRST_INPUT_FILE_NAME for filetype, directory, and filename |
| 397 |
INPUT_FTYPE=${FIRST_INPUT_FILE_NAME##*\.} |
| 398 |
INDIR=$(getdname $FIRST_INPUT_FILE_NAME) |
| 399 |
FILENAME=${FIRST_INPUT_FILE_NAME##*/} |
| 400 |
# FNAME has the filetype extension removed, used for naming intermediate filenames |
| 401 |
FNAME=${FILENAME%.*} |
| 402 |
|
| 403 |
if [ -z $OUTFILE ] ; then |
| 404 |
# Output file not specified so use input directory |
| 405 |
OUTDIR=$INDIR |
| 406 |
if [ $GEN_OBJECT_ONLY ] ; then |
| 407 |
OUTFILE=${FNAME}.o |
| 408 |
else |
| 409 |
OUTFILE="a.out" |
| 410 |
fi |
| 411 |
else |
| 412 |
# Use the specified OUTFILE |
| 413 |
OUTDIR=$(getdname $OUTFILE) |
| 414 |
OUTFILE=${OUTFILE##*/} |
| 415 |
fi |
| 416 |
|
| 417 |
sdir=$(getdname $0) |
| 418 |
[ ! -L "$sdir/hipfc" ] || sdir="$(getdname "$(realpath "$sdir/hipfc")")" |
| 419 |
ROCC_DIR=$sdir |
| 420 |
|
| 421 |
TMPNAME="hipfc-tmp-$$" |
| 422 |
TMPDIR=${TMPDIR:-/tmp/$TMPNAME} |
| 423 |
if [ -d $TMPDIR ] ; then |
| 424 |
KEEPTDIR=true |
| 425 |
else |
| 426 |
if [ $DRYRUN ] ; then |
| 427 |
echo "mkdir -p $TMPDIR" |
| 428 |
else |
| 429 |
mkdir -p $TMPDIR |
| 430 |
NEWTMPDIR=true |
| 431 |
fi |
| 432 |
fi |
| 433 |
|
| 434 |
# Be sure not to delete the output directory |
| 435 |
if [ $TMPDIR == $OUTDIR ] ; then |
| 436 |
KEEPTDIR=true |
| 437 |
fi |
| 438 |
if [ ! -d $TMPDIR ] && [ ! $DRYRUN ] ; then |
| 439 |
echo "ERROR: Directory $TMPDIR does not exist or could not be created" |
| 440 |
exit $DEADRC |
| 441 |
fi |
| 442 |
if [ ! -d $OUTDIR ] && [ ! $DRYRUN ] ; then |
| 443 |
echo "ERROR: The output directory $OUTDIR does not exist" |
| 444 |
exit $DEADRC |
| 445 |
fi |
| 446 |
|
| 447 |
UNAMEP=`uname -p` |
| 448 |
HOST_TARGET="$UNAMEP-pc-linux-gnu" |
| 449 |
if [ "$UNAMEP" == "ppc64le" ] ; then |
| 450 |
HOST_TARGET="ppc64le-linux-gnu" |
| 451 |
fi |
| 452 |
|
| 453 |
if [[ "$HIPFORT_COMPILER" == *"ftn" ]] ; then |
| 454 |
FCARGS="-eT -J$HIPFORT/include/hipfort/$TARGET_ARCH" |
| 455 |
else |
| 456 |
FCARGS="-cpp -I$HIPFORT/include/hipfort/$TARGET_ARCH" |
| 457 |
fi |
| •458 |
|
| 459 |
if [ $GEN_OBJECT_ONLY ] ; then |
| 460 |
FCARGS=" -c $FCARGS" |
| 461 |
HIPCC_OPTS=" -c $HIPCC_OPTS" |
| 462 |
LINKOPTS="" |
| 463 |
else |
| 464 |
if [ -f ${HIPFORT}/lib64/hipfort-${TARGET_ARCH}.a ] || [ -f ${HIPFORT}/lib64/libhipfort-${TARGET_ARCH}.so ]; then |
| 465 |
LINKOPTS="-L$HIPFORT/lib64" |
| 466 |
else |
| 467 |
LINKOPTS="-L$HIPFORT/lib" |
| 468 |
fi |
| 469 |
LINKOPTS="${LINKOPTS} -lhipfort-$TARGET_ARCH" |
| 470 |
for lib in $ROCM_LIBS; do |
| 471 |
addrocmlib $lib |
| 472 |
done |
| 473 |
for lib in $CUDA_LIBS; do |
| 474 |
addcudalib $lib |
| 475 |
done |
| 476 |
LINKOPTS="$LINKOPTS $TARGET_LIBS -lstdc++" |
| 477 |
fi |
| 478 |
|
| 479 |
# Separate hipcc inputs from fortran inputs |
| 480 |
__INPUTS="" |
| 481 |
__HIPCC_INPUTS="" |
| 482 |
for __input_file in `echo $INPUTFILES` ; do |
| 483 |
_ftype=${__input_file##*\.} |
| 484 |
if [ "$_ftype" == "hip" ] ; then |
| 485 |
__HIPCC_INPUTS+="$__input_file" |
| 486 |
elif [ "$_ftype" == "cpp" ] ; then |
| 487 |
__HIPCC_INPUTS+=" $__input_file" |
| 488 |
elif [ "$_ftype" == "hpp" ] ; then |
| 489 |
__HIPCC_INPUTS+=" $__input_file" |
| 490 |
elif [ "$_ftype" == "c" ] ; then |
| 491 |
__HIPCC_INPUTS+=" $__input_file" |
| 492 |
elif [ "$_ftype" == "h" ] ; then |
| 493 |
__HIPCC_INPUTS+=" $__input_file" |
| 494 |
else |
| 495 |
__INPUTS+=" $__input_file" |
| 496 |
fi |
| 497 |
done |
| 498 |
|
| 499 |
if [ $GEN_DEBUG ] ; then |
| 500 |
FCARGS=" -g $FCARGS" |
| 501 |
HIPCC_OPTS=" -g $HIPCC_OPTS" |
| 502 |
fi |
| 503 |
if [ $VV ] ; then |
| 504 |
FCARGS=" -v $FCARGS" |
| 505 |
HIPCC_OPTS=" -v $HIPCC_OPTS" |
| 506 |
fi |
| 507 |
|
| 508 |
# Print Header block |
| 509 |
if [ $VV ] ; then |
| 510 |
echo "# " |
| 511 |
echo "#Info: HIPFORT Version: $PROGVERSION" |
| 512 |
echo "#Info: HIPFORT Compiler: $HIPFORT_COMPILER" |
| 513 |
echo "#Info: HIPFORT Path: $HIPFORT" |
| 514 |
echo "#Info: ROCM Path: $ROCM_PATH" |
| 515 |
echo "#Info: CUDA Path: $CUDA_PATH" |
| 516 |
echo "#Info: How called: $HOW_CALLED" |
| 517 |
echo "#Info: Target GPU: $HIPFORT_GPU" |
| 518 |
echo "#Info: Input files: $INPUTFILES" |
| 519 |
echo "#Info: Output file: $OUTDIR/$OUTFILE" |
| 520 |
echo "#Info: Passthru args: $PASSTHRUARGS" |
| 521 |
echo "#Info: Run date: $RUNDATE" |
| 522 |
[ $KEEPTDIR ] && echo "#Info: Temp dir: $TMPDIR" |
| 523 |
echo "# " |
| 524 |
fi |
| 525 |
|
| 526 |
rc=0 |
| 527 |
if [ "$__HIPCC_INPUTS" != "" ] ; then |
| 528 |
if [ "$__INPUTS" == "" ] ; then |
| 529 |
__HIPCC_OUTFILE="$OUTDIR/$OUTFILE" |
| 530 |
__HIPCC_LINKOPTS=$LINKOPTS |
| 531 |
else |
| 532 |
HIPCC_OPTS+=" -c" |
| 533 |
__HIPCC_LINKOPTS="" |
| 534 |
__HIPCC_OUTFILE="$TMPDIR/hipcc.o" |
| 535 |
__INPUTS+=" $__HIPCC_OUTFILE" |
| 536 |
fi |
| 537 |
if [ ! -f $ROCM_PATH/bin/hipcc ] ; then |
| 538 |
echo "ERROR: hipcc compiler not found at $ROCM_PATH/bin/hipcc" |
| 539 |
echo " Please install hip" |
| 540 |
exit $DEADRC |
| 541 |
fi |
| 542 |
export $HIPCC_ENV |
| 543 |
runcmd "$ROCM_PATH/bin/hipcc $HIPCC_OPTS $PASSTHRUARGS $__HIPCC_INPUTS $__HIPCC_LINKOPTS -o $__HIPCC_OUTFILE" |
| 544 |
fi |
| 545 |
|
| 546 |
if [ "$__INPUTS" != "" ] ; then |
| 547 |
runcmd "$HIPFORT_COMPILER $FCARGS $__INPUTS $PASSTHRUARGS $LINKOPTS -o $OUTDIR/$OUTFILE" |
| 548 |
fi |
| 549 |
|
| 550 |
# cleanup |
| 551 |
do_err 0 |
| 552 |
exit 0 |