Skip to content

Commit

Permalink
[CTS] extend kernel launch test with bg verification
Browse files Browse the repository at this point in the history
  • Loading branch information
igchor authored and pbalcer committed Sep 17, 2024
1 parent 4c7173f commit ab537af
Showing 1 changed file with 50 additions and 20 deletions.
70 changes: 50 additions & 20 deletions test/conformance/enqueue/urEnqueueKernelLaunchAndMemcpyInOrder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,30 @@ struct urMultiQueueLaunchMemcpyTest : uur::urMultiDeviceContextTestTemplate<1>,
UUR_RETURN_ON_FATAL_FAILURE(
uur::urMultiDeviceContextTestTemplate<1>::TearDown());
}

void runBackgroundCheck(std::vector<uur::raii::Event> &Events) {
std::vector<std::thread> threads;
for (size_t i = 0; i < devices.size(); i++) {
threads.emplace_back([&, i] {
ur_event_status_t status;
do {
ASSERT_SUCCESS(urEventGetInfo(
Events[i * 2].get(),
UR_EVENT_INFO_COMMAND_EXECUTION_STATUS,
sizeof(ur_event_status_t), &status, nullptr));
} while (status != UR_EVENT_STATUS_COMPLETE);

auto ExpectedValue = InitialValue + i + 1;
for (uint32_t j = 0; j < ArraySize; ++j) {
ASSERT_EQ(reinterpret_cast<uint32_t *>(SharedMem[i])[j],
ExpectedValue);
}
});
}
for (auto &thread : threads) {
thread.join();
}
}
};

template <typename Param>
Expand Down Expand Up @@ -237,23 +261,38 @@ TEST_P(urEnqueueKernelLaunchIncrementTest, Success) {

template <typename T>
inline std::string
printBoolParam(const testing::TestParamInfo<typename T::ParamType> &info) {
printParams(const testing::TestParamInfo<typename T::ParamType> &info) {
std::stringstream ss;
ss << (info.param.value ? "" : "No") << info.param.name;

auto param1 = std::get<0>(info.param);
ss << (param1.value ? "" : "No") << param1.name;

auto param2 = std::get<1>(info.param);
ss << (param2.value ? "" : "No") << param2.name;

if constexpr (std::tuple_size_v < typename T::ParamType >> 2) {
auto param3 = std::get<2>(info.param);
}

return ss.str();
}

using urEnqueueKernelLaunchIncrementMultiDeviceTest =
urEnqueueKernelLaunchIncrementMultiDeviceTestWithParam<uur::BoolTestParam>;
urEnqueueKernelLaunchIncrementMultiDeviceTestWithParam<
std::tuple<uur::BoolTestParam, uur::BoolTestParam>>;

INSTANTIATE_TEST_SUITE_P(
, urEnqueueKernelLaunchIncrementMultiDeviceTest,
testing::ValuesIn(uur::BoolTestParam::makeBoolParam("UseEventWait")),
printBoolParam<urEnqueueKernelLaunchIncrementMultiDeviceTest>);
testing::Combine(
testing::ValuesIn(uur::BoolTestParam::makeBoolParam("UseEventWait")),
testing::ValuesIn(
uur::BoolTestParam::makeBoolParam("RunBackgroundCheck"))),
printParams<urEnqueueKernelLaunchIncrementMultiDeviceTest>);

// Do a chain of kernelLaunch(dev0) -> memcpy(dev0, dev1) -> kernelLaunch(dev1) ... ops
TEST_P(urEnqueueKernelLaunchIncrementMultiDeviceTest, Success) {
auto waitOnEvent = GetParam().value;
auto waitOnEvent = std::get<0>(GetParam()).value;
auto runBackgroundCheck = std::get<1>(GetParam()).value;

size_t returned_size;
ASSERT_SUCCESS(urDeviceGetInfo(devices[0], UR_DEVICE_INFO_EXTENSIONS, 0,
Expand Down Expand Up @@ -300,6 +339,11 @@ TEST_P(urEnqueueKernelLaunchIncrementMultiDeviceTest, Success) {
}
}

// While the device(s) execute, loop over the events and if completed, verify the results
if (runBackgroundCheck) {
this->runBackgroundCheck(Events);
}

// synchronize on the last queue/event only, this has to ensure all the operations
// are completed
if (waitOnEvent) {
Expand All @@ -318,20 +362,6 @@ TEST_P(urEnqueueKernelLaunchIncrementMultiDeviceTest, Success) {
}
}

template <typename T>
inline std::string
printParams(const testing::TestParamInfo<typename T::ParamType> &info) {
std::stringstream ss;

auto param1 = std::get<0>(info.param);
auto param2 = std::get<1>(info.param);

ss << (param1.value ? "" : "No") << param1.name;
ss << (param2.value ? "" : "No") << param2.name;

return ss.str();
}

using urEnqueueKernelLaunchIncrementMultiDeviceMultiThreadTest =
urEnqueueKernelLaunchIncrementMultiDeviceTestWithParam<
std::tuple<uur::BoolTestParam, uur::BoolTestParam>>;
Expand Down

0 comments on commit ab537af

Please sign in to comment.