SWDEV-470698 - fix formatting, add format check workflow (#657)
This commit is contained in:
committato da
GitHub
parent
5840940caa
commit
f7338717ae
@@ -33,26 +33,24 @@ enum TestType { SameStream = 0, DifferentStreams };
|
||||
// Func -> Memset/MemsetD[8/16/32], T - type of data to be worked on
|
||||
// basically each thread memsets value present in input one by one on its
|
||||
// allocated buffer
|
||||
template <typename Func, typename T>
|
||||
void threadCall(Func f, hipStream_t stream) {
|
||||
template <typename Func, typename T> void threadCall(Func f, hipStream_t stream) {
|
||||
// Should match hipMemsetAsync or hipMemsetD*Async arguments
|
||||
static_assert(
|
||||
(std::is_same<Func, hipError_t (*)(void *, int, size_t, hipStream_t)>::
|
||||
value || // hipMemsetAsync
|
||||
(std::is_same<Func,
|
||||
hipError_t (*)(void*, int, size_t, hipStream_t)>::value || // hipMemsetAsync
|
||||
std::is_same<Func,
|
||||
hipError_t (*)(hipDeviceptr_t, int, size_t,
|
||||
hipStream_t)>::value || // hipMemsetD32Async
|
||||
hipStream_t)>::value || // hipMemsetD32Async
|
||||
std::is_same<Func,
|
||||
hipError_t (*)(hipDeviceptr_t, unsigned short, size_t,
|
||||
hipStream_t)>::value || // hipMemsetD16Async
|
||||
hipStream_t)>::value || // hipMemsetD16Async
|
||||
std::is_same<Func,
|
||||
hipError_t (*)(hipDeviceptr_t, unsigned char, size_t,
|
||||
hipStream_t)>::value) && // hipMemsetD8Async
|
||||
hipStream_t)>::value) && // hipMemsetD8Async
|
||||
"Func f should be hipMemsetAsync or hipMemsetD*Async");
|
||||
|
||||
constexpr bool cast_2_void =
|
||||
std::is_same<Func,
|
||||
hipError_t (*)(void *, int, size_t, hipStream_t)>::value;
|
||||
std::is_same<Func, hipError_t (*)(void*, int, size_t, hipStream_t)>::value;
|
||||
|
||||
// Use the unsiged type, since memset concerns with set bit values over a mem
|
||||
// address
|
||||
@@ -63,10 +61,10 @@ void threadCall(Func f, hipStream_t stream) {
|
||||
|
||||
std::mt19937_64 engine(std::random_device{}());
|
||||
auto distribution = std::uniform_int_distribution<unsigned int>(
|
||||
min, max); // this needs to be unsigned because windows does not treats
|
||||
// char as numeric types
|
||||
min, max); // this needs to be unsigned because windows does not treats
|
||||
// char as numeric types
|
||||
|
||||
T *ptr{nullptr};
|
||||
T* ptr{nullptr};
|
||||
constexpr size_t size = 1024;
|
||||
constexpr size_t iter = 1024;
|
||||
HIP_CHECK_THREAD(hipMalloc(&ptr, sizeof(T) * size));
|
||||
@@ -80,19 +78,17 @@ void threadCall(Func f, hipStream_t stream) {
|
||||
|
||||
std::vector<T> dst(size, 0);
|
||||
for (size_t i = 0; i < iter; i++) {
|
||||
overlay_val.u_val = static_cast<unsigned_t>(
|
||||
distribution(engine)); // generate an unsigned int number
|
||||
overlay_val.u_val =
|
||||
static_cast<unsigned_t>(distribution(engine)); // generate an unsigned int number
|
||||
if constexpr (cast_2_void) {
|
||||
HIP_CHECK_THREAD(f((void *)ptr, overlay_val.t_val, size, stream));
|
||||
HIP_CHECK_THREAD(f((void*)ptr, overlay_val.t_val, size, stream));
|
||||
} else {
|
||||
HIP_CHECK_THREAD(
|
||||
f(*(hipDeviceptr_t *)&ptr, overlay_val.t_val, size, stream));
|
||||
HIP_CHECK_THREAD(f(*(hipDeviceptr_t*)&ptr, overlay_val.t_val, size, stream));
|
||||
}
|
||||
HIP_CHECK_THREAD(hipMemcpyAsync(dst.data(), ptr, size * sizeof(T),
|
||||
hipMemcpyDeviceToHost, stream));
|
||||
HIP_CHECK_THREAD(hipEventRecord(event, stream));
|
||||
HIP_CHECK_THREAD(
|
||||
hipStreamWaitEvent(stream, event, 0)); // wait till memcpy is done
|
||||
hipMemcpyAsync(dst.data(), ptr, size * sizeof(T), hipMemcpyDeviceToHost, stream));
|
||||
HIP_CHECK_THREAD(hipEventRecord(event, stream));
|
||||
HIP_CHECK_THREAD(hipStreamWaitEvent(stream, event, 0)); // wait till memcpy is done
|
||||
REQUIRE_THREAD(std::all_of(dst.begin(), dst.end(), [&](T v) {
|
||||
// If this test ever fails, add prints here on mismatch
|
||||
return v == overlay_val.t_val;
|
||||
@@ -109,25 +105,24 @@ template <typename Func, typename T> void launchThreads(Func f, TestType type) {
|
||||
|
||||
// Should match hipMemsetAsync or hipMemsetD*Async arguments
|
||||
static_assert(
|
||||
(std::is_same<Func, hipError_t (*)(void *, int, size_t, hipStream_t)>::
|
||||
value || // hipMemsetAsync
|
||||
(std::is_same<Func,
|
||||
hipError_t (*)(void*, int, size_t, hipStream_t)>::value || // hipMemsetAsync
|
||||
std::is_same<Func,
|
||||
hipError_t (*)(hipDeviceptr_t, int, size_t,
|
||||
hipStream_t)>::value || // hipMemsetD32Async
|
||||
hipStream_t)>::value || // hipMemsetD32Async
|
||||
std::is_same<Func,
|
||||
hipError_t (*)(hipDeviceptr_t, unsigned short, size_t,
|
||||
hipStream_t)>::value || // hipMemsetD16Async
|
||||
hipStream_t)>::value || // hipMemsetD16Async
|
||||
std::is_same<Func,
|
||||
hipError_t (*)(hipDeviceptr_t, unsigned char, size_t,
|
||||
hipStream_t)>::value) && // hipMemsetD8Async
|
||||
hipStream_t)>::value) && // hipMemsetD8Async
|
||||
"Func f should be hipMemsetAsync or hipMemsetD*Async");
|
||||
|
||||
const size_t num_threads =
|
||||
(std::thread::hardware_concurrency() > 8)
|
||||
? (((std::thread::hardware_concurrency() / 4) >= 127)
|
||||
? 127
|
||||
: (std::thread::hardware_concurrency() / 4))
|
||||
: 2; // thread count between 2 - 127
|
||||
const size_t num_threads = (std::thread::hardware_concurrency() > 8)
|
||||
? (((std::thread::hardware_concurrency() / 4) >= 127)
|
||||
? 127
|
||||
: (std::thread::hardware_concurrency() / 4))
|
||||
: 2; // thread count between 2 - 127
|
||||
|
||||
const size_t num_streams = (type == SameStream) ? 1 : num_threads;
|
||||
std::vector<hipStream_t> streams(num_streams, nullptr);
|
||||
@@ -149,7 +144,7 @@ template <typename Func, typename T> void launchThreads(Func f, TestType type) {
|
||||
thread_pool[i].join();
|
||||
}
|
||||
|
||||
HIP_CHECK_THREAD_FINALIZE(); // Make sure all thread have exited properly
|
||||
HIP_CHECK_THREAD_FINALIZE(); // Make sure all thread have exited properly
|
||||
|
||||
for (size_t i = 0; i < num_streams; i++) {
|
||||
HIP_CHECK(hipStreamDestroy(streams[i]));
|
||||
@@ -157,26 +152,20 @@ template <typename Func, typename T> void launchThreads(Func f, TestType type) {
|
||||
}
|
||||
|
||||
TEST_CASE("Unit_hipMemsetAsync_QueueJobsMultithreaded") {
|
||||
using hipMemsetAsync_t =
|
||||
hipError_t (*)(void *, int, const size_t, hipStream_t);
|
||||
using hipMemsetAsync_t = hipError_t (*)(void*, int, const size_t, hipStream_t);
|
||||
using hipMemsetAsyncD8_t =
|
||||
hipError_t (*)(hipDeviceptr_t, unsigned char, const size_t, hipStream_t);
|
||||
using hipMemsetAsyncD16_t =
|
||||
hipError_t (*)(hipDeviceptr_t, unsigned short, const size_t, hipStream_t);
|
||||
using hipMemsetAsyncD32_t =
|
||||
hipError_t (*)(hipDeviceptr_t, int, const size_t, hipStream_t);
|
||||
using hipMemsetAsyncD32_t = hipError_t (*)(hipDeviceptr_t, int, const size_t, hipStream_t);
|
||||
|
||||
launchThreads<hipMemsetAsync_t, char>(hipMemsetAsync, SameStream);
|
||||
launchThreads<hipMemsetAsync_t, char>(hipMemsetAsync, DifferentStreams);
|
||||
|
||||
launchThreads<hipMemsetAsyncD8_t, unsigned char>(hipMemsetD8Async,
|
||||
SameStream);
|
||||
launchThreads<hipMemsetAsyncD8_t, unsigned char>(hipMemsetD8Async,
|
||||
DifferentStreams);
|
||||
launchThreads<hipMemsetAsyncD16_t, unsigned short>(hipMemsetD16Async,
|
||||
SameStream);
|
||||
launchThreads<hipMemsetAsyncD16_t, unsigned short>(hipMemsetD16Async,
|
||||
DifferentStreams);
|
||||
launchThreads<hipMemsetAsyncD8_t, unsigned char>(hipMemsetD8Async, SameStream);
|
||||
launchThreads<hipMemsetAsyncD8_t, unsigned char>(hipMemsetD8Async, DifferentStreams);
|
||||
launchThreads<hipMemsetAsyncD16_t, unsigned short>(hipMemsetD16Async, SameStream);
|
||||
launchThreads<hipMemsetAsyncD16_t, unsigned short>(hipMemsetD16Async, DifferentStreams);
|
||||
launchThreads<hipMemsetAsyncD32_t, int>(hipMemsetD32Async, SameStream);
|
||||
launchThreads<hipMemsetAsyncD32_t, int>(hipMemsetD32Async, DifferentStreams);
|
||||
}
|
||||
|
||||
@@ -2,35 +2,35 @@
|
||||
#include <hip_test_common.hh>
|
||||
|
||||
#ifdef _WIN32
|
||||
#define MAX_BURST_SIZE 40
|
||||
#define MAX_BURST_SIZE 40
|
||||
#else
|
||||
#define MAX_BURST_SIZE 100
|
||||
#define MAX_BURST_SIZE 100
|
||||
#endif
|
||||
|
||||
// Create a lot of streams and then destroy 'em.
|
||||
void createThenDestroyStreams(int iterations, int burstSize) {
|
||||
hipStream_t* streams = new hipStream_t[burstSize];
|
||||
hipStream_t* streams = new hipStream_t[burstSize];
|
||||
|
||||
for (int i = 0; i < iterations; i++) {
|
||||
for (int j = 0; j < burstSize; j++) {
|
||||
HIPCHECK(hipStreamCreate(&streams[j]));
|
||||
}
|
||||
for (int j = 0; j < burstSize; j++) {
|
||||
HIPCHECK(hipStreamDestroy(streams[j]));
|
||||
}
|
||||
for (int i = 0; i < iterations; i++) {
|
||||
for (int j = 0; j < burstSize; j++) {
|
||||
HIPCHECK(hipStreamCreate(&streams[j]));
|
||||
}
|
||||
for (int j = 0; j < burstSize; j++) {
|
||||
HIPCHECK(hipStreamDestroy(streams[j]));
|
||||
}
|
||||
}
|
||||
|
||||
delete[] streams;
|
||||
delete[] streams;
|
||||
}
|
||||
|
||||
|
||||
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++) {
|
||||
HIPCHECK(hipDeviceSynchronize());
|
||||
}
|
||||
// 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++) {
|
||||
HIPCHECK(hipDeviceSynchronize());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -38,67 +38,61 @@ void waitStreams(int iterations) {
|
||||
// Some create many queue, some not many.
|
||||
//
|
||||
void multiThread_pyramid(bool serialize, int iters) {
|
||||
std::thread t1(createThenDestroyStreams, iters * 1, MAX_BURST_SIZE);
|
||||
if (serialize) {
|
||||
t1.join();
|
||||
}
|
||||
std::thread t1(createThenDestroyStreams, iters * 1, MAX_BURST_SIZE);
|
||||
if (serialize) {
|
||||
t1.join();
|
||||
}
|
||||
|
||||
std::thread t2(createThenDestroyStreams, iters * 10, 10);
|
||||
if (serialize) {
|
||||
t2.join();
|
||||
}
|
||||
std::thread t2(createThenDestroyStreams, iters * 10, 10);
|
||||
if (serialize) {
|
||||
t2.join();
|
||||
}
|
||||
|
||||
std::thread t3(createThenDestroyStreams, iters * 100, 1);
|
||||
if (serialize) {
|
||||
t3.join();
|
||||
}
|
||||
std::thread t3(createThenDestroyStreams, iters * 100, 1);
|
||||
if (serialize) {
|
||||
t3.join();
|
||||
}
|
||||
|
||||
if (!serialize) {
|
||||
t1.join();
|
||||
t2.join();
|
||||
t3.join();
|
||||
}
|
||||
if (!serialize) {
|
||||
t1.join();
|
||||
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) {
|
||||
std::thread t1(createThenDestroyStreams, iters, 1);
|
||||
if (serialize) {
|
||||
t1.join();
|
||||
}
|
||||
std::thread t1(createThenDestroyStreams, iters, 1);
|
||||
if (serialize) {
|
||||
t1.join();
|
||||
}
|
||||
|
||||
std::thread t2(createThenDestroyStreams, iters, 1);
|
||||
if (serialize) {
|
||||
t2.join();
|
||||
}
|
||||
std::thread t2(createThenDestroyStreams, iters, 1);
|
||||
if (serialize) {
|
||||
t2.join();
|
||||
}
|
||||
|
||||
std::thread t3(waitStreams, iters * 50);
|
||||
if (serialize) {
|
||||
t3.join();
|
||||
}
|
||||
std::thread t3(waitStreams, iters * 50);
|
||||
if (serialize) {
|
||||
t3.join();
|
||||
}
|
||||
|
||||
if (!serialize) {
|
||||
t1.join();
|
||||
t2.join();
|
||||
t3.join();
|
||||
}
|
||||
if (!serialize) {
|
||||
t1.join();
|
||||
t2.join();
|
||||
t3.join();
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("Unit_hipMultiThreadDevice_Streams") {
|
||||
// Serial version, just call once:
|
||||
createThenDestroyStreams(10, 10);
|
||||
// Serial version, just call once:
|
||||
createThenDestroyStreams(10, 10);
|
||||
}
|
||||
|
||||
TEST_CASE("Unit_hipMultiThreadDevice_SerialPyramid") {
|
||||
multiThread_pyramid(true, 3);
|
||||
}
|
||||
TEST_CASE("Unit_hipMultiThreadDevice_SerialPyramid") { multiThread_pyramid(true, 3); }
|
||||
|
||||
TEST_CASE("Unit_hipMultiThreadDevice_ParallelPyramid") {
|
||||
multiThread_pyramid(false, 3);
|
||||
}
|
||||
TEST_CASE("Unit_hipMultiThreadDevice_ParallelPyramid") { multiThread_pyramid(false, 3); }
|
||||
|
||||
TEST_CASE("Unit_hipMultiThreadDevice_NearZero") {
|
||||
multiThread_nearzero(false, 1000);
|
||||
}
|
||||
TEST_CASE("Unit_hipMultiThreadDevice_NearZero") { multiThread_nearzero(false, 1000); }
|
||||
|
||||
@@ -35,106 +35,104 @@ unsigned threadsPerBlock = 256;
|
||||
|
||||
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;
|
||||
size_t Nbytes = numElements * sizeof(T);
|
||||
using HipTest::MemTraits;
|
||||
size_t Nbytes = numElements * sizeof(T);
|
||||
|
||||
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;
|
||||
|
||||
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());
|
||||
|
||||
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);
|
||||
|
||||
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);
|
||||
MemTraits<C>::Copy(B_d, B_h, Nbytes, hipMemcpyHostToDevice, stream);
|
||||
|
||||
hipLaunchKernelGGL(HipTest::vectorADDReverse, dim3(blocks), dim3(threadsPerBlock), 0, 0,
|
||||
static_cast<const T*>(A_d), static_cast<const T*>(B_d), C_d, numElements);
|
||||
HIP_CHECK(hipGetLastError());
|
||||
|
||||
MemTraits<C>::Copy(C_h, C_d, Nbytes, hipMemcpyDeviceToHost, 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;
|
||||
}
|
||||
HipTest::checkVectorADD(A_h, B_h, C_h, numElements);
|
||||
}
|
||||
|
||||
|
||||
for (int i = 0; i < iters; i++) {
|
||||
unsigned blocks = HipTest::setNumBlocks(blocksPerCU, threadsPerBlock, numElements);
|
||||
|
||||
MemTraits<C>::Copy(A_d, A_h, Nbytes, hipMemcpyHostToDevice, stream);
|
||||
MemTraits<C>::Copy(B_d, B_h, Nbytes, hipMemcpyHostToDevice, stream);
|
||||
|
||||
hipLaunchKernelGGL(HipTest::vectorADDReverse, dim3(blocks), dim3(threadsPerBlock), 0, 0,
|
||||
static_cast<const T*>(A_d), static_cast<const T*>(B_d), C_d, numElements);
|
||||
HIP_CHECK(hipGetLastError());
|
||||
|
||||
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);
|
||||
HIPCHECK(hipDeviceSynchronize());
|
||||
HipTest::freeArrays(A_d, B_d, C_d, A_h, B_h, C_h, P::isPinned);
|
||||
HIPCHECK(hipDeviceSynchronize());
|
||||
}
|
||||
|
||||
template <typename T, class C>
|
||||
void test_multiThread_1(hipStream_t stream0, hipStream_t stream1, bool serialize) {
|
||||
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);
|
||||
if (serialize) {
|
||||
t1.join();
|
||||
}
|
||||
std::thread t2(simpleVectorAdd<T, HipTest::Pinned, C>, numElements, p_iters /*iters*/, stream1);
|
||||
if (serialize) {
|
||||
t2.join();
|
||||
}
|
||||
|
||||
// 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);
|
||||
if (serialize) {
|
||||
t2.join();
|
||||
}
|
||||
if (!serialize) {
|
||||
t1.join();
|
||||
t2.join();
|
||||
}
|
||||
|
||||
if (!serialize) {
|
||||
t1.join();
|
||||
t2.join();
|
||||
}
|
||||
|
||||
HIPCHECK(hipDeviceSynchronize());
|
||||
HIPCHECK(hipDeviceSynchronize());
|
||||
};
|
||||
|
||||
TEST_CASE("Unit_hipMultiThreadStreams1_AsyncSync") {
|
||||
hipStream_t stream;
|
||||
HIPCHECK(hipStreamCreate(&stream));
|
||||
|
||||
hipStream_t 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));
|
||||
HIPCHECK(hipStreamDestroy(stream));
|
||||
}
|
||||
|
||||
TEST_CASE("Unit_hipMultiThreadStreams1_AsyncAsync") {
|
||||
hipStream_t stream0, stream1;
|
||||
HIPCHECK(hipStreamCreate(&stream0));
|
||||
HIPCHECK(hipStreamCreate(&stream1));
|
||||
hipStream_t stream0, stream1;
|
||||
HIPCHECK(hipStreamCreate(&stream0));
|
||||
HIPCHECK(hipStreamCreate(&stream1));
|
||||
|
||||
// Easy tests to verify the test works - these don't allow overlap between the threads:
|
||||
test_multiThread_1<float, HipTest::MemcpyAsync>(NULL, NULL, true);
|
||||
test_multiThread_1<float, HipTest::MemcpyAsync>(stream0, stream1, true);
|
||||
// Easy tests to verify the test works - these don't allow overlap between the threads:
|
||||
test_multiThread_1<float, HipTest::MemcpyAsync>(NULL, NULL, true);
|
||||
test_multiThread_1<float, HipTest::MemcpyAsync>(stream0, stream1, true);
|
||||
|
||||
HIPCHECK(hipStreamDestroy(stream0));
|
||||
HIPCHECK(hipStreamDestroy(stream1));
|
||||
HIPCHECK(hipStreamDestroy(stream0));
|
||||
HIPCHECK(hipStreamDestroy(stream1));
|
||||
}
|
||||
TEST_CASE("Unit_hipMultiThreadStreams1_AsyncSame") {
|
||||
hipStream_t stream;
|
||||
HIPCHECK(hipStreamCreate(&stream));
|
||||
hipStream_t stream;
|
||||
HIPCHECK(hipStreamCreate(&stream));
|
||||
|
||||
// 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>(stream, stream, 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>(stream, stream, false);
|
||||
|
||||
HIPCHECK(hipStreamDestroy(stream));
|
||||
HIPCHECK(hipStreamDestroy(stream));
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
//This file is a port from hiprocclrtests (hipMultiThreadStreams2)
|
||||
// This file is a port from hiprocclrtests (hipMultiThreadStreams2)
|
||||
|
||||
|
||||
#include <iostream>
|
||||
@@ -28,120 +28,119 @@ THE SOFTWARE.
|
||||
#include <thread>
|
||||
#define N 1000
|
||||
|
||||
template <typename T>
|
||||
__global__ void Inc(T* Array) {
|
||||
int tx = threadIdx.x + blockIdx.x * blockDim.x;
|
||||
Array[tx] = Array[tx] + T(1);
|
||||
template <typename T> __global__ void Inc(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;
|
||||
float *snap = (float *) malloc(size);
|
||||
float *Ah, *Bh, *Cd, *Dd, *Eh;
|
||||
float* snap = (float*)malloc(size);
|
||||
|
||||
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));
|
||||
hipLaunchKernelGGL(HIP_KERNEL_NAME(Inc), dim3(N / 500), dim3(500), 0, stream, Cd);
|
||||
HIP_CHECK(hipGetLastError());
|
||||
HIPCHECK(hipMemcpyAsync(Dd, Cd, size, hipMemcpyDeviceToDevice, stream));
|
||||
HIPCHECK(hipMemcpyAsync(Eh, Dd, size, hipMemcpyDeviceToHost, stream));
|
||||
HIPCHECK(hipDeviceSynchronize());
|
||||
HIPCHECK(hipMemcpyAsync(Bh, Ah, size, hipMemcpyHostToHost, stream));
|
||||
HIPCHECK(hipMemcpyAsync(Cd, Bh, size, hipMemcpyHostToDevice, stream));
|
||||
hipLaunchKernelGGL(HIP_KERNEL_NAME(Inc), dim3(N / 500), dim3(500), 0, stream, Cd);
|
||||
HIP_CHECK(hipGetLastError());
|
||||
HIPCHECK(hipMemcpyAsync(Dd, Cd, size, hipMemcpyDeviceToDevice, stream));
|
||||
HIPCHECK(hipMemcpyAsync(Eh, Dd, size, hipMemcpyDeviceToHost, stream));
|
||||
HIPCHECK(hipDeviceSynchronize());
|
||||
|
||||
memcpy(snap, Eh, size);
|
||||
for (int i = 0; i < N; i++) {
|
||||
HIPASSERT(snap[i] == Ah[i] + 1.0f);
|
||||
}
|
||||
free(snap);
|
||||
HIPCHECK(hipHostFree(Ah));
|
||||
HIPCHECK(hipHostFree(Bh));
|
||||
HIPCHECK(hipHostFree(Eh));
|
||||
HIPCHECK(hipFree(Cd));
|
||||
HIPCHECK(hipFree(Dd));
|
||||
memcpy(snap, Eh, size);
|
||||
for (int i = 0; i < N; i++) {
|
||||
HIPASSERT(snap[i] == Ah[i] + 1.0f);
|
||||
}
|
||||
free(snap);
|
||||
HIPCHECK(hipHostFree(Ah));
|
||||
HIPCHECK(hipHostFree(Bh));
|
||||
HIPCHECK(hipHostFree(Eh));
|
||||
HIPCHECK(hipFree(Cd));
|
||||
HIPCHECK(hipFree(Dd));
|
||||
}
|
||||
|
||||
|
||||
void run(size_t size, hipStream_t stream1, hipStream_t stream2) {
|
||||
float *Ah, *Bh, *Cd, *Dd, *Eh;
|
||||
float *Ahh, *Bhh, *Cdd, *Ddd, *Ehh;
|
||||
float *snap, *snapp;
|
||||
float *Ah, *Bh, *Cd, *Dd, *Eh;
|
||||
float *Ahh, *Bhh, *Cdd, *Ddd, *Ehh;
|
||||
float *snap, *snapp;
|
||||
|
||||
snap = (float *) malloc(size);
|
||||
snapp = (float *) malloc(size);
|
||||
snap = (float*)malloc(size);
|
||||
snapp = (float*)malloc(size);
|
||||
|
||||
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));
|
||||
hipLaunchKernelGGL(HIP_KERNEL_NAME(Inc), dim3(N / 500), dim3(500), 0, stream1, Cd);
|
||||
HIP_CHECK(hipGetLastError());
|
||||
hipLaunchKernelGGL(HIP_KERNEL_NAME(Inc), dim3(N / 500), dim3(500), 0, stream2, Cdd);
|
||||
HIP_CHECK(hipGetLastError());
|
||||
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());
|
||||
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));
|
||||
hipLaunchKernelGGL(HIP_KERNEL_NAME(Inc), dim3(N / 500), dim3(500), 0, stream1, Cd);
|
||||
HIP_CHECK(hipGetLastError());
|
||||
hipLaunchKernelGGL(HIP_KERNEL_NAME(Inc), dim3(N / 500), dim3(500), 0, stream2, Cdd);
|
||||
HIP_CHECK(hipGetLastError());
|
||||
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());
|
||||
|
||||
memcpy(snap, Eh, size);
|
||||
memcpy(snapp, Ehh, size);
|
||||
memcpy(snap, Eh, size);
|
||||
memcpy(snapp, Ehh, size);
|
||||
|
||||
for (int i = 0; i < N; i++) {
|
||||
HIPASSERT(snap[i] == Ah[i] + 1.0f);
|
||||
HIPASSERT(snapp[i] == Ahh[i] + 1.0f);
|
||||
}
|
||||
free(snap);
|
||||
free(snapp);
|
||||
HIPCHECK(hipHostFree(Ah));
|
||||
HIPCHECK(hipHostFree(Bh));
|
||||
HIPCHECK(hipHostFree(Eh));
|
||||
HIPCHECK(hipHostFree(Ahh));
|
||||
HIPCHECK(hipHostFree(Bhh));
|
||||
HIPCHECK(hipHostFree(Ehh));
|
||||
HIPCHECK(hipFree(Cd));
|
||||
HIPCHECK(hipFree(Dd));
|
||||
HIPCHECK(hipFree(Cdd));
|
||||
HIPCHECK(hipFree(Ddd));
|
||||
for (int i = 0; i < N; i++) {
|
||||
HIPASSERT(snap[i] == Ah[i] + 1.0f);
|
||||
HIPASSERT(snapp[i] == Ahh[i] + 1.0f);
|
||||
}
|
||||
free(snap);
|
||||
free(snapp);
|
||||
HIPCHECK(hipHostFree(Ah));
|
||||
HIPCHECK(hipHostFree(Bh));
|
||||
HIPCHECK(hipHostFree(Eh));
|
||||
HIPCHECK(hipHostFree(Ahh));
|
||||
HIPCHECK(hipHostFree(Bhh));
|
||||
HIPCHECK(hipHostFree(Ehh));
|
||||
HIPCHECK(hipFree(Cd));
|
||||
HIPCHECK(hipFree(Dd));
|
||||
HIPCHECK(hipFree(Cdd));
|
||||
HIPCHECK(hipFree(Ddd));
|
||||
}
|
||||
TEST_CASE("Unit_hipMultiThreadStreams2") {
|
||||
int iterations = 100;
|
||||
int iterations = 100;
|
||||
|
||||
hipStream_t stream[3];
|
||||
for (int i = 0; i < 3; i++) {
|
||||
HIPCHECK(hipStreamCreate(&stream[i]));
|
||||
}
|
||||
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]);
|
||||
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();
|
||||
t2.join();
|
||||
t3.join();
|
||||
}
|
||||
t1.join();
|
||||
t2.join();
|
||||
t3.join();
|
||||
}
|
||||
|
||||
for (int i = 0; i < 3; i++) {
|
||||
HIPCHECK(hipStreamDestroy(stream[i]));
|
||||
}
|
||||
for (int i = 0; i < 3; i++) {
|
||||
HIPCHECK(hipStreamDestroy(stream[i]));
|
||||
}
|
||||
}
|
||||
|
||||
Fai riferimento in un nuovo problema
Block a user