SWDEV-470698 - fix formatting, add format check workflow (#657)
This commit is contained in:
committed by
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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user