Apply .clangformat to all repo source files

Change-Id: I7e79c6058f0303f9a98911e3b7dd2e8596079344
This commit is contained in:
Maneesh Gupta
2018-03-12 11:29:03 +05:30
parent 18e70b1e6b
commit 1ba06f63c4
293 changed files with 43980 additions and 45830 deletions
+8 -8
View File
@@ -24,22 +24,22 @@ THE SOFTWARE.
#include "hip/hcc_detail/hip_complex.h"
#define LEN 64
#define SIZE 64<<2
#define SIZE 64 << 2
__global__ void getSqAbs(hipLaunchParm lp, float *A, float *B, float *C){
__global__ void getSqAbs(hipLaunchParm lp, float* A, float* B, float* C) {
int tx = threadIdx.x + blockIdx.x * blockDim.x;
C[tx] = hipCsqabsf(make_hipFloatComplex(A[tx], B[tx]));
}
int main(){
int main() {
float *A, *Ad, *B, *Bd, *C, *Cd;
A = new float[LEN];
B = new float[LEN];
C = new float[LEN];
for(uint32_t i=0;i<LEN;i++){
A[i] = i*1.0f;
B[i] = i*1.0f;
C[i] = i*1.0f;
for (uint32_t i = 0; i < LEN; i++) {
A[i] = i * 1.0f;
B[i] = i * 1.0f;
C[i] = i * 1.0f;
}
hipMalloc((void**)&Ad, SIZE);
@@ -49,5 +49,5 @@ int main(){
hipMemcpy(Bd, B, SIZE, hipMemcpyHostToDevice);
hipLaunchKernel(getSqAbs, dim3(1), dim3(LEN), 0, 0, Ad, Bd, Cd);
hipMemcpy(C, Cd, SIZE, hipMemcpyDeviceToHost);
std::cout<<A[11]<<" "<<B[11]<<" "<<C[11]<<std::endl;
std::cout << A[11] << " " << B[11] << " " << C[11] << std::endl;
}
+9 -12
View File
@@ -14,27 +14,24 @@
*/
__global__ void cpy(hipLaunchParm lp, uint32_t *Out, uint32_t *In)
{
__global__ void cpy(hipLaunchParm lp, uint32_t* Out, uint32_t* In) {
int tx = threadIdx.x;
memcpy(Out + tx, In + tx, sizeof(uint32_t));
}
__global__ void set(hipLaunchParm lp, uint32_t *ptr, uint8_t val, size_t size)
{
__global__ void set(hipLaunchParm lp, uint32_t* ptr, uint8_t val, size_t size) {
int tx = threadIdx.x;
memset(ptr + tx, val, sizeof(uint32_t));
}
int main()
{
int main() {
uint32_t *A, *Ad, *B, *Bd;
uint32_t *Val;
uint32_t* Val;
A = new uint32_t[LEN];
B = new uint32_t[LEN];
Val = new uint32_t;
*Val = 0;
for(int i=0;i<LEN;i++){
for (int i = 0; i < LEN; i++) {
A[i] = i;
B[i] = 0;
}
@@ -45,16 +42,16 @@ int main()
hipLaunchKernel(cpy, dim3(1), dim3(LEN), 0, 0, Bd, Ad);
hipMemcpy(B, Bd, SIZE, hipMemcpyDeviceToHost);
for(int i=LEN-16;i<LEN;i++){
if(A[i]!=B[i]){
for (int i = LEN - 16; i < LEN; i++) {
if (A[i] != B[i]) {
return 0;
}
}
hipLaunchKernel(set, dim3(1), dim3(LEN), 0, 0, Bd, 0x1, LEN);
hipMemcpy(B, Bd, SIZE, hipMemcpyDeviceToHost);
for(int i=LEN-16;i<LEN;i++){
if(0x01010101!=B[i]){
for (int i = LEN - 16; i < LEN; i++) {
if (0x01010101 != B[i]) {
return 0;
}
}
@@ -33,8 +33,7 @@ THE SOFTWARE.
#pragma GCC diagnostic ignored "-Wall"
#pragma clang diagnostic ignored "-Wunused-variable"
__device__ void double_precision_intrinsics()
{
__device__ void double_precision_intrinsics() {
__dadd_rd(0.0, 1.0);
__dadd_rn(0.0, 1.0);
__dadd_ru(0.0, 1.0);
@@ -65,13 +64,11 @@ __device__ void double_precision_intrinsics()
__fma_rz(1.0, 2.0, 3.0);
}
__global__ void compileDoublePrecisionIntrinsics(hipLaunchParm lp, int ignored)
{
__global__ void compileDoublePrecisionIntrinsics(hipLaunchParm lp, int ignored) {
double_precision_intrinsics();
}
int main()
{
hipLaunchKernel(compileDoublePrecisionIntrinsics, dim3(1,1,1), dim3(1,1,1), 0, 0, 1);
passed();
int main() {
hipLaunchKernel(compileDoublePrecisionIntrinsics, dim3(1, 1, 1), dim3(1, 1, 1), 0, 0, 1);
passed();
}
@@ -33,8 +33,7 @@ THE SOFTWARE.
#pragma GCC diagnostic ignored "-Wall"
#pragma clang diagnostic ignored "-Wunused-variable"
__device__ void double_precision_math_functions()
{
__device__ void double_precision_math_functions() {
int iX;
double fX, fY;
@@ -51,8 +50,8 @@ __device__ void double_precision_math_functions()
cos(0.0);
cosh(0.0);
cospi(0.0);
// cyl_bessel_i0(0.0);
// cyl_bessel_i1(0.0);
// cyl_bessel_i0(0.0);
// cyl_bessel_i1(0.0);
erf(0.0);
erfc(0.0);
erfcinv(2.0);
@@ -79,7 +78,7 @@ __device__ void double_precision_math_functions()
j1(0.0);
jn(-1.0, 1.0);
ldexp(0.0, 0);
// lgamma(1.0);
// lgamma(1.0);
llrint(0.0);
llround(0.0);
log(1.0);
@@ -89,28 +88,30 @@ __device__ void double_precision_math_functions()
logb(1.0);
lrint(0.0);
lround(0.0);
// modf(0.0, &fX);
// modf(0.0, &fX);
nan("1");
nearbyint(0.0);
nextafter(0.0, 0.0);
fX = 1.0; norm(1, &fX);
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);
// rcbrt(1.0);
remainder(2.0, 1.0);
// remquo(1.0, 2.0, &iX);
// remquo(1.0, 2.0, &iX);
rhypot(0.0, 1.0);
rint(1.0);
fX = 1.0; rnorm(1, &fX);
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);
// scalbln(0.0, 1);
// scalbn(0.0, 1);
signbit(1.0);
sin(0.0);
sincos(0.0, &fX, &fY);
@@ -127,13 +128,11 @@ __device__ void double_precision_math_functions()
yn(1, 1.0);
}
__global__ void compileDoublePrecisionMathOnDevice(hipLaunchParm lp, int ignored)
{
__global__ void compileDoublePrecisionMathOnDevice(hipLaunchParm lp, int ignored) {
double_precision_math_functions();
}
int main()
{
hipLaunchKernel(compileDoublePrecisionMathOnDevice, dim3(1,1,1), dim3(1,1,1), 0, 0, 1);
passed();
int main() {
hipLaunchKernel(compileDoublePrecisionMathOnDevice, dim3(1, 1, 1), dim3(1, 1, 1), 0, 0, 1);
passed();
}
@@ -29,13 +29,12 @@ THE SOFTWARE.
#include <hip/hip_runtime.h>
//#include <hip/math_functions.h>
#include "test_common.h"
#include<cmath>
#include <cmath>
#pragma GCC diagnostic ignored "-Wall"
#pragma clang diagnostic ignored "-Wunused-variable"
__host__ void double_precision_math_functions()
{
__host__ void double_precision_math_functions() {
int iX;
double fX, fY;
@@ -51,14 +50,14 @@ __host__ void double_precision_math_functions()
copysign(1.0, -2.0);
cos(0.0);
cosh(0.0);
//cospi(0.0);
//cyl_bessel_i0(0.0);
//cyl_bessel_i1(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);
// erfcinv(2.0);
// erfcx(0.0);
// erfinv(1.0);
exp(0.0);
exp10(0.0);
exp2(0.0);
@@ -80,7 +79,7 @@ __host__ void double_precision_math_functions()
j1(0.0);
jn(-1.0, 1.0);
ldexp(0.0, 0);
// lgamma(1.0);
// lgamma(1.0);
llrint(0.0);
llround(0.0);
log(1.0);
@@ -93,38 +92,38 @@ __host__ void double_precision_math_functions()
modf(0.0, &fX);
nan("1");
nearbyint(0.0);
//nextafter(0.0);
fX = 1.0; //norm(1, &fX);
// nextafter(0.0);
fX = 1.0; // norm(1, &fX);
#if defined(__HIP_PLATFORM_HCC__)
//norm3d(1.0, 0.0, 0.0);
//norm4d(1.0, 0.0, 0.0, 0.0);
// norm3d(1.0, 0.0, 0.0);
// norm4d(1.0, 0.0, 0.0, 0.0);
#endif
// normcdf(0.0);
// normcdfinv(1.0);
// normcdf(0.0);
// normcdfinv(1.0);
pow(1.0, 0.0);
//rcbrt(1.0);
// rcbrt(1.0);
remainder(2.0, 1.0);
remquo(1.0, 2.0, &iX);
#if defined(__HIP_PLATFORM_HCC__)
//rhypot(0.0, 1.0);
// rhypot(0.0, 1.0);
#endif
rint(1.0);
#if defined(__HIP_PLATFORM_HCC__)
fX = 1.0; //rnorm(1, &fX);
//rnorm3d(0.0, 0.0, 1.0);
//rnorm4d(0.0, 0.0, 0.0, 1.0);
fX = 1.0; // rnorm(1, &fX);
// rnorm3d(0.0, 0.0, 1.0);
// rnorm4d(0.0, 0.0, 0.0, 1.0);
#endif
round(0.0);
//rsqrt(1.0);
// rsqrt(1.0);
scalbln(0.0, 1);
scalbn(0.0, 1);
std::signbit(1.0);
sin(0.0);
sincos(0.0, &fX, &fY);
//sincospi(0.0, &fX, &fY);
// sincospi(0.0, &fX, &fY);
sinh(0.0);
//sinpi(0.0);
// sinpi(0.0);
sqrt(0.0);
tan(0.0);
tanh(0.0);
@@ -135,13 +134,9 @@ __host__ void double_precision_math_functions()
yn(1, 1.0);
}
static void compileOnHost()
{
double_precision_math_functions();
}
static void compileOnHost() { double_precision_math_functions(); }
int main()
{
compileOnHost();
passed();
int main() {
compileOnHost();
passed();
}
+25 -26
View File
@@ -30,34 +30,33 @@ THE SOFTWARE.
#include <hip/device_functions.h>
#define LEN 512
#define SIZE LEN<<2
#define SIZE LEN << 2
__global__ void floatMath(hipLaunchParm lp, float *In, float *Out) {
int tid = threadIdx.x + blockIdx.x * blockDim.x;
Out[tid] = __cosf(In[tid]);
Out[tid] = __exp10f(Out[tid]);
Out[tid] = __expf(Out[tid]);
Out[tid] = __frsqrt_rn(Out[tid]);
Out[tid] = __fsqrt_rd(Out[tid]);
Out[tid] = __fsqrt_rn(Out[tid]);
Out[tid] = __fsqrt_ru(Out[tid]);
Out[tid] = __fsqrt_rz(Out[tid]);
Out[tid] = __log10f(Out[tid]);
Out[tid] = __log2f(Out[tid]);
Out[tid] = __logf(Out[tid]);
Out[tid] = __powf(2.0f, Out[tid]);
__sincosf(Out[tid], &In[tid], &Out[tid]);
Out[tid] = __sinf(Out[tid]);
Out[tid] = __cosf(Out[tid]);
Out[tid] = __tanf(Out[tid]);
__global__ void floatMath(hipLaunchParm lp, float* In, float* Out) {
int tid = threadIdx.x + blockIdx.x * blockDim.x;
Out[tid] = __cosf(In[tid]);
Out[tid] = __exp10f(Out[tid]);
Out[tid] = __expf(Out[tid]);
Out[tid] = __frsqrt_rn(Out[tid]);
Out[tid] = __fsqrt_rd(Out[tid]);
Out[tid] = __fsqrt_rn(Out[tid]);
Out[tid] = __fsqrt_ru(Out[tid]);
Out[tid] = __fsqrt_rz(Out[tid]);
Out[tid] = __log10f(Out[tid]);
Out[tid] = __log2f(Out[tid]);
Out[tid] = __logf(Out[tid]);
Out[tid] = __powf(2.0f, Out[tid]);
__sincosf(Out[tid], &In[tid], &Out[tid]);
Out[tid] = __sinf(Out[tid]);
Out[tid] = __cosf(Out[tid]);
Out[tid] = __tanf(Out[tid]);
}
int main(){
float *Ind, *Outd;
hipMalloc((void**)&Ind, SIZE);
hipMalloc((void**)&Outd, SIZE);
hipLaunchKernel(floatMath, dim3(LEN,1,1), dim3(1,1,1), 0, 0, Ind, Outd);
passed();
int main() {
float *Ind, *Outd;
hipMalloc((void**)&Ind, SIZE);
hipMalloc((void**)&Outd, SIZE);
hipLaunchKernel(floatMath, dim3(LEN, 1, 1), dim3(1, 1, 1), 0, 0, Ind, Outd);
passed();
}
+14 -13
View File
@@ -30,9 +30,8 @@ THE SOFTWARE.
#include <hip/math_functions.h>
#include "test_common.h"
__global__ void FloatMathPrecise(hipLaunchParm lp)
{
//int iX; //uncomment this when remqouf() is enabled again
__global__ void FloatMathPrecise(hipLaunchParm lp) {
// int iX; //uncomment this when remqouf() is enabled again
float fX, fY;
acosf(1.0f);
@@ -48,8 +47,8 @@ __global__ void FloatMathPrecise(hipLaunchParm lp)
cosf(0.0f);
coshf(0.0f);
cospif(0.0f);
//cyl_bessel_i0f(0.0f);
//cyl_bessel_i1f(0.0f);
// cyl_bessel_i0f(0.0f);
// cyl_bessel_i1f(0.0f);
erfcf(0.0f);
erfcinvf(2.0f);
erfcxf(0.0f);
@@ -67,7 +66,7 @@ __global__ void FloatMathPrecise(hipLaunchParm lp)
fX = fmaxf(0.0f, 0.0f);
fX = fminf(0.0f, 0.0f);
fmodf(0.0f, 1.0f);
//frexpf(0.0f, &iX);
// frexpf(0.0f, &iX);
hypotf(1.0f, 0.0f);
ilogbf(1.0f);
isfinite(0.0f);
@@ -77,7 +76,7 @@ __global__ void FloatMathPrecise(hipLaunchParm lp)
j1f(0.0f);
jnf(-1.0f, 1.0f);
ldexpf(0.0f, 0);
//lgammaf(1.0f);
// lgammaf(1.0f);
llrintf(0.0f);
llroundf(0.0f);
log10f(1.0f);
@@ -87,24 +86,26 @@ __global__ void FloatMathPrecise(hipLaunchParm lp)
logf(1.0f);
lrintf(0.0f);
lroundf(0.0f);
//modff(0.0f, &fX);
// modff(0.0f, &fX);
fX = nanf("1");
fX = nearbyintf(0.0f);
//nextafterf(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);
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);
// remquof(1.0f, 2.0f, &iX);
rhypotf(0.0f, 1.0f);
fY = 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);
fX = 1.0f;
rnormf(1, &fX);
fY = roundf(0.0f);
rsqrtf(1.0f);
scalblnf(0.0f, 1);
@@ -126,6 +127,6 @@ __global__ void FloatMathPrecise(hipLaunchParm lp)
}
int main() {
hipLaunchKernel(FloatMathPrecise, dim3(1,1,1), dim3(1,1,1), 0, 0);
hipLaunchKernel(FloatMathPrecise, dim3(1, 1, 1), dim3(1, 1, 1), 0, 0);
passed();
}
+5 -10
View File
@@ -34,8 +34,7 @@ THE SOFTWARE.
#pragma GCC diagnostic ignored "-Wall"
#pragma clang diagnostic ignored "-Wunused-variable"
__device__ void integer_intrinsics()
{
__device__ void integer_intrinsics() {
__brev((unsigned int)10);
__brevll((unsigned long long)10);
__byte_perm((unsigned int)0, (unsigned int)0, 0);
@@ -63,13 +62,9 @@ __device__ void integer_intrinsics()
assert(1);
}
__global__ void compileIntegerIntrinsics(hipLaunchParm lp, int ignored)
{
integer_intrinsics();
}
__global__ void compileIntegerIntrinsics(hipLaunchParm lp, int ignored) { integer_intrinsics(); }
int main()
{
hipLaunchKernel(compileIntegerIntrinsics, dim3(1,1,1), dim3(1,1,1), 0, 0, 1);
passed();
int main() {
hipLaunchKernel(compileIntegerIntrinsics, dim3(1, 1, 1), dim3(1, 1, 1), 0, 0, 1);
passed();
}
+1 -2
View File
@@ -24,8 +24,7 @@ THE SOFTWARE.
#include "hip/hip_runtime.h"
#include "test_common.h"
int main(int argc, char *argv[])
{
int main(int argc, char* argv[]) {
HipTest::parseStandardArguments(argc, argv, true);
passed();
+54 -85
View File
@@ -34,9 +34,9 @@ THE SOFTWARE.
#include "hip/hip_runtime.h"
#include <test_common.h>
#define EXIT_WAIVED 2
#define EXIT_WAIVED 2
const char *sampleName = "hipSimpleAtomicsTest";
const char* sampleName = "hipSimpleAtomicsTest";
////////////////////////////////////////////////////////////////////////////////
// Auto-Verification Code
@@ -44,81 +44,69 @@ bool testResult = true;
////////////////////////////////////////////////////////////////////////////////
// Declaration, forward
void runTest(int argc, char **argv);
void runTest(int argc, char** argv);
#define min(a,b) (a) < (b) ? (a) : (b)
#define max(a,b) (a) > (b) ? (a) : (b)
#define min(a, b) (a) < (b) ? (a) : (b)
#define max(a, b) (a) > (b) ? (a) : (b)
int computeGold(int *gpuData, const int len)
{
int computeGold(int* gpuData, const int len) {
int val = 0;
for (int i = 0; i < len; ++i)
{
for (int i = 0; i < len; ++i) {
val += 10;
}
if (val != gpuData[0])
{
if (val != gpuData[0]) {
printf("atomicAdd failed\n");
return false;
}
val = 0;
for (int i = 0; i < len; ++i)
{
for (int i = 0; i < len; ++i) {
val -= 10;
}
if (val != gpuData[1])
{
if (val != gpuData[1]) {
printf("atomicSub failed\n");
return false;
}
bool found = false;
for (int i = 0; i < len; ++i)
{
for (int i = 0; i < len; ++i) {
// third element should be a member of [0, len)
if (i == gpuData[2])
{
if (i == gpuData[2]) {
found = true;
break;
}
}
if (!found)
{
if (!found) {
printf("atomicExch failed\n");
return false;
}
val = -(1 << 8);
for (int i = 0; i < len; ++i)
{
for (int i = 0; i < len; ++i) {
// fourth element should be len-1
val = max(val, i);
}
if (val != gpuData[3])
{
if (val != gpuData[3]) {
printf("atomicMax failed\n");
return false;
}
val = 1 << 8;
for (int i = 0; i < len; ++i)
{
for (int i = 0; i < len; ++i) {
val = min(val, i);
}
if (val != gpuData[4])
{
if (val != gpuData[4]) {
printf("atomicMin failed\n");
return false;
}
@@ -126,13 +114,11 @@ int computeGold(int *gpuData, const int len)
int limit = 17;
val = 0;
for (int i = 0; i < len; ++i)
{
val = (val >= limit) ? 0 : val+1;
for (int i = 0; i < len; ++i) {
val = (val >= limit) ? 0 : val + 1;
}
if (val != gpuData[5])
{
if (val != gpuData[5]) {
printf("atomicInc failed\n");
return false;
}
@@ -140,73 +126,62 @@ int computeGold(int *gpuData, const int len)
limit = 137;
val = 0;
for (int i = 0; i < len; ++i)
{
val = ((val == 0) || (val > limit)) ? limit : val-1;
for (int i = 0; i < len; ++i) {
val = ((val == 0) || (val > limit)) ? limit : val - 1;
}
if (val != gpuData[6])
{
if (val != gpuData[6]) {
printf("atomicDec failed\n");
return false;
}
found = false;
for (int i = 0; i < len; ++i)
{
for (int i = 0; i < len; ++i) {
// eighth element should be a member of [0, len)
if (i == gpuData[7])
{
if (i == gpuData[7]) {
found = true;
break;
}
}
if (!found)
{
if (!found) {
printf("atomicCAS failed\n");
return false;
}
val = 0xff;
for (int i = 0; i < len; ++i)
{
for (int i = 0; i < len; ++i) {
// 9th element should be 1
val &= (2 * i + 7);
}
if (val != gpuData[8])
{
if (val != gpuData[8]) {
printf("atomicAnd failed\n");
return false;
}
val = 0;
for (int i = 0; i < len; ++i)
{
for (int i = 0; i < len; ++i) {
// 10th element should be 0xff
val |= (1 << i);
}
if (val != gpuData[9])
{
if (val != gpuData[9]) {
printf("atomicOr failed\n");
return false;
}
val = 0xff;
for (int i = 0; i < len; ++i)
{
for (int i = 0; i < len; ++i) {
// 11th element should be 0xff
val ^= i;
}
if (val != gpuData[10])
{
if (val != gpuData[10]) {
printf("atomicXor failed\n");
return false;
}
@@ -214,8 +189,7 @@ int computeGold(int *gpuData, const int len)
return true;
}
__global__ void testKernel(hipLaunchParm lp,int *g_odata)
{
__global__ void testKernel(hipLaunchParm lp, int* g_odata) {
// access thread id
const unsigned int tid = blockDim.x * blockIdx.x + threadIdx.x;
@@ -239,18 +213,18 @@ __global__ void testKernel(hipLaunchParm lp,int *g_odata)
atomicMin(&g_odata[4], tid);
// Atomic increment (modulo 17+1)
atomicInc((unsigned int *)&g_odata[5], 17);
atomicInc((unsigned int*)&g_odata[5], 17);
// Atomic decrement
atomicDec((unsigned int *)&g_odata[6], 137);
atomicDec((unsigned int*)&g_odata[6], 137);
// Atomic compare-and-swap
atomicCAS(&g_odata[7], tid-1, tid);
atomicCAS(&g_odata[7], tid - 1, tid);
// Bitwise atomic instructions
// Atomic AND
atomicAnd(&g_odata[8], 2*tid+7);
atomicAnd(&g_odata[8], 2 * tid + 7);
// Atomic OR
atomicOr(&g_odata[9], 1 << tid);
@@ -260,21 +234,17 @@ __global__ void testKernel(hipLaunchParm lp,int *g_odata)
}
int main(int argc, char **argv)
{
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!");
printf("%s completed, returned %s\n", sampleName, testResult ? "OK" : "ERROR!");
exit(testResult ? EXIT_SUCCESS : EXIT_FAILURE);
}
void runTest(int argc, char **argv)
{
void runTest(int argc, char** argv) {
hipDeviceProp_t deviceProp;
deviceProp.major = 0;
deviceProp.minor = 0;
@@ -283,10 +253,10 @@ void runTest(int argc, char **argv)
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);
printf(
"> GPU device has %d Multi-Processors, "
"SM %d.%d compute capabilities\n\n",
deviceProp.multiProcessorCount, deviceProp.major, deviceProp.minor);
unsigned int numThreads = 256;
@@ -294,27 +264,26 @@ void runTest(int argc, char **argv)
unsigned int numData = 11;
unsigned int memSize = sizeof(int) * numData;
//allocate mem for the result on host side
int *hOData = (int *) malloc(memSize);
// 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;
// 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...
// 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);
int* dOData;
hipMalloc((void**)&dOData, memSize);
// copy host memory to device to initialize to zero
hipMemcpy(dOData, hOData, memSize,hipMemcpyHostToDevice);
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);
// Copy result from device to host
hipMemcpy(hOData, dOData, memSize, hipMemcpyDeviceToHost);
// Compute reference solution
testResult = computeGold(hOData, numThreads * numBlocks);
@@ -32,8 +32,7 @@ THE SOFTWARE.
#pragma GCC diagnostic ignored "-Wall"
#pragma clang diagnostic ignored "-Wunused-variable"
__device__ void single_precision_intrinsics()
{
__device__ void single_precision_intrinsics() {
float fX, fY;
__cosf(0.0f);
@@ -80,14 +79,12 @@ __device__ void single_precision_intrinsics()
}
__global__ void compileSinglePrecisionIntrinsics(hipLaunchParm lp, int ignored)
{
__global__ void compileSinglePrecisionIntrinsics(hipLaunchParm lp, int ignored) {
single_precision_intrinsics();
}
int main()
{
hipLaunchKernel(compileSinglePrecisionIntrinsics, dim3(1,1,1), dim3(1,1,1), 0, 0, 1);
passed();
int main() {
hipLaunchKernel(compileSinglePrecisionIntrinsics, dim3(1, 1, 1), dim3(1, 1, 1), 0, 0, 1);
passed();
}
@@ -33,8 +33,7 @@ THE SOFTWARE.
#pragma GCC diagnostic ignored "-Wall"
#pragma clang diagnostic ignored "-Wunused-variable"
__device__ void single_precision_math_functions()
{
__device__ void single_precision_math_functions() {
int iX;
float fX, fY;
@@ -51,8 +50,8 @@ __device__ void single_precision_math_functions()
cosf(0.0f);
coshf(0.0f);
cospif(0.0f);
//cyl_bessel_i0f(0.0f);
//cyl_bessel_i1f(0.0f);
// cyl_bessel_i0f(0.0f);
// cyl_bessel_i1f(0.0f);
erfcf(0.0f);
erfcinvf(2.0f);
erfcxf(0.0f);
@@ -80,7 +79,7 @@ __device__ void single_precision_math_functions()
j1f(0.0f);
jnf(-1.0f, 1.0f);
ldexpf(0.0f, 0);
//lgammaf(1.0f);
// lgammaf(1.0f);
llrintf(0.0f);
llroundf(0.0f);
log10f(1.0f);
@@ -90,28 +89,30 @@ __device__ void single_precision_math_functions()
logf(1.0f);
lrintf(0.0f);
lroundf(0.0f);
//modff(0.0f, &fX);
// modff(0.0f, &fX);
nanf("1");
nearbyintf(0.0f);
//nextafterf(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);
fX = 1.0f;
normf(1, &fX);
powf(1.0f, 0.0f);
//rcbrtf(1.0f);
// rcbrtf(1.0f);
remainderf(2.0f, 1.0f);
//remquof(1.0f, 2.0f, &iX);
// 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);
fX = 1.0f;
rnormf(1, &fX);
roundf(0.0f);
rsqrtf(1.0f);
//scalblnf(0.0f, 1);
//scalbnf(0.0f, 1);
// scalblnf(0.0f, 1);
// scalbnf(0.0f, 1);
signbit(1.0f);
sincosf(0.0f, &fX, &fY);
sincospif(0.0f, &fX, &fY);
@@ -128,13 +129,11 @@ __device__ void single_precision_math_functions()
ynf(1, 1.0f);
}
__global__ void compileSinglePrecisionMathOnDevice(hipLaunchParm lp, int ignored)
{
__global__ void compileSinglePrecisionMathOnDevice(hipLaunchParm lp, int ignored) {
single_precision_math_functions();
}
int main()
{
hipLaunchKernel(compileSinglePrecisionMathOnDevice, dim3(1,1,1), dim3(1,1,1), 0, 0, 1);
passed();
int main() {
hipLaunchKernel(compileSinglePrecisionMathOnDevice, dim3(1, 1, 1), dim3(1, 1, 1), 0, 0, 1);
passed();
}
@@ -29,13 +29,12 @@ THE SOFTWARE.
#include <hip/hip_runtime.h>
//#include <hip/math_functions.h>
#include "test_common.h"
#include<cmath>
#include <cmath>
#pragma GCC diagnostic ignored "-Wall"
#pragma clang diagnostic ignored "-Wunused-variable"
__host__ void single_precision_math_functions()
{
__host__ void single_precision_math_functions() {
int iX;
float fX, fY;
@@ -51,14 +50,14 @@ __host__ void single_precision_math_functions()
copysignf(1.0f, -2.0f);
cosf(0.0f);
coshf(0.0f);
//cospif(0.0f);
//cyl_bessel_i0f(0.0f);
//cyl_bessel_i1f(0.0f);
// cospif(0.0f);
// cyl_bessel_i0f(0.0f);
// cyl_bessel_i1f(0.0f);
erfcf(0.0f);
//erfcinvf(2.0f);
//erfcxf(0.0f);
// erfcinvf(2.0f);
// erfcxf(0.0f);
erff(0.0f);
//erfinvf(1.0f);
// erfinvf(1.0f);
exp10f(0.0f);
exp2f(0.0f);
expf(0.0f);
@@ -66,7 +65,7 @@ __host__ void single_precision_math_functions()
fabsf(1.0f);
fdimf(1.0f, 0.0f);
#if defined(__HIP_PLATFORM_HCC__)
//fdividef(0.0f, 1.0f);
// fdividef(0.0f, 1.0f);
#endif
floorf(0.0f);
fmaf(1.0f, 2.0f, 3.0f);
@@ -96,37 +95,37 @@ __host__ void single_precision_math_functions()
modff(0.0f, &fX);
nanf("1");
nearbyintf(0.0f);
//nextafterf(0.0f);
// nextafterf(0.0f);
#if defined(__HIP_PLATFORM_HCC__)
//norm3df(1.0f, 0.0f, 0.0f);
//norm4df(1.0f, 0.0f, 0.0f, 0.0f);
// norm3df(1.0f, 0.0f, 0.0f);
// norm4df(1.0f, 0.0f, 0.0f, 0.0f);
#endif
//normcdff(0.0f);
//normcdfinvf(1.0f);
//fX = 1.0f; normf(1, &fX);
// normcdff(0.0f);
// normcdfinvf(1.0f);
// fX = 1.0f; normf(1, &fX);
powf(1.0f, 0.0f);
//rcbrtf(1.0f);
// rcbrtf(1.0f);
remainderf(2.0f, 1.0f);
remquof(1.0f, 2.0f, &iX);
#if defined(__HIP_PLATFORM_HCC__)
//rhypotf(0.0f, 1.0f);
// rhypotf(0.0f, 1.0f);
#endif
rintf(1.0f);
#if defined(__HIP_PLATFORM_HCC__)
//rnorm3df(0.0f, 0.0f, 1.0f);
//rnorm4df(0.0f, 0.0f, 0.0f, 1.0f);
fX = 1.0f; //rnormf(1, &fX);
// rnorm3df(0.0f, 0.0f, 1.0f);
// rnorm4df(0.0f, 0.0f, 0.0f, 1.0f);
fX = 1.0f; // rnormf(1, &fX);
#endif
roundf(0.0f);
///rsqrtf(1.0f);
/// rsqrtf(1.0f);
scalblnf(0.0f, 1);
scalbnf(0.0f, 1);
std::signbit(1.0f);
sincosf(0.0f, &fX, &fY);
//sincospif(0.0f, &fX, &fY);
// sincospif(0.0f, &fX, &fY);
sinf(0.0f);
sinhf(0.0f);
//sinpif(0.0f);
// sinpif(0.0f);
sqrtf(0.0f);
tanf(0.0f);
tanhf(0.0f);
@@ -137,13 +136,9 @@ __host__ void single_precision_math_functions()
ynf(1, 1.0f);
}
static void compileOnHost()
{
single_precision_math_functions();
}
static void compileOnHost() { single_precision_math_functions(); }
int main()
{
compileOnHost();
passed();
int main() {
compileOnHost();
passed();
}
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+4 -5
View File
@@ -17,12 +17,11 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#include<hip/hip_runtime_api.h>
#include<iostream>
#include<assert.h>
#include <hip/hip_runtime_api.h>
#include <iostream>
#include <assert.h>
int main()
{
int main() {
size_t heap;
assert(hipSuccess == hipDeviceGetLimit(&heap, hipLimitMallocHeapSize));
assert(heap == 4194304);
+21 -23
View File
@@ -23,32 +23,30 @@ THE SOFTWARE.
* HIT_END
*/
#include<hip/hip_runtime.h>
#include<hip/hip_runtime_api.h>
#include"test_common.h"
#include<iostream>
#include <hip/hip_runtime.h>
#include <hip/hip_runtime_api.h>
#include "test_common.h"
#include <iostream>
#define NUM 1024
#define SIZE 1024*4
#define SIZE 1024 * 4
__device__ int globalIn[NUM];
__device__ int globalOut[NUM];
__global__ void Assign(hipLaunchParm lp, int* Out)
{
__global__ void Assign(hipLaunchParm lp, int* Out) {
int tid = threadIdx.x + blockIdx.x * blockDim.x;
Out[tid] = globalIn[tid];
globalOut[tid] = globalIn[tid];
}
int main()
{
int main() {
int *A, *Am, *B, *Ad, *C, *Cm;
A = new int[NUM];
B = new int[NUM];
C = new int[NUM];
for(int i=0;i<NUM;i++) {
A[i] = -1*i;
for (int i = 0; i < NUM; i++) {
A[i] = -1 * i;
B[i] = 0;
C[i] = 0;
}
@@ -56,8 +54,8 @@ int main()
hipMalloc((void**)&Ad, SIZE);
hipHostMalloc((void**)&Am, SIZE);
hipHostMalloc((void**)&Cm, SIZE);
for(int i=0;i<NUM;i++) {
Am[i] = -1*i;
for (int i = 0; i < NUM; i++) {
Am[i] = -1 * i;
Cm[i] = 0;
}
@@ -65,41 +63,41 @@ int main()
hipStreamCreate(&stream);
hipMemcpyToSymbolAsync(HIP_SYMBOL(globalIn), Am, SIZE, 0, hipMemcpyHostToDevice, stream);
hipStreamSynchronize(stream);
hipLaunchKernel(Assign, dim3(1,1,1), dim3(NUM,1,1), 0, 0, Ad);
hipLaunchKernel(Assign, dim3(1, 1, 1), dim3(NUM, 1, 1), 0, 0, Ad);
hipMemcpy(B, Ad, SIZE, hipMemcpyDeviceToHost);
hipMemcpyFromSymbolAsync(Cm, HIP_SYMBOL(globalOut), SIZE, 0, hipMemcpyDeviceToHost, stream);
hipStreamSynchronize(stream);
for(int i=0;i<NUM;i++) {
for (int i = 0; i < NUM; i++) {
assert(Am[i] == B[i]);
assert(Am[i] == Cm[i]);
}
for(int i=0;i<NUM;i++) {
A[i] = -2*i;
for (int i = 0; i < NUM; i++) {
A[i] = -2 * i;
B[i] = 0;
}
hipMemcpyToSymbol(HIP_SYMBOL(globalIn), A, SIZE, 0, hipMemcpyHostToDevice);
hipLaunchKernel(Assign, dim3(1,1,1), dim3(NUM,1,1), 0, 0, Ad);
hipLaunchKernel(Assign, dim3(1, 1, 1), dim3(NUM, 1, 1), 0, 0, Ad);
hipMemcpy(B, Ad, SIZE, hipMemcpyDeviceToHost);
hipMemcpyFromSymbol(C, HIP_SYMBOL(globalOut), SIZE, 0, hipMemcpyDeviceToHost);
for(int i=0;i<NUM;i++) {
for (int i = 0; i < NUM; i++) {
assert(A[i] == B[i]);
assert(A[i] == C[i]);
}
for(int i=0;i<NUM;i++) {
A[i] = -3*i;
for (int i = 0; i < NUM; i++) {
A[i] = -3 * i;
B[i] = 0;
}
hipMemcpyToSymbolAsync(HIP_SYMBOL(globalIn), A, SIZE, 0, hipMemcpyHostToDevice, stream);
hipStreamSynchronize(stream);
hipLaunchKernel(Assign, dim3(1,1,1), dim3(NUM,1,1), 0, 0, Ad);
hipLaunchKernel(Assign, dim3(1, 1, 1), dim3(NUM, 1, 1), 0, 0, Ad);
hipMemcpy(B, Ad, SIZE, hipMemcpyDeviceToHost);
hipMemcpyFromSymbolAsync(C, HIP_SYMBOL(globalOut), SIZE, 0, hipMemcpyDeviceToHost, stream);
hipStreamSynchronize(stream);
for(int i=0;i<NUM;i++) {
for (int i = 0; i < NUM; i++) {
assert(A[i] == B[i]);
assert(A[i] == C[i]);
}
+32 -32
View File
@@ -23,50 +23,50 @@ THE SOFTWARE.
#include "test_common.h"
#define LEN 64
#define HALF_SIZE 64*sizeof(__half)
#define HALF2_SIZE 64*sizeof(__half2)
#define HALF_SIZE 64 * sizeof(__half)
#define HALF2_SIZE 64 * sizeof(__half2)
#if __HIP_ARCH_GFX803__ || __HIP_ARCH_GFX900__
__global__ void __halfMath(hipLaunchParm lp, __half *A, __half *B, __half *C) {
int tx = threadIdx.x;
__half a = A[tx];
__half b = B[tx];
__half c = C[tx];
c = __hadd(a, c);
c = __hadd_sat(b, c);
c = __hfma(a, c, b);
c = __hfma_sat(b, c, a);
c = __hsub(a, c);
c = __hsub_sat(b, c);
c = __hmul(a, c);
c = __hmul_sat(b, c);
c = hdiv(a, c);
__global__ void __halfMath(hipLaunchParm lp, __half* A, __half* B, __half* C) {
int tx = threadIdx.x;
__half a = A[tx];
__half b = B[tx];
__half c = C[tx];
c = __hadd(a, c);
c = __hadd_sat(b, c);
c = __hfma(a, c, b);
c = __hfma_sat(b, c, a);
c = __hsub(a, c);
c = __hsub_sat(b, c);
c = __hmul(a, c);
c = __hmul_sat(b, c);
c = hdiv(a, c);
}
__global__ void __half2Math(hipLaunchParm lp, __half2 *A, __half2 *B, __half2 *C) {
int tx = threadIdx.x;
__half2 a = A[tx];
__half2 b = B[tx];
__half2 c = C[tx];
c = __hadd2(a, c);
c = __hadd2_sat(b, c);
c = __hfma2(a, c, b);
c = __hfma2_sat(b, c, a);
c = __hsub2(a, c);
c = __hsub2_sat(b, c);
c = __hmul2(a, c);
c = __hmul2_sat(b, c);
__global__ void __half2Math(hipLaunchParm lp, __half2* A, __half2* B, __half2* C) {
int tx = threadIdx.x;
__half2 a = A[tx];
__half2 b = B[tx];
__half2 c = C[tx];
c = __hadd2(a, c);
c = __hadd2_sat(b, c);
c = __hfma2(a, c, b);
c = __hfma2_sat(b, c, a);
c = __hsub2(a, c);
c = __hsub2_sat(b, c);
c = __hmul2(a, c);
c = __hmul2_sat(b, c);
}
#endif
int main(){
int main() {
__half *A, *B, *C;
hipMalloc(&A, HALF_SIZE);
hipMalloc(&B, HALF_SIZE);
hipMalloc(&C, HALF_SIZE);
hipLaunchKernel(__halfMath, dim3(1,1,1), dim3(LEN,1,1), 0, 0, A, B, C);
hipLaunchKernel(__halfMath, dim3(1, 1, 1), dim3(LEN, 1, 1), 0, 0, A, B, C);
hipFree(A);
hipFree(B);
hipFree(C);
@@ -74,7 +74,7 @@ int main(){
hipMalloc(&A2, HALF2_SIZE);
hipMalloc(&B2, HALF2_SIZE);
hipMalloc(&C2, HALF2_SIZE);
hipLaunchKernel(__half2Math, dim3(1,1,1), dim3(LEN,1,1), 0, 0, A2, B2, C2);
hipLaunchKernel(__half2Math, dim3(1, 1, 1), dim3(LEN, 1, 1), 0, 0, A2, B2, C2);
hipFree(A2);
hipFree(B2);
hipFree(C2);
+106 -153
View File
@@ -23,234 +23,212 @@ THE SOFTWARE.
#define N 512
bool check_erfcinvf(){
bool check_erfcinvf() {
uint32_t len = 4;
float Val[] = {0.1, 1.2, 1, 0.9};
float Out[] = {1.16309, -0.179144, 0, 0.0889};
for(int i=0;i<len;i++){
if(Out[i] - erfcinvf(Val[i]) > 0.0001)
{
for (int i = 0; i < len; i++) {
if (Out[i] - erfcinvf(Val[i]) > 0.0001) {
return false;
}
}
return true;
}
bool check_erfcxf(){
bool check_erfcxf() {
uint32_t len = 4;
float Val[] = {-0.5, 15, 3.2, 1};
float Out[] = {1.9524, 0.0375, 0.1687, 0.4276};
for(int i=0;i<len;i++){
if(Out[i] - erfcxf(Val[i]) > 0.0001)
{
for (int i = 0; i < len; i++) {
if (Out[i] - erfcxf(Val[i]) > 0.0001) {
return false;
}
}
return true;
}
bool check_erfinvf()
{
bool check_erfinvf() {
uint32_t len = 4;
float Val[] = {0, -0.5, 0.9, -0.2};
float Out[] = {0, -0.4769, 1.1631, -0.1791};
for(int i=0;i<len;i++){
if(Out[i] - erfinvf(Val[i]) > 0.0001){
for (int i = 0; i < len; i++) {
if (Out[i] - erfinvf(Val[i]) > 0.0001) {
return false;
}
}
return true;
}
bool check_fdividef()
{
bool check_fdividef() {
uint32_t len = 4;
float Val[] = {0, -0.5, 0.9, -0.2};
float Out[] = {1, -0.4769, 1.1631, -0.1791};
for(int i=0;i<len;i++){
if(Val[i]/Out[i] - fdividef(Val[i], Out[i]) > 0.0001){
for (int i = 0; i < len; i++) {
if (Val[i] / Out[i] - fdividef(Val[i], Out[i]) > 0.0001) {
return false;
}
}
return true;
}
bool check_erfcinv(){
bool check_erfcinv() {
uint32_t len = 4;
double Val[] = {0.1, 1.2, 1, 0.9};
double Out[] = {1.16309, -0.179144, 0, 0.0889};
for(int i=0;i<len;i++){
if(Out[i] - erfcinv(Val[i]) > 0.0001)
{
for (int i = 0; i < len; i++) {
if (Out[i] - erfcinv(Val[i]) > 0.0001) {
return false;
}
}
return true;
}
bool check_erfcx(){
bool check_erfcx() {
uint32_t len = 4;
double Val[] = {-0.5, 15, 3.2, 1};
double Out[] = {1.9524, 0.0375, 0.1687, 0.4276};
for(int i=0;i<len;i++){
if(Out[i] - erfcx(Val[i]) > 0.0001)
{
for (int i = 0; i < len; i++) {
if (Out[i] - erfcx(Val[i]) > 0.0001) {
return false;
}
}
return true;
}
bool check_erfinv()
{
bool check_erfinv() {
uint32_t len = 4;
double Val[] = {0, -0.5, 0.9, -0.2};
double Out[] = {0, -0.4769, 1.1631, -0.1791};
for(int i=0;i<len;i++){
if(Out[i] - erfinv(Val[i]) > 0.0001){
for (int i = 0; i < len; i++) {
if (Out[i] - erfinv(Val[i]) > 0.0001) {
return false;
}
}
return true;
}
bool check_fdivide()
{
bool check_fdivide() {
uint32_t len = 4;
double Val[] = {0, -0.5, 0.9, -0.2};
double Out[] = {1, -0.4769, 1.1631, -0.1791};
for(int i=0;i<len;i++){
if(Val[i]/Out[i] - fdivide(Val[i], Out[i]) > 0.0001){
for (int i = 0; i < len; i++) {
if (Val[i] / Out[i] - fdivide(Val[i], Out[i]) > 0.0001) {
return false;
}
}
return true;
}
bool check_modff()
{
bool check_modff() {
uint32_t len = 4;
float Val[] = {0, -0.5, 0.9, -0.2};
float iPtr[] = {0, 0, 0, 0};
float frac[] = {0, -0.5, 0.9, -0.2};
float Out[] = {1, 1, 1, 1};
for(int i=0;i<len;i++){
if(frac[i] - modff(Val[i], Out+i) > 0.0001 && iPtr[i] == Out[i]){
for (int i = 0; i < len; i++) {
if (frac[i] - modff(Val[i], Out + i) > 0.0001 && iPtr[i] == Out[i]) {
return false;
}
}
return true;
}
bool check_modf()
{
bool check_modf() {
uint32_t len = 4;
double Val[] = {0, -0.5, 0.9, -0.2};
double iPtr[] = {0, 0, 0, 0};
double frac[] = {0, -0.5, 0.9, -0.2};
double Out[] = {1, 1, 1, 1};
for(int i=0;i<len;i++){
if(frac[i] - modf(Val[i], Out+i) > 0.0001 && iPtr[i] == Out[i]){
for (int i = 0; i < len; i++) {
if (frac[i] - modf(Val[i], Out + i) > 0.0001 && iPtr[i] == Out[i]) {
return false;
}
}
return true;
}
bool check_nextafterf()
{
bool check_nextafterf() {
uint32_t len = 4;
float Val[] = {0, -0.5, 0.9, -0.2};
float iPtr[] = {0, 0, 0, 0};
float frac[] = {0, -0.5, 0.9, -0.2};
float Out[] = {1, 1, 1, 1};
for(int i=0;i<len;i++){
if(nextafterf(Val[i],1) - Val[i] > 0.0001){
for (int i = 0; i < len; i++) {
if (nextafterf(Val[i], 1) - Val[i] > 0.0001) {
return false;
}
}
return true;
}
bool check_nextafter()
{
bool check_nextafter() {
uint32_t len = 4;
double Val[] = {0, -0.5, 0.9, -0.2};
double iPtr[] = {0, 0, 0, 0};
double frac[] = {0, -0.5, 0.9, -0.2};
double Out[] = {1, 1, 1, 1};
for(int i=0;i<len;i++){
if(nextafter(Val[i],1) - Val[i] > 0.0001){
for (int i = 0; i < len; i++) {
if (nextafter(Val[i], 1) - Val[i] > 0.0001) {
return false;
}
}
return true;
}
bool check_norm3df(float *A)
{
bool check_norm3df(float* A) {
float f = norm3df(A[0], A[1], A[2]);
float out = sqrt(A[0]*A[0] + A[1]*A[1] + A[2]*A[2]);
if(f - out > 0.0001)
{
float out = sqrt(A[0] * A[0] + A[1] * A[1] + A[2] * A[2]);
if (f - out > 0.0001) {
return false;
}
return true;
}
bool check_norm3d(double *A)
{
bool check_norm3d(double* A) {
double f = norm3d(A[0], A[1], A[2]);
double out = sqrt(A[0]*A[0] + A[1]*A[1] + A[2]*A[2]);
if(f - out > 0.0001)
{
double out = sqrt(A[0] * A[0] + A[1] * A[1] + A[2] * A[2]);
if (f - out > 0.0001) {
return false;
}
return true;
}
bool check_norm4df(float *A)
{
bool check_norm4df(float* A) {
float f = norm4df(A[0], A[1], A[2], A[3]);
float out = sqrt(A[0]*A[0] + A[1]*A[1] + A[2]*A[2] + A[3]*A[3]);
if(f - out > 0.0001)
{
float out = sqrt(A[0] * A[0] + A[1] * A[1] + A[2] * A[2] + A[3] * A[3]);
if (f - out > 0.0001) {
return false;
}
return true;
}
bool check_norm4d(double *A)
{
bool check_norm4d(double* A) {
double f = norm4d(A[0], A[1], A[2], A[3]);
double out = sqrt(A[0]*A[0] + A[1]*A[1] + A[2]*A[2] + A[3]*A[3]);
if(f - out > 0.0001)
{
double out = sqrt(A[0] * A[0] + A[1] * A[1] + A[2] * A[2] + A[3] * A[3]);
if (f - out > 0.0001) {
return false;
}
return true;
}
bool check_normcdff(){
bool check_normcdff() {
uint32_t len = 2;
float Val[] = {0,1};
float Val[] = {0, 1};
float Out[] = {0.5, 0.8413};
for(int i=0;i<len;i++){
if(Out[i] - normcdff(Val[i]) > 0.0001)
{
for (int i = 0; i < len; i++) {
if (Out[i] - normcdff(Val[i]) > 0.0001) {
return false;
}
}
return true;
}
bool check_normcdf(){
bool check_normcdf() {
uint32_t len = 2;
float Val[] = {0,1};
float Val[] = {0, 1};
float Out[] = {0.5, 0.8413};
for(int i=0;i<len;i++){
if(Out[i] - normcdf(Val[i]) > 0.0001)
{
for (int i = 0; i < len; i++) {
if (Out[i] - normcdf(Val[i]) > 0.0001) {
return false;
}
}
@@ -258,174 +236,149 @@ bool check_normcdf(){
}
bool check_normcdfinvf(){
bool check_normcdfinvf() {
uint32_t len = 2;
double Val[] = {0.5, 0.8413};
for(int i=0;i<len;i++){
if(Val[i] - normcdfinvf(normcdff(Val[i])) > 0.0001)
{
for (int i = 0; i < len; i++) {
if (Val[i] - normcdfinvf(normcdff(Val[i])) > 0.0001) {
return false;
}
}
return true;
}
bool check_normcdfinv(){
bool check_normcdfinv() {
uint32_t len = 2;
double Val[] = {0.5, 0.8413};
for(int i=0;i<len;i++){
if(Val[i] - normcdfinv(normcdf(Val[i])) > 0.0001)
{
for (int i = 0; i < len; i++) {
if (Val[i] - normcdfinv(normcdf(Val[i])) > 0.0001) {
return false;
}
}
return true;
}
bool check_rcbrtf()
{
bool check_rcbrtf() {
float f = 1.0f;
if(rcbrtf(f) != 1.0f)
{
if (rcbrtf(f) != 1.0f) {
return false;
}
return true;
}
bool check_rcbrt()
{
bool check_rcbrt() {
double f = 1.0;
if(rcbrt(f) != 1.0)
{
if (rcbrt(f) != 1.0) {
return false;
}
return true;
}
bool check_rhypotf()
{
bool check_rhypotf() {
float f = 1.0f;
float g = 2.0f;
float val = rhypotf(f, g);
float sq = f*f + g*g ;
if(1/(val*val) - sq > 0.0001)
{
float sq = f * f + g * g;
if (1 / (val * val) - sq > 0.0001) {
return false;
}
return true;
}
bool check_rhypot()
{
bool check_rhypot() {
double f = 1.0f;
double g = 2.0f;
double val = rhypot(f, g);
double sq = f*f + g*g;
if(1/(val*val) - sq > 0.0001)
{
double sq = f * f + g * g;
if (1 / (val * val) - sq > 0.0001) {
return false;
}
return true;
}
bool check_rnorm3df(float *A)
{
bool check_rnorm3df(float* A) {
float f = rnorm3df(A[0], A[1], A[2]);
float out = sqrt(A[0]*A[0] + A[1]*A[1] + A[2]*A[2]);
if(f - 1/out > 0.0001)
{
float out = sqrt(A[0] * A[0] + A[1] * A[1] + A[2] * A[2]);
if (f - 1 / out > 0.0001) {
return false;
}
return true;
}
bool check_rnorm3d(double *A)
{
bool check_rnorm3d(double* A) {
double f = rnorm3d(A[0], A[1], A[2]);
double out = sqrt(A[0]*A[0] + A[1]*A[1] + A[2]*A[2]);
if(f - 1/out > 0.0001)
{
double out = sqrt(A[0] * A[0] + A[1] * A[1] + A[2] * A[2]);
if (f - 1 / out > 0.0001) {
return false;
}
return true;
}
bool check_rnorm4df(float *A)
{
bool check_rnorm4df(float* A) {
float f = rnorm4df(A[0], A[1], A[2], A[3]);
float out = sqrt(A[0]*A[0] + A[1]*A[1] + A[2]*A[2] + A[3]*A[3]);
if(f - 1/out > 0.0001)
{
float out = sqrt(A[0] * A[0] + A[1] * A[1] + A[2] * A[2] + A[3] * A[3]);
if (f - 1 / out > 0.0001) {
return false;
}
return true;
}
bool check_rnorm4d(double *A)
{
bool check_rnorm4d(double* A) {
double f = rnorm4d(A[0], A[1], A[2], A[3]);
double out = sqrt(A[0]*A[0] + A[1]*A[1] + A[2]*A[2] + A[3]*A[3]);
if(f - 1/out > 0.0001)
{
double out = sqrt(A[0] * A[0] + A[1] * A[1] + A[2] * A[2] + A[3] * A[3]);
if (f - 1 / out > 0.0001) {
return false;
}
return true;
}
bool check_rnormf(float *A)
{
return (rnorm3df(A[0],A[1],A[2]) - rnormf(3,A) < 0.0001) && (rnorm4df(A[0],A[1],A[2],A[3]) - rnormf(4, A) < 0.0001 );
bool check_rnormf(float* A) {
return (rnorm3df(A[0], A[1], A[2]) - rnormf(3, A) < 0.0001) &&
(rnorm4df(A[0], A[1], A[2], A[3]) - rnormf(4, A) < 0.0001);
}
bool check_rnorm(double *A)
{
return (rnorm3d(A[0],A[1],A[2]) - rnorm(3,A) < 0.0001) && (rnorm4d(A[0],A[1],A[2],A[3]) - rnorm(4, A) < 0.0001 );
bool check_rnorm(double* A) {
return (rnorm3d(A[0], A[1], A[2]) - rnorm(3, A) < 0.0001) &&
(rnorm4d(A[0], A[1], A[2], A[3]) - rnorm(4, A) < 0.0001);
}
bool check_sincospif()
{
bool check_sincospif() {
float s1, c1, s2, c2;
float in1 = 1, in2 = 0.5;
sincospif(in1, &s1, &c1);
sincospif(in2, &s2, &c2);
if( (s1 - 0 < 0.00001) && (s2 - 1 < 0.00001) && (c1 + 1 < 0.00001) && (c2 - 0 < 0.00001)){
if ((s1 - 0 < 0.00001) && (s2 - 1 < 0.00001) && (c1 + 1 < 0.00001) && (c2 - 0 < 0.00001)) {
return true;
}
return false;
}
bool check_sincospi()
{
bool check_sincospi() {
double s1, c1, s2, c2;
double in1 = 1, in2 = 0.5;
sincospi(in1, &s1, &c1);
sincospi(in2, &s2, &c2);
if( (s1 - 0 < 0.00001) && (s2 - 1 < 0.00001) && (c1 + 1 < 0.00001) && (c2 - 0 < 0.00001)){
if ((s1 - 0 < 0.00001) && (s2 - 1 < 0.00001) && (c1 + 1 < 0.00001) && (c2 - 0 < 0.00001)) {
return true;
}
return false;
}
int main(){
float *Af = new float[N];
double *A = new double[N];
for(int i=0;i<N;i++){
int main() {
float* Af = new float[N];
double* A = new double[N];
for (int i = 0; i < N; i++) {
Af[i] = i * 1.0f;
A[i] = i * 1.0;
}
if(check_erfcinvf() && check_erfcxf() && check_erfcinvf() &&
check_erfcinv() && check_erfcx() && check_erfcinv() &&
check_fdividef() && check_fdivide() && check_modff() &&
check_modf() && check_nextafterf() && check_norm3df(Af) &&
check_norm3d(A) && check_norm4df(Af) && check_norm4d(A) &&
check_normcdff() && check_normcdf() && check_normcdfinvf() &&
check_normcdfinv() && check_rcbrtf() && check_rcbrt() &&
check_rhypotf() && check_rhypot() && check_rnorm3df(Af) &&
check_rnorm3d(A) && check_rnorm4df(Af) && check_rnorm4d(A) &&
check_rnormf(Af) && check_rnorm(A) && check_sincospif() &&
check_sincospi()
){
if (check_erfcinvf() && check_erfcxf() && check_erfcinvf() && check_erfcinv() &&
check_erfcx() && check_erfcinv() && check_fdividef() && check_fdivide() && check_modff() &&
check_modf() && check_nextafterf() && check_norm3df(Af) && check_norm3d(A) &&
check_norm4df(Af) && check_norm4d(A) && check_normcdff() && check_normcdf() &&
check_normcdfinvf() && check_normcdfinv() && check_rcbrtf() && check_rcbrt() &&
check_rhypotf() && check_rhypot() && check_rnorm3df(Af) && check_rnorm3d(A) &&
check_rnorm4df(Af) && check_rnorm4d(A) && check_rnormf(Af) && check_rnorm(A) &&
check_sincospif() && check_sincospi()) {
passed();
}
}
+15 -18
View File
@@ -23,34 +23,31 @@ THE SOFTWARE.
* HIT_END
*/
#include<iostream>
#include<hip/hip_runtime_api.h>
#include<hip/hip_runtime.h>
#include"test_common.h"
#include <iostream>
#include <hip/hip_runtime_api.h>
#include <hip/hip_runtime.h>
#include "test_common.h"
#define NUM 1024
#define SIZE NUM*sizeof(float)
#define SIZE NUM * sizeof(float)
__global__ void vAdd(hipLaunchParm lp, float *In1, float *In2, float *In3, float *In4, float *Out)
{
__global__ void vAdd(hipLaunchParm lp, float* In1, float* In2, float* In3, float* In4, float* Out) {
int tid = threadIdx.x + blockIdx.x * blockDim.x;
In4[tid] = In1[tid] + In2[tid];
__threadfence();
In3[tid] = In3[tid] + In4[tid];
__threadfence_block();
Out[tid] = In4[tid] + In3[tid];
}
int main(){
float *In1 = new float[1024];
float *In2 = new float[1024];
float *In3 = new float[1024];
float *In4 = new float[1024];
float *Out = new float[1024];
int main() {
float* In1 = new float[1024];
float* In2 = new float[1024];
float* In3 = new float[1024];
float* In4 = new float[1024];
float* Out = new float[1024];
for(uint32_t i=0;i<1024;i++)
{
for (uint32_t i = 0; i < 1024; i++) {
In1[i] = 1.0f;
In2[i] = 1.0f;
In3[i] = 1.0f;
@@ -69,8 +66,8 @@ int main(){
hipMemcpy(In3d, In3, SIZE, hipMemcpyHostToDevice);
hipMemcpy(In4d, In4, SIZE, hipMemcpyHostToDevice);
hipLaunchKernel(vAdd, dim3(32,1,1), dim3(32,1,1), 0, 0, In1d, In2d, In3d, In4d, Outd);
hipLaunchKernel(vAdd, dim3(32, 1, 1), dim3(32, 1, 1), 0, 0, In1d, In2d, In3d, In4d, Outd);
hipMemcpy(Out, Outd, SIZE, hipMemcpyDeviceToHost);
assert(Out[10] == 2*In1[10] + 2*In2[10] + In3[10]);
assert(Out[10] == 2 * In1[10] + 2 * In2[10] + In3[10]);
passed();
}
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+58 -54
View File
@@ -21,7 +21,7 @@ THE SOFTWARE.
*/
/* HIT_START
* BUILD: %t %s ../test_common.cpp NVCC_OPTIONS --Wno-deprecated-declarations
* BUILD: %t %s ../test_common.cpp NVCC_OPTIONS --Wno-deprecated-declarations
* RUN: %t
* HIT_END
*/
@@ -31,75 +31,79 @@ THE SOFTWARE.
#include <hip/hip_runtime.h>
#include <hip/device_functions.h>
#define HIP_ASSERT(x) (assert((x)==hipSuccess))
#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 = threadIdx.x + blockIdx.x * blockDim.x;
device_any[threadIdx.x>>pshift] = __any(tid -77);
device_all[threadIdx.x>>pshift] = __all(tid -77);
__global__ void warpvote(hipLaunchParm lp, int* device_any, int* device_all,
int Num_Warps_per_Block, int pshift) {
int tid = threadIdx.x + blockIdx.x * blockDim.x;
device_any[threadIdx.x >> pshift] = __any(tid - 77);
device_all[threadIdx.x >> pshift] = __all(tid - 77);
}
int main(int argc, char *argv[])
{ int warpSize, pshift;
hipDeviceProp_t devProp;
hipGetDeviceProperties(&devProp, 0);
warpSize = devProp.warpSize;
int main(int argc, char* argv[]) {
int warpSize, pshift;
hipDeviceProp_t devProp;
hipGetDeviceProperties(&devProp, 0);
warpSize = devProp.warpSize;
int w = warpSize;
pshift = 0;
while (w >>= 1) ++pshift;
int w = warpSize;
pshift = 0;
while (w >>= 1) ++pshift;
printf ("warpSize=%d pshift=%d\n", warpSize, pshift);
printf("warpSize=%d pshift=%d\n", warpSize, pshift);
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 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));
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);
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++) {
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]);
printf("warp no. %d __any = %d \n",i,host_any[i]);
printf("warp no. %d __all = %d \n",i,host_all[i]);
if (host_all[i]!=1) ++allcount;
#if defined (__HIP_PLATFORM_HCC__) && !defined ( NVCC_COMPAT )
if (host_any[i]!=64) ++anycount;
if (host_all[i] != 1) ++allcount;
#if defined(__HIP_PLATFORM_HCC__) && !defined(NVCC_COMPAT)
if (host_any[i] != 64) ++anycount;
#else
if (host_any[i]!=1) ++anycount;
if (host_any[i] != 1) ++anycount;
#endif
}
}
#if defined (__HIP_PLATFORM_HCC__) && !defined ( NVCC_COMPAT )
if (anycount == 1 && allcount ==1) printf("PASSED\n"); else printf("FAILED\n");
#if defined(__HIP_PLATFORM_HCC__) && !defined(NVCC_COMPAT)
if (anycount == 1 && allcount == 1)
printf("PASSED\n");
else
printf("FAILED\n");
#else
if (anycount == 0 && allcount ==1) printf("PASSED\n"); else printf("FAILED\n");
if (anycount == 0 && allcount == 1)
printf("PASSED\n");
else
printf("FAILED\n");
#endif
return EXIT_SUCCESS;
return EXIT_SUCCESS;
}
+47 -39
View File
@@ -28,60 +28,68 @@ THE SOFTWARE.
#include <hip/hip_runtime.h>
#include <hip/device_functions.h>
#define HIP_ASSERT(x) (assert((x)==hipSuccess))
#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 = threadIdx.x + blockIdx.x * blockDim.x;
const unsigned int warp_num = threadIdx.x >> pshift;
__global__ void gpu_ballot(hipLaunchParm lp, unsigned int* device_ballot, int Num_Warps_per_Block,
int pshift) {
int tid = threadIdx.x + blockIdx.x * blockDim.x;
const unsigned int warp_num = threadIdx.x >> pshift;
#ifdef __HIP_PLATFORM_HCC__
atomicAdd(&device_ballot[warp_num+blockIdx.x*Num_Warps_per_Block],__popcll(__ballot(tid - 245)));
atomicAdd(&device_ballot[warp_num + blockIdx.x * Num_Warps_per_Block],
__popcll(__ballot(tid - 245)));
#else
atomicAdd(&device_ballot[warp_num+blockIdx.x*Num_Warps_per_Block],__popc(__ballot(tid - 245)));
atomicAdd(&device_ballot[warp_num + blockIdx.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);
int main(int argc, char* argv[]) {
int warpSize, pshift;
hipDeviceProp_t devProp;
hipGetDeviceProperties(&devProp, 0);
warpSize = devProp.warpSize;
warpSize = devProp.warpSize;
int w = warpSize;
pshift = 0;
while (w >>= 1) ++pshift;
int w = warpSize;
pshift = 0;
while (w >>= 1) ++pshift;
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;
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));
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);
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++) {
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";
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;
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;
}
+101 -109
View File
@@ -34,150 +34,142 @@ THE SOFTWARE.
#include "hip/hip_runtime.h"
#include <hip/device_functions.h>
#define HIP_ASSERT(x) (assert((x)==hipSuccess))
#define HIP_ASSERT(x) (assert((x) == hipSuccess))
#define WIDTH 32
#define HEIGHT 32
#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
#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)
{
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--;
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)
{
__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 = blockDim.x * blockIdx.x + threadIdx.x;
int y = blockDim.y * blockIdx.y + threadIdx.y;
int x = blockDim.x * blockIdx.x + threadIdx.x;
int y = blockDim.y * blockIdx.y + threadIdx.y;
int i = y * width + x;
if ( i < (width * height)) {
int i = y * width + x;
if (i < (width * height)) {
a[i] = __brev(b[i]);
c[i] = __brevll(d[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* 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;
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;
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 ;
cout << "hip Device prop succeeded " << endl;
int i;
int errors;
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));
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++;
// initialize the input data
for (i = 0; i < NUM; i++) {
hostB[i] = i;
hostD[i] = i;
}
}
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++;
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;
}
}
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));
HIP_ASSERT(hipFree(deviceA));
HIP_ASSERT(hipFree(deviceB));
HIP_ASSERT(hipFree(deviceC));
HIP_ASSERT(hipFree(deviceD));
free(hostA);
free(hostB);
free(hostC);
free(hostD);
free(hostA);
free(hostB);
free(hostC);
free(hostD);
return errors;
return errors;
}
+117 -124
View File
@@ -34,158 +34,151 @@ THE SOFTWARE.
#include "hip/hip_runtime.h"
#include <hip/device_functions.h>
#define HIP_ASSERT(x) (assert((x)==hipSuccess))
#define WIDTH 8
#define HEIGHT 8
#define NUM (WIDTH*HEIGHT)
#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
#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)
{
#if defined (__HIP_PLATFORM_HCC__) && !defined ( NVCC_COMPAT )
unsigned int firstbit_u32(unsigned int a) {
if (a == 0) {
#if defined(__HIP_PLATFORM_HCC__) && !defined(NVCC_COMPAT)
return -1;
return -1;
#else
return 32;
return 32;
#endif
}
unsigned int pos = 0;
while ((int )a > 0) {
a <<= 1; pos++;
}
return pos;
}
unsigned int pos = 0;
while ((int)a > 0) {
a <<= 1;
pos++;
}
return pos;
}
unsigned int firstbit_u64(unsigned long long int a)
{
if (a == 0)
{
#if defined (__HIP_PLATFORM_HCC__) && !defined ( NVCC_COMPAT )
return -1;
unsigned int firstbit_u64(unsigned long long int a) {
if (a == 0) {
#if defined(__HIP_PLATFORM_HCC__) && !defined(NVCC_COMPAT)
return -1;
#else
return 64;
return 64;
#endif
}
unsigned int pos = 0;
while ((long long int)a > 0) {
a <<= 1; pos++;
}
return pos;
}
unsigned int pos = 0;
while ((long long int)a > 0) {
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)
{
__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 = blockDim.x * blockIdx.x + threadIdx.x;
int y = blockDim.y * blockIdx.y + threadIdx.y;
int x = blockDim.x * blockIdx.x + threadIdx.x;
int y = blockDim.y * blockIdx.y + threadIdx.y;
int i = y * width + x;
if ( i < (width * height)) {
int i = y * width + x;
if (i < (width * height)) {
a[i] = __clz(b[i]);
c[i] = __clzll(d[i]);
}
}
c[i] = __clzll(d[i]);
}
}
using namespace std;
int main() {
unsigned int* hostA;
unsigned int* hostB;
unsigned int* hostC;
unsigned long long int* hostD;
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;
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;
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;
cout << "hip Device prop succeeded " << endl ;
unsigned int i;
int errors;
unsigned 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));
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] = 419430*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 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_clz =%d, cpu_clz =%d \n",hostA[i],firstbit_u32(hostB[i]));
if (hostA[i] != firstbit_u32(hostB[i])) {
errors++;
// initialize the input data
for (i = 0; i < NUM; i++) {
hostB[i] = 419430 * i;
hostD[i] = i;
}
}
if (errors!=0) {
cout << "FAILED clz" << endl;
return -1;
} else {
cout << "__clz() checked!" << endl;
}
errors = 0;
for (i = 0; i < NUM; i++) {
printf("gpu_clzll =%d, cpu_clzll =%d \n",hostC[i],firstbit_u64(hostD[i]));
if (hostC[i] != firstbit_u64(hostD[i])) {
errors++;
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_clz =%d, cpu_clz =%d \n", hostA[i], firstbit_u32(hostB[i]));
if (hostA[i] != firstbit_u32(hostB[i])) {
errors++;
}
}
if (errors != 0) {
cout << "FAILED clz" << endl;
return -1;
} else {
cout << "__clz() checked!" << endl;
}
errors = 0;
for (i = 0; i < NUM; i++) {
printf("gpu_clzll =%d, cpu_clzll =%d \n", hostC[i], firstbit_u64(hostD[i]));
if (hostC[i] != firstbit_u64(hostD[i])) {
errors++;
}
}
if (errors != 0) {
cout << "FAILED clz" << endl;
return -1;
} else {
cout << "__clzll() checked!" << endl;
}
}
if (errors!=0) {
cout << "FAILED clz" << endl;
return -1;
} else {
cout << "__clzll() 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(deviceA));
HIP_ASSERT(hipFree(deviceB));
HIP_ASSERT(hipFree(deviceC));
HIP_ASSERT(hipFree(deviceD));
free(hostA);
free(hostB);
free(hostC);
free(hostD);
free(hostA);
free(hostB);
free(hostC);
free(hostD);
return errors;
return errors;
}
+107 -115
View File
@@ -34,153 +34,145 @@ THE SOFTWARE.
#include <hip/hip_runtime.h>
#include <hip/device_functions.h>
#define HIP_ASSERT(x) (assert((x)==hipSuccess))
#define HIP_ASSERT(x) (assert((x) == hipSuccess))
#define WIDTH 8
#define HEIGHT 8
#define WIDTH 8
#define HEIGHT 8
#define NUM (WIDTH*HEIGHT)
#define NUM (WIDTH * HEIGHT)
#define THREADS_PER_BLOCK_X 8
#define THREADS_PER_BLOCK_Y 8
#define THREADS_PER_BLOCK_Z 1
#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)
#if defined (__HIP_PLATFORM_HCC__) && !defined ( NVCC_COMPAT )
return -1;
template <typename T>
int lastbit(T a) {
if (a == 0)
#if defined(__HIP_PLATFORM_HCC__) && !defined(NVCC_COMPAT)
return -1;
#else
return 0;
return 0;
#endif
int pos = 1;
while ((a&1) != 1) {
a >>= 1; pos++;
}
#if defined (__HIP_PLATFORM_HCC__) && !defined ( NVCC_COMPAT )
return pos-1;
int pos = 1;
while ((a & 1) != 1) {
a >>= 1;
pos++;
}
#if defined(__HIP_PLATFORM_HCC__) && !defined(NVCC_COMPAT)
return pos - 1;
#else
return pos;
return pos;
#endif
}
__global__ void
HIP_kernel(hipLaunchParm lp,
unsigned int* a, unsigned int* b, unsigned int* c, unsigned long long int* d,
int width, int height)
{
__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 = blockDim.x * blockIdx.x + threadIdx.x;
int y = blockDim.y * blockIdx.y + threadIdx.y;
int x = blockDim.x * blockIdx.x + threadIdx.x;
int y = blockDim.y * blockIdx.y + threadIdx.y;
int i = y * width + x;
if ( i < (width * height)) {
int i = y * width + x;
if (i < (width * height)) {
a[i] = __ffs(b[i]);
c[i] = __ffsll(d[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* 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;
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;
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 ;
cout << "hip Device prop succeeded " << endl;
int i;
int errors;
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));
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++;
// initialize the input data
for (i = 0; i < NUM; i++) {
hostB[i] = i;
hostD[i] = 1099511627776 + i;
}
}
if (errors!=0) {
cout << "FAILED: ffs" << endl;
return -1;
} else {
cout << "__ffs() for unsigned checked!" << endl;
}
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++;
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) {
cout << "FAILED: ffs" << endl;
return -1;
} else {
cout << "__ffs() for unsigned checked!" << endl;
}
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) {
cout << "FAILED: ffs" << endl;
return -1;
} else {
cout << "__ffsll() for unsigned checked!" << endl;
}
}
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));
HIP_ASSERT(hipFree(deviceA));
HIP_ASSERT(hipFree(deviceB));
HIP_ASSERT(hipFree(deviceC));
HIP_ASSERT(hipFree(deviceD));
free(hostA);
free(hostB);
free(hostC);
free(hostD);
free(hostA);
free(hostB);
free(hostC);
free(hostD);
return errors;
return errors;
}
+100 -108
View File
@@ -34,141 +34,133 @@ THE SOFTWARE.
#include <hip/hip_runtime.h>
#include <hip/device_functions.h>
#define HIP_ASSERT(x) (assert((x)==hipSuccess))
#define HIP_ASSERT(x) (assert((x) == hipSuccess))
#define WIDTH 16
#define HEIGHT 16
#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
#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;
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)
{
__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 = blockDim.x * blockIdx.x + threadIdx.x;
int y = blockDim.y * blockIdx.y + threadIdx.y;
int x = blockDim.x * blockIdx.x + threadIdx.x;
int y = blockDim.y * blockIdx.y + threadIdx.y;
int i = y * width + x;
if ( i < (width * height)) {
int i = y * width + x;
if (i < (width * height)) {
a[i] = __popc(b[i]);
c[i] = __popcll(d[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* 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;
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;
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 ;
cout << "hip Device prop succeeded " << endl;
int i;
int errors;
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));
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++;
// initialize the input data
for (i = 0; i < NUM; i++) {
hostB[i] = i;
hostD[i] = 1099511627776 - i;
}
}
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++;
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;
}
}
if (errors!=0) {
cout << "FAILED:popc" << endl;
return -1;
} else {
cout << "__popcll() checked!" << endl;
}
cout << "popc test PASSED!" << endl;
cout << "popc test PASSED!" << endl;
HIP_ASSERT(hipFree(deviceA));
HIP_ASSERT(hipFree(deviceB));
HIP_ASSERT(hipFree(deviceC));
HIP_ASSERT(hipFree(deviceD));
HIP_ASSERT(hipFree(deviceA));
HIP_ASSERT(hipFree(deviceB));
HIP_ASSERT(hipFree(deviceC));
HIP_ASSERT(hipFree(deviceD));
free(hostA);
free(hostB);
free(hostC);
free(hostD);
free(hostA);
free(hostB);
free(hostC);
free(hostD);
return errors;
return errors;
}
+225 -300
View File
@@ -30,353 +30,282 @@ THE SOFTWARE.
#include <stdio.h>
#include <algorithm>
#include <stdlib.h>
#include<iostream>
#include <iostream>
#include "hip/hip_runtime.h"
#include "hip/hip_vector_types.h"
#include "test_common.h"
#if (__hcc_workweek__ >= 16164) || defined (__HIP_PLATFORM_NVCC__)
#if (__hcc_workweek__ >= 16164) || defined(__HIP_PLATFORM_NVCC__)
#define HIP_ASSERT(x) (assert((x)==hipSuccess))
#define HIP_ASSERT(x) (assert((x) == hipSuccess))
#define WIDTH 8
#define HEIGHT 8
#define WIDTH 8
#define HEIGHT 8
#define NUM (WIDTH*HEIGHT)
#define NUM (WIDTH * HEIGHT)
#define THREADS_PER_BLOCK_X 8
#define THREADS_PER_BLOCK_Y 8
#define THREADS_PER_BLOCK_Z 1
#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)
template <typename T>
__global__ void vectoradd_float(hipLaunchParm lp, T* a, const T* bm, int width, int height)
{
int x = blockDim.x * blockIdx.x + threadIdx.x;
int y = blockDim.y * blockIdx.y + threadIdx.y;
{
int x = blockDim.x * blockIdx.x + threadIdx.x;
int y = blockDim.y * blockIdx.y + threadIdx.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,
static_cast<const T*>(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++;
int i = y * width + x;
if (i < (width * height)) {
a[i] = __ldg(&bm[i]);
}
}
if (errors!=0) {
std::cout << "FAILED\n"<<std::endl;
ret = false;
} else {
ret = true;
}
}
HIP_ASSERT(hipFree(deviceA));
HIP_ASSERT(hipFree(deviceB));
int2 make_vector2(int a) { return make_int2(a, a); }
free(hostA);
free(hostB);
char2 make_vector2(signed char a) { return make_char2(a, a); }
return ret;
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,
static_cast<const T*>(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;
template <typename T, typename U>
bool dataTypesRun2() {
T* hostA;
T* hostB;
T* deviceA;
T* deviceB;
T* deviceA;
T* deviceB;
int i;
int errors;
int i;
int errors;
hostA = (T*)malloc(NUM * sizeof(T));
hostB = (T*)malloc(NUM * sizeof(T));
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,
static_cast<const T*>(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++;
// initialize the input data
for (i = 0; i < NUM; i++) {
hostB[i] = make_vector2((U)i);
}
}
if (errors!=0) {
std::cout << "FAILED\n"<<std::endl;
ret = false;
} else {
ret = true;
}
HIP_ASSERT(hipFree(deviceA));
HIP_ASSERT(hipFree(deviceB));
HIP_ASSERT(hipMalloc((void**)&deviceA, NUM * sizeof(T)));
HIP_ASSERT(hipMalloc((void**)&deviceB, NUM * sizeof(T)));
free(hostA);
free(hostB);
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,
static_cast<const T*>(deviceB), WIDTH, HEIGHT);
return ret;
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;
template <typename T, typename U>
bool dataTypesRun4() {
T* hostA;
T* hostB;
T* deviceA;
T* deviceB;
T* deviceA;
T* deviceB;
int i;
int errors;
int i;
int errors;
hostA = (T*)malloc(NUM * sizeof(T));
hostB = (T*)malloc(NUM * sizeof(T));
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,
static_cast<const T*>(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++;
// initialize the input data
for (i = 0; i < NUM; i++) {
hostB[i] = make_vector4((U)i);
}
}
if (errors!=0) {
std::cout << "FAILED\n"<<std::endl;
ret = false;
} else {
ret = true;
}
HIP_ASSERT(hipFree(deviceA));
HIP_ASSERT(hipFree(deviceB));
HIP_ASSERT(hipMalloc((void**)&deviceA, NUM * sizeof(T)));
HIP_ASSERT(hipMalloc((void**)&deviceB, NUM * sizeof(T)));
free(hostA);
free(hostB);
HIP_ASSERT(hipMemcpy(deviceB, hostB, NUM * sizeof(T), hipMemcpyHostToDevice));
return ret;
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,
static_cast<const T*>(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;
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>();
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){
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;
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>();
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){
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;
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
@@ -384,24 +313,20 @@ int main() {
#if 1
errors = dataTypesRun4<int4,int>() &
dataTypesRun4<char4,signed char>() &
dataTypesRun4<uchar4,unsigned char>() &
dataTypesRun4<short4, short>() &
dataTypesRun4<uint4,unsigned int>() &
dataTypesRun4<float4,float>() ;
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){
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;
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;
std::cout << "ldg test PASSED \n" << std::endl;
}
#endif
+265 -275
View File
@@ -23,76 +23,73 @@ THE SOFTWARE.
#include <stdio.h>
#include <algorithm>
#include <stdlib.h>
#include<iostream>
#include <iostream>
#include "hip/hip_runtime.h"
#include "test_common.h"
#define HIP_ASSERT(x) (assert((x)==hipSuccess))
#define HIP_ASSERT(x) (assert((x) == hipSuccess))
#define WIDTH 8
#define HEIGHT 8
#define WIDTH 8
#define HEIGHT 8
#define NUM (WIDTH*HEIGHT)
#define NUM (WIDTH * HEIGHT)
#define THREADS_PER_BLOCK_X 8
#define THREADS_PER_BLOCK_Y 8
#define THREADS_PER_BLOCK_Z 1
#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)
__global__ void vectoradd_char1(hipLaunchParm lp, char1* a, const char1* bm, const char1* cm,
int width, int height)
{
int x = blockDim.x * blockIdx.x + threadIdx.x;
int y = blockDim.y * blockIdx.y + threadIdx.y;
{
int x = blockDim.x * blockIdx.x + threadIdx.x;
int y = blockDim.y * blockIdx.y + threadIdx.y;
int i = y * width + x;
if ( i < (width * height)) {
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)
__global__ void vectoradd_char2(hipLaunchParm lp, char2* a, const char2* bm, const char2* cm,
int width, int height)
{
int x = blockDim.x * blockIdx.x + threadIdx.x;
int y = blockDim.y * blockIdx.y + threadIdx.y;
{
int x = blockDim.x * blockIdx.x + threadIdx.x;
int y = blockDim.y * blockIdx.y + threadIdx.y;
int i = y * width + x;
if ( i < (width * height)) {
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)
__global__ void vectoradd_char3(hipLaunchParm lp, char3* a, const char3* bm, const char3* cm,
int width, int height)
{
int x = blockDim.x * blockIdx.x + threadIdx.x;
int y = blockDim.y * blockIdx.y + threadIdx.y;
{
int x = blockDim.x * blockIdx.x + threadIdx.x;
int y = blockDim.y * blockIdx.y + threadIdx.y;
int i = y * width + x;
if ( i < (width * height)) {
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)
__global__ void vectoradd_char4(hipLaunchParm lp, char4* a, const char4* bm, const char4* cm,
int width, int height)
{
int x = blockDim.x * blockIdx.x + threadIdx.x;
int y = blockDim.y * blockIdx.y + threadIdx.y;
{
int x = blockDim.x * blockIdx.x + threadIdx.x;
int y = blockDim.y * blockIdx.y + threadIdx.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);
}
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);
}
}
@@ -112,282 +109,275 @@ __kernel__ void vectoradd_float(float* a, const float* b, const float* c, int wi
using namespace std;
template<typename T>
bool dataTypesRun(){
T* hostA;
T* hostB;
T* hostC;
template <typename T>
bool dataTypesRun() {
T* hostA;
T* hostB;
T* hostC;
T* deviceA;
T* deviceB;
T* deviceC;
T* deviceA;
T* deviceB;
T* deviceC;
int i;
int errors;
int i;
int errors;
hostA = (T*)malloc(NUM * sizeof(T));
hostB = (T*)malloc(NUM * sizeof(T));
hostC = (T*)malloc(NUM * sizeof(T));
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++;
// initialize the input data
for (i = 0; i < NUM; i++) {
hostB[i] = (T)i;
hostC[i] = (T)i;
}
}
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));
HIP_ASSERT(hipMalloc((void**)&deviceA, NUM * sizeof(T)));
HIP_ASSERT(hipMalloc((void**)&deviceB, NUM * sizeof(T)));
HIP_ASSERT(hipMalloc((void**)&deviceC, NUM * sizeof(T)));
free(hostA);
free(hostB);
free(hostC);
HIP_ASSERT(hipMemcpy(deviceB, hostB, NUM * sizeof(T), hipMemcpyHostToDevice));
HIP_ASSERT(hipMemcpy(deviceC, hostC, NUM * sizeof(T), hipMemcpyHostToDevice));
return ret;
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;
template <typename T>
bool dataTypesRun() {
T* hostA;
T* hostB;
T* hostC;
T* deviceA;
T* deviceB;
T* deviceC;
T* deviceA;
T* deviceB;
T* deviceC;
int i;
int errors;
int i;
int errors;
hostA = (T*)malloc(NUM * sizeof(T));
hostB = (T*)malloc(NUM * sizeof(T));
hostC = (T*)malloc(NUM * sizeof(T));
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++;
// initialize the input data
for (i = 0; i < NUM; i++) {
hostB[i] = (T)i;
hostC[i] = (T)i;
}
}
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));
HIP_ASSERT(hipMalloc((void**)&deviceA, NUM * sizeof(T)));
HIP_ASSERT(hipMalloc((void**)&deviceB, NUM * sizeof(T)));
HIP_ASSERT(hipMalloc((void**)&deviceC, NUM * sizeof(T)));
free(hostA);
free(hostB);
free(hostC);
HIP_ASSERT(hipMemcpy(deviceB, hostB, NUM * sizeof(T), hipMemcpyHostToDevice));
HIP_ASSERT(hipMemcpy(deviceC, hostC, NUM * sizeof(T), hipMemcpyHostToDevice));
return ret;
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;
template <typename T>
bool dataTypesRun() {
T* hostA;
T* hostB;
T* hostC;
T* deviceA;
T* deviceB;
T* deviceC;
T* deviceA;
T* deviceB;
T* deviceC;
int i;
int errors;
int i;
int errors;
hostA = (T*)malloc(NUM * sizeof(T));
hostB = (T*)malloc(NUM * sizeof(T));
hostC = (T*)malloc(NUM * sizeof(T));
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++;
// initialize the input data
for (i = 0; i < NUM; i++) {
hostB[i] = (T)i;
hostC[i] = (T)i;
}
}
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));
HIP_ASSERT(hipMalloc((void**)&deviceA, NUM * sizeof(T)));
HIP_ASSERT(hipMalloc((void**)&deviceB, NUM * sizeof(T)));
HIP_ASSERT(hipMalloc((void**)&deviceC, NUM * sizeof(T)));
free(hostA);
free(hostB);
free(hostC);
HIP_ASSERT(hipMemcpy(deviceB, hostB, NUM * sizeof(T), hipMemcpyHostToDevice));
HIP_ASSERT(hipMemcpy(deviceC, hostC, NUM * sizeof(T), hipMemcpyHostToDevice));
return ret;
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;
bool dataTypesRunChar4() {
char4* hostA;
char4* hostB;
char4* hostC;
char4* deviceA;
char4* deviceB;
char4* deviceC;
char4* deviceA;
char4* deviceB;
char4* deviceC;
int i;
int errors;
int i;
int errors;
hostA = (T*)malloc(NUM * sizeof(T));
hostB = (T*)malloc(NUM * sizeof(T));
hostC = (T*)malloc(NUM * sizeof(T));
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++;
// initialize the input data
for (i = 0; i < NUM; i++) {
hostB[i] = (T)i;
hostC[i] = (T)i;
}
}
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));
HIP_ASSERT(hipMalloc((void**)&deviceA, NUM * sizeof(T)));
HIP_ASSERT(hipMalloc((void**)&deviceB, NUM * sizeof(T)));
HIP_ASSERT(hipMalloc((void**)&deviceC, NUM * sizeof(T)));
free(hostA);
free(hostB);
free(hostC);
HIP_ASSERT(hipMemcpy(deviceB, hostB, NUM * sizeof(T), hipMemcpyHostToDevice));
HIP_ASSERT(hipMemcpy(deviceC, hostC, NUM * sizeof(T), hipMemcpyHostToDevice));
return ret;
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;
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>();
errors = dataTypesRun<char1>() & dataTypesRun<char2>() & dataTypesRun<char3>() &
dataTypesRun<char4>();
//hipResetDefaultAccelerator();
if(errors == 1){
// hipResetDefaultAccelerator();
if (errors == 1) {
passed();
}else{
std::cout<<"Failed Float"<<std::endl;
} else {
std::cout << "Failed Float" << std::endl;
return -1;
}
}
+74 -76
View File
@@ -35,95 +35,93 @@ THE SOFTWARE.
#include "hip/device_functions.h"
#include "test_common.h"
#define HIP_ASSERT(x) (assert((x)==hipSuccess))
#define HIP_ASSERT(x) (assert((x) == hipSuccess))
__host__ __device__ void fence_system() {
#ifdef __HIP_DEVICE_COMPILE__
__threadfence_system();
__threadfence_system();
#else
std::atomic_thread_fence(std::memory_order_seq_cst);
std::atomic_thread_fence(std::memory_order_seq_cst);
#endif
}
__host__ __device__ void round_robin(const int id, const int num_dev, const int num_iter, volatile int* data, volatile int* flag) {
for (int i = 0; i < num_iter; i++) {
while(*flag%num_dev != id)
fence_system(); // invalid the cache for read
__host__ __device__ void round_robin(const int id, const int num_dev, const int num_iter,
volatile int* data, volatile int* flag) {
for (int i = 0; i < num_iter; i++) {
while (*flag % num_dev != id) fence_system(); // invalid the cache for read
(*data)++;
fence_system(); // make sure the store to data is sequenced before the store to flag
(*flag)++;
fence_system(); // invalid the cache to flush out flag
}
(*data)++;
fence_system(); // make sure the store to data is sequenced before the store to flag
(*flag)++;
fence_system(); // invalid the cache to flush out flag
}
}
__global__ void gpu_round_robin(const int id, const int num_dev, const int num_iter, volatile int* data, volatile int* flag) {
round_robin(id, num_dev, num_iter, data, flag);
__global__ void gpu_round_robin(const int id, const int num_dev, const int num_iter,
volatile int* data, volatile int* flag) {
round_robin(id, num_dev, num_iter, data, flag);
}
int main() {
int num_gpus = 0;
HIP_ASSERT(hipGetDeviceCount(&num_gpus));
if (num_gpus == 0) {
passed();
return 0;
}
volatile int* data;
HIP_ASSERT(hipHostMalloc(&data, sizeof(int), hipHostMallocCoherent));
constexpr int init_data = 1000;
*data = init_data;
volatile int* flag;
HIP_ASSERT(hipHostMalloc(&flag, sizeof(int), hipHostMallocCoherent));
*flag = 0;
// number of rounds per device
constexpr int num_iter = 1000;
// one CPU thread + 1 kernel/GPU
const int num_dev = num_gpus + 1;
int next_id = 0;
std::vector<std::thread> threads;
// create a CPU thread for the round_robin
threads.push_back(std::thread(round_robin, next_id++, num_dev, num_iter, data, flag));
// run one thread per GPU
dim3 dim_block(1, 1, 1);
dim3 dim_grid(1, 1, 1);
// launch one kernel per device for the round robin
for (; next_id < num_dev; ++next_id) {
threads.push_back(std::thread([=]() {
HIP_ASSERT(hipSetDevice(next_id - 1));
hipLaunchKernelGGL(gpu_round_robin, dim_grid, dim_block, 0, 0x0, next_id, num_dev,
num_iter, data, flag);
HIP_ASSERT(hipDeviceSynchronize());
}));
}
for (auto& t : threads) {
t.join();
}
int expected_data = init_data + num_dev * num_iter;
int expected_flag = num_dev * num_iter;
bool passed = *data == expected_data && *flag == expected_flag;
HIP_ASSERT(hipHostFree((void*)data));
HIP_ASSERT(hipHostFree((void*)flag));
if (passed) {
passed();
} else {
failed("Failed Verification!\n");
}
int num_gpus = 0;
HIP_ASSERT(hipGetDeviceCount(&num_gpus));
if (num_gpus == 0) {
passed();
return 0;
}
volatile int* data;
HIP_ASSERT(hipHostMalloc(&data, sizeof(int), hipHostMallocCoherent));
constexpr int init_data = 1000;
*data = init_data;
volatile int* flag;
HIP_ASSERT(hipHostMalloc(&flag, sizeof(int), hipHostMallocCoherent));
*flag = 0;
// number of rounds per device
constexpr int num_iter = 1000;
// one CPU thread + 1 kernel/GPU
const int num_dev = num_gpus + 1;
int next_id = 0;
std::vector<std::thread> threads;
// create a CPU thread for the round_robin
threads.push_back(std::thread(round_robin, next_id++, num_dev, num_iter, data, flag));
// run one thread per GPU
dim3 dim_block(1,1,1);
dim3 dim_grid(1,1,1);
// launch one kernel per device for the round robin
for (; next_id < num_dev; ++next_id) {
threads.push_back(std::thread([=]() {
HIP_ASSERT(hipSetDevice(next_id-1));
hipLaunchKernelGGL(gpu_round_robin, dim_grid, dim_block, 0, 0x0
, next_id, num_dev, num_iter, data, flag);
HIP_ASSERT(hipDeviceSynchronize());
}));
}
for (auto& t : threads) {
t.join();
}
int expected_data = init_data + num_dev * num_iter;
int expected_flag = num_dev * num_iter;
bool passed = *data == expected_data
&& *flag == expected_flag;
HIP_ASSERT(hipHostFree((void*)data));
HIP_ASSERT(hipHostFree((void*)flag));
if (passed) {
passed();
}
else {
failed("Failed Verification!\n");
}
return 0;
}
+49 -47
View File
@@ -26,57 +26,59 @@ THE SOFTWARE.
* HIT_END
*/
#include<hip/hip_runtime_api.h>
#include<hip/hip_runtime.h>
#include<iostream>
#include"test_common.h"
#include<hip/device_functions.h>
#include <hip/hip_runtime_api.h>
#include <hip/hip_runtime.h>
#include <iostream>
#include "test_common.h"
#include <hip/device_functions.h>
#define LEN 512
#define SIZE LEN<<2
#define SIZE LEN << 2
__global__ void kernel_trig(hipLaunchParm lp, float *In, float *sin_d, float *cos_d, float *tan_d, float *sin_pd, float *cos_pd){
int tid = threadIdx.x + blockIdx.x * blockDim.x;
sin_d[tid] = __sinf(In[tid]);
cos_d[tid] = __cosf(In[tid]);
tan_d[tid] = __tanf(In[tid]);
__sincosf(In[tid], &sin_pd[tid], &cos_pd[tid]);
__global__ void kernel_trig(hipLaunchParm lp, float* In, float* sin_d, float* cos_d, float* tan_d,
float* sin_pd, float* cos_pd) {
int tid = threadIdx.x + blockIdx.x * blockDim.x;
sin_d[tid] = __sinf(In[tid]);
cos_d[tid] = __cosf(In[tid]);
tan_d[tid] = __tanf(In[tid]);
__sincosf(In[tid], &sin_pd[tid], &cos_pd[tid]);
}
int main(){
float *In, *sin_h, *cos_h, *tan_h, *sin_ph, *cos_ph;
float *In_d, *sin_d, *cos_d, *tan_d, *sin_pd, *cos_pd;
In = new float[LEN];
sin_h = new float[LEN];
cos_h = new float[LEN];
tan_h = new float[LEN];
sin_ph = new float[LEN];
cos_ph = new float[LEN];
for(int i=0;i<LEN;i++){
In[i] = 1.0f;
sin_h[i] = 0.0f;
cos_h[i] = 0.0f;
tan_h[i] = 0.0f;
sin_ph[i] = 0.0f;
cos_ph[i] = 0.0f;
}
hipMalloc((void**)&In_d, SIZE);
hipMalloc((void**)&sin_d, SIZE);
hipMalloc((void**)&cos_d, SIZE);
hipMalloc((void**)&tan_d, SIZE);
hipMalloc((void**)&sin_pd, SIZE);
hipMalloc((void**)&cos_pd, SIZE);
hipMemcpy(In_d, In, SIZE, hipMemcpyHostToDevice);
hipLaunchKernel(kernel_trig, dim3(LEN,1,1), dim3(1,1,1), 0, 0, In_d, sin_d, cos_d, tan_d, sin_pd, cos_pd);
hipMemcpy(sin_h, sin_d, SIZE, hipMemcpyDeviceToHost);
hipMemcpy(cos_h, cos_d, SIZE, hipMemcpyDeviceToHost);
hipMemcpy(tan_h, tan_d, SIZE, hipMemcpyDeviceToHost);
hipMemcpy(sin_ph, sin_pd, SIZE, hipMemcpyDeviceToHost);
hipMemcpy(cos_ph, cos_pd, SIZE, hipMemcpyDeviceToHost);
for(int i=0;i<LEN;i++) {
if(sin_h[i] != sin_ph[i] || cos_h[i] != cos_ph[i] || tan_h[i]*cos_h[i] != sin_h[i]){
std::cout<<"Failed!"<<std::endl;
int main() {
float *In, *sin_h, *cos_h, *tan_h, *sin_ph, *cos_ph;
float *In_d, *sin_d, *cos_d, *tan_d, *sin_pd, *cos_pd;
In = new float[LEN];
sin_h = new float[LEN];
cos_h = new float[LEN];
tan_h = new float[LEN];
sin_ph = new float[LEN];
cos_ph = new float[LEN];
for (int i = 0; i < LEN; i++) {
In[i] = 1.0f;
sin_h[i] = 0.0f;
cos_h[i] = 0.0f;
tan_h[i] = 0.0f;
sin_ph[i] = 0.0f;
cos_ph[i] = 0.0f;
}
}
passed();
hipMalloc((void**)&In_d, SIZE);
hipMalloc((void**)&sin_d, SIZE);
hipMalloc((void**)&cos_d, SIZE);
hipMalloc((void**)&tan_d, SIZE);
hipMalloc((void**)&sin_pd, SIZE);
hipMalloc((void**)&cos_pd, SIZE);
hipMemcpy(In_d, In, SIZE, hipMemcpyHostToDevice);
hipLaunchKernel(kernel_trig, dim3(LEN, 1, 1), dim3(1, 1, 1), 0, 0, In_d, sin_d, cos_d, tan_d,
sin_pd, cos_pd);
hipMemcpy(sin_h, sin_d, SIZE, hipMemcpyDeviceToHost);
hipMemcpy(cos_h, cos_d, SIZE, hipMemcpyDeviceToHost);
hipMemcpy(tan_h, tan_d, SIZE, hipMemcpyDeviceToHost);
hipMemcpy(sin_ph, sin_pd, SIZE, hipMemcpyDeviceToHost);
hipMemcpy(cos_ph, cos_pd, SIZE, hipMemcpyDeviceToHost);
for (int i = 0; i < LEN; i++) {
if (sin_h[i] != sin_ph[i] || cos_h[i] != cos_ph[i] || tan_h[i] * cos_h[i] != sin_h[i]) {
std::cout << "Failed!" << std::endl;
}
}
passed();
}