diff --git a/projects/hip/tests/src/deviceLib/hipStdComplex.cpp b/projects/hip/tests/src/deviceLib/hipStdComplex.cpp index a2233c2452..55a3ef264e 100644 --- a/projects/hip/tests/src/deviceLib/hipStdComplex.cpp +++ b/projects/hip/tests/src/deviceLib/hipStdComplex.cpp @@ -18,12 +18,18 @@ THE SOFTWARE. */ /* HIT_START * BUILD: %t %s NVCC_OPTIONS -std=c++11 - * TEST: %t EXCLUDE_HIP_PLATFORM nvidia + * TEST: %t * HIT_END */ #include "test_common.h" #include +#ifdef __HIP_PLATFORM_AMD__ #include +using namespace std; +#else +#include +using namespace cuda::std; +#endif // Tolerance for error const double tolerance = 1e-6; @@ -52,6 +58,7 @@ std::string getName(enum CalcKind CK) { switch(CK){ ALL_FUN } + return ""; // To prevent compile warning } #undef OP @@ -60,11 +67,11 @@ std::string getName(enum CalcKind CK) { // If the function returns real number, converts it to a complex number. #define ONE_ARG(func) \ case CK_##func: \ - return std::complex(std::func(A)); + return complex(func(A)); template -__device__ __host__ std::complex calc(std::complex A, - std::complex B, +__device__ __host__ complex calc(complex A, + complex B, enum CalcKind CK) { switch(CK) { case CK_add: @@ -81,11 +88,12 @@ __device__ __host__ std::complex calc(std::complex A, ONE_ARG(sin) ONE_ARG(cos) } + return A; // To prevent compile warning } template -__global__ void kernel(std::complex* A, - std::complex* B, std::complex* C, +__global__ void kernel(complex* A, + complex* B, complex* C, enum CalcKind CK) { int tx = threadIdx.x + blockIdx.x * blockDim.x; C[tx] = calc(A[tx], B[tx], CK); @@ -93,7 +101,8 @@ __global__ void kernel(std::complex* A, template void test() { - typedef std::complex ComplexT; + typedef complex ComplexT; + ComplexT *A, *Ad, *B, *Bd, *C, *Cd, *D; A = new ComplexT[LEN]; B = new ComplexT[LEN]; @@ -118,15 +127,15 @@ void test() { hipMemcpy(C, Cd, sizeof(ComplexT)*LEN, hipMemcpyDeviceToHost); for (int i = 0; i < LEN; i++) { ComplexT Expected = calc(A[i], B[i], CK); - FloatT error = std::abs(C[i] - Expected); - if (std::abs(Expected) > tolerance) - error /= std::abs(Expected); + FloatT error = abs(C[i] - Expected); + if (abs(Expected) > tolerance) + error /= abs(Expected); bool pass = error < tolerance; if (verbose || !pass) { std::cout << "Function: " << getName(CK) - << " Operands: " << A[i] << " " << B[i] - << " Result: " << C[i] - << " Expected: " << Expected + << " Operands: " << A[i].real() << ", " << A[i].imag() << "; " <