Apply .clangformat to all repo source files
Change-Id: I7e79c6058f0303f9a98911e3b7dd2e8596079344
[ROCm/clr commit: 9e47fccc89]
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Verwijs in nieuw issue
Block a user