From 8b25f7b4cf19bf2b4a0bb76eba61e659a8d89be9 Mon Sep 17 00:00:00 2001 From: Maneesh Gupta Date: Wed, 27 Feb 2019 14:10:21 +0530 Subject: [PATCH] [hipcofig] Update HIP_PLATFORM detection logic HIP_PLATFORM detection logic relied on finding a working KFD. If it was found, the platform was set as hcc else as nvcc. However this logic is flawed since it is possible for the development system to only have the user mode bits to build HIP application code. Hence the better logic is to rely on finding a suitable compiler. The new logic is as follows: - look for a working HCC. If found, platform is set as hcc. - else look for a working NVCC. If found, platform is set as nvcc. - else the platform defaults to hcc for now. Change-Id: Ifcc42c29a19f722153d5c23c55f1a8765dceaf6b --- bin/hipconfig | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/bin/hipconfig b/bin/hipconfig index e70e6ae970..520a58cc2c 100755 --- a/bin/hipconfig +++ b/bin/hipconfig @@ -59,6 +59,18 @@ sub parse_config_file { } } +#--- +# Function to check if executable can be run +sub can_run { + my ($exe) = @_; + `$exe --version 2>&1`; + if ($? == 0) { + return 1; + } else { + return 0; + } +} + $CUDA_PATH=$ENV{'CUDA_PATH'} // '/usr/local/cuda'; $HCC_HOME=$ENV{'HCC_HOME'} // '/opt/rocm/hcc'; $HSA_PATH=$ENV{'HSA_PATH'} // '/opt/rocm/hsa'; @@ -67,12 +79,13 @@ $HSA_PATH=$ENV{'HSA_PATH'} // '/opt/rocm/hsa'; #HIP_PLATFORM controls whether to use NVCC or HCC for compilation: $HIP_PLATFORM=$ENV{'HIP_PLATFORM'}; if (not defined $HIP_PLATFORM) { - $NAMDGPUNODES=`cat /sys/class/kfd/kfd/topology/nodes/*/properties 2>/dev/null | grep -c 'simd_count [1-9]'`; - - if ($NAMDGPUNODES > 0) { - $HIP_PLATFORM = "hcc" - } else { + if (can_run("$HCC_HOME/bin/hcc") or can_run("hcc")) { + $HIP_PLATFORM = "hcc"; + } elsif (can_run("$CUDA_PATH/bin/nvcc") or can_run("nvcc")) { $HIP_PLATFORM = "nvcc"; + } else { + # Default to hcc for now + $HIP_PLATFORM = "hcc"; } }