Apply .clangformat to all repo source files

Change-Id: I7e79c6058f0303f9a98911e3b7dd2e8596079344


[ROCm/clr commit: 9e47fccc89]
This commit is contained in:
Maneesh Gupta
2018-03-12 11:29:03 +05:30
förälder ecbb701440
incheckning 46ddefedee
293 ändrade filer med 43980 tillägg och 45830 borttagningar
@@ -29,209 +29,213 @@ THE SOFTWARE.
#include "hip/hip_runtime.h"
#include "test_common.h"
void printSep()
{
printf ("======================================================================================\n");
void printSep() {
printf(
"======================================================================================\n");
}
//---
// Test copies of a matrix numW by numH
// The subroutine allocates memory , copies to device, runs a vector add kernel, copies back, and checks the result.
// The subroutine allocates memory , copies to device, runs a vector add kernel, copies back, and
// checks the result.
//
// IN: numW: number of elements in the 1st dimension used for allocation
// IN: numH: number of elements in the 2nd dimension used for allocation
// IN: usePinnedHost : If true, allocate host with hipHostMalloc and is pinned ; else allocate host memory with malloc.
// IN: usePinnedHost : If true, allocate host with hipHostMalloc and is pinned ; else allocate host
// memory with malloc.
//
template <typename T>
void memcpy2Dtest(size_t numW, size_t numH, bool usePinnedHost)
{
void memcpy2Dtest(size_t numW, size_t numH, bool usePinnedHost) {
size_t width = numW * sizeof(T);
size_t sizeElements = width * numH;
size_t width = numW * sizeof(T);
size_t sizeElements = width * numH;
printf("memcpy2Dtest: %s<%s> size=%lu (%6.2fMB) W: %d, H:%d, usePinnedHost: %d\n", __func__,
TYPENAME(T), sizeElements, sizeElements / 1024.0 / 1024.0, (int)numW, (int)numH,
usePinnedHost);
printf("memcpy2Dtest: %s<%s> size=%lu (%6.2fMB) W: %d, H:%d, usePinnedHost: %d\n",
__func__,
TYPENAME(T),
sizeElements, sizeElements/1024.0/1024.0,
(int)numW, (int)numH, usePinnedHost);
T *A_d, *B_d, *C_d;
T *A_h, *B_h, *C_h;
T *A_d, *B_d, *C_d;
T *A_h, *B_h, *C_h;
size_t pitch_A, pitch_B, pitch_C;
size_t pitch_A, pitch_B, pitch_C;
hipChannelFormatDesc desc = hipCreateChannelDesc<T>();
HipTest::initArrays2DPitch(&A_d, &B_d, &C_d, &pitch_A, &pitch_B, &pitch_C, numW, numH);
HipTest::initArraysForHost(&A_h, &B_h, &C_h, numW * numH, usePinnedHost);
unsigned blocks = HipTest::setNumBlocks(blocksPerCU, threadsPerBlock, numW * numH);
hipChannelFormatDesc desc = hipCreateChannelDesc<T>();
HipTest::initArrays2DPitch(&A_d, &B_d, &C_d, &pitch_A, &pitch_B, &pitch_C, numW, numH);
HipTest::initArraysForHost(&A_h, &B_h, &C_h, numW*numH, usePinnedHost);
unsigned blocks = HipTest::setNumBlocks(blocksPerCU, threadsPerBlock, numW*numH);
HIPCHECK(hipMemcpy2D(A_d, pitch_A, A_h, width, width, numH, hipMemcpyHostToDevice));
HIPCHECK(hipMemcpy2D(B_d, pitch_B, B_h, width, width, numH, hipMemcpyHostToDevice));
HIPCHECK (hipMemcpy2D (A_d, pitch_A, A_h, width, width, numH, hipMemcpyHostToDevice) );
HIPCHECK (hipMemcpy2D (B_d, pitch_B, B_h, width, width, numH, hipMemcpyHostToDevice) );
hipLaunchKernel(HipTest::vectorADD, dim3(blocks), dim3(threadsPerBlock), 0, 0, A_d, B_d, C_d,
(pitch_C / sizeof(T)) * numH);
hipLaunchKernel(HipTest::vectorADD, dim3(blocks), dim3(threadsPerBlock), 0, 0, A_d, B_d, C_d, (pitch_C/sizeof(T))*numH);
HIPCHECK(hipMemcpy2D(C_h, width, C_d, pitch_C, width, numH, hipMemcpyDeviceToHost));
HIPCHECK (hipMemcpy2D (C_h, width, C_d, pitch_C, width, numH, hipMemcpyDeviceToHost) );
HIPCHECK(hipDeviceSynchronize());
HipTest::checkVectorADD(A_h, B_h, C_h, numW * numH);
HIPCHECK ( hipDeviceSynchronize() );
HipTest::checkVectorADD(A_h, B_h, C_h, numW*numH);
HipTest::freeArrays(A_d, B_d, C_d, A_h, B_h, C_h, usePinnedHost);
HipTest::freeArrays (A_d, B_d, C_d, A_h, B_h, C_h, usePinnedHost);
printf (" %s success\n", __func__);
printf(" %s success\n", __func__);
}
//---
// Test copies of a matrix numW by numH into a hipArray data structure
// The subroutine allocates memory , copies to device, runs a vector add kernel, copies back, and checks the result.
// The subroutine allocates memory , copies to device, runs a vector add kernel, copies back, and
// checks the result.
//
// IN: numW: number of elements in the 1st dimension used for allocation
// IN: numH: number of elements in the 2nd dimension used for allocation. If this is 1, then the 1-dimensional copy API
// IN: numH: number of elements in the 2nd dimension used for allocation. If this is 1, then the
// 1-dimensional copy API
// would be used
// IN: usePinnedHost : If true, allocate host with hipHostMalloc and is pinned ; else allocate host memory with malloc.
// IN: usePitch: If true, pads additional memory. This is only valid in the 2-dimensional case
// IN: usePinnedHost : If true, allocate host with hipHostMalloc and is pinned ; else allocate host
// memory with malloc. IN: usePitch: If true, pads additional memory. This is only valid in the
// 2-dimensional case
//
template <typename T>
void memcpyArraytest(size_t numW, size_t numH, bool usePinnedHost, bool usePitch=false)
{
void memcpyArraytest(size_t numW, size_t numH, bool usePinnedHost, bool usePitch = false) {
size_t width = numW * sizeof(T);
size_t sizeElements = width * numH;
size_t width = numW * sizeof(T);
size_t sizeElements = width * numH;
printf(
"memcpyArraytest: %s<%s> size=%lu (%6.2fMB) W: %d, H: %d, usePinnedHost: %d, usePitch: "
"%d\n",
__func__, TYPENAME(T), sizeElements, sizeElements / 1024.0 / 1024.0, (int)numW, (int)numH,
usePinnedHost, usePitch);
printf("memcpyArraytest: %s<%s> size=%lu (%6.2fMB) W: %d, H: %d, usePinnedHost: %d, usePitch: %d\n",
__func__,
TYPENAME(T),
sizeElements, sizeElements/1024.0/1024.0,
(int)numW, (int)numH, usePinnedHost, usePitch);
hipArray *A_d, *B_d, *C_d;
T *A_h, *B_h, *C_h;
hipArray *A_d, *B_d, *C_d;
T *A_h, *B_h, *C_h;
// 1D
if ((numW >= 1) && (numH == 1)) {
hipChannelFormatDesc desc = hipCreateChannelDesc<T>();
HipTest::initHIPArrays(&A_d, &B_d, &C_d, &desc, numW, 1, 0);
HipTest::initArraysForHost(&A_h, &B_h, &C_h, numW * numH, usePinnedHost);
unsigned blocks = HipTest::setNumBlocks(blocksPerCU, threadsPerBlock, numW * numH);
// 1D
if ((numW >= 1) && (numH == 1)) {
hipChannelFormatDesc desc = hipCreateChannelDesc<T>();
HipTest::initHIPArrays(&A_d, &B_d, &C_d, &desc, numW, 1, 0);
HipTest::initArraysForHost(&A_h, &B_h, &C_h, numW*numH, usePinnedHost);
unsigned blocks = HipTest::setNumBlocks(blocksPerCU, threadsPerBlock, numW*numH);
HIPCHECK(hipMemcpyToArray(A_d, 0, 0, (void*)A_h, width, hipMemcpyHostToDevice));
HIPCHECK(hipMemcpyToArray(B_d, 0, 0, (void*)B_h, width, hipMemcpyHostToDevice));
HIPCHECK (hipMemcpyToArray (A_d, 0, 0, (void *)A_h, width, hipMemcpyHostToDevice) );
HIPCHECK (hipMemcpyToArray (B_d, 0, 0, (void *)B_h, width, hipMemcpyHostToDevice) );
hipLaunchKernel(HipTest::vectorADD, dim3(blocks), dim3(threadsPerBlock), 0, 0,
(T*)A_d->data, (T*)B_d->data, (T*)C_d->data, numW);
hipLaunchKernel(HipTest::vectorADD, dim3(blocks), dim3(threadsPerBlock), 0, 0, (T*)A_d->data, (T*)B_d->data, (T*)C_d->data, numW);
HIPCHECK(hipMemcpy(C_h, C_d->data, width, hipMemcpyDeviceToHost));
HIPCHECK (hipMemcpy (C_h, C_d->data, width, hipMemcpyDeviceToHost) );
HIPCHECK(hipDeviceSynchronize());
HipTest::checkVectorADD(A_h, B_h, C_h, numW);
HIPCHECK ( hipDeviceSynchronize() );
HipTest::checkVectorADD(A_h, B_h, C_h, numW);
}
// 2D
else if ((numW >= 1) && (numH >= 1)) {
hipChannelFormatDesc desc = hipCreateChannelDesc<T>();
HipTest::initHIPArrays(&A_d, &B_d, &C_d, &desc, numW, numH, 0);
HipTest::initArraysForHost(&A_h, &B_h, &C_h, numW*numH, usePinnedHost);
unsigned blocks = HipTest::setNumBlocks(blocksPerCU, threadsPerBlock, numW*numH);
if (usePitch) {
T *A_p, *B_p, *C_p;
size_t pitch_A, pitch_B, pitch_C;
HipTest::initArrays2DPitch(&A_p, &B_p, &C_p, &pitch_A, &pitch_B, &pitch_C, numW, numH);
HIPCHECK (hipMemcpy2D (A_p, pitch_A, A_h, width, width, numH, hipMemcpyHostToDevice) );
HIPCHECK (hipMemcpy2D (B_p, pitch_B, B_h, width, width, numH, hipMemcpyHostToDevice) );
HIPCHECK (hipMemcpy2DToArray (A_d, 0, 0, (void *)A_p, pitch_A, width, numH, hipMemcpyDeviceToDevice) );
HIPCHECK (hipMemcpy2DToArray (B_d, 0, 0, (void *)B_p, pitch_B, width, numH, hipMemcpyDeviceToDevice) );
hipFree(A_p);
hipFree(B_p);
hipFree(C_p);
}
// 2D
else if ((numW >= 1) && (numH >= 1)) {
hipChannelFormatDesc desc = hipCreateChannelDesc<T>();
HipTest::initHIPArrays(&A_d, &B_d, &C_d, &desc, numW, numH, 0);
HipTest::initArraysForHost(&A_h, &B_h, &C_h, numW * numH, usePinnedHost);
unsigned blocks = HipTest::setNumBlocks(blocksPerCU, threadsPerBlock, numW * numH);
if (usePitch) {
T *A_p, *B_p, *C_p;
size_t pitch_A, pitch_B, pitch_C;
HipTest::initArrays2DPitch(&A_p, &B_p, &C_p, &pitch_A, &pitch_B, &pitch_C, numW, numH);
HIPCHECK(hipMemcpy2D(A_p, pitch_A, A_h, width, width, numH, hipMemcpyHostToDevice));
HIPCHECK(hipMemcpy2D(B_p, pitch_B, B_h, width, width, numH, hipMemcpyHostToDevice));
HIPCHECK(hipMemcpy2DToArray(A_d, 0, 0, (void*)A_p, pitch_A, width, numH,
hipMemcpyDeviceToDevice));
HIPCHECK(hipMemcpy2DToArray(B_d, 0, 0, (void*)B_p, pitch_B, width, numH,
hipMemcpyDeviceToDevice));
hipFree(A_p);
hipFree(B_p);
hipFree(C_p);
} else {
HIPCHECK(hipMemcpy2DToArray(A_d, 0, 0, (void*)A_h, width, width, numH,
hipMemcpyHostToDevice));
HIPCHECK(hipMemcpy2DToArray(B_d, 0, 0, (void*)B_h, width, width, numH,
hipMemcpyHostToDevice));
}
hipLaunchKernel(HipTest::vectorADD, dim3(blocks), dim3(threadsPerBlock), 0, 0,
(T*)A_d->data, (T*)B_d->data, (T*)C_d->data, numW * numH);
HIPCHECK(hipMemcpy2D((void*)C_h, width, (void*)C_d->data, width, width, numH,
hipMemcpyDeviceToHost));
HIPCHECK(hipDeviceSynchronize());
HipTest::checkVectorADD(A_h, B_h, C_h, numW * numH);
}
// Unknown
else {
HIPCHECK (hipMemcpy2DToArray (A_d, 0, 0, (void *)A_h, width, width, numH, hipMemcpyHostToDevice) );
HIPCHECK (hipMemcpy2DToArray (B_d, 0, 0, (void *)B_h, width, width, numH, hipMemcpyHostToDevice) );
HIPASSERT("Incompatible dimensions" && 0);
}
hipLaunchKernel(HipTest::vectorADD, dim3(blocks), dim3(threadsPerBlock), 0, 0, (T*)A_d->data, (T*)B_d->data, (T*)C_d->data, numW*numH);
HIPCHECK (hipMemcpy2D ((void*)C_h, width, (void*)C_d->data, width, width, numH, hipMemcpyDeviceToHost) );
HIPCHECK ( hipDeviceSynchronize() );
HipTest::checkVectorADD(A_h, B_h, C_h, numW*numH);
}
// Unknown
else {
HIPASSERT("Incompatible dimensions" && 0);
}
hipFreeArray(A_d);
hipFreeArray(B_d);
hipFreeArray(C_d);
HipTest::freeArraysForHost(A_h, B_h, C_h, usePinnedHost);
printf (" %s success\n", __func__);
hipFreeArray(A_d);
hipFreeArray(B_d);
hipFreeArray(C_d);
HipTest::freeArraysForHost(A_h, B_h, C_h, usePinnedHost);
printf(" %s success\n", __func__);
}
//---
//Try many different sizes to memory copy.
// Try many different sizes to memory copy.
template <typename T>
void memcpyArraytest_size(size_t maxElem=0, size_t offset=0)
{
printf ("test: %s<%s>\n", __func__, TYPENAME(T));
void memcpyArraytest_size(size_t maxElem = 0, size_t offset = 0) {
printf("test: %s<%s>\n", __func__, TYPENAME(T));
int deviceId;
HIPCHECK(hipGetDevice(&deviceId));
int deviceId;
HIPCHECK(hipGetDevice(&deviceId));
size_t free, total;
HIPCHECK(hipMemGetInfo(&free, &total));
size_t free, total;
HIPCHECK(hipMemGetInfo(&free, &total));
if (maxElem == 0) {
maxElem = free/sizeof(T)/5;
}
if (maxElem == 0) {
maxElem = free / sizeof(T) / 5;
}
printf (" device#%d: hipMemGetInfo: free=%zu (%4.2fMB) total=%zu (%4.2fMB) maxSize=%6.1fMB offset=%lu\n",
deviceId, free, (float)(free/1024.0/1024.0), total, (float)(total/1024.0/1024.0), maxElem*sizeof(T)/1024.0/1024.0, offset);
printf(
" device#%d: hipMemGetInfo: free=%zu (%4.2fMB) total=%zu (%4.2fMB) maxSize=%6.1fMB "
"offset=%lu\n",
deviceId, free, (float)(free / 1024.0 / 1024.0), total, (float)(total / 1024.0 / 1024.0),
maxElem * sizeof(T) / 1024.0 / 1024.0, offset);
// Test 1D
for (size_t elem=64; elem+offset<=maxElem; elem*=2) {
HIPCHECK ( hipDeviceReset() );
memcpyArraytest<T>(elem+offset, 1, 0); // unpinned host
HIPCHECK ( hipDeviceReset() );
memcpyArraytest<T>(elem+offset, 1, 1); // pinned host
}
// Test 1D
for (size_t elem = 64; elem + offset <= maxElem; elem *= 2) {
HIPCHECK(hipDeviceReset());
memcpyArraytest<T>(elem + offset, 1, 0); // unpinned host
HIPCHECK(hipDeviceReset());
memcpyArraytest<T>(elem + offset, 1, 1); // pinned host
}
// Test 2D
size_t maxElem2D = sqrt(maxElem);
// Test 2D
size_t maxElem2D = sqrt(maxElem);
for (size_t elem=64; elem+offset<=maxElem2D; elem*=2) {
HIPCHECK ( hipDeviceReset() );
memcpyArraytest<T>(elem+offset, elem+offset, 0, 1); // use pitch
}
for (size_t elem = 64; elem + offset <= maxElem2D; elem *= 2) {
HIPCHECK(hipDeviceReset());
memcpyArraytest<T>(elem + offset, elem + offset, 0, 1); // use pitch
}
}
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));
if (p_tests & 0x1) {
printf ("\n\n=== tests&1 (types)\n");
printf("\n\n=== tests&1 (types)\n");
printSep();
HIPCHECK ( hipDeviceReset() );
size_t width = N/6;
size_t height = N/6;
HIPCHECK(hipDeviceReset());
size_t width = N / 6;
size_t height = N / 6;
memcpy2Dtest<float>(321, 211, 0);
memcpy2Dtest<double>(322, 211, 0);
memcpy2Dtest<char>(320, 211, 0);
memcpy2Dtest<int>(323, 211, 0);
printf ("===\n\n\n");
printf("===\n\n\n");
printf ("\n\n=== tests&1 (types)\n");
printf("\n\n=== tests&1 (types)\n");
printSep();
// 2D
memcpyArraytest<float>(320, 211, 0, 0);
@@ -245,23 +249,22 @@ int main(int argc, char *argv[])
memcpyArraytest<float>(320, 1, 0);
memcpyArraytest<unsigned int>(322, 1, 0);
memcpyArraytest<int>(320, 1, 0);
printf ("===\n\n\n");
printf("===\n\n\n");
}
if (p_tests & 0x4) {
printf ("\n\n=== tests&4 (test sizes and offsets)\n");
printf("\n\n=== tests&4 (test sizes and offsets)\n");
printSep();
HIPCHECK ( hipDeviceReset() );
HIPCHECK(hipDeviceReset());
printSep();
memcpyArraytest_size<float>(0,0);
memcpyArraytest_size<float>(0, 0);
printSep();
memcpyArraytest_size<float>(0,64);
memcpyArraytest_size<float>(0, 64);
printSep();
memcpyArraytest_size<float>(1024*1024,13);
memcpyArraytest_size<float>(1024 * 1024, 13);
printSep();
memcpyArraytest_size<float>(1024*1024,50);
memcpyArraytest_size<float>(1024 * 1024, 50);
}
passed();
}
@@ -26,61 +26,62 @@ THE SOFTWARE.
* HIT_END
*/
#include"test_common.h"
#include<malloc.h>
#include "test_common.h"
#include <malloc.h>
#define LEN 1024*1024
#define SIZE LEN*sizeof(float)
#define LEN 1024 * 1024
#define SIZE LEN * sizeof(float)
__global__ void Add(hipLaunchParm lp, float *Ad, float *Bd, float *Cd){
int tx = threadIdx.x + blockIdx.x * blockDim.x;
Cd[tx] = Ad[tx] + Bd[tx];
__global__ void Add(hipLaunchParm lp, float* Ad, float* Bd, float* Cd) {
int tx = threadIdx.x + blockIdx.x * blockDim.x;
Cd[tx] = Ad[tx] + Bd[tx];
}
int main(){
float *A, *B, *C, *D;
float *Ad, *Bd, *Cd, *Dd;
unsigned int FlagA, FlagB, FlagC;
FlagA = hipHostMallocWriteCombined | hipHostMallocMapped;
FlagB = hipHostMallocWriteCombined | hipHostMallocMapped;
FlagC = hipHostMallocMapped;
hipDeviceProp_t prop;
int device;
HIPCHECK(hipGetDevice(&device));
HIPCHECK(hipGetDeviceProperties(&prop, device));
if(prop.canMapHostMemory != 1){
std::cout<<"Exiting..."<<std::endl;
}
HIPCHECK(hipHostMalloc((void**)&A, SIZE, hipHostMallocWriteCombined | hipHostMallocMapped));
HIPCHECK(hipHostMalloc((void**)&B, SIZE, hipHostMallocWriteCombined | hipHostMallocMapped));
HIPCHECK(hipHostMalloc((void**)&C, SIZE, hipHostMallocMapped));
HIPCHECK(hipHostMalloc((void**)&D, SIZE, hipHostMallocDefault));
unsigned int flagA, flagB, flagC;
HIPCHECK(hipHostGetDevicePointer((void**)&Ad, A, 0));
HIPCHECK(hipHostGetDevicePointer((void**)&Bd, B, 0));
HIPCHECK(hipHostGetDevicePointer((void**)&Cd, C, 0));
HIPCHECK(hipHostGetDevicePointer((void**)&Dd, D, 0));
HIPCHECK(hipHostGetFlags(&flagA, A));
HIPCHECK(hipHostGetFlags(&flagB, B));
HIPCHECK(hipHostGetFlags(&flagC, C));
for(int i=0;i<LEN;i++){
A[i] = 1.0f;
B[i] = 2.0f;
}
dim3 dimGrid(LEN/512,1,1);
dim3 dimBlock(512,1,1);
hipLaunchKernel(HIP_KERNEL_NAME(Add), dimGrid, dimBlock, 0, 0, Ad, Bd, Cd);
HIPCHECK(hipMemcpy(C, Cd, SIZE, hipMemcpyDeviceToHost)); // Note this really HostToHost not DeviceToHost, since memory is mapped...
HIPASSERT(C[10] == 3.0f);
HIPASSERT(flagA == FlagA);
HIPASSERT(flagB == FlagB);
HIPASSERT(flagC == FlagC);
passed();
int main() {
float *A, *B, *C, *D;
float *Ad, *Bd, *Cd, *Dd;
unsigned int FlagA, FlagB, FlagC;
FlagA = hipHostMallocWriteCombined | hipHostMallocMapped;
FlagB = hipHostMallocWriteCombined | hipHostMallocMapped;
FlagC = hipHostMallocMapped;
hipDeviceProp_t prop;
int device;
HIPCHECK(hipGetDevice(&device));
HIPCHECK(hipGetDeviceProperties(&prop, device));
if (prop.canMapHostMemory != 1) {
std::cout << "Exiting..." << std::endl;
}
HIPCHECK(hipHostMalloc((void**)&A, SIZE, hipHostMallocWriteCombined | hipHostMallocMapped));
HIPCHECK(hipHostMalloc((void**)&B, SIZE, hipHostMallocWriteCombined | hipHostMallocMapped));
HIPCHECK(hipHostMalloc((void**)&C, SIZE, hipHostMallocMapped));
HIPCHECK(hipHostMalloc((void**)&D, SIZE, hipHostMallocDefault));
unsigned int flagA, flagB, flagC;
HIPCHECK(hipHostGetDevicePointer((void**)&Ad, A, 0));
HIPCHECK(hipHostGetDevicePointer((void**)&Bd, B, 0));
HIPCHECK(hipHostGetDevicePointer((void**)&Cd, C, 0));
HIPCHECK(hipHostGetDevicePointer((void**)&Dd, D, 0));
HIPCHECK(hipHostGetFlags(&flagA, A));
HIPCHECK(hipHostGetFlags(&flagB, B));
HIPCHECK(hipHostGetFlags(&flagC, C));
for (int i = 0; i < LEN; i++) {
A[i] = 1.0f;
B[i] = 2.0f;
}
dim3 dimGrid(LEN / 512, 1, 1);
dim3 dimBlock(512, 1, 1);
hipLaunchKernel(HIP_KERNEL_NAME(Add), dimGrid, dimBlock, 0, 0, Ad, Bd, Cd);
HIPCHECK(
hipMemcpy(C, Cd, SIZE, hipMemcpyDeviceToHost)); // Note this really HostToHost not
// DeviceToHost, since memory is mapped...
HIPASSERT(C[10] == 3.0f);
HIPASSERT(flagA == FlagA);
HIPASSERT(flagB == FlagB);
HIPASSERT(flagC == FlagC);
passed();
}
@@ -27,18 +27,18 @@
*/
#include <vector>
#include"test_common.h"
#include "test_common.h"
#define LEN 1024*1024
#define SIZE LEN*sizeof(float)
#define LEN 1024 * 1024
#define SIZE LEN * sizeof(float)
__global__ void Add(float *Ad, float *Bd, float *Cd){
__global__ void Add(float* Ad, float* Bd, float* Cd) {
int tx = threadIdx.x + blockIdx.x * blockDim.x;
Cd[tx] = Ad[tx] + Bd[tx];
}
__global__ void Set(int *Ad, int val){
__global__ void Set(int* Ad, int val) {
int tx = threadIdx.x + blockIdx.x * blockDim.x;
Ad[tx] = val;
}
@@ -50,16 +50,16 @@ __global__ void Set(int *Ad, int val){
std::vector<std::string> syncMsg = {"event", "stream", "device"};
void CheckHostPointer(int numElements, int *ptr, unsigned eventFlags, int syncMethod, std::string msg)
{
std::cerr << "test: CheckHostPointer " << msg
void CheckHostPointer(int numElements, int* ptr, unsigned eventFlags, int syncMethod,
std::string msg) {
std::cerr << "test: CheckHostPointer "
<< msg
//<< " HIP_COHERENT_HOST_ALLOC=" << HIP_COHERENT_HOST_ALLOC
//<< " HIP_EVENT_SYS_RELEASE=" << HIP_EVENT_SYS_RELEASE
<< " eventFlags = " << std::hex << eventFlags
<< ((eventFlags & hipEventReleaseToDevice) ? " hipEventReleaseToDevice" : "")
<< ((eventFlags & hipEventReleaseToDevice) ? " hipEventReleaseToDevice" : "")
<< ((eventFlags & hipEventReleaseToSystem) ? " hipEventReleaseToSystem" : "")
<< " ptr=" << ptr
<< " syncMethod=" << syncMsg[syncMethod] << "\n";
<< " ptr=" << ptr << " syncMethod=" << syncMsg[syncMethod] << "\n";
hipStream_t s;
hipEvent_t e;
@@ -67,8 +67,8 @@ void CheckHostPointer(int numElements, int *ptr, unsigned eventFlags, int syncMe
// Init:
HIPCHECK(hipStreamCreate(&s));
HIPCHECK(hipEventCreateWithFlags(&e, eventFlags))
dim3 dimBlock(64,1,1);
dim3 dimGrid(numElements/dimBlock.x,1,1);
dim3 dimBlock(64, 1, 1);
dim3 dimGrid(numElements / dimBlock.x, 1, 1);
const int expected = 13;
@@ -94,9 +94,9 @@ void CheckHostPointer(int numElements, int *ptr, unsigned eventFlags, int syncMe
assert(0);
};
for (int i=0; i<numElements; i++) {
for (int i = 0; i < numElements; i++) {
if (ptr[i] != expected) {
printf ("mismatch at %d: %d != %d\n", i, ptr[i], expected);
printf("mismatch at %d: %d != %d\n", i, ptr[i], expected);
assert(ptr[i] == expected);
}
}
@@ -105,15 +105,13 @@ void CheckHostPointer(int numElements, int *ptr, unsigned eventFlags, int syncMe
HIPCHECK(hipEventDestroy(e));
};
int main(){
int main() {
hipDeviceProp_t prop;
int device;
HIPCHECK(hipGetDevice(&device));
HIPCHECK(hipGetDeviceProperties(&prop, device));
if(prop.canMapHostMemory != 1){
std::cout<<"Exiting..."<<std::endl;
if (prop.canMapHostMemory != 1) {
std::cout << "Exiting..." << std::endl;
failed("Does support HostPinned Memory");
}
@@ -128,7 +126,7 @@ int main(){
HIPCHECK(hipHostGetDevicePointer((void**)&Ad, A, 0));
HIPCHECK(hipHostGetDevicePointer((void**)&Cd, C, 0));
for(int i=0;i<LEN;i++){
for (int i = 0; i < LEN; i++) {
A[i] = 1.0f;
B[i] = 2.0f;
}
@@ -136,8 +134,8 @@ int main(){
HIPCHECK(hipMalloc((void**)&Bd, SIZE));
HIPCHECK(hipMemcpy(Bd, B, SIZE, hipMemcpyHostToDevice));
dim3 dimGrid(LEN/512,1,1);
dim3 dimBlock(512,1,1);
dim3 dimGrid(LEN / 512, 1, 1);
dim3 dimBlock(512, 1, 1);
hipLaunchKernelGGL(Add, dimGrid, dimBlock, 0, 0, Ad, Bd, Cd);
@@ -149,64 +147,61 @@ int main(){
}
{
int numElements = 1024*16;
size_t sizeBytes = numElements * sizeof (int);
int numElements = 1024 * 16;
size_t sizeBytes = numElements * sizeof(int);
#ifdef __HIP_PLATFORM_HCC__
{
// Stimulate error condition:
int *A = &numElements;
HIPCHECK_API(hipHostMalloc((void**)&A, sizeBytes, hipHostMallocCoherent|hipHostMallocNonCoherent), hipErrorInvalidValue);
int* A = &numElements;
HIPCHECK_API(hipHostMalloc((void**)&A, sizeBytes,
hipHostMallocCoherent | hipHostMallocNonCoherent),
hipErrorInvalidValue);
assert (A == 0);
assert(A == 0);
}
#endif
{
int *A = nullptr;
int* A = nullptr;
HIPCHECK(hipHostMalloc((void**)&A, sizeBytes, hipHostMallocNonCoherent));
const char *ptrType = "non-coherent"; // TODO
CheckHostPointer(numElements, A, hipEventReleaseToSystem, SYNC_DEVICE, ptrType);
CheckHostPointer(numElements, A, hipEventReleaseToSystem, SYNC_STREAM, ptrType);
CheckHostPointer(numElements, A, hipEventReleaseToSystem, SYNC_EVENT, ptrType);
const char* ptrType = "non-coherent"; // TODO
CheckHostPointer(numElements, A, hipEventReleaseToSystem, SYNC_DEVICE, ptrType);
CheckHostPointer(numElements, A, hipEventReleaseToSystem, SYNC_STREAM, ptrType);
CheckHostPointer(numElements, A, hipEventReleaseToSystem, SYNC_EVENT, ptrType);
// agent-scope releases don't provide host visibility, don't use them here:
}
if (1) {
int *A = nullptr;
int* A = nullptr;
HIPCHECK(hipHostMalloc((void**)&A, sizeBytes, hipHostMallocCoherent));
const char *ptrType = "coherent";
CheckHostPointer(numElements, A, hipEventReleaseToDevice, SYNC_DEVICE, ptrType);
CheckHostPointer(numElements, A, hipEventReleaseToDevice, SYNC_STREAM, ptrType);
CheckHostPointer(numElements, A, hipEventReleaseToDevice, SYNC_EVENT, ptrType);
const char* ptrType = "coherent";
CheckHostPointer(numElements, A, hipEventReleaseToDevice, SYNC_DEVICE, ptrType);
CheckHostPointer(numElements, A, hipEventReleaseToDevice, SYNC_STREAM, ptrType);
CheckHostPointer(numElements, A, hipEventReleaseToDevice, SYNC_EVENT, ptrType);
CheckHostPointer(numElements, A, hipEventReleaseToSystem, SYNC_DEVICE, ptrType);
CheckHostPointer(numElements, A, hipEventReleaseToSystem, SYNC_STREAM, ptrType);
CheckHostPointer(numElements, A, hipEventReleaseToSystem, SYNC_EVENT, ptrType);
CheckHostPointer(numElements, A, hipEventReleaseToSystem, SYNC_DEVICE, ptrType);
CheckHostPointer(numElements, A, hipEventReleaseToSystem, SYNC_STREAM, ptrType);
CheckHostPointer(numElements, A, hipEventReleaseToSystem, SYNC_EVENT, ptrType);
}
// Check defaults:
if (1) {
int *A = nullptr;
int* A = nullptr;
HIPCHECK(hipHostMalloc((void**)&A, sizeBytes));
const char *ptrType = "default";
CheckHostPointer(numElements, A, 0, SYNC_DEVICE, ptrType);
CheckHostPointer(numElements, A, 0, SYNC_STREAM, ptrType);
CheckHostPointer(numElements, A, 0, SYNC_EVENT, ptrType);
const char* ptrType = "default";
CheckHostPointer(numElements, A, 0, SYNC_DEVICE, ptrType);
CheckHostPointer(numElements, A, 0, SYNC_STREAM, ptrType);
CheckHostPointer(numElements, A, 0, SYNC_EVENT, ptrType);
CheckHostPointer(numElements, A, 0, SYNC_DEVICE, ptrType);
CheckHostPointer(numElements, A, 0, SYNC_STREAM, ptrType);
CheckHostPointer(numElements, A, 0, SYNC_EVENT, ptrType);
CheckHostPointer(numElements, A, 0, SYNC_DEVICE, ptrType);
CheckHostPointer(numElements, A, 0, SYNC_STREAM, ptrType);
CheckHostPointer(numElements, A, 0, SYNC_EVENT, ptrType);
}
}
passed();
}
@@ -25,18 +25,17 @@ THE SOFTWARE.
// TODO - bug if run both back-to-back, once fixed should just need one command line
#include"test_common.h"
#include<malloc.h>
#include "test_common.h"
#include <malloc.h>
__global__ void Inc(hipLaunchParm lp, float *Ad){
__global__ void Inc(hipLaunchParm lp, float* Ad) {
int tx = threadIdx.x + blockIdx.x * blockDim.x;
Ad[tx] = Ad[tx] + float(1);
}
template<typename T>
void doMemCopy(size_t numElements, int offset, T *A, T *Bh, T *Bd, bool internalRegister)
{
template <typename T>
void doMemCopy(size_t numElements, int offset, T* A, T* Bh, T* Bd, bool internalRegister) {
A = A + offset;
numElements -= offset;
@@ -48,7 +47,7 @@ void doMemCopy(size_t numElements, int offset, T *A, T *Bh, T *Bd, bool internal
// Reset
for(size_t i=0;i<numElements;i++){
for (size_t i = 0; i < numElements; i++) {
A[i] = float(i);
Bh[i] = 0.0f;
}
@@ -57,13 +56,13 @@ void doMemCopy(size_t numElements, int offset, T *A, T *Bh, T *Bd, bool internal
//
HIPCHECK(hipMemcpy(Bd, A, sizeBytes, hipMemcpyHostToDevice));
HIPCHECK(hipMemcpy(Bd, A, sizeBytes, hipMemcpyHostToDevice));
HIPCHECK(hipMemcpy(Bh, Bd, sizeBytes, hipMemcpyDeviceToHost));
// Make sure the copy worked
for(size_t i=0;i<numElements;i++){
for (size_t i = 0; i < numElements; i++) {
if (Bh[i] != A[i]) {
printf ("mismatch at Bh[%zu]=%f, A[%zu]=%f\n", i, Bh[i], i, A[i]);
printf("mismatch at Bh[%zu]=%f, A[%zu]=%f\n", i, Bh[i], i, A[i]);
failed("mismatch");
};
}
@@ -71,12 +70,9 @@ void doMemCopy(size_t numElements, int offset, T *A, T *Bh, T *Bd, bool internal
if (internalRegister) {
HIPCHECK(hipHostUnregister(A));
}
}
int main(int argc, char *argv[])
{
int main(int argc, char* argv[]) {
HipTest::parseStandardArguments(argc, argv, true);
const size_t size = N * sizeof(float);
@@ -90,20 +86,20 @@ int main(int argc, char *argv[])
HIPCHECK(hipHostRegister(A, size, 0));
for(int i=0;i<N;i++){
for (int i = 0; i < N; i++) {
A[i] = float(1);
}
for(int i=0;i<num_devices;i++){
for (int i = 0; i < num_devices; i++) {
HIPCHECK(hipSetDevice(i));
HIPCHECK(hipHostGetDevicePointer((void**)&Ad[i], A, 0));
}
// Reference the registered device pointer Ad from inside the kernel:
for(int i=0;i<num_devices;i++){
for (int i = 0; i < num_devices; i++) {
HIPCHECK(hipSetDevice(i));
hipLaunchKernel(Inc, dim3(N/512), dim3(512), 0, 0, Ad[i]);
hipLaunchKernel(Inc, dim3(N / 512), dim3(512), 0, 0, Ad[i]);
HIPCHECK(hipDeviceSynchronize());
}
@@ -111,7 +107,7 @@ int main(int argc, char *argv[])
HIPCHECK(hipHostUnregister(A));
free (A);
free(A);
}
@@ -120,7 +116,7 @@ int main(int argc, char *argv[])
HIPCHECK(hipSetDevice(0));
float * A = (float*)malloc(size);
float* A = (float*)malloc(size);
// Copy to B, this should be optimal pinned malloc copy:
// Note we are using the host pointer here:
@@ -130,29 +126,26 @@ int main(int argc, char *argv[])
// TODO - set to 128
#define OFFSETS_TO_TRY 128
assert (N>OFFSETS_TO_TRY);
assert(N > OFFSETS_TO_TRY);
if (p_tests & 0x2) {
for (size_t i=0; i<OFFSETS_TO_TRY; i++) {
doMemCopy(N, i, A, Bh, Bd, true/*internalRegister*/);
for (size_t i = 0; i < OFFSETS_TO_TRY; i++) {
doMemCopy(N, i, A, Bh, Bd, true /*internalRegister*/);
}
}
if (p_tests & 0x4) {
HIPCHECK(hipHostRegister(A, size, 0));
for (size_t i=0; i<OFFSETS_TO_TRY; i++) {
doMemCopy(N, i, A, Bh, Bd, false/*internalRegister*/);
for (size_t i = 0; i < OFFSETS_TO_TRY; i++) {
doMemCopy(N, i, A, Bh, Bd, false /*internalRegister*/);
}
HIPCHECK(hipHostUnregister(A));
}
free (A);
free(A);
}
passed();
passed();
}
@@ -26,27 +26,27 @@ THE SOFTWARE.
* HIT_END
*/
#include"test_common.h"
#include "test_common.h"
struct {
float a;
int b;
void *c;
} Struct ;
float a;
int b;
void* c;
} Struct;
int main(){
int *iPtr;
float *fPtr;
struct Struct *sPtr;
size_t sSetSize = 1024, sGetSize;
hipMalloc(&iPtr, sSetSize);
hipMalloc(&fPtr, sSetSize);
hipMalloc(&sPtr, sSetSize);
hipMemPtrGetInfo(iPtr, &sGetSize);
assert(sGetSize == sSetSize);
hipMemPtrGetInfo(fPtr, &sGetSize);
assert(sGetSize == sSetSize);
hipMemPtrGetInfo(sPtr, &sGetSize);
assert(sGetSize == sSetSize);
passed();
int main() {
int* iPtr;
float* fPtr;
struct Struct* sPtr;
size_t sSetSize = 1024, sGetSize;
hipMalloc(&iPtr, sSetSize);
hipMalloc(&fPtr, sSetSize);
hipMalloc(&sPtr, sSetSize);
hipMemPtrGetInfo(iPtr, &sGetSize);
assert(sGetSize == sSetSize);
hipMemPtrGetInfo(fPtr, &sGetSize);
assert(sGetSize == sSetSize);
hipMemPtrGetInfo(sPtr, &sGetSize);
assert(sGetSize == sSetSize);
passed();
}
@@ -35,23 +35,22 @@ THE SOFTWARE.
#include "test_common.h"
void printSep()
{
printf ("======================================================================================\n");
void printSep() {
printf(
"======================================================================================\n");
}
//-------
template<typename T>
class DeviceMemory
{
public:
template <typename T>
class DeviceMemory {
public:
DeviceMemory(size_t numElements);
~DeviceMemory();
T *A_d() const { return _A_d + _offset; };
T *B_d() const { return _B_d + _offset; };
T *C_d() const { return _C_d + _offset; };
T *C_dd() const { return _C_dd + _offset; };
T* A_d() const { return _A_d + _offset; };
T* B_d() const { return _B_d + _offset; };
T* C_d() const { return _C_d + _offset; };
T* C_dd() const { return _C_dd + _offset; };
size_t maxNumElements() const { return _maxNumElements; };
@@ -59,92 +58,83 @@ public:
void offset(int offset) { _offset = offset; };
int offset() const { return _offset; };
private:
T * _A_d;
T* _B_d;
T* _C_d;
T* _C_dd;
private:
T* _A_d;
T* _B_d;
T* _C_d;
T* _C_dd;
size_t _maxNumElements;
int _offset;
};
template<typename T>
DeviceMemory<T>::DeviceMemory(size_t numElements)
: _maxNumElements(numElements),
_offset(0)
{
T ** np = nullptr;
HipTest::initArrays (&_A_d, &_B_d, &_C_d, np, np, np, numElements, 0);
template <typename T>
DeviceMemory<T>::DeviceMemory(size_t numElements) : _maxNumElements(numElements), _offset(0) {
T** np = nullptr;
HipTest::initArrays(&_A_d, &_B_d, &_C_d, np, np, np, numElements, 0);
size_t sizeElements = numElements * sizeof(T);
HIPCHECK ( hipMalloc(&_C_dd, sizeElements) );
HIPCHECK(hipMalloc(&_C_dd, sizeElements));
}
template<typename T>
DeviceMemory<T>::~DeviceMemory ()
{
T * np = nullptr;
HipTest::freeArrays (_A_d, _B_d, _C_d, np, np, np, 0);
template <typename T>
DeviceMemory<T>::~DeviceMemory() {
T* np = nullptr;
HipTest::freeArrays(_A_d, _B_d, _C_d, np, np, np, 0);
HIPCHECK (hipFree(_C_dd));
HIPCHECK(hipFree(_C_dd));
_C_dd = NULL;
};
//-------
template<typename T>
class HostMemory
{
public:
template <typename T>
class HostMemory {
public:
HostMemory(size_t numElements, bool usePinnedHost);
void reset(size_t numElements, bool full=false) ;
void reset(size_t numElements, bool full = false);
~HostMemory();
T *A_h() const { return _A_h + _offset; };
T *B_h() const { return _B_h + _offset; };
T *C_h() const { return _C_h + _offset; };
T* A_h() const { return _A_h + _offset; };
T* B_h() const { return _B_h + _offset; };
T* C_h() const { return _C_h + _offset; };
size_t maxNumElements() const { return _maxNumElements; };
void offset(int offset) { _offset = offset; };
int offset() const { return _offset; };
public:
public:
// Host arrays, secondary copy
T * A_hh;
T* B_hh;
T* A_hh;
T* B_hh;
bool _usePinnedHost;
private:
bool _usePinnedHost;
private:
size_t _maxNumElements;
int _offset;
// Host arrays
T * _A_h;
T* _B_h;
T* _C_h;
T* _A_h;
T* _B_h;
T* _C_h;
};
template<typename T>
template <typename T>
HostMemory<T>::HostMemory(size_t numElements, bool usePinnedHost)
: _maxNumElements(numElements),
_usePinnedHost(usePinnedHost),
_offset(0)
{
T ** np = nullptr;
HipTest::initArrays (np, np, np, &_A_h, &_B_h, &_C_h, numElements, usePinnedHost);
: _maxNumElements(numElements), _usePinnedHost(usePinnedHost), _offset(0) {
T** np = nullptr;
HipTest::initArrays(np, np, np, &_A_h, &_B_h, &_C_h, numElements, usePinnedHost);
A_hh = NULL;
B_hh = NULL;
@@ -153,142 +143,137 @@ HostMemory<T>::HostMemory(size_t numElements, bool usePinnedHost)
size_t sizeElements = numElements * sizeof(T);
if (usePinnedHost) {
HIPCHECK ( hipHostMalloc((void**)&A_hh, sizeElements, hipHostMallocDefault) );
HIPCHECK ( hipHostMalloc((void**)&B_hh, sizeElements, hipHostMallocDefault) );
HIPCHECK(hipHostMalloc((void**)&A_hh, sizeElements, hipHostMallocDefault));
HIPCHECK(hipHostMalloc((void**)&B_hh, sizeElements, hipHostMallocDefault));
} else {
A_hh = (T*)malloc(sizeElements);
B_hh = (T*)malloc(sizeElements);
}
}
template<typename T>
void
HostMemory<T>::reset(size_t numElements, bool full)
{
template <typename T>
void HostMemory<T>::reset(size_t numElements, bool full) {
// Initialize the host data:
for (size_t i=0; i<numElements; i++) {
for (size_t i = 0; i < numElements; i++) {
(A_hh)[i] = 1097.0 + i;
(B_hh)[i] = 1492.0 + i; // Phi
(B_hh)[i] = 1492.0 + i; // Phi
if (full) {
(_A_h)[i] = 3.146f + i; // Pi
(_B_h)[i] = 1.618f + i; // Phi
(_A_h)[i] = 3.146f + i; // Pi
(_B_h)[i] = 1.618f + i; // Phi
}
}
}
template<typename T>
HostMemory<T>::~HostMemory ()
{
HipTest::freeArraysForHost (_A_h, _B_h, _C_h, _usePinnedHost);
template <typename T>
HostMemory<T>::~HostMemory() {
HipTest::freeArraysForHost(_A_h, _B_h, _C_h, _usePinnedHost);
if (_usePinnedHost) {
HIPCHECK (hipHostFree(A_hh));
HIPCHECK (hipHostFree(B_hh));
HIPCHECK(hipHostFree(A_hh));
HIPCHECK(hipHostFree(B_hh));
} else {
free(A_hh);
free(B_hh);
}
};
//---
// Test many different kinds of memory copies.
// The subroutine allocates memory , copies to device, runs a vector add kernel, copies back, and checks the result.
// The subroutine allocates memory , copies to device, runs a vector add kernel, copies back, and
// checks the result.
//
// IN: numElements controls the number of elements used for allocations.
// IN: usePinnedHost : If true, allocate host with hipHostMalloc and is pinned ; else allocate host memory with malloc.
// IN: useHostToHost : If true, add an extra host-to-host copy.
// IN: useDeviceToDevice : If true, add an extra deviceto-device copy after result is produced.
// IN: useMemkindDefault : If true, use memkinddefault (runtime figures out direction). if false, use explicit memcpy direction.
// IN: usePinnedHost : If true, allocate host with hipHostMalloc and is pinned ; else allocate host
// memory with malloc. IN: useHostToHost : If true, add an extra host-to-host copy. IN:
// useDeviceToDevice : If true, add an extra deviceto-device copy after result is produced. IN:
// useMemkindDefault : If true, use memkinddefault (runtime figures out direction). if false, use
// explicit memcpy direction.
//
template <typename T>
void memcpytest2(DeviceMemory<T> *dmem, HostMemory<T> *hmem, size_t numElements, bool useHostToHost, bool useDeviceToDevice, bool useMemkindDefault)
{
void memcpytest2(DeviceMemory<T>* dmem, HostMemory<T>* hmem, size_t numElements, bool useHostToHost,
bool useDeviceToDevice, bool useMemkindDefault) {
size_t sizeElements = numElements * sizeof(T);
printf ("test: %s<%s> size=%lu (%6.2fMB) usePinnedHost:%d, useHostToHost:%d, useDeviceToDevice:%d, useMemkindDefault:%d, offsets:dev:%+d host:+%d\n",
__func__,
TYPENAME(T),
sizeElements, sizeElements/1024.0/1024.0,
hmem->_usePinnedHost, useHostToHost, useDeviceToDevice, useMemkindDefault,
dmem->offset(), hmem->offset()
);
printf(
"test: %s<%s> size=%lu (%6.2fMB) usePinnedHost:%d, useHostToHost:%d, useDeviceToDevice:%d, "
"useMemkindDefault:%d, offsets:dev:%+d host:+%d\n",
__func__, TYPENAME(T), sizeElements, sizeElements / 1024.0 / 1024.0, hmem->_usePinnedHost,
useHostToHost, useDeviceToDevice, useMemkindDefault, dmem->offset(), hmem->offset());
hmem->reset(numElements);
unsigned blocks = HipTest::setNumBlocks(blocksPerCU, threadsPerBlock, numElements);
assert (numElements <= dmem->maxNumElements());
assert (numElements <= hmem->maxNumElements());
assert(numElements <= dmem->maxNumElements());
assert(numElements <= hmem->maxNumElements());
if (useHostToHost) {
// Do some extra host-to-host copies here to mix things up:
HIPCHECK ( hipMemcpy(hmem->A_hh, hmem->A_h(), sizeElements, useMemkindDefault? hipMemcpyDefault : hipMemcpyHostToHost));
HIPCHECK ( hipMemcpy(hmem->B_hh, hmem->B_h(), sizeElements, useMemkindDefault? hipMemcpyDefault : hipMemcpyHostToHost));
HIPCHECK(hipMemcpy(hmem->A_hh, hmem->A_h(), sizeElements,
useMemkindDefault ? hipMemcpyDefault : hipMemcpyHostToHost));
HIPCHECK(hipMemcpy(hmem->B_hh, hmem->B_h(), sizeElements,
useMemkindDefault ? hipMemcpyDefault : hipMemcpyHostToHost));
HIPCHECK ( hipMemcpy(dmem->A_d(), hmem->A_hh, sizeElements, useMemkindDefault ? hipMemcpyDefault : hipMemcpyHostToDevice));
HIPCHECK ( hipMemcpy(dmem->B_d(), hmem->B_hh, sizeElements, useMemkindDefault ? hipMemcpyDefault : hipMemcpyHostToDevice));
HIPCHECK(hipMemcpy(dmem->A_d(), hmem->A_hh, sizeElements,
useMemkindDefault ? hipMemcpyDefault : hipMemcpyHostToDevice));
HIPCHECK(hipMemcpy(dmem->B_d(), hmem->B_hh, sizeElements,
useMemkindDefault ? hipMemcpyDefault : hipMemcpyHostToDevice));
} else {
HIPCHECK ( hipMemcpy(dmem->A_d(), hmem->A_h(), sizeElements, useMemkindDefault ? hipMemcpyDefault : hipMemcpyHostToDevice));
HIPCHECK ( hipMemcpy(dmem->B_d(), hmem->B_h(), sizeElements, useMemkindDefault ? hipMemcpyDefault : hipMemcpyHostToDevice));
HIPCHECK(hipMemcpy(dmem->A_d(), hmem->A_h(), sizeElements,
useMemkindDefault ? hipMemcpyDefault : hipMemcpyHostToDevice));
HIPCHECK(hipMemcpy(dmem->B_d(), hmem->B_h(), sizeElements,
useMemkindDefault ? hipMemcpyDefault : hipMemcpyHostToDevice));
}
hipLaunchKernel(
HipTest::vectorADD,
dim3(blocks),
dim3(threadsPerBlock),
0,
0,
static_cast<const T*>(dmem->A_d()),
static_cast<const T*>(dmem->B_d()),
dmem->C_d(),
numElements);
hipLaunchKernel(HipTest::vectorADD, dim3(blocks), dim3(threadsPerBlock), 0, 0,
static_cast<const T*>(dmem->A_d()), static_cast<const T*>(dmem->B_d()),
dmem->C_d(), numElements);
if (useDeviceToDevice) {
// Do an extra device-to-device copy here to mix things up:
HIPCHECK ( hipMemcpy(dmem->C_dd(), dmem->C_d(), sizeElements, useMemkindDefault? hipMemcpyDefault : hipMemcpyDeviceToDevice));
HIPCHECK(hipMemcpy(dmem->C_dd(), dmem->C_d(), sizeElements,
useMemkindDefault ? hipMemcpyDefault : hipMemcpyDeviceToDevice));
//Destroy the original dmem->C_d():
HIPCHECK ( hipMemset(dmem->C_d(), 0x5A, sizeElements));
// Destroy the original dmem->C_d():
HIPCHECK(hipMemset(dmem->C_d(), 0x5A, sizeElements));
HIPCHECK ( hipMemcpy(hmem->C_h(), dmem->C_dd(), sizeElements, useMemkindDefault? hipMemcpyDefault:hipMemcpyDeviceToHost));
HIPCHECK(hipMemcpy(hmem->C_h(), dmem->C_dd(), sizeElements,
useMemkindDefault ? hipMemcpyDefault : hipMemcpyDeviceToHost));
} else {
HIPCHECK ( hipMemcpy(hmem->C_h(), dmem->C_d(), sizeElements, useMemkindDefault? hipMemcpyDefault:hipMemcpyDeviceToHost));
HIPCHECK(hipMemcpy(hmem->C_h(), dmem->C_d(), sizeElements,
useMemkindDefault ? hipMemcpyDefault : hipMemcpyDeviceToHost));
}
HIPCHECK ( hipDeviceSynchronize() );
HIPCHECK(hipDeviceSynchronize());
HipTest::checkVectorADD(hmem->A_h(), hmem->B_h(), hmem->C_h(), numElements);
printf (" %s success\n", __func__);
printf(" %s success\n", __func__);
}
//---
//Try all the 16 possible combinations to memcpytest2 - usePinnedHost, useHostToHost, useDeviceToDevice, useMemkindDefault
template<typename T>
void memcpytest2_for_type(size_t numElements)
{
// Try all the 16 possible combinations to memcpytest2 - usePinnedHost, useHostToHost,
// useDeviceToDevice, useMemkindDefault
template <typename T>
void memcpytest2_for_type(size_t numElements) {
printSep();
DeviceMemory<T> memD(numElements);
HostMemory<T> memU(numElements, 0/*usePinnedHost*/);
HostMemory<T> memP(numElements, 1/*usePinnedHost*/);
HostMemory<T> memU(numElements, 0 /*usePinnedHost*/);
HostMemory<T> memP(numElements, 1 /*usePinnedHost*/);
for (int usePinnedHost =0; usePinnedHost<=1; usePinnedHost++) {
for (int useHostToHost =0; useHostToHost<=1; useHostToHost++) { // TODO
for (int useDeviceToDevice =0; useDeviceToDevice<=1; useDeviceToDevice++) {
for (int useMemkindDefault =0; useMemkindDefault<=1; useMemkindDefault++) {
memcpytest2<T>(&memD, usePinnedHost ? &memP : &memU, numElements, useHostToHost, useDeviceToDevice, useMemkindDefault);
for (int usePinnedHost = 0; usePinnedHost <= 1; usePinnedHost++) {
for (int useHostToHost = 0; useHostToHost <= 1; useHostToHost++) { // TODO
for (int useDeviceToDevice = 0; useDeviceToDevice <= 1; useDeviceToDevice++) {
for (int useMemkindDefault = 0; useMemkindDefault <= 1; useMemkindDefault++) {
memcpytest2<T>(&memD, usePinnedHost ? &memP : &memU, numElements, useHostToHost,
useDeviceToDevice, useMemkindDefault);
}
}
}
@@ -297,12 +282,11 @@ void memcpytest2_for_type(size_t numElements)
//---
//Try many different sizes to memory copy.
template<typename T>
void memcpytest2_sizes(size_t maxElem=0)
{
// Try many different sizes to memory copy.
template <typename T>
void memcpytest2_sizes(size_t maxElem = 0) {
printSep();
printf ("test: %s<%s>\n", __func__, TYPENAME(T));
printf("test: %s<%s>\n", __func__, TYPENAME(T));
int deviceId;
HIPCHECK(hipGetDevice(&deviceId));
@@ -311,17 +295,19 @@ void memcpytest2_sizes(size_t maxElem=0)
HIPCHECK(hipMemGetInfo(&free, &total));
if (maxElem == 0) {
maxElem = free/sizeof(T)/8;
maxElem = free / sizeof(T) / 8;
}
printf (" device#%d: hipMemGetInfo: free=%zu (%4.2fMB) total=%zu (%4.2fMB) maxSize=%6.1fMB\n",
deviceId, free, (float)(free/1024.0/1024.0), total, (float)(total/1024.0/1024.0), maxElem*sizeof(T)/1024.0/1024.0);
HIPCHECK ( hipDeviceReset() );
printf(
" device#%d: hipMemGetInfo: free=%zu (%4.2fMB) total=%zu (%4.2fMB) maxSize=%6.1fMB\n",
deviceId, free, (float)(free / 1024.0 / 1024.0), total, (float)(total / 1024.0 / 1024.0),
maxElem * sizeof(T) / 1024.0 / 1024.0);
HIPCHECK(hipDeviceReset());
DeviceMemory<T> memD(maxElem);
HostMemory<T> memU(maxElem, 0/*usePinnedHost*/);
HostMemory<T> memP(maxElem, 1/*usePinnedHost*/);
HostMemory<T> memU(maxElem, 0 /*usePinnedHost*/);
HostMemory<T> memP(maxElem, 1 /*usePinnedHost*/);
for (size_t elem=1; elem<=maxElem; elem*=2) {
for (size_t elem = 1; elem <= maxElem; elem *= 2) {
memcpytest2<T>(&memD, &memU, elem, 1, 1, 0); // unpinned host
memcpytest2<T>(&memD, &memP, elem, 1, 1, 0); // pinned host
}
@@ -329,12 +315,11 @@ void memcpytest2_sizes(size_t maxElem=0)
//---
//Try many different sizes to memory copy.
template<typename T>
void memcpytest2_offsets(size_t maxElem, bool devOffsets, bool hostOffsets)
{
// Try many different sizes to memory copy.
template <typename T>
void memcpytest2_offsets(size_t maxElem, bool devOffsets, bool hostOffsets) {
printSep();
printf ("test: %s<%s>\n", __func__, TYPENAME(T));
printf("test: %s<%s>\n", __func__, TYPENAME(T));
int deviceId;
HIPCHECK(hipGetDevice(&deviceId));
@@ -343,17 +328,19 @@ void memcpytest2_offsets(size_t maxElem, bool devOffsets, bool hostOffsets)
HIPCHECK(hipMemGetInfo(&free, &total));
printf (" device#%d: hipMemGetInfo: free=%zu (%4.2fMB) total=%zu (%4.2fMB) maxSize=%6.1fMB\n",
deviceId, free, (float)(free/1024.0/1024.0), total, (float)(total/1024.0/1024.0), maxElem*sizeof(T)/1024.0/1024.0);
HIPCHECK ( hipDeviceReset() );
printf(
" device#%d: hipMemGetInfo: free=%zu (%4.2fMB) total=%zu (%4.2fMB) maxSize=%6.1fMB\n",
deviceId, free, (float)(free / 1024.0 / 1024.0), total, (float)(total / 1024.0 / 1024.0),
maxElem * sizeof(T) / 1024.0 / 1024.0);
HIPCHECK(hipDeviceReset());
DeviceMemory<T> memD(maxElem);
HostMemory<T> memU(maxElem, 0/*usePinnedHost*/);
HostMemory<T> memP(maxElem, 1/*usePinnedHost*/);
HostMemory<T> memU(maxElem, 0 /*usePinnedHost*/);
HostMemory<T> memP(maxElem, 1 /*usePinnedHost*/);
size_t elem = maxElem / 2;
for (int offset=0; offset < 512; offset++) {
assert (elem + offset < maxElem);
for (int offset = 0; offset < 512; offset++) {
assert(elem + offset < maxElem);
if (devOffsets) {
memD.offset(offset);
}
@@ -365,8 +352,8 @@ void memcpytest2_offsets(size_t maxElem, bool devOffsets, bool hostOffsets)
memcpytest2<T>(&memD, &memP, elem, 1, 1, 0); // pinned host
}
for (int offset=512; offset < elem; offset*=2) {
assert (elem + offset < maxElem);
for (int offset = 512; offset < elem; offset *= 2) {
assert(elem + offset < maxElem);
if (devOffsets) {
memD.offset(offset);
}
@@ -381,23 +368,24 @@ void memcpytest2_offsets(size_t maxElem, bool devOffsets, bool hostOffsets)
//---
//Create multiple threads to stress multi-thread locking behavior in the allocation/deallocation/tracking logic:
template<typename T>
void multiThread_1(bool serialize, bool usePinnedHost)
{
// Create multiple threads to stress multi-thread locking behavior in the
// allocation/deallocation/tracking logic:
template <typename T>
void multiThread_1(bool serialize, bool usePinnedHost) {
printSep();
printf ("test: %s<%s> serialize=%d usePinnedHost=%d\n", __func__, TYPENAME(T), serialize, usePinnedHost);
printf("test: %s<%s> serialize=%d usePinnedHost=%d\n", __func__, TYPENAME(T), serialize,
usePinnedHost);
DeviceMemory<T> memD(N);
HostMemory<T> mem1(N, usePinnedHost);
HostMemory<T> mem2(N, usePinnedHost);
std::thread t1 (memcpytest2<T>, &memD, &mem1, N, 0,0,0);
std::thread t1(memcpytest2<T>, &memD, &mem1, N, 0, 0, 0);
if (serialize) {
t1.join();
}
std::thread t2 (memcpytest2<T>,&memD, &mem2, N, 0,0,0);
std::thread t2(memcpytest2<T>, &memD, &mem2, N, 0, 0, 0);
if (serialize) {
t2.join();
}
@@ -409,64 +397,57 @@ void multiThread_1(bool serialize, bool usePinnedHost)
}
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));
if (p_tests & 0x1) {
printf ("\n\n=== tests&1 (types and different memcpy kinds (H2D, D2H, H2H, D2D)\n");
HIPCHECK ( hipDeviceReset() );
printf("\n\n=== tests&1 (types and different memcpy kinds (H2D, D2H, H2H, D2D)\n");
HIPCHECK(hipDeviceReset());
memcpytest2_for_type<float>(N);
memcpytest2_for_type<double>(N);
memcpytest2_for_type<char>(N);
memcpytest2_for_type<int>(N);
printf ("===\n\n\n");
printf("===\n\n\n");
}
if (p_tests & 0x2) {
// Some tests around the 64KB boundary which have historically shown issues:
printf ("\n\n=== tests&0x2 (64KB boundary)\n");
size_t maxElem = 32*1024*1024;
printf("\n\n=== tests&0x2 (64KB boundary)\n");
size_t maxElem = 32 * 1024 * 1024;
DeviceMemory<float> memD(maxElem);
HostMemory<float> memU(maxElem, 0/*usePinnedHost*/);
HostMemory<float> memP(maxElem, 0/*usePinnedHost*/);
HostMemory<float> memU(maxElem, 0 /*usePinnedHost*/);
HostMemory<float> memP(maxElem, 0 /*usePinnedHost*/);
// These all pass:
memcpytest2<float>(&memD, &memP, 15*1024*1024, 0, 0, 0);
memcpytest2<float>(&memD, &memP, 16*1024*1024, 0, 0, 0);
memcpytest2<float>(&memD, &memP, 16*1024*1024+16*1024, 0, 0, 0);
memcpytest2<float>(&memD, &memP, 15 * 1024 * 1024, 0, 0, 0);
memcpytest2<float>(&memD, &memP, 16 * 1024 * 1024, 0, 0, 0);
memcpytest2<float>(&memD, &memP, 16 * 1024 * 1024 + 16 * 1024, 0, 0, 0);
// Just over 64MB:
memcpytest2<float>(&memD, &memP, 16*1024*1024+512*1024, 0, 0, 0);
memcpytest2<float>(&memD, &memP, 17*1024*1024+1024, 0, 0, 0);
memcpytest2<float>(&memD, &memP, 32*1024*1024, 0, 0, 0);
memcpytest2<float>(&memD, &memU, 32*1024*1024, 0, 0, 0);
memcpytest2<float>(&memD, &memP, 32*1024*1024, 1, 1, 0);
memcpytest2<float>(&memD, &memP, 32*1024*1024, 1, 1, 0);
memcpytest2<float>(&memD, &memP, 16 * 1024 * 1024 + 512 * 1024, 0, 0, 0);
memcpytest2<float>(&memD, &memP, 17 * 1024 * 1024 + 1024, 0, 0, 0);
memcpytest2<float>(&memD, &memP, 32 * 1024 * 1024, 0, 0, 0);
memcpytest2<float>(&memD, &memU, 32 * 1024 * 1024, 0, 0, 0);
memcpytest2<float>(&memD, &memP, 32 * 1024 * 1024, 1, 1, 0);
memcpytest2<float>(&memD, &memP, 32 * 1024 * 1024, 1, 1, 0);
}
if (p_tests & 0x4) {
printf ("\n\n=== tests&4 (test sizes)\n");
HIPCHECK ( hipDeviceReset() );
printf("\n\n=== tests&4 (test sizes)\n");
HIPCHECK(hipDeviceReset());
memcpytest2_sizes<float>(0);
printSep();
}
if (p_tests & 0x8) {
printf ("\n\n=== tests&8\n");
HIPCHECK ( hipDeviceReset() );
printf("\n\n=== tests&8\n");
HIPCHECK(hipDeviceReset());
printSep();
// Simplest cases: serialize the threads, and also used pinned memory:
@@ -480,32 +461,30 @@ int main(int argc, char *argv[])
multiThread_1<float>(false, true);
// Remove serialization, and use unpinned.
multiThread_1<float>(false, false); // TODO
printf ("===\n\n\n");
multiThread_1<float>(false, false); // TODO
printf("===\n\n\n");
}
if (p_tests & 0x10) {
printf ("\n\n=== tests&0x10 (test device offsets)\n");
HIPCHECK ( hipDeviceReset() );
size_t maxSize = 256*1024;
memcpytest2_offsets<char> (maxSize, true, false);
memcpytest2_offsets<float> (maxSize, true, false);
printf("\n\n=== tests&0x10 (test device offsets)\n");
HIPCHECK(hipDeviceReset());
size_t maxSize = 256 * 1024;
memcpytest2_offsets<char>(maxSize, true, false);
memcpytest2_offsets<float>(maxSize, true, false);
memcpytest2_offsets<double>(maxSize, true, false);
}
if (p_tests & 0x20) {
printf ("\n\n=== tests&0x10 (test device offsets)\n");
HIPCHECK ( hipDeviceReset() );
size_t maxSize = 256*1024;
memcpytest2_offsets<char> (maxSize, false, true);
memcpytest2_offsets<float> (maxSize, false, true);
printf("\n\n=== tests&0x10 (test device offsets)\n");
HIPCHECK(hipDeviceReset());
size_t maxSize = 256 * 1024;
memcpytest2_offsets<char>(maxSize, false, true);
memcpytest2_offsets<float>(maxSize, false, true);
memcpytest2_offsets<double>(maxSize, false, true);
}
passed();
}
@@ -23,112 +23,106 @@ THE SOFTWARE.
*/
#include "hip/hip_runtime.h"
#include<iostream>
#include<assert.h>
#include"test_common.h"
#include <iostream>
#include <assert.h>
#include "test_common.h"
#define len 1024*1024
#define len 1024 * 1024
#define size len * sizeof(float)
template<typename T>
void hmemset(T *ptr, T value)
{
for(int i=0;i<len;i++){
ptr[i] = value;
}
template <typename T>
void hmemset(T* ptr, T value) {
for (int i = 0; i < len; i++) {
ptr[i] = value;
}
}
int main(){
int main() {
int num;
hipGetDeviceCount(&num);
if (num < 2) {
printf("warning: Not enough GPUs to run the test, exiting without running.\n");
passed();
return 0;
}
int num;
hipGetDeviceCount(&num);
if(num < 2)
{
printf ("warning: Not enough GPUs to run the test, exiting without running.\n");
float *h0, *h1;
float *ph0, *ph1;
float *d0, *d1;
h0 = new float[len];
h1 = new float[len];
hmemset(h0, 1.0f);
int gpu0 = 0, gpu1 = 1;
hipSetDevice(gpu0);
hipHostMalloc((void**)&ph0, size);
hipMalloc(&d0, size);
hipSetDevice(gpu1);
hipHostMalloc((void**)&ph1, size);
hipMalloc(&d1, size);
hipSetDevice(gpu0);
hipMemcpy(h1, h0, size, hipMemcpyDefault);
hipMemcpy(ph0, h1, size, hipMemcpyDefault);
hipMemcpy(ph1, ph0, size, hipMemcpyDefault);
assert(h0[0] == ph1[0]);
hmemset(ph1, 0.0f);
hipMemcpy(h0, ph1, size, hipMemcpyDefault);
assert(h0[0] == 0.0f);
hipSetDevice(gpu0);
hmemset(ph0, 2.0f);
hipMemcpy(d0, ph0, size, hipMemcpyDefault);
hipMemcpy(h0, d0, size, hipMemcpyDefault);
assert(h0[0] == ph0[0]);
hmemset(h0, 3.0f);
hipMemcpy(d0, h0, size, hipMemcpyDefault);
hipMemcpy(ph0, d0, size, hipMemcpyDefault);
assert(h0[0] == ph0[0]);
hipSetDevice(gpu1);
hmemset(ph1, 2.0f);
hipMemcpy(d1, ph1, size, hipMemcpyDefault);
hipMemcpy(h1, d1, size, hipMemcpyDefault);
assert(h1[0] == ph1[0]);
hmemset(h1, 3.0f);
hipMemcpy(d1, h1, size, hipMemcpyDefault);
hipMemcpy(ph1, d1, size, hipMemcpyDefault);
assert(h1[0] == ph1[0]);
hipSetDevice(gpu0);
hmemset(ph0, 4.0f);
hipMemcpy(d0, ph0, size, hipMemcpyDefault);
hipMemcpy(ph0, d0, size, hipMemcpyDefault);
hipMemcpy(h0, d0, size, hipMemcpyDefault);
assert(ph0[0] == 4.0f);
assert(h0[0] == 4.0f);
hipSetDevice(gpu1);
hmemset(ph1, 5.0f);
hipMemcpy(d1, ph1, size, hipMemcpyDefault);
hipMemcpy(ph1, d1, size, hipMemcpyDefault);
hipMemcpy(h1, d1, size, hipMemcpyDefault);
assert(ph1[0] == 5.0f);
assert(h1[0] == 5.0f);
hipSetDevice(gpu0);
hipMemcpy(d0, ph1, size, hipMemcpyDefault);
hipMemcpy(d1, d0, size, hipMemcpyDefault);
passed();
return 0;
}
float *h0, *h1;
float *ph0, *ph1;
float *d0, *d1;
h0 = new float[len];
h1 = new float[len];
hmemset(h0, 1.0f);
int gpu0 = 0, gpu1 = 1;
hipSetDevice(gpu0);
hipHostMalloc((void**)&ph0, size);
hipMalloc(&d0, size);
hipSetDevice(gpu1);
hipHostMalloc((void**)&ph1, size);
hipMalloc(&d1, size);
hipSetDevice(gpu0);
hipMemcpy(h1, h0, size, hipMemcpyDefault);
hipMemcpy(ph0, h1, size, hipMemcpyDefault);
hipMemcpy(ph1, ph0, size, hipMemcpyDefault);
assert(h0[0] == ph1[0]);
hmemset(ph1, 0.0f);
hipMemcpy(h0, ph1, size, hipMemcpyDefault);
assert(h0[0] == 0.0f);
hipSetDevice(gpu0);
hmemset(ph0, 2.0f);
hipMemcpy(d0, ph0, size, hipMemcpyDefault);
hipMemcpy(h0, d0, size, hipMemcpyDefault);
assert(h0[0] == ph0[0]);
hmemset(h0, 3.0f);
hipMemcpy(d0, h0, size, hipMemcpyDefault);
hipMemcpy(ph0, d0, size, hipMemcpyDefault);
assert(h0[0] == ph0[0]);
hipSetDevice(gpu1);
hmemset(ph1, 2.0f);
hipMemcpy(d1, ph1, size, hipMemcpyDefault);
hipMemcpy(h1, d1, size, hipMemcpyDefault);
assert(h1[0] == ph1[0]);
hmemset(h1, 3.0f);
hipMemcpy(d1, h1, size, hipMemcpyDefault);
hipMemcpy(ph1, d1, size, hipMemcpyDefault);
assert(h1[0] == ph1[0]);
hipSetDevice(gpu0);
hmemset(ph0, 4.0f);
hipMemcpy(d0, ph0, size, hipMemcpyDefault);
hipMemcpy(ph0, d0, size, hipMemcpyDefault);
hipMemcpy(h0, d0, size, hipMemcpyDefault);
assert(ph0[0] == 4.0f);
assert(h0[0] == 4.0f);
hipSetDevice(gpu1);
hmemset(ph1, 5.0f);
hipMemcpy(d1, ph1, size, hipMemcpyDefault);
hipMemcpy(ph1, d1, size, hipMemcpyDefault);
hipMemcpy(h1, d1, size, hipMemcpyDefault);
assert(ph1[0] == 5.0f);
assert(h1[0] == 5.0f);
hipSetDevice(gpu0);
hipMemcpy(d0, ph1, size, hipMemcpyDefault);
hipMemcpy(d1, d0, size, hipMemcpyDefault);
passed();
}
@@ -24,13 +24,12 @@ THE SOFTWARE.
unsigned p_streams = 2;
void simpleNegTest()
{
printf ("testing: %s\n",__func__);
void simpleNegTest() {
printf("testing: %s\n", __func__);
hipError_t e;
float *A_malloc, *A_pinned, *A_d;
size_t Nbytes = N*sizeof(float);
size_t Nbytes = N * sizeof(float);
A_malloc = (float*)malloc(Nbytes);
HIPCHECK(hipHostMalloc((void**)&A_pinned, Nbytes, hipHostMallocDefault));
A_d = NULL;
@@ -38,68 +37,70 @@ void simpleNegTest()
HIPASSERT(A_d != NULL);
// Can't use default with async copy
e = hipMemcpyAsync(A_pinned, A_d, Nbytes, hipMemcpyDefault, NULL);
// HIPASSERT (e == hipSuccess);
// HIPASSERT (e == hipSuccess);
// Not sure what happens here, the memory must be pinned.
e = hipMemcpyAsync(A_malloc, A_d, Nbytes, hipMemcpyHostToDevice, NULL);
printf (" async memcpy of A_malloc to A_d. Result=%d\n", e);
//HIPASSERT (e==hipErrorInvalidValue);
printf(" async memcpy of A_malloc to A_d. Result=%d\n", e);
// HIPASSERT (e==hipErrorInvalidValue);
}
class Pinned;
class Unpinned;
template <typename T> struct HostTraits;
template <typename T>
struct HostTraits;
template<>
struct HostTraits<Pinned>
{
static const char *Name() { return "Pinned"; } ;
template <>
struct HostTraits<Pinned> {
static const char* Name() { return "Pinned"; };
static void *Alloc(size_t sizeBytes) {
void *p;
static void* Alloc(size_t sizeBytes) {
void* p;
HIPCHECK(hipHostMalloc((void**)&p, sizeBytes, hipHostMallocDefault));
return p;
};
};
template<typename T>
__global__ void
addK (hipLaunchParm lp, T *A, T K, size_t numElements)
{
template <typename T>
__global__ void addK(hipLaunchParm lp, T* A, T K, size_t numElements) {
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<numElements; i+=stride) {
for (size_t i = offset; i < numElements; i += stride) {
A[i] = A[i] + K;
}
}
}
//---
//Tests propert dependency resolution between H2D and D2H commands in same stream:
//IN: numInflight : number of copies inflight at any time:
//IN: numPongs = number of iterations to run (iteration)
template<typename T, class AllocType>
void test_pingpong(hipStream_t stream, size_t numElements, int numInflight, int numPongs, bool doHostSide)
{
HIPASSERT(numElements % numInflight == 0); // Must be evenly divisible.
size_t Nbytes = numElements*sizeof(T);
// Tests propert dependency resolution between H2D and D2H commands in same stream:
// IN: numInflight : number of copies inflight at any time:
// IN: numPongs = number of iterations to run (iteration)
template <typename T, class AllocType>
void test_pingpong(hipStream_t stream, size_t numElements, int numInflight, int numPongs,
bool doHostSide) {
HIPASSERT(numElements % numInflight == 0); // Must be evenly divisible.
size_t Nbytes = numElements * sizeof(T);
size_t eachCopyElements = numElements / numInflight;
size_t eachCopyBytes = eachCopyElements * sizeof(T);
unsigned blocks = HipTest::setNumBlocks(blocksPerCU, threadsPerBlock, numElements);
printf ("-----------------------------------------------------------------------------------------------\n");
printf ("testing: %s<%s> Nbytes=%zu (%6.1f MB) numPongs=%d numInflight=%d eachCopyElements=%zu eachCopyBytes=%zu\n",
__func__, HostTraits<AllocType>::Name(), Nbytes, (double)(Nbytes)/1024.0/1024.0, numPongs, numInflight, eachCopyElements, eachCopyBytes);
printf(
"------------------------------------------------------------------------------------------"
"-----\n");
printf(
"testing: %s<%s> Nbytes=%zu (%6.1f MB) numPongs=%d numInflight=%d eachCopyElements=%zu "
"eachCopyBytes=%zu\n",
__func__, HostTraits<AllocType>::Name(), Nbytes, (double)(Nbytes) / 1024.0 / 1024.0,
numPongs, numInflight, eachCopyElements, eachCopyBytes);
T *A_h = NULL;
T *A_d = NULL;
T* A_h = NULL;
T* A_d = NULL;
A_h = (T*)(HostTraits<AllocType>::Alloc(Nbytes));
HIPCHECK(hipMalloc(&A_d, Nbytes));
@@ -108,22 +109,25 @@ void test_pingpong(hipStream_t stream, size_t numElements, int numInflight, int
const T initValue = 13;
const T deviceConst = 2;
const T hostConst = 10000;
for (size_t i=0; i<numElements; i++) {
for (size_t i = 0; i < numElements; i++) {
A_h[i] = initValue + i;
}
for (int k=0; k<numPongs; k++ ) {
for (int i=0; i<numInflight; i++) {
HIPASSERT(A_d + i*eachCopyElements < A_d + Nbytes);
HIPCHECK(hipMemcpyAsync(&A_d[i*eachCopyElements], &A_h[i*eachCopyElements], eachCopyBytes, hipMemcpyHostToDevice, stream));
for (int k = 0; k < numPongs; k++) {
for (int i = 0; i < numInflight; i++) {
HIPASSERT(A_d + i * eachCopyElements < A_d + Nbytes);
HIPCHECK(hipMemcpyAsync(&A_d[i * eachCopyElements], &A_h[i * eachCopyElements],
eachCopyBytes, hipMemcpyHostToDevice, stream));
}
hipLaunchKernel(addK<T>, dim3(blocks), dim3(threadsPerBlock), 0, stream, A_d, 2, numElements);
hipLaunchKernel(addK<T>, dim3(blocks), dim3(threadsPerBlock), 0, stream, A_d, 2,
numElements);
for (int i=0; i<numInflight; i++ ) {
HIPASSERT(A_d + i*eachCopyElements < A_d + Nbytes);
HIPCHECK(hipMemcpyAsync(&A_h[i*eachCopyElements], &A_d[i*eachCopyElements], eachCopyBytes, hipMemcpyDeviceToHost, stream));
for (int i = 0; i < numInflight; i++) {
HIPASSERT(A_d + i * eachCopyElements < A_d + Nbytes);
HIPCHECK(hipMemcpyAsync(&A_h[i * eachCopyElements], &A_d[i * eachCopyElements],
eachCopyBytes, hipMemcpyDeviceToHost, stream));
}
if (doHostSide) {
@@ -133,7 +137,7 @@ void test_pingpong(hipStream_t stream, size_t numElements, int numInflight, int
HIPCHECK(hipEventCreate(&e));
#endif
HIPCHECK(hipDeviceSynchronize());
for (size_t i=0; i<numElements; i++) {
for (size_t i = 0; i < numElements; i++) {
A_h[i] += hostConst;
}
}
@@ -143,10 +147,10 @@ void test_pingpong(hipStream_t stream, size_t numElements, int numInflight, int
// Verify we copied back all the data correctly:
for (size_t i=0; i<numElements; i++) {
for (size_t i = 0; i < numElements; i++) {
T gold = initValue + i;
// Perform calcs in same order as test above to replicate FP order-of-operations:
for (int k=0; k<numPongs; k++) {
for (int k = 0; k < numPongs; k++) {
gold += deviceConst;
if (doHostSide) {
gold += hostConst;
@@ -166,55 +170,60 @@ void test_pingpong(hipStream_t stream, size_t numElements, int numInflight, int
//---
//Send many async copies to the same stream.
//This requires runtime to keep track of many outstanding commands, and in the case of HCC requires growing/tracking the signal pool:
template<typename T>
void test_manyInflightCopies(hipStream_t stream, int numElements, int numCopies, bool syncBetweenCopies)
{
size_t Nbytes = numElements*sizeof(T);
// Send many async copies to the same stream.
// This requires runtime to keep track of many outstanding commands, and in the case of HCC requires
// growing/tracking the signal pool:
template <typename T>
void test_manyInflightCopies(hipStream_t stream, int numElements, int numCopies,
bool syncBetweenCopies) {
size_t Nbytes = numElements * sizeof(T);
size_t eachCopyElements = numElements / numCopies;
size_t eachCopyBytes = eachCopyElements * sizeof(T);
printf ("-----------------------------------------------------------------------------------------------\n");
printf ("testing: %s Nbytes=%zu (%6.1f MB) numCopies=%d eachCopyElements=%zu eachCopyBytes=%zu\n",
__func__, Nbytes, (double)(Nbytes)/1024.0/1024.0, numCopies, eachCopyElements, eachCopyBytes);
printf(
"------------------------------------------------------------------------------------------"
"-----\n");
printf(
"testing: %s Nbytes=%zu (%6.1f MB) numCopies=%d eachCopyElements=%zu eachCopyBytes=%zu\n",
__func__, Nbytes, (double)(Nbytes) / 1024.0 / 1024.0, numCopies, eachCopyElements,
eachCopyBytes);
T *A_d;
T* A_d;
T *A_h1, *A_h2;
HIPCHECK(hipHostMalloc((void**)&A_h1, Nbytes, hipHostMallocDefault));
HIPCHECK(hipHostMalloc((void**)&A_h2, Nbytes, hipHostMallocDefault));
HIPCHECK(hipMalloc(&A_d, Nbytes));
for (int i=0; i<numElements; i++) {
A_h1[i] = 3.14f + static_cast<T> (i);
for (int i = 0; i < numElements; i++) {
A_h1[i] = 3.14f + static_cast<T>(i);
}
//stream=0; // fixme TODO
// stream=0; // fixme TODO
for (int i=0; i<numCopies; i++)
{
HIPASSERT(A_d + i*eachCopyElements < A_d + Nbytes);
HIPCHECK(hipMemcpyAsync(&A_d[i*eachCopyElements], &A_h1[i*eachCopyElements], eachCopyBytes, hipMemcpyHostToDevice, stream));
for (int i = 0; i < numCopies; i++) {
HIPASSERT(A_d + i * eachCopyElements < A_d + Nbytes);
HIPCHECK(hipMemcpyAsync(&A_d[i * eachCopyElements], &A_h1[i * eachCopyElements],
eachCopyBytes, hipMemcpyHostToDevice, stream));
}
if (syncBetweenCopies) {
HIPCHECK(hipDeviceSynchronize());
}
for (int i=0; i<numCopies; i++)
{
HIPASSERT(A_d + i*eachCopyElements < A_d + Nbytes);
HIPCHECK(hipMemcpyAsync(&A_h2[i*eachCopyElements], &A_d[i*eachCopyElements], eachCopyBytes, hipMemcpyDeviceToHost, stream));
for (int i = 0; i < numCopies; i++) {
HIPASSERT(A_d + i * eachCopyElements < A_d + Nbytes);
HIPCHECK(hipMemcpyAsync(&A_h2[i * eachCopyElements], &A_d[i * eachCopyElements],
eachCopyBytes, hipMemcpyDeviceToHost, stream));
}
HIPCHECK(hipDeviceSynchronize());
// Verify we copied back all the data correctly:
for (int i=0; i<numElements; i++) {
for (int i = 0; i < numElements; i++) {
HIPASSERT(A_h1[i] == A_h2[i]);
}
@@ -226,38 +235,38 @@ void test_manyInflightCopies(hipStream_t stream, int numElements, int numCopies,
//---
//Classic example showing how to overlap data transfer with compute.
//We divide the work into "chunks" and create a stream for each chunk.
//Each chunk then runs a H2D copy, followed by kernel execution, followed by D2H copyback.
//Work in separate streams is independent which enables concurrency.
// Classic example showing how to overlap data transfer with compute.
// We divide the work into "chunks" and create a stream for each chunk.
// Each chunk then runs a H2D copy, followed by kernel execution, followed by D2H copyback.
// Work in separate streams is independent which enables concurrency.
// IN: nStreams : number of streams to use for the test
// IN :useNullStream - use NULL stream. Synchronizes everything.
// IN: useSyncMemcpyH2D - use sync memcpy (no overlap) for H2D
// IN: useSyncMemcpyD2H - use sync memcpy (no overlap) for D2H
void test_chunkedAsyncExample(int nStreams, bool useNullStream, bool useSyncMemcpyH2D, bool useSyncMemcpyD2H)
{
size_t Nbytes = N*sizeof(int);
printf ("testing: %s(useNullStream=%d, useSyncMemcpyH2D=%d, useSyncMemcpyD2H=%d) ",__func__, useNullStream, useSyncMemcpyH2D, useSyncMemcpyD2H);
printf ("Nbytes=%zu (%6.1f MB)\n", Nbytes, (double)(Nbytes)/1024.0/1024.0);
void test_chunkedAsyncExample(int nStreams, bool useNullStream, bool useSyncMemcpyH2D,
bool useSyncMemcpyD2H) {
size_t Nbytes = N * sizeof(int);
printf("testing: %s(useNullStream=%d, useSyncMemcpyH2D=%d, useSyncMemcpyD2H=%d) ", __func__,
useNullStream, useSyncMemcpyH2D, useSyncMemcpyD2H);
printf("Nbytes=%zu (%6.1f MB)\n", Nbytes, (double)(Nbytes) / 1024.0 / 1024.0);
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, true);
HipTest::initArrays(&A_d, &B_d, &C_d, &A_h, &B_h, &C_h, N, true);
unsigned blocks = HipTest::setNumBlocks(blocksPerCU, threadsPerBlock, N);
hipStream_t *stream = (hipStream_t*)malloc(sizeof(hipStream_t) * nStreams);
hipStream_t* stream = (hipStream_t*)malloc(sizeof(hipStream_t) * nStreams);
if (useNullStream) {
nStreams = 1;
stream[0] = NULL;
} else {
} else {
for (int i = 0; i < nStreams; ++i) {
HIPCHECK (hipStreamCreate(&stream[i]));
HIPCHECK(hipStreamCreate(&stream[i]));
}
}
@@ -268,52 +277,55 @@ void test_chunkedAsyncExample(int nStreams, bool useNullStream, bool useSyncMemc
size_t work = (workLeft < workPerStream) ? workLeft : workPerStream;
size_t workBytes = work * sizeof(int);
size_t offset = i*workPerStream;
size_t offset = i * workPerStream;
HIPASSERT(A_d + offset < A_d + Nbytes);
HIPASSERT(B_d + offset < B_d + Nbytes);
HIPASSERT(C_d + offset < C_d + Nbytes);
if (useSyncMemcpyH2D) {
HIPCHECK ( hipMemcpy(&A_d[offset], &A_h[offset], workBytes, hipMemcpyHostToDevice));
HIPCHECK ( hipMemcpy(&B_d[offset], &B_h[offset], workBytes, hipMemcpyHostToDevice));
HIPCHECK(hipMemcpy(&A_d[offset], &A_h[offset], workBytes, hipMemcpyHostToDevice));
HIPCHECK(hipMemcpy(&B_d[offset], &B_h[offset], workBytes, hipMemcpyHostToDevice));
} else {
HIPCHECK ( hipMemcpyAsync(&A_d[offset], &A_h[offset], workBytes, hipMemcpyHostToDevice, stream[i]));
HIPCHECK ( hipMemcpyAsync(&B_d[offset], &B_h[offset], workBytes, hipMemcpyHostToDevice, stream[i]));
HIPCHECK(hipMemcpyAsync(&A_d[offset], &A_h[offset], workBytes, hipMemcpyHostToDevice,
stream[i]));
HIPCHECK(hipMemcpyAsync(&B_d[offset], &B_h[offset], workBytes, hipMemcpyHostToDevice,
stream[i]));
};
hipLaunchKernel(HipTest::vectorADD, dim3(blocks), dim3(threadsPerBlock), 0, stream[i], &A_d[offset], &B_d[offset], &C_d[offset], work);
hipLaunchKernel(HipTest::vectorADD, dim3(blocks), dim3(threadsPerBlock), 0, stream[i],
&A_d[offset], &B_d[offset], &C_d[offset], work);
if (useSyncMemcpyD2H) {
HIPCHECK ( hipMemcpy(&C_h[offset], &C_d[offset], workBytes, hipMemcpyDeviceToHost));
HIPCHECK(hipMemcpy(&C_h[offset], &C_d[offset], workBytes, hipMemcpyDeviceToHost));
} else {
HIPCHECK ( hipMemcpyAsync(&C_h[offset], &C_d[offset], workBytes, hipMemcpyDeviceToHost, stream[i]));
HIPCHECK(hipMemcpyAsync(&C_h[offset], &C_d[offset], workBytes, hipMemcpyDeviceToHost,
stream[i]));
}
}
HIPCHECK (hipDeviceSynchronize());
HIPCHECK(hipDeviceSynchronize());
HipTest::checkVectorADD(A_h, B_h, C_h, N);
HipTest::freeArrays (A_d, B_d, C_d, A_h, B_h, C_h, true);
HipTest::freeArrays(A_d, B_d, C_d, A_h, B_h, C_h, true);
free(stream);
};
//---
//Parse arguments specific to this test.
void parseMyArguments(int argc, char *argv[])
{
// Parse arguments specific to this test.
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, "--streams")) {
if (++i >= argc || !HipTest::parseUInt(argv[i], &p_streams)) {
failed("Bad streams argument");
failed("Bad streams argument");
}
} else {
failed("Bad argument '%s'", arg);
@@ -322,15 +334,12 @@ void parseMyArguments(int argc, char *argv[])
};
int main(int argc, char *argv[])
{
int main(int argc, char* argv[]) {
HipTest::parseStandardArguments(argc, argv, false);
parseMyArguments(argc, argv);
printf ("info: set device to %d tests=%x\n", p_gpuDevice, p_tests);
printf("info: set device to %d tests=%x\n", p_gpuDevice, p_tests);
HIPCHECK(hipSetDevice(p_gpuDevice));
if (p_tests & 0x01) {
@@ -339,34 +348,34 @@ int main(int argc, char *argv[])
if (p_tests & 0x02) {
hipStream_t stream;
HIPCHECK (hipStreamCreate(&stream));
HIPCHECK(hipStreamCreate(&stream));
test_manyInflightCopies<float>(stream, 1024, 16, true);
test_manyInflightCopies<float>(stream, 1024, 4, true); // verify we re-use the same entries instead of growing pool.
test_manyInflightCopies<float>(stream, 1024*8, 64, false);
test_manyInflightCopies<float>(stream, 1024, 16, true);
test_manyInflightCopies<float>(
stream, 1024, 4, true); // verify we re-use the same entries instead of growing pool.
test_manyInflightCopies<float>(stream, 1024 * 8, 64, false);
HIPCHECK(hipStreamDestroy(stream));
}
if (p_tests & 0x04) {
test_chunkedAsyncExample(p_streams, true, true, true); // Easy sync version
test_chunkedAsyncExample(p_streams, false, true, true); // Easy sync version
test_chunkedAsyncExample(p_streams, false, false, true); // Some async
test_chunkedAsyncExample(p_streams, false, false, false); // All async
test_chunkedAsyncExample(p_streams, true, true, true); // Easy sync version
test_chunkedAsyncExample(p_streams, false, true, true); // Easy sync version
test_chunkedAsyncExample(p_streams, false, false, true); // Some async
test_chunkedAsyncExample(p_streams, false, false, false); // All async
}
if (p_tests & 0x08) {
hipStream_t stream;
HIPCHECK (hipStreamCreate(&stream));
HIPCHECK(hipStreamCreate(&stream));
// test_pingpong<int, Pinned>(stream, 1024*1024*32, 1, 1, false);
// test_pingpong<int, Pinned>(stream, 1024*1024*32, 1, 10, false);
// test_pingpong<int, Pinned>(stream, 1024*1024*32, 1, 1, false);
// test_pingpong<int, Pinned>(stream, 1024*1024*32, 1, 10, false);
HIPCHECK(hipStreamDestroy(stream));
}
passed();
}
@@ -22,18 +22,18 @@ THE SOFTWARE.
* HIT_END
*/
#include"test_common.h"
#include "test_common.h"
#define SIZE 1024*1024
#define SIZE 1024 * 1024
int main(){
int main() {
float *A, *Ad;
HIPCHECK(hipHostMalloc((void**)&A,SIZE, hipHostMallocDefault));
HIPCHECK(hipHostMalloc((void**)&A, SIZE, hipHostMallocDefault));
HIPCHECK(hipMalloc((void**)&Ad, SIZE));
hipStream_t stream;
HIPCHECK(hipStreamCreate(&stream));
for(int i=0;i<SIZE;i++){
HIPCHECK(hipMemcpyAsync(Ad, A, SIZE, hipMemcpyHostToDevice, stream));
HIPCHECK(hipDeviceSynchronize());
for (int i = 0; i < SIZE; i++) {
HIPCHECK(hipMemcpyAsync(Ad, A, SIZE, hipMemcpyHostToDevice, stream));
HIPCHECK(hipDeviceSynchronize());
}
}
@@ -19,7 +19,8 @@ THE SOFTWARE.
/*
* Conformance test for checking functionality of
* hipError_t hipMemcpyPeer(void* dst, int dstDeviceId, const void* src, int srcDeviceId, size_t sizeBytes);
* hipError_t hipMemcpyPeer(void* dst, int dstDeviceId, const void* src, int srcDeviceId, size_t
* sizeBytes);
*/
/* HIT_START
@@ -30,58 +31,39 @@ THE SOFTWARE.
#include "test_common.h"
int main()
{
size_t Nbytes = N*sizeof(int);
int main() {
size_t Nbytes = N * sizeof(int);
int numDevices = 0;
int *A_d, *B_d, *C_d, *X_d, *Y_d, *Z_d;
int *A_h, *B_h, *C_h ;
int *A_h, *B_h, *C_h;
HIPCHECK(hipGetDeviceCount(&numDevices));
if(numDevices > 1)
{
if (numDevices > 1) {
HIPCHECK(hipSetDevice(0));
unsigned blocks = HipTest::setNumBlocks(blocksPerCU, threadsPerBlock, N);
HipTest::initArrays(&A_d, &B_d, &C_d, &A_h, &B_h, &C_h, N, false);
HIPCHECK(hipSetDevice(1));
HIPCHECK(hipMalloc(&X_d,Nbytes));
HIPCHECK(hipMalloc(&Y_d,Nbytes));
HIPCHECK(hipMalloc(&Z_d,Nbytes));
HIPCHECK(hipMalloc(&X_d, Nbytes));
HIPCHECK(hipMalloc(&Y_d, Nbytes));
HIPCHECK(hipMalloc(&Z_d, Nbytes));
HIPCHECK(hipSetDevice(0));
HIPCHECK(hipMemcpy(A_d, A_h, Nbytes, hipMemcpyHostToDevice));
HIPCHECK(hipMemcpy(B_d, B_h, Nbytes, hipMemcpyHostToDevice));
hipLaunchKernel(
HipTest::vectorADD,
dim3(blocks),
dim3(threadsPerBlock),
0,
0,
static_cast<const int*>(A_d),
static_cast<const int*>(B_d),
C_d,
N);
hipLaunchKernel(HipTest::vectorADD, dim3(blocks), dim3(threadsPerBlock), 0, 0,
static_cast<const int*>(A_d), static_cast<const int*>(B_d), C_d, N);
HIPCHECK(hipMemcpy(C_h, C_d, Nbytes, hipMemcpyDeviceToHost));
HIPCHECK(hipDeviceSynchronize());
HipTest::checkVectorADD(A_h, B_h, C_h, N);
HIPCHECK(hipSetDevice(1));
HIPCHECK(hipMemcpyDtoD((hipDeviceptr_t)X_d, (hipDeviceptr_t)A_d, Nbytes));
HIPCHECK(hipMemcpyDtoD((hipDeviceptr_t)Y_d, (hipDeviceptr_t)B_d, Nbytes));
HIPCHECK(hipMemcpyDtoD((hipDeviceptr_t)X_d, (hipDeviceptr_t)A_d, Nbytes));
HIPCHECK(hipMemcpyDtoD((hipDeviceptr_t)Y_d, (hipDeviceptr_t)B_d, Nbytes));
hipLaunchKernel(
HipTest::vectorADD,
dim3(blocks),
dim3(threadsPerBlock),
0,
0,
static_cast<const int*>(X_d),
static_cast<const int*>(Y_d),
Z_d,
N);
hipLaunchKernel(HipTest::vectorADD, dim3(blocks), dim3(threadsPerBlock), 0, 0,
static_cast<const int*>(X_d), static_cast<const int*>(Y_d), Z_d, N);
HIPCHECK(hipMemcpyDtoH(C_h, (hipDeviceptr_t)Z_d, Nbytes));
HIPCHECK(hipDeviceSynchronize());
HipTest::checkVectorADD(A_h, B_h, C_h, N);
@@ -90,9 +72,7 @@ int main()
HIPCHECK(hipFree(X_d));
HIPCHECK(hipFree(Y_d));
HIPCHECK(hipFree(Z_d));
}
passed();
}
passed();
}
@@ -19,7 +19,8 @@ THE SOFTWARE.
/*
* Conformance test for checking functionality of
* hipError_t hipMemcpyPeer(void* dst, int dstDeviceId, const void* src, int srcDeviceId, size_t sizeBytes);
* hipError_t hipMemcpyPeer(void* dst, int dstDeviceId, const void* src, int srcDeviceId, size_t
* sizeBytes);
*/
/* HIT_START
@@ -30,39 +31,29 @@ THE SOFTWARE.
#include "test_common.h"
int main()
{
size_t Nbytes = N*sizeof(int);
int main() {
size_t Nbytes = N * sizeof(int);
int numDevices = 0;
int *A_d, *B_d, *C_d, *X_d, *Y_d, *Z_d;
int *A_h, *B_h, *C_h ;
int *A_h, *B_h, *C_h;
hipStream_t s;
HIPCHECK(hipGetDeviceCount(&numDevices));
if(numDevices > 1)
{
if (numDevices > 1) {
HIPCHECK(hipSetDevice(0));
unsigned blocks = HipTest::setNumBlocks(blocksPerCU, threadsPerBlock, N);
HipTest::initArrays(&A_d, &B_d, &C_d, &A_h, &B_h, &C_h, N, false);
HIPCHECK(hipSetDevice(1));
HIPCHECK(hipMalloc(&X_d,Nbytes));
HIPCHECK(hipMalloc(&Y_d,Nbytes));
HIPCHECK(hipMalloc(&Z_d,Nbytes));
HIPCHECK(hipMalloc(&X_d, Nbytes));
HIPCHECK(hipMalloc(&Y_d, Nbytes));
HIPCHECK(hipMalloc(&Z_d, Nbytes));
HIPCHECK(hipSetDevice(0));
HIPCHECK(hipMemcpy(A_d, A_h, Nbytes, hipMemcpyHostToDevice));
HIPCHECK(hipMemcpy(B_d, B_h, Nbytes, hipMemcpyHostToDevice));
hipLaunchKernel(
HipTest::vectorADD,
dim3(blocks),
dim3(threadsPerBlock),
0,
0,
static_cast<const int*>(A_d),
static_cast<const int*>(B_d),
C_d,
N);
hipLaunchKernel(HipTest::vectorADD, dim3(blocks), dim3(threadsPerBlock), 0, 0,
static_cast<const int*>(A_d), static_cast<const int*>(B_d), C_d, N);
HIPCHECK(hipMemcpy(C_h, C_d, Nbytes, hipMemcpyDeviceToHost));
HIPCHECK(hipDeviceSynchronize());
HipTest::checkVectorADD(A_h, B_h, C_h, N);
@@ -72,16 +63,8 @@ int main()
HIPCHECK(hipMemcpyDtoDAsync((hipDeviceptr_t)X_d, (hipDeviceptr_t)A_d, Nbytes, s));
HIPCHECK(hipMemcpyDtoDAsync((hipDeviceptr_t)Y_d, (hipDeviceptr_t)B_d, Nbytes, s));
hipLaunchKernel(
HipTest::vectorADD,
dim3(blocks),
dim3(threadsPerBlock),
0,
0,
static_cast<const int*>(X_d),
static_cast<const int*>(Y_d),
Z_d,
N);
hipLaunchKernel(HipTest::vectorADD, dim3(blocks), dim3(threadsPerBlock), 0, 0,
static_cast<const int*>(X_d), static_cast<const int*>(Y_d), Z_d, N);
HIPCHECK(hipMemcpyDtoHAsync(C_h, (hipDeviceptr_t)Z_d, Nbytes, s));
HIPCHECK(hipStreamSynchronize(s));
HIPCHECK(hipDeviceSynchronize());
@@ -92,10 +75,7 @@ int main()
HIPCHECK(hipFree(X_d));
HIPCHECK(hipFree(Y_d));
HIPCHECK(hipFree(Z_d));
}
passed();
}
passed();
}
@@ -19,7 +19,8 @@ THE SOFTWARE.
/*
* Conformance test for checking functionality of
* hipError_t hipMemcpyPeer(void* dst, int dstDeviceId, const void* src, int srcDeviceId, size_t sizeBytes);
* hipError_t hipMemcpyPeer(void* dst, int dstDeviceId, const void* src, int srcDeviceId, size_t
* sizeBytes);
*/
/* HIT_START
@@ -30,55 +31,39 @@ THE SOFTWARE.
#include "test_common.h"
int main()
{
size_t Nbytes = N*sizeof(int);
int main() {
size_t Nbytes = N * sizeof(int);
int numDevices = 0;
int *A_d, *B_d, *C_d, *X_d, *Y_d, *Z_d;
int *A_h, *B_h, *C_h ;
int *A_h, *B_h, *C_h;
HIPCHECK(hipGetDeviceCount(&numDevices));
if(numDevices > 1)
{
if (numDevices > 1) {
HIPCHECK(hipSetDevice(0));
unsigned blocks = HipTest::setNumBlocks(blocksPerCU, threadsPerBlock, N);
HipTest::initArrays(&A_d, &B_d, &C_d, &A_h, &B_h, &C_h, N, false);
HIPCHECK(hipSetDevice(1));
HIPCHECK(hipMalloc(&X_d,Nbytes));
HIPCHECK(hipMalloc(&Y_d,Nbytes));
HIPCHECK(hipMalloc(&Z_d,Nbytes));
HIPCHECK(hipMalloc(&X_d, Nbytes));
HIPCHECK(hipMalloc(&Y_d, Nbytes));
HIPCHECK(hipMalloc(&Z_d, Nbytes));
HIPCHECK(hipSetDevice(0));
HIPCHECK(hipMemcpy(A_d, A_h, Nbytes, hipMemcpyHostToDevice));
HIPCHECK(hipMemcpy(B_d, B_h, Nbytes, hipMemcpyHostToDevice));
hipLaunchKernel(
HipTest::vectorADD,
dim3(blocks),
dim3(threadsPerBlock),
0,
0,
static_cast<const int*>(A_d),
static_cast<const int*>(B_d),
C_d,
N);
hipLaunchKernel(HipTest::vectorADD, dim3(blocks), dim3(threadsPerBlock), 0, 0,
static_cast<const int*>(A_d), static_cast<const int*>(B_d), C_d, N);
HIPCHECK(hipMemcpy(C_h, C_d, Nbytes, hipMemcpyDeviceToHost));
HIPCHECK(hipDeviceSynchronize());
HipTest::checkVectorADD(A_h, B_h, C_h, N);
HIPCHECK(hipSetDevice(1));
hipMemcpyPeer(X_d, 1, A_d, 0, Nbytes); //this call is eqv to hipMemcpy(hipMemcpyD2D) which goes via stg bufs.
hipMemcpyPeer(
X_d, 1, A_d, 0,
Nbytes); // this call is eqv to hipMemcpy(hipMemcpyD2D) which goes via stg bufs.
hipMemcpyPeer(Y_d, 1, B_d, 0, Nbytes);
hipLaunchKernel(
HipTest::vectorADD,
dim3(blocks),
dim3(threadsPerBlock),
0,
0,
static_cast<const int*>(X_d),
static_cast<const int*>(Y_d),
Z_d,
N);
hipLaunchKernel(HipTest::vectorADD, dim3(blocks), dim3(threadsPerBlock), 0, 0,
static_cast<const int*>(X_d), static_cast<const int*>(Y_d), Z_d, N);
HIPCHECK(hipMemcpy(C_h, Z_d, Nbytes, hipMemcpyDeviceToHost));
HIPCHECK(hipDeviceSynchronize());
HipTest::checkVectorADD(A_h, B_h, C_h, N);
@@ -87,11 +72,6 @@ int main()
HIPCHECK(hipFree(X_d));
HIPCHECK(hipFree(Y_d));
HIPCHECK(hipFree(Z_d));
}
passed();
}
passed();
}
@@ -19,7 +19,8 @@ THE SOFTWARE.
/*
* Conformance test for checking functionality of
* hipError_t hipMemcpyPeer(void* dst, int dstDeviceId, const void* src, int srcDeviceId, size_t sizeBytes);
* hipError_t hipMemcpyPeer(void* dst, int dstDeviceId, const void* src, int srcDeviceId, size_t
* sizeBytes);
*/
/* HIT_START
@@ -30,43 +31,33 @@ THE SOFTWARE.
#include "test_common.h"
int main()
{
int main() {
hipDevice_t device;
size_t Nbytes = N*sizeof(int);
size_t Nbytes = N * sizeof(int);
int numDevices = 0;
int *A_d, *B_d, *C_d, *X_d, *Y_d, *Z_d;
int *A_h, *B_h, *C_h ;
int *A_h, *B_h, *C_h;
hipStream_t s;
HIPCHECK(hipGetDeviceCount(&numDevices));
if(numDevices > 1)
{
if (numDevices > 1) {
HIPCHECK(hipSetDevice(0));
unsigned blocks = HipTest::setNumBlocks(blocksPerCU, threadsPerBlock, N);
HipTest::initArrays(&A_d, &B_d, &C_d, &A_h, &B_h, &C_h, N, false);
HIPCHECK(hipSetDevice(1));
HIPCHECK(hipMalloc(&X_d,Nbytes));
HIPCHECK(hipMalloc(&Y_d,Nbytes));
HIPCHECK(hipMalloc(&Z_d,Nbytes));
HIPCHECK(hipMalloc(&X_d, Nbytes));
HIPCHECK(hipMalloc(&Y_d, Nbytes));
HIPCHECK(hipMalloc(&Z_d, Nbytes));
HIPCHECK(hipSetDevice(0));
HIPCHECK ( hipMemcpy(A_d, A_h, Nbytes, hipMemcpyHostToDevice));
HIPCHECK ( hipMemcpy(B_d, B_h, Nbytes, hipMemcpyHostToDevice));
hipLaunchKernel(
HipTest::vectorADD,
dim3(blocks),
dim3(threadsPerBlock),
0,
0,
static_cast<const int*>(A_d),
static_cast<const int*>(B_d),
C_d,
N);
HIPCHECK ( hipMemcpy(C_h, C_d, Nbytes, hipMemcpyDeviceToHost));
HIPCHECK (hipDeviceSynchronize());
HIPCHECK(hipMemcpy(A_d, A_h, Nbytes, hipMemcpyHostToDevice));
HIPCHECK(hipMemcpy(B_d, B_h, Nbytes, hipMemcpyHostToDevice));
hipLaunchKernel(HipTest::vectorADD, dim3(blocks), dim3(threadsPerBlock), 0, 0,
static_cast<const int*>(A_d), static_cast<const int*>(B_d), C_d, N);
HIPCHECK(hipMemcpy(C_h, C_d, Nbytes, hipMemcpyDeviceToHost));
HIPCHECK(hipDeviceSynchronize());
HipTest::checkVectorADD(A_h, B_h, C_h, N);
HIPCHECK(hipStreamCreate(&s));
@@ -74,19 +65,11 @@ int main()
HIPCHECK(hipMemcpyPeerAsync(X_d, 1, A_d, 0, Nbytes, s));
HIPCHECK(hipMemcpyPeerAsync(Y_d, 1, B_d, 0, Nbytes, s));
hipLaunchKernel(
HipTest::vectorADD,
dim3(blocks),
dim3(threadsPerBlock),
0,
0,
static_cast<const int*>(X_d),
static_cast<const int*>(Y_d),
Z_d,
N);
HIPCHECK ( hipMemcpy(C_h, Z_d, Nbytes, hipMemcpyDeviceToHost));
HIPCHECK (hipDeviceSynchronize());
HIPCHECK (hipStreamSynchronize(s));
hipLaunchKernel(HipTest::vectorADD, dim3(blocks), dim3(threadsPerBlock), 0, 0,
static_cast<const int*>(X_d), static_cast<const int*>(Y_d), Z_d, N);
HIPCHECK(hipMemcpy(C_h, Z_d, Nbytes, hipMemcpyDeviceToHost));
HIPCHECK(hipDeviceSynchronize());
HIPCHECK(hipStreamSynchronize(s));
HipTest::checkVectorADD(A_h, B_h, C_h, N);
HIPCHECK(hipStreamDestroy(s));
@@ -94,10 +77,7 @@ int main()
HIPCHECK(hipFree(X_d));
HIPCHECK(hipFree(Y_d));
HIPCHECK(hipFree(Z_d));
}
passed();
}
passed();
}
@@ -33,8 +33,7 @@ THE SOFTWARE.
bool p_async = false;
// ****************************************************************************
hipError_t memcopy(void * dst, const void *src, size_t sizeBytes, enum hipMemcpyKind kind)
{
hipError_t memcopy(void* dst, const void* src, size_t sizeBytes, enum hipMemcpyKind kind) {
if (p_async) {
return hipMemcpyAsync(dst, src, sizeBytes, kind, NULL);
} else {
@@ -46,59 +45,50 @@ hipError_t memcopy(void * dst, const void *src, size_t sizeBytes, enum hipMemcpy
//---
// Test simple H2D copies and back.
// Designed to stress a small number of simple smoke tests
void simpleTest1()
{
printf ("test: %s\n", __func__);
size_t Nbytes = N*sizeof(int);
printf ("N=%zu Nbytes=%6.2fMB\n", N, Nbytes/1024.0/1024.0);
void simpleTest1() {
printf("test: %s\n", __func__);
size_t Nbytes = N * sizeof(int);
printf("N=%zu Nbytes=%6.2fMB\n", N, Nbytes / 1024.0 / 1024.0);
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, false);
HipTest::initArrays(&A_d, &B_d, &C_d, &A_h, &B_h, &C_h, N, false);
printf ("A_d=%p B_d=%p C_d=%p A_h=%p B_h=%p C_h=%p\n", A_d, B_d, C_d, A_h, B_d, C_h);
printf("A_d=%p B_d=%p C_d=%p A_h=%p B_h=%p C_h=%p\n", A_d, B_d, C_d, A_h, B_d, C_h);
unsigned blocks = HipTest::setNumBlocks(blocksPerCU, threadsPerBlock, N);
HIPCHECK ( memcopy(A_d, A_h, Nbytes, hipMemcpyHostToDevice));
HIPCHECK ( memcopy(B_d, B_h, Nbytes, hipMemcpyHostToDevice));
HIPCHECK(memcopy(A_d, A_h, Nbytes, hipMemcpyHostToDevice));
HIPCHECK(memcopy(B_d, B_h, Nbytes, hipMemcpyHostToDevice));
hipLaunchKernel(
HipTest::vectorADD,
dim3(blocks),
dim3(threadsPerBlock),
0,
0,
static_cast<const int*>(A_d),
static_cast<const int*>(B_d),
C_d,
N);
hipLaunchKernel(HipTest::vectorADD, dim3(blocks), dim3(threadsPerBlock), 0, 0,
static_cast<const int*>(A_d), static_cast<const int*>(B_d), C_d, N);
HIPCHECK ( memcopy(C_h, C_d, Nbytes, hipMemcpyDeviceToHost));
HIPCHECK(memcopy(C_h, C_d, Nbytes, hipMemcpyDeviceToHost));
HIPCHECK (hipDeviceSynchronize());
HIPCHECK(hipDeviceSynchronize());
HipTest::checkVectorADD(A_h, B_h, C_h, N);
HipTest::freeArrays (A_d, B_d, C_d, A_h, B_h, C_h, false);
HIPCHECK (hipDeviceReset());
HipTest::freeArrays(A_d, B_d, C_d, A_h, B_h, C_h, false);
HIPCHECK(hipDeviceReset());
printf (" %s success\n", __func__);
printf(" %s success\n", __func__);
}
template <typename T>
void simpleTest2(size_t numElements, bool usePinnedHost)
{
void simpleTest2(size_t numElements, bool usePinnedHost) {
size_t sizeElements = numElements * sizeof(T);
size_t alignment = 4096;
printf ("test: %s<%s> numElements=%zu sizeElements=%zu bytes\n", __func__, TYPENAME(T), numElements, sizeElements);
printf("test: %s<%s> numElements=%zu sizeElements=%zu bytes\n", __func__, TYPENAME(T),
numElements, sizeElements);
T *A_d, *A_h1, *A_h2;
if (usePinnedHost) {
HIPCHECK ( hipHostMalloc((void**)&A_h1, sizeElements, hipHostMallocDefault) );
HIPCHECK ( hipHostMalloc((void**)&A_h2, sizeElements, hipHostMallocDefault) );
HIPCHECK(hipHostMalloc((void**)&A_h1, sizeElements, hipHostMallocDefault));
HIPCHECK(hipHostMalloc((void**)&A_h2, sizeElements, hipHostMallocDefault));
} else {
A_h1 = (T*)aligned_alloc(alignment, sizeElements);
HIPASSERT(A_h1);
@@ -107,12 +97,13 @@ void simpleTest2(size_t numElements, bool usePinnedHost)
}
// Alloc device array:
HIPCHECK ( hipMalloc(&A_d, sizeElements) );
HIPCHECK(hipMalloc(&A_d, sizeElements));
for (size_t i=0; i<numElements; i++) {
A_h1[i] = 3.14f+ 1000*i;
A_h2[i] = 12345678.0 + i; // init output with something distincctive, to ensure we replace it.
for (size_t i = 0; i < numElements; i++) {
A_h1[i] = 3.14f + 1000 * i;
A_h2[i] =
12345678.0 + i; // init output with something distincctive, to ensure we replace it.
}
HIPCHECK(memcopy(A_d, A_h1, sizeElements, hipMemcpyHostToDevice));
@@ -120,7 +111,7 @@ void simpleTest2(size_t numElements, bool usePinnedHost)
HIPCHECK(memcopy(A_h2, A_d, sizeElements, hipMemcpyDeviceToHost));
HIPCHECK(hipDeviceSynchronize());
for (size_t i=0; i<numElements; i++) {
for (size_t i = 0; i < numElements; i++) {
HIPASSERT(A_h1[i] == A_h2[i]);
}
@@ -135,14 +126,13 @@ void simpleTest2(size_t numElements, bool usePinnedHost)
}
//Parse arguments specific to this test.
void parseMyArguments(int argc, char *argv[])
{
// Parse arguments specific to this test.
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, "--async")) {
p_async = true;
@@ -154,31 +144,30 @@ void parseMyArguments(int argc, char *argv[])
};
int main(int argc, char *argv[])
{
int main(int argc, char* argv[]) {
parseMyArguments(argc, argv);
printf ("info: set device to %d, tests=%x\n", p_gpuDevice, p_tests);
printf("info: set device to %d, tests=%x\n", p_gpuDevice, p_tests);
HIPCHECK(hipSetDevice(p_gpuDevice));
if (p_tests & 0x1) {
printf ("\n\n=== tests&1\n");
HIPCHECK ( hipDeviceReset() );
printf("\n\n=== tests&1\n");
HIPCHECK(hipDeviceReset());
simpleTest1();
printf ("===\n\n\n");
printf("===\n\n\n");
}
if (p_tests & 0x2) {
printf ("\n\n=== tests&2 (copy ping-pong, pinned host)\n");
simpleTest2<float>(N, true/*usePinnedHost*/);
simpleTest2<char>(N, true/*usePinnedHost*/);
printf("\n\n=== tests&2 (copy ping-pong, pinned host)\n");
simpleTest2<float>(N, true /*usePinnedHost*/);
simpleTest2<char>(N, true /*usePinnedHost*/);
}
if (p_tests & 0x4) {
printf ("\n\n=== tests&4 (copy ping-pong, unpinned host)\n");
simpleTest2<char>(N, false/*usePinnedHost*/);
simpleTest2<float>(N, false/*usePinnedHost*/);
printf("\n\n=== tests&4 (copy ping-pong, unpinned host)\n");
simpleTest2<char>(N, false /*usePinnedHost*/);
simpleTest2<float>(N, false /*usePinnedHost*/);
}
hipDeviceSynchronize();
@@ -29,33 +29,32 @@ THE SOFTWARE.
#include <cstdio>
#include "hip/hip_runtime.h"
__global__ void Kernel(hipLaunchParm lp,volatile float* hostRes)
{
__global__ void Kernel(hipLaunchParm lp, volatile float* hostRes) {
int tid = threadIdx.x + blockIdx.x * blockDim.x;
hostRes[tid] = tid + 1;
__threadfence_system();
// expecting that the data is getting flushed to host here!
// time waster for-loop (sleep)
for (int timeWater = 0; timeWater < 100000000; timeWater++);
for (int timeWater = 0; timeWater < 100000000; timeWater++)
;
}
int main()
{
int main() {
size_t blocks = 2;
volatile float* hostRes;
hipHostMalloc((void**)&hostRes,blocks*sizeof(float),hipHostMallocMapped);
hostRes[0]=0;
hostRes[1]=0;
hipHostMalloc((void**)&hostRes, blocks * sizeof(float), hipHostMallocMapped);
hostRes[0] = 0;
hostRes[1] = 0;
hipLaunchKernel(HIP_KERNEL_NAME(Kernel), dim3(1), dim3(blocks), 0, 0, hostRes);
int eleCounter = 0;
while (eleCounter < blocks)
{
while (eleCounter < blocks) {
// blocks until the value changes
while(hostRes[eleCounter] == 0);
printf("%f\n", hostRes[eleCounter]);;
while (hostRes[eleCounter] == 0)
;
printf("%f\n", hostRes[eleCounter]);
;
eleCounter++;
}
hipHostFree((void *)hostRes);
hipHostFree((void*)hostRes);
return 0;
}
@@ -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 ../../test_common.cpp NVCC_OPTIONS -std=c++11
@@ -31,11 +31,11 @@ THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
#include "hip/hip_runtime.h"
using namespace std;
string getRes(){
FILE *in;
string getRes() {
FILE* in;
char buff[512], buff_2[512];
string str = "./hipMemoryAllocateCoherent";
if(!(in = popen(str.c_str(), "r"))){
if (!(in = popen(str.c_str(), "r"))) {
exit(1);
}
fgets(buff, sizeof(buff), in);
@@ -47,14 +47,13 @@ string getRes(){
}
int main() {
setenv("HIP_COHERENT_HOST_ALLOC","1000,0,1",1);
setenv("HIP_COHERENT_HOST_ALLOC", "1000,0,1", 1);
string output = getRes();
istringstream buffer(output);
double res1, res2;
buffer >> res1;
buffer >> res2;
if((res2-res1*2)>0.000001)
exit(1);
if ((res2 - res1 * 2) > 0.000001) exit(1);
std::cout << "PASSED" << std::endl;
return 0;
}
@@ -38,34 +38,31 @@ THE SOFTWARE.
#include "test_common.h"
int main(int argc, char *argv[])
{
int main(int argc, char* argv[]) {
HipTest::parseStandardArguments(argc, argv, true);
HIPCHECK(hipSetDevice(p_gpuDevice));
size_t Nbytes = N*sizeof(char);
size_t Nbytes = N * sizeof(char);
printf ("N=%zu memsetval=%2x device=%d\n", N, memsetval, p_gpuDevice);
printf("N=%zu memsetval=%2x device=%d\n", N, memsetval, p_gpuDevice);
char *A_d;
char *A_h;
char* A_d;
char* A_h;
HIPCHECK ( hipMalloc(&A_d, Nbytes) );
HIPCHECK(hipMalloc(&A_d, Nbytes));
A_h = (char*)malloc(Nbytes);
HIPCHECK ( hipMemset(A_d, memsetval, Nbytes) );
HIPCHECK(hipMemset(A_d, memsetval, Nbytes));
HIPCHECK ( hipMemcpy(A_h, A_d, Nbytes, hipMemcpyDeviceToHost));
HIPCHECK(hipMemcpy(A_h, A_d, Nbytes, hipMemcpyDeviceToHost));
for (int i=0; i<N; i++) {
for (int i = 0; i < N; i++) {
if (A_h[i] != memsetval) {
failed("mismatch at index:%d computed:%02x, memsetval:%02x\n", i, (int)A_h[i], (int)memsetval);
failed("mismatch at index:%d computed:%02x, memsetval:%02x\n", i, (int)A_h[i],
(int)memsetval);
}
}
passed();
}
@@ -29,77 +29,76 @@ THE SOFTWARE.
#include "hip/hip_runtime.h"
#include "test_common.h"
#define WIDTH 1024
#define HEIGHT 1024
#define WIDTH 1024
#define HEIGHT 1024
#define NUM (WIDTH*HEIGHT)
#define NUM (WIDTH * HEIGHT)
#define THREADS_PER_BLOCK_X 16
#define THREADS_PER_BLOCK_Y 16
#define THREADS_PER_BLOCK_Z 1
#define THREADS_PER_BLOCK_X 16
#define THREADS_PER_BLOCK_Y 16
#define THREADS_PER_BLOCK_Z 1
int main() {
int* hostA;
int* hostB;
int *hostA;
int *hostB;
int* deviceA;
int* deviceB;
int *deviceA;
int *deviceB;
int i;
int errors;
int i;
int errors;
hostA = (int*)malloc(NUM * sizeof(int));
hostB = (int*)malloc(NUM * sizeof(int));
hostA = (int *)malloc(NUM * sizeof(int));
hostB = (int *)malloc(NUM * sizeof(int));
// initialize the input data
for (i = 0; i < NUM; i++) {
hostB[i] = i;
}
// initialize the input data
for (i = 0; i < NUM; i++) {
hostB[i] = i;
}
HIPCHECK(hipMalloc((void**)&deviceA, NUM * sizeof(int)));
HIPCHECK(hipMalloc((void**)&deviceB, NUM * sizeof(int)));
HIPCHECK(hipMalloc((void**)&deviceA, NUM * sizeof(int)));
HIPCHECK(hipMalloc((void**)&deviceB, NUM * sizeof(int)));
hipStream_t s;
HIPCHECK(hipStreamCreate(&s));
hipStream_t s;
HIPCHECK(hipStreamCreate(&s));
// hostB -> deviceB -> hostA
// hostB -> deviceB -> hostA
#define ASYNC 1
#if ASYNC
HIPCHECK(hipMemcpyAsync(deviceB, hostB, NUM*sizeof(int), hipMemcpyHostToDevice, s));
HIPCHECK(hipMemcpyAsync(hostA, deviceB, NUM*sizeof(int), hipMemcpyDeviceToHost, s));
HIPCHECK(hipMemcpyAsync(deviceB, hostB, NUM * sizeof(int), hipMemcpyHostToDevice, s));
HIPCHECK(hipMemcpyAsync(hostA, deviceB, NUM * sizeof(int), hipMemcpyDeviceToHost, s));
#else
HIPCHECK(hipMemcpy(deviceB, hostB, NUM*sizeof(int), hipMemcpyHostToDevice));
HIPCHECK(hipMemcpy(hostA, deviceB, NUM*sizeof(int), hipMemcpyDeviceToHost));
HIPCHECK(hipMemcpy(deviceB, hostB, NUM * sizeof(int), hipMemcpyHostToDevice));
HIPCHECK(hipMemcpy(hostA, deviceB, NUM * sizeof(int), hipMemcpyDeviceToHost));
#endif
HIPCHECK(hipStreamSynchronize(s));
HIPCHECK(hipDeviceSynchronize());
HIPCHECK(hipStreamSynchronize(s));
HIPCHECK(hipDeviceSynchronize());
// verify the results
errors = 0;
for (i = 0; i < NUM; i++) {
if (hostA[i] != (hostB[i])) {
errors++;
// verify the results
errors = 0;
for (i = 0; i < NUM; i++) {
if (hostA[i] != (hostB[i])) {
errors++;
}
}
}
HIPCHECK(hipStreamDestroy(s));
HIPCHECK(hipStreamDestroy(s));
HIPCHECK(hipFree(deviceA));
HIPCHECK(hipFree(deviceB));
HIPCHECK(hipFree(deviceA));
HIPCHECK(hipFree(deviceB));
free(hostA);
free(hostB);
free(hostA);
free(hostB);
//hipResetDefaultAccelerator();
// hipResetDefaultAccelerator();
if(errors != 0){
HIPASSERT(1 == 2);
}else{
passed();
}
if (errors != 0) {
HIPASSERT(1 == 2);
} else {
passed();
}
return errors;
return errors;
}
@@ -24,12 +24,12 @@ THE SOFTWARE.
*/
#include "hip/hip_runtime.h"
#include"test_common.h"
#include "test_common.h"
#define len 1024*1024
#define len 1024 * 1024
#define size len * sizeof(float)
int main(){
int main() {
float *Ad, *A;
hipHostMalloc((void**)&A, size);
hipMalloc((void**)&Ad, size);
@@ -35,15 +35,13 @@ THE SOFTWARE.
#include <hc_am.hpp>
#endif
#define USE_HCC_MEMTRACKER 0 /* Debug flag to show the memtracker periodically */
#define USE_HCC_MEMTRACKER 0 /* Debug flag to show the memtracker periodically */
int elementSizes[] = {1, 16, 1024, 524288, 16 * 1000 * 1000};
int nSizes = sizeof(elementSizes) / sizeof(int);
int elementSizes[] = {1, 16, 1024, 524288, 16*1000*1000};
int nSizes = sizeof(elementSizes) / sizeof(int);
int enablePeers(int dev0, int dev1)
{
int enablePeers(int dev0, int dev1) {
int canAccessPeer01, canAccessPeer10;
HIPCHECK(hipDeviceCanAccessPeer(&canAccessPeer01, dev0, dev1));
HIPCHECK(hipDeviceCanAccessPeer(&canAccessPeer10, dev1, dev0));
@@ -52,79 +50,78 @@ int enablePeers(int dev0, int dev1)
}
HIPCHECK(hipSetDevice(dev0));
HIPCHECK(hipDeviceEnablePeerAccess(dev1, 0/*flags*/));
HIPCHECK(hipDeviceEnablePeerAccess(dev1, 0 /*flags*/));
HIPCHECK(hipSetDevice(dev1));
HIPCHECK(hipDeviceEnablePeerAccess(dev0, 0/*flags*/));
HIPCHECK(hipDeviceEnablePeerAccess(dev0, 0 /*flags*/));
return 0;
};
// Set value of array to specified 32-bit integer:
__global__ void
memsetIntKernel(int * ptr, const int val, size_t numElements)
{
__global__ void memsetIntKernel(int* ptr, const int val, size_t numElements) {
int gid = (blockIdx.x * blockDim.x + threadIdx.x);
int stride = blockDim.x * gridDim.x ;
for (size_t i= gid; i< numElements; i+=stride){
ptr[i] = val;
int stride = blockDim.x * gridDim.x;
for (size_t i = gid; i < numElements; i += stride) {
ptr[i] = val;
}
};
__global__ void
memcpyIntKernel(const int * src, int* dst, size_t numElements)
{
__global__ void memcpyIntKernel(const int* src, int* dst, size_t numElements) {
int gid = (blockIdx.x * blockDim.x + threadIdx.x);
int stride = blockDim.x * gridDim.x ;
for (size_t i= gid; i< numElements; i+=stride){
dst[i] = src[i];
int stride = blockDim.x * gridDim.x;
for (size_t i = gid; i < numElements; i += stride) {
dst[i] = src[i];
}
};
// CHeck arrays in reverse order, to more easily detect cases where
// the copy is "partially" done.
void checkReverse(const int *ptr, int numElements, int expected) {
for (int i=numElements-1; i>=0; i--) {
void checkReverse(const int* ptr, int numElements, int expected) {
for (int i = numElements - 1; i >= 0; i--) {
if (ptr[i] != expected) {
printf ("i=%d, ptr[](%d) != expected (%d)\n", i, ptr[i], expected);
assert (ptr[i] == expected);
printf("i=%d, ptr[](%d) != expected (%d)\n", i, ptr[i], expected);
assert(ptr[i] == expected);
}
}
printf ("test: OK\n");
printf("test: OK\n");
}
void runTestImpl(bool stepAIsCopy, bool hostSync, hipStream_t gpu0Stream, hipStream_t gpu1Stream, int numElements,
int * dataGpu0_0, int * dataGpu0_1, int *dataGpu1, int *dataHost, int expected)
{
void runTestImpl(bool stepAIsCopy, bool hostSync, hipStream_t gpu0Stream, hipStream_t gpu1Stream,
int numElements, int* dataGpu0_0, int* dataGpu0_1, int* dataGpu1, int* dataHost,
int expected) {
hipEvent_t e;
if(!hostSync) {
HIPCHECK(hipEventCreateWithFlags(&e,0));
if (!hostSync) {
HIPCHECK(hipEventCreateWithFlags(&e, 0));
}
const size_t sizeElements = numElements * sizeof(int);
printf ("test: runTestImpl with %zu bytes %s with hostSync %s\n", sizeElements, stepAIsCopy ? "copy" : "kernel", hostSync ? "enabled" : "disabled");
printf("test: runTestImpl with %zu bytes %s with hostSync %s\n", sizeElements,
stepAIsCopy ? "copy" : "kernel", hostSync ? "enabled" : "disabled");
hipStream_t stepAStream = gpu0Stream;
if (stepAIsCopy) {
HIPCHECK(hipMemcpyAsync(dataGpu1, dataGpu0_0, sizeElements, hipMemcpyDeviceToDevice, stepAStream));
HIPCHECK(hipMemcpyAsync(dataGpu1, dataGpu0_0, sizeElements, hipMemcpyDeviceToDevice,
stepAStream));
} else {
unsigned blocks = HipTest::setNumBlocks(blocksPerCU, threadsPerBlock, numElements);
hipLaunchKernelGGL(memcpyIntKernel, dim3(blocks), dim3(threadsPerBlock), 0, gpu0Stream,
dataGpu0_0, dataGpu1, numElements);
dataGpu0_0, dataGpu1, numElements);
}
if(!hostSync) {
if (!hostSync) {
HIPCHECK(hipEventRecord(e, stepAStream));
HIPCHECK(hipStreamWaitEvent(gpu1Stream, e, 0));
} else {
HIPCHECK(hipStreamSynchronize(stepAStream));
}
HIPCHECK(hipMemcpyAsync(dataGpu0_1, dataGpu1, sizeElements, hipMemcpyDeviceToDevice, gpu1Stream));
HIPCHECK(
hipMemcpyAsync(dataGpu0_1, dataGpu1, sizeElements, hipMemcpyDeviceToDevice, gpu1Stream));
if(!hostSync) {
if (!hostSync) {
HIPCHECK(hipEventRecord(e, gpu1Stream));
} else {
HIPCHECK(hipStreamSynchronize(gpu1Stream));
@@ -134,16 +131,15 @@ void runTestImpl(bool stepAIsCopy, bool hostSync, hipStream_t gpu0Stream, hipStr
HIPCHECK(hipStreamSynchronize(gpu0Stream));
checkReverse(dataHost, numElements, expected);
if(!hostSync) {
if (!hostSync) {
HIPCHECK(hipEventDestroy(e));
}
}
void testMultiGpu(int dev0, int dev1, int numElements, bool hostSync)
{
void testMultiGpu(int dev0, int dev1, int numElements, bool hostSync) {
const size_t sizeElements = numElements * sizeof(int);
int * dataGpu0_0, * dataGpu0_1, *dataGpu1, *dataHost;
int *dataGpu0_0, *dataGpu0_1, *dataGpu1, *dataHost;
hipStream_t gpu0Stream, gpu1Stream;
const int expected = 42;
unsigned blocks = HipTest::setNumBlocks(blocksPerCU, threadsPerBlock, numElements);
@@ -172,8 +168,9 @@ void testMultiGpu(int dev0, int dev1, int numElements, bool hostSync)
hc::am_memtracker_print(0x0);
#endif
printf (" test: init complete\n");
runTestImpl(true, hostSync, gpu0Stream, gpu1Stream, numElements, dataGpu0_0,dataGpu0_1, dataGpu1, dataHost, expected);
printf(" test: init complete\n");
runTestImpl(true, hostSync, gpu0Stream, gpu1Stream, numElements, dataGpu0_0, dataGpu0_1,
dataGpu1, dataHost, expected);
HIPCHECK(hipFree(dataGpu0_0));
HIPCHECK(hipFree(dataGpu0_1));
@@ -184,8 +181,7 @@ void testMultiGpu(int dev0, int dev1, int numElements, bool hostSync)
HIPCHECK(hipStreamDestroy(gpu1Stream));
};
int main(int argc, char *argv[])
{
int main(int argc, char* argv[]) {
HipTest::parseStandardArguments(argc, argv, true);
@@ -199,14 +195,14 @@ int main(int argc, char *argv[])
passed();
}
if (enablePeers(dev0,dev1) == -1) {
printf ("warning : could not find peer gpus\n");
if (enablePeers(dev0, dev1) == -1) {
printf("warning : could not find peer gpus\n");
return -1;
};
for(int index = 0;index < nSizes;index++) {
testMultiGpu(dev0, dev1, elementSizes[index] , false /*GPU Synchronization*/);
testMultiGpu(dev0, dev1, elementSizes[index] , true /*Host Synchronization*/);
for (int index = 0; index < nSizes; index++) {
testMultiGpu(dev0, dev1, elementSizes[index], false /*GPU Synchronization*/);
testMultiGpu(dev0, dev1, elementSizes[index], true /*Host Synchronization*/);
}