changed __global__ attribute
1. Moved around tests and added them to HIT Change-Id: I5d75280c42a5af852670ebabc7305ee56721ec7b
Αυτή η υποβολή περιλαμβάνεται σε:
1 γονέας
2790e9a448
υποβολή
5e3d63c0a3
52 files changed
+316
-411
No files matched your search
@@ -0,0 +1,267 @@
|
||||
/*
|
||||
Copyright (c) 2015-2017 Advanced Micro Devices, Inc. All rights reserved.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
/* HIT_START
|
||||
* BUILD: %t %s ../../test_common.cpp EXCLUDE_HIP_PLATFORM nvcc
|
||||
* RUN: %t EXCLUDE_HIP_PLATFORM
|
||||
* HIT_END
|
||||
*/
|
||||
|
||||
#include "hip/hip_runtime.h"
|
||||
#include "test_common.h"
|
||||
|
||||
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.
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
template <typename T>
|
||||
void memcpy2Dtest(size_t numW, size_t numH, bool usePinnedHost)
|
||||
{
|
||||
|
||||
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);
|
||||
|
||||
T *A_d, *B_d, *C_d;
|
||||
T *A_h, *B_h, *C_h;
|
||||
|
||||
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);
|
||||
|
||||
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);
|
||||
|
||||
HIPCHECK (hipMemcpy2D (C_h, width, C_d, pitch_C, width, numH, hipMemcpyDeviceToHost) );
|
||||
|
||||
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);
|
||||
|
||||
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.
|
||||
//
|
||||
// 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
|
||||
// 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
|
||||
//
|
||||
template <typename T>
|
||||
void memcpyArraytest(size_t numW, size_t numH, bool usePinnedHost, bool usePitch=false)
|
||||
{
|
||||
|
||||
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);
|
||||
|
||||
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);
|
||||
|
||||
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);
|
||||
|
||||
HIPCHECK (hipMemcpy (C_h, C_d->data, width, hipMemcpyDeviceToHost) );
|
||||
|
||||
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);
|
||||
}
|
||||
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 {
|
||||
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__);
|
||||
|
||||
}
|
||||
|
||||
//---
|
||||
//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));
|
||||
|
||||
int deviceId;
|
||||
HIPCHECK(hipGetDevice(&deviceId));
|
||||
|
||||
size_t free, total;
|
||||
HIPCHECK(hipMemGetInfo(&free, &total));
|
||||
|
||||
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);
|
||||
|
||||
// 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);
|
||||
|
||||
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[])
|
||||
{
|
||||
HipTest::parseStandardArguments(argc, argv, true);
|
||||
|
||||
printf ("info: set device to %d\n", p_gpuDevice);
|
||||
HIPCHECK(hipSetDevice(p_gpuDevice));
|
||||
|
||||
if (p_tests & 0x1) {
|
||||
printf ("\n\n=== tests&1 (types)\n");
|
||||
printSep();
|
||||
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=== tests&1 (types)\n");
|
||||
printSep();
|
||||
// 2D
|
||||
memcpyArraytest<float>(320, 211, 0, 0);
|
||||
memcpyArraytest<unsigned int>(322, 211, 0, 0);
|
||||
memcpyArraytest<int>(320, 211, 0, 0);
|
||||
memcpyArraytest<float>(320, 211, 0, 1);
|
||||
memcpyArraytest<float>(322, 211, 0, 1);
|
||||
memcpyArraytest<int>(320, 211, 0, 1);
|
||||
printSep();
|
||||
// 1D
|
||||
memcpyArraytest<float>(320, 1, 0);
|
||||
memcpyArraytest<unsigned int>(322, 1, 0);
|
||||
memcpyArraytest<int>(320, 1, 0);
|
||||
printf ("===\n\n\n");
|
||||
}
|
||||
|
||||
if (p_tests & 0x4) {
|
||||
printf ("\n\n=== tests&4 (test sizes and offsets)\n");
|
||||
printSep();
|
||||
HIPCHECK ( hipDeviceReset() );
|
||||
printSep();
|
||||
memcpyArraytest_size<float>(0,0);
|
||||
printSep();
|
||||
memcpyArraytest_size<float>(0,64);
|
||||
printSep();
|
||||
memcpyArraytest_size<float>(1024*1024,13);
|
||||
printSep();
|
||||
memcpyArraytest_size<float>(1024*1024,50);
|
||||
}
|
||||
|
||||
passed();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
/*
|
||||
Copyright (c) 2015-2016 Advanced Micro Devices, Inc. All rights reserved.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
/* HIT_START
|
||||
* BUILD: %t %s ../../test_common.cpp
|
||||
* RUN: %t
|
||||
* HIT_END
|
||||
*/
|
||||
|
||||
#include"test_common.h"
|
||||
#include<malloc.h>
|
||||
|
||||
#define LEN 1024*1024
|
||||
#define SIZE LEN*sizeof(float)
|
||||
|
||||
__global__ void Add(hipLaunchParm lp, float *Ad, float *Bd, float *Cd){
|
||||
int tx = hipThreadIdx_x + hipBlockIdx_x * hipBlockDim_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();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
Copyright (c) 2015-2016 Advanced Micro Devices, Inc. All rights reserved.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
/* HIT_START
|
||||
* BUILD: %t %s ../../test_common.cpp
|
||||
* RUN: %t
|
||||
* HIT_END
|
||||
*/
|
||||
|
||||
#include"test_common.h"
|
||||
|
||||
#define LEN 1024*1024
|
||||
#define SIZE LEN*sizeof(float)
|
||||
|
||||
__global__ void Add(hipLaunchParm lp, float *Ad, float *Bd, float *Cd){
|
||||
int tx = hipThreadIdx_x + hipBlockIdx_x * hipBlockDim_x;
|
||||
Cd[tx] = Ad[tx] + Bd[tx];
|
||||
}
|
||||
|
||||
int main(){
|
||||
float *A, *B, *C;
|
||||
float *Ad, *Bd, *Cd;
|
||||
|
||||
hipDeviceProp_t prop;
|
||||
int device;
|
||||
HIPCHECK(hipGetDevice(&device));
|
||||
HIPCHECK(hipGetDeviceProperties(&prop, device));
|
||||
if(prop.canMapHostMemory != 1){
|
||||
std::cout<<"Exiting..."<<std::endl;
|
||||
failed("Does support HostPinned Memory");
|
||||
}
|
||||
|
||||
HIPCHECK(hipHostMalloc((void**)&A, SIZE, hipHostMallocWriteCombined | hipHostMallocMapped));
|
||||
HIPCHECK(hipHostMalloc((void**)&B, SIZE, hipHostMallocDefault));
|
||||
HIPCHECK(hipHostMalloc((void**)&C, SIZE, hipHostMallocMapped));
|
||||
|
||||
HIPCHECK(hipHostGetDevicePointer((void**)&Ad, A, 0));
|
||||
HIPCHECK(hipHostGetDevicePointer((void**)&Cd, C, 0));
|
||||
|
||||
for(int i=0;i<LEN;i++){
|
||||
A[i] = 1.0f;
|
||||
B[i] = 2.0f;
|
||||
}
|
||||
|
||||
HIPCHECK(hipMalloc((void**)&Bd, SIZE));
|
||||
HIPCHECK(hipMemcpy(Bd, B, SIZE, hipMemcpyHostToDevice));
|
||||
|
||||
dim3 dimGrid(LEN/512,1,1);
|
||||
dim3 dimBlock(512,1,1);
|
||||
|
||||
hipLaunchKernel(HIP_KERNEL_NAME(Add), dimGrid, dimBlock, 0, 0, Ad, Bd, Cd);
|
||||
|
||||
passed();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
Copyright (c) 2015-2016 Advanced Micro Devices, Inc. All rights reserved.
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
/* HIT_START
|
||||
* BUILD: %t %s ../../test_common.cpp
|
||||
* RUN: %t
|
||||
* HIT_END
|
||||
*/
|
||||
|
||||
#include"test_common.h"
|
||||
#include<malloc.h>
|
||||
|
||||
__global__ void Inc(hipLaunchParm lp, float *Ad){
|
||||
int tx = hipThreadIdx_x + hipBlockIdx_x * hipBlockDim_x;
|
||||
Ad[tx] = Ad[tx] + float(1);
|
||||
}
|
||||
|
||||
int main(){
|
||||
float *A, **Ad;
|
||||
int num_devices;
|
||||
HIPCHECK(hipGetDeviceCount(&num_devices));
|
||||
Ad = new float*[num_devices];
|
||||
const size_t size = N * sizeof(float);
|
||||
A = (float*)malloc(size);
|
||||
HIPCHECK(hipHostRegister(A, size, 0));
|
||||
for(int i=0;i<N;i++){
|
||||
A[i] = float(1);
|
||||
}
|
||||
for(int i=0;i<num_devices;i++){
|
||||
HIPCHECK(hipSetDevice(i));
|
||||
HIPCHECK(hipHostGetDevicePointer((void**)&Ad[i], A, 0));
|
||||
}
|
||||
|
||||
for(int i=0;i<num_devices;i++){
|
||||
HIPCHECK(hipSetDevice(i));
|
||||
hipLaunchKernel(HIP_KERNEL_NAME(Inc), dim3(N/512), dim3(512), 0, 0, Ad[i]);
|
||||
|
||||
HIPCHECK(hipDeviceSynchronize());
|
||||
|
||||
}
|
||||
HIPASSERT(A[10] == 1.0f + float(num_devices));
|
||||
HIPCHECK(hipHostUnregister(A));
|
||||
passed();
|
||||
}
|
||||
@@ -1,3 +1,27 @@
|
||||
/*
|
||||
Copyright (c) 2015-2016 Advanced Micro Devices, Inc. All rights reserved.
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
/* HIT_START
|
||||
* BUILD: %t %s ../../test_common.cpp
|
||||
* HIT_END
|
||||
*/
|
||||
|
||||
#include"test_common.h"
|
||||
|
||||
#define SIZE 1024*1024
|
||||
|
||||
@@ -0,0 +1,105 @@
|
||||
/*
|
||||
Copyright (c) 2015-2016 Advanced Micro Devices, Inc. All rights reserved.
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
/* HIT_START
|
||||
* BUILD: %t %s ../../test_common.cpp
|
||||
* RUN: %t
|
||||
* HIT_END
|
||||
*/
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "hip/hip_runtime.h"
|
||||
#include "test_common.h"
|
||||
|
||||
#define WIDTH 1024
|
||||
#define HEIGHT 1024
|
||||
|
||||
#define NUM (WIDTH*HEIGHT)
|
||||
|
||||
#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 *deviceA;
|
||||
int *deviceB;
|
||||
|
||||
int i;
|
||||
int errors;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
HIPCHECK(hipMalloc((void**)&deviceA, NUM * sizeof(int)));
|
||||
HIPCHECK(hipMalloc((void**)&deviceB, NUM * sizeof(int)));
|
||||
|
||||
hipStream_t s;
|
||||
HIPCHECK(hipStreamCreate(&s));
|
||||
|
||||
|
||||
// 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));
|
||||
#else
|
||||
HIPCHECK(hipMemcpy(deviceB, hostB, NUM*sizeof(int), hipMemcpyHostToDevice));
|
||||
HIPCHECK(hipMemcpy(hostA, deviceB, NUM*sizeof(int), hipMemcpyDeviceToHost));
|
||||
#endif
|
||||
|
||||
HIPCHECK(hipStreamSynchronize(s));
|
||||
HIPCHECK(hipDeviceSynchronize());
|
||||
|
||||
// verify the results
|
||||
errors = 0;
|
||||
for (i = 0; i < NUM; i++) {
|
||||
if (hostA[i] != (hostB[i])) {
|
||||
errors++;
|
||||
}
|
||||
}
|
||||
|
||||
HIPCHECK(hipStreamDestroy(s));
|
||||
|
||||
HIPCHECK(hipFree(deviceA));
|
||||
HIPCHECK(hipFree(deviceB));
|
||||
|
||||
free(hostA);
|
||||
free(hostB);
|
||||
|
||||
//hipResetDefaultAccelerator();
|
||||
|
||||
if(errors != 0){
|
||||
HIPASSERT(1 == 2);
|
||||
}else{
|
||||
passed();
|
||||
}
|
||||
|
||||
return errors;
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
Copyright (c) 2015-2016 Advanced Micro Devices, Inc. All rights reserved.
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
/* HIT_START
|
||||
* BUILD: %t %s ../../test_common.cpp
|
||||
* RUN: %t
|
||||
* HIT_END
|
||||
*/
|
||||
|
||||
#include "hip/hip_runtime.h"
|
||||
#include"test_common.h"
|
||||
|
||||
#define len 1024*1024
|
||||
#define size len * sizeof(float)
|
||||
|
||||
int main(){
|
||||
float *Ad, *A;
|
||||
hipHostMalloc((void**)&A, size);
|
||||
hipMalloc((void**)&Ad, size);
|
||||
assert(hipSuccess == hipMemcpy(Ad, A, size, hipMemcpyHostToDevice));
|
||||
assert(hipSuccess == hipMemcpy(A, Ad, size, hipMemcpyDeviceToHost));
|
||||
passed();
|
||||
}
|
||||
Reference in new issue
Block a user