From 4de15fc86feb3047d3ae62ab893b318fc47ae85d Mon Sep 17 00:00:00 2001 From: foreman Date: Fri, 6 May 2016 13:39:37 -0400 Subject: [PATCH] P4 to Git Change 1266028 by smekhano@stas-rampitec-hsa on 2016/05/06 13:22:26 SWDEV-93545 - HSA HLC: produce v_fma_f32 instead of v_mad_f32/v_mac_f32 on GFX9 if denorms are supported 1. Added means to know HW target for HSAIL BE. 2. Simplified compiler lib logic in handling target capabilities. 3. Used target info to fuse mul/add into fma_f32 on GFX9. Previously it was disabled because mad/mac always flush. v_fma_f32 does not flush, but only fast starting with GFX9. Testing: smoke, precheckin Reviewed by Nikolay Haustov and Evgeny Mankov Affected files ... ... //depot/stg/opencl/drivers/opencl/compiler/lib/backends/common/codegen.cpp#69 edit ... //depot/stg/opencl/drivers/opencl/compiler/lib/backends/common/linker.cpp#142 edit ... //depot/stg/opencl/drivers/opencl/compiler/lib/utils/v0_8/libUtils.cpp#17 edit ... //depot/stg/opencl/drivers/opencl/compiler/lib/utils/v0_8/libUtils.h#26 edit ... //depot/stg/opencl/drivers/opencl/compiler/llvm/lib/Target/HSAIL/HSAIL.h#42 edit ... //depot/stg/opencl/drivers/opencl/compiler/llvm/lib/Target/HSAIL/HSAILFusion.td#29 edit ... //depot/stg/opencl/drivers/opencl/compiler/llvm/lib/Target/HSAIL/HSAILISelDAGToDAG.cpp#70 edit ... //depot/stg/opencl/drivers/opencl/compiler/llvm/lib/Target/HSAIL/HSAILISelLowering.cpp#115 edit ... //depot/stg/opencl/drivers/opencl/compiler/llvm/lib/Target/HSAIL/HSAILInstructions.td#21 edit ... //depot/stg/opencl/drivers/opencl/compiler/llvm/lib/Target/HSAIL/HSAILTargetMachine.cpp#56 edit ... //depot/stg/opencl/drivers/opencl/tests/hsa/tlst/llc_opt.tlst#95 edit --- .../compiler/lib/backends/common/codegen.cpp | 5 ++ .../compiler/lib/backends/common/linker.cpp | 7 +-- rocclr/compiler/lib/utils/v0_8/libUtils.cpp | 47 +++++++++++++------ rocclr/compiler/lib/utils/v0_8/libUtils.h | 3 ++ 4 files changed, 41 insertions(+), 21 deletions(-) diff --git a/rocclr/compiler/lib/backends/common/codegen.cpp b/rocclr/compiler/lib/backends/common/codegen.cpp index 739a28cb87..ca235d7487 100644 --- a/rocclr/compiler/lib/backends/common/codegen.cpp +++ b/rocclr/compiler/lib/backends/common/codegen.cpp @@ -42,6 +42,10 @@ using namespace amdcl; using namespace llvm; +namespace llvm { + extern int HsailOptimizeFor; +} + //!--------------------------------------------------------------------------!// // JIT Memory manager //!--------------------------------------------------------------------------!// @@ -614,6 +618,7 @@ llvmCodeGen( #ifdef WITH_TARGET_HSAIL if (isHSAILTarget(binary->target)) { + llvm::HsailOptimizeFor = getIsaType(aclutGetTargetInfo(binary)); if (Target.addPassesToEmitFile(Passes, *Out, TargetMachine::CGFT_ObjectFile, true)) { delete Out; return 1; diff --git a/rocclr/compiler/lib/backends/common/linker.cpp b/rocclr/compiler/lib/backends/common/linker.cpp index 4d66c0061b..49ca3c6e74 100644 --- a/rocclr/compiler/lib/backends/common/linker.cpp +++ b/rocclr/compiler/lib/backends/common/linker.cpp @@ -750,12 +750,7 @@ amdcl::OCLLinker::link(llvm::Module* input, std::vector &libs) || chip == "Hawaii" || chip == "Carrizo" || chip == ""); - setISAVersion((chip == "Hawaii") ? 701 : - ((chip == "Iceland" || chip == "Tonga") ? 800 : - ((chip == "Carrizo") ? 801 : - ((chip == "Fiji" || chip == "Baffin" || chip == "Ellesmere") ? 804 : - ((chip == "Stoney") ? 810 : - ((chip == "") ? 900 : 700)))))); + setISAVersion(getIsaType(aclutGetTargetInfo(Elf()))); LLVMBinary()->getContext().setAMDLLVMContextHook(&hookup_); std::string clp_errmsg; diff --git a/rocclr/compiler/lib/utils/v0_8/libUtils.cpp b/rocclr/compiler/lib/utils/v0_8/libUtils.cpp index 2418ed843e..2d497e0044 100644 --- a/rocclr/compiler/lib/utils/v0_8/libUtils.cpp +++ b/rocclr/compiler/lib/utils/v0_8/libUtils.cpp @@ -511,47 +511,64 @@ unsigned getChipEnum(const aclTargetInfo *target) *the TargetMapping table for the specific target device id. */ const std::string &getIsaTypeName(const aclTargetInfo *target) +{ + switch (getIsaType(target)) { + default: return sgfx700; + case 700: return sgfx700; + case 701: return sgfx701; + case 800: return sgfx800; + case 801: return sgfx801; + case 804: return sgfx804; + case 810: return sgfx810; + case 900: return sgfx900; + } +} + +/*! Function that returns isa type (compute capability) from + *the TargetMapping table for the specific target device id. + */ +int getIsaType(const aclTargetInfo *target) { const TargetMapping& Mapping = getTargetMapping(*target); switch (Mapping.family_enum) { - default: return sgfx700; + default: return 700; case FAMILY_KV: switch (Mapping.chip_enum) { - default: return sgfx700; + default: return 700; case KV_SPECTRE_A0: case KV_SPOOKY_A0: case KB_KALINDI_A0: // ??? - case ML_GODAVARI_A0: return sgfx700; + case ML_GODAVARI_A0: return 700; } case FAMILY_CI: switch (Mapping.chip_enum) { - default: return sgfx700; + default: return 700; case CI_BONAIRE_M_A0: - case CI_BONAIRE_M_A1: return sgfx700; - case CI_HAWAII_P_A0: return sgfx701; + case CI_BONAIRE_M_A1: return 700; + case CI_HAWAII_P_A0: return 701; case CI_TIRAN_P_A0: - case CI_MAUI_P_A0: return sgfx700; + case CI_MAUI_P_A0: return 700; } case FAMILY_VI: switch (Mapping.chip_enum) { - default: return sgfx800; + default: return 800; case VI_ICELAND_M_A0: - case VI_TONGA_P_A0: return sgfx800; + case VI_TONGA_P_A0: return 800; case VI_ELLESMERE_P_A0: case VI_BAFFIN_M_A0: - case VI_FIJI_P_A0: return sgfx804; + case VI_FIJI_P_A0: return 804; } case FAMILY_CZ: switch (Mapping.chip_enum) { - default: return sgfx801; - case CARRIZO_A0: return sgfx801; - case STONEY_A0: return sgfx810; + default: return 801; + case CARRIZO_A0: return 801; + case STONEY_A0: return 810; } case FAMILY_AI: switch (Mapping.chip_enum) { - default: return sgfx900; - case AI_GREENLAND_P_A0: return sgfx900; + default: return 900; + case AI_GREENLAND_P_A0: return 900; } } } diff --git a/rocclr/compiler/lib/utils/v0_8/libUtils.h b/rocclr/compiler/lib/utils/v0_8/libUtils.h index 06ed8a6105..ef6b764aa8 100644 --- a/rocclr/compiler/lib/utils/v0_8/libUtils.h +++ b/rocclr/compiler/lib/utils/v0_8/libUtils.h @@ -55,6 +55,9 @@ unsigned getChipEnum(const aclTargetInfo *target); // get isa type name (compute capability) from the target information. const std::string &getIsaTypeName(const aclTargetInfo *target); +// get isa type (compute capability) from the target information. +int getIsaType(const aclTargetInfo *target); + // Create a copy of an ELF and duplicate all sections/symbols aclBinary* createELFCopy(aclBinary *src);