From 830e85060b451f343519c6d245e49d1c060076aa Mon Sep 17 00:00:00 2001 From: Maneesh Gupta Date: Fri, 28 Jul 2017 16:18:15 +0530 Subject: [PATCH 1/3] [hipcc] Cleanup amdgpu target logic Existing logic has a bug. If user specifies targetA via commandline options, while enumerator returns targetB, hipcc will create a fatbin containing targets targetA and targetB. enumerator should only be used when no target is specified by user (commandline or env var). Change-Id: I6da857f86860c0e671b5988cd858644a08f723b9 --- bin/hipcc | 133 ++++++++++++++++++++++++++++++++---------------------- 1 file changed, 80 insertions(+), 53 deletions(-) diff --git a/bin/hipcc b/bin/hipcc index 8a1874a36a..b40b4ee855 100755 --- a/bin/hipcc +++ b/bin/hipcc @@ -75,6 +75,7 @@ $target_gfx801 = 0; $target_gfx802 = 0; $target_gfx803 = 0; $target_gfx900 = 0; +$default_amdgpu_target = 1; if ($HIP_PLATFORM eq "hcc") { $HSA_PATH=$ENV{'HSA_PATH'} // "/opt/rocm/hsa"; @@ -103,29 +104,6 @@ if ($HIP_PLATFORM eq "hcc") { $HIPLDFLAGS = `${HCC_HOME}/bin/hcc-config --ldflags`; - $ROCM_AGENT_ENUM = "${ROCM_PATH}/bin/rocm_agent_enumerator"; - - my $myAgents = `${ROCM_AGENT_ENUM} -t GPU`; - my @agentsLine = split('\n', $myAgents); - - foreach my $val (@agentsLine) { - if($val eq "gfx701") { - $target_gfx701 = 1; - } - if($val eq "gfx801") { - $target_gfx801 = 1; - } - if($val eq "gfx802") { - $target_gfx802 = 1; - } - if($val eq "gfx803") { - $target_gfx803 = 1; - } - if($val eq "gfx900") { - $target_gfx900 = 1; - } - } - #### GCC system includes workaround #### $HCC_WA_FLAGS = " "; if ($HCC_VERSION_MAJOR eq 1) { @@ -278,25 +256,32 @@ foreach $arg (@ARGV) $HIPCXXFLAGS .= " -stdlib=libc++"; $setStdLib = 1; } + + # TODO: Add support for comma separated list like HCC_AMDGPU_TARGET if($arg eq '--amdgpu-target=gfx701') { $target_gfx701 = 1; + $default_amdgpu_target = 0; } if($arg eq '--amdgpu-target=gfx801') { $target_gfx801 = 1; + $default_amdgpu_target = 0; } if($arg eq '--amdgpu-target=gfx802') { $target_gfx802 = 1; + $default_amdgpu_target = 0; } if($arg eq '--amdgpu-target=gfx803') { $target_gfx803 = 1; + $default_amdgpu_target = 0; } if($arg eq '--amdgpu-target=gfx900') { $target_gfx900 = 1; + $default_amdgpu_target = 0; } if(($trimarg eq '-stdlib=libstdc++') and ($setStdLib eq 0)) @@ -358,38 +343,80 @@ foreach $arg (@ARGV) } $toolArgs .= " $arg" unless $swallowArg; } -if(defined $ENV{HCC_AMDGPU_TARGET}) -{ - foreach my $target (split(/,/, $ENV{HCC_AMDGPU_TARGET})) - { - if($target eq 'gfx701') - { - $target_gfx701 = 1; - } - if($target eq 'gfx801') - { - $target_gfx801 = 1; - } - if($target eq 'gfx802') - { - $target_gfx802 = 1; - } - if($target eq 'gfx803') - { - $target_gfx803 = 1; - } - if($target eq 'gfx900') - { - $target_gfx900 = 1; - } - } -} -if ($target_gfx701 eq 0 and $target_gfx801 eq 0 and $target_gfx802 eq 0 and $target_gfx803 eq 0 and $target_gfx900 eq 0) -{ - $target_gfx803 = 1; -} if($HIP_PLATFORM eq "hcc"){ + # No AMDGPU target specified at commandline + if($default_amdgpu_target eq 1) + { + # Look for HCC_AMDGPU_TARGET + if(defined $ENV{HCC_AMDGPU_TARGET}) + { + foreach my $target (split(/,/, $ENV{HCC_AMDGPU_TARGET})) + { + if($target eq 'gfx701') + { + $target_gfx701 = 1; + $default_amdgpu_target = 0; + } + if($target eq 'gfx801') + { + $target_gfx801 = 1; + $default_amdgpu_target = 0; + } + if($target eq 'gfx802') + { + $target_gfx802 = 1; + $default_amdgpu_target = 0; + } + if($target eq 'gfx803') + { + $target_gfx803 = 1; + $default_amdgpu_target = 0; + } + if($target eq 'gfx900') + { + $target_gfx900 = 1; + $default_amdgpu_target = 0; + } + } + } + # Else try using rocm_agent_enumerator + else + { + $ROCM_AGENT_ENUM = "${ROCM_PATH}/bin/rocm_agent_enumerator"; + + my $myAgents = `${ROCM_AGENT_ENUM} -t GPU`; + my @agentsLine = split('\n', $myAgents); + + foreach my $val (@agentsLine) { + if($val eq "gfx701") { + $target_gfx701 = 1; + $default_amdgpu_target = 0; + } + if($val eq "gfx801") { + $target_gfx801 = 1; + $default_amdgpu_target = 0; + } + if($val eq "gfx802") { + $target_gfx802 = 1; + $default_amdgpu_target = 0; + } + if($val eq "gfx803") { + $target_gfx803 = 1; + $default_amdgpu_target = 0; + } + if($val eq "gfx900") { + $target_gfx900 = 1; + $default_amdgpu_target = 0; + } + } + } + } + # All options including enumerator failed! Fallback to gfx803 for now + if ($default_amdgpu_target eq 1) + { + $target_gfx803 = 1; + } $ENV{HCC_EXTRA_LIBRARIES}="$HIP_PATH/lib/hip_hc.ll\n"; From 85ff6e3ef4525497c5203e58b61c2d8be6978694 Mon Sep 17 00:00:00 2001 From: Maneesh Gupta Date: Mon, 31 Jul 2017 10:11:19 +0530 Subject: [PATCH 2/3] [hipcc] Fix amdgpu target selection logic - Refactoring introduced a bug when user does not specify any target via --amdgpu-target, but has an invalid target specified in HCC_AMDGPU_TARGET. In this case the selection logic was defaulting to gf803. - Removed defaulting to any specific target if rocm_agent_enumerator fails. hipcc will report this and die if linking was required. Change-Id: I76131867049fef92331807dd19a926406dcc1d02 --- bin/hipcc | 122 ++++++++++++++++++++++++++---------------------------- 1 file changed, 59 insertions(+), 63 deletions(-) diff --git a/bin/hipcc b/bin/hipcc index b40b4ee855..624777ab25 100755 --- a/bin/hipcc +++ b/bin/hipcc @@ -345,77 +345,73 @@ foreach $arg (@ARGV) } if($HIP_PLATFORM eq "hcc"){ - # No AMDGPU target specified at commandline - if($default_amdgpu_target eq 1) + # No AMDGPU target specified at commandline. So look for HCC_AMDGPU_TARGET + if($default_amdgpu_target eq 1 and defined $ENV{HCC_AMDGPU_TARGET}) { - # Look for HCC_AMDGPU_TARGET - if(defined $ENV{HCC_AMDGPU_TARGET}) + foreach my $target (split(/,/, $ENV{HCC_AMDGPU_TARGET})) { - foreach my $target (split(/,/, $ENV{HCC_AMDGPU_TARGET})) + if($target eq 'gfx701') { - if($target eq 'gfx701') - { - $target_gfx701 = 1; - $default_amdgpu_target = 0; - } - if($target eq 'gfx801') - { - $target_gfx801 = 1; - $default_amdgpu_target = 0; - } - if($target eq 'gfx802') - { - $target_gfx802 = 1; - $default_amdgpu_target = 0; - } - if($target eq 'gfx803') - { - $target_gfx803 = 1; - $default_amdgpu_target = 0; - } - if($target eq 'gfx900') - { - $target_gfx900 = 1; - $default_amdgpu_target = 0; - } + $target_gfx701 = 1; + $default_amdgpu_target = 0; } - } - # Else try using rocm_agent_enumerator - else - { - $ROCM_AGENT_ENUM = "${ROCM_PATH}/bin/rocm_agent_enumerator"; - - my $myAgents = `${ROCM_AGENT_ENUM} -t GPU`; - my @agentsLine = split('\n', $myAgents); - - foreach my $val (@agentsLine) { - if($val eq "gfx701") { - $target_gfx701 = 1; - $default_amdgpu_target = 0; - } - if($val eq "gfx801") { - $target_gfx801 = 1; - $default_amdgpu_target = 0; - } - if($val eq "gfx802") { - $target_gfx802 = 1; - $default_amdgpu_target = 0; - } - if($val eq "gfx803") { - $target_gfx803 = 1; - $default_amdgpu_target = 0; - } - if($val eq "gfx900") { - $target_gfx900 = 1; - $default_amdgpu_target = 0; - } + if($target eq 'gfx801') + { + $target_gfx801 = 1; + $default_amdgpu_target = 0; + } + if($target eq 'gfx802') + { + $target_gfx802 = 1; + $default_amdgpu_target = 0; + } + if($target eq 'gfx803') + { + $target_gfx803 = 1; + $default_amdgpu_target = 0; + } + if($target eq 'gfx900') + { + $target_gfx900 = 1; + $default_amdgpu_target = 0; } } } - # All options including enumerator failed! Fallback to gfx803 for now - if ($default_amdgpu_target eq 1) + # Else try using rocm_agent_enumerator + if($default_amdgpu_target eq 1) { - $target_gfx803 = 1; + $ROCM_AGENT_ENUM = "${ROCM_PATH}/bin/rocm_agent_enumerator"; + + my $myAgents = `${ROCM_AGENT_ENUM} -t GPU`; + my @agentsLine = split('\n', $myAgents); + + foreach my $val (@agentsLine) { + if($val eq "gfx701") { + $target_gfx701 = 1; + $default_amdgpu_target = 0; + } + if($val eq "gfx801") { + $target_gfx801 = 1; + $default_amdgpu_target = 0; + } + if($val eq "gfx802") { + $target_gfx802 = 1; + $default_amdgpu_target = 0; + } + if($val eq "gfx803") { + $target_gfx803 = 1; + $default_amdgpu_target = 0; + } + if($val eq "gfx900") { + $target_gfx900 = 1; + $default_amdgpu_target = 0; + } + } + } + # rocm_agent_enumerator failed! Throw an error and die if linking is required + if ($default_amdgpu_target eq 1 and $compileOnly eq 0) + { + print "No valid AMD GPU target was either specified or found. Please specify a valid target using --amdgpu-target=" and die(); } $ENV{HCC_EXTRA_LIBRARIES}="$HIP_PATH/lib/hip_hc.ll\n"; From e9c995959b5be31d6377538ce13a8d04810e70a5 Mon Sep 17 00:00:00 2001 From: Maneesh Gupta Date: Mon, 31 Jul 2017 14:57:32 +0530 Subject: [PATCH 3/3] [doc] Add details of HIP build time dependencies to INSTALL.md Change-Id: Iee87d1345aba716d0ce49f7afb45ba073a16be88 --- INSTALL.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/INSTALL.md b/INSTALL.md index dc9ae41b9c..eb219e19f7 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -59,7 +59,8 @@ HIP source code is available and the project can be built from source on the HCC 1. Follow the above steps to install and validate the binary packages. 2. Download HIP source code (from the [GitHub repot](https://github.com/ROCm-Developer-Tools/HIP).) -3. Build and install HIP (This is the simple version assuming default paths ; see below for additional options.) +3. Install HIP build-time dependencies using ```sudo apt-get install libelf-dev```. +4. Build and install HIP (This is the simple version assuming default paths ; see below for additional options.) ``` cd HIP mkdir build