Refactor directed test infrastructue.
- Add hierarchy. Tests now live in directories, each with its own CMakeFiles.txt. Reduces merge conflicts. - Change make_hip_executable -> build_hip_executable. - Refresh docs. - Enable some tests that were previously built but not run. Change-Id: I8c5de3c954400bf233904282b8b42861a2b7c536
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
cmake_minimum_required (VERSION 2.6)
|
||||
|
||||
project (deviceLib)
|
||||
|
||||
include_directories( ${HIPTEST_SOURCE_DIR} )
|
||||
|
||||
build_hip_executable (hip_ballot hip_ballot.cpp)
|
||||
make_test(hip_ballot " " )
|
||||
|
||||
build_hip_executable (hip_anyall hip_anyall.cpp)
|
||||
make_test(hip_anyall " " )
|
||||
|
||||
build_hip_executable (hip_popc hip_popc.cpp)
|
||||
make_test(hip_popc " " )
|
||||
|
||||
build_hip_executable (hip_clz hip_clz.cpp)
|
||||
make_test(hip_clz " " )
|
||||
|
||||
build_hip_executable (hip_brev hip_brev.cpp)
|
||||
make_test(hip_brev " " )
|
||||
|
||||
build_hip_executable (hip_ffs hip_ffs.cpp)
|
||||
make_test(hip_ffs " " )
|
||||
|
||||
build_hip_executable_sm35 (hip_test_ldg hip_test_ldg.cpp)
|
||||
make_test(hip_test_ldg " " )
|
||||
|
||||
|
||||
build_hip_executable (hipSimpleAtomicsTest hipSimpleAtomicsTest.cpp)
|
||||
make_test(hipSimpleAtomicsTest " ")
|
||||
|
||||
build_hip_executable (hipMathFunctionsHost hipMathFunctions.cpp hipSinglePrecisionMathHost.cpp hipDoublePrecisionMathHost.cpp)
|
||||
make_test(hipMathFunctionsHost " ")
|
||||
|
||||
build_hip_executable (hipMathFunctionsDevice hipMathFunctions.cpp hipSinglePrecisionMathDevice.cpp hipDoublePrecisionMathDevice.cpp)
|
||||
make_test(hipMathFunctionsDevice " ")
|
||||
|
||||
build_hip_executable (hipIntrinsics hipMathFunctions.cpp hipSinglePrecisionIntrinsics.cpp hipDoublePrecisionIntrinsics.cpp hipIntegerIntrinsics.cpp)
|
||||
make_test(hipIntrinsics " ")
|
||||
|
||||
build_hip_executable (hipTestDevice hipTestDevice.cpp)
|
||||
make_test(hipTestDevice " ")
|
||||
|
||||
build_hip_executable (hipTestDeviceDouble hipTestDeviceDouble.cpp)
|
||||
make_test(hipTestDeviceDouble " ")
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
Copyright (c) 2015-2016 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.
|
||||
*/
|
||||
#include "hip_runtime.h"
|
||||
#include "test_common.h"
|
||||
|
||||
#pragma GCC diagnostic ignored "-Wall"
|
||||
#pragma clang diagnostic ignored "-Wunused-variable"
|
||||
|
||||
__device__ void double_precision_intrinsics()
|
||||
{
|
||||
//__dadd_rd(0.0, 1.0);
|
||||
//__dadd_rn(0.0, 1.0);
|
||||
//__dadd_ru(0.0, 1.0);
|
||||
//__dadd_rz(0.0, 1.0);
|
||||
//__ddiv_rd(0.0, 1.0);
|
||||
//__ddiv_rn(0.0, 1.0);
|
||||
//__ddiv_ru(0.0, 1.0);
|
||||
//__ddiv_rz(0.0, 1.0);
|
||||
//__dmul_rd(1.0, 2.0);
|
||||
//__dmul_rn(1.0, 2.0);
|
||||
//__dmul_ru(1.0, 2.0);
|
||||
//__dmul_rz(1.0, 2.0);
|
||||
//__drcp_rd(2.0);
|
||||
//__drcp_rn(2.0);
|
||||
//__drcp_ru(2.0);
|
||||
//__drcp_rz(2.0);
|
||||
__dsqrt_rd(4.0);
|
||||
__dsqrt_rn(4.0);
|
||||
__dsqrt_ru(4.0);
|
||||
__dsqrt_rz(4.0);
|
||||
//__dsub_rd(2.0, 1.0);
|
||||
//__dsub_rn(2.0, 1.0);
|
||||
//__dsub_ru(2.0, 1.0);
|
||||
//__dsub_rz(2.0, 1.0);
|
||||
//__fma_rd(1.0, 2.0, 3.0);
|
||||
//__fma_rn(1.0, 2.0, 3.0);
|
||||
//__fma_ru(1.0, 2.0, 3.0);
|
||||
//__fma_rz(1.0, 2.0, 3.0);
|
||||
}
|
||||
|
||||
__global__ void compileDoublePrecisionIntrinsics(hipLaunchParm lp, int ignored)
|
||||
{
|
||||
double_precision_intrinsics();
|
||||
}
|
||||
@@ -0,0 +1,125 @@
|
||||
/*
|
||||
Copyright (c) 2015-2016 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.
|
||||
*/
|
||||
#include "hip_runtime.h"
|
||||
#include "test_common.h"
|
||||
|
||||
#pragma GCC diagnostic ignored "-Wall"
|
||||
#pragma clang diagnostic ignored "-Wunused-variable"
|
||||
|
||||
__device__ void double_precision_math_functions()
|
||||
{
|
||||
int iX;
|
||||
double fX, fY;
|
||||
|
||||
acos(1.0);
|
||||
acosh(1.0);
|
||||
asin(0.0);
|
||||
asinh(0.0);
|
||||
atan(0.0);
|
||||
atan2(0.0, 1.0);
|
||||
atanh(0.0);
|
||||
cbrt(0.0);
|
||||
ceil(0.0);
|
||||
copysign(1.0, -2.0);
|
||||
cos(0.0);
|
||||
cosh(0.0);
|
||||
cospi(0.0);
|
||||
//cyl_bessel_i0(0.0);
|
||||
//cyl_bessel_i1(0.0);
|
||||
erf(0.0);
|
||||
erfc(0.0);
|
||||
//erfcinv(2.0);
|
||||
//erfcx(0.0);
|
||||
//erfinv(1.0);
|
||||
exp(0.0);
|
||||
exp10(0.0);
|
||||
exp2(0.0);
|
||||
expm1(0.0);
|
||||
fabs(1.0);
|
||||
fdim(1.0, 0.0);
|
||||
floor(0.0);
|
||||
fma(1.0, 2.0, 3.0);
|
||||
fmax(0.0, 0.0);
|
||||
fmin(0.0, 0.0);
|
||||
fmod(0.0, 1.0);
|
||||
//frexp(0.0, &iX);
|
||||
hypot(1.0, 0.0);
|
||||
ilogb(1.0);
|
||||
isfinite(0.0);
|
||||
isinf(0.0);
|
||||
isnan(0.0);
|
||||
//j0(0.0);
|
||||
//j1(0.0);
|
||||
//jn(-1.0, 1.0);
|
||||
ldexp(0.0, 0);
|
||||
//lgamma(1.0);
|
||||
//llrint(0.0);
|
||||
//llround(0.0);
|
||||
log(1.0);
|
||||
log10(1.0);
|
||||
log1p(-1.0);
|
||||
log2(1.0);
|
||||
logb(1.0);
|
||||
//lrint(0.0);
|
||||
//lround(0.0);
|
||||
//modf(0.0, &fX);
|
||||
nan("1");
|
||||
nearbyint(0.0);
|
||||
//nextafter(0.0);
|
||||
//fX = 1.0; norm(1, &fX);
|
||||
//norm3d(1.0, 0.0, 0.0);
|
||||
//norm4d(1.0, 0.0, 0.0, 0.0);
|
||||
//normcdf(0.0);
|
||||
//normcdfinv(1.0);
|
||||
pow(1.0, 0.0);
|
||||
//rcbrt(1.0);
|
||||
remainder(2.0, 1.0);
|
||||
//remquo(1.0, 2.0, &iX);
|
||||
//rhypot(0.0, 1.0);
|
||||
//rint(1.0);
|
||||
//fX = 1.0; rnorm(1, &fX);
|
||||
//rnorm3d(0.0, 0.0, 1.0);
|
||||
//rnorm4d(0.0, 0.0, 0.0, 1.0);
|
||||
round(0.0);
|
||||
rsqrt(1.0);
|
||||
//scalbln(0.0, 1);
|
||||
scalbn(0.0, 1);
|
||||
signbit(1.0);
|
||||
sin(0.0);
|
||||
//sincos(0.0, &fX, &fY);
|
||||
//sincospi(0.0, &fX, &fY);
|
||||
sinh(0.0);
|
||||
sinpi(0.0);
|
||||
sqrt(0.0);
|
||||
tan(0.0);
|
||||
tanh(0.0);
|
||||
tgamma(2.0);
|
||||
trunc(0.0);
|
||||
//y0(1.0);
|
||||
//y1(1.0);
|
||||
//yn(1, 1.0);
|
||||
}
|
||||
|
||||
__global__ void compileDoublePrecisionMathOnDevice(hipLaunchParm lp, int ignored)
|
||||
{
|
||||
double_precision_math_functions();
|
||||
}
|
||||
@@ -0,0 +1,125 @@
|
||||
/*
|
||||
Copyright (c) 2015-2016 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.
|
||||
*/
|
||||
#include "hip_runtime.h"
|
||||
#include "test_common.h"
|
||||
|
||||
#pragma GCC diagnostic ignored "-Wall"
|
||||
#pragma clang diagnostic ignored "-Wunused-variable"
|
||||
|
||||
__host__ void double_precision_math_functions()
|
||||
{
|
||||
int iX;
|
||||
double fX, fY;
|
||||
|
||||
acos(1.0);
|
||||
acosh(1.0);
|
||||
asin(0.0);
|
||||
asinh(0.0);
|
||||
atan(0.0);
|
||||
atan2(0.0, 1.0);
|
||||
atanh(0.0);
|
||||
cbrt(0.0);
|
||||
ceil(0.0);
|
||||
copysign(1.0, -2.0);
|
||||
cos(0.0);
|
||||
cosh(0.0);
|
||||
cospi(0.0);
|
||||
//cyl_bessel_i0(0.0);
|
||||
//cyl_bessel_i1(0.0);
|
||||
erf(0.0);
|
||||
erfc(0.0);
|
||||
//erfcinv(2.0);
|
||||
//erfcx(0.0);
|
||||
//erfinv(1.0);
|
||||
exp(0.0);
|
||||
exp10(0.0);
|
||||
exp2(0.0);
|
||||
expm1(0.0);
|
||||
fabs(1.0);
|
||||
fdim(1.0, 0.0);
|
||||
floor(0.0);
|
||||
fma(1.0, 2.0, 3.0);
|
||||
fmax(0.0, 0.0);
|
||||
fmin(0.0, 0.0);
|
||||
fmod(0.0, 1.0);
|
||||
frexp(0.0, &iX);
|
||||
hypot(1.0, 0.0);
|
||||
ilogb(1.0);
|
||||
isfinite(0.0);
|
||||
isinf(0.0);
|
||||
isnan(0.0);
|
||||
///j0(0.0);
|
||||
///j1(0.0);
|
||||
///jn(-1.0, 1.0);
|
||||
ldexp(0.0, 0);
|
||||
///lgamma(1.0);
|
||||
///llrint(0.0);
|
||||
///llround(0.0);
|
||||
log(1.0);
|
||||
log10(1.0);
|
||||
log1p(-1.0);
|
||||
log2(1.0);
|
||||
logb(1.0);
|
||||
///lrint(0.0);
|
||||
///lround(0.0);
|
||||
modf(0.0, &fX);
|
||||
///nan("1");
|
||||
nearbyint(0.0);
|
||||
//nextafter(0.0);
|
||||
//fX = 1.0; norm(1, &fX);
|
||||
//norm3d(1.0, 0.0, 0.0);
|
||||
//norm4d(1.0, 0.0, 0.0, 0.0);
|
||||
//normcdf(0.0);
|
||||
//normcdfinv(1.0);
|
||||
pow(1.0, 0.0);
|
||||
//rcbrt(1.0);
|
||||
remainder(2.0, 1.0);
|
||||
remquo(1.0, 2.0, &iX);
|
||||
//rhypot(0.0, 1.0);
|
||||
///rint(1.0);
|
||||
//fX = 1.0; rnorm(1, &fX);
|
||||
//rnorm3d(0.0, 0.0, 1.0);
|
||||
//rnorm4d(0.0, 0.0, 0.0, 1.0);
|
||||
round(0.0);
|
||||
rsqrt(1.0);
|
||||
///scalbln(0.0, 1);
|
||||
scalbn(0.0, 1);
|
||||
signbit(1.0);
|
||||
sin(0.0);
|
||||
sincos(0.0, &fX, &fY);
|
||||
//sincospi(0.0, &fX, &fY);
|
||||
sinh(0.0);
|
||||
sinpi(0.0);
|
||||
sqrt(0.0);
|
||||
tan(0.0);
|
||||
tanh(0.0);
|
||||
tgamma(2.0);
|
||||
trunc(0.0);
|
||||
///y0(1.0);
|
||||
///y1(1.0);
|
||||
///yn(1, 1.0);
|
||||
}
|
||||
|
||||
static void compileOnHost()
|
||||
{
|
||||
double_precision_math_functions();
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
Copyright (c) 2015-2016 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.
|
||||
*/
|
||||
#include "hip_runtime.h"
|
||||
#include "test_common.h"
|
||||
|
||||
#pragma GCC diagnostic ignored "-Wall"
|
||||
#pragma clang diagnostic ignored "-Wunused-variable"
|
||||
|
||||
__device__ void integer_intrinsics()
|
||||
{
|
||||
__brev((unsigned int)10);
|
||||
__brevll((unsigned long long)10);
|
||||
//__byte_perm((unsigned int)0, (unsigned int)0, 0);
|
||||
__clz((int)10);
|
||||
__clzll((long long)10);
|
||||
__ffs((int)10);
|
||||
__ffsll((long long)10);
|
||||
//__hadd((int)1, (int)3);
|
||||
//__mul24((int)1, (int)2);
|
||||
//__mul64hi((long long)1, (long long)2);
|
||||
//__mulhi((int)1, (int)2);
|
||||
__popc((unsigned int)4);
|
||||
__popcll((unsigned long long)4);
|
||||
int a = min((int)4, (int)5);
|
||||
int b = max((int)4, (int)5);
|
||||
//__rhadd((int)1, (int)2);
|
||||
//__sad((int)1, (int)2, 0);
|
||||
//__uhadd((unsigned int)1, (unsigned int)3);
|
||||
//__umul24((unsigned int)1, (unsigned int)2);
|
||||
//__umul64hi((unsigned long long)1, (unsigned long long)2);
|
||||
//__umulhi((unsigned int)1, (unsigned int)2);
|
||||
//__urhadd((unsigned int)1, (unsigned int)2);
|
||||
//__usad((unsigned int)1, (unsigned int)2, 0);
|
||||
}
|
||||
|
||||
__global__ void compileIntegerIntrinsics(hipLaunchParm lp, int ignored)
|
||||
{
|
||||
integer_intrinsics();
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
Copyright (c) 2015-2016 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.
|
||||
*/
|
||||
#include "hip_runtime.h"
|
||||
#include "test_common.h"
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
HipTest::parseStandardArguments(argc, argv, true);
|
||||
|
||||
passed();
|
||||
}
|
||||
@@ -0,0 +1,321 @@
|
||||
/*
|
||||
Copyright (c) 2015-2016 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.
|
||||
*/
|
||||
|
||||
// includes, system
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
|
||||
|
||||
// Includes HIP Runtime
|
||||
#include <hip_runtime.h>
|
||||
#include <test_common.h>
|
||||
|
||||
#define EXIT_WAIVED 2
|
||||
|
||||
const char *sampleName = "hipSimpleAtomicsTest";
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Auto-Verification Code
|
||||
bool testResult = true;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Declaration, forward
|
||||
void runTest(int argc, char **argv);
|
||||
|
||||
|
||||
#define min(a,b) (a) < (b) ? (a) : (b)
|
||||
#define max(a,b) (a) > (b) ? (a) : (b)
|
||||
|
||||
int computeGold(int *gpuData, const int len)
|
||||
{
|
||||
int val = 0;
|
||||
|
||||
for (int i = 0; i < len; ++i)
|
||||
{
|
||||
val += 10;
|
||||
}
|
||||
|
||||
if (val != gpuData[0])
|
||||
{
|
||||
printf("atomicAdd failed\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
val = 0;
|
||||
|
||||
for (int i = 0; i < len; ++i)
|
||||
{
|
||||
val -= 10;
|
||||
}
|
||||
|
||||
if (val != gpuData[1])
|
||||
{
|
||||
printf("atomicSub failed\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
bool found = false;
|
||||
|
||||
for (int i = 0; i < len; ++i)
|
||||
{
|
||||
// third element should be a member of [0, len)
|
||||
if (i == gpuData[2])
|
||||
{
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!found)
|
||||
{
|
||||
printf("atomicExch failed\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
val = -(1 << 8);
|
||||
|
||||
for (int i = 0; i < len; ++i)
|
||||
{
|
||||
// fourth element should be len-1
|
||||
val = max(val, i);
|
||||
}
|
||||
|
||||
if (val != gpuData[3])
|
||||
{
|
||||
printf("atomicMax failed\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
val = 1 << 8;
|
||||
|
||||
for (int i = 0; i < len; ++i)
|
||||
{
|
||||
val = min(val, i);
|
||||
}
|
||||
|
||||
if (val != gpuData[4])
|
||||
{
|
||||
printf("atomicMin failed\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
int limit = 17;
|
||||
val = 0;
|
||||
|
||||
for (int i = 0; i < len; ++i)
|
||||
{
|
||||
val = (val >= limit) ? 0 : val+1;
|
||||
}
|
||||
|
||||
if (val != gpuData[5])
|
||||
{
|
||||
printf("atomicInc failed\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
limit = 137;
|
||||
val = 0;
|
||||
|
||||
for (int i = 0; i < len; ++i)
|
||||
{
|
||||
val = ((val == 0) || (val > limit)) ? limit : val-1;
|
||||
}
|
||||
|
||||
if (val != gpuData[6])
|
||||
{
|
||||
printf("atomicDec failed\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
found = false;
|
||||
|
||||
for (int i = 0; i < len; ++i)
|
||||
{
|
||||
// eighth element should be a member of [0, len)
|
||||
if (i == gpuData[7])
|
||||
{
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!found)
|
||||
{
|
||||
printf("atomicCAS failed\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
val = 0xff;
|
||||
|
||||
for (int i = 0; i < len; ++i)
|
||||
{
|
||||
// 9th element should be 1
|
||||
val &= (2 * i + 7);
|
||||
}
|
||||
|
||||
if (val != gpuData[8])
|
||||
{
|
||||
printf("atomicAnd failed\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
val = 0;
|
||||
|
||||
for (int i = 0; i < len; ++i)
|
||||
{
|
||||
// 10th element should be 0xff
|
||||
val |= (1 << i);
|
||||
}
|
||||
|
||||
if (val != gpuData[9])
|
||||
{
|
||||
printf("atomicOr failed\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
val = 0xff;
|
||||
|
||||
for (int i = 0; i < len; ++i)
|
||||
{
|
||||
// 11th element should be 0xff
|
||||
val ^= i;
|
||||
}
|
||||
|
||||
if (val != gpuData[10])
|
||||
{
|
||||
printf("atomicXor failed\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
__global__ void testKernel(hipLaunchParm lp,int *g_odata)
|
||||
{
|
||||
// access thread id
|
||||
const unsigned int tid = hipBlockDim_x * hipBlockIdx_x + hipThreadIdx_x;
|
||||
|
||||
// Test various atomic instructions
|
||||
|
||||
// Arithmetic atomic instructions
|
||||
|
||||
// Atomic addition
|
||||
atomicAdd(&g_odata[0], 10);
|
||||
|
||||
// Atomic subtraction (final should be 0)
|
||||
atomicSub(&g_odata[1], 10);
|
||||
|
||||
// Atomic exchange
|
||||
atomicExch(&g_odata[2], tid);
|
||||
|
||||
// Atomic maximum
|
||||
atomicMax(&g_odata[3], tid);
|
||||
|
||||
// Atomic minimum
|
||||
atomicMin(&g_odata[4], tid);
|
||||
|
||||
// Atomic increment (modulo 17+1)
|
||||
atomicInc((unsigned int *)&g_odata[5], 17);
|
||||
|
||||
// Atomic decrement
|
||||
atomicDec((unsigned int *)&g_odata[6], 137);
|
||||
|
||||
// Atomic compare-and-swap
|
||||
atomicCAS(&g_odata[7], tid-1, tid);
|
||||
|
||||
// Bitwise atomic instructions
|
||||
|
||||
// Atomic AND
|
||||
atomicAnd(&g_odata[8], 2*tid+7);
|
||||
|
||||
// Atomic OR
|
||||
atomicOr(&g_odata[9], 1 << tid);
|
||||
|
||||
// Atomic XOR
|
||||
atomicXor(&g_odata[10], tid);
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
printf("%s starting...\n", sampleName);
|
||||
|
||||
runTest(argc, argv);
|
||||
|
||||
hipDeviceReset();
|
||||
printf("%s completed, returned %s\n",
|
||||
sampleName,
|
||||
testResult ? "OK" : "ERROR!");
|
||||
exit(testResult ? EXIT_SUCCESS : EXIT_FAILURE);
|
||||
}
|
||||
|
||||
void runTest(int argc, char **argv)
|
||||
{
|
||||
hipDeviceProp_t deviceProp;
|
||||
deviceProp.major = 0;
|
||||
deviceProp.minor = 0;
|
||||
int dev = 0;
|
||||
|
||||
hipGetDeviceProperties(&deviceProp, dev);
|
||||
|
||||
// Statistics about the GPU device
|
||||
printf("> GPU device has %d Multi-Processors, "
|
||||
"SM %d.%d compute capabilities\n\n",
|
||||
deviceProp.multiProcessorCount, deviceProp.major, deviceProp.minor);
|
||||
|
||||
int version = (deviceProp.major * 0x10 + deviceProp.minor);
|
||||
|
||||
unsigned int numThreads = 256;
|
||||
unsigned int numBlocks = 64;
|
||||
unsigned int numData = 11;
|
||||
unsigned int memSize = sizeof(int) * numData;
|
||||
|
||||
//allocate mem for the result on host side
|
||||
int *hOData = (int *) malloc(memSize);
|
||||
|
||||
//initialize the memory
|
||||
for (unsigned int i = 0; i < numData; i++)
|
||||
hOData[i] = 0;
|
||||
|
||||
//To make the AND and XOR tests generate something other than 0...
|
||||
hOData[8] = hOData[10] = 0xff;
|
||||
|
||||
// allocate device memory for result
|
||||
int *dOData;
|
||||
hipMalloc((void **) &dOData, memSize);
|
||||
// copy host memory to device to initialize to zero
|
||||
hipMemcpy(dOData, hOData, memSize,hipMemcpyHostToDevice);
|
||||
|
||||
// execute the kernel
|
||||
hipLaunchKernel(testKernel, dim3(numBlocks), dim3(numThreads), 0, 0, dOData);
|
||||
|
||||
//Copy result from device to host
|
||||
hipMemcpy(hOData,dOData, memSize,hipMemcpyDeviceToHost);
|
||||
|
||||
// Compute reference solution
|
||||
testResult = computeGold(hOData, numThreads * numBlocks);
|
||||
|
||||
// Cleanup memory
|
||||
free(hOData);
|
||||
hipFree(dOData);
|
||||
|
||||
passed();
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
Copyright (c) 2015-2016 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.
|
||||
*/
|
||||
#include "hip_runtime.h"
|
||||
#include "test_common.h"
|
||||
|
||||
#pragma GCC diagnostic ignored "-Wall"
|
||||
#pragma clang diagnostic ignored "-Wunused-variable"
|
||||
|
||||
__device__ void single_precision_intrinsics()
|
||||
{
|
||||
float fX, fY;
|
||||
|
||||
__cosf(0.0f);
|
||||
//__exp10f(0.0f);
|
||||
__expf(0.0f);
|
||||
//__fadd_rd(0.0f, 1.0f);
|
||||
//__fadd_rn(0.0f, 1.0f);
|
||||
//__fadd_ru(0.0f, 1.0f);
|
||||
//__fadd_rz(0.0f, 1.0f);
|
||||
//__fdiv_rd(4.0f, 2.0f);
|
||||
//__fdiv_rn(4.0f, 2.0f);
|
||||
//__fdiv_ru(4.0f, 2.0f);
|
||||
//__fdiv_rz(4.0f, 2.0f);
|
||||
//__fdividef(4.0f, 2.0f);
|
||||
//__fmaf_rd(1.0f, 2.0f, 3.0f);
|
||||
//__fmaf_rn(1.0f, 2.0f, 3.0f);
|
||||
//__fmaf_ru(1.0f, 2.0f, 3.0f);
|
||||
//__fmaf_rz(1.0f, 2.0f, 3.0f);
|
||||
//__fmul_rd(1.0f, 2.0f);
|
||||
//__fmul_rn(1.0f, 2.0f);
|
||||
//__fmul_ru(1.0f, 2.0f);
|
||||
//__fmul_rz(1.0f, 2.0f);
|
||||
//__frcp_rd(2.0f);
|
||||
//__frcp_rn(2.0f);
|
||||
//__frcp_ru(2.0f);
|
||||
//__frcp_rz(2.0f);
|
||||
__frsqrt_rn(4.0f);
|
||||
__fsqrt_rd(4.0f);
|
||||
__fsqrt_rn(4.0f);
|
||||
__fsqrt_ru(4.0f);
|
||||
__fsqrt_rz(4.0f);
|
||||
//__fsub_rd(2.0f, 1.0f);
|
||||
//__fsub_rn(2.0f, 1.0f);
|
||||
//__fsub_ru(2.0f, 1.0f);
|
||||
//__fsub_rz(2.0f, 1.0f);
|
||||
__log10f(1.0f);
|
||||
__log2f(1.0f);
|
||||
__logf(1.0f);
|
||||
__powf(1.0f, 0.0f);
|
||||
//__saturatef(0.1f);
|
||||
//__sincosf(0.0f, &fX, &fY);
|
||||
__sinf(0.0f);
|
||||
__tanf(0.0f);
|
||||
}
|
||||
|
||||
|
||||
__global__ void compileSinglePrecisionIntrinsics(hipLaunchParm lp, int ignored)
|
||||
{
|
||||
single_precision_intrinsics();
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
/*
|
||||
Copyright (c) 2015-2016 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.
|
||||
*/
|
||||
#include "hip_runtime.h"
|
||||
#include "test_common.h"
|
||||
|
||||
#pragma GCC diagnostic ignored "-Wall"
|
||||
#pragma clang diagnostic ignored "-Wunused-variable"
|
||||
|
||||
__device__ void single_precision_math_functions()
|
||||
{
|
||||
int iX;
|
||||
float fX, fY;
|
||||
|
||||
acosf(1.0f);
|
||||
acoshf(1.0f);
|
||||
asinf(0.0f);
|
||||
asinhf(0.0f);
|
||||
atan2f(0.0f, 1.0f);
|
||||
atanf(0.0f);
|
||||
atanhf(0.0f);
|
||||
cbrtf(0.0f);
|
||||
ceilf(0.0f);
|
||||
copysignf(1.0f, -2.0f);
|
||||
cosf(0.0f);
|
||||
coshf(0.0f);
|
||||
cospif(0.0f);
|
||||
//cyl_bessel_i0f(0.0f);
|
||||
//cyl_bessel_i1f(0.0f);
|
||||
erfcf(0.0f);
|
||||
//erfcinvf(2.0f);
|
||||
//erfcxf(0.0f);
|
||||
erff(0.0f);
|
||||
//erfinvf(1.0f);
|
||||
exp10f(0.0f);
|
||||
exp2f(0.0f);
|
||||
expf(0.0f);
|
||||
expm1f(0.0f);
|
||||
fabsf(1.0f);
|
||||
fdimf(1.0f, 0.0f);
|
||||
//fdividef(0.0f, 1.0f);
|
||||
floorf(0.0f);
|
||||
fmaf(1.0f, 2.0f, 3.0f);
|
||||
fmaxf(0.0f, 0.0f);
|
||||
fminf(0.0f, 0.0f);
|
||||
fmodf(0.0f, 1.0f);
|
||||
//frexpf(0.0f, &iX);
|
||||
hypotf(1.0f, 0.0f);
|
||||
ilogbf(1.0f);
|
||||
isfinite(0.0f);
|
||||
isinf(0.0f);
|
||||
isnan(0.0f);
|
||||
//j0f(0.0f);
|
||||
//j1f(0.0f);
|
||||
//jnf(-1.0f, 1.0f);
|
||||
ldexpf(0.0f, 0);
|
||||
//lgammaf(1.0f);
|
||||
//llrintf(0.0f);
|
||||
//llroundf(0.0f);
|
||||
log10f(1.0f);
|
||||
log1pf(-1.0f);
|
||||
log2f(1.0f);
|
||||
logbf(1.0f);
|
||||
logf(1.0f);
|
||||
//lrintf(0.0f);
|
||||
//lroundf(0.0f);
|
||||
//modff(0.0f, &fX);
|
||||
nanf("1");
|
||||
nearbyintf(0.0f);
|
||||
//nextafterf(0.0f);
|
||||
//norm3df(1.0f, 0.0f, 0.0f);
|
||||
//norm4df(1.0f, 0.0f, 0.0f, 0.0f);
|
||||
//normcdff(0.0f);
|
||||
//normcdfinvf(1.0f);
|
||||
//fX = 1.0f; normf(1, &fX);
|
||||
powf(1.0f, 0.0f);
|
||||
//rcbrtf(1.0f);
|
||||
remainderf(2.0f, 1.0f);
|
||||
//remquof(1.0f, 2.0f, &iX);
|
||||
//rhypotf(0.0f, 1.0f);
|
||||
//rintf(1.0f);
|
||||
//rnorm3df(0.0f, 0.0f, 1.0f);
|
||||
//rnorm4df(0.0f, 0.0f, 0.0f, 1.0f);
|
||||
//fX = 1.0f; rnormf(1, &fX);
|
||||
roundf(0.0f);
|
||||
rsqrtf(1.0f);
|
||||
//scalblnf(0.0f, 1);
|
||||
scalbnf(0.0f, 1);
|
||||
signbit(1.0f);
|
||||
//sincosf(0.0f, &fX, &fY);
|
||||
//sincospif(0.0f, &fX, &fY);
|
||||
sinf(0.0f);
|
||||
sinhf(0.0f);
|
||||
sinpif(0.0f);
|
||||
sqrtf(0.0f);
|
||||
tanf(0.0f);
|
||||
tanhf(0.0f);
|
||||
tgammaf(2.0f);
|
||||
truncf(0.0f);
|
||||
//y0f(1.0f);
|
||||
//y1f(1.0f);
|
||||
//ynf(1, 1.0f);
|
||||
}
|
||||
|
||||
__global__ void compileSinglePrecisionMathOnDevice(hipLaunchParm lp, int ignored)
|
||||
{
|
||||
single_precision_math_functions();
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
/*
|
||||
Copyright (c) 2015-2016 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.
|
||||
*/
|
||||
#include "hip_runtime.h"
|
||||
#include "test_common.h"
|
||||
|
||||
#pragma GCC diagnostic ignored "-Wall"
|
||||
#pragma clang diagnostic ignored "-Wunused-variable"
|
||||
|
||||
__host__ void single_precision_math_functions()
|
||||
{
|
||||
int iX;
|
||||
float fX, fY;
|
||||
|
||||
acosf(1.0f);
|
||||
acoshf(1.0f);
|
||||
asinf(0.0f);
|
||||
asinhf(0.0f);
|
||||
atan2f(0.0f, 1.0f);
|
||||
atanf(0.0f);
|
||||
atanhf(0.0f);
|
||||
cbrtf(0.0f);
|
||||
ceilf(0.0f);
|
||||
copysignf(1.0f, -2.0f);
|
||||
cosf(0.0f);
|
||||
coshf(0.0f);
|
||||
cospif(0.0f);
|
||||
//cyl_bessel_i0f(0.0f);
|
||||
//cyl_bessel_i1f(0.0f);
|
||||
erfcf(0.0f);
|
||||
//erfcinvf(2.0f);
|
||||
//erfcxf(0.0f);
|
||||
erff(0.0f);
|
||||
//erfinvf(1.0f);
|
||||
exp10f(0.0f);
|
||||
exp2f(0.0f);
|
||||
expf(0.0f);
|
||||
expm1f(0.0f);
|
||||
fabsf(1.0f);
|
||||
fdimf(1.0f, 0.0f);
|
||||
//fdividef(0.0f, 1.0f);
|
||||
floorf(0.0f);
|
||||
fmaf(1.0f, 2.0f, 3.0f);
|
||||
fmaxf(0.0f, 0.0f);
|
||||
fminf(0.0f, 0.0f);
|
||||
fmodf(0.0f, 1.0f);
|
||||
frexpf(0.0f, &iX);
|
||||
hypotf(1.0f, 0.0f);
|
||||
ilogbf(1.0f);
|
||||
isfinite(0.0f);
|
||||
isinf(0.0f);
|
||||
isnan(0.0f);
|
||||
///j0f(0.0f);
|
||||
///j1f(0.0f);
|
||||
///jnf(-1.0f, 1.0f);
|
||||
ldexpf(0.0f, 0);
|
||||
///lgammaf(1.0f);
|
||||
///llrintf(0.0f);
|
||||
///llroundf(0.0f);
|
||||
log10f(1.0f);
|
||||
log1pf(-1.0f);
|
||||
log2f(1.0f);
|
||||
logbf(1.0f);
|
||||
logf(1.0f);
|
||||
///lrintf(0.0f);
|
||||
///lroundf(0.0f);
|
||||
modff(0.0f, &fX);
|
||||
///nanf("1");
|
||||
nearbyintf(0.0f);
|
||||
//nextafterf(0.0f);
|
||||
//norm3df(1.0f, 0.0f, 0.0f);
|
||||
//norm4df(1.0f, 0.0f, 0.0f, 0.0f);
|
||||
//normcdff(0.0f);
|
||||
//normcdfinvf(1.0f);
|
||||
//fX = 1.0f; normf(1, &fX);
|
||||
powf(1.0f, 0.0f);
|
||||
//rcbrtf(1.0f);
|
||||
remainderf(2.0f, 1.0f);
|
||||
remquof(1.0f, 2.0f, &iX);
|
||||
//rhypotf(0.0f, 1.0f);
|
||||
///rintf(1.0f);
|
||||
//rnorm3df(0.0f, 0.0f, 1.0f);
|
||||
//rnorm4df(0.0f, 0.0f, 0.0f, 1.0f);
|
||||
//fX = 1.0f; rnormf(1, &fX);
|
||||
roundf(0.0f);
|
||||
rsqrtf(1.0f);
|
||||
///scalblnf(0.0f, 1);
|
||||
scalbnf(0.0f, 1);
|
||||
signbit(1.0f);
|
||||
sincosf(0.0f, &fX, &fY);
|
||||
//sincospif(0.0f, &fX, &fY);
|
||||
sinf(0.0f);
|
||||
sinhf(0.0f);
|
||||
sinpif(0.0f);
|
||||
sqrtf(0.0f);
|
||||
tanf(0.0f);
|
||||
tanhf(0.0f);
|
||||
tgammaf(2.0f);
|
||||
truncf(0.0f);
|
||||
///y0f(1.0f);
|
||||
///y1f(1.0f);
|
||||
///ynf(1, 1.0f);
|
||||
}
|
||||
|
||||
static void compileOnHost()
|
||||
{
|
||||
single_precision_math_functions();
|
||||
}
|
||||
@@ -0,0 +1,634 @@
|
||||
/*
|
||||
Copyright (c) 2015-2016 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.
|
||||
*/
|
||||
#include"test_common.h"
|
||||
#include"hip_runtime.h"
|
||||
#include"hip_runtime_api.h"
|
||||
|
||||
#define N 512
|
||||
#define SIZE N*sizeof(float)
|
||||
|
||||
__global__ void test_sincosf(hipLaunchParm lp, float* a, float* b, float *c){
|
||||
int tid = hipThreadIdx_x;
|
||||
sincosf(a[tid], b+tid, c+tid);
|
||||
}
|
||||
|
||||
__global__ void test_sincospif(hipLaunchParm lp, float* a, float* b, float *c){
|
||||
int tid = hipThreadIdx_x;
|
||||
sincospif(a[tid], b+tid, c+tid);
|
||||
}
|
||||
|
||||
__global__ void test_fdividef(hipLaunchParm lp, float *a, float* b, float *c){
|
||||
int tid = hipThreadIdx_x;
|
||||
c[tid] = fdividef(a[tid], b[tid]);
|
||||
}
|
||||
|
||||
__global__ void test_llrintf(hipLaunchParm lp, float *a, long long int *b){
|
||||
int tid = hipThreadIdx_x;
|
||||
b[tid] = llrintf(a[tid]);
|
||||
}
|
||||
|
||||
__global__ void test_lrintf(hipLaunchParm lp, float *a, long int *b){
|
||||
int tid = hipThreadIdx_x;
|
||||
b[tid] = lrintf(a[tid]);
|
||||
}
|
||||
|
||||
__global__ void test_rintf(hipLaunchParm lp, float *a, float *b){
|
||||
int tid = hipThreadIdx_x;
|
||||
b[tid] = rintf(a[tid]);
|
||||
}
|
||||
|
||||
__global__ void test_llroundf(hipLaunchParm lp, float *a, long long int *b){
|
||||
int tid = hipThreadIdx_x;
|
||||
b[tid] = llroundf(a[tid]);
|
||||
}
|
||||
|
||||
__global__ void test_lroundf(hipLaunchParm lp, float *a, long int *b){
|
||||
int tid = hipThreadIdx_x;
|
||||
b[tid] = lroundf(a[tid]);
|
||||
}
|
||||
|
||||
__global__ void test_rhypotf(hipLaunchParm lp, float *a, float* b, float *c){
|
||||
int tid = hipThreadIdx_x;
|
||||
c[tid] = rhypotf(a[tid], b[tid]);
|
||||
}
|
||||
|
||||
__global__ void test_norm3df(hipLaunchParm lp, float *a, float* b, float *c, float *d){
|
||||
int tid = hipThreadIdx_x;
|
||||
d[tid] = norm3df(a[tid], b[tid], c[tid]);
|
||||
}
|
||||
|
||||
__global__ void test_norm4df(hipLaunchParm lp, float *a, float* b, float *c, float *d, float *e){
|
||||
int tid = hipThreadIdx_x;
|
||||
e[tid] = norm4df(a[tid], b[tid], c[tid], d[tid]);
|
||||
}
|
||||
|
||||
__global__ void test_normf(hipLaunchParm lp, float *a, float *b){
|
||||
int tid = hipThreadIdx_x;
|
||||
b[tid] = normf(N, a);
|
||||
}
|
||||
|
||||
__global__ void test_rnorm3df(hipLaunchParm lp, float *a, float* b, float *c, float *d){
|
||||
int tid = hipThreadIdx_x;
|
||||
d[tid] = rnorm3df(a[tid], b[tid], c[tid]);
|
||||
}
|
||||
|
||||
__global__ void test_rnorm4df(hipLaunchParm lp, float *a, float* b, float *c, float *d, float *e){
|
||||
int tid = hipThreadIdx_x;
|
||||
e[tid] = rnorm4df(a[tid], b[tid], c[tid], d[tid]);
|
||||
}
|
||||
|
||||
__global__ void test_rnormf(hipLaunchParm lp, float *a, float *b){
|
||||
int tid = hipThreadIdx_x;
|
||||
b[tid] = rnormf(N, a);
|
||||
}
|
||||
|
||||
__global__ void test_erfinvf(hipLaunchParm lp, float *a, float *b){
|
||||
int tid = hipThreadIdx_x;
|
||||
b[tid] = erff(erfinvf(a[tid]));
|
||||
}
|
||||
|
||||
|
||||
bool run_sincosf(){
|
||||
float *A, *Ad, *B, *C, *Bd, *Cd;
|
||||
A = new float[N];
|
||||
B = new float[N];
|
||||
C = new float[N];
|
||||
for(int i=0;i<N;i++){
|
||||
A[i] = 1.0f;
|
||||
}
|
||||
hipMalloc((void**)&Ad, SIZE);
|
||||
hipMalloc((void**)&Bd, SIZE);
|
||||
hipMalloc((void**)&Cd, SIZE);
|
||||
hipMemcpy(Ad, A, SIZE, hipMemcpyHostToDevice);
|
||||
hipLaunchKernel(test_sincosf, dim3(1), dim3(N), 0, 0, Ad, Bd, Cd);
|
||||
hipMemcpy(B, Bd, SIZE, hipMemcpyDeviceToHost);
|
||||
hipMemcpy(C, Cd, SIZE, hipMemcpyDeviceToHost);
|
||||
int passed = 0;
|
||||
for(int i=0;i<512;i++){
|
||||
if(B[i] == sinf(1.0f)){
|
||||
passed = 1;
|
||||
}
|
||||
}
|
||||
passed = 0;
|
||||
for(int i=0;i<512;i++){
|
||||
if(C[i] == cosf(1.0f)){
|
||||
passed = 1;
|
||||
}
|
||||
}
|
||||
free(A);
|
||||
if(passed == 1){
|
||||
return true;
|
||||
}
|
||||
assert(passed == 1);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool run_sincospif(){
|
||||
float *A, *Ad, *B, *C, *Bd, *Cd;
|
||||
A = new float[N];
|
||||
B = new float[N];
|
||||
C = new float[N];
|
||||
for(int i=0;i<N;i++){
|
||||
A[i] = 1.0f;
|
||||
}
|
||||
hipMalloc((void**)&Ad, SIZE);
|
||||
hipMalloc((void**)&Bd, SIZE);
|
||||
hipMalloc((void**)&Cd, SIZE);
|
||||
hipMemcpy(Ad, A, SIZE, hipMemcpyHostToDevice);
|
||||
hipLaunchKernel(test_sincospif, dim3(1), dim3(N), 0, 0, Ad, Bd, Cd);
|
||||
hipMemcpy(B, Bd, SIZE, hipMemcpyDeviceToHost);
|
||||
hipMemcpy(C, Cd, SIZE, hipMemcpyDeviceToHost);
|
||||
int passed = 0;
|
||||
for(int i=0;i<512;i++){
|
||||
if(B[i] - sinpif(1.0f) < 0.1){
|
||||
passed = 1;
|
||||
}
|
||||
}
|
||||
passed = 0;
|
||||
for(int i=0;i<512;i++){
|
||||
if(C[i] - cospif(1.0f) < 0.1){
|
||||
passed = 1;
|
||||
}
|
||||
}
|
||||
free(A);
|
||||
if(passed == 1){
|
||||
return true;
|
||||
}
|
||||
assert(passed == 1);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool run_fdividef(){
|
||||
float *A, *Ad, *B, *C, *Bd, *Cd;
|
||||
A = new float[N];
|
||||
B = new float[N];
|
||||
C = new float[N];
|
||||
for(int i=0;i<N;i++){
|
||||
A[i] = 1.0f;
|
||||
B[i] = 2.0f;
|
||||
}
|
||||
hipMalloc((void**)&Ad, SIZE);
|
||||
hipMalloc((void**)&Bd, SIZE);
|
||||
hipMalloc((void**)&Cd, SIZE);
|
||||
hipMemcpy(Ad, A, SIZE, hipMemcpyHostToDevice);
|
||||
hipMemcpy(Bd, B, SIZE, hipMemcpyHostToDevice);
|
||||
hipLaunchKernel(test_fdividef, dim3(1), dim3(N), 0, 0, Ad, Bd, Cd);
|
||||
hipMemcpy(C, Cd, SIZE, hipMemcpyDeviceToHost);
|
||||
int passed = 0;
|
||||
for(int i=0;i<512;i++){
|
||||
if(C[i] == A[i]/B[i]){
|
||||
passed = 1;
|
||||
}
|
||||
}
|
||||
|
||||
free(A);
|
||||
if(passed == 1){
|
||||
return true;
|
||||
}
|
||||
assert(passed == 1);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool run_llrintf(){
|
||||
float *A, *Ad;
|
||||
long long int *B, *Bd;
|
||||
A = new float[N];
|
||||
B = new long long int[N];
|
||||
for(int i=0;i<N;i++){
|
||||
A[i] = 1.345f;
|
||||
}
|
||||
hipMalloc((void**)&Ad, SIZE);
|
||||
hipMalloc((void**)&Bd, N*sizeof(long long int));
|
||||
hipMemcpy(Ad, A, SIZE, hipMemcpyHostToDevice);
|
||||
hipLaunchKernel(test_llrintf, dim3(1), dim3(N), 0, 0, Ad, Bd);
|
||||
hipMemcpy(B, Bd, N*sizeof(long long int), hipMemcpyDeviceToHost);
|
||||
int passed = 0;
|
||||
for(int i=0;i<512;i++){
|
||||
int x = roundf(A[i]);
|
||||
long long int y = x;
|
||||
if(B[i] == x){
|
||||
passed = 1;
|
||||
}
|
||||
}
|
||||
free(A);
|
||||
if(passed == 1){
|
||||
return true;
|
||||
}
|
||||
assert(passed == 1);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool run_lrintf(){
|
||||
float *A, *Ad;
|
||||
long int *B, *Bd;
|
||||
A = new float[N];
|
||||
B = new long int[N];
|
||||
for(int i=0;i<N;i++){
|
||||
A[i] = 1.345f;
|
||||
}
|
||||
hipMalloc((void**)&Ad, SIZE);
|
||||
hipMalloc((void**)&Bd, N*sizeof(long int));
|
||||
hipMemcpy(Ad, A, SIZE, hipMemcpyHostToDevice);
|
||||
hipLaunchKernel(test_lrintf, dim3(1), dim3(N), 0, 0, Ad, Bd);
|
||||
hipMemcpy(B, Bd, N*sizeof(long int), hipMemcpyDeviceToHost);
|
||||
int passed = 0;
|
||||
for(int i=0;i<512;i++){
|
||||
int x = roundf(A[i]);
|
||||
long int y = x;
|
||||
if(B[i] == x){
|
||||
passed = 1;
|
||||
}
|
||||
}
|
||||
free(A);
|
||||
if(passed == 1){
|
||||
return true;
|
||||
}
|
||||
assert(passed == 1);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool run_rintf(){
|
||||
float *A, *Ad;
|
||||
float *B, *Bd;
|
||||
A = new float[N];
|
||||
B = new float[N];
|
||||
for(int i=0;i<N;i++){
|
||||
A[i] = 1.345f;
|
||||
}
|
||||
hipMalloc((void**)&Ad, SIZE);
|
||||
hipMalloc((void**)&Bd, SIZE);
|
||||
hipMemcpy(Ad, A, SIZE, hipMemcpyHostToDevice);
|
||||
hipLaunchKernel(test_rintf, dim3(1), dim3(N), 0, 0, Ad, Bd);
|
||||
hipMemcpy(B, Bd, SIZE, hipMemcpyDeviceToHost);
|
||||
int passed = 0;
|
||||
for(int i=0;i<512;i++){
|
||||
float x = roundf(A[i]);
|
||||
if(B[i] == x){
|
||||
passed = 1;
|
||||
}
|
||||
}
|
||||
free(A);
|
||||
if(passed == 1){
|
||||
return true;
|
||||
}
|
||||
assert(passed == 1);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool run_llroundf(){
|
||||
float *A, *Ad;
|
||||
long long int *B, *Bd;
|
||||
A = new float[N];
|
||||
B = new long long int[N];
|
||||
for(int i=0;i<N;i++){
|
||||
A[i] = 1.345f;
|
||||
}
|
||||
hipMalloc((void**)&Ad, SIZE);
|
||||
hipMalloc((void**)&Bd, N*sizeof(long long int));
|
||||
hipMemcpy(Ad, A, SIZE, hipMemcpyHostToDevice);
|
||||
hipLaunchKernel(test_llroundf, dim3(1), dim3(N), 0, 0, Ad, Bd);
|
||||
hipMemcpy(B, Bd, N*sizeof(long long int), hipMemcpyDeviceToHost);
|
||||
int passed = 0;
|
||||
for(int i=0;i<512;i++){
|
||||
int x = roundf(A[i]);
|
||||
long long int y = x;
|
||||
if(B[i] == x){
|
||||
passed = 1;
|
||||
}
|
||||
}
|
||||
free(A);
|
||||
if(passed == 1){
|
||||
return true;
|
||||
}
|
||||
assert(passed == 1);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool run_lroundf(){
|
||||
float *A, *Ad;
|
||||
long int *B, *Bd;
|
||||
A = new float[N];
|
||||
B = new long int[N];
|
||||
for(int i=0;i<N;i++){
|
||||
A[i] = 1.345f;
|
||||
}
|
||||
hipMalloc((void**)&Ad, SIZE);
|
||||
hipMalloc((void**)&Bd, N*sizeof(long int));
|
||||
hipMemcpy(Ad, A, SIZE, hipMemcpyHostToDevice);
|
||||
hipLaunchKernel(test_lroundf, dim3(1), dim3(N), 0, 0, Ad, Bd);
|
||||
hipMemcpy(B, Bd, N*sizeof(long int), hipMemcpyDeviceToHost);
|
||||
int passed = 0;
|
||||
for(int i=0;i<512;i++){
|
||||
int x = roundf(A[i]);
|
||||
long int y = x;
|
||||
if(B[i] == x){
|
||||
passed = 1;
|
||||
}
|
||||
}
|
||||
free(A);
|
||||
if(passed == 1){
|
||||
return true;
|
||||
}
|
||||
assert(passed == 1);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool run_norm3df(){
|
||||
float *A, *Ad, *B, *Bd, *C, *Cd, *D, *Dd;
|
||||
A = new float[N];
|
||||
B = new float[N];
|
||||
C = new float[N];
|
||||
D = new float[N];
|
||||
float val = 0.0f;
|
||||
for(int i=0;i<N;i++){
|
||||
A[i] = 1.0f;
|
||||
B[i] = 2.0f;
|
||||
C[i] = 3.0f;
|
||||
}
|
||||
val = sqrtf(1.0f + 4.0f + 9.0f);
|
||||
hipMalloc((void**)&Ad, SIZE);
|
||||
hipMalloc((void**)&Bd, SIZE);
|
||||
hipMalloc((void**)&Cd, SIZE);
|
||||
hipMalloc((void**)&Dd, SIZE);
|
||||
hipMemcpy(Ad, A, SIZE, hipMemcpyHostToDevice);
|
||||
hipMemcpy(Bd, B, SIZE, hipMemcpyHostToDevice);
|
||||
hipMemcpy(Cd, C, SIZE, hipMemcpyHostToDevice);
|
||||
hipLaunchKernel(test_norm3df, dim3(1), dim3(N), 0, 0, Ad, Bd, Cd, Dd);
|
||||
hipMemcpy(D, Dd, SIZE, hipMemcpyDeviceToHost);
|
||||
int passed = 0;
|
||||
for(int i=0;i<512;i++){
|
||||
if(D[i] - val < 0.000001){
|
||||
passed = 1;
|
||||
}
|
||||
}
|
||||
free(A);
|
||||
if(passed == 1){
|
||||
return true;
|
||||
}
|
||||
assert(passed == 1);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool run_norm4df(){
|
||||
float *A, *Ad, *B, *Bd, *C, *Cd, *D, *Dd, *E, *Ed;
|
||||
A = new float[N];
|
||||
B = new float[N];
|
||||
C = new float[N];
|
||||
D = new float[N];
|
||||
E = new float[N];
|
||||
float val = 0.0f;
|
||||
for(int i=0;i<N;i++){
|
||||
A[i] = 1.0f;
|
||||
B[i] = 2.0f;
|
||||
C[i] = 3.0f;
|
||||
D[i] = 4.0f;
|
||||
}
|
||||
val = sqrtf(1.0f + 4.0f + 9.0f + 16.0f);
|
||||
hipMalloc((void**)&Ad, SIZE);
|
||||
hipMalloc((void**)&Bd, SIZE);
|
||||
hipMalloc((void**)&Cd, SIZE);
|
||||
hipMalloc((void**)&Dd, SIZE);
|
||||
hipMalloc((void**)&Ed, SIZE);
|
||||
hipMemcpy(Ad, A, SIZE, hipMemcpyHostToDevice);
|
||||
hipMemcpy(Bd, B, SIZE, hipMemcpyHostToDevice);
|
||||
hipMemcpy(Cd, C, SIZE, hipMemcpyHostToDevice);
|
||||
hipMemcpy(Dd, D, SIZE, hipMemcpyHostToDevice);
|
||||
hipLaunchKernel(test_norm4df, dim3(1), dim3(N), 0, 0, Ad, Bd, Cd, Dd, Ed);
|
||||
hipMemcpy(E, Ed, SIZE, hipMemcpyDeviceToHost);
|
||||
int passed = 0;
|
||||
for(int i=0;i<512;i++){
|
||||
if(E[i] - val < 0.000001){
|
||||
passed = 1;
|
||||
}
|
||||
}
|
||||
free(A);
|
||||
if(passed == 1){
|
||||
return true;
|
||||
}
|
||||
assert(passed == 1);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool run_normf(){
|
||||
float *A, *Ad, *B, *Bd;
|
||||
A = new float[N];
|
||||
B = new float[N];
|
||||
float val = 0.0f;
|
||||
for(int i=0;i<N;i++){
|
||||
A[i] = 1.0f;
|
||||
B[i] = 0.0f;
|
||||
val += 1.0f;
|
||||
}
|
||||
val = sqrtf(val);
|
||||
hipMalloc((void**)&Ad, SIZE);
|
||||
hipMalloc((void**)&Bd, SIZE);
|
||||
hipMemcpy(Ad, A, SIZE, hipMemcpyHostToDevice);
|
||||
hipLaunchKernel(test_normf, dim3(1), dim3(N), 0, 0, Ad, Bd);
|
||||
hipMemcpy(B, Bd, SIZE, hipMemcpyDeviceToHost);
|
||||
int passed = 0;
|
||||
for(int i=0;i<512;i++){
|
||||
if(B[0] - val < 0.000001){
|
||||
passed = 1;
|
||||
}
|
||||
}
|
||||
free(A);
|
||||
if(passed == 1){
|
||||
return true;
|
||||
}
|
||||
assert(passed == 1);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool run_rhypotf(){
|
||||
float *A, *Ad, *B, *Bd, *C, *Cd;
|
||||
A = new float[N];
|
||||
B = new float[N];
|
||||
C = new float[N];
|
||||
float val = 0.0f;
|
||||
for(int i=0;i<N;i++){
|
||||
A[i] = 1.0f;
|
||||
B[i] = 2.0f;
|
||||
}
|
||||
val = 1/sqrtf(1.0f + 4.0f);
|
||||
hipMalloc((void**)&Ad, SIZE);
|
||||
hipMalloc((void**)&Bd, SIZE);
|
||||
hipMalloc((void**)&Cd, SIZE);
|
||||
hipMemcpy(Ad, A, SIZE, hipMemcpyHostToDevice);
|
||||
hipMemcpy(Bd, B, SIZE, hipMemcpyHostToDevice);
|
||||
hipLaunchKernel(test_rhypotf, dim3(1), dim3(N), 0, 0, Ad, Bd, Cd);
|
||||
hipMemcpy(C, Cd, SIZE, hipMemcpyDeviceToHost);
|
||||
int passed = 0;
|
||||
for(int i=0;i<512;i++){
|
||||
if(C[i] - val < 0.000001){
|
||||
passed = 1;
|
||||
}
|
||||
}
|
||||
free(A);
|
||||
if(passed == 1){
|
||||
return true;
|
||||
}
|
||||
assert(passed == 1);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool run_rnorm3df(){
|
||||
float *A, *Ad, *B, *Bd, *C, *Cd, *D, *Dd;
|
||||
A = new float[N];
|
||||
B = new float[N];
|
||||
C = new float[N];
|
||||
D = new float[N];
|
||||
float val = 0.0f;
|
||||
for(int i=0;i<N;i++){
|
||||
A[i] = 1.0f;
|
||||
B[i] = 2.0f;
|
||||
C[i] = 3.0f;
|
||||
}
|
||||
val = 1/sqrtf(1.0f + 4.0f + 9.0f);
|
||||
hipMalloc((void**)&Ad, SIZE);
|
||||
hipMalloc((void**)&Bd, SIZE);
|
||||
hipMalloc((void**)&Cd, SIZE);
|
||||
hipMalloc((void**)&Dd, SIZE);
|
||||
hipMemcpy(Ad, A, SIZE, hipMemcpyHostToDevice);
|
||||
hipMemcpy(Bd, B, SIZE, hipMemcpyHostToDevice);
|
||||
hipMemcpy(Cd, C, SIZE, hipMemcpyHostToDevice);
|
||||
hipLaunchKernel(test_rnorm3df, dim3(1), dim3(N), 0, 0, Ad, Bd, Cd, Dd);
|
||||
hipMemcpy(D, Dd, SIZE, hipMemcpyDeviceToHost);
|
||||
int passed = 0;
|
||||
for(int i=0;i<512;i++){
|
||||
if(D[i] - val < 0.000001){
|
||||
passed = 1;
|
||||
}
|
||||
}
|
||||
free(A);
|
||||
if(passed == 1){
|
||||
return true;
|
||||
}
|
||||
assert(passed == 1);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool run_rnorm4df(){
|
||||
float *A, *Ad, *B, *Bd, *C, *Cd, *D, *Dd, *E, *Ed;
|
||||
A = new float[N];
|
||||
B = new float[N];
|
||||
C = new float[N];
|
||||
D = new float[N];
|
||||
E = new float[N];
|
||||
float val = 0.0f;
|
||||
for(int i=0;i<N;i++){
|
||||
A[i] = 1.0f;
|
||||
B[i] = 2.0f;
|
||||
C[i] = 3.0f;
|
||||
D[i] = 4.0f;
|
||||
}
|
||||
val = 1/sqrtf(1.0f + 4.0f + 9.0f + 16.0f);
|
||||
hipMalloc((void**)&Ad, SIZE);
|
||||
hipMalloc((void**)&Bd, SIZE);
|
||||
hipMalloc((void**)&Cd, SIZE);
|
||||
hipMalloc((void**)&Dd, SIZE);
|
||||
hipMalloc((void**)&Ed, SIZE);
|
||||
hipMemcpy(Ad, A, SIZE, hipMemcpyHostToDevice);
|
||||
hipMemcpy(Bd, B, SIZE, hipMemcpyHostToDevice);
|
||||
hipMemcpy(Cd, C, SIZE, hipMemcpyHostToDevice);
|
||||
hipMemcpy(Dd, D, SIZE, hipMemcpyHostToDevice);
|
||||
hipLaunchKernel(test_rnorm4df, dim3(1), dim3(N), 0, 0, Ad, Bd, Cd, Dd, Ed);
|
||||
hipMemcpy(E, Ed, SIZE, hipMemcpyDeviceToHost);
|
||||
int passed = 0;
|
||||
for(int i=0;i<512;i++){
|
||||
if(E[i] - val < 0.000001){
|
||||
passed = 1;
|
||||
}
|
||||
}
|
||||
free(A);
|
||||
if(passed == 1){
|
||||
return true;
|
||||
}
|
||||
assert(passed == 1);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool run_rnormf(){
|
||||
float *A, *Ad, *B, *Bd;
|
||||
A = new float[N];
|
||||
B = new float[N];
|
||||
float val = 0.0f;
|
||||
for(int i=0;i<N;i++){
|
||||
A[i] = 1.0f;
|
||||
B[i] = 0.0f;
|
||||
val += 1.0f;
|
||||
}
|
||||
val = 1/sqrtf(val);
|
||||
hipMalloc((void**)&Ad, SIZE);
|
||||
hipMalloc((void**)&Bd, SIZE);
|
||||
hipMemcpy(Ad, A, SIZE, hipMemcpyHostToDevice);
|
||||
hipLaunchKernel(test_rnormf, dim3(1), dim3(N), 0, 0, Ad, Bd);
|
||||
hipMemcpy(B, Bd, SIZE, hipMemcpyDeviceToHost);
|
||||
int passed = 0;
|
||||
for(int i=0;i<512;i++){
|
||||
if(B[0] - val < 0.000001){
|
||||
passed = 1;
|
||||
}
|
||||
}
|
||||
free(A);
|
||||
if(passed == 1){
|
||||
return true;
|
||||
}
|
||||
assert(passed == 1);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool run_erfinvf(){
|
||||
float *A, *Ad, *B, *Bd;
|
||||
A = new float[N];
|
||||
B = new float[N];
|
||||
for(int i=0;i<N;i++){
|
||||
A[i] = -0.6f;
|
||||
B[i] = 0.0f;
|
||||
}
|
||||
hipMalloc((void**)&Ad, SIZE);
|
||||
hipMalloc((void**)&Bd, SIZE);
|
||||
hipMemcpy(Ad, A, SIZE, hipMemcpyHostToDevice);
|
||||
hipLaunchKernel(test_erfinvf, dim3(1), dim3(N), 0, 0, Ad, Bd);
|
||||
hipMemcpy(B, Bd, SIZE, hipMemcpyDeviceToHost);
|
||||
int passed = 0;
|
||||
for(int i=0;i<512;i++){
|
||||
if(B[i] - A[i] < 0.000001){
|
||||
passed = 1;
|
||||
}
|
||||
}
|
||||
free(A);
|
||||
if(passed == 1){
|
||||
return true;
|
||||
}
|
||||
assert(passed == 1);
|
||||
return false;
|
||||
}
|
||||
|
||||
int main(){
|
||||
if(run_sincosf() && run_sincospif() && run_fdividef() &&
|
||||
run_llrintf() && run_norm3df() && run_norm4df() &&
|
||||
run_normf() && run_rnorm3df() && run_rnorm4df() &&
|
||||
run_rnormf() && run_lroundf() && run_llroundf() &&
|
||||
run_rintf() && run_rhypotf() && run_erfinvf()
|
||||
){
|
||||
passed();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,560 @@
|
||||
/*
|
||||
Copyright (c) 2015-2016 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.
|
||||
*/
|
||||
#include"test_common.h"
|
||||
#include"hip_runtime.h"
|
||||
#include"hip_runtime_api.h"
|
||||
|
||||
#define N 512
|
||||
#define SIZE N*sizeof(double)
|
||||
|
||||
__global__ void test_sincos(hipLaunchParm lp, double* a, double* b, double *c){
|
||||
int tid = hipThreadIdx_x;
|
||||
sincos(a[tid], b+tid, c+tid);
|
||||
}
|
||||
|
||||
__global__ void test_sincospi(hipLaunchParm lp, double* a, double* b, double *c){
|
||||
int tid = hipThreadIdx_x;
|
||||
sincospi(a[tid], b+tid, c+tid);
|
||||
}
|
||||
|
||||
__global__ void test_llrint(hipLaunchParm lp, double *a, long long int *b){
|
||||
int tid = hipThreadIdx_x;
|
||||
b[tid] = llrint(a[tid]);
|
||||
}
|
||||
|
||||
__global__ void test_lrint(hipLaunchParm lp, double *a, long int *b){
|
||||
int tid = hipThreadIdx_x;
|
||||
b[tid] = lrint(a[tid]);
|
||||
}
|
||||
|
||||
__global__ void test_rint(hipLaunchParm lp, double *a, double *b){
|
||||
int tid = hipThreadIdx_x;
|
||||
b[tid] = rint(a[tid]);
|
||||
}
|
||||
|
||||
__global__ void test_llround(hipLaunchParm lp, double *a, long long int *b){
|
||||
int tid = hipThreadIdx_x;
|
||||
b[tid] = llround(a[tid]);
|
||||
}
|
||||
|
||||
__global__ void test_lround(hipLaunchParm lp, double *a, long int *b){
|
||||
int tid = hipThreadIdx_x;
|
||||
b[tid] = lround(a[tid]);
|
||||
}
|
||||
|
||||
__global__ void test_rhypot(hipLaunchParm lp, double *a, double* b, double *c){
|
||||
int tid = hipThreadIdx_x;
|
||||
c[tid] = rhypot(a[tid], b[tid]);
|
||||
}
|
||||
|
||||
__global__ void test_norm3d(hipLaunchParm lp, double *a, double* b, double *c, double *d){
|
||||
int tid = hipThreadIdx_x;
|
||||
d[tid] = norm3d(a[tid], b[tid], c[tid]);
|
||||
}
|
||||
|
||||
__global__ void test_norm4d(hipLaunchParm lp, double *a, double* b, double *c, double *d, double *e){
|
||||
int tid = hipThreadIdx_x;
|
||||
e[tid] = norm4d(a[tid], b[tid], c[tid], d[tid]);
|
||||
}
|
||||
|
||||
__global__ void test_rnorm3d(hipLaunchParm lp, double *a, double* b, double *c, double *d){
|
||||
int tid = hipThreadIdx_x;
|
||||
d[tid] = rnorm3d(a[tid], b[tid], c[tid]);
|
||||
}
|
||||
|
||||
__global__ void test_rnorm4d(hipLaunchParm lp, double *a, double* b, double *c, double *d, double *e){
|
||||
int tid = hipThreadIdx_x;
|
||||
e[tid] = rnorm4d(a[tid], b[tid], c[tid], d[tid]);
|
||||
}
|
||||
|
||||
__global__ void test_rnorm(hipLaunchParm lp, double *a, double *b){
|
||||
int tid = hipThreadIdx_x;
|
||||
b[tid] = rnorm(N, a);
|
||||
}
|
||||
|
||||
__global__ void test_erfinv(hipLaunchParm lp, double *a, double *b){
|
||||
int tid = hipThreadIdx_x;
|
||||
b[tid] = erf(erfinv(a[tid]));
|
||||
}
|
||||
|
||||
bool run_sincos(){
|
||||
double *A, *Ad, *B, *C, *Bd, *Cd;
|
||||
A = new double[N];
|
||||
B = new double[N];
|
||||
C = new double[N];
|
||||
for(int i=0;i<N;i++){
|
||||
A[i] = 1.0;
|
||||
}
|
||||
hipMalloc((void**)&Ad, SIZE);
|
||||
hipMalloc((void**)&Bd, SIZE);
|
||||
hipMalloc((void**)&Cd, SIZE);
|
||||
hipMemcpy(Ad, A, SIZE, hipMemcpyHostToDevice);
|
||||
hipLaunchKernel(test_sincos, dim3(1), dim3(N), 0, 0, Ad, Bd, Cd);
|
||||
hipMemcpy(B, Bd, SIZE, hipMemcpyDeviceToHost);
|
||||
hipMemcpy(C, Cd, SIZE, hipMemcpyDeviceToHost);
|
||||
int passed = 0;
|
||||
for(int i=0;i<512;i++){
|
||||
if(B[i] == sin(1.0)){
|
||||
passed = 1;
|
||||
}
|
||||
}
|
||||
passed = 0;
|
||||
for(int i=0;i<512;i++){
|
||||
if(C[i] == cos(1.0)){
|
||||
passed = 1;
|
||||
}
|
||||
}
|
||||
free(A);
|
||||
if(passed == 1){
|
||||
return true;
|
||||
}
|
||||
assert(passed == 1);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool run_sincospi(){
|
||||
double *A, *Ad, *B, *C, *Bd, *Cd;
|
||||
A = new double[N];
|
||||
B = new double[N];
|
||||
C = new double[N];
|
||||
for(int i=0;i<N;i++){
|
||||
A[i] = 1.0;
|
||||
}
|
||||
hipMalloc((void**)&Ad, SIZE);
|
||||
hipMalloc((void**)&Bd, SIZE);
|
||||
hipMalloc((void**)&Cd, SIZE);
|
||||
hipMemcpy(Ad, A, SIZE, hipMemcpyHostToDevice);
|
||||
hipLaunchKernel(test_sincospi, dim3(1), dim3(N), 0, 0, Ad, Bd, Cd);
|
||||
hipMemcpy(B, Bd, SIZE, hipMemcpyDeviceToHost);
|
||||
hipMemcpy(C, Cd, SIZE, hipMemcpyDeviceToHost);
|
||||
int passed = 0;
|
||||
for(int i=0;i<512;i++){
|
||||
if(B[i] - sinpi(1.0) < 0.1){
|
||||
passed = 1;
|
||||
}
|
||||
}
|
||||
passed = 0;
|
||||
for(int i=0;i<512;i++){
|
||||
if(C[i] - cospi(1.0) < 0.1){
|
||||
passed = 1;
|
||||
}
|
||||
}
|
||||
free(A);
|
||||
if(passed == 1){
|
||||
return true;
|
||||
}
|
||||
assert(passed == 1);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool run_llrint(){
|
||||
double *A, *Ad;
|
||||
long long int *B, *Bd;
|
||||
A = new double[N];
|
||||
B = new long long int[N];
|
||||
for(int i=0;i<N;i++){
|
||||
A[i] = 1.345;
|
||||
}
|
||||
hipMalloc((void**)&Ad, SIZE);
|
||||
hipMalloc((void**)&Bd, N*sizeof(long long int));
|
||||
hipMemcpy(Ad, A, SIZE, hipMemcpyHostToDevice);
|
||||
hipLaunchKernel(test_llrint, dim3(1), dim3(N), 0, 0, Ad, Bd);
|
||||
hipMemcpy(B, Bd, N*sizeof(long long int), hipMemcpyDeviceToHost);
|
||||
int passed = 0;
|
||||
for(int i=0;i<512;i++){
|
||||
int x = round(A[i]);
|
||||
long long int y = x;
|
||||
if(B[i] == x){
|
||||
passed = 1;
|
||||
}
|
||||
}
|
||||
free(A);
|
||||
if(passed == 1){
|
||||
return true;
|
||||
}
|
||||
assert(passed == 1);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool run_lrint(){
|
||||
double *A, *Ad;
|
||||
long int *B, *Bd;
|
||||
A = new double[N];
|
||||
B = new long int[N];
|
||||
for(int i=0;i<N;i++){
|
||||
A[i] = 1.345;
|
||||
}
|
||||
hipMalloc((void**)&Ad, SIZE);
|
||||
hipMalloc((void**)&Bd, N*sizeof(long int));
|
||||
hipMemcpy(Ad, A, SIZE, hipMemcpyHostToDevice);
|
||||
hipLaunchKernel(test_lrint, dim3(1), dim3(N), 0, 0, Ad, Bd);
|
||||
hipMemcpy(B, Bd, N*sizeof(long int), hipMemcpyDeviceToHost);
|
||||
int passed = 0;
|
||||
for(int i=0;i<512;i++){
|
||||
long int x = round(A[i]);
|
||||
if(B[i] == x){
|
||||
passed = 1;
|
||||
}
|
||||
}
|
||||
free(A);
|
||||
if(passed == 1){
|
||||
return true;
|
||||
}
|
||||
assert(passed == 1);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool run_rint(){
|
||||
double *A, *Ad;
|
||||
double *B, *Bd;
|
||||
A = new double[N];
|
||||
B = new double[N];
|
||||
for(int i=0;i<N;i++){
|
||||
A[i] = 1.345;
|
||||
}
|
||||
hipMalloc((void**)&Ad, SIZE);
|
||||
hipMalloc((void**)&Bd, SIZE);
|
||||
hipMemcpy(Ad, A, SIZE, hipMemcpyHostToDevice);
|
||||
hipLaunchKernel(test_rint, dim3(1), dim3(N), 0, 0, Ad, Bd);
|
||||
hipMemcpy(B, Bd, SIZE, hipMemcpyDeviceToHost);
|
||||
int passed = 0;
|
||||
for(int i=0;i<512;i++){
|
||||
double x = round(A[i]);
|
||||
if(B[i] == x){
|
||||
passed = 1;
|
||||
}
|
||||
}
|
||||
free(A);
|
||||
if(passed == 1){
|
||||
return true;
|
||||
}
|
||||
assert(passed == 1);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool run_llround(){
|
||||
double *A, *Ad;
|
||||
long long int *B, *Bd;
|
||||
A = new double[N];
|
||||
B = new long long int[N];
|
||||
for(int i=0;i<N;i++){
|
||||
A[i] = 1.345;
|
||||
}
|
||||
hipMalloc((void**)&Ad, SIZE);
|
||||
hipMalloc((void**)&Bd, N*sizeof(long long int));
|
||||
hipMemcpy(Ad, A, SIZE, hipMemcpyHostToDevice);
|
||||
hipLaunchKernel(test_llround, dim3(1), dim3(N), 0, 0, Ad, Bd);
|
||||
hipMemcpy(B, Bd, N*sizeof(long long int), hipMemcpyDeviceToHost);
|
||||
int passed = 0;
|
||||
for(int i=0;i<512;i++){
|
||||
long long int x = round(A[i]);
|
||||
if(B[i] == x){
|
||||
passed = 1;
|
||||
}
|
||||
}
|
||||
free(A);
|
||||
if(passed == 1){
|
||||
return true;
|
||||
}
|
||||
assert(passed == 1);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool run_lround(){
|
||||
double *A, *Ad;
|
||||
long int *B, *Bd;
|
||||
A = new double[N];
|
||||
B = new long int[N];
|
||||
for(int i=0;i<N;i++){
|
||||
A[i] = 1.345;
|
||||
}
|
||||
hipMalloc((void**)&Ad, SIZE);
|
||||
hipMalloc((void**)&Bd, N*sizeof(long int));
|
||||
hipMemcpy(Ad, A, SIZE, hipMemcpyHostToDevice);
|
||||
hipLaunchKernel(test_lround, dim3(1), dim3(N), 0, 0, Ad, Bd);
|
||||
hipMemcpy(B, Bd, N*sizeof(long int), hipMemcpyDeviceToHost);
|
||||
int passed = 0;
|
||||
for(int i=0;i<512;i++){
|
||||
long int x = round(A[i]);
|
||||
if(B[i] == x){
|
||||
passed = 1;
|
||||
}
|
||||
}
|
||||
free(A);
|
||||
if(passed == 1){
|
||||
return true;
|
||||
}
|
||||
assert(passed == 1);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool run_norm3d(){
|
||||
double *A, *Ad, *B, *Bd, *C, *Cd, *D, *Dd;
|
||||
A = new double[N];
|
||||
B = new double[N];
|
||||
C = new double[N];
|
||||
D = new double[N];
|
||||
double val = 0.0;
|
||||
for(int i=0;i<N;i++){
|
||||
A[i] = 1.0;
|
||||
B[i] = 2.0;
|
||||
C[i] = 3.0;
|
||||
}
|
||||
val = sqrt(1.0 + 4.0 + 9.0);
|
||||
hipMalloc((void**)&Ad, SIZE);
|
||||
hipMalloc((void**)&Bd, SIZE);
|
||||
hipMalloc((void**)&Cd, SIZE);
|
||||
hipMalloc((void**)&Dd, SIZE);
|
||||
hipMemcpy(Ad, A, SIZE, hipMemcpyHostToDevice);
|
||||
hipMemcpy(Bd, B, SIZE, hipMemcpyHostToDevice);
|
||||
hipMemcpy(Cd, C, SIZE, hipMemcpyHostToDevice);
|
||||
hipLaunchKernel(test_norm3d, dim3(1), dim3(N), 0, 0, Ad, Bd, Cd, Dd);
|
||||
hipMemcpy(D, Dd, SIZE, hipMemcpyDeviceToHost);
|
||||
int passed = 0;
|
||||
for(int i=0;i<512;i++){
|
||||
if(D[i] - val < 0.000001){
|
||||
passed = 1;
|
||||
}
|
||||
}
|
||||
free(A);
|
||||
if(passed == 1){
|
||||
return true;
|
||||
}
|
||||
assert(passed == 1);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool run_norm4d(){
|
||||
double *A, *Ad, *B, *Bd, *C, *Cd, *D, *Dd, *E, *Ed;
|
||||
A = new double[N];
|
||||
B = new double[N];
|
||||
C = new double[N];
|
||||
D = new double[N];
|
||||
E = new double[N];
|
||||
double val = 0.0;
|
||||
for(int i=0;i<N;i++){
|
||||
A[i] = 1.0;
|
||||
B[i] = 2.0;
|
||||
C[i] = 3.0;
|
||||
D[i] = 4.0;
|
||||
}
|
||||
val = sqrt(1.0 + 4.0 + 9.0 + 16.0);
|
||||
hipMalloc((void**)&Ad, SIZE);
|
||||
hipMalloc((void**)&Bd, SIZE);
|
||||
hipMalloc((void**)&Cd, SIZE);
|
||||
hipMalloc((void**)&Dd, SIZE);
|
||||
hipMalloc((void**)&Ed, SIZE);
|
||||
hipMemcpy(Ad, A, SIZE, hipMemcpyHostToDevice);
|
||||
hipMemcpy(Bd, B, SIZE, hipMemcpyHostToDevice);
|
||||
hipMemcpy(Cd, C, SIZE, hipMemcpyHostToDevice);
|
||||
hipMemcpy(Dd, D, SIZE, hipMemcpyHostToDevice);
|
||||
hipLaunchKernel(test_norm4d, dim3(1), dim3(N), 0, 0, Ad, Bd, Cd, Dd, Ed);
|
||||
hipMemcpy(E, Ed, SIZE, hipMemcpyDeviceToHost);
|
||||
int passed = 0;
|
||||
for(int i=0;i<512;i++){
|
||||
if(E[i] - val < 0.000001){
|
||||
passed = 1;
|
||||
}
|
||||
}
|
||||
free(A);
|
||||
if(passed == 1){
|
||||
return true;
|
||||
}
|
||||
assert(passed == 1);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool run_rhypot(){
|
||||
double *A, *Ad, *B, *Bd, *C, *Cd;
|
||||
A = new double[N];
|
||||
B = new double[N];
|
||||
C = new double[N];
|
||||
double val = 0.0;
|
||||
for(int i=0;i<N;i++){
|
||||
A[i] = 1.0;
|
||||
B[i] = 2.0;
|
||||
}
|
||||
val = 1/sqrt(1.0 + 4.0);
|
||||
hipMalloc((void**)&Ad, SIZE);
|
||||
hipMalloc((void**)&Bd, SIZE);
|
||||
hipMalloc((void**)&Cd, SIZE);
|
||||
hipMemcpy(Ad, A, SIZE, hipMemcpyHostToDevice);
|
||||
hipMemcpy(Bd, B, SIZE, hipMemcpyHostToDevice);
|
||||
hipLaunchKernel(test_rhypot, dim3(1), dim3(N), 0, 0, Ad, Bd, Cd);
|
||||
hipMemcpy(C, Cd, SIZE, hipMemcpyDeviceToHost);
|
||||
int passed = 0;
|
||||
for(int i=0;i<512;i++){
|
||||
if(C[i] - val < 0.000001){
|
||||
passed = 1;
|
||||
}
|
||||
}
|
||||
free(A);
|
||||
if(passed == 1){
|
||||
return true;
|
||||
}
|
||||
assert(passed == 1);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool run_rnorm3d(){
|
||||
double *A, *Ad, *B, *Bd, *C, *Cd, *D, *Dd;
|
||||
A = new double[N];
|
||||
B = new double[N];
|
||||
C = new double[N];
|
||||
D = new double[N];
|
||||
double val = 0.0;
|
||||
for(int i=0;i<N;i++){
|
||||
A[i] = 1.0;
|
||||
B[i] = 2.0;
|
||||
C[i] = 3.0;
|
||||
}
|
||||
val = 1/sqrt(1.0 + 4.0 + 9.0);
|
||||
hipMalloc((void**)&Ad, SIZE);
|
||||
hipMalloc((void**)&Bd, SIZE);
|
||||
hipMalloc((void**)&Cd, SIZE);
|
||||
hipMalloc((void**)&Dd, SIZE);
|
||||
hipMemcpy(Ad, A, SIZE, hipMemcpyHostToDevice);
|
||||
hipMemcpy(Bd, B, SIZE, hipMemcpyHostToDevice);
|
||||
hipMemcpy(Cd, C, SIZE, hipMemcpyHostToDevice);
|
||||
hipLaunchKernel(test_rnorm3d, dim3(1), dim3(N), 0, 0, Ad, Bd, Cd, Dd);
|
||||
hipMemcpy(D, Dd, SIZE, hipMemcpyDeviceToHost);
|
||||
int passed = 0;
|
||||
for(int i=0;i<512;i++){
|
||||
if(D[i] - val < 0.000001){
|
||||
passed = 1;
|
||||
}
|
||||
}
|
||||
free(A);
|
||||
if(passed == 1){
|
||||
return true;
|
||||
}
|
||||
assert(passed == 1);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool run_rnorm4d(){
|
||||
double *A, *Ad, *B, *Bd, *C, *Cd, *D, *Dd, *E, *Ed;
|
||||
A = new double[N];
|
||||
B = new double[N];
|
||||
C = new double[N];
|
||||
D = new double[N];
|
||||
E = new double[N];
|
||||
double val = 0.0;
|
||||
for(int i=0;i<N;i++){
|
||||
A[i] = 1.0;
|
||||
B[i] = 2.0;
|
||||
C[i] = 3.0;
|
||||
D[i] = 4.0;
|
||||
}
|
||||
val = 1/sqrt(1.0 + 4.0 + 9.0 + 16.0);
|
||||
hipMalloc((void**)&Ad, SIZE);
|
||||
hipMalloc((void**)&Bd, SIZE);
|
||||
hipMalloc((void**)&Cd, SIZE);
|
||||
hipMalloc((void**)&Dd, SIZE);
|
||||
hipMalloc((void**)&Ed, SIZE);
|
||||
hipMemcpy(Ad, A, SIZE, hipMemcpyHostToDevice);
|
||||
hipMemcpy(Bd, B, SIZE, hipMemcpyHostToDevice);
|
||||
hipMemcpy(Cd, C, SIZE, hipMemcpyHostToDevice);
|
||||
hipMemcpy(Dd, D, SIZE, hipMemcpyHostToDevice);
|
||||
hipLaunchKernel(test_rnorm4d, dim3(1), dim3(N), 0, 0, Ad, Bd, Cd, Dd, Ed);
|
||||
hipMemcpy(E, Ed, SIZE, hipMemcpyDeviceToHost);
|
||||
int passed = 0;
|
||||
for(int i=0;i<512;i++){
|
||||
if(E[i] - val < 0.000001){
|
||||
passed = 1;
|
||||
}
|
||||
}
|
||||
free(A);
|
||||
if(passed == 1){
|
||||
return true;
|
||||
}
|
||||
assert(passed == 1);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool run_rnorm(){
|
||||
double *A, *Ad, *B, *Bd;
|
||||
A = new double[N];
|
||||
B = new double[N];
|
||||
double val = 0.0;
|
||||
for(int i=0;i<N;i++){
|
||||
A[i] = 1.0;
|
||||
B[i] = 0.0;
|
||||
val += 1.0;
|
||||
}
|
||||
val = 1/sqrt(val);
|
||||
hipMalloc((void**)&Ad, SIZE);
|
||||
hipMalloc((void**)&Bd, SIZE);
|
||||
hipMemcpy(Ad, A, SIZE, hipMemcpyHostToDevice);
|
||||
hipLaunchKernel(test_rnorm, dim3(1), dim3(N), 0, 0, Ad, Bd);
|
||||
hipMemcpy(B, Bd, SIZE, hipMemcpyDeviceToHost);
|
||||
int passed = 0;
|
||||
for(int i=0;i<512;i++){
|
||||
if(B[0] - val < 0.000001){
|
||||
passed = 1;
|
||||
}
|
||||
}
|
||||
free(A);
|
||||
if(passed == 1){
|
||||
return true;
|
||||
}
|
||||
assert(passed == 1);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool run_erfinv(){
|
||||
double *A, *Ad, *B, *Bd;
|
||||
A = new double[N];
|
||||
B = new double[N];
|
||||
for(int i=0;i<N;i++){
|
||||
A[i] = -0.6;
|
||||
B[i] = 0.0;
|
||||
}
|
||||
hipMalloc((void**)&Ad, SIZE);
|
||||
hipMalloc((void**)&Bd, SIZE);
|
||||
hipMemcpy(Ad, A, SIZE, hipMemcpyHostToDevice);
|
||||
hipLaunchKernel(test_erfinv, dim3(1), dim3(N), 0, 0, Ad, Bd);
|
||||
hipMemcpy(B, Bd, SIZE, hipMemcpyDeviceToHost);
|
||||
int passed = 0;
|
||||
for(int i=0;i<512;i++){
|
||||
if(B[i] - A[i] < 0.000001){
|
||||
passed = 1;
|
||||
}
|
||||
}
|
||||
free(A);
|
||||
if(passed == 1){
|
||||
return true;
|
||||
}
|
||||
assert(passed == 1);
|
||||
return false;
|
||||
}
|
||||
|
||||
int main(){
|
||||
if(run_sincos() && run_sincospi() && run_llrint() && run_norm3d() && run_norm4d() &&
|
||||
run_rnorm3d() && run_rnorm4d() &&
|
||||
run_rnorm() && run_lround() && run_llround() &&
|
||||
run_rint() && run_rhypot() && run_erfinv()
|
||||
){
|
||||
passed();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
/*
|
||||
Copyright (c) 2015-2016 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.
|
||||
*/
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <iostream>
|
||||
|
||||
#include <hip_runtime.h>
|
||||
#define HIP_ASSERT(x) (assert((x)==hipSuccess))
|
||||
|
||||
__global__ void
|
||||
warpvote(hipLaunchParm lp, int* device_any, int* device_all , int Num_Warps_per_Block, int pshift)
|
||||
{
|
||||
|
||||
int tid = hipThreadIdx_x + hipBlockIdx_x * hipBlockDim_x;
|
||||
device_any[hipThreadIdx_x>>pshift] = __any(tid -77);
|
||||
device_all[hipThreadIdx_x>>pshift] = __all(tid -77);
|
||||
}
|
||||
|
||||
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{ int warpSize, pshift;
|
||||
hipDeviceProp_t devProp;
|
||||
hipGetDeviceProperties(&devProp, 0);
|
||||
if(strncmp(devProp.name,"Fiji",1)==0)
|
||||
{ warpSize =64;
|
||||
pshift =6;
|
||||
}
|
||||
else {warpSize =32; pshift=5;}
|
||||
int anycount =0;
|
||||
int allcount =0;
|
||||
int Num_Threads_per_Block = 1024;
|
||||
int Num_Blocks_per_Grid = 1;
|
||||
int Num_Warps_per_Block = Num_Threads_per_Block/warpSize;
|
||||
int Num_Warps_per_Grid = (Num_Threads_per_Block*Num_Blocks_per_Grid)/warpSize;
|
||||
|
||||
int * host_any = ( int*)malloc(Num_Warps_per_Grid*sizeof(int));
|
||||
int * host_all = ( int*)malloc(Num_Warps_per_Grid*sizeof(int));
|
||||
int *device_any;
|
||||
int *device_all;
|
||||
HIP_ASSERT(hipMalloc((void**)&device_any,Num_Warps_per_Grid*sizeof( int)));
|
||||
HIP_ASSERT(hipMalloc((void**)&device_all,Num_Warps_per_Grid*sizeof(int)));
|
||||
for (int i=0; i<Num_Warps_per_Grid; i++)
|
||||
{
|
||||
host_any[i] = 0;
|
||||
host_all[i] = 0;
|
||||
}
|
||||
HIP_ASSERT(hipMemcpy(device_any, host_any,sizeof(int), hipMemcpyHostToDevice));
|
||||
HIP_ASSERT(hipMemcpy(device_all, host_all,sizeof(int), hipMemcpyHostToDevice));
|
||||
|
||||
hipLaunchKernel(warpvote, dim3(Num_Blocks_per_Grid),dim3(Num_Threads_per_Block),0,0, device_any, device_all ,Num_Warps_per_Block,pshift);
|
||||
|
||||
|
||||
HIP_ASSERT(hipMemcpy(host_any, device_any, Num_Warps_per_Grid*sizeof(int), hipMemcpyDeviceToHost));
|
||||
HIP_ASSERT(hipMemcpy(host_all, device_all, Num_Warps_per_Grid*sizeof(int), hipMemcpyDeviceToHost));
|
||||
for (int i=0; i<Num_Warps_per_Grid; i++) {
|
||||
|
||||
printf("warp no. %d __any = %d \n",i,host_any[i]);
|
||||
printf("warp no. %d __all = %d \n",i,host_all[i]);
|
||||
if (host_any[i]!=1) ++anycount;
|
||||
if (host_all[i]!=1) ++allcount;
|
||||
|
||||
}
|
||||
if (anycount == 0 && allcount ==1) printf("PASSED\n"); else printf("FAILED\n");
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
Copyright (c) 2015-2016 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.
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include <hip_runtime.h>
|
||||
#define HIP_ASSERT(x) (assert((x)==hipSuccess))
|
||||
|
||||
__global__ void
|
||||
gpu_ballot(hipLaunchParm lp, unsigned int* device_ballot, int Num_Warps_per_Block,int pshift)
|
||||
{
|
||||
|
||||
int tid = hipThreadIdx_x + hipBlockIdx_x * hipBlockDim_x;
|
||||
const unsigned int warp_num = hipThreadIdx_x >> pshift;
|
||||
#ifdef __HIP_PLATFORM_HCC__
|
||||
atomicAdd(&device_ballot[warp_num+hipBlockIdx_x*Num_Warps_per_Block],__popcll(__ballot(tid - 245)));
|
||||
#else
|
||||
atomicAdd(&device_ballot[warp_num+hipBlockIdx_x*Num_Warps_per_Block],__popc(__ballot(tid - 245)));
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{ int warpSize, pshift;
|
||||
hipDeviceProp_t devProp;
|
||||
hipGetDeviceProperties(&devProp, 0);
|
||||
|
||||
if(strncmp(devProp.name,"Fiji",1)==0)
|
||||
{warpSize = 64; pshift =6;}
|
||||
else {warpSize =32; pshift =5;}
|
||||
|
||||
unsigned int Num_Threads_per_Block = 512;
|
||||
unsigned int Num_Blocks_per_Grid = 1;
|
||||
unsigned int Num_Warps_per_Block = Num_Threads_per_Block/warpSize;
|
||||
unsigned int Num_Warps_per_Grid = (Num_Threads_per_Block*Num_Blocks_per_Grid)/warpSize;
|
||||
unsigned int* host_ballot = (unsigned int*)malloc(Num_Warps_per_Grid*sizeof(unsigned int));
|
||||
unsigned int* device_ballot;
|
||||
HIP_ASSERT(hipMalloc((void**)&device_ballot, Num_Warps_per_Grid*sizeof(unsigned int)));
|
||||
int divergent_count =0;
|
||||
for (int i=0; i<Num_Warps_per_Grid; i++) host_ballot[i] = 0;
|
||||
|
||||
|
||||
HIP_ASSERT(hipMemcpy(device_ballot, host_ballot, Num_Warps_per_Grid*sizeof(unsigned int), hipMemcpyHostToDevice));
|
||||
|
||||
hipLaunchKernel(gpu_ballot, dim3(Num_Blocks_per_Grid),dim3(Num_Threads_per_Block),0,0, device_ballot,Num_Warps_per_Block,pshift);
|
||||
|
||||
|
||||
HIP_ASSERT(hipMemcpy(host_ballot, device_ballot, Num_Warps_per_Grid*sizeof(unsigned int), hipMemcpyDeviceToHost));
|
||||
for (int i=0; i<Num_Warps_per_Grid; i++) {
|
||||
|
||||
if ((host_ballot[i] == 0)||(host_ballot[i]/warpSize == warpSize)) std::cout << "Warp " << i << " IS convergent- Predicate true for " << host_ballot[i]/warpSize << " threads\n";
|
||||
|
||||
else {std::cout << " Warp " << i << " IS divergent - Predicate true for " << host_ballot[i]/warpSize<< " threads\n";
|
||||
divergent_count++;}
|
||||
}
|
||||
|
||||
if (divergent_count==1) printf("PASSED\n"); else printf("FAILED\n");
|
||||
return EXIT_SUCCESS;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,178 @@
|
||||
/*
|
||||
Copyright (c) 2015-2016 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.
|
||||
*/
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <algorithm>
|
||||
#include <stdlib.h>
|
||||
#include <iostream>
|
||||
#include "hip_runtime.h"
|
||||
|
||||
|
||||
#define HIP_ASSERT(x) (assert((x)==hipSuccess))
|
||||
|
||||
|
||||
#define WIDTH 32
|
||||
#define HEIGHT 32
|
||||
|
||||
#define NUM (WIDTH*HEIGHT)
|
||||
|
||||
#define THREADS_PER_BLOCK_X 8
|
||||
#define THREADS_PER_BLOCK_Y 8
|
||||
#define THREADS_PER_BLOCK_Z 1
|
||||
|
||||
|
||||
|
||||
// CPU implementation of bitreverse
|
||||
template<typename T>
|
||||
T bitreverse(T num)
|
||||
{
|
||||
T count = sizeof(num) * 8 - 1;
|
||||
T reverse_num = num;
|
||||
|
||||
num >>= 1;
|
||||
while(num)
|
||||
{
|
||||
reverse_num <<= 1;
|
||||
reverse_num |= num & 1;
|
||||
num >>= 1;
|
||||
count--;
|
||||
}
|
||||
reverse_num <<= count;
|
||||
return reverse_num;
|
||||
}
|
||||
|
||||
__global__ void
|
||||
HIP_kernel(hipLaunchParm lp,
|
||||
unsigned int* a, unsigned int* b,unsigned long long int* c, unsigned long long int* d, int width, int height)
|
||||
{
|
||||
|
||||
int x = hipBlockDim_x * hipBlockIdx_x + hipThreadIdx_x;
|
||||
int y = hipBlockDim_y * hipBlockIdx_y + hipThreadIdx_y;
|
||||
|
||||
int i = y * width + x;
|
||||
if ( i < (width * height)) {
|
||||
a[i] = __brev(b[i]);
|
||||
c[i] = __brevll(d[i]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main() {
|
||||
|
||||
unsigned int* hostA;
|
||||
unsigned int* hostB;
|
||||
unsigned long long int* hostC;
|
||||
unsigned long long int* hostD;
|
||||
|
||||
unsigned int* deviceA;
|
||||
unsigned int* deviceB;
|
||||
unsigned long long int* deviceC;
|
||||
unsigned long long int* deviceD;
|
||||
|
||||
hipDeviceProp_t devProp;
|
||||
hipGetDeviceProperties(&devProp, 0);
|
||||
cout << " System minor " << devProp.minor << endl;
|
||||
cout << " System major " << devProp.major << endl;
|
||||
cout << " agent prop name " << devProp.name << endl;
|
||||
|
||||
cout << "hip Device prop succeeded " << endl ;
|
||||
|
||||
|
||||
int i;
|
||||
int errors;
|
||||
|
||||
hostA = (unsigned int*)malloc(NUM * sizeof(unsigned int));
|
||||
hostB = (unsigned int*)malloc(NUM * sizeof(unsigned int));
|
||||
hostC = (unsigned long long int*)malloc(NUM * sizeof(unsigned long long int));
|
||||
hostD = (unsigned long long int*)malloc(NUM * sizeof(unsigned long long int));
|
||||
|
||||
// initialize the input data
|
||||
for (i = 0; i < NUM; i++) {
|
||||
hostB[i] = i;
|
||||
hostD[i] = i;
|
||||
}
|
||||
|
||||
HIP_ASSERT(hipMalloc((void**)&deviceA, NUM * sizeof(unsigned int)));
|
||||
HIP_ASSERT(hipMalloc((void**)&deviceB, NUM * sizeof(unsigned int)));
|
||||
HIP_ASSERT(hipMalloc((void**)&deviceC, NUM * sizeof(unsigned long long int)));
|
||||
HIP_ASSERT(hipMalloc((void**)&deviceD, NUM * sizeof(unsigned long long int)));
|
||||
|
||||
HIP_ASSERT(hipMemcpy(deviceB, hostB, NUM*sizeof(unsigned int), hipMemcpyHostToDevice));
|
||||
HIP_ASSERT(hipMemcpy(deviceD, hostD, NUM*sizeof(unsigned long long int), hipMemcpyHostToDevice));
|
||||
|
||||
|
||||
hipLaunchKernel(HIP_kernel,
|
||||
dim3(WIDTH/THREADS_PER_BLOCK_X, HEIGHT/THREADS_PER_BLOCK_Y),
|
||||
dim3(THREADS_PER_BLOCK_X, THREADS_PER_BLOCK_Y),
|
||||
0, 0,
|
||||
deviceA ,deviceB, deviceC,deviceD ,WIDTH ,HEIGHT);
|
||||
|
||||
|
||||
HIP_ASSERT(hipMemcpy(hostA, deviceA, NUM*sizeof(unsigned int), hipMemcpyDeviceToHost));
|
||||
HIP_ASSERT(hipMemcpy(hostC, deviceC, NUM*sizeof(unsigned long long int), hipMemcpyDeviceToHost));
|
||||
|
||||
// verify the results
|
||||
errors = 0;
|
||||
for (i = 0; i < NUM; i++) {
|
||||
if (hostA[i] != bitreverse(hostB[i])) {
|
||||
errors++;
|
||||
}
|
||||
}
|
||||
if (errors!=0) {
|
||||
cout << "__brev() FAILED\n" << endl;
|
||||
return -1;
|
||||
} else {
|
||||
cout << "__brev() checked!" << endl;
|
||||
}
|
||||
errors = 0;
|
||||
for (i = 0; i < NUM; i++) {
|
||||
if (hostC[i] != bitreverse(hostD[i])) {
|
||||
errors++;
|
||||
}
|
||||
}
|
||||
if (errors!=0) {
|
||||
cout << "__brevll() FAILED" << endl;
|
||||
return -1;
|
||||
} else {
|
||||
cout << "__brevll() checked!" << endl;
|
||||
}
|
||||
|
||||
cout << "__brev() and __brevll() PASSED!" << endl;
|
||||
|
||||
HIP_ASSERT(hipFree(deviceA));
|
||||
HIP_ASSERT(hipFree(deviceB));
|
||||
HIP_ASSERT(hipFree(deviceC));
|
||||
HIP_ASSERT(hipFree(deviceD));
|
||||
|
||||
free(hostA);
|
||||
free(hostB);
|
||||
free(hostC);
|
||||
free(hostD);
|
||||
|
||||
return errors;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,247 @@
|
||||
/*
|
||||
Copyright (c) 2015-2016 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.
|
||||
*/
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <algorithm>
|
||||
#include <stdlib.h>
|
||||
#include <iostream>
|
||||
#include "hip_runtime.h"
|
||||
|
||||
|
||||
#define HIP_ASSERT(x) (assert((x)==hipSuccess))
|
||||
|
||||
|
||||
#define WIDTH 32
|
||||
#define HEIGHT 32
|
||||
|
||||
#define NUM (WIDTH*HEIGHT)
|
||||
|
||||
#define THREADS_PER_BLOCK_X 8
|
||||
#define THREADS_PER_BLOCK_Y 8
|
||||
#define THREADS_PER_BLOCK_Z 1
|
||||
|
||||
unsigned int firstbit_u32(unsigned int a)
|
||||
{
|
||||
if (a == 0)
|
||||
return -1;
|
||||
unsigned int pos = 0;
|
||||
while ((int )a > 0) {
|
||||
a <<= 1; pos++;
|
||||
}
|
||||
return pos;
|
||||
}
|
||||
unsigned int firstbit_s32(int a)
|
||||
{
|
||||
unsigned int u = a >= 0? a: ~a; // complement negative numbers
|
||||
return firstbit_u32(u);
|
||||
}
|
||||
|
||||
unsigned int firstbit_u64(unsigned long long int a)
|
||||
{
|
||||
if (a == 0)
|
||||
return -1;
|
||||
unsigned int pos = 0;
|
||||
while ((long long int)a > 0) {
|
||||
a <<= 1; pos++;
|
||||
}
|
||||
return pos;
|
||||
}
|
||||
unsigned int firstbit_s64(long long int a)
|
||||
{
|
||||
unsigned long long int u = a >= 0? a: ~a; // complement negative numbers
|
||||
return firstbit_u64(u);
|
||||
}
|
||||
|
||||
|
||||
|
||||
__global__ void
|
||||
HIP_kernel(hipLaunchParm lp,
|
||||
unsigned int* a, unsigned int* b,unsigned int* c, unsigned long long int* d,
|
||||
unsigned int* e, int* f,unsigned int* g, long long int* h, int width, int height)
|
||||
{
|
||||
|
||||
int x = hipBlockDim_x * hipBlockIdx_x + hipThreadIdx_x;
|
||||
int y = hipBlockDim_y * hipBlockIdx_y + hipThreadIdx_y;
|
||||
|
||||
int i = y * width + x;
|
||||
if ( i < (width * height)) {
|
||||
a[i] = __clz(b[i]);
|
||||
c[i] = __clzll(d[i]);
|
||||
e[i] = __clz(f[i]);
|
||||
g[i] = __clzll(h[i]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main() {
|
||||
|
||||
unsigned int* hostA;
|
||||
unsigned int* hostB;
|
||||
unsigned int* hostC;
|
||||
unsigned long long int* hostD;
|
||||
unsigned int* hostE;
|
||||
int* hostF;
|
||||
unsigned int* hostG;
|
||||
long long int* hostH;
|
||||
|
||||
unsigned int* deviceA;
|
||||
unsigned int* deviceB;
|
||||
unsigned int* deviceC;
|
||||
unsigned long long int* deviceD;
|
||||
unsigned int* deviceE;
|
||||
int* deviceF;
|
||||
unsigned int* deviceG;
|
||||
long long int* deviceH;
|
||||
|
||||
hipDeviceProp_t devProp;
|
||||
hipGetDeviceProperties(&devProp, 0);
|
||||
cout << " System minor " << devProp.minor << endl;
|
||||
cout << " System major " << devProp.major << endl;
|
||||
cout << " agent prop name " << devProp.name << endl;
|
||||
|
||||
cout << "hip Device prop succeeded " << endl ;
|
||||
|
||||
|
||||
int i;
|
||||
int errors;
|
||||
|
||||
hostA = (unsigned int*)malloc(NUM * sizeof(unsigned int));
|
||||
hostB = (unsigned int*)malloc(NUM * sizeof(unsigned int));
|
||||
hostC = (unsigned int*)malloc(NUM * sizeof(unsigned int));
|
||||
hostD = (unsigned long long int*)malloc(NUM * sizeof(unsigned long long int));
|
||||
hostE = (unsigned int*)malloc(NUM * sizeof(unsigned int));
|
||||
hostF = (int*)malloc(NUM * sizeof(int));
|
||||
hostG = (unsigned int*)malloc(NUM * sizeof(unsigned int));
|
||||
hostH = (long long int*)malloc(NUM * sizeof(long long int));
|
||||
|
||||
// initialize the input data
|
||||
for (i = 0; i < NUM; i++) {
|
||||
hostB[i] = i;
|
||||
hostD[i] = 1099511627776+i;
|
||||
hostF[i] = -2100+i;
|
||||
hostH[i] = 1099511627776+i;
|
||||
}
|
||||
|
||||
HIP_ASSERT(hipMalloc((void**)&deviceA, NUM * sizeof(unsigned int)));
|
||||
HIP_ASSERT(hipMalloc((void**)&deviceB, NUM * sizeof(unsigned int)));
|
||||
HIP_ASSERT(hipMalloc((void**)&deviceC, NUM * sizeof(unsigned int)));
|
||||
HIP_ASSERT(hipMalloc((void**)&deviceD, NUM * sizeof(unsigned long long int)));
|
||||
HIP_ASSERT(hipMalloc((void**)&deviceE, NUM * sizeof(unsigned int)));
|
||||
HIP_ASSERT(hipMalloc((void**)&deviceF, NUM * sizeof(int)));
|
||||
HIP_ASSERT(hipMalloc((void**)&deviceG, NUM * sizeof(unsigned int)));
|
||||
HIP_ASSERT(hipMalloc((void**)&deviceH, NUM * sizeof(long long int)));
|
||||
|
||||
HIP_ASSERT(hipMemcpy(deviceB, hostB, NUM*sizeof(unsigned int), hipMemcpyHostToDevice));
|
||||
HIP_ASSERT(hipMemcpy(deviceD, hostD, NUM*sizeof(unsigned long long int), hipMemcpyHostToDevice));
|
||||
HIP_ASSERT(hipMemcpy(deviceF, hostF, NUM*sizeof(int), hipMemcpyHostToDevice));
|
||||
HIP_ASSERT(hipMemcpy(deviceH, hostD, NUM*sizeof(long long int), hipMemcpyHostToDevice));
|
||||
|
||||
hipLaunchKernel(HIP_kernel,
|
||||
dim3(WIDTH/THREADS_PER_BLOCK_X, HEIGHT/THREADS_PER_BLOCK_Y),
|
||||
dim3(THREADS_PER_BLOCK_X, THREADS_PER_BLOCK_Y),
|
||||
0, 0,
|
||||
deviceA ,deviceB, deviceC,deviceD ,deviceE ,deviceF, deviceG,deviceH, WIDTH ,HEIGHT);
|
||||
|
||||
|
||||
HIP_ASSERT(hipMemcpy(hostA, deviceA, NUM*sizeof(unsigned int), hipMemcpyDeviceToHost));
|
||||
HIP_ASSERT(hipMemcpy(hostC, deviceC, NUM*sizeof(unsigned int), hipMemcpyDeviceToHost));
|
||||
HIP_ASSERT(hipMemcpy(hostE, deviceE, NUM*sizeof(unsigned int), hipMemcpyDeviceToHost));
|
||||
HIP_ASSERT(hipMemcpy(hostG, deviceG, NUM*sizeof(unsigned int), hipMemcpyDeviceToHost));
|
||||
|
||||
// verify the results
|
||||
errors = 0;
|
||||
for (i = 0; i < NUM; i++) {
|
||||
if (hostA[i] != firstbit_u32(hostB[i])) {
|
||||
errors++;
|
||||
}
|
||||
}
|
||||
if (errors!=0) {
|
||||
cout << "FAILED clz" << endl;
|
||||
return -1;
|
||||
} else {
|
||||
cout << "__clz_u() for unsigned checked!" << endl;
|
||||
}
|
||||
errors = 0;
|
||||
for (i = 0; i < NUM; i++) {
|
||||
if (hostC[i] != firstbit_u64(hostD[i])) {
|
||||
errors++;
|
||||
}
|
||||
}
|
||||
if (errors!=0) {
|
||||
cout << "FAILED clz" << endl;
|
||||
return -1;
|
||||
} else {
|
||||
cout << "__clzll_u() for unsigned checked!" << endl;
|
||||
}
|
||||
errors = 0;
|
||||
for (i = 0; i < NUM; i++) {
|
||||
if (hostE[i] != firstbit_s32(hostF[i])) {
|
||||
errors++;
|
||||
}
|
||||
}
|
||||
if (errors!=0) {
|
||||
cout << "FAILED clz\n" << endl;
|
||||
return -1;
|
||||
} else {
|
||||
cout << "__clz_s() checked!" << endl;
|
||||
}
|
||||
errors = 0;
|
||||
for (i = 0; i < NUM; i++) {
|
||||
if (hostG[i] != firstbit_s64(hostH[i])) {
|
||||
errors++;
|
||||
}
|
||||
}
|
||||
if (errors!=0) {
|
||||
cout << "FAILED clz" << endl;
|
||||
return -1;
|
||||
} else {
|
||||
cout << "__clzll_s() checked!" << endl;
|
||||
}
|
||||
|
||||
cout << "clz test PASSED!" << endl;
|
||||
|
||||
HIP_ASSERT(hipFree(deviceA));
|
||||
HIP_ASSERT(hipFree(deviceB));
|
||||
HIP_ASSERT(hipFree(deviceC));
|
||||
HIP_ASSERT(hipFree(deviceD));
|
||||
HIP_ASSERT(hipFree(deviceE));
|
||||
HIP_ASSERT(hipFree(deviceF));
|
||||
HIP_ASSERT(hipFree(deviceG));
|
||||
HIP_ASSERT(hipFree(deviceH));
|
||||
|
||||
free(hostA);
|
||||
free(hostB);
|
||||
free(hostC);
|
||||
free(hostD);
|
||||
free(hostE);
|
||||
free(hostF);
|
||||
free(hostG);
|
||||
free(hostH);
|
||||
|
||||
return errors;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,171 @@
|
||||
/*
|
||||
Copyright (c) 2015-2016 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.
|
||||
*/
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <algorithm>
|
||||
#include <stdlib.h>
|
||||
#include <iostream>
|
||||
#include "hip_runtime.h"
|
||||
|
||||
|
||||
#define HIP_ASSERT(x) (assert((x)==hipSuccess))
|
||||
|
||||
|
||||
#define WIDTH 32
|
||||
#define HEIGHT 32
|
||||
|
||||
#define NUM (WIDTH*HEIGHT)
|
||||
|
||||
#define THREADS_PER_BLOCK_X 8
|
||||
#define THREADS_PER_BLOCK_Y 8
|
||||
#define THREADS_PER_BLOCK_Z 1
|
||||
|
||||
template<typename T>
|
||||
int lastbit( T a)
|
||||
{
|
||||
if (a == 0)
|
||||
return 0;
|
||||
int pos = 1;
|
||||
while ((a&1) != 1) {
|
||||
a >>= 1; pos++;
|
||||
}
|
||||
return pos;
|
||||
}
|
||||
|
||||
|
||||
__global__ void
|
||||
HIP_kernel(hipLaunchParm lp,
|
||||
unsigned int* a, unsigned int* b, unsigned int* c, unsigned long long int* d,
|
||||
int width, int height)
|
||||
{
|
||||
|
||||
int x = hipBlockDim_x * hipBlockIdx_x + hipThreadIdx_x;
|
||||
int y = hipBlockDim_y * hipBlockIdx_y + hipThreadIdx_y;
|
||||
|
||||
int i = y * width + x;
|
||||
if ( i < (width * height)) {
|
||||
a[i] = __ffs(b[i]);
|
||||
c[i] = __ffsll(d[i]);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main() {
|
||||
|
||||
unsigned int* hostA;
|
||||
unsigned int* hostB;
|
||||
unsigned int* hostC;
|
||||
unsigned long long int* hostD;
|
||||
|
||||
unsigned int* deviceA;
|
||||
unsigned int* deviceB;
|
||||
unsigned int* deviceC;
|
||||
unsigned long long int* deviceD;
|
||||
|
||||
hipDeviceProp_t devProp;
|
||||
hipGetDeviceProperties(&devProp, 0);
|
||||
cout << " System minor " << devProp.minor << endl;
|
||||
cout << " System major " << devProp.major << endl;
|
||||
cout << " agent prop name " << devProp.name << endl;
|
||||
|
||||
cout << "hip Device prop succeeded " << endl ;
|
||||
|
||||
|
||||
int i;
|
||||
int errors;
|
||||
|
||||
hostA = (unsigned int*)malloc(NUM * sizeof(unsigned int));
|
||||
hostB = (unsigned int*)malloc(NUM * sizeof(unsigned int));
|
||||
hostC = (unsigned int*)malloc(NUM * sizeof(unsigned int));
|
||||
hostD = (unsigned long long int*)malloc(NUM * sizeof(unsigned long long int));
|
||||
|
||||
// initialize the input data
|
||||
for (i = 0; i < NUM; i++) {
|
||||
hostB[i] = i;
|
||||
hostD[i] = 1099511627776+i;
|
||||
}
|
||||
|
||||
HIP_ASSERT(hipMalloc((void**)&deviceA, NUM * sizeof(unsigned int)));
|
||||
HIP_ASSERT(hipMalloc((void**)&deviceB, NUM * sizeof(unsigned int)));
|
||||
HIP_ASSERT(hipMalloc((void**)&deviceC, NUM * sizeof(unsigned int)));
|
||||
HIP_ASSERT(hipMalloc((void**)&deviceD, NUM * sizeof(unsigned long long int)));
|
||||
|
||||
HIP_ASSERT(hipMemcpy(deviceB, hostB, NUM*sizeof(unsigned int), hipMemcpyHostToDevice));
|
||||
HIP_ASSERT(hipMemcpy(deviceD, hostD, NUM*sizeof(unsigned long long int), hipMemcpyHostToDevice));
|
||||
|
||||
hipLaunchKernel(HIP_kernel,
|
||||
dim3(WIDTH/THREADS_PER_BLOCK_X, HEIGHT/THREADS_PER_BLOCK_Y),
|
||||
dim3(THREADS_PER_BLOCK_X, THREADS_PER_BLOCK_Y),
|
||||
0, 0,
|
||||
deviceA ,deviceB, deviceC,deviceD, WIDTH ,HEIGHT);
|
||||
|
||||
|
||||
HIP_ASSERT(hipMemcpy(hostA, deviceA, NUM*sizeof(unsigned int), hipMemcpyDeviceToHost));
|
||||
HIP_ASSERT(hipMemcpy(hostC, deviceC, NUM*sizeof(unsigned int), hipMemcpyDeviceToHost));
|
||||
|
||||
// verify the results
|
||||
errors = 0;
|
||||
for (i = 0; i < NUM; i++) {
|
||||
if (hostA[i] != lastbit(hostB[i])) {
|
||||
errors++;
|
||||
}
|
||||
}
|
||||
if (errors!=0) {
|
||||
cout << "FAILED: ffs" << endl;
|
||||
return -1;
|
||||
} else {
|
||||
cout << "__ffs() for unsigned checked!" << endl;
|
||||
}
|
||||
errors = 0;
|
||||
for (i = 0; i < NUM; i++) {
|
||||
if (hostC[i] != lastbit(hostD[i])) {
|
||||
errors++;
|
||||
}
|
||||
}
|
||||
if (errors!=0) {
|
||||
cout << "FAILED: ffs" << endl;
|
||||
return -1;
|
||||
} else {
|
||||
cout << "__ffsll() for unsigned checked!" << endl;
|
||||
}
|
||||
|
||||
cout << "ffs test PASSED!" << endl;
|
||||
|
||||
HIP_ASSERT(hipFree(deviceA));
|
||||
HIP_ASSERT(hipFree(deviceB));
|
||||
HIP_ASSERT(hipFree(deviceC));
|
||||
HIP_ASSERT(hipFree(deviceD));
|
||||
|
||||
|
||||
free(hostA);
|
||||
free(hostB);
|
||||
free(hostC);
|
||||
free(hostD);
|
||||
|
||||
return errors;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,169 @@
|
||||
/*
|
||||
Copyright (c) 2015-2016 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.
|
||||
*/
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <algorithm>
|
||||
#include <stdlib.h>
|
||||
#include <iostream>
|
||||
#include "hip_runtime.h"
|
||||
|
||||
|
||||
#define HIP_ASSERT(x) (assert((x)==hipSuccess))
|
||||
|
||||
|
||||
#define WIDTH 16
|
||||
#define HEIGHT 16
|
||||
|
||||
#define NUM (WIDTH*HEIGHT)
|
||||
|
||||
#define THREADS_PER_BLOCK_X 8
|
||||
#define THREADS_PER_BLOCK_Y 8
|
||||
#define THREADS_PER_BLOCK_Z 1
|
||||
|
||||
|
||||
|
||||
// CPU implementation of popcount
|
||||
template<typename T>
|
||||
unsigned int popcountCPU( T value) {
|
||||
unsigned int ret = 0;
|
||||
while (value) {
|
||||
if (value & 0x1) ++ret;
|
||||
value >>=1;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
__global__ void
|
||||
HIP_kernel(hipLaunchParm lp,
|
||||
unsigned int* a, unsigned int* b,unsigned int* c, unsigned long long int* d, int width, int height)
|
||||
{
|
||||
|
||||
int x = hipBlockDim_x * hipBlockIdx_x + hipThreadIdx_x;
|
||||
int y = hipBlockDim_y * hipBlockIdx_y + hipThreadIdx_y;
|
||||
|
||||
int i = y * width + x;
|
||||
if ( i < (width * height)) {
|
||||
a[i] = __popc(b[i]);
|
||||
c[i] = __popcll(d[i]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main() {
|
||||
|
||||
unsigned int* hostA;
|
||||
unsigned int* hostB;
|
||||
unsigned int* hostC;
|
||||
unsigned long long int* hostD;
|
||||
|
||||
unsigned int* deviceA;
|
||||
unsigned int* deviceB;
|
||||
unsigned int* deviceC;
|
||||
unsigned long long int* deviceD;
|
||||
|
||||
hipDeviceProp_t devProp;
|
||||
hipGetDeviceProperties(&devProp, 0);
|
||||
cout << " System minor " << devProp.minor << endl;
|
||||
cout << " System major " << devProp.major << endl;
|
||||
cout << " agent prop name " << devProp.name << endl;
|
||||
|
||||
cout << "hip Device prop succeeded " << endl ;
|
||||
|
||||
|
||||
int i;
|
||||
int errors;
|
||||
|
||||
hostA = (unsigned int*)malloc(NUM * sizeof(unsigned int));
|
||||
hostB = (unsigned int*)malloc(NUM * sizeof(unsigned int));
|
||||
hostC = (unsigned int*)malloc(NUM * sizeof(unsigned int));
|
||||
hostD = (unsigned long long int*)malloc(NUM * sizeof(unsigned long long int));
|
||||
|
||||
// initialize the input data
|
||||
for (i = 0; i < NUM; i++) {
|
||||
hostB[i] = i;
|
||||
hostD[i] = 1099511627776-i;
|
||||
}
|
||||
|
||||
HIP_ASSERT(hipMalloc((void**)&deviceA, NUM * sizeof(unsigned int)));
|
||||
HIP_ASSERT(hipMalloc((void**)&deviceB, NUM * sizeof(unsigned int)));
|
||||
HIP_ASSERT(hipMalloc((void**)&deviceC, NUM * sizeof(unsigned int)));
|
||||
HIP_ASSERT(hipMalloc((void**)&deviceD, NUM * sizeof(unsigned long long int)));
|
||||
|
||||
HIP_ASSERT(hipMemcpy(deviceB, hostB, NUM*sizeof(unsigned int), hipMemcpyHostToDevice));
|
||||
HIP_ASSERT(hipMemcpy(deviceD, hostD, NUM*sizeof(unsigned long long int), hipMemcpyHostToDevice));
|
||||
|
||||
|
||||
hipLaunchKernel(HIP_kernel,
|
||||
dim3(WIDTH/THREADS_PER_BLOCK_X, HEIGHT/THREADS_PER_BLOCK_Y),
|
||||
dim3(THREADS_PER_BLOCK_X, THREADS_PER_BLOCK_Y),
|
||||
0, 0,
|
||||
deviceA ,deviceB, deviceC,deviceD ,WIDTH ,HEIGHT);
|
||||
|
||||
|
||||
HIP_ASSERT(hipMemcpy(hostA, deviceA, NUM*sizeof(unsigned int), hipMemcpyDeviceToHost));
|
||||
HIP_ASSERT(hipMemcpy(hostC, deviceC, NUM*sizeof(unsigned int), hipMemcpyDeviceToHost));
|
||||
// verify the results
|
||||
errors = 0;
|
||||
for (i = 0; i < NUM; i++) {
|
||||
if (hostA[i] != popcountCPU(hostB[i])) {
|
||||
errors++;
|
||||
}
|
||||
}
|
||||
if (errors!=0) {
|
||||
cout << "FAILED: popc" << endl;
|
||||
return -1;
|
||||
} else {
|
||||
cout << "__popc() checked!" << endl;
|
||||
}
|
||||
errors = 0;
|
||||
for (i = 0; i < NUM; i++) {
|
||||
if (hostC[i] != popcountCPU(hostD[i])) {
|
||||
errors++;
|
||||
}
|
||||
}
|
||||
if (errors!=0) {
|
||||
cout << "FAILED:popc" << endl;
|
||||
return -1;
|
||||
} else {
|
||||
cout << "__popcll() checked!" << endl;
|
||||
}
|
||||
|
||||
cout << "popc test PASSED!" << endl;
|
||||
|
||||
HIP_ASSERT(hipFree(deviceA));
|
||||
HIP_ASSERT(hipFree(deviceB));
|
||||
HIP_ASSERT(hipFree(deviceC));
|
||||
HIP_ASSERT(hipFree(deviceD));
|
||||
|
||||
free(hostA);
|
||||
free(hostB);
|
||||
free(hostC);
|
||||
free(hostD);
|
||||
|
||||
return errors;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,385 @@
|
||||
/*
|
||||
Copyright (c) 2015-2016 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.
|
||||
*/
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <algorithm>
|
||||
#include <stdlib.h>
|
||||
#include<iostream>
|
||||
#include "hip_runtime.h"
|
||||
#include "test_common.h"
|
||||
|
||||
#if (__hcc_workweek__ >= 16164) || defined (__HIP_PLATFORM_NVCC__)
|
||||
|
||||
#define HIP_ASSERT(x) (assert((x)==hipSuccess))
|
||||
|
||||
|
||||
#define WIDTH 8
|
||||
#define HEIGHT 8
|
||||
|
||||
#define NUM (WIDTH*HEIGHT)
|
||||
|
||||
#define THREADS_PER_BLOCK_X 8
|
||||
#define THREADS_PER_BLOCK_Y 8
|
||||
#define THREADS_PER_BLOCK_Z 1
|
||||
|
||||
using namespace std;
|
||||
|
||||
template<typename T>
|
||||
__global__ void
|
||||
vectoradd_float(hipLaunchParm lp,
|
||||
T* a, const T* bm, int width, int height)
|
||||
|
||||
{
|
||||
int x = hipBlockDim_x * hipBlockIdx_x + hipThreadIdx_x;
|
||||
int y = hipBlockDim_y * hipBlockIdx_y + hipThreadIdx_y;
|
||||
|
||||
int i = y * width + x;
|
||||
if ( i < (width * height)) {
|
||||
a[i] = __ldg(&bm[i]) ;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
int2 make_vector2(int a){
|
||||
return make_int2(a,a);
|
||||
}
|
||||
|
||||
char2 make_vector2(signed char a){
|
||||
return make_char2(a, a);
|
||||
}
|
||||
|
||||
char4 make_vector4(signed char a){
|
||||
return make_char4(a, a, a ,a);
|
||||
}
|
||||
|
||||
short2 make_vector2(short a){
|
||||
return make_short2(a,a);
|
||||
}
|
||||
|
||||
ushort2 make_vector2(unsigned short a){
|
||||
return make_ushort2(a,a);
|
||||
}
|
||||
|
||||
short4 make_vector4(short a){
|
||||
return make_short4(a,a,a,a);
|
||||
}
|
||||
|
||||
int4 make_vector4(int a){
|
||||
return make_int4(a,a,a,a);
|
||||
}
|
||||
|
||||
uint2 make_vector2 (unsigned int a){
|
||||
return make_uint2 (a,a);
|
||||
}
|
||||
|
||||
uint4 make_vector4 (unsigned int a){
|
||||
return make_uint4 (a,a,a,a);
|
||||
}
|
||||
|
||||
float2 make_vector2 (float a){
|
||||
return make_float2 (a,a);
|
||||
}
|
||||
|
||||
float4 make_vector4 (float a){
|
||||
return make_float4 (a,a,a,a);
|
||||
}
|
||||
|
||||
uchar2 make_vector2 (unsigned char a){
|
||||
return make_uchar2 (a,a);
|
||||
}
|
||||
|
||||
uchar4 make_vector4 (unsigned char a){
|
||||
return make_uchar4 (a,a,a,a);
|
||||
}
|
||||
|
||||
double2 make_vector2 (double a){
|
||||
return make_double2 (a,a);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
template<typename T, typename U>
|
||||
bool dataTypesRun(){
|
||||
T* hostA;
|
||||
T* hostB;
|
||||
|
||||
|
||||
T* deviceA;
|
||||
T* deviceB;
|
||||
|
||||
|
||||
int i;
|
||||
int errors;
|
||||
|
||||
hostA = (T*)malloc(NUM * sizeof(T));
|
||||
hostB = (T*)malloc(NUM * sizeof(T));
|
||||
|
||||
// initialize the input data
|
||||
for (i = 0; i < NUM; i++) {
|
||||
hostB[i] = (U)i;
|
||||
}
|
||||
|
||||
HIP_ASSERT(hipMalloc((void**)&deviceA, NUM * sizeof(T)));
|
||||
HIP_ASSERT(hipMalloc((void**)&deviceB, NUM * sizeof(T)));
|
||||
|
||||
HIP_ASSERT(hipMemcpy(deviceB, hostB, NUM*sizeof(T), hipMemcpyHostToDevice));
|
||||
|
||||
|
||||
hipLaunchKernel(vectoradd_float,
|
||||
dim3(WIDTH/THREADS_PER_BLOCK_X, HEIGHT/THREADS_PER_BLOCK_Y),
|
||||
dim3(THREADS_PER_BLOCK_X, THREADS_PER_BLOCK_Y),
|
||||
0, 0,
|
||||
deviceA ,deviceB ,WIDTH ,HEIGHT);
|
||||
|
||||
|
||||
HIP_ASSERT(hipMemcpy(hostA, deviceA, NUM*sizeof(T), hipMemcpyDeviceToHost));
|
||||
|
||||
bool ret = false;
|
||||
// verify the results
|
||||
errors = 0;
|
||||
for (i = 0; i < NUM; i++) {
|
||||
if (hostA[i] != (hostB[i])) {
|
||||
errors++;
|
||||
}
|
||||
}
|
||||
if (errors!=0) {
|
||||
std::cout << "FAILED\n"<<std::endl;
|
||||
ret = false;
|
||||
} else {
|
||||
ret = true;
|
||||
}
|
||||
|
||||
HIP_ASSERT(hipFree(deviceA));
|
||||
HIP_ASSERT(hipFree(deviceB));
|
||||
|
||||
free(hostA);
|
||||
free(hostB);
|
||||
|
||||
return ret;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
template<typename T, typename U>
|
||||
bool dataTypesRun2(){
|
||||
T* hostA;
|
||||
T* hostB;
|
||||
|
||||
|
||||
T* deviceA;
|
||||
T* deviceB;
|
||||
|
||||
|
||||
int i;
|
||||
int errors;
|
||||
|
||||
hostA = (T*)malloc(NUM * sizeof(T));
|
||||
hostB = (T*)malloc(NUM * sizeof(T));
|
||||
|
||||
// initialize the input data
|
||||
for (i = 0; i < NUM; i++) {
|
||||
hostB[i] = make_vector2((U)i);
|
||||
|
||||
}
|
||||
|
||||
HIP_ASSERT(hipMalloc((void**)&deviceA, NUM * sizeof(T)));
|
||||
HIP_ASSERT(hipMalloc((void**)&deviceB, NUM * sizeof(T)));
|
||||
|
||||
HIP_ASSERT(hipMemcpy(deviceB, hostB, NUM*sizeof(T), hipMemcpyHostToDevice));
|
||||
hipLaunchKernel(vectoradd_float,
|
||||
dim3(WIDTH/THREADS_PER_BLOCK_X, HEIGHT/THREADS_PER_BLOCK_Y),
|
||||
dim3(THREADS_PER_BLOCK_X, THREADS_PER_BLOCK_Y),
|
||||
0, 0,
|
||||
deviceA ,deviceB,WIDTH ,HEIGHT);
|
||||
|
||||
|
||||
HIP_ASSERT(hipMemcpy(hostA, deviceA, NUM*sizeof(T), hipMemcpyDeviceToHost));
|
||||
|
||||
bool ret = false;
|
||||
// verify the results
|
||||
errors = 0;
|
||||
for (i = 0; i < NUM; i++) {
|
||||
if (hostA[i].x != (hostB[i].x) && hostA[i].y != (hostB[i].y)) {
|
||||
errors++;
|
||||
}
|
||||
}
|
||||
if (errors!=0) {
|
||||
std::cout << "FAILED\n"<<std::endl;
|
||||
ret = false;
|
||||
} else {
|
||||
ret = true;
|
||||
}
|
||||
|
||||
HIP_ASSERT(hipFree(deviceA));
|
||||
HIP_ASSERT(hipFree(deviceB));
|
||||
|
||||
free(hostA);
|
||||
free(hostB);
|
||||
|
||||
return ret;
|
||||
|
||||
}
|
||||
|
||||
|
||||
template<typename T, typename U>
|
||||
bool dataTypesRun4(){
|
||||
T* hostA;
|
||||
T* hostB;
|
||||
|
||||
T* deviceA;
|
||||
T* deviceB;
|
||||
|
||||
int i;
|
||||
int errors;
|
||||
|
||||
hostA = (T*)malloc(NUM * sizeof(T));
|
||||
hostB = (T*)malloc(NUM * sizeof(T));
|
||||
|
||||
// initialize the input data
|
||||
for (i = 0; i < NUM; i++) {
|
||||
hostB[i] = make_vector4((U)i);
|
||||
}
|
||||
|
||||
HIP_ASSERT(hipMalloc((void**)&deviceA, NUM * sizeof(T)));
|
||||
HIP_ASSERT(hipMalloc((void**)&deviceB, NUM * sizeof(T)));
|
||||
|
||||
HIP_ASSERT(hipMemcpy(deviceB, hostB, NUM*sizeof(T), hipMemcpyHostToDevice));
|
||||
|
||||
|
||||
hipLaunchKernel(vectoradd_float,
|
||||
dim3(WIDTH/THREADS_PER_BLOCK_X, HEIGHT/THREADS_PER_BLOCK_Y),
|
||||
dim3(THREADS_PER_BLOCK_X, THREADS_PER_BLOCK_Y),
|
||||
0, 0,
|
||||
deviceA ,deviceB ,WIDTH ,HEIGHT);
|
||||
|
||||
|
||||
HIP_ASSERT(hipMemcpy(hostA, deviceA, NUM*sizeof(T), hipMemcpyDeviceToHost));
|
||||
|
||||
bool ret = false;
|
||||
// verify the results
|
||||
errors = 0;
|
||||
for (i = 0; i < NUM; i++) {
|
||||
if (hostA[i].x != (hostB[i].x ) && hostA[i].y != (hostB[i].y ) && hostA[i].z != (hostB[i].z ) && hostA[i].w != (hostB[i].w )) {
|
||||
errors++;
|
||||
}
|
||||
}
|
||||
if (errors!=0) {
|
||||
std::cout << "FAILED\n"<<std::endl;
|
||||
ret = false;
|
||||
} else {
|
||||
ret = true;
|
||||
}
|
||||
|
||||
HIP_ASSERT(hipFree(deviceA));
|
||||
HIP_ASSERT(hipFree(deviceB));
|
||||
|
||||
free(hostA);
|
||||
free(hostB);
|
||||
|
||||
return ret;
|
||||
|
||||
}
|
||||
|
||||
int main() {
|
||||
|
||||
hipDeviceProp_t devProp;
|
||||
hipGetDeviceProperties(&devProp, 0);
|
||||
cout << " System minor " << devProp.minor << endl;
|
||||
cout << " System major " << devProp.major << endl;
|
||||
cout << " agent prop name " << devProp.name << endl;
|
||||
|
||||
int errors;
|
||||
|
||||
errors = dataTypesRun<char,char>() &
|
||||
dataTypesRun<short, short>() &
|
||||
dataTypesRun<int,int>() &
|
||||
dataTypesRun<long, long>() &
|
||||
dataTypesRun<long long, long long>() &
|
||||
dataTypesRun<signed char,signed char>() &
|
||||
dataTypesRun<unsigned char, unsigned char>()&
|
||||
dataTypesRun<unsigned short, unsigned short>()&
|
||||
dataTypesRun<unsigned int, unsigned int>()&
|
||||
dataTypesRun<unsigned long, unsigned long>()&
|
||||
dataTypesRun<unsigned long long,unsigned long long>()&
|
||||
dataTypesRun<float, float>()&
|
||||
dataTypesRun<double, double>();
|
||||
|
||||
if(errors == 1){
|
||||
errors = 0;
|
||||
std::cout<<"ldg working for single element data types\n"<<std::endl;
|
||||
}else{
|
||||
std::cout<<"Failed single element data types"<<std::endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
#if 1
|
||||
errors = dataTypesRun2<int2,int>() &
|
||||
dataTypesRun2<short2,short>() &
|
||||
dataTypesRun2<ushort2,unsigned short>() &
|
||||
dataTypesRun2<char2,signed char>() &
|
||||
dataTypesRun2<uchar2,unsigned char>() &
|
||||
dataTypesRun2<uint2,unsigned int>() &
|
||||
dataTypesRun2<float2,float>() &
|
||||
dataTypesRun2<double2,double>();
|
||||
|
||||
if(errors == 1){
|
||||
errors = 0;
|
||||
std::cout<<"ldg working for two element data types\n"<<std::endl;
|
||||
}else{
|
||||
std::cout<<"Failed two element vector data types"<<std::endl;
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#if 1
|
||||
|
||||
errors = dataTypesRun4<int4,int>() &
|
||||
dataTypesRun4<char4,signed char>() &
|
||||
dataTypesRun4<uchar4,unsigned char>() &
|
||||
dataTypesRun4<short4, short>() &
|
||||
dataTypesRun4<uint4,unsigned int>() &
|
||||
dataTypesRun4<float4,float>() ;
|
||||
|
||||
if(errors == 1){
|
||||
errors = 0;
|
||||
std::cout<<"ldg working for four element data types\n"<<std::endl;
|
||||
}else{
|
||||
std::cout<<"Failed four element vector data types"<<std::endl;
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
|
||||
std::cout<<"ldg test PASSED \n"<<std::endl;
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,393 @@
|
||||
/*
|
||||
Copyright (c) 2015-2016 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.
|
||||
*/
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <algorithm>
|
||||
#include <stdlib.h>
|
||||
#include<iostream>
|
||||
#include "hip_runtime.h"
|
||||
#include "test_common.h"
|
||||
|
||||
#define HIP_ASSERT(x) (assert((x)==hipSuccess))
|
||||
|
||||
|
||||
#define WIDTH 8
|
||||
#define HEIGHT 8
|
||||
|
||||
#define NUM (WIDTH*HEIGHT)
|
||||
|
||||
#define THREADS_PER_BLOCK_X 8
|
||||
#define THREADS_PER_BLOCK_Y 8
|
||||
#define THREADS_PER_BLOCK_Z 1
|
||||
|
||||
|
||||
__global__ void
|
||||
vectoradd_char1(hipLaunchParm lp,
|
||||
char1* a, const char1* bm, const char1* cm, int width, int height)
|
||||
|
||||
{
|
||||
int x = hipBlockDim_x * hipBlockIdx_x + hipThreadIdx_x;
|
||||
int y = hipBlockDim_y * hipBlockIdx_y + hipThreadIdx_y;
|
||||
|
||||
int i = y * width + x;
|
||||
if ( i < (width * height)) {
|
||||
a[i] = make_char1(bm[i].x) + make_char1(cm[i].x);
|
||||
}
|
||||
}
|
||||
|
||||
__global__ void
|
||||
vectoradd_char2(hipLaunchParm lp,
|
||||
char2* a, const char2* bm, const char2* cm, int width, int height)
|
||||
|
||||
{
|
||||
int x = hipBlockDim_x * hipBlockIdx_x + hipThreadIdx_x;
|
||||
int y = hipBlockDim_y * hipBlockIdx_y + hipThreadIdx_y;
|
||||
|
||||
int i = y * width + x;
|
||||
if ( i < (width * height)) {
|
||||
a[i] = make_char2(bm[i].x, bm[i].y) + make_char2(cm[i].x, cm[i].y);
|
||||
}
|
||||
}
|
||||
|
||||
__global__ void
|
||||
vectoradd_char3(hipLaunchParm lp,
|
||||
char3* a, const char3* bm, const char3* cm, int width, int height)
|
||||
|
||||
{
|
||||
int x = hipBlockDim_x * hipBlockIdx_x + hipThreadIdx_x;
|
||||
int y = hipBlockDim_y * hipBlockIdx_y + hipThreadIdx_y;
|
||||
|
||||
int i = y * width + x;
|
||||
if ( i < (width * height)) {
|
||||
a[i] = make_char3(bm[i].x, bm[i].y, bm[i].z) + make_char3(cm[i].x, cm[i].y, cm[i].z);
|
||||
}
|
||||
}
|
||||
__global__ void
|
||||
vectoradd_char4(hipLaunchParm lp,
|
||||
char4* a, const char4* bm, const char4* cm, int width, int height)
|
||||
|
||||
{
|
||||
int x = hipBlockDim_x * hipBlockIdx_x + hipThreadIdx_x;
|
||||
int y = hipBlockDim_y * hipBlockIdx_y + hipThreadIdx_y;
|
||||
|
||||
int i = y * width + x;
|
||||
if ( i < (width * height)) {
|
||||
a[i] = make_char4(bm[i].x, bm[i].y, bm[i].z, bm[i].w) + make_char4(cm[i].x, cm[i].y, cm[i].z, cm[i].w);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#if 0
|
||||
__kernel__ void vectoradd_float(float* a, const float* b, const float* c, int width, int height) {
|
||||
|
||||
|
||||
int x = blockDimX * blockIdx.x + threadIdx.x;
|
||||
int y = blockDimY * blockIdy.y + threadIdx.y;
|
||||
|
||||
int i = y * width + x;
|
||||
if ( i < (width * height)) {
|
||||
a[i] = b[i] + c[i];
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
using namespace std;
|
||||
|
||||
template<typename T>
|
||||
bool dataTypesRun(){
|
||||
T* hostA;
|
||||
T* hostB;
|
||||
T* hostC;
|
||||
|
||||
T* deviceA;
|
||||
T* deviceB;
|
||||
T* deviceC;
|
||||
|
||||
int i;
|
||||
int errors;
|
||||
|
||||
hostA = (T*)malloc(NUM * sizeof(T));
|
||||
hostB = (T*)malloc(NUM * sizeof(T));
|
||||
hostC = (T*)malloc(NUM * sizeof(T));
|
||||
|
||||
// initialize the input data
|
||||
for (i = 0; i < NUM; i++) {
|
||||
hostB[i] = (T)i;
|
||||
hostC[i] = (T)i;
|
||||
}
|
||||
|
||||
HIP_ASSERT(hipMalloc((void**)&deviceA, NUM * sizeof(T)));
|
||||
HIP_ASSERT(hipMalloc((void**)&deviceB, NUM * sizeof(T)));
|
||||
HIP_ASSERT(hipMalloc((void**)&deviceC, NUM * sizeof(T)));
|
||||
|
||||
HIP_ASSERT(hipMemcpy(deviceB, hostB, NUM*sizeof(T), hipMemcpyHostToDevice));
|
||||
HIP_ASSERT(hipMemcpy(deviceC, hostC, NUM*sizeof(T), hipMemcpyHostToDevice));
|
||||
|
||||
hipLaunchKernel(HIP_KERNEL_NAME(vectoradd_char1),
|
||||
dim3(WIDTH/THREADS_PER_BLOCK_X, HEIGHT/THREADS_PER_BLOCK_Y),
|
||||
dim3(THREADS_PER_BLOCK_X, THREADS_PER_BLOCK_Y),
|
||||
0, 0,
|
||||
deviceA ,deviceB ,deviceC ,WIDTH ,HEIGHT);
|
||||
|
||||
HIP_ASSERT(hipMemcpy(hostA, deviceA, NUM*sizeof(T), hipMemcpyDeviceToHost));
|
||||
|
||||
bool ret = false;
|
||||
// verify the results
|
||||
errors = 0;
|
||||
for (i = 0; i < NUM; i++) {
|
||||
if (hostA[i] != (hostB[i] + hostC[i])) {
|
||||
errors++;
|
||||
}
|
||||
}
|
||||
if (errors!=0) {
|
||||
printf("FAILED: %d errors\n",errors);
|
||||
ret = false;
|
||||
} else {
|
||||
ret = true;
|
||||
}
|
||||
|
||||
HIP_ASSERT(hipFree(deviceA));
|
||||
HIP_ASSERT(hipFree(deviceB));
|
||||
HIP_ASSERT(hipFree(deviceC));
|
||||
|
||||
free(hostA);
|
||||
free(hostB);
|
||||
free(hostC);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
bool dataTypesRun(){
|
||||
T* hostA;
|
||||
T* hostB;
|
||||
T* hostC;
|
||||
|
||||
T* deviceA;
|
||||
T* deviceB;
|
||||
T* deviceC;
|
||||
|
||||
int i;
|
||||
int errors;
|
||||
|
||||
hostA = (T*)malloc(NUM * sizeof(T));
|
||||
hostB = (T*)malloc(NUM * sizeof(T));
|
||||
hostC = (T*)malloc(NUM * sizeof(T));
|
||||
|
||||
// initialize the input data
|
||||
for (i = 0; i < NUM; i++) {
|
||||
hostB[i] = (T)i;
|
||||
hostC[i] = (T)i;
|
||||
}
|
||||
|
||||
HIP_ASSERT(hipMalloc((void**)&deviceA, NUM * sizeof(T)));
|
||||
HIP_ASSERT(hipMalloc((void**)&deviceB, NUM * sizeof(T)));
|
||||
HIP_ASSERT(hipMalloc((void**)&deviceC, NUM * sizeof(T)));
|
||||
|
||||
HIP_ASSERT(hipMemcpy(deviceB, hostB, NUM*sizeof(T), hipMemcpyHostToDevice));
|
||||
HIP_ASSERT(hipMemcpy(deviceC, hostC, NUM*sizeof(T), hipMemcpyHostToDevice));
|
||||
|
||||
hipLaunchKernel(HIP_KERNEL_NAME(vectoradd_char1),
|
||||
dim3(WIDTH/THREADS_PER_BLOCK_X, HEIGHT/THREADS_PER_BLOCK_Y),
|
||||
dim3(THREADS_PER_BLOCK_X, THREADS_PER_BLOCK_Y),
|
||||
0, 0,
|
||||
deviceA ,deviceB ,deviceC ,WIDTH ,HEIGHT);
|
||||
|
||||
HIP_ASSERT(hipMemcpy(hostA, deviceA, NUM*sizeof(T), hipMemcpyDeviceToHost));
|
||||
|
||||
bool ret = false;
|
||||
// verify the results
|
||||
errors = 0;
|
||||
for (i = 0; i < NUM; i++) {
|
||||
if (hostA[i] != (hostB[i] + hostC[i])) {
|
||||
errors++;
|
||||
}
|
||||
}
|
||||
if (errors!=0) {
|
||||
printf("FAILED: %d errors\n",errors);
|
||||
ret = false;
|
||||
} else {
|
||||
ret = true;
|
||||
}
|
||||
|
||||
HIP_ASSERT(hipFree(deviceA));
|
||||
HIP_ASSERT(hipFree(deviceB));
|
||||
HIP_ASSERT(hipFree(deviceC));
|
||||
|
||||
free(hostA);
|
||||
free(hostB);
|
||||
free(hostC);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
bool dataTypesRun(){
|
||||
T* hostA;
|
||||
T* hostB;
|
||||
T* hostC;
|
||||
|
||||
T* deviceA;
|
||||
T* deviceB;
|
||||
T* deviceC;
|
||||
|
||||
int i;
|
||||
int errors;
|
||||
|
||||
hostA = (T*)malloc(NUM * sizeof(T));
|
||||
hostB = (T*)malloc(NUM * sizeof(T));
|
||||
hostC = (T*)malloc(NUM * sizeof(T));
|
||||
|
||||
// initialize the input data
|
||||
for (i = 0; i < NUM; i++) {
|
||||
hostB[i] = (T)i;
|
||||
hostC[i] = (T)i;
|
||||
}
|
||||
|
||||
HIP_ASSERT(hipMalloc((void**)&deviceA, NUM * sizeof(T)));
|
||||
HIP_ASSERT(hipMalloc((void**)&deviceB, NUM * sizeof(T)));
|
||||
HIP_ASSERT(hipMalloc((void**)&deviceC, NUM * sizeof(T)));
|
||||
|
||||
HIP_ASSERT(hipMemcpy(deviceB, hostB, NUM*sizeof(T), hipMemcpyHostToDevice));
|
||||
HIP_ASSERT(hipMemcpy(deviceC, hostC, NUM*sizeof(T), hipMemcpyHostToDevice));
|
||||
|
||||
hipLaunchKernel(HIP_KERNEL_NAME(vectoradd_char1),
|
||||
dim3(WIDTH/THREADS_PER_BLOCK_X, HEIGHT/THREADS_PER_BLOCK_Y),
|
||||
dim3(THREADS_PER_BLOCK_X, THREADS_PER_BLOCK_Y),
|
||||
0, 0,
|
||||
deviceA ,deviceB ,deviceC ,WIDTH ,HEIGHT);
|
||||
|
||||
HIP_ASSERT(hipMemcpy(hostA, deviceA, NUM*sizeof(T), hipMemcpyDeviceToHost));
|
||||
|
||||
bool ret = false;
|
||||
// verify the results
|
||||
errors = 0;
|
||||
for (i = 0; i < NUM; i++) {
|
||||
if (hostA[i] != (hostB[i] + hostC[i])) {
|
||||
errors++;
|
||||
}
|
||||
}
|
||||
if (errors!=0) {
|
||||
printf("FAILED: %d errors\n",errors);
|
||||
ret = false;
|
||||
} else {
|
||||
ret = true;
|
||||
}
|
||||
|
||||
HIP_ASSERT(hipFree(deviceA));
|
||||
HIP_ASSERT(hipFree(deviceB));
|
||||
HIP_ASSERT(hipFree(deviceC));
|
||||
|
||||
free(hostA);
|
||||
free(hostB);
|
||||
free(hostC);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool dataTypesRunChar4(){
|
||||
char4* hostA;
|
||||
char4* hostB;
|
||||
char4* hostC;
|
||||
|
||||
char4* deviceA;
|
||||
char4* deviceB;
|
||||
char4* deviceC;
|
||||
|
||||
int i;
|
||||
int errors;
|
||||
|
||||
hostA = (T*)malloc(NUM * sizeof(T));
|
||||
hostB = (T*)malloc(NUM * sizeof(T));
|
||||
hostC = (T*)malloc(NUM * sizeof(T));
|
||||
|
||||
// initialize the input data
|
||||
for (i = 0; i < NUM; i++) {
|
||||
hostB[i] = (T)i;
|
||||
hostC[i] = (T)i;
|
||||
}
|
||||
|
||||
HIP_ASSERT(hipMalloc((void**)&deviceA, NUM * sizeof(T)));
|
||||
HIP_ASSERT(hipMalloc((void**)&deviceB, NUM * sizeof(T)));
|
||||
HIP_ASSERT(hipMalloc((void**)&deviceC, NUM * sizeof(T)));
|
||||
|
||||
HIP_ASSERT(hipMemcpy(deviceB, hostB, NUM*sizeof(T), hipMemcpyHostToDevice));
|
||||
HIP_ASSERT(hipMemcpy(deviceC, hostC, NUM*sizeof(T), hipMemcpyHostToDevice));
|
||||
|
||||
hipLaunchKernel(HIP_KERNEL_NAME(vectoradd_char1),
|
||||
dim3(WIDTH/THREADS_PER_BLOCK_X, HEIGHT/THREADS_PER_BLOCK_Y),
|
||||
dim3(THREADS_PER_BLOCK_X, THREADS_PER_BLOCK_Y),
|
||||
0, 0,
|
||||
deviceA ,deviceB ,deviceC ,WIDTH ,HEIGHT);
|
||||
|
||||
HIP_ASSERT(hipMemcpy(hostA, deviceA, NUM*sizeof(T), hipMemcpyDeviceToHost));
|
||||
|
||||
bool ret = false;
|
||||
// verify the results
|
||||
errors = 0;
|
||||
for (i = 0; i < NUM; i++) {
|
||||
if (hostA[i] != (hostB[i] + hostC[i])) {
|
||||
errors++;
|
||||
}
|
||||
}
|
||||
if (errors!=0) {
|
||||
printf("FAILED: %d errors\n",errors);
|
||||
ret = false;
|
||||
} else {
|
||||
ret = true;
|
||||
}
|
||||
|
||||
HIP_ASSERT(hipFree(deviceA));
|
||||
HIP_ASSERT(hipFree(deviceB));
|
||||
HIP_ASSERT(hipFree(deviceC));
|
||||
|
||||
free(hostA);
|
||||
free(hostB);
|
||||
free(hostC);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int main() {
|
||||
|
||||
hipDeviceProp_t devProp;
|
||||
hipGetDeviceProperties(&devProp, 0);
|
||||
cout << " System minor " << devProp.minor << endl;
|
||||
cout << " System major " << devProp.major << endl;
|
||||
cout << " agent prop name " << devProp.name << endl;
|
||||
|
||||
int errors;
|
||||
|
||||
errors = dataTypesRun<char1>() &
|
||||
dataTypesRun<char2>() &
|
||||
dataTypesRun<char3>() &
|
||||
dataTypesRun<char4>();
|
||||
|
||||
|
||||
//hipResetDefaultAccelerator();
|
||||
if(errors == 1){
|
||||
passed();
|
||||
}else{
|
||||
std::cout<<"Failed Float"<<std::endl;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
مرجع در شماره جدید
Block a user