Apply .clangformat to all repo source files

Change-Id: I7e79c6058f0303f9a98911e3b7dd2e8596079344


[ROCm/clr commit: 9e47fccc89]
Bu işleme şunda yer alıyor:
Maneesh Gupta
2018-03-12 11:29:03 +05:30
ebeveyn ecbb701440
işleme 46ddefedee
293 değiştirilmiş dosya ile 43980 ekleme ve 45830 silme
+54 -26
Dosyayı Görüntüle
@@ -29,15 +29,15 @@ THE SOFTWARE.
#include "hip/hip_runtime.h"
#include "test_common.h"
template<typename T>
__global__ void testExternSharedKernel(hipLaunchParm lp, const T* A_d, const T* B_d, T* C_d, size_t numElements, size_t groupElements) {
template <typename T>
__global__ void testExternSharedKernel(hipLaunchParm lp, const T* A_d, const T* B_d, T* C_d,
size_t numElements, size_t groupElements) {
// declare dynamic shared memory
#if defined(__HIP_PLATFORM_HCC__)
HIP_DYNAMIC_SHARED(T, sdata)
#else
HIP_DYNAMIC_SHARED(__align__(sizeof(T)) unsigned char, my_sdata)
T *sdata = reinterpret_cast<T *>(my_sdata);
T* sdata = reinterpret_cast<T*>(my_sdata);
#endif
size_t gid = (blockIdx.x * blockDim.x + threadIdx.x);
@@ -50,25 +50,52 @@ __global__ void testExternSharedKernel(hipLaunchParm lp, const T* A_d, const T*
// prefix sum inside dynamic shared memory
if (groupElements >= 512) {
if (tid >= 256) { sdata[tid] += sdata[tid - 256]; } __syncthreads();
if (tid >= 256) {
sdata[tid] += sdata[tid - 256];
}
__syncthreads();
}
if (groupElements >= 256) {
if (tid >= 128) { sdata[tid] += sdata[tid - 128]; } __syncthreads();
if (tid >= 128) {
sdata[tid] += sdata[tid - 128];
}
__syncthreads();
}
if (groupElements >= 128) {
if (tid >= 64) { sdata[tid] += sdata[tid - 64]; } __syncthreads();
if (tid >= 64) {
sdata[tid] += sdata[tid - 64];
}
__syncthreads();
}
if (groupElements >= 64) { sdata[tid] += sdata[tid - 32]; } __syncthreads();
if (groupElements >= 32) { sdata[tid] += sdata[tid - 16]; } __syncthreads();
if (groupElements >= 16) { sdata[tid] += sdata[tid - 8]; } __syncthreads();
if (groupElements >= 8) { sdata[tid] += sdata[tid - 4]; } __syncthreads();
if (groupElements >= 4) { sdata[tid] += sdata[tid - 2]; } __syncthreads();
if (groupElements >= 2) { sdata[tid] += sdata[tid - 1]; } __syncthreads();
if (groupElements >= 64) {
sdata[tid] += sdata[tid - 32];
}
__syncthreads();
if (groupElements >= 32) {
sdata[tid] += sdata[tid - 16];
}
__syncthreads();
if (groupElements >= 16) {
sdata[tid] += sdata[tid - 8];
}
__syncthreads();
if (groupElements >= 8) {
sdata[tid] += sdata[tid - 4];
}
__syncthreads();
if (groupElements >= 4) {
sdata[tid] += sdata[tid - 2];
}
__syncthreads();
if (groupElements >= 2) {
sdata[tid] += sdata[tid - 1];
}
__syncthreads();
C_d[gid] = A_d[gid] + B_d[gid] + sdata[tid % groupElements];
}
template<typename T>
template <typename T>
void testExternShared(size_t N, size_t groupElements) {
size_t Nbytes = N * sizeof(T);
@@ -78,7 +105,7 @@ void testExternShared(size_t N, size_t groupElements) {
HipTest::initArrays(&A_d, &B_d, &C_d, &A_h, &B_h, &C_h, N, false);
unsigned blocks = HipTest::setNumBlocks(blocksPerCU, threadsPerBlock, N);
//printf("blocksPerCU: %d\nthreadsPerBlock: %d\nN: %zu\n", blocksPerCU, threadsPerBlock, N);
// printf("blocksPerCU: %d\nthreadsPerBlock: %d\nN: %zu\n", blocksPerCU, threadsPerBlock, N);
HIPCHECK(hipMemcpy(A_d, A_h, Nbytes, hipMemcpyHostToDevice));
HIPCHECK(hipMemcpy(B_d, B_h, Nbytes, hipMemcpyHostToDevice));
@@ -87,7 +114,8 @@ void testExternShared(size_t N, size_t groupElements) {
size_t groupMemBytes = groupElements * sizeof(T);
// launch kernel with dynamic shared memory
hipLaunchKernel(HIP_KERNEL_NAME(testExternSharedKernel<T>), dim3(blocks), dim3(threadsPerBlock), groupMemBytes, 0, A_d, B_d, C_d, N, groupElements);
hipLaunchKernel(HIP_KERNEL_NAME(testExternSharedKernel<T>), dim3(blocks), dim3(threadsPerBlock),
groupMemBytes, 0, A_d, B_d, C_d, N, groupElements);
HIPCHECK(hipDeviceSynchronize());
@@ -99,25 +127,25 @@ void testExternShared(size_t N, size_t groupElements) {
T sumFromSharedMemory = static_cast<T>(tid * (tid + 1) / 2);
T expected = A_h[i] + B_h[i] + sumFromSharedMemory;
if (C_h[i] != expected) {
std::cout << std::fixed << std::setprecision(32);
std::cout << "At " << i << std::endl;
std::cout << " Computed:" << C_h[i] << std::endl;
std::cout << " Expected:" << expected << std::endl;
std::cout << sumFromSharedMemory << std::endl;
std::cout << A_h[i] << std::endl;
std::cout << B_h[i] << std::endl;
std::cout << std::fixed << std::setprecision(32);
std::cout << "At " << i << std::endl;
std::cout << " Computed:" << C_h[i] << std::endl;
std::cout << " Expected:" << expected << std::endl;
std::cout << sumFromSharedMemory << std::endl;
std::cout << A_h[i] << std::endl;
std::cout << B_h[i] << std::endl;
failed("Failed at index:%zu\n", i);
failed("Failed at index:%zu\n", i);
}
}
HipTest::freeArrays(A_d, B_d, C_d, A_h, B_h, C_h, false);
}
int main(int argc, char *argv[]) {
int main(int argc, char* argv[]) {
HipTest::parseStandardArguments(argc, argv, true);
//printf("info: set device to %d\n", p_gpuDevice);
// printf("info: set device to %d\n", p_gpuDevice);
HIPCHECK(hipSetDevice(p_gpuDevice));
testExternShared<float>(1024, 4);
+28 -28
Dosyayı Görüntüle
@@ -26,37 +26,37 @@ THE SOFTWARE.
* HIT_END
*/
#include "hip/hip_runtime.h"
#include "test_common.h"
#include "hip/hip_runtime.h"
#include "test_common.h"
#define LEN 16*1024
#define SIZE LEN*4
#define LEN 16 * 1024
#define SIZE LEN * 4
__global__ void vectorAdd(hipLaunchParm lp, float *Ad, float *Bd) {
HIP_DYNAMIC_SHARED(float, sBd);
int tx = threadIdx.x;
for(int i=0;i<LEN/64;i++) {
sBd[tx + i * 64] = Ad[tx + i * 64] + 1.0f;
Bd[tx + i * 64] = sBd[tx + i * 64];
}
__global__ void vectorAdd(hipLaunchParm lp, float* Ad, float* Bd) {
HIP_DYNAMIC_SHARED(float, sBd);
int tx = threadIdx.x;
for (int i = 0; i < LEN / 64; i++) {
sBd[tx + i * 64] = Ad[tx + i * 64] + 1.0f;
Bd[tx + i * 64] = sBd[tx + i * 64];
}
}
int main() {
float *A, *B, *Ad, *Bd;
A = new float[LEN];
B = new float[LEN];
for(int i=0;i<LEN;i++) {
A[i] = 1.0f;
B[i] = 1.0f;
}
hipMalloc(&Ad, SIZE);
hipMalloc(&Bd, SIZE);
hipMemcpy(Ad, A, SIZE, hipMemcpyHostToDevice);
hipMemcpy(Bd, B, SIZE, hipMemcpyHostToDevice);
hipLaunchKernel(vectorAdd, dim3(1,1,1), dim3(64,1,1), SIZE, 0, Ad, Bd);
hipMemcpy(B, Bd, SIZE, hipMemcpyDeviceToHost);
for(int i=0;i<LEN;i++) {
assert(B[i] > 1.0f && B[i] < 3.0f);
}
passed();
float *A, *B, *Ad, *Bd;
A = new float[LEN];
B = new float[LEN];
for (int i = 0; i < LEN; i++) {
A[i] = 1.0f;
B[i] = 1.0f;
}
hipMalloc(&Ad, SIZE);
hipMalloc(&Bd, SIZE);
hipMemcpy(Ad, A, SIZE, hipMemcpyHostToDevice);
hipMemcpy(Bd, B, SIZE, hipMemcpyHostToDevice);
hipLaunchKernel(vectorAdd, dim3(1, 1, 1), dim3(64, 1, 1), SIZE, 0, Ad, Bd);
hipMemcpy(B, Bd, SIZE, hipMemcpyDeviceToHost);
for (int i = 0; i < LEN; i++) {
assert(B[i] > 1.0f && B[i] < 3.0f);
}
passed();
}
+6 -6
Dosyayı Görüntüle
@@ -23,12 +23,12 @@ THE SOFTWARE.
* HIT_END
*/
#include"test_common.h"
#include "test_common.h"
__global__ void Empty(hipLaunchParm lp, int param){}
__global__ void Empty(hipLaunchParm lp, int param) {}
int main(){
hipLaunchKernel(HIP_KERNEL_NAME(Empty), dim3(1), dim3(1), 0, 0, 0);
hipDeviceSynchronize();
passed();
int main() {
hipLaunchKernel(HIP_KERNEL_NAME(Empty), dim3(1), dim3(1), 0, 0, 0);
hipDeviceSynchronize();
passed();
}
+13 -27
Dosyayı Görüntüle
@@ -31,65 +31,51 @@ THE SOFTWARE.
#include "test_common.h"
// __device__ maps to __attribute__((hc))
__device__ int foo(int i)
{
return i+1;
}
__device__ int foo(int i) { return i + 1; }
//---
//Syntax we would like to support with GRID_LAUNCH enabled:
// Syntax we would like to support with GRID_LAUNCH enabled:
template <typename T>
__global__ void
vectorADD2( hipLaunchParm lp,
T *A_d,
T *B_d,
T *C_d,
size_t N)
{
__global__ void vectorADD2(hipLaunchParm lp, T* A_d, T* B_d, T* C_d, size_t N) {
size_t offset = (blockIdx.x * blockDim.x + threadIdx.x);
size_t stride = blockDim.x * gridDim.x ;
size_t stride = blockDim.x * gridDim.x;
for (size_t i=offset; i<N; i+=stride) {
for (size_t i = offset; i < N; i += stride) {
double foo = __hiloint2double(A_d[i], B_d[i]);
C_d[i] = __double2loint(foo) + __double2hiint(foo);//A_d[i] + B_d[i] ;
C_d[i] = __double2loint(foo) + __double2hiint(foo); // A_d[i] + B_d[i] ;
}
}
int test_gl2(size_t N) {
size_t Nbytes = N*sizeof(int);
size_t Nbytes = N * sizeof(int);
int *A_d, *B_d, *C_d;
int *A_h, *B_h, *C_h;
HipTest::initArrays (&A_d, &B_d, &C_d, &A_h, &B_h, &C_h, N);
HipTest::initArrays(&A_d, &B_d, &C_d, &A_h, &B_h, &C_h, N);
unsigned blocks = HipTest::setNumBlocks(blocksPerCU, threadsPerBlock, N);
// Full vadd in one large chunk, to get things started:
HIPCHECK ( hipMemcpy(A_d, A_h, Nbytes, hipMemcpyHostToDevice));
HIPCHECK ( hipMemcpy(B_d, B_h, Nbytes, hipMemcpyHostToDevice));
HIPCHECK(hipMemcpy(A_d, A_h, Nbytes, hipMemcpyHostToDevice));
HIPCHECK(hipMemcpy(B_d, B_h, Nbytes, hipMemcpyHostToDevice));
hipLaunchKernel(vectorADD2, dim3(blocks), dim3(threadsPerBlock), 0, 0, A_d, B_d, C_d, N);
HIPCHECK ( hipMemcpy(C_h, C_d, Nbytes, hipMemcpyDeviceToHost));
HIPCHECK(hipMemcpy(C_h, C_d, Nbytes, hipMemcpyDeviceToHost));
HIPCHECK (hipDeviceSynchronize());
HIPCHECK(hipDeviceSynchronize());
HipTest::checkVectorADD(A_h, B_h, C_h, N);
return 0;
}
int main(int argc, char *argv[])
{
int main(int argc, char* argv[]) {
HipTest::parseStandardArguments(argc, argv, true);
test_gl2(N);
+23 -35
Dosyayı Görüntüle
@@ -45,50 +45,38 @@ __constant__ int constantVar1;
__constant__ __device__ int constantVar2;
// Test HOST space:
__host__ void foo() {
printf ("foo!\n");
}
__host__ void foo() { printf("foo!\n"); }
__device__ __noinline__ int sum1_noinline(int a) { return a+1;};
__device__ __forceinline__ int sum1_forceinline(int a) { return a+1;};
__device__ __noinline__ int sum1_noinline(int a) { return a + 1; };
__device__ __forceinline__ int sum1_forceinline(int a) { return a + 1; };
__device__ __host__ float PlusOne(float x)
{
return x + 1.0;
}
__device__ __host__ float PlusOne(float x) { return x + 1.0; }
__global__ void MyKernel (const hipLaunchParm lp, const float *a, const float *b, float *c, unsigned N)
{
//KERNELBEGIN;
__global__ void MyKernel(const hipLaunchParm lp, const float* a, const float* b, float* c,
unsigned N) {
// KERNELBEGIN;
unsigned gid = threadIdx.x;
if (gid < N) {
c[gid] = a[gid] + PlusOne(b[gid]);
}
//KERNELEND;
// KERNELEND;
}
void callMyKernel()
{
void callMyKernel() {
float *a, *b, *c;
const unsigned blockSize = 256;
unsigned N = blockSize;
hipLaunchKernel(MyKernel, dim3(N/blockSize), dim3(blockSize), 0, 0, a,b,c,N);
hipLaunchKernel(MyKernel, dim3(N / blockSize), dim3(blockSize), 0, 0, a, b, c, N);
}
template <typename T>
__global__ void
vectorADD(const hipLaunchParm lp,
T __restrict__ *A_d,
T *B_d,
T *C_d,
size_t N)
{
__global__ void vectorADD(const hipLaunchParm lp, T __restrict__* A_d, T* B_d, T* C_d, size_t N) {
// KERNELBEGIN;
#ifdef NOT_YET
int a = __shfl_up(x, 1);
@@ -102,31 +90,31 @@ vectorADD(const hipLaunchParm lp,
#ifdef __HCC__
int b = threadIdx.x;
int c;
int b = threadIdx.x;
int c;
// TODO - move to HIP atomics when ready.
concurrency :: atomic_fetch_add(&c, b);
//Concurrency::atomic_add_unsigned (&x, a);
// TODO - move to HIP atomics when ready.
concurrency ::atomic_fetch_add(&c, b);
// Concurrency::atomic_add_unsigned (&x, a);
//concurrency ::atomic_add_ (x, a);
// concurrency ::atomic_add_ (x, a);
#endif
__syncthreads();
size_t offset = (blockIdx.x * blockDim.x + threadIdx.x);
size_t stride = blockDim.x * gridDim.x ;
size_t stride = blockDim.x * gridDim.x;
for (size_t i=offset; i<N; i+=stride) {
C_d[i] = A_d[i] + B_d[i];
}
for (size_t i = offset; i < N; i += stride) {
C_d[i] = A_d[i] + B_d[i];
}
// KERNELEND;
// KERNELEND;
}
int main() {
printf ("Hello world\n");
printf("Hello world\n");
passed();
}
+34 -36
Dosyayı Görüntüle
@@ -24,48 +24,46 @@ THE SOFTWARE.
*/
#include "hip/hip_runtime.h"
#include"test_common.h"
#include "test_common.h"
#include "hip/hip_runtime_api.h"
#include<iostream>
#include <iostream>
__global__ void vAdd(hipLaunchParm lp, float *a){}
__global__ void vAdd(hipLaunchParm lp, float* a) {}
//---
//Some wrapper macro for testing:
// Some wrapper macro for testing:
#define WRAP(...) __VA_ARGS__
#include <sys/time.h>
#define GPU_PRINT_TIME(cmd, elapsed, quiet) do {\
struct timeval start, stop;\
float elapsed;\
gettimeofday(&start, NULL);\
hipDeviceSynchronize();\
cmd;\
hipDeviceSynchronize();\
gettimeofday(&stop, NULL);\
} while(0);
#define GPU_PRINT_TIME(cmd, elapsed, quiet) \
do { \
struct timeval start, stop; \
float elapsed; \
gettimeofday(&start, NULL); \
hipDeviceSynchronize(); \
cmd; \
hipDeviceSynchronize(); \
gettimeofday(&stop, NULL); \
} while (0);
#define MY_LAUNCH(command, doTrace, msg) \
{\
if (doTrace) printf ("TRACE: %s %s\n", msg, #command); \
command;\
}
#define MY_LAUNCH(command, doTrace, msg) \
{ \
if (doTrace) printf("TRACE: %s %s\n", msg, #command); \
command; \
}
#define MY_LAUNCH_WITH_PAREN(command, doTrace, msg) \
{\
if (doTrace) printf ("TRACE: %s %s\n", msg, #command); \
(command);\
}
#define MY_LAUNCH_WITH_PAREN(command, doTrace, msg) \
{ \
if (doTrace) printf("TRACE: %s %s\n", msg, #command); \
(command); \
}
int main()
{
float *Ad;
int main() {
float* Ad;
hipMalloc((void**)&Ad, 1024);
// Test the different hipLaunchParm options:
@@ -76,23 +74,23 @@ int main()
// Test case with hipLaunchKernel inside another macro:
float e0;
GPU_PRINT_TIME (hipLaunchKernel(vAdd, dim3(1024), dim3(1), 0, 0, Ad), e0, j);
GPU_PRINT_TIME (WRAP(hipLaunchKernel(vAdd, dim3(1024), dim3(1), 0, 0, Ad)), e0, j);
GPU_PRINT_TIME(hipLaunchKernel(vAdd, dim3(1024), dim3(1), 0, 0, Ad), e0, j);
GPU_PRINT_TIME(WRAP(hipLaunchKernel(vAdd, dim3(1024), dim3(1), 0, 0, Ad)), e0, j);
#ifdef EXTRA_PARENS_1
// Don't wrap hipLaunchKernel in extra set of parens:
GPU_PRINT_TIME ((hipLaunchKernel(vAdd, dim3(1024), dim3(1), 0, 0, Ad)), e0, j);
GPU_PRINT_TIME((hipLaunchKernel(vAdd, dim3(1024), dim3(1), 0, 0, Ad)), e0, j);
#endif
MY_LAUNCH (hipLaunchKernel(vAdd, dim3(1024), dim3(1), 0, 0, Ad), true, "firstCall");
MY_LAUNCH(hipLaunchKernel(vAdd, dim3(1024), dim3(1), 0, 0, Ad), true, "firstCall");
float *A;
float* A;
float e1;
MY_LAUNCH_WITH_PAREN (hipMalloc(&A, 100), true, "launch2");
MY_LAUNCH_WITH_PAREN(hipMalloc(&A, 100), true, "launch2");
#ifdef EXTRA_PARENS_2
//MY_LAUNCH_WITH_PAREN wraps cmd in () which can cause issues.
MY_LAUNCH_WITH_PAREN (hipLaunchKernel(vAdd, dim3(1024), dim3(1), 0, 0, Ad), true, "firstCall");
// MY_LAUNCH_WITH_PAREN wraps cmd in () which can cause issues.
MY_LAUNCH_WITH_PAREN(hipLaunchKernel(vAdd, dim3(1024), dim3(1), 0, 0, Ad), true, "firstCall");
#endif
passed();
+7 -9
Dosyayı Görüntüle
@@ -18,21 +18,19 @@ THE SOFTWARE.
*/
/* HIT_START
* BUILD: %t %s ../test_common.cpp
* BUILD: %t %s ../test_common.cpp
* RUN: %t
* HIT_END
*/
#define HIP_ENABLE_PRINTF
#include"test_common.h"
#include "test_common.h"
__global__ void run_printf(hipLaunchParm lp){
printf("Hello World\n");
}
__global__ void run_printf(hipLaunchParm lp) { printf("Hello World\n"); }
int main(){
hipLaunchKernel(HIP_KERNEL_NAME(run_printf), dim3(1), dim3(1), 0, 0);
hipDeviceSynchronize();
passed();
int main() {
hipLaunchKernel(HIP_KERNEL_NAME(run_printf), dim3(1), dim3(1), 0, 0);
hipDeviceSynchronize();
passed();
}
+10 -15
Dosyayı Görüntüle
@@ -23,44 +23,39 @@ THE SOFTWARE.
* HIT_END
*/
#include<hip/hip_runtime.h>
#include<hip/hip_runtime_api.h>
#include<iostream>
#include <hip/hip_runtime.h>
#include <hip/hip_runtime_api.h>
#include <iostream>
#include "test_common.h"
#define HIP_ASSERT(status) \
assert(status == hipSuccess)
#define HIP_ASSERT(status) assert(status == hipSuccess)
#define LEN 512
#define SIZE 2048
__constant__ int Value[LEN];
__global__ void Get(hipLaunchParm lp, int *Ad)
{
__global__ void Get(hipLaunchParm lp, int* Ad) {
int tid = threadIdx.x + blockIdx.x * blockDim.x;
Ad[tid] = Value[tid];
}
int main()
{
int main() {
int *A, *B, *Ad;
A = new int[LEN];
B = new int[LEN];
for(unsigned i=0;i<LEN;i++)
{
A[i] = -1*i;
for (unsigned i = 0; i < LEN; i++) {
A[i] = -1 * i;
B[i] = 0;
}
HIP_ASSERT(hipMalloc((void**)&Ad, SIZE));
HIP_ASSERT(hipMemcpyToSymbol(HIP_SYMBOL(Value), A, SIZE, 0, hipMemcpyHostToDevice));
hipLaunchKernel(Get, dim3(1,1,1), dim3(LEN,1,1), 0, 0, Ad);
hipLaunchKernel(Get, dim3(1, 1, 1), dim3(LEN, 1, 1), 0, 0, Ad);
HIP_ASSERT(hipMemcpy(B, Ad, SIZE, hipMemcpyDeviceToHost));
for(unsigned i=0;i<LEN;i++)
{
for (unsigned i = 0; i < LEN; i++) {
assert(A[i] == B[i]);
}
passed();
+13 -14
Dosyayı Görüntüle
@@ -23,45 +23,44 @@ THE SOFTWARE.
* HIT_END
*/
#include<hip/hip_runtime.h>
#include<hip/hip_runtime_api.h>
#include<iostream>
#include <hip/hip_runtime.h>
#include <hip/hip_runtime_api.h>
#include <iostream>
#define HIP_ASSERT(status) assert(hipSuccess == status);
#define NUM 1024
#define NUM 1024
#define SIZE NUM * 8
__global__ void Alloc(hipLaunchParm lp, uint64_t *Ptr) {
__global__ void Alloc(hipLaunchParm lp, uint64_t* Ptr) {
int tid = threadIdx.x + blockIdx.x * blockDim.x;
Ptr[tid] = (uint64_t)malloc(128);
}
__global__ void Free(hipLaunchParm lp, uint64_t *Ptr) {
__global__ void Free(hipLaunchParm lp, uint64_t* Ptr) {
int tid = threadIdx.x + blockIdx.x * blockDim.x;
free((void*)Ptr[tid]);
}
int main()
{
int main() {
uint64_t *hPtr, *dPtr;
hPtr = new uint64_t[NUM];
for(uint32_t i=0;i<NUM;i++) {
for (uint32_t i = 0; i < NUM; i++) {
hPtr[i] = 1;
}
int devCnt;
hipGetDeviceCount(&devCnt);
for(uint32_t i=0;i<devCnt;i++){
for (uint32_t i = 0; i < devCnt; i++) {
HIP_ASSERT(hipSetDevice(i));
HIP_ASSERT(hipMalloc((void**)&dPtr, SIZE));
HIP_ASSERT(hipMemcpy(dPtr, hPtr, SIZE, hipMemcpyHostToDevice));
hipLaunchKernel(Alloc, dim3(1,1,1), dim3(NUM,1,1), 0, 0, dPtr);
hipLaunchKernel(Alloc, dim3(1, 1, 1), dim3(NUM, 1, 1), 0, 0, dPtr);
HIP_ASSERT(hipMemcpy(hPtr, dPtr, SIZE, hipMemcpyDeviceToHost));
assert(hPtr[0] != 0);
hipLaunchKernel(Free, dim3(1,1,1), dim3(NUM,1,1), 0, 0, dPtr);
hipLaunchKernel(Free, dim3(1, 1, 1), dim3(NUM, 1, 1), 0, 0, dPtr);
HIP_ASSERT(hipFree(dPtr));
for(uint32_t i=1;i<NUM;i++) {
assert(hPtr[i] == hPtr[i-1] + 4096);
for (uint32_t i = 1; i < NUM; i++) {
assert(hPtr[i] == hPtr[i - 1] + 4096);
}
}
}
+72 -72
Dosyayı Görüntüle
@@ -23,73 +23,73 @@ THE SOFTWARE.
* HIT_END
*/
#include<hip/hip_runtime_api.h>
#include<hip/hip_runtime.h>
#include<iostream>
#include"test_common.h"
#include <hip/hip_runtime_api.h>
#include <hip/hip_runtime.h>
#include <iostream>
#include "test_common.h"
#define LEN8 8 * 4
#define LEN9 9 * 4
#define LEN8 8 * 4
#define LEN9 9 * 4
#define LEN10 10 * 4
#define LEN11 11 * 4
#define LEN12 12 * 4
__global__ void MemCpy8(hipLaunchParm lp, uint8_t *In, uint8_t *Out) {
int tid = threadIdx.x + blockIdx.x * blockDim.x;
memcpy(Out + tid*8, In + tid*8, 8);
__global__ void MemCpy8(hipLaunchParm lp, uint8_t* In, uint8_t* Out) {
int tid = threadIdx.x + blockIdx.x * blockDim.x;
memcpy(Out + tid * 8, In + tid * 8, 8);
}
__global__ void MemCpy9(hipLaunchParm lp, uint8_t *In, uint8_t *Out) {
int tid = threadIdx.x + blockIdx.x * blockDim.x;
memcpy(Out + tid*9, In + tid*9, 9);
__global__ void MemCpy9(hipLaunchParm lp, uint8_t* In, uint8_t* Out) {
int tid = threadIdx.x + blockIdx.x * blockDim.x;
memcpy(Out + tid * 9, In + tid * 9, 9);
}
__global__ void MemCpy10(hipLaunchParm lp, uint8_t *In, uint8_t *Out) {
int tid = threadIdx.x + blockIdx.x * blockDim.x;
memcpy(Out + tid*10, In + tid*10, 10);
__global__ void MemCpy10(hipLaunchParm lp, uint8_t* In, uint8_t* Out) {
int tid = threadIdx.x + blockIdx.x * blockDim.x;
memcpy(Out + tid * 10, In + tid * 10, 10);
}
__global__ void MemCpy11(hipLaunchParm lp, uint8_t *In, uint8_t *Out) {
int tid = threadIdx.x + blockIdx.x * blockDim.x;
memcpy(Out + tid*11, In + tid*11, 11);
__global__ void MemCpy11(hipLaunchParm lp, uint8_t* In, uint8_t* Out) {
int tid = threadIdx.x + blockIdx.x * blockDim.x;
memcpy(Out + tid * 11, In + tid * 11, 11);
}
__global__ void MemCpy12(hipLaunchParm lp, uint8_t *In, uint8_t *Out) {
int tid = threadIdx.x + blockIdx.x * blockDim.x;
memcpy(Out + tid*12, In + tid*12, 12);
__global__ void MemCpy12(hipLaunchParm lp, uint8_t* In, uint8_t* Out) {
int tid = threadIdx.x + blockIdx.x * blockDim.x;
memcpy(Out + tid * 12, In + tid * 12, 12);
}
__global__ void MemSet8(hipLaunchParm lp, uint8_t *In) {
int tid = threadIdx.x + blockIdx.x * blockDim.x;
memset(In + tid*8, 1, 8);
__global__ void MemSet8(hipLaunchParm lp, uint8_t* In) {
int tid = threadIdx.x + blockIdx.x * blockDim.x;
memset(In + tid * 8, 1, 8);
}
__global__ void MemSet9(hipLaunchParm lp, uint8_t *In) {
int tid = threadIdx.x + blockIdx.x * blockDim.x;
memset(In + tid*9, 1, 9);
__global__ void MemSet9(hipLaunchParm lp, uint8_t* In) {
int tid = threadIdx.x + blockIdx.x * blockDim.x;
memset(In + tid * 9, 1, 9);
}
__global__ void MemSet10(hipLaunchParm lp, uint8_t *In) {
int tid = threadIdx.x + blockIdx.x * blockDim.x;
memset(In + tid*10, 1, 10);
__global__ void MemSet10(hipLaunchParm lp, uint8_t* In) {
int tid = threadIdx.x + blockIdx.x * blockDim.x;
memset(In + tid * 10, 1, 10);
}
__global__ void MemSet11(hipLaunchParm lp, uint8_t *In) {
int tid = threadIdx.x + blockIdx.x * blockDim.x;
memset(In + tid*11, 1, 11);
__global__ void MemSet11(hipLaunchParm lp, uint8_t* In) {
int tid = threadIdx.x + blockIdx.x * blockDim.x;
memset(In + tid * 11, 1, 11);
}
__global__ void MemSet12(hipLaunchParm lp, uint8_t *In) {
int tid = threadIdx.x + blockIdx.x * blockDim.x;
memset(In + tid*12, 1, 12);
__global__ void MemSet12(hipLaunchParm lp, uint8_t* In) {
int tid = threadIdx.x + blockIdx.x * blockDim.x;
memset(In + tid * 12, 1, 12);
}
int main(){
int main() {
uint8_t *A, *Ad, *B, *Bd, *C, *Cd;
A = new uint8_t[LEN8];
B = new uint8_t[LEN8];
C = new uint8_t[LEN8];
for(uint32_t i=0;i<LEN8;i++) {
for (uint32_t i = 0; i < LEN8; i++) {
A[i] = i;
B[i] = 0;
C[i] = 0;
@@ -98,18 +98,18 @@ int main(){
hipMalloc((void**)&Bd, LEN8);
hipMalloc((void**)&Cd, LEN8);
hipMemcpy(Ad, A, LEN8, hipMemcpyHostToDevice);
hipLaunchKernel(MemCpy8, dim3(2,1,1), dim3(2,1,1), 0, 0, Ad, Bd);
hipLaunchKernel(MemSet8, dim3(2,1,1), dim3(2,1,1), 0, 0, Cd);
hipLaunchKernel(MemCpy8, dim3(2, 1, 1), dim3(2, 1, 1), 0, 0, Ad, Bd);
hipLaunchKernel(MemSet8, dim3(2, 1, 1), dim3(2, 1, 1), 0, 0, Cd);
hipMemcpy(B, Bd, LEN8, hipMemcpyDeviceToHost);
hipMemcpy(C, Cd, LEN8, hipMemcpyDeviceToHost);
for(uint32_t i=0;i<LEN8;i++) {
for (uint32_t i = 0; i < LEN8; i++) {
assert(A[i] == B[i]);
assert(C[i] == 1);
}
delete [] A;
delete [] B;
delete [] C;
delete[] A;
delete[] B;
delete[] C;
hipFree(Ad);
hipFree(Bd);
hipFree(Cd);
@@ -117,7 +117,7 @@ int main(){
A = new uint8_t[LEN9];
B = new uint8_t[LEN9];
C = new uint8_t[LEN9];
for(uint32_t i=0;i<LEN9;i++) {
for (uint32_t i = 0; i < LEN9; i++) {
A[i] = i;
B[i] = 0;
C[i] = 0;
@@ -126,18 +126,18 @@ int main(){
hipMalloc((void**)&Bd, LEN9);
hipMalloc((void**)&Cd, LEN9);
hipMemcpy(Ad, A, LEN9, hipMemcpyHostToDevice);
hipLaunchKernel(MemCpy9, dim3(2,1,1), dim3(2,1,1), 0, 0, Ad, Bd);
hipLaunchKernel(MemSet9, dim3(2,1,1), dim3(2,1,1), 0, 0, Cd);
hipLaunchKernel(MemCpy9, dim3(2, 1, 1), dim3(2, 1, 1), 0, 0, Ad, Bd);
hipLaunchKernel(MemSet9, dim3(2, 1, 1), dim3(2, 1, 1), 0, 0, Cd);
hipMemcpy(B, Bd, LEN9, hipMemcpyDeviceToHost);
hipMemcpy(C, Cd, LEN9, hipMemcpyDeviceToHost);
for(uint32_t i=0;i<LEN9;i++) {
for (uint32_t i = 0; i < LEN9; i++) {
assert(A[i] == B[i]);
assert(C[i] == 1);
}
delete [] A;
delete [] B;
delete [] C;
delete[] A;
delete[] B;
delete[] C;
hipFree(Ad);
hipFree(Bd);
hipFree(Cd);
@@ -145,7 +145,7 @@ int main(){
A = new uint8_t[LEN10];
B = new uint8_t[LEN10];
C = new uint8_t[LEN10];
for(uint32_t i=0;i<LEN10;i++) {
for (uint32_t i = 0; i < LEN10; i++) {
A[i] = i;
B[i] = 0;
C[i] = 0;
@@ -154,18 +154,18 @@ int main(){
hipMalloc((void**)&Bd, LEN10);
hipMalloc((void**)&Cd, LEN10);
hipMemcpy(Ad, A, LEN10, hipMemcpyHostToDevice);
hipLaunchKernel(MemCpy10, dim3(2,1,1), dim3(2,1,1), 0, 0, Ad, Bd);
hipLaunchKernel(MemSet10, dim3(2,1,1), dim3(2,1,1), 0, 0, Cd);
hipLaunchKernel(MemCpy10, dim3(2, 1, 1), dim3(2, 1, 1), 0, 0, Ad, Bd);
hipLaunchKernel(MemSet10, dim3(2, 1, 1), dim3(2, 1, 1), 0, 0, Cd);
hipMemcpy(B, Bd, LEN10, hipMemcpyDeviceToHost);
hipMemcpy(C, Cd, LEN10, hipMemcpyDeviceToHost);
for(uint32_t i=0;i<LEN10;i++) {
for (uint32_t i = 0; i < LEN10; i++) {
assert(A[i] == B[i]);
assert(C[i] == 1);
}
delete [] A;
delete [] B;
delete [] C;
delete[] A;
delete[] B;
delete[] C;
hipFree(Ad);
hipFree(Bd);
hipFree(Cd);
@@ -173,7 +173,7 @@ int main(){
A = new uint8_t[LEN11];
B = new uint8_t[LEN11];
C = new uint8_t[LEN11];
for(uint32_t i=0;i<LEN11;i++) {
for (uint32_t i = 0; i < LEN11; i++) {
A[i] = i;
B[i] = 0;
C[i] = 0;
@@ -182,18 +182,18 @@ int main(){
hipMalloc((void**)&Bd, LEN11);
hipMalloc((void**)&Cd, LEN11);
hipMemcpy(Ad, A, LEN11, hipMemcpyHostToDevice);
hipLaunchKernel(MemCpy11, dim3(2,1,1), dim3(2,1,1), 0, 0, Ad, Bd);
hipLaunchKernel(MemSet11, dim3(2,1,1), dim3(2,1,1), 0, 0, Cd);
hipLaunchKernel(MemCpy11, dim3(2, 1, 1), dim3(2, 1, 1), 0, 0, Ad, Bd);
hipLaunchKernel(MemSet11, dim3(2, 1, 1), dim3(2, 1, 1), 0, 0, Cd);
hipMemcpy(B, Bd, LEN11, hipMemcpyDeviceToHost);
hipMemcpy(C, Cd, LEN11, hipMemcpyDeviceToHost);
for(uint32_t i=0;i<LEN11;i++) {
for (uint32_t i = 0; i < LEN11; i++) {
assert(A[i] == B[i]);
assert(C[i] == 1);
}
delete [] A;
delete [] B;
delete [] C;
delete[] A;
delete[] B;
delete[] C;
hipFree(Ad);
hipFree(Bd);
hipFree(Cd);
@@ -201,7 +201,7 @@ int main(){
A = new uint8_t[LEN12];
B = new uint8_t[LEN12];
C = new uint8_t[LEN12];
for(uint32_t i=0;i<LEN12;i++) {
for (uint32_t i = 0; i < LEN12; i++) {
A[i] = i;
B[i] = 0;
C[i] = 0;
@@ -210,18 +210,18 @@ int main(){
hipMalloc((void**)&Bd, LEN12);
hipMalloc((void**)&Cd, LEN12);
hipMemcpy(Ad, A, LEN12, hipMemcpyHostToDevice);
hipLaunchKernel(MemCpy12, dim3(2,1,1), dim3(2,1,1), 0, 0, Ad, Bd);
hipLaunchKernel(MemSet12, dim3(2,1,1), dim3(2,1,1), 0, 0, Cd);
hipLaunchKernel(MemCpy12, dim3(2, 1, 1), dim3(2, 1, 1), 0, 0, Ad, Bd);
hipLaunchKernel(MemSet12, dim3(2, 1, 1), dim3(2, 1, 1), 0, 0, Cd);
hipMemcpy(B, Bd, LEN12, hipMemcpyDeviceToHost);
hipMemcpy(C, Cd, LEN12, hipMemcpyDeviceToHost);
for(uint32_t i=0;i<LEN12;i++) {
for (uint32_t i = 0; i < LEN12; i++) {
assert(A[i] == B[i]);
assert(C[i] == 1);
}
delete [] A;
delete [] B;
delete [] C;
delete[] A;
delete[] B;
delete[] C;
hipFree(Ad);
hipFree(Bd);
hipFree(Cd);
+33 -45
Dosyayı Görüntüle
@@ -1,19 +1,19 @@
/* Copyright (c) 2015-2016 Advanced Micro Devices, Inc. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
associated documentation files (the "Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the
following conditions:
associated documentation files (the "Software"), to deal in the Software without restriction,
including without limitation the rights to use, copy, modify, merge, publish, distribute,
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial
portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO
EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/* HIT_START
* BUILD: %t %s
@@ -22,46 +22,37 @@ THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
*/
#include<iostream>
#include <iostream>
// hip header file
#include "hip/hip_runtime.h"
#define NUM 1024
#define NUM 1024
#define THREADS_PER_BLOCK_X 4
#define THREADS_PER_BLOCK_X 4
// Device (Kernel) function, it must be void
// hipLaunchParm provides the execution configuration
__global__ void vadd_asm(hipLaunchParm lp,
float *out,
float *in)
{
__global__ void vadd_asm(hipLaunchParm lp, float* out, float* in) {
int i = blockDim.x * blockIdx.x + threadIdx.x;
#ifdef __HIP_PLATFORM_NVCC__
asm volatile("add.f32 %0,%1,%2;":"=f"(out[i]):"f"(in[i]),"f"(out[i]));
asm volatile("add.f32 %0,%1,%2;" : "=f"(out[i]) : "f"(in[i]), "f"(out[i]));
#endif
#ifdef __HIP_PLATFORM_HCC__
asm volatile ("v_add_f32_e32 %0, %1, %2" : "=v" (out[i]) : "v"(in[i]),"v" (out[i]));
asm volatile("v_add_f32_e32 %0, %1, %2" : "=v"(out[i]) : "v"(in[i]), "v"(out[i]));
#endif
}
// CPU implementation of Vector Result
void addCPUReference(
float * output,
float * input)
{
for(unsigned int j=0; j < NUM; j++)
{
output[j]= input[j] + output[j];
void addCPUReference(float* output, float* input) {
for (unsigned int j = 0; j < NUM; j++) {
output[j] = input[j] + output[j];
}
}
int main(){
int main() {
float* VectorA;
float* ResultVector;
float* VectorB;
@@ -78,8 +69,8 @@ int main(){
// initialize the input data
for (i = 0; i < NUM; i++) {
VectorA[i] = (float)i*10.0f;
VectorB[i] = (float)i*30.0f;
VectorA[i] = (float)i * 10.0f;
VectorB[i] = (float)i * 30.0f;
}
// allocate the memory on the device side
@@ -87,18 +78,15 @@ int main(){
hipMalloc((void**)&gpuResultVector, NUM * sizeof(float));
// Memory transfer from host to device
hipMemcpy(gpuVector, VectorA, NUM*sizeof(float), hipMemcpyHostToDevice);
hipMemcpy(gpuResultVector, VectorB, NUM*sizeof(float), hipMemcpyHostToDevice);
hipMemcpy(gpuVector, VectorA, NUM * sizeof(float), hipMemcpyHostToDevice);
hipMemcpy(gpuResultVector, VectorB, NUM * sizeof(float), hipMemcpyHostToDevice);
// Lauching kernel from host
hipLaunchKernel(vadd_asm,
dim3(NUM/THREADS_PER_BLOCK_X),
dim3(THREADS_PER_BLOCK_X),
0, 0,
gpuResultVector , gpuVector);
hipLaunchKernel(vadd_asm, dim3(NUM / THREADS_PER_BLOCK_X), dim3(THREADS_PER_BLOCK_X), 0, 0,
gpuResultVector, gpuVector);
// Memory transfer from device to host
hipMemcpy(ResultVector, gpuResultVector, NUM*sizeof(float), hipMemcpyDeviceToHost);
hipMemcpy(ResultVector, gpuResultVector, NUM * sizeof(float), hipMemcpyDeviceToHost);
// CPU Result computation
addCPUReference(VectorB, VectorA);
@@ -107,23 +95,23 @@ int main(){
errors = 0;
double eps = 1.0E-3;
for (i = 0; i < NUM; i++) {
if (std::abs(ResultVector[i] - VectorB[i]) > eps ) {
errors++;
if (std::abs(ResultVector[i] - VectorB[i]) > eps) {
errors++;
}
}
if (errors!=0) {
printf("FAILED: %d errors\n",errors);
if (errors != 0) {
printf("FAILED: %d errors\n", errors);
} else {
printf ("PASSED!\n");
printf("PASSED!\n");
}
//free the resources on device side
// free the resources on device side
hipFree(gpuVector);
hipFree(gpuResultVector);
hipDeviceReset();
//free the resources on host side
// free the resources on host side
free(VectorA);
free(ResultVector);
free(VectorB);
+24 -37
Dosyayı Görüntüle
@@ -20,40 +20,31 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#include<iostream>
#include <iostream>
// hip header file
#include "hip/hip_runtime.h"
#define NUM 1024
#define NUM 1024
#define THREADS_PER_BLOCK_X 4
#define THREADS_PER_BLOCK_X 4
// Device (Kernel) function, it must be void
// hipLaunchParm provides the execution configuration
__global__ void vmac_asm(hipLaunchParm lp,
float *out,
float *in)
{
__global__ void vmac_asm(hipLaunchParm lp, float* out, float* in) {
int i = blockDim.x * blockIdx.x + threadIdx.x;
asm volatile ("v_mac_f32_e32 %0, %2, %3" : "=v" (out[i]) : "0"(out[i]), "v" (a), "v" (in[i]));
asm volatile("v_mac_f32_e32 %0, %2, %3" : "=v"(out[i]) : "0"(out[i]), "v"(a), "v"(in[i]));
}
// CPU implementation of saxpy
void CPUReference(
float * output,
float * input)
{
for(unsigned int j=0; j < NUM; j++)
{
output[j]= a*input[j] + output[j];
void CPUReference(float* output, float* input) {
for (unsigned int j = 0; j < NUM; j++) {
output[j] = a * input[j] + output[j];
}
}
int main(){
int main() {
float* VectorA;
float* ResultVector;
float* VectorB;
@@ -61,8 +52,7 @@ int main(){
float* gpuVector;
float* gpuResultVector;
const float a = 10.0f
int i;
const float a = 10.0f int i;
int errors;
VectorA = (float*)malloc(NUM * sizeof(float));
@@ -71,8 +61,8 @@ int main(){
// initialize the input data
for (i = 0; i < NUM; i++) {
VectorA[i] = (float)i*10.0f;
VectorB[i] = (float)i*30.0f;
VectorA[i] = (float)i * 10.0f;
VectorB[i] = (float)i * 30.0f;
}
// allocate the memory on the device side
@@ -80,18 +70,15 @@ int main(){
hipMalloc((void**)&gpuResultVector, NUM * sizeof(float));
// Memory transfer from host to device
hipMemcpy(gpuVector, VectorA, NUM*sizeof(float), hipMemcpyHostToDevice);
hipMemcpy(gpuResultVector, VectorB, NUM*sizeof(float), hipMemcpyHostToDevice);
hipMemcpy(gpuVector, VectorA, NUM * sizeof(float), hipMemcpyHostToDevice);
hipMemcpy(gpuResultVector, VectorB, NUM * sizeof(float), hipMemcpyHostToDevice);
// Lauching kernel from host
hipLaunchKernel(vmac_asm,
dim3(NUM/THREADS_PER_BLOCK_X),
dim3(THREADS_PER_BLOCK_X),
0, 0,
gpuResultVector , gpuVector);
hipLaunchKernel(vmac_asm, dim3(NUM / THREADS_PER_BLOCK_X), dim3(THREADS_PER_BLOCK_X), 0, 0,
gpuResultVector, gpuVector);
// Memory transfer from device to host
hipMemcpy(ResultVector, gpuResultVector, NUM*sizeof(float), hipMemcpyDeviceToHost);
hipMemcpy(ResultVector, gpuResultVector, NUM * sizeof(float), hipMemcpyDeviceToHost);
// CPU Result computation
addCPUReference(VectorB, VectorA);
@@ -100,23 +87,23 @@ int main(){
errors = 0;
double eps = 1.0E-3;
for (i = 0; i < NUM; i++) {
if (std::abs(ResultVector[i] - VectorB[i]) > eps ) {
errors++;
if (std::abs(ResultVector[i] - VectorB[i]) > eps) {
errors++;
}
}
if (errors!=0) {
printf("FAILED: %d errors\n",errors);
if (errors != 0) {
printf("FAILED: %d errors\n", errors);
} else {
printf ("PASSED!\n");
printf("PASSED!\n");
}
//free the resources on device side
// free the resources on device side
hipFree(gpuVector);
hipFree(gpuResultVector);
hipDeviceReset();
//free the resources on host side
// free the resources on host side
free(VectorA);
free(ResultVector);
free(VectorB);
+30 -39
Dosyayı Görüntüle
@@ -28,11 +28,8 @@ THE SOFTWARE.
int p_blockSize = 256;
__global__
void
__launch_bounds__(256, 2)
myKern(hipLaunchParm lp, int *C, const int *A, int N, int xfactor)
{
__global__ void __launch_bounds__(256, 2)
myKern(hipLaunchParm lp, int* C, const int* A, int N, int xfactor) {
int tid = (blockIdx.x * blockDim.x + threadIdx.x);
if (tid < N) {
@@ -41,16 +38,15 @@ myKern(hipLaunchParm lp, int *C, const int *A, int N, int xfactor)
};
void parseMyArguments(int argc, char *argv[])
{
void parseMyArguments(int argc, char* argv[]) {
int more_argc = HipTest::parseStandardArguments(argc, argv, false);
// parse args for this test:
for (int i = 1; i < more_argc; i++) {
const char *arg = argv[i];
const char* arg = argv[i];
if (!strcmp(arg, "--blockSize")) {
if (++i >= argc || !HipTest::parseInt(argv[i], &p_blockSize)) {
failed("Bad peerDevice argument");
failed("Bad peerDevice argument");
}
} else {
failed("Bad argument '%s'", arg);
@@ -59,63 +55,58 @@ void parseMyArguments(int argc, char *argv[])
};
int main(int argc, char *argv[])
{
int main(int argc, char* argv[]) {
parseMyArguments(argc, argv);
size_t Nbytes = N*sizeof(int);
size_t Nbytes = N * sizeof(int);
int *A_d, *C_d, *A_h, *C_h;
HIPCHECK ( hipMalloc(&A_d, Nbytes) );
HIPCHECK ( hipMalloc(&C_d, Nbytes) );
HIPCHECK(hipMalloc(&A_d, Nbytes));
HIPCHECK(hipMalloc(&C_d, Nbytes));
A_h = (int*)malloc (Nbytes);
C_h = (int*)malloc (Nbytes);
A_h = (int*)malloc(Nbytes);
C_h = (int*)malloc(Nbytes);
for (int i=0; i<N; i++) {
A_h[i] = i*10;
for (int i = 0; i < N; i++) {
A_h[i] = i * 10;
C_h[i] = 0x0;
}
int blocks = N / p_blockSize;
printf ("running with N=%zu p_blockSize=%d blocks=%d\n", N, p_blockSize, blocks);
printf("running with N=%zu p_blockSize=%d blocks=%d\n", N, p_blockSize, blocks);
HIPCHECK ( hipMemcpy(A_d, A_h, Nbytes, hipMemcpyHostToDevice) );
HIPCHECK ( hipGetLastError() );
HIPCHECK(hipMemcpy(A_d, A_h, Nbytes, hipMemcpyHostToDevice));
HIPCHECK(hipGetLastError());
hipLaunchKernel(myKern, dim3(blocks), dim3(p_blockSize), 0, 0, C_d, A_d, N, 0);
#ifdef __HIP_PLATFORM_NVCC__
cudaFuncAttributes attrib;
cudaFuncGetAttributes (&attrib, myKern);
printf ("binaryVersion = %d\n", attrib.binaryVersion);
printf ("cacheModeCA = %d\n", attrib.cacheModeCA);
printf ("constSizeBytes = %zu\n", attrib.constSizeBytes);
printf ("localSizeBytes = %zud\n", attrib.localSizeBytes);
printf ("maxThreadsPerBlock = %d\n", attrib.maxThreadsPerBlock);
printf ("numRegs = %d\n", attrib.numRegs);
printf ("ptxVersion = %d\n", attrib.ptxVersion);
printf ("sharedSizeBytes = %zud\n", attrib.sharedSizeBytes);
cudaFuncGetAttributes(&attrib, myKern);
printf("binaryVersion = %d\n", attrib.binaryVersion);
printf("cacheModeCA = %d\n", attrib.cacheModeCA);
printf("constSizeBytes = %zu\n", attrib.constSizeBytes);
printf("localSizeBytes = %zud\n", attrib.localSizeBytes);
printf("maxThreadsPerBlock = %d\n", attrib.maxThreadsPerBlock);
printf("numRegs = %d\n", attrib.numRegs);
printf("ptxVersion = %d\n", attrib.ptxVersion);
printf("sharedSizeBytes = %zud\n", attrib.sharedSizeBytes);
#endif
HIPCHECK ( hipDeviceSynchronize() );
HIPCHECK(hipDeviceSynchronize());
HIPCHECK ( hipGetLastError() );
HIPCHECK(hipGetLastError());
HIPCHECK ( hipMemcpy(C_h, C_d, Nbytes, hipMemcpyDeviceToHost) );
HIPCHECK(hipMemcpy(C_h, C_d, Nbytes, hipMemcpyDeviceToHost));
HIPCHECK ( hipDeviceSynchronize() );
HIPCHECK(hipDeviceSynchronize());
for (int i=0; i<N; i++) {
for (int i = 0; i < N; i++) {
int goldVal = i * 10;
if (C_h[i] != goldVal) {
failed("mismatch at index:%d computed:%02d, gold:%02d\n", i, (int)C_h[i], (int)goldVal);
}
}
passed();
};