From 450ea49df0bc01140d3ed1ae6f2bf2018bbbe87c Mon Sep 17 00:00:00 2001 From: Yaxun Sam Liu Date: Tue, 7 Aug 2018 17:14:39 -0400 Subject: [PATCH] Fix __HIP_DEVICE_COMPILE__ not defined when hip/math_functions.h is included This fixes build failure in TensorFlow 1.8 for HCC --- include/hip/math_functions.h | 1 + tests/src/deviceLib/hipTestIncludeMath.cpp | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/include/hip/math_functions.h b/include/hip/math_functions.h index 23dddf9f9d..2dfec4551b 100644 --- a/include/hip/math_functions.h +++ b/include/hip/math_functions.h @@ -27,6 +27,7 @@ THE SOFTWARE. // paths to provide a consistent include env and avoid "missing symbol" errors that only appears // on NVCC path: +#include #if defined(__HIP_PLATFORM_HCC__) && !defined(__HIP_PLATFORM_NVCC__) #include diff --git a/tests/src/deviceLib/hipTestIncludeMath.cpp b/tests/src/deviceLib/hipTestIncludeMath.cpp index 1097c23166..fd9bff1ad9 100644 --- a/tests/src/deviceLib/hipTestIncludeMath.cpp +++ b/tests/src/deviceLib/hipTestIncludeMath.cpp @@ -31,6 +31,20 @@ THE SOFTWARE. // declartions. #include + +// Test __HIP_DEVICE_COMPILE__ is defined after math_functions.h +// is included. +// +__device__ __host__ inline void throw_std_bad_alloc() +{ + #ifndef __HIP_DEVICE_COMPILE__ + throw std::bad_alloc(); + #else + std::size_t huge = static_cast(-1); + new int[huge]; + #endif +} + #include #include "test_common.h"