SWDEV-491253 - Create stream capture test for kernel APIs (#1189)

This commit is contained in:
vstojilj
2025-11-27 17:40:11 +01:00
zatwierdzone przez GitHub
rodzic 1c09c87cc7
commit 259010f2d5
6 zmienionych plików z 108 dodań i 9 usunięć
@@ -188,8 +188,6 @@ TEST_CASE("Unit_hipExtLaunchKernel_Negative_Parameters") {
* - HIP_VERSION >= 6.0
*/
TEST_CASE("Unit_hipExtLaunchKernel_capturehipExtLaunchKernel") {
hipGraph_t graph{nullptr};
hipGraphExec_t graphExec{nullptr};
hipStream_t stream;
HIP_CHECK(hipStreamCreate(&stream));
int* A_d;
@@ -197,24 +195,21 @@ TEST_CASE("Unit_hipExtLaunchKernel_capturehipExtLaunchKernel") {
A_h = reinterpret_cast<int*>(malloc(sizeof(int)));
HIP_CHECK(hipMalloc(reinterpret_cast<void**>(&A_d), sizeof(int)));
void* args[1] = {&A_d};
// Begin Capture operation
HIP_CHECK(hipStreamBeginCapture(stream, hipStreamCaptureModeGlobal));
GENERATE_CAPTURE();
BEGIN_CAPTURE(stream);
HIP_CHECK(hipExtLaunchKernel(reinterpret_cast<void*>(kernel_42), dim3{1, 1, 1}, dim3{1, 1, 1},
args, 0, stream, nullptr, nullptr, 0u));
// End Capture
HIP_CHECK(hipStreamEndCapture(stream, &graph));
END_CAPTURE(stream);
// Create and Launch Executable Graphs
HIP_CHECK(hipGraphInstantiate(&graphExec, graph, nullptr, nullptr, 0));
HIP_CHECK(hipGraphLaunch(graphExec, stream));
HIP_CHECK(hipStreamSynchronize(stream));
HIP_CHECK(hipMemcpyDtoH(A_h, A_d, sizeof(int)));
REQUIRE(A_h != nullptr);
REQUIRE(*A_h == 42);
HIP_CHECK(hipGraphExecDestroy(graphExec));
HIP_CHECK(hipGraphDestroy(graph));
HIP_CHECK(hipStreamDestroy(stream));
HIP_CHECK(hipFree(A_d));
free(A_h);
@@ -177,3 +177,22 @@ TEST_CASE("Unit_hipLaunchCooperativeKernel_Negative_Parameters") {
hipErrorCooperativeLaunchTooLarge);
}
}
TEST_CASE("Unit_hipLaunchCooperativeKernel_Verify_Capture") {
if (!DeviceAttributesSupport(0, hipDeviceAttributeCooperativeLaunch)) {
HipTest::HIP_SKIP_TEST("CooperativeLaunch not supported");
return;
}
hipStream_t stream;
HIP_CHECK(hipStreamCreate(&stream));
GENERATE_CAPTURE();
BEGIN_CAPTURE(stream);
HIP_CHECK(hipLaunchCooperativeKernel(reinterpret_cast<void*>(coop_kernel), dim3{2, 2, 1},
dim3{1, 1, 1}, nullptr, 0, stream));
END_CAPTURE(stream);
HIP_CHECK(hipDeviceSynchronize());
HIP_CHECK(hipStreamDestroy(stream));
}
@@ -155,4 +155,18 @@ TEST_CASE("Unit_hipLaunchKernel_Negative_Parameters") {
hipErrorInvalidValue);
}
#endif
}
TEST_CASE("Unit_hipLaunchKernel_Verify_Capture") {
hipStream_t stream;
HIP_CHECK(hipStreamCreate(&stream));
GENERATE_CAPTURE();
BEGIN_CAPTURE(stream);
HIP_CHECK(hipLaunchKernel(reinterpret_cast<void*>(kernel), dim3{1, 1, 1}, dim3{1, 1, 1}, nullptr,
0, stream));
END_CAPTURE(stream);
HIP_CHECK(hipDeviceSynchronize());
HIP_CHECK(hipStreamDestroy(stream));
}
@@ -66,4 +66,24 @@ TEST_CASE("Unit___hipPushCallConfiguration_Positive_Basic") {
REQUIRE(block.z == 1);
REQUIRE(shmem == 1024);
REQUIRE(stream == stream_guard.stream());
}
TEST_CASE("Unit_hipLaunchByPtr_Verify_Capture") {
LinearAllocGuard<int> alloc(LinearAllocs::hipMallocManaged, 4);
hipStream_t stream;
HIP_CHECK(hipStreamCreate(&stream));
GENERATE_CAPTURE();
BEGIN_CAPTURE(stream);
HIP_CHECK(hipConfigureCall(dim3{1}, dim3{1}, 0, stream));
int* arg = alloc.ptr();
HIP_CHECK(hipSetupArgument(&arg, sizeof(int*), 0));
HIP_CHECK(hipLaunchByPtr(reinterpret_cast<void*>(kernel_42)));
END_CAPTURE(stream);
HIP_CHECK(hipDeviceSynchronize());
HIP_CHECK(hipStreamDestroy(stream));
REQUIRE(alloc.ptr()[0] == 42);
}