Apply .clangformat to all repo source files
Change-Id: I7e79c6058f0303f9a98911e3b7dd2e8596079344
This commit is contained in:
@@ -11,25 +11,24 @@
|
||||
|
||||
|
||||
// Create a lot of streams and then destroy 'em.
|
||||
void createThenDestroyStreams(int iterations, int burstSize)
|
||||
{
|
||||
hipStream_t *streams = new hipStream_t[burstSize];
|
||||
void createThenDestroyStreams(int iterations, int burstSize) {
|
||||
hipStream_t* streams = new hipStream_t[burstSize];
|
||||
|
||||
for (int i=0; i<iterations; i++) {
|
||||
for (int i = 0; i < iterations; i++) {
|
||||
if (p_verbose & 0x1) {
|
||||
printf ("%s iter=%d, create %d then destroy %d\n", __func__, i, burstSize, burstSize);
|
||||
printf("%s iter=%d, create %d then destroy %d\n", __func__, i, burstSize, burstSize);
|
||||
}
|
||||
for (int j=0; j<burstSize; j++) {
|
||||
for (int j = 0; j < burstSize; j++) {
|
||||
if (p_verbose & 0x2) {
|
||||
printf (" %d.%d streamCreate\n", i, j);
|
||||
printf(" %d.%d streamCreate\n", i, j);
|
||||
}
|
||||
HIPCHECK( hipStreamCreate(&streams[j]));
|
||||
HIPCHECK(hipStreamCreate(&streams[j]));
|
||||
}
|
||||
for (int j=0; j<burstSize; j++) {
|
||||
for (int j = 0; j < burstSize; j++) {
|
||||
if (p_verbose & 0x2) {
|
||||
printf (" %d.%d streamDestroy\n", i, j);
|
||||
printf(" %d.%d streamDestroy\n", i, j);
|
||||
}
|
||||
HIPCHECK( hipStreamDestroy(streams[j]));
|
||||
HIPCHECK(hipStreamDestroy(streams[j]));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,11 +36,11 @@ void createThenDestroyStreams(int iterations, int burstSize)
|
||||
}
|
||||
|
||||
|
||||
void waitStreams(int iterations)
|
||||
{
|
||||
void waitStreams(int iterations) {
|
||||
// Repeatedly sync and wait for all streams to complete.
|
||||
// TO make this interesting, the test has other threads repeatedly adding and removing streams to the device.
|
||||
for (int i=0; i<iterations; i++) {
|
||||
// TO make this interesting, the test has other threads repeatedly adding and removing streams
|
||||
// to the device.
|
||||
for (int i = 0; i < iterations; i++) {
|
||||
HIPCHECK(hipDeviceSynchronize());
|
||||
}
|
||||
}
|
||||
@@ -50,22 +49,21 @@ void waitStreams(int iterations)
|
||||
// Create 3 streams, all creating and destroying streams on the same device.
|
||||
// Some create many queue, some not many.
|
||||
//
|
||||
void multiThread_pyramid(bool serialize, int iters)
|
||||
{
|
||||
printf ("%s creating %d streams\n", __func__, iters*100);
|
||||
std::thread t1 (createThenDestroyStreams, iters*1, 100);
|
||||
void multiThread_pyramid(bool serialize, int iters) {
|
||||
printf("%s creating %d streams\n", __func__, iters * 100);
|
||||
std::thread t1(createThenDestroyStreams, iters * 1, 100);
|
||||
if (serialize) {
|
||||
t1.join();
|
||||
printf("t1 done\n");
|
||||
}
|
||||
|
||||
std::thread t2 (createThenDestroyStreams, iters*10, 10);
|
||||
std::thread t2(createThenDestroyStreams, iters * 10, 10);
|
||||
if (serialize) {
|
||||
t2.join();
|
||||
printf("t2 done\n");
|
||||
}
|
||||
|
||||
std::thread t3 (createThenDestroyStreams, iters*100, 1);
|
||||
std::thread t3(createThenDestroyStreams, iters * 100, 1);
|
||||
if (serialize) {
|
||||
t3.join();
|
||||
printf("t3 done\n");
|
||||
@@ -76,69 +74,68 @@ void multiThread_pyramid(bool serialize, int iters)
|
||||
t2.join();
|
||||
t3.join();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
// Create 3 streams, all creating and destroying streams on the same device.
|
||||
// Try to keep number of streams near zero, to cause problems.
|
||||
void multiThread_nearzero(bool serialize, int iters)
|
||||
{
|
||||
printf ("%s creating %d streams x 3 threads\n", __func__, iters);
|
||||
std::thread t1 (createThenDestroyStreams, iters, 1);
|
||||
void multiThread_nearzero(bool serialize, int iters) {
|
||||
printf("%s creating %d streams x 3 threads\n", __func__, iters);
|
||||
std::thread t1(createThenDestroyStreams, iters, 1);
|
||||
if (serialize) {
|
||||
t1.join();
|
||||
printf("t1 done\n");
|
||||
}
|
||||
|
||||
std::thread t2 (createThenDestroyStreams, iters, 1);
|
||||
std::thread t2(createThenDestroyStreams, iters, 1);
|
||||
if (serialize) {
|
||||
t2.join();
|
||||
printf("t2 done\n");
|
||||
}
|
||||
|
||||
std::thread t3 (waitStreams, iters*50);
|
||||
std::thread t3(waitStreams, iters * 50);
|
||||
if (serialize) {
|
||||
t3.join();
|
||||
printf("t3 done\n");
|
||||
}
|
||||
|
||||
if (!serialize) {
|
||||
t1.join(); printf ("t1 done\n");
|
||||
t2.join(); printf ("t2 done\n");
|
||||
t3.join(); printf ("t3 done\n");
|
||||
t1.join();
|
||||
printf("t1 done\n");
|
||||
t2.join();
|
||||
printf("t2 done\n");
|
||||
t3.join();
|
||||
printf("t3 done\n");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int main(int argc, char* argv[]) {
|
||||
HipTest::parseStandardArguments(argc, argv, true);
|
||||
|
||||
// Serial version, just call once:
|
||||
if (p_tests & 0x1) {
|
||||
printf ("\ntest 0x1 : serial createThenDestroyStreams(10) \n");
|
||||
printf("\ntest 0x1 : serial createThenDestroyStreams(10) \n");
|
||||
createThenDestroyStreams(10, 10);
|
||||
};
|
||||
|
||||
/*disable, this takess a while and if the next one works then no need to run serial*/
|
||||
if (1 && (p_tests & 0x2)) {
|
||||
printf ("\ntest 0x2 : serialized multiThread_pyramid(1) \n");
|
||||
printf("\ntest 0x2 : serialized multiThread_pyramid(1) \n");
|
||||
multiThread_pyramid(true, 3);
|
||||
}
|
||||
|
||||
if (p_tests & 0x4) {
|
||||
printf ("\ntest 0x4 : parallel multiThread_pyramid(1) \n");
|
||||
printf("\ntest 0x4 : parallel multiThread_pyramid(1) \n");
|
||||
multiThread_pyramid(false, 3);
|
||||
}
|
||||
|
||||
//if (p_tests & 0x8) {
|
||||
// if (p_tests & 0x8) {
|
||||
// printf ("test 0x8 : multiThread_pyramid(100) \n");
|
||||
// multiThread_pyramid(false, 100);
|
||||
// }
|
||||
// }
|
||||
|
||||
if (p_tests & 0x10) {
|
||||
printf ("\ntest 0x10 : parallel multiThread_nearzero(1000) \n");
|
||||
printf("\ntest 0x10 : parallel multiThread_nearzero(1000) \n");
|
||||
multiThread_nearzero(false, 1000);
|
||||
}
|
||||
|
||||
|
||||
@@ -29,106 +29,91 @@ THE SOFTWARE.
|
||||
#include "hip/hip_runtime.h"
|
||||
#include "test_common.h"
|
||||
|
||||
int p_iters=10;
|
||||
int p_iters = 10;
|
||||
|
||||
void printSep()
|
||||
{
|
||||
printf ("======================================================================================\n");
|
||||
void printSep() {
|
||||
printf(
|
||||
"======================================================================================\n");
|
||||
}
|
||||
|
||||
//---
|
||||
// Test simple H2D copies and back.
|
||||
// Designed to stress a small number of simple smoke tests
|
||||
|
||||
template<
|
||||
typename T=float,
|
||||
class P=HipTest::Unpinned,
|
||||
class C=HipTest::Memcpy
|
||||
>
|
||||
void simpleVectorAdd(size_t numElements, int iters, hipStream_t stream)
|
||||
{
|
||||
using HipTest::MemTraits;
|
||||
template <typename T = float, class P = HipTest::Unpinned, class C = HipTest::Memcpy>
|
||||
void simpleVectorAdd(size_t numElements, int iters, hipStream_t stream) {
|
||||
using HipTest::MemTraits;
|
||||
|
||||
std::thread::id pid = std::this_thread::get_id();
|
||||
std::thread::id pid = std::this_thread::get_id();
|
||||
|
||||
printf ("test: %s <%s> %s %s\n", __func__, TYPENAME(T), P::str(), C::str());
|
||||
size_t Nbytes = numElements*sizeof(T);
|
||||
printf ("numElements=%zu Nbytes=%6.2fMB\n", numElements, Nbytes/1024.0/1024.0);
|
||||
printf("test: %s <%s> %s %s\n", __func__, TYPENAME(T), P::str(), C::str());
|
||||
size_t Nbytes = numElements * sizeof(T);
|
||||
printf("numElements=%zu Nbytes=%6.2fMB\n", numElements, Nbytes / 1024.0 / 1024.0);
|
||||
|
||||
T *A_d, *B_d, *C_d;
|
||||
T *A_h, *B_h, *C_h;
|
||||
|
||||
HipTest::initArrays (&A_d, &B_d, &C_d, &A_h, &B_h, &C_h, N, P::isPinned);
|
||||
for (size_t i=0; i<numElements; i++) {
|
||||
A_h[i] = 1000.0f;
|
||||
B_h[i] = 2000.0f;
|
||||
C_h[i] = -1;
|
||||
}
|
||||
HipTest::initArrays(&A_d, &B_d, &C_d, &A_h, &B_h, &C_h, N, P::isPinned);
|
||||
for (size_t i = 0; i < numElements; i++) {
|
||||
A_h[i] = 1000.0f;
|
||||
B_h[i] = 2000.0f;
|
||||
C_h[i] = -1;
|
||||
}
|
||||
|
||||
|
||||
MemTraits<C>::Copy(B_d, B_h, Nbytes, hipMemcpyHostToDevice, stream);
|
||||
MemTraits<C>::Copy(A_d, A_h, Nbytes, hipMemcpyHostToDevice, stream);
|
||||
MemTraits<C>::Copy(C_d, C_h, Nbytes, hipMemcpyHostToDevice, stream);
|
||||
HIPCHECK (hipDeviceSynchronize());
|
||||
MemTraits<C>::Copy(B_d, B_h, Nbytes, hipMemcpyHostToDevice, stream);
|
||||
MemTraits<C>::Copy(A_d, A_h, Nbytes, hipMemcpyHostToDevice, stream);
|
||||
MemTraits<C>::Copy(C_d, C_h, Nbytes, hipMemcpyHostToDevice, stream);
|
||||
HIPCHECK(hipDeviceSynchronize());
|
||||
|
||||
for (size_t i=0; i<numElements; i++) {
|
||||
A_h[i] = 1.0f;
|
||||
B_h[i] = 2.0f;
|
||||
C_h[i] = -1;
|
||||
}
|
||||
for (size_t i = 0; i < numElements; i++) {
|
||||
A_h[i] = 1.0f;
|
||||
B_h[i] = 2.0f;
|
||||
C_h[i] = -1;
|
||||
}
|
||||
|
||||
|
||||
for (int i = 0; i < iters; i++) {
|
||||
unsigned blocks = HipTest::setNumBlocks(blocksPerCU, threadsPerBlock, numElements);
|
||||
|
||||
for (int i=0; i<iters; i++) {
|
||||
MemTraits<C>::Copy(A_d, A_h, Nbytes, hipMemcpyHostToDevice, stream);
|
||||
MemTraits<C>::Copy(B_d, B_h, Nbytes, hipMemcpyHostToDevice, stream);
|
||||
|
||||
unsigned blocks = HipTest::setNumBlocks(blocksPerCU, threadsPerBlock, numElements);
|
||||
// HIPCHECK(hipStreamSynchronize(stream));
|
||||
|
||||
MemTraits<C>::Copy(A_d, A_h, Nbytes, hipMemcpyHostToDevice, stream);
|
||||
MemTraits<C>::Copy(B_d, B_h, Nbytes, hipMemcpyHostToDevice, stream);
|
||||
// This is the null stream?
|
||||
// hipLaunchKernel(HipTest::vectorADD, dim3(blocks), dim3(threadsPerBlock), 0, 0, A_d, B_d,
|
||||
// C_d, numElements);
|
||||
hipLaunchKernel(HipTest::vectorADDReverse, dim3(blocks), dim3(threadsPerBlock), 0, 0,
|
||||
static_cast<const T*>(A_d), static_cast<const T*>(B_d), C_d, numElements);
|
||||
|
||||
//HIPCHECK(hipStreamSynchronize(stream));
|
||||
MemTraits<C>::Copy(C_h, C_d, Nbytes, hipMemcpyDeviceToHost, stream);
|
||||
|
||||
// This is the null stream?
|
||||
//hipLaunchKernel(HipTest::vectorADD, dim3(blocks), dim3(threadsPerBlock), 0, 0, A_d, B_d, C_d, numElements);
|
||||
hipLaunchKernel(
|
||||
HipTest::vectorADDReverse,
|
||||
dim3(blocks),
|
||||
dim3(threadsPerBlock),
|
||||
0,
|
||||
0,
|
||||
static_cast<const T*>(A_d),
|
||||
static_cast<const T*>(B_d),
|
||||
C_d,
|
||||
numElements);
|
||||
HIPCHECK(hipDeviceSynchronize());
|
||||
|
||||
MemTraits<C>::Copy(C_h, C_d, Nbytes, hipMemcpyDeviceToHost, stream);
|
||||
|
||||
HIPCHECK (hipDeviceSynchronize());
|
||||
|
||||
HipTest::checkVectorADD(A_h, B_h, C_h, numElements);
|
||||
}
|
||||
|
||||
HipTest::freeArrays (A_d, B_d, C_d, A_h, B_h, C_h, P::isPinned);
|
||||
std::cout <<" pid" << pid << " success\n";
|
||||
HIPCHECK (hipDeviceSynchronize());
|
||||
HipTest::checkVectorADD(A_h, B_h, C_h, numElements);
|
||||
}
|
||||
|
||||
HipTest::freeArrays(A_d, B_d, C_d, A_h, B_h, C_h, P::isPinned);
|
||||
std::cout << " pid" << pid << " success\n";
|
||||
HIPCHECK(hipDeviceSynchronize());
|
||||
}
|
||||
|
||||
template<typename T, class C>
|
||||
void test_multiThread_1(std::string testName, hipStream_t stream0, hipStream_t stream1, bool serialize)
|
||||
{
|
||||
printSep();
|
||||
printf ("%s\n", __func__);
|
||||
std::cout << testName << std::endl;
|
||||
template <typename T, class C>
|
||||
void test_multiThread_1(std::string testName, hipStream_t stream0, hipStream_t stream1,
|
||||
bool serialize) {
|
||||
printSep();
|
||||
printf("%s\n", __func__);
|
||||
std::cout << testName << std::endl;
|
||||
|
||||
size_t numElements = N;
|
||||
size_t numElements = N;
|
||||
|
||||
// Test 2 threads operating on same stream:
|
||||
std::thread t1 (simpleVectorAdd<T, HipTest::Pinned, C>, numElements, p_iters/*iters*/, stream0);
|
||||
// Test 2 threads operating on same stream:
|
||||
std::thread t1(simpleVectorAdd<T, HipTest::Pinned, C>, numElements, p_iters /*iters*/, stream0);
|
||||
if (serialize) {
|
||||
t1.join();
|
||||
}
|
||||
std::thread t2 (simpleVectorAdd<T, HipTest::Pinned, C>, numElements, p_iters/*iters*/, stream1);
|
||||
std::thread t2(simpleVectorAdd<T, HipTest::Pinned, C>, numElements, p_iters /*iters*/, stream1);
|
||||
if (serialize) {
|
||||
t2.join();
|
||||
}
|
||||
@@ -138,48 +123,51 @@ void test_multiThread_1(std::string testName, hipStream_t stream0, hipStream_t s
|
||||
t2.join();
|
||||
}
|
||||
|
||||
HIPCHECK(hipDeviceSynchronize());
|
||||
HIPCHECK(hipDeviceSynchronize());
|
||||
};
|
||||
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
N = 8000000;
|
||||
int main(int argc, char* argv[]) {
|
||||
N = 8000000;
|
||||
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) {
|
||||
HIPCHECK ( hipDeviceReset() );
|
||||
HIPCHECK(hipDeviceReset());
|
||||
|
||||
hipStream_t stream;
|
||||
HIPCHECK (hipStreamCreate(&stream));
|
||||
HIPCHECK(hipStreamCreate(&stream));
|
||||
|
||||
simpleVectorAdd<float, HipTest::Pinned, HipTest::MemcpyAsync> (N/*mb*/, 10/*iters*/, stream);
|
||||
simpleVectorAdd<float, HipTest::Pinned, HipTest::Memcpy> (N/*mb*/, 10/*iters*/, stream);
|
||||
simpleVectorAdd<float, HipTest::Pinned, HipTest::MemcpyAsync>(N /*mb*/, 10 /*iters*/,
|
||||
stream);
|
||||
simpleVectorAdd<float, HipTest::Pinned, HipTest::Memcpy>(N /*mb*/, 10 /*iters*/, stream);
|
||||
|
||||
HIPCHECK(hipStreamDestroy(stream));
|
||||
}
|
||||
|
||||
|
||||
hipStream_t stream0, stream1;
|
||||
HIPCHECK (hipStreamCreate(&stream0));
|
||||
HIPCHECK (hipStreamCreate(&stream1));
|
||||
HIPCHECK(hipStreamCreate(&stream0));
|
||||
HIPCHECK(hipStreamCreate(&stream1));
|
||||
|
||||
if (p_tests & 0x2) {
|
||||
// Easy tests to verify the test works - these don't allow overlap between the threads:
|
||||
test_multiThread_1<float, HipTest::MemcpyAsync> ("Multithread NULL with serialized", NULL, NULL, true);
|
||||
test_multiThread_1<float, HipTest::MemcpyAsync> ("Multithread two streams serialized", stream0, stream1, true);
|
||||
// Easy tests to verify the test works - these don't allow overlap between the threads:
|
||||
test_multiThread_1<float, HipTest::MemcpyAsync>("Multithread NULL with serialized", NULL,
|
||||
NULL, true);
|
||||
test_multiThread_1<float, HipTest::MemcpyAsync>("Multithread two streams serialized",
|
||||
stream0, stream1, true);
|
||||
}
|
||||
|
||||
if (p_tests & 0x4) {
|
||||
//test_multiThread_1<float, HipTest::MemcpyAsync> ("Multithread with NULL stream", NULL, NULL, false);
|
||||
//test_multiThread_1<float, HipTest::MemcpyAsync> ("Multithread with two streams", stream0, stream1, false);
|
||||
test_multiThread_1<float, HipTest::MemcpyAsync> ("Multithread with one stream", stream0, stream0, false);
|
||||
}
|
||||
// test_multiThread_1<float, HipTest::MemcpyAsync> ("Multithread with NULL stream", NULL,
|
||||
// NULL, false); test_multiThread_1<float, HipTest::MemcpyAsync> ("Multithread with two
|
||||
// streams", stream0, stream1, false);
|
||||
test_multiThread_1<float, HipTest::MemcpyAsync>("Multithread with one stream", stream0,
|
||||
stream0, false);
|
||||
}
|
||||
|
||||
passed();
|
||||
|
||||
}
|
||||
|
||||
@@ -26,70 +26,69 @@ THE SOFTWARE.
|
||||
* HIT_END
|
||||
*/
|
||||
|
||||
#include<iostream>
|
||||
#include"test_common.h"
|
||||
#include<thread>
|
||||
#include <iostream>
|
||||
#include "test_common.h"
|
||||
#include <thread>
|
||||
#define N 1000
|
||||
|
||||
|
||||
|
||||
template<typename T>
|
||||
__global__ void Inc(hipLaunchParm lp, T *Array){
|
||||
int tx = threadIdx.x + blockIdx.x * blockDim.x;
|
||||
Array[tx] = Array[tx] + T(1);
|
||||
template <typename T>
|
||||
__global__ void Inc(hipLaunchParm lp, T* Array) {
|
||||
int tx = threadIdx.x + blockIdx.x * blockDim.x;
|
||||
Array[tx] = Array[tx] + T(1);
|
||||
}
|
||||
|
||||
void run1(size_t size, hipStream_t stream){
|
||||
float *Ah, *Bh, *Cd, *Dd, *Eh;
|
||||
void run1(size_t size, hipStream_t stream) {
|
||||
float *Ah, *Bh, *Cd, *Dd, *Eh;
|
||||
|
||||
HIPCHECK(hipHostMalloc((void**)&Ah, size, hipHostMallocDefault));
|
||||
HIPCHECK(hipHostMalloc((void**)&Bh, size, hipHostMallocDefault));
|
||||
HIPCHECK(hipMalloc(&Cd, size));
|
||||
HIPCHECK(hipMalloc(&Dd, size));
|
||||
HIPCHECK(hipHostMalloc((void**)&Eh, size, hipHostMallocDefault));
|
||||
HIPCHECK(hipHostMalloc((void**)&Ah, size, hipHostMallocDefault));
|
||||
HIPCHECK(hipHostMalloc((void**)&Bh, size, hipHostMallocDefault));
|
||||
HIPCHECK(hipMalloc(&Cd, size));
|
||||
HIPCHECK(hipMalloc(&Dd, size));
|
||||
HIPCHECK(hipHostMalloc((void**)&Eh, size, hipHostMallocDefault));
|
||||
|
||||
for(int i=0;i<N;i++){
|
||||
Ah[i] = 1.0f;
|
||||
}
|
||||
for (int i = 0; i < N; i++) {
|
||||
Ah[i] = 1.0f;
|
||||
}
|
||||
|
||||
HIPCHECK(hipMemcpyAsync(Bh, Ah, size, hipMemcpyHostToHost, stream));
|
||||
HIPCHECK(hipMemcpyAsync(Cd, Bh, size, hipMemcpyHostToDevice, stream));
|
||||
hipLaunchKernel(HIP_KERNEL_NAME(Inc), dim3(N/500), dim3(500), 0, stream, Cd);
|
||||
HIPCHECK(hipMemcpyAsync(Dd, Cd, size, hipMemcpyDeviceToDevice, stream));
|
||||
HIPCHECK(hipMemcpyAsync(Eh, Dd, size, hipMemcpyDeviceToHost, stream));
|
||||
HIPCHECK(hipDeviceSynchronize());
|
||||
HIPASSERT(Eh[10] == Ah[10] + 1.0f);
|
||||
HIPCHECK(hipMemcpyAsync(Bh, Ah, size, hipMemcpyHostToHost, stream));
|
||||
HIPCHECK(hipMemcpyAsync(Cd, Bh, size, hipMemcpyHostToDevice, stream));
|
||||
hipLaunchKernel(HIP_KERNEL_NAME(Inc), dim3(N / 500), dim3(500), 0, stream, Cd);
|
||||
HIPCHECK(hipMemcpyAsync(Dd, Cd, size, hipMemcpyDeviceToDevice, stream));
|
||||
HIPCHECK(hipMemcpyAsync(Eh, Dd, size, hipMemcpyDeviceToHost, stream));
|
||||
HIPCHECK(hipDeviceSynchronize());
|
||||
HIPASSERT(Eh[10] == Ah[10] + 1.0f);
|
||||
}
|
||||
|
||||
|
||||
void run(size_t size, hipStream_t stream1, hipStream_t stream2){
|
||||
float *Ah, *Bh, *Cd, *Dd, *Eh;
|
||||
float *Ahh, *Bhh, *Cdd, *Ddd, *Ehh;
|
||||
void run(size_t size, hipStream_t stream1, hipStream_t stream2) {
|
||||
float *Ah, *Bh, *Cd, *Dd, *Eh;
|
||||
float *Ahh, *Bhh, *Cdd, *Ddd, *Ehh;
|
||||
|
||||
HIPCHECK(hipHostMalloc((void**)&Ah, size, hipHostMallocDefault));
|
||||
HIPCHECK(hipHostMalloc((void**)&Bh, size, hipHostMallocDefault));
|
||||
HIPCHECK(hipMalloc(&Cd, size));
|
||||
HIPCHECK(hipMalloc(&Dd, size));
|
||||
HIPCHECK(hipHostMalloc((void**)&Eh, size, hipHostMallocDefault));
|
||||
HIPCHECK(hipHostMalloc((void**)&Ahh, size, hipHostMallocDefault));
|
||||
HIPCHECK(hipHostMalloc((void**)&Bhh, size, hipHostMallocDefault));
|
||||
HIPCHECK(hipMalloc(&Cdd, size));
|
||||
HIPCHECK(hipMalloc(&Ddd, size));
|
||||
HIPCHECK(hipHostMalloc((void**)&Ehh, size, hipHostMallocDefault));
|
||||
HIPCHECK(hipHostMalloc((void**)&Ah, size, hipHostMallocDefault));
|
||||
HIPCHECK(hipHostMalloc((void**)&Bh, size, hipHostMallocDefault));
|
||||
HIPCHECK(hipMalloc(&Cd, size));
|
||||
HIPCHECK(hipMalloc(&Dd, size));
|
||||
HIPCHECK(hipHostMalloc((void**)&Eh, size, hipHostMallocDefault));
|
||||
HIPCHECK(hipHostMalloc((void**)&Ahh, size, hipHostMallocDefault));
|
||||
HIPCHECK(hipHostMalloc((void**)&Bhh, size, hipHostMallocDefault));
|
||||
HIPCHECK(hipMalloc(&Cdd, size));
|
||||
HIPCHECK(hipMalloc(&Ddd, size));
|
||||
HIPCHECK(hipHostMalloc((void**)&Ehh, size, hipHostMallocDefault));
|
||||
|
||||
HIPCHECK(hipMemcpyAsync(Bh, Ah, size, hipMemcpyHostToHost, stream1));
|
||||
HIPCHECK(hipMemcpyAsync(Bhh, Ahh, size, hipMemcpyHostToHost, stream2));
|
||||
HIPCHECK(hipMemcpyAsync(Cd, Bh, size, hipMemcpyHostToDevice, stream1));
|
||||
HIPCHECK(hipMemcpyAsync(Cdd, Bhh, size, hipMemcpyHostToDevice, stream2));
|
||||
hipLaunchKernel(HIP_KERNEL_NAME(Inc), dim3(N/500), dim3(500), 0, stream1, Cd);
|
||||
hipLaunchKernel(HIP_KERNEL_NAME(Inc), dim3(N/500), dim3(500), 0, stream2, Cdd);
|
||||
HIPCHECK(hipMemcpyAsync(Dd, Cd, size, hipMemcpyDeviceToDevice, stream1));
|
||||
HIPCHECK(hipMemcpyAsync(Ddd, Cdd, size, hipMemcpyDeviceToDevice, stream2));
|
||||
HIPCHECK(hipMemcpyAsync(Eh, Dd, size, hipMemcpyDeviceToHost, stream1));
|
||||
HIPCHECK(hipMemcpyAsync(Ehh, Ddd, size, hipMemcpyDeviceToHost, stream2));
|
||||
HIPCHECK(hipDeviceSynchronize());
|
||||
HIPASSERT(Eh[10] = Ah[10] + 1.0f);
|
||||
HIPASSERT(Ehh[10] = Ahh[10] + 1.0f);
|
||||
HIPCHECK(hipMemcpyAsync(Bh, Ah, size, hipMemcpyHostToHost, stream1));
|
||||
HIPCHECK(hipMemcpyAsync(Bhh, Ahh, size, hipMemcpyHostToHost, stream2));
|
||||
HIPCHECK(hipMemcpyAsync(Cd, Bh, size, hipMemcpyHostToDevice, stream1));
|
||||
HIPCHECK(hipMemcpyAsync(Cdd, Bhh, size, hipMemcpyHostToDevice, stream2));
|
||||
hipLaunchKernel(HIP_KERNEL_NAME(Inc), dim3(N / 500), dim3(500), 0, stream1, Cd);
|
||||
hipLaunchKernel(HIP_KERNEL_NAME(Inc), dim3(N / 500), dim3(500), 0, stream2, Cdd);
|
||||
HIPCHECK(hipMemcpyAsync(Dd, Cd, size, hipMemcpyDeviceToDevice, stream1));
|
||||
HIPCHECK(hipMemcpyAsync(Ddd, Cdd, size, hipMemcpyDeviceToDevice, stream2));
|
||||
HIPCHECK(hipMemcpyAsync(Eh, Dd, size, hipMemcpyDeviceToHost, stream1));
|
||||
HIPCHECK(hipMemcpyAsync(Ehh, Ddd, size, hipMemcpyDeviceToHost, stream2));
|
||||
HIPCHECK(hipDeviceSynchronize());
|
||||
HIPASSERT(Eh[10] = Ah[10] + 1.0f);
|
||||
HIPASSERT(Ehh[10] = Ahh[10] + 1.0f);
|
||||
|
||||
HIPCHECK(hipHostFree(Ah));
|
||||
HIPCHECK(hipHostFree(Bh));
|
||||
@@ -103,31 +102,28 @@ void run(size_t size, hipStream_t stream1, hipStream_t stream2){
|
||||
HIPCHECK(hipFree(Ddd));
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int main(int argc, char** argv) {
|
||||
iterations = 100;
|
||||
|
||||
HipTest::parseStandardArguments(argc, argv, true);
|
||||
HipTest::parseStandardArguments(argc, argv, true);
|
||||
|
||||
|
||||
hipStream_t stream[3];
|
||||
for(int i=0;i<3;i++){
|
||||
HIPCHECK(hipStreamCreate(&stream[i]));
|
||||
}
|
||||
|
||||
const size_t size = N * sizeof(float);
|
||||
|
||||
for (int i=0; i< iterations; i++) {
|
||||
|
||||
std::thread t1(run1, size, stream[0]);
|
||||
std::thread t2(run1, size, stream[0]);
|
||||
std::thread t3(run, size, stream[1], stream[2]);
|
||||
t1.join();
|
||||
// std::cout<<"T1"<<std::endl;
|
||||
t2.join();
|
||||
// std::cout<<"T2"<<std::endl;
|
||||
t3.join();
|
||||
hipStream_t stream[3];
|
||||
for (int i = 0; i < 3; i++) {
|
||||
HIPCHECK(hipStreamCreate(&stream[i]));
|
||||
}
|
||||
passed();
|
||||
}
|
||||
|
||||
const size_t size = N * sizeof(float);
|
||||
|
||||
for (int i = 0; i < iterations; i++) {
|
||||
std::thread t1(run1, size, stream[0]);
|
||||
std::thread t2(run1, size, stream[0]);
|
||||
std::thread t3(run, size, stream[1], stream[2]);
|
||||
t1.join();
|
||||
// std::cout<<"T1"<<std::endl;
|
||||
t2.join();
|
||||
// std::cout<<"T2"<<std::endl;
|
||||
t3.join();
|
||||
}
|
||||
passed();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user