Files
rocm-systems/hipamd/tests/src/runtimeApi/multiThread/hipMultiThreadDevice.cpp
T

144 خطوط
3.9 KiB
C++

/* HIT_START
* BUILD: %t %s ../../test_common.cpp NVCC_OPTIONS -std=c++11
* RUN_NAMED: %t hipMultiThreadDevice-serial --tests 0x1
* RUN_NAMED: %t hipMultiThreadDevice-pyramid --tests 0x4
* RUN_NAMED: %t hipMultiThreadDevice-nearzero --tests 0x10
* HIT_END
*/
#include "hip/hip_runtime_api.h"
2016-03-26 10:46:20 -05:00
#include "test_common.h"
// Create a lot of streams and then destroy 'em.
2018-03-12 11:29:03 +05:30
void createThenDestroyStreams(int iterations, int burstSize) {
hipStream_t* streams = new hipStream_t[burstSize];
2016-03-26 10:46:20 -05:00
2018-03-12 11:29:03 +05:30
for (int i = 0; i < iterations; i++) {
2016-03-26 10:46:20 -05:00
if (p_verbose & 0x1) {
2018-03-12 11:29:03 +05:30
printf("%s iter=%d, create %d then destroy %d\n", __func__, i, burstSize, burstSize);
2016-03-26 10:46:20 -05:00
}
2018-03-12 11:29:03 +05:30
for (int j = 0; j < burstSize; j++) {
2016-03-26 10:46:20 -05:00
if (p_verbose & 0x2) {
2018-03-12 11:29:03 +05:30
printf(" %d.%d streamCreate\n", i, j);
2016-03-26 10:46:20 -05:00
}
2018-03-12 11:29:03 +05:30
HIPCHECK(hipStreamCreate(&streams[j]));
2016-03-26 10:46:20 -05:00
}
2018-03-12 11:29:03 +05:30
for (int j = 0; j < burstSize; j++) {
2016-03-26 10:46:20 -05:00
if (p_verbose & 0x2) {
2018-03-12 11:29:03 +05:30
printf(" %d.%d streamDestroy\n", i, j);
2016-03-26 10:46:20 -05:00
}
2018-03-12 11:29:03 +05:30
HIPCHECK(hipStreamDestroy(streams[j]));
2016-03-26 10:46:20 -05:00
}
}
2017-01-09 20:22:43 -06:00
delete[] streams;
2016-03-26 10:46:20 -05:00
}
2018-03-12 11:29:03 +05:30
void waitStreams(int iterations) {
2016-03-26 10:46:20 -05:00
// Repeatedly sync and wait for all streams to complete.
2018-03-12 11:29:03 +05:30
// TO make this interesting, the test has other threads repeatedly adding and removing streams
// to the device.
for (int i = 0; i < iterations; i++) {
2016-03-26 10:46:20 -05:00
HIPCHECK(hipDeviceSynchronize());
}
}
// Create 3 streams, all creating and destroying streams on the same device.
// Some create many queue, some not many.
//
2018-03-12 11:29:03 +05:30
void multiThread_pyramid(bool serialize, int iters) {
printf("%s creating %d streams\n", __func__, iters * 100);
std::thread t1(createThenDestroyStreams, iters * 1, 100);
2016-03-26 10:46:20 -05:00
if (serialize) {
t1.join();
printf("t1 done\n");
}
2018-03-12 11:29:03 +05:30
std::thread t2(createThenDestroyStreams, iters * 10, 10);
2016-03-26 10:46:20 -05:00
if (serialize) {
t2.join();
printf("t2 done\n");
}
2018-03-12 11:29:03 +05:30
std::thread t3(createThenDestroyStreams, iters * 100, 1);
2016-03-26 10:46:20 -05:00
if (serialize) {
t3.join();
printf("t3 done\n");
}
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.
2018-03-12 11:29:03 +05:30
void multiThread_nearzero(bool serialize, int iters) {
printf("%s creating %d streams x 3 threads\n", __func__, iters);
std::thread t1(createThenDestroyStreams, iters, 1);
2016-03-26 10:46:20 -05:00
if (serialize) {
t1.join();
printf("t1 done\n");
}
2018-03-12 11:29:03 +05:30
std::thread t2(createThenDestroyStreams, iters, 1);
2016-03-26 10:46:20 -05:00
if (serialize) {
t2.join();
printf("t2 done\n");
}
2018-03-12 11:29:03 +05:30
std::thread t3(waitStreams, iters * 50);
2016-03-26 10:46:20 -05:00
if (serialize) {
t3.join();
printf("t3 done\n");
}
if (!serialize) {
2018-03-12 11:29:03 +05:30
t1.join();
printf("t1 done\n");
t2.join();
printf("t2 done\n");
t3.join();
printf("t3 done\n");
2016-03-26 10:46:20 -05:00
}
}
2018-03-12 11:29:03 +05:30
int main(int argc, char* argv[]) {
2016-03-26 10:46:20 -05:00
HipTest::parseStandardArguments(argc, argv, true);
// Serial version, just call once:
if (p_tests & 0x1) {
2018-03-12 11:29:03 +05:30
printf("\ntest 0x1 : serial createThenDestroyStreams(10) \n");
2016-03-26 10:46:20 -05:00
createThenDestroyStreams(10, 10);
};
2016-03-29 17:29:31 -05:00
/*disable, this takess a while and if the next one works then no need to run serial*/
if (1 && (p_tests & 0x2)) {
2018-03-12 11:29:03 +05:30
printf("\ntest 0x2 : serialized multiThread_pyramid(1) \n");
2016-04-11 13:46:53 -05:00
multiThread_pyramid(true, 3);
2016-03-26 10:46:20 -05:00
}
if (p_tests & 0x4) {
2018-03-12 11:29:03 +05:30
printf("\ntest 0x4 : parallel multiThread_pyramid(1) \n");
2016-04-11 13:46:53 -05:00
multiThread_pyramid(false, 3);
2016-03-26 10:46:20 -05:00
}
2018-03-12 11:29:03 +05:30
// if (p_tests & 0x8) {
2016-03-26 10:46:20 -05:00
// printf ("test 0x8 : multiThread_pyramid(100) \n");
// multiThread_pyramid(false, 100);
2018-03-12 11:29:03 +05:30
// }
2016-03-26 10:46:20 -05:00
if (p_tests & 0x10) {
2018-03-12 11:29:03 +05:30
printf("\ntest 0x10 : parallel multiThread_nearzero(1000) \n");
2016-03-29 17:29:31 -05:00
multiThread_nearzero(false, 1000);
2016-03-26 10:46:20 -05:00
}
passed();
}