Add compiler-rt library for __fp16 and _Float16

Similar to HCC, link with compiler-rt to support __fp16 and _Float16 type conversions in ONNX models. This should resolve SWDEV-238491.

Change-Id: Iad8dcff568831719f501f562a04023326ae8036c
This commit is contained in:
Aaron En Ye Shi
2020-05-29 21:45:34 +00:00
parent f20748854e
commit 56392b4f8a
3 changed files with 75 additions and 0 deletions
+2
View File
@@ -840,6 +840,8 @@ if ($HIP_PLATFORM eq "hcc" and $HIP_COMPILER eq "clang") {
} else {
$toolArgs .= " -Wl,--enable-new-dtags -Wl,--rpath=$HIP_LIB_PATH:$ROCM_PATH/lib -lhip_hcc ";
}
# To support __fp16 and _Float16, explicitly link with compiler-rt
$toolArgs .= " -L$HIP_CLANG_PATH/../lib/clang/$HIP_CLANG_VERSION/lib/linux -lclang_rt.builtins-x86_64 "
}
}
+14
View File
@@ -196,6 +196,20 @@ if(HIP_COMPILER STREQUAL "clang")
message("clang compiler doesn't support parallel jobs")
endif()
endif()
# Add support for __fp16 and _Float16, explicitly link with compiler-rt
set_property(TARGET hip::host APPEND PROPERTY
INTERFACE_COMPILE_OPTIONS -L${HIP_CLANG_INCLUDE_PATH}/../lib/linux -lclang_rt.builtins-x86_64
)
set_property(TARGET hip::host APPEND PROPERTY
INTERFACE_LINK_LIBRARIES -L${HIP_CLANG_INCLUDE_PATH}/../lib/linux -lclang_rt.builtins-x86_64
)
set_property(TARGET hip::device APPEND PROPERTY
INTERFACE_COMPILE_OPTIONS -L${HIP_CLANG_INCLUDE_PATH}/../lib/linux -lclang_rt.builtins-x86_64
)
set_property(TARGET hip::device APPEND PROPERTY
INTERFACE_LINK_LIBRARIES -L${HIP_CLANG_INCLUDE_PATH}/../lib/linux -lclang_rt.builtins-x86_64
)
endif()
set( hip_LIBRARIES hip::host hip::device)
+59
View File
@@ -0,0 +1,59 @@
/*
Copyright (c) 2015-2020 Advanced Micro Devices, Inc. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
/* HIT_START
* BUILD: %t %s ../../test_common.cpp EXCLUDE_HIP_PLATFORM nvcc
* TEST: %t 1.2 2.3
* HIT_END
*/
#include <cstdlib>
#include <hip/hip_runtime.h>
#include "test_common.h"
int main(int argc, char* argv[]) {
// Testing that the compiler supports host _Float16 conversions
float init_value = atof(argv[1]);
_Float16 value_float16 = static_cast<_Float16>(init_value);
float result_value = static_cast<float>(value_float16);
if(std::abs(result_value - init_value) >= 0.01){
printf("init: %f\n", init_value);
printf("result: %f\n", result_value);
printf("diff: %f\n", std::abs(result_value - init_value));
failed("Failed host _Float16 test.");
}
// Testing that the compiler supports host __fp16 conversions
init_value = atof(argv[2]);
__fp16 value_fp16 = static_cast<__fp16>(init_value);
result_value = static_cast<float>(value_fp16);
if(std::abs(result_value - init_value) >= 0.01){
printf("init: %f\n", init_value);
printf("result: %f\n", result_value);
printf("diff: %f\n", std::abs(result_value - init_value));
failed("Failed host __fp16 test.");
}
passed();
}