Initial commit for GPUOpen Launch

This commit is contained in:
Ben Sander
2016-01-26 20:14:33 -06:00
parent 9eca92261c
commit f38e63ff18
384 changed files with 38024 additions and 2 deletions
+33
View File
@@ -0,0 +1,33 @@
Tests uses CMAKE as teh build infrastructure.
Use :
> mkdir build
> cd build
> cmake ../src
> make test
#-----
# How to add a new test;
# edit src/CMakeFiles to add the test:
# add the executable and list of required CPP files, ie:
# make_test (EXE CPP_FILES)
> make_hip_executable (hipMemset hipMemset.cpp)
# Add to automated Test framework:
# make_test (TESTNAME ARGS)
> make_test(hipMemset " ")
# Running tests:
make test
# Run a specific test:
./hipMemset
View File
+135
View File
@@ -0,0 +1,135 @@
cmake_minimum_required (VERSION 2.6)
project (HIP_Unit_Tests)
include(CTest)
include_directories( ${PROJECT_SOURCE_DIR}/include )
# The version number.
set (HIP_Unit_Test_VERSION_MAJOR 1)
set (HIP_Unit_Test_VERSION_MINOR 0)
set (CUDA_PATH $ENV{CUDA_PATH})
if (NOT DEFINED CUDA_PATH)
set( CUDA_PATH /usr/local/cuda)
endif()
set (HIP_PATH $ENV{HIP_PATH})
if (NOT DEFINED HIP_PATH)
set (HIP_PATH ../..)
endif()
set (HIP_PLATFORM $ENV{HIP_PLATFORM})
if (NOT DEFINED HIP_PLATFORM)
if (EXISTS $CUDA_PATH)
set (HIP_PLATFORM nvcc)
else()
set (HIP_PLATFORM hcc)
endif()
endif()
if (${HIP_PLATFORM} STREQUAL "hcc")
MESSAGE ("HCC")
set (HC_PATH ${HIP_PATH}/hc)
set (HSA_PATH /opt/hsa)
#---
# Add HSA library:
add_library(hsa-runtime64 SHARED IMPORTED)
set_property(TARGET hsa-runtime64 PROPERTY IMPORTED_LOCATION "${HSA_PATH}/lib/libhsa-runtime64.so")
#These includes are used for all files.
#Include HIP and HC since the tests need both of these:
#Note below HSA path is surgically included only where necessary.
include_directories(${HIP_PATH}/include ${HC_PATH}/include)
# hip_hcc.o:
add_library(hip_hcc OBJECT ${HIP_PATH}/src/hip_hcc.cpp)
target_include_directories(hip_hcc PRIVATE ${HSA_PATH}/include)
elseif (${HIP_PLATFORM} STREQUAL "nvcc")
MESSAGE ("NVCC")
# NVCC does not not support -rdynamic option
set(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS )
set(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS )
else()
MESSAGE ("UNKNOWN HIP_PLATFORM=" ${HIP_PLATFORM})
endif()
set (HIPCC ${HIP_PATH}/bin/hipcc)
set (CMAKE_CXX_COMPILER ${HIPCC})
add_library(test_common OBJECT test_common.cpp )
# usage : make_hip_executable (exe_name CPP_FILES)
macro (make_hip_executable exe cpp)
if (${HIP_PLATFORM} STREQUAL "hcc")
add_executable (${exe} ${cpp} ${ARGN} $<TARGET_OBJECTS:test_common> $<TARGET_OBJECTS:hip_hcc> )
else()
add_executable (${exe} ${cpp} ${ARGN} $<TARGET_OBJECTS:test_common> )
endif()
endmacro()
macro (make_test exe )
string (REPLACE " " "" smush_args ${ARGN})
set (testname ${exe}${smush_args}.tst)
add_test (NAME ${testname}
COMMAND ${PROJECT_BINARY_DIR}/${exe} ${ARGN}
)
set_tests_properties (${testname}
PROPERTIES PASS_REGULAR_EXPRESSION "PASSED"
)
endmacro()
macro (make_test_matches exe match_string)
string (REPLACE " " "" smush_args ${ARGN})
set (testname ${exe}${smush_args}.tst)
add_test (NAME ${testname}
COMMAND ${PROJECT_BINARY_DIR}/${exe} ${ARGN}
)
set_tests_properties (${testname}
PROPERTIES PASS_REGULAR_EXPRESSION ${match_string}
)
endmacro()
#set(CMAKE_INSTALL_PREFIX "./install")
#install (TARGETS hipMemset DESTINATION bin)
#install (TARGETS hipEventRecord DESTINATION bin)
make_hip_executable (hip_anyall hip_anyall.cpp)
make_hip_executable (hip_popc hip_popc.cpp)
make_hip_executable (hip_clz hip_clz.cpp)
make_hip_executable (hip_brev hip_brev.cpp)
make_hip_executable (hip_ffs hip_ffs.cpp)
make_hip_executable (hipMemset hipMemset.cpp)
make_hip_executable (hipMemcpy hipMemcpy.cpp)
make_hip_executable (hipEventRecord hipEventRecord.cpp)
make_hip_executable (hipLanguageExtensions hipLanguageExtensions.cpp)
make_hip_executable (hipGridLaunch hipGridLaunch.cpp)
make_hip_executable (hipHcc hipHcc.cpp)
make_hip_executable (hipSimpleAtomicsTest hipSimpleAtomicsTest.cpp)
make_hip_executable (hipMathFunctions hipMathFunctions.cpp hipSinglePrecisionMathHost.cpp hipDoublePrecisionMathHost.cpp hipSinglePrecisionMathDevice.cpp hipDoublePrecisionMathDevice.cpp)
target_link_libraries(hipMathFunctions m)
make_test(hip_anyall " " )
make_test(hip_popc " " )
make_test(hip_brev " " )
make_test(hip_clz " " )
make_test(hip_ffs " " )
make_test(hipEventRecord --iterations 10)
make_test(hipMemset " " )
make_test(hipMemset --N 10 --memsetval 0x42 ) # small copy, just 10 bytes.
make_test(hipMemset --N 10013 --memsetval 0x5a ) # oddball size.
make_test(hipMemset --N 500M --memsetval 0xa6 ) # big copy
make_test(hipGridLaunch " " )
make_test(hipMemcpy " " )
make_test(hipHcc " " )
+21
View File
@@ -0,0 +1,21 @@
HIP_PATH=..
TARGET=hcc
include $(HIP_PATH)/examples/common/hip.prologue.make
SOURCES = hipMemset.cpp
OBJECTS=$(SOURCES:.cpp=.o)
EXECUTABLE=hipMemset
$(EXECUTABLE): $(HIP_DEPS) $(OBJECTS)
$(HCC) $(HLDFLAGS) $(OBJECTS) -o $@
.cpp.o:
$(HCC) $(HCFLAGS) -c $< -o $@
@$(CC) -MM -MT $@ $(CFLAGS) -c $< > $(@:.o=.d)
clean: hip_clean
rm -rf $(EXECUTABLE) $(OBJECTS)
include $(HIP_PATH)/examples/common/hip.epilogue.make
+3
View File
@@ -0,0 +1,3 @@
Unit tests for HIP API.
To add a new test:
@@ -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(4.0, 2.0);
__ddiv_rn(4.0, 2.0);
__ddiv_ru(4.0, 2.0);
__ddiv_rz(4.0, 2.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();
}
+125
View File
@@ -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();
}
+125
View File
@@ -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();
}
+99
View File
@@ -0,0 +1,99 @@
/*
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.
*/
// Test hipEventRecord serialization behavior.
// Through manual inspection of the reported timestamps, can determine if recording a NULL event forces synchronization :
// set
#include "hip_runtime.h"
#include "test_common.h"
int main(int argc, char *argv[])
{
HipTest::parseStandardArguments(argc, argv, true);
unsigned blocks = (N+threadsPerBlock-1)/threadsPerBlock;
if (blocks > 1024)
blocks = 1024;
if (blocks ==0 )
blocks = 1;
printf ("N=%zu (A+B+C= %6.1f MB total) blocks=%u threadsPerBlock=%u iterations=%d\n", N, ((double)3*N*sizeof(float))/1024/1024, blocks, threadsPerBlock, iterations);
printf ("iterations=%d\n", iterations);
size_t Nbytes = N*sizeof(float);
float * A_h, *B_h, *C_h;
float * A_d, *B_d, *C_d;
HipTest::initArrays (&A_d, &B_d, &C_d, &A_h, &B_h, &C_h, N);
hipEvent_t start, stop;
// NULL stream check:
HIPCHECK (hipEventCreate(&start));
HIPCHECK (hipEventCreate(&stop));
HIPCHECK ( hipMemcpy(A_d, A_h, Nbytes, hipMemcpyHostToDevice));
HIPCHECK ( hipMemcpy(B_d, B_h, Nbytes, hipMemcpyHostToDevice));
for (int i=0; i<iterations; i++) {
//--- START TIMED REGION
long long hostStart = HipTest::get_time();
// Record the start event
HIPCHECK (hipEventRecord(start, NULL));
hipLaunchKernel(HipTest::vectorADD, dim3(blocks), dim3(threadsPerBlock), 0, 0, A_d, B_d, C_d, N);
HIPCHECK (hipEventRecord(stop, NULL));
HIPCHECK (hipEventSynchronize(stop) );
long long hostStop = HipTest::get_time();
//--- STOP TIMED REGION
float eventMs = 1.0f;
HIPCHECK (hipEventElapsedTime(&eventMs, start, stop));
float hostMs = HipTest::elapsed_time(hostStart, hostStop);
printf ("host_time (gettimeofday) =%6.3fms\n", hostMs);
printf ("kernel_time (hipEventElapsedTime) =%6.3fms\n", eventMs);
printf ("\n");
// Make sure timer is timing something...
HIPASSERT(eventMs > 0.0f);
}
HIPCHECK (hipMemcpy(C_h, C_d, Nbytes, hipMemcpyDeviceToHost));
printf ("check:\n");
HipTest::checkVectorADD(A_h, B_h, C_h, N, true);
passed();
}
+94
View File
@@ -0,0 +1,94 @@
/*
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.
*/
// Test the Grid_Launch syntax.
#undef DISABLE_GRID_LAUNCH /* Tell hip_*.h to compile in GL mode */
#include "hip_runtime.h"
#include "test_common.h"
// __device__ maps to __attribute__((hc))
__device__ int foo(int i)
{
return i+1;
}
//---
//Syntax we would like to support with GRID_LAUNCH enabled:
template <typename T>
__global__ void
vectorADD2( grid_launch_parm lp,
T *A_d,
T *B_d,
T *C_d,
size_t N)
{
size_t offset = (hipBlockIdx_x * hipBlockDim_x + hipThreadIdx_x);
size_t stride = hipBlockDim_x * hipGridDim_x ;
for (size_t i=offset; i<N; i+=stride) {
C_d[i] = A_d[i] + B_d[i] ;
}
}
int test_gl2(size_t N) {
size_t Nbytes = N*sizeof(int);
int *A_d, *B_d, *C_d;
int *A_h, *B_h, *C_h;
HipTest::initArrays (&A_d, &B_d, &C_d, &A_h, &B_h, &C_h, N);
unsigned blocks = HipTest::setNumBlocks(blocksPerCU, threadsPerBlock, N);
// Full vadd in one large chunk, to get things started:
HIPCHECK ( hipMemcpy(A_d, A_h, Nbytes, hipMemcpyHostToDevice));
HIPCHECK ( hipMemcpy(B_d, B_h, Nbytes, hipMemcpyHostToDevice));
hipLaunchKernel(vectorADD2, dim3(blocks), dim3(threadsPerBlock), 0, 0, A_d, B_d, C_d, N);
HIPCHECK ( hipMemcpy(C_h, C_d, Nbytes, hipMemcpyDeviceToHost));
HIPCHECK (hipDeviceSynchronize());
HipTest::checkVectorADD(A_h, B_h, C_h, N);
return 0;
}
int main(int argc, char *argv[])
{
HipTest::parseStandardArguments(argc, argv, true);
test_gl2(N);
passed();
}
+58
View File
@@ -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.
*/
// Test the HCC-specific API extensions for HIP:
#include <stdio.h>
#include <iostream>
#include <hip_runtime.h>
#include "test_common.h"
#define CHECK(error) \
if (error != hipSuccess) { \
fprintf(stderr, "error: '%s'(%d) at %s:%d\n", hipGetErrorString(error), error,__FILE__, __LINE__); \
exit(EXIT_FAILURE);\
}
int main(int argc, char *argv[])
{
int deviceId;
CHECK (hipGetDevice(&deviceId));
hipDeviceProp_t props;
CHECK(hipDeviceGetProperties(&props, deviceId));
printf ("info: running on device #%d %s\n", deviceId, props.name);
#ifdef __HCC__
hc::accelerator acc;
CHECK(hipHccGetAccelerator(deviceId, &acc));
std::wcout << "device_path=" << acc.get_device_path() << "\n";
hc::accelerator_view *av;
CHECK(hipHccGetAcceleratorView(0/*nullStream*/, &av));
#endif
passed();
};
+56
View File
@@ -0,0 +1,56 @@
/*
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);
__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();
}
+128
View File
@@ -0,0 +1,128 @@
/*
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.
*/
// Collection of code to make sure that various features in the hip kernel language compile.
#include <hip_runtime.h>
#ifdef __HCC__
#include <amp.h>
#endif
// cudaA
// Simple tests for variable type qualifiers:
__device__ int deviceVar;
// TODO-HCC __constant__ not working yet.
__constant__ int constantVar1;
__constant__ __device__ int constantVar2;
// Test HOST space:
__host__ void foo() {
printf ("foo!\n");
}
__device__ __noinline__ int sum1_noinline(int a) { return a+1;};
__device__ __forceinline__ int sum1_forceinline(int a) { return a+1;};
__device__ __host__ float PlusOne(float x)
{
return x + 1.0;
}
__global__ void MyKernel (const hipLaunchParm lp, const float *a, const float *b, float *c, unsigned N)
{
KERNELBEGIN;
unsigned gid = hipThreadIdx_x;
if (gid < N) {
c[gid] = a[gid] + PlusOne(b[gid]);
}
KERNELEND;
}
void callMyKernel()
{
float *a, *b, *c;
unsigned N;
const unsigned blockSize = 256;
hipLaunchKernel(MyKernel, dim3(N/blockSize), dim3(blockSize), 0, 0, a,b,c,N);
}
template <typename T>
__global__ void
vectorADD(const hipLaunchParm lp,
T __restrict__ *A_d,
T *B_d,
T *C_d,
size_t N)
{
KERNELBEGIN;
int ws = warpSize;
int zuzu = deviceVar + 1;
int b = hipThreadIdx_x;
int c;
#ifdef NOT_YET
int a = __shfl_up(x, 1);
#endif
float x;
float z = sin(x);
#ifdef NOT_YET
float fastZ = __sin(x);
#endif
#ifdef __HCC__
// TODO - move to HIP atomics when ready.
concurrency :: atomic_fetch_add(&c, b);
//Concurrency::atomic_add_unsigned (&x, a);
//concurrency ::atomic_add_ (x, a);
#endif
__syncthreads();
size_t offset = (hipBlockIdx_x * hipBlockDim_x + hipThreadIdx_x);
size_t stride = hipBlockDim_x * hipGridDim_x ;
for (size_t i=offset; i<N; i+=stride) {
C_d[i] = A_d[i] + B_d[i];
}
KERNELEND;
}
int main() {
printf ("Hello world\n");
}
+30
View File
@@ -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();
}
+57
View File
@@ -0,0 +1,57 @@
/*
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);
size_t Nbytes = N*sizeof(int);
printf ("N=%zu \n", N);
int *A_d, *B_d, *C_d;
int *A_h, *B_h, *C_h;
HipTest::initArrays (&A_d, &B_d, &C_d, &A_h, &B_h, &C_h, N);
unsigned blocks = HipTest::setNumBlocks(blocksPerCU, threadsPerBlock, N);
HIPCHECK ( hipMemcpy(A_d, A_h, Nbytes, hipMemcpyHostToDevice));
HIPCHECK ( hipMemcpy(B_d, B_h, Nbytes, hipMemcpyHostToDevice));
hipLaunchKernel(HipTest::vectorADD, dim3(blocks), dim3(threadsPerBlock), 0, 0, A_d, B_d, C_d, N);
HIPCHECK ( hipMemcpy(C_h, C_d, Nbytes, hipMemcpyDeviceToHost));
HIPCHECK (hipDeviceSynchronize());
HipTest::checkVectorADD(A_h, B_h, C_h, N);
passed();
}
+57
View File
@@ -0,0 +1,57 @@
/*
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.
*/
// Simple test for memset.
// Also serves as a template for other tests.
#include "hip_runtime.h"
#include "test_common.h"
int main(int argc, char *argv[])
{
HipTest::parseStandardArguments(argc, argv, true);
size_t Nbytes = N*sizeof(char);
printf ("N=%zu memsetval=%2x\n", N, memsetval);
char *A_d;
char *A_h;
HIPCHECK ( hipMalloc(&A_d, Nbytes) );
A_h = (char*)malloc(Nbytes);
HIPCHECK ( hipMemset(A_d, memsetval, Nbytes) );
HIPCHECK ( hipMemcpy(A_h, A_d, Nbytes, hipMemcpyDeviceToHost));
for (int i=0; i<N; i++) {
if (A_h[i] != memsetval) {
failed("mismatch at index:%d computed:%02x, memsetval:%02x\n", i, (int)A_h[i], (int)memsetval);
}
}
passed();
}
+303
View File
@@ -0,0 +1,303 @@
// includes, system
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
// Includes HIP Runtime
#include <hip_runtime.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;
val = 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;
val = 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 HIP_FUNCTION(testKernel,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);
atomicInc((unsigned int *)&g_odata[5]);
// Atomic decrement
// atomicDec((unsigned int *)&g_odata[6], 137);
atomicDec((unsigned int *)&g_odata[6]);
// 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);
}
HIP_FUNCTION_END
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;
hipDeviceGetProperties(&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);
}
@@ -0,0 +1,78 @@
/*
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();
}
+126
View File
@@ -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();
}
+126
View File
@@ -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();
}
+79
View File
@@ -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 <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 tid = hipThreadIdx_x + hipBlockIdx_x * hipBlockDim_x;
device_any[hipThreadIdx_x>>6] = __any(tid >77);
device_all[hipThreadIdx_x>>6] = __all(tid >77);
}
int main(int argc, char *argv[])
{
int Num_Threads_per_Block = 1024;
int Num_Blocks_per_Grid = 1;
int Num_Warps_per_Block = Num_Threads_per_Block/64;
int Num_Warps_per_Grid = (Num_Threads_per_Block*Num_Blocks_per_Grid)/64;
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);
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]);
}
return EXIT_SUCCESS;
}
+203
View File
@@ -0,0 +1,203 @@
/*
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]);
}
}
#if 0
__kernel__ void HIP_kernel(unsigned int* a, unsigned int* b, unsigned long long int* c, unsigned long long int* d, 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] = __brev(b[i]);
c[i] = __brevll(d[i]);
}
}
#endif
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;
hipDeviceGetProperties(&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++) {
printf("gpu_brev =%d, cpu_brev =%d \n",hostA[i],bitreverse(hostB[i]));
if (hostA[i] != bitreverse(hostB[i])) {
errors++;
}
}
if (errors!=0) {
printf("FAILED: %d errors\n",errors);
} else {
printf ("__brev() PASSED!\n");
}
errors = 0;
for (i = 0; i < NUM; i++) {
printf("gpu_brevll =%llu, cpu_brevll =%llu \n",hostC[i],bitreverse(hostD[i]));
if (hostC[i] != bitreverse(hostD[i])) {
errors++;
}
}
if (errors!=0) {
printf("FAILED: %d errors\n",errors);
} else {
printf ("__brevll() PASSED!\n");
}
HIP_ASSERT(hipFree(deviceA));
HIP_ASSERT(hipFree(deviceB));
HIP_ASSERT(hipFree(deviceC));
HIP_ASSERT(hipFree(deviceD));
free(hostA);
free(hostB);
free(hostC);
free(hostD);
//hipResetDefaultAccelerator();
return errors;
}
+275
View File
@@ -0,0 +1,275 @@
/*
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]);
}
}
#if 0
__kernel__ void HIP_kernel(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 = blockDimX * blockIdx.x + threadIdx.x;
int y = blockDimY * blockIdy.y + threadIdx.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]);
}
}
#endif
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;
hipDeviceGetProperties(&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++) {
printf("gpu_clz_u =%d, cpu_clz_u =%d \n",hostA[i],firstbit_u32(hostB[i]));
if (hostA[i] != firstbit_u32(hostB[i])) {
errors++;
}
}
if (errors!=0) {
printf("FAILED: %d errors\n",errors);
} else {
printf ("__clz_u() for unsigned PASSED!\n");
}
errors = 0;
for (i = 0; i < NUM; i++) {
printf("gpu_clzll_u =%d, cpu_clzll_u =%d \n",hostC[i],firstbit_u64(hostD[i]));
if (hostC[i] != firstbit_u64(hostD[i])) {
errors++;
}
}
if (errors!=0) {
printf("FAILED: %d errors\n",errors);
} else {
printf ("__clzll_u() for unsigned PASSED!\n");
}
errors = 0;
for (i = 0; i < NUM; i++) {
printf("gpu_clz_s =%d, cpu_clz_s =%d \n",hostE[i],firstbit_s32(hostF[i]));
if (hostE[i] != firstbit_s32(hostF[i])) {
errors++;
}
}
if (errors!=0) {
printf("FAILED: %d errors\n",errors);
} else {
printf ("__clz_s() PASSED!\n");
}
errors = 0;
for (i = 0; i < NUM; i++) {
printf("gpu_clzll_s =%d, cpu_clzll_s =%d \n",hostG[i],firstbit_s64(hostH[i]));
if (hostG[i] != firstbit_s64(hostH[i])) {
errors++;
}
}
if (errors!=0) {
printf("FAILED: %d errors\n",errors);
} else {
printf ("__clzll_s() PASSED!\n");
}
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);
//hipResetDefaultAccelerator();
//return errors;
}
+201
View File
@@ -0,0 +1,201 @@
/*
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]);
}
}
#if 0
__kernel__ void HIP_kernel( unsigned int* a, unsigned int* b, unsigned int* c, unsigned long long int* d,
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] = __ffs(b[i]);
c[i] = __ffsll(d[i]);
}
}
#endif
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;
hipDeviceGetProperties(&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++) {
printf("gpu_ffs =%d, cpu_ffs =%d \n",hostA[i],lastbit(hostB[i]));
if (hostA[i] != lastbit(hostB[i])) {
errors++;
}
}
if (errors!=0) {
printf("FAILED: %d errors\n",errors);
} else {
printf ("__ffs() for unsigned PASSED!\n");
}
errors = 0;
for (i = 0; i < NUM; i++) {
printf("gpu_ffsll =%d, cpu_ffsll =%d \n",hostC[i],lastbit(hostD[i]));
if (hostC[i] != lastbit(hostD[i])) {
errors++;
}
}
if (errors!=0) {
printf("FAILED: %d errors\n",errors);
} else {
printf ("__ffsll() for unsigned PASSED!\n");
}
HIP_ASSERT(hipFree(deviceA));
HIP_ASSERT(hipFree(deviceB));
HIP_ASSERT(hipFree(deviceC));
HIP_ASSERT(hipFree(deviceD));
free(hostA);
free(hostB);
free(hostC);
free(hostD);
//hipResetDefaultAccelerator();
//return errors;
}
+195
View File
@@ -0,0 +1,195 @@
/*
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 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]);
}
}
#if 0
__kernel__ void HIP_kernel(unsigned int* a, unsigned int* b, unsigned int* c, unsigned long long int* d, 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] = __popc(b[i]);
c[i] = __popcll(d[i]);
}
}
#endif
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;
hipDeviceGetProperties(&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++) {
printf("gpu_popc =%d, cpu_popc =%d \n",hostA[i],popcountCPU(hostB[i]));
if (hostA[i] != popcountCPU(hostB[i])) {
errors++;
}
}
if (errors!=0) {
printf("FAILED: %d errors\n",errors);
} else {
printf ("__popc() PASSED!\n");
}
errors = 0;
for (i = 0; i < NUM; i++) {
printf("gpu_popcll =%d, cpu_popcll =%d \n",hostC[i],popcountCPU(hostD[i]));
if (hostC[i] != popcountCPU(hostD[i])) {
errors++;
}
}
if (errors!=0) {
printf("FAILED: %d errors\n",errors);
} else {
printf ("__popcll() PASSED!\n");
}
HIP_ASSERT(hipFree(deviceA));
HIP_ASSERT(hipFree(deviceB));
HIP_ASSERT(hipFree(deviceC));
HIP_ASSERT(hipFree(deviceD));
free(hostA);
free(hostB);
free(hostC);
free(hostD);
//hipResetDefaultAccelerator();
return errors;
}
+142
View File
@@ -0,0 +1,142 @@
/*
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"
// standard global variables that can be set on command line
size_t N = 4*1024*1024;
char memsetval=0x42;
int iterations = 1;
unsigned blocksPerCU = 6; // to hide latency
unsigned threadsPerBlock = 256;
namespace HipTest {
double elapsed_time(long long startTimeUs, long long stopTimeUs)
{
return ((double) (stopTimeUs - startTimeUs)) / ((double)(1000));
}
int parseSize(const char *str, size_t *output)
{
char *next;
*output = strtoull(str, &next, 0);
int l = strlen(str);
if (l) {
char c = str[l-1]; // last char.
if ((c == 'k') || (c == 'K')) {
*output *= 1024;
}
if ((c == 'm') || (c == 'M')) {
*output *= (1024*1024);
}
if ((c == 'g') || (c == 'G')) {
*output *= (1024*1024*1024);
}
}
return 1;
}
int parseUInt(const char *str, unsigned int *output)
{
char *next;
*output = strtoul(str, &next, 0);
return !strlen(next);
}
int parseInt(const char *str, int *output)
{
char *next;
*output = strtol(str, &next, 0);
return !strlen(next);
}
int parseStandardArguments(int argc, char *argv[], bool failOnUndefinedArg)
{
int extraArgs = 1;
for (int i = 1; i < argc; i++) {
const char *arg = argv[i];
if (!strcmp(arg, " ")) {
// skip NULL args.
} else if (!strcmp(arg, "--N")) {
if (++i >= argc || !HipTest::parseSize(argv[i], &N)) {
failed("Bad N size argument");
}
} else if (!strcmp(arg, "--threadsPerBlock")) {
if (++i >= argc || !HipTest::parseUInt(argv[i], &threadsPerBlock)) {
failed("Bad threadsPerBlock argument");
}
} else if (!strcmp(arg, "--blocksPerCU")) {
if (++i >= argc || !HipTest::parseUInt(argv[i], &blocksPerCU)) {
failed("Bad blocksPerCU argument");
}
} else if (!strcmp(arg, "--memsetval")) {
int ex;
if (++i >= argc || !HipTest::parseInt(argv[i], &ex)) {
failed("Bad memsetval argument");
}
memsetval = ex;
} else if (!strcmp(arg, "--iterations") || (!strcmp(arg, "-i"))) {
if (++i >= argc || !HipTest::parseInt(argv[i], &iterations)) {
failed("Bad itertions argument");
}
}
else {
if (failOnUndefinedArg) {
failed("Bad argument '%s'", arg);
} else {
argv[extraArgs++] = argv[i];
}
}
};
return extraArgs;
}
unsigned setNumBlocks(unsigned blocksPerCU, unsigned threadsPerBlock, size_t N)
{
int device;
HIPCHECK(hipGetDevice(&device));
hipDeviceProp_t props;
HIPCHECK(hipDeviceGetProperties(&props, device));
unsigned blocks = props.multiProcessorCount * blocksPerCU;
if (blocks * threadsPerBlock > N) {
blocks = (N+threadsPerBlock-1)/threadsPerBlock;
}
return blocks;
}
}// namespace HipTest
+163
View File
@@ -0,0 +1,163 @@
#include <iostream>
#include <sys/time.h>
#include <stddef.h>
#include "hip_runtime.h"
#define HC __attribute__((hc))
#define KNRM "\x1B[0m"
#define KRED "\x1B[31m"
#define KGRN "\x1B[32m"
#define KYEL "\x1B[33m"
#define KBLU "\x1B[34m"
#define KMAG "\x1B[35m"
#define KCYN "\x1B[36m"
#define KWHT "\x1B[37m"
#define passed() \
printf ("%sPASSED!%s\n",KGRN, KNRM);\
exit(0);
#define failed(...) \
printf ("%serror: ", KRED);\
printf (__VA_ARGS__);\
printf ("\n");\
printf ("error: TEST FAILED\n%s", KNRM );\
exit(EXIT_FAILURE);
#define HIPCHECK(error) \
if (error != hipSuccess) { \
printf("%serror: '%s'(%d) at %s:%d%s\n", \
KRED,hipGetErrorString(error), error,\
__FILE__, __LINE__,KNRM); \
failed("API returned error code.");\
}
#define HIPASSERT(condition) \
if (! (condition) ) { \
failed("%sassertion %s at %s:%d%s \n", \
KRED, #condition,\
__FILE__, __LINE__,KNRM); \
}
// standard command-line variables:
extern size_t N;
extern char memsetval;
extern int iterations;
extern unsigned blocksPerCU;
extern unsigned threadsPerBlock;
namespace HipTest {
// Returns the current system time in microseconds
inline long long get_time()
{
struct timeval tv;
gettimeofday(&tv, 0);
return (tv.tv_sec * 1000000) + tv.tv_usec;
}
double elapsed_time(long long startTimeUs, long long stopTimeUs);
int parseSize(const char *str, size_t *output);
int parseUInt(const char *str, unsigned int *output);
int parseInt(const char *str, int *output);
int parseStandardArguments(int argc, char *argv[], bool failOnUndefinedArg);
unsigned setNumBlocks(unsigned blocksPerCU, unsigned threadsPerBlock, size_t N);
template <typename T>
__global__ void
vectorADD(hipLaunchParm lp,
const T *A_d,
const T *B_d,
T *C_d,
size_t N)
{
size_t offset = (hipBlockIdx_x * hipBlockDim_x + hipThreadIdx_x);
size_t stride = hipBlockDim_x * hipGridDim_x ;
for (size_t i=offset; i<N; i+=stride) {
C_d[i] = A_d[i] + B_d[i];
}
}
template <typename T>
void initArrays(T **A_d, T **B_d, T **C_d,
T **A_h, T **B_h, T **C_h,
size_t N)
{
size_t Nbytes = N*sizeof(T);
if (A_d) {
HIPCHECK ( hipMalloc(A_d, Nbytes) );
}
if (B_d) {
HIPCHECK ( hipMalloc(B_d, Nbytes) );
}
if (C_d) {
HIPCHECK ( hipMalloc(C_d, Nbytes) );
}
if (A_h)
*A_h = (T*)malloc(Nbytes);
if (B_h)
*B_h = (T*)malloc(Nbytes);
if (C_h)
*C_h = (T*)malloc(Nbytes);
// Initialize the host data:
for (size_t i=0; i<N; i++) {
if (A_h)
(*A_h)[i] = 3.146f + i; // Pi
if (B_h)
(*B_h)[i] = 1.618f + i; // Phi
}
}
// Assumes C_h contains vector add of A_h + B_h
// Calls the test "failed" macro if a mismatch is detected.
template <typename T>
void checkVectorADD(T* A_h, T* B_h, T* result_H, size_t N, bool expectMatch=true)
{
size_t mismatchCount = 0;
size_t firstMismatch = 0;
size_t mismatchesToPrint = 10;
for (size_t i=0; i<N; i++) {
T expected = A_h[i] + B_h[i];
if (result_H[i] != expected) {
if (mismatchCount == 0) {
firstMismatch = i;
}
mismatchCount++;
if ((mismatchCount <= mismatchesToPrint) && expectMatch) {
std::cout << "At " << i << " Computed:" << result_H[i] << ", expected:" << expected << std::endl;
}
}
}
if (expectMatch) {
if (mismatchCount) {
failed("%zu mismatches ; first at index:%zu\n", mismatchCount, firstMismatch);
}
} else {
if (mismatchCount == 0) {
failed("expected mismatches but did not detect any!");
}
}
}
}; // namespace HipTest