SWDEV-470698 - fix formatting, add format check workflow (#657)

This commit is contained in:
Danylo Lytovchenko authored and GitHub committed 2025-08-20 19:58:06 +05:30
1 szülő 5840940caa
commit f7338717ae
1574 files changed
+162903 -199277

No files matched your search

@@ -41,16 +41,16 @@ constexpr size_t N = 1 << 20;
constexpr unsigned blocks = 256;
constexpr unsigned threadsPerBlock = 64;
static bool CaptureStreamAndLaunchGraph(int *A_d, int *B_d, int *C_d,
int *A_h, int *B_h, int *C_h, hipStreamCaptureMode mode,
hipStream_t &stream1, hipStream_t &stream2, hipGraph_t &graph,
bool verifyStreamSync = false, std::function<bool()> verifyFunc1= nullptr) {
static bool CaptureStreamAndLaunchGraph(int* A_d, int* B_d, int* C_d, int* A_h, int* B_h, int* C_h,
hipStreamCaptureMode mode, hipStream_t& stream1,
hipStream_t& stream2, hipGraph_t& graph,
bool verifyStreamSync = false,
std::function<bool()> verifyFunc1 = nullptr) {
auto verifyFunc = [&]() {
// Validate the computation
for (size_t i = 0; i < N; i++) {
if (C_h[i] != (A_h[i] - B_h[i])) {
fprintf(stderr, "Error at %zu: C=%d, A=%d, B=%d\n", i,
C_h[i], A_h[i], B_h[i]);
fprintf(stderr, "Error at %zu: C=%d, A=%d, B=%d\n", i, C_h[i], A_h[i], B_h[i]);
return false;
}
}
@@ -61,8 +61,7 @@ static bool CaptureStreamAndLaunchGraph(int *A_d, int *B_d, int *C_d,
size_t Nbytes = N * sizeof(int);
hipEvent_t e;
HIP_CHECK(hipEventCreate(&e));
HIP_CHECK(hipStreamBeginCaptureToGraph(stream1, graph, nullptr,
nullptr, 0, mode));
HIP_CHECK(hipStreamBeginCaptureToGraph(stream1, graph, nullptr, nullptr, 0, mode));
HIP_CHECK(hipEventRecord(e, stream1));
HIP_CHECK(hipStreamWaitEvent(stream2, e, 0));
HIP_CHECK(hipMemsetAsync(C_d, 0, Nbytes, stream1));
@@ -70,8 +69,7 @@ static bool CaptureStreamAndLaunchGraph(int *A_d, int *B_d, int *C_d,
HIP_CHECK(hipMemcpyAsync(B_d, B_h, Nbytes, hipMemcpyHostToDevice, stream2));
HIP_CHECK(hipEventRecord(e, stream2));
HIP_CHECK(hipStreamWaitEvent(stream1, e, 0));
HipTest::vectorSUB<<< dim3(blocks), dim3(threadsPerBlock), 0, stream1 >>>
(A_d, B_d, C_d, N);
HipTest::vectorSUB<<<dim3(blocks), dim3(threadsPerBlock), 0, stream1>>>(A_d, B_d, C_d, N);
HIP_CHECK(hipMemcpyAsync(C_h, C_d, Nbytes, hipMemcpyDeviceToHost, stream1));
HIP_CHECK(hipStreamEndCapture(stream1, &graph));
@@ -123,8 +121,8 @@ TEST_CASE("Unit_hipStreamBeginCaptureToGraph_BasicFunctional") {
// Fill with data
for (size_t i = 0; i < N; i++) {
A_h[i] = 2*i;
B_h[i] = 2*i + 1;
A_h[i] = 2 * i;
B_h[i] = 2 * i + 1;
}
HIP_CHECK(hipStreamCreate(&stream1));
@@ -136,36 +134,27 @@ TEST_CASE("Unit_hipStreamBeginCaptureToGraph_BasicFunctional") {
bool verifyStreamSync = false;
SECTION("Capture stream and launch graph when mode is global") {
SECTION("Verify after hipGraphExecDestroy()") {
verifyStreamSync = false;
}
SECTION("Verify after hipStreamSynchronize()") {
verifyStreamSync = true;
}
ret = CaptureStreamAndLaunchGraph(A_d, B_d, C_d, A_h.data(), B_h.data(),
C_h.data(), hipStreamCaptureModeGlobal, stream1, stream2, graph, verifyStreamSync);
SECTION("Verify after hipGraphExecDestroy()") { verifyStreamSync = false; }
SECTION("Verify after hipStreamSynchronize()") { verifyStreamSync = true; }
ret = CaptureStreamAndLaunchGraph(A_d, B_d, C_d, A_h.data(), B_h.data(), C_h.data(),
hipStreamCaptureModeGlobal, stream1, stream2, graph,
verifyStreamSync);
}
SECTION("Capture stream and launch graph when mode is local") {
SECTION("Verify after hipGraphExecDestroy()") {
verifyStreamSync = false;
}
SECTION("Verify after hipStreamSynchronize()") {
verifyStreamSync = true;
}
ret = CaptureStreamAndLaunchGraph(A_d, B_d, C_d, A_h.data(), B_h.data(),
C_h.data(), hipStreamCaptureModeThreadLocal, stream1, stream2, graph, verifyStreamSync);
SECTION("Verify after hipGraphExecDestroy()") { verifyStreamSync = false; }
SECTION("Verify after hipStreamSynchronize()") { verifyStreamSync = true; }
ret = CaptureStreamAndLaunchGraph(A_d, B_d, C_d, A_h.data(), B_h.data(), C_h.data(),
hipStreamCaptureModeThreadLocal, stream1, stream2, graph,
verifyStreamSync);
}
SECTION("Capture stream and launch graph when mode is relaxed") {
SECTION("Verify after hipGraphExecDestroy()") {
verifyStreamSync = false;
}
SECTION("Verify after hipStreamSynchronize()") {
verifyStreamSync = true;
}
ret = CaptureStreamAndLaunchGraph(A_d, B_d, C_d, A_h.data(), B_h.data(),
C_h.data(), hipStreamCaptureModeRelaxed, stream1, stream2, graph, verifyStreamSync);
SECTION("Verify after hipGraphExecDestroy()") { verifyStreamSync = false; }
SECTION("Verify after hipStreamSynchronize()") { verifyStreamSync = true; }
ret = CaptureStreamAndLaunchGraph(A_d, B_d, C_d, A_h.data(), B_h.data(), C_h.data(),
hipStreamCaptureModeRelaxed, stream1, stream2, graph,
verifyStreamSync);
}
HIP_CHECK(hipStreamDestroy(stream1));
@@ -205,8 +194,7 @@ TEST_CASE("Unit_hipStreamBeginCaptureToGraph_CaptureIndepGraph") {
// Validate the computation
for (size_t i = 0; i < N; i++) {
if (C2_h[i] != (A2_h[i] + B2_h[i])) {
fprintf(stderr, "Error at %zu: C2=%d, A2=%d, B2=%d\n", i,
C2_h[i], A2_h[i], B2_h[i]);
fprintf(stderr, "Error at %zu: C2=%d, A2=%d, B2=%d\n", i, C2_h[i], A2_h[i], B2_h[i]);
return false;
}
}
@@ -215,8 +203,8 @@ TEST_CASE("Unit_hipStreamBeginCaptureToGraph_CaptureIndepGraph") {
// Fill with data
for (size_t i = 0; i < N; i++) {
A2_h[i] = A1_h[i] = 2*i;
B2_h[i] = B1_h[i] = 2*i + 1;
A2_h[i] = A1_h[i] = 2 * i;
B2_h[i] = B1_h[i] = 2 * i + 1;
}
// Create stream and empty graph
@@ -233,17 +221,15 @@ TEST_CASE("Unit_hipStreamBeginCaptureToGraph_CaptureIndepGraph") {
HIP_CHECK(hipMalloc(&C2_d, Nbytes));
// Create manual graph
HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpyNode1, graph, nullptr, 0, A2_d,
A2_h.data(), Nbytes, hipMemcpyHostToDevice));
HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpyNode2, graph, nullptr, 0, B2_d,
B2_h.data(), Nbytes, hipMemcpyHostToDevice));
HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpyNode3, graph, nullptr, 0,
C2_h.data(), C2_d, Nbytes, hipMemcpyDeviceToHost));
HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpyNode1, graph, nullptr, 0, A2_d, A2_h.data(), Nbytes,
hipMemcpyHostToDevice));
HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpyNode2, graph, nullptr, 0, B2_d, B2_h.data(), Nbytes,
hipMemcpyHostToDevice));
HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpyNode3, graph, nullptr, 0, C2_h.data(), C2_d, Nbytes,
hipMemcpyDeviceToHost));
size_t arrSize = N;
void* kernelArgs[4] = {reinterpret_cast<void*>(&A2_d),
reinterpret_cast<void*>(&B2_d),
reinterpret_cast<void*>(&C2_d),
&arrSize};
void* kernelArgs[4] = {reinterpret_cast<void*>(&A2_d), reinterpret_cast<void*>(&B2_d),
reinterpret_cast<void*>(&C2_d), &arrSize};
hipKernelNodeParams kernelNodeParams{};
kernelNodeParams.func = reinterpret_cast<void*>(HipTest::vectorADD<int>);
kernelNodeParams.gridDim = dim3(blocks, 1, 1);
@@ -251,22 +237,18 @@ TEST_CASE("Unit_hipStreamBeginCaptureToGraph_CaptureIndepGraph") {
kernelNodeParams.sharedMemBytes = 0;
kernelNodeParams.kernelParams = reinterpret_cast<void**>(kernelArgs);
kernelNodeParams.extra = nullptr;
HIP_CHECK(hipGraphAddKernelNode(&kernelNode, graph, 0, 0,
&kernelNodeParams));
HIP_CHECK(hipGraphAddKernelNode(&kernelNode, graph, 0, 0, &kernelNodeParams));
HIP_CHECK(hipGraphAddDependencies(graph, &memcpyNode1, &kernelNode, 1));
HIP_CHECK(hipGraphAddDependencies(graph, &memcpyNode2, &kernelNode, 1));
HIP_CHECK(hipGraphAddDependencies(graph, &kernelNode, &memcpyNode3, 1));
bool verifyStreamSync = false;
// Capture an independent graph from stream
SECTION("Verify after hipGraphExecDestroy()") {
verifyStreamSync = false;
}
SECTION("Verify after hipStreamSynchronize()") {
verifyStreamSync = true;
}
SECTION("Verify after hipGraphExecDestroy()") { verifyStreamSync = false; }
SECTION("Verify after hipStreamSynchronize()") { verifyStreamSync = true; }
ret = CaptureStreamAndLaunchGraph(A1_d, B1_d, C1_d, A1_h.data(), B1_h.data(), C1_h.data(),
hipStreamCaptureModeGlobal, stream1, stream2, graph, verifyStreamSync, verifyFunc);
hipStreamCaptureModeGlobal, stream1, stream2, graph,
verifyStreamSync, verifyFunc);
REQUIRE(ret == true);
HIP_CHECK(hipStreamDestroy(stream1));
@@ -304,8 +286,8 @@ TEST_CASE("Unit_hipStreamBeginCaptureToGraph_CaptureDepGraph") {
// Fill with data
for (size_t i = 0; i < N; i++) {
A1_h[i] = 2*i;
B1_h[i] = 2*i + 1;
A1_h[i] = 2 * i;
B1_h[i] = 2 * i + 1;
}
// Create stream and empty graph
@@ -319,17 +301,15 @@ TEST_CASE("Unit_hipStreamBeginCaptureToGraph_CaptureDepGraph") {
HIP_CHECK(hipMalloc(&C2_d, Nbytes));
// Create manual graph
HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpyNode1, graph, nullptr, 0, A1_d,
A1_h.data(), Nbytes, hipMemcpyHostToDevice));
HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpyNode2, graph, nullptr, 0, B1_d,
B1_h.data(), Nbytes, hipMemcpyHostToDevice));
HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpyNode3, graph, nullptr, 0,
C1_h.data(), C1_d, Nbytes, hipMemcpyDeviceToHost));
HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpyNode1, graph, nullptr, 0, A1_d, A1_h.data(), Nbytes,
hipMemcpyHostToDevice));
HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpyNode2, graph, nullptr, 0, B1_d, B1_h.data(), Nbytes,
hipMemcpyHostToDevice));
HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpyNode3, graph, nullptr, 0, C1_h.data(), C1_d, Nbytes,
hipMemcpyDeviceToHost));
size_t arrSize = N;
void* kernelArgs[4] = {reinterpret_cast<void*>(&A1_d),
reinterpret_cast<void*>(&B1_d),
reinterpret_cast<void*>(&C1_d),
&arrSize};
void* kernelArgs[4] = {reinterpret_cast<void*>(&A1_d), reinterpret_cast<void*>(&B1_d),
reinterpret_cast<void*>(&C1_d), &arrSize};
hipKernelNodeParams kernelNodeParams{};
kernelNodeParams.func = reinterpret_cast<void*>(HipTest::vectorADD<int>);
kernelNodeParams.gridDim = dim3(blocks, 1, 1);
@@ -337,8 +317,7 @@ TEST_CASE("Unit_hipStreamBeginCaptureToGraph_CaptureDepGraph") {
kernelNodeParams.sharedMemBytes = 0;
kernelNodeParams.kernelParams = reinterpret_cast<void**>(kernelArgs);
kernelNodeParams.extra = nullptr;
HIP_CHECK(hipGraphAddKernelNode(&kernelNode, graph, 0, 0,
&kernelNodeParams));
HIP_CHECK(hipGraphAddKernelNode(&kernelNode, graph, 0, 0, &kernelNodeParams));
HIP_CHECK(hipGraphAddDependencies(graph, &memcpyNode1, &kernelNode, 1));
HIP_CHECK(hipGraphAddDependencies(graph, &memcpyNode2, &kernelNode, 1));
HIP_CHECK(hipGraphAddDependencies(graph, &kernelNode, &memcpyNode3, 1));
@@ -347,12 +326,10 @@ TEST_CASE("Unit_hipStreamBeginCaptureToGraph_CaptureDepGraph") {
std::vector<hipGraphNode_t> vnode;
vnode.push_back(memcpyNode1);
vnode.push_back(memcpyNode2);
HIP_CHECK(hipStreamBeginCaptureToGraph(stream, graph, vnode.data(),
nullptr, vnode.size(), hipStreamCaptureModeGlobal));
HipTest::vectorSUB<<< dim3(blocks), dim3(threadsPerBlock), 0, stream >>>
(A1_d, B1_d, C2_d, N);
HIP_CHECK(hipMemcpyAsync(C2_h.data(), C2_d, Nbytes, hipMemcpyDeviceToHost,
stream));
HIP_CHECK(hipStreamBeginCaptureToGraph(stream, graph, vnode.data(), nullptr, vnode.size(),
hipStreamCaptureModeGlobal));
HipTest::vectorSUB<<<dim3(blocks), dim3(threadsPerBlock), 0, stream>>>(A1_d, B1_d, C2_d, N);
HIP_CHECK(hipMemcpyAsync(C2_h.data(), C2_d, Nbytes, hipMemcpyDeviceToHost, stream));
HIP_CHECK(hipStreamEndCapture(stream, &graph));
// Instantiate and Launch the graph
@@ -365,14 +342,12 @@ TEST_CASE("Unit_hipStreamBeginCaptureToGraph_CaptureDepGraph") {
// Verify Manual Graph
for (size_t i = 0; i < N; i++) {
if (C1_h[i] != (A1_h[i] + B1_h[i])) {
fprintf(stderr, "Error at %zu: C1=%d, A1=%d, B1=%d\n", i,
C1_h[i], A1_h[i], B1_h[i]);
fprintf(stderr, "Error at %zu: C1=%d, A1=%d, B1=%d\n", i, C1_h[i], A1_h[i], B1_h[i]);
ret = false;
break;
}
if (C2_h[i] != (A1_h[i] - B1_h[i])) {
fprintf(stderr, "Error at %zu: C2=%d, A1=%d, B1=%d\n", i,
C2_h[i], A1_h[i], B1_h[i]);
fprintf(stderr, "Error at %zu: C2=%d, A1=%d, B1=%d\n", i, C2_h[i], A1_h[i], B1_h[i]);
ret = false;
break;
}
@@ -405,8 +380,8 @@ TEST_CASE("Unit_hipStreamBeginCaptureToGraph_ComplexGraph") {
// Fill with data
for (size_t i = 0; i < N; i++) {
A_h[i] = 2*i;
B_h[i] = 2*i + 1;
A_h[i] = 2 * i;
B_h[i] = 2 * i + 1;
}
// Create streams, events and empty graph
@@ -431,17 +406,15 @@ TEST_CASE("Unit_hipStreamBeginCaptureToGraph_ComplexGraph") {
HIP_CHECK(hipMalloc(&D_d, Nbytes));
// Capture Nodes from multiple streams
HIP_CHECK(hipStreamBeginCaptureToGraph(stream1, graph, nullptr, nullptr,
0, hipStreamCaptureModeGlobal));
HIP_CHECK(hipStreamBeginCaptureToGraph(stream1, graph, nullptr, nullptr, 0,
hipStreamCaptureModeGlobal));
// Capture all the other streams as well
HIP_CHECK(hipEventRecord(e1, stream1));
HIP_CHECK(hipStreamWaitEvent(stream2, e1, 0));
HIP_CHECK(hipStreamWaitEvent(stream3, e1, 0));
HIP_CHECK(hipStreamWaitEvent(stream4, e1, 0));
HIP_CHECK(hipMemcpyAsync(A_d, A_h.data(), Nbytes, hipMemcpyHostToDevice,
stream1));
HIP_CHECK(hipMemcpyAsync(B_d, B_h.data(), Nbytes, hipMemcpyHostToDevice,
stream2));
HIP_CHECK(hipMemcpyAsync(A_d, A_h.data(), Nbytes, hipMemcpyHostToDevice, stream1));
HIP_CHECK(hipMemcpyAsync(B_d, B_h.data(), Nbytes, hipMemcpyHostToDevice, stream2));
HIP_CHECK(hipMemsetAsync(C_d, 0, Nbytes, stream3));
HIP_CHECK(hipMemsetAsync(D_d, 0, Nbytes, stream4));
HIP_CHECK(hipEventRecord(e1, stream1));
@@ -449,16 +422,12 @@ TEST_CASE("Unit_hipStreamBeginCaptureToGraph_ComplexGraph") {
HIP_CHECK(hipEventRecord(e3, stream3));
HIP_CHECK(hipStreamWaitEvent(stream1, e2, 0));
HIP_CHECK(hipStreamWaitEvent(stream1, e3, 0));
HipTest::vectorADD<<< dim3(blocks), dim3(threadsPerBlock), 0, stream1 >>>
(A_d, B_d, C_d, N);
HipTest::vectorADD<<<dim3(blocks), dim3(threadsPerBlock), 0, stream1>>>(A_d, B_d, C_d, N);
HIP_CHECK(hipStreamWaitEvent(stream4, e2, 0));
HIP_CHECK(hipStreamWaitEvent(stream4, e1, 0));
HipTest::vectorSUB<<< dim3(blocks), dim3(threadsPerBlock), 0, stream4 >>>
(A_d, B_d, D_d, N);
HIP_CHECK(hipMemcpyAsync(C_h.data(), C_d, Nbytes, hipMemcpyDeviceToHost,
stream1));
HIP_CHECK(hipMemcpyAsync(D_h.data(), D_d, Nbytes, hipMemcpyDeviceToHost,
stream4));
HipTest::vectorSUB<<<dim3(blocks), dim3(threadsPerBlock), 0, stream4>>>(A_d, B_d, D_d, N);
HIP_CHECK(hipMemcpyAsync(C_h.data(), C_d, Nbytes, hipMemcpyDeviceToHost, stream1));
HIP_CHECK(hipMemcpyAsync(D_h.data(), D_d, Nbytes, hipMemcpyDeviceToHost, stream4));
HIP_CHECK(hipEventRecord(e4, stream4));
HIP_CHECK(hipStreamWaitEvent(stream1, e4, 0));
HIP_CHECK(hipStreamEndCapture(stream1, &graph));
@@ -513,8 +482,8 @@ TEST_CASE("Unit_hipStreamBeginCaptureToGraph_CaptureTwice") {
// Fill with data
for (size_t i = 0; i < N; i++) {
A_h[i] = 2*i;
B_h[i] = 2*i + 1;
A_h[i] = 2 * i;
B_h[i] = 2 * i + 1;
}
// Create streams, events and empty graph
@@ -538,24 +507,20 @@ TEST_CASE("Unit_hipStreamBeginCaptureToGraph_CaptureTwice") {
// Capture Nodes from multiple streams
if (useSameAPI) {
HIP_CHECK(hipStreamBeginCaptureToGraph(stream1, graph, nullptr, nullptr,
0, hipStreamCaptureModeGlobal));
HIP_CHECK(hipStreamBeginCaptureToGraph(stream1, graph, nullptr, nullptr, 0,
hipStreamCaptureModeGlobal));
} else {
HIP_CHECK(hipStreamBeginCapture(stream1, hipStreamCaptureModeGlobal));
}
// Capture all the other streams as well
HIP_CHECK(hipEventRecord(e1, stream1));
HIP_CHECK(hipStreamWaitEvent(stream2, e1, 0));
HIP_CHECK(hipMemcpyAsync(A_d, A_h.data(), Nbytes, hipMemcpyHostToDevice,
stream1));
HIP_CHECK(hipMemcpyAsync(B_d, B_h.data(), Nbytes, hipMemcpyHostToDevice,
stream2));
HIP_CHECK(hipMemcpyAsync(A_d, A_h.data(), Nbytes, hipMemcpyHostToDevice, stream1));
HIP_CHECK(hipMemcpyAsync(B_d, B_h.data(), Nbytes, hipMemcpyHostToDevice, stream2));
HIP_CHECK(hipEventRecord(e2, stream2));
HIP_CHECK(hipStreamWaitEvent(stream1, e2, 0));
HipTest::vectorADD<<< dim3(blocks), dim3(threadsPerBlock), 0, stream1 >>>
(A_d, B_d, C_d, N);
HIP_CHECK(hipMemcpyAsync(C_h.data(), C_d, Nbytes, hipMemcpyDeviceToHost,
stream1));
HipTest::vectorADD<<<dim3(blocks), dim3(threadsPerBlock), 0, stream1>>>(A_d, B_d, C_d, N);
HIP_CHECK(hipMemcpyAsync(C_h.data(), C_d, Nbytes, hipMemcpyDeviceToHost, stream1));
HIP_CHECK(hipStreamEndCapture(stream1, &graph));
// Get the dependant nodes
@@ -564,12 +529,10 @@ TEST_CASE("Unit_hipStreamBeginCaptureToGraph_CaptureTwice") {
std::vector<hipGraphNode_t> rootNodes(numRootNodes);
HIP_CHECK(hipGraphGetRootNodes(graph, rootNodes.data(), &numRootNodes));
// Capture Nodes from multiple streams
HIP_CHECK(hipStreamBeginCaptureToGraph(stream1, graph, rootNodes.data(),
nullptr, rootNodes.size(), hipStreamCaptureModeGlobal));
HipTest::vectorSUB<<< dim3(blocks), dim3(threadsPerBlock), 0, stream1 >>>
(A_d, B_d, D_d, N);
HIP_CHECK(hipMemcpyAsync(D_h.data(), D_d, Nbytes, hipMemcpyDeviceToHost,
stream1));
HIP_CHECK(hipStreamBeginCaptureToGraph(stream1, graph, rootNodes.data(), nullptr,
rootNodes.size(), hipStreamCaptureModeGlobal));
HipTest::vectorSUB<<<dim3(blocks), dim3(threadsPerBlock), 0, stream1>>>(A_d, B_d, D_d, N);
HIP_CHECK(hipMemcpyAsync(D_h.data(), D_d, Nbytes, hipMemcpyDeviceToHost, stream1));
HIP_CHECK(hipStreamEndCapture(stream1, &graph));
// Instantiate Graph
@@ -616,8 +579,8 @@ TEST_CASE("Unit_hipStreamBeginCaptureToGraph_ModifyCloneGraph") {
// Fill with data
for (size_t i = 0; i < N; i++) {
A_h[i] = 2*i;
B_h[i] = 2*i + 1;
A_h[i] = 2 * i;
B_h[i] = 2 * i + 1;
}
// Create streams, events and empty graph
@@ -638,21 +601,17 @@ TEST_CASE("Unit_hipStreamBeginCaptureToGraph_ModifyCloneGraph") {
HIP_CHECK(hipMalloc(&D_d, Nbytes));
// Capture Nodes from multiple streams
HIP_CHECK(hipStreamBeginCaptureToGraph(stream1, graph, nullptr, nullptr,
0, hipStreamCaptureModeGlobal));
HIP_CHECK(hipStreamBeginCaptureToGraph(stream1, graph, nullptr, nullptr, 0,
hipStreamCaptureModeGlobal));
// Capture all the other streams as well
HIP_CHECK(hipEventRecord(e1, stream1));
HIP_CHECK(hipStreamWaitEvent(stream2, e1, 0));
HIP_CHECK(hipMemcpyAsync(A_d, A_h.data(), Nbytes, hipMemcpyHostToDevice,
stream1));
HIP_CHECK(hipMemcpyAsync(B_d, B_h.data(), Nbytes, hipMemcpyHostToDevice,
stream2));
HIP_CHECK(hipMemcpyAsync(A_d, A_h.data(), Nbytes, hipMemcpyHostToDevice, stream1));
HIP_CHECK(hipMemcpyAsync(B_d, B_h.data(), Nbytes, hipMemcpyHostToDevice, stream2));
HIP_CHECK(hipEventRecord(e2, stream2));
HIP_CHECK(hipStreamWaitEvent(stream1, e2, 0));
HipTest::vectorADD<<< dim3(blocks), dim3(threadsPerBlock), 0, stream1 >>>
(A_d, B_d, C_d, N);
HIP_CHECK(hipMemcpyAsync(C_h.data(), C_d, Nbytes, hipMemcpyDeviceToHost,
stream1));
HipTest::vectorADD<<<dim3(blocks), dim3(threadsPerBlock), 0, stream1>>>(A_d, B_d, C_d, N);
HIP_CHECK(hipMemcpyAsync(C_h.data(), C_d, Nbytes, hipMemcpyDeviceToHost, stream1));
HIP_CHECK(hipStreamEndCapture(stream1, &graph));
// Clone the graph
hipGraph_t graphClone{nullptr};
@@ -661,16 +620,12 @@ TEST_CASE("Unit_hipStreamBeginCaptureToGraph_ModifyCloneGraph") {
size_t numRootNodes = 0;
HIP_CHECK(hipGraphGetRootNodes(graphClone, nullptr, &numRootNodes));
std::vector<hipGraphNode_t> rootNodes(numRootNodes);
HIP_CHECK(hipGraphGetRootNodes(graphClone, rootNodes.data(),
&numRootNodes));
HIP_CHECK(hipGraphGetRootNodes(graphClone, rootNodes.data(), &numRootNodes));
// Capture Nodes from multiple streams
HIP_CHECK(hipStreamBeginCaptureToGraph(stream1, graphClone,
rootNodes.data(), nullptr, rootNodes.size(),
hipStreamCaptureModeGlobal));
HipTest::vectorSUB<<< dim3(blocks), dim3(threadsPerBlock), 0, stream1 >>>
(A_d, B_d, D_d, N);
HIP_CHECK(hipMemcpyAsync(D_h.data(), D_d, Nbytes, hipMemcpyDeviceToHost,
stream1));
HIP_CHECK(hipStreamBeginCaptureToGraph(stream1, graphClone, rootNodes.data(), nullptr,
rootNodes.size(), hipStreamCaptureModeGlobal));
HipTest::vectorSUB<<<dim3(blocks), dim3(threadsPerBlock), 0, stream1>>>(A_d, B_d, D_d, N);
HIP_CHECK(hipMemcpyAsync(D_h.data(), D_d, Nbytes, hipMemcpyDeviceToHost, stream1));
HIP_CHECK(hipStreamEndCapture(stream1, &graphClone));
// Instantiate Cloned Graph
@@ -738,17 +693,15 @@ TEST_CASE("Unit_hipStreamBeginCaptureToGraph_CaptureChildpGraph") {
HIP_CHECK(hipMalloc(&D_d, Nbytes));
// Create manual graph
HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpyNode1, graph, nullptr, 0, A_d,
A_h.data(), Nbytes, hipMemcpyHostToDevice));
HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpyNode2, graph, nullptr, 0, B_d,
B_h.data(), Nbytes, hipMemcpyHostToDevice));
HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpyNode3, graphChild, nullptr, 0,
C_h.data(), C_d, Nbytes, hipMemcpyDeviceToHost));
HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpyNode1, graph, nullptr, 0, A_d, A_h.data(), Nbytes,
hipMemcpyHostToDevice));
HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpyNode2, graph, nullptr, 0, B_d, B_h.data(), Nbytes,
hipMemcpyHostToDevice));
HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpyNode3, graphChild, nullptr, 0, C_h.data(), C_d, Nbytes,
hipMemcpyDeviceToHost));
size_t arrSize = N;
void* kernelArgs[4] = {reinterpret_cast<void*>(&A_d),
reinterpret_cast<void*>(&B_d),
reinterpret_cast<void*>(&C_d),
&arrSize};
void* kernelArgs[4] = {reinterpret_cast<void*>(&A_d), reinterpret_cast<void*>(&B_d),
reinterpret_cast<void*>(&C_d), &arrSize};
hipKernelNodeParams kernelNodeParams{};
kernelNodeParams.func = reinterpret_cast<void*>(HipTest::vectorADD<int>);
kernelNodeParams.gridDim = dim3(blocks, 1, 1);
@@ -757,27 +710,21 @@ TEST_CASE("Unit_hipStreamBeginCaptureToGraph_CaptureChildpGraph") {
kernelNodeParams.kernelParams = reinterpret_cast<void**>(kernelArgs);
kernelNodeParams.extra = nullptr;
// Create the child graph node kernelNode1->memcpyNode3
HIP_CHECK(hipGraphAddKernelNode(&kernelNode1, graphChild, 0, 0,
&kernelNodeParams));
HIP_CHECK(hipGraphAddDependencies(graphChild, &kernelNode1,
&memcpyNode3, 1));
HIP_CHECK(hipGraphAddKernelNode(&kernelNode1, graphChild, 0, 0, &kernelNodeParams));
HIP_CHECK(hipGraphAddDependencies(graphChild, &kernelNode1, &memcpyNode3, 1));
// Add the graphChild to graph with dependencies
std::vector<hipGraphNode_t> dependncy;
dependncy.push_back(memcpyNode1);
dependncy.push_back(memcpyNode2);
hipGraphNode_t childGraphNode;
HIP_CHECK(hipGraphAddChildGraphNode(&childGraphNode, graph,
dependncy.data(), dependncy.size(),
HIP_CHECK(hipGraphAddChildGraphNode(&childGraphNode, graph, dependncy.data(), dependncy.size(),
graphChild));
// Capture stream into graph
// Capture Nodes from multiple streams
HIP_CHECK(hipStreamBeginCaptureToGraph(stream, graph, dependncy.data(),
nullptr, dependncy.size(),
hipStreamCaptureModeGlobal));
HipTest::vectorSUB<<< dim3(blocks), dim3(threadsPerBlock), 0, stream >>>
(A_d, B_d, D_d, N);
HIP_CHECK(hipMemcpyAsync(D_h.data(), D_d, Nbytes, hipMemcpyDeviceToHost,
stream));
HIP_CHECK(hipStreamBeginCaptureToGraph(stream, graph, dependncy.data(), nullptr, dependncy.size(),
hipStreamCaptureModeGlobal));
HipTest::vectorSUB<<<dim3(blocks), dim3(threadsPerBlock), 0, stream>>>(A_d, B_d, D_d, N);
HIP_CHECK(hipMemcpyAsync(D_h.data(), D_d, Nbytes, hipMemcpyDeviceToHost, stream));
HIP_CHECK(hipStreamEndCapture(stream, &graph));
// Instantiate Cloned Graph
hipGraphExec_t graphExec{nullptr};
@@ -840,17 +787,15 @@ TEST_CASE("Unit_hipStreamBeginCaptureToGraph_ModifyChildpGraph") {
HIP_CHECK(hipMalloc(&D_d, Nbytes));
// Create manual graph
HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpyNode1, graph, nullptr, 0, A_d,
A_h.data(), Nbytes, hipMemcpyHostToDevice));
HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpyNode2, graph, nullptr, 0, B_d,
B_h.data(), Nbytes, hipMemcpyHostToDevice));
HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpyNode3, graphChild, nullptr, 0,
C_h.data(), C_d, Nbytes, hipMemcpyDeviceToHost));
HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpyNode1, graph, nullptr, 0, A_d, A_h.data(), Nbytes,
hipMemcpyHostToDevice));
HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpyNode2, graph, nullptr, 0, B_d, B_h.data(), Nbytes,
hipMemcpyHostToDevice));
HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpyNode3, graphChild, nullptr, 0, C_h.data(), C_d, Nbytes,
hipMemcpyDeviceToHost));
size_t arrSize = N;
void* kernelArgs[4] = {reinterpret_cast<void*>(&A_d),
reinterpret_cast<void*>(&B_d),
reinterpret_cast<void*>(&C_d),
&arrSize};
void* kernelArgs[4] = {reinterpret_cast<void*>(&A_d), reinterpret_cast<void*>(&B_d),
reinterpret_cast<void*>(&C_d), &arrSize};
hipKernelNodeParams kernelNodeParams{};
kernelNodeParams.func = reinterpret_cast<void*>(HipTest::vectorADD<int>);
kernelNodeParams.gridDim = dim3(blocks, 1, 1);
@@ -859,27 +804,22 @@ TEST_CASE("Unit_hipStreamBeginCaptureToGraph_ModifyChildpGraph") {
kernelNodeParams.kernelParams = reinterpret_cast<void**>(kernelArgs);
kernelNodeParams.extra = nullptr;
// Create the child graph node kernelNode1->memcpyNode3
HIP_CHECK(hipGraphAddKernelNode(&kernelNode1, graphChild, 0, 0,
&kernelNodeParams));
HIP_CHECK(hipGraphAddDependencies(graphChild, &kernelNode1,
&memcpyNode3, 1));
HIP_CHECK(hipGraphAddKernelNode(&kernelNode1, graphChild, 0, 0, &kernelNodeParams));
HIP_CHECK(hipGraphAddDependencies(graphChild, &kernelNode1, &memcpyNode3, 1));
// Add the graphChild to graph with dependencies
std::vector<hipGraphNode_t> dependncy;
dependncy.push_back(memcpyNode1);
dependncy.push_back(memcpyNode2);
hipGraphNode_t childGraphNode;
HIP_CHECK(hipGraphAddChildGraphNode(&childGraphNode, graph,
dependncy.data(), dependncy.size(),
HIP_CHECK(hipGraphAddChildGraphNode(&childGraphNode, graph, dependncy.data(), dependncy.size(),
graphChild));
HIP_CHECK(hipGraphChildGraphNodeGetGraph(childGraphNode, &graphChild));
// Capture stream into graph
// Capture Nodes from multiple streams
HIP_CHECK(hipStreamBeginCaptureToGraph(stream, graphChild, nullptr, nullptr,
0, hipStreamCaptureModeGlobal));
HipTest::vectorSUB<<< dim3(blocks), dim3(threadsPerBlock), 0, stream >>>
(A_d, B_d, D_d, N);
HIP_CHECK(hipMemcpyAsync(D_h.data(), D_d, Nbytes, hipMemcpyDeviceToHost,
stream));
HIP_CHECK(hipStreamBeginCaptureToGraph(stream, graphChild, nullptr, nullptr, 0,
hipStreamCaptureModeGlobal));
HipTest::vectorSUB<<<dim3(blocks), dim3(threadsPerBlock), 0, stream>>>(A_d, B_d, D_d, N);
HIP_CHECK(hipMemcpyAsync(D_h.data(), D_d, Nbytes, hipMemcpyDeviceToHost, stream));
HIP_CHECK(hipStreamEndCapture(stream, &graphChild));
// Instantiate Cloned Graph
hipGraphExec_t graphExec{nullptr};
@@ -922,24 +862,24 @@ TEST_CASE("Unit_hipStreamBeginCaptureToGraph_Negative") {
HIP_CHECK(hipGraphCreate(&graph, 0));
SECTION("Null graph") {
REQUIRE(hipErrorInvalidValue ==
hipStreamBeginCaptureToGraph(stream, nullptr, nullptr,
nullptr, 0, hipStreamCaptureModeGlobal));
hipStreamBeginCaptureToGraph(stream, nullptr, nullptr, nullptr, 0,
hipStreamCaptureModeGlobal));
}
SECTION("Null dependencies") {
REQUIRE(hipErrorInvalidValue ==
hipStreamBeginCaptureToGraph(stream, graph, nullptr,
nullptr, 1, hipStreamCaptureModeGlobal));
hipStreamBeginCaptureToGraph(stream, graph, nullptr, nullptr, 1,
hipStreamCaptureModeGlobal));
}
SECTION("Invalid mode") {
REQUIRE(hipErrorInvalidValue ==
hipStreamBeginCaptureToGraph(stream, graph, nullptr, nullptr, 0,
static_cast<hipStreamCaptureMode>(-1)));
hipStreamBeginCaptureToGraph(stream, graph, nullptr, nullptr, 0,
static_cast<hipStreamCaptureMode>(-1)));
}
SECTION("Capturing a stream already in Capture mode") {
hipGraph_t graphLoc{nullptr};
HIP_CHECK(hipStreamBeginCapture(stream, hipStreamCaptureModeGlobal));
hipError_t err = hipStreamBeginCaptureToGraph(stream, graph, nullptr,
nullptr, 0, hipStreamCaptureModeGlobal);
hipError_t err = hipStreamBeginCaptureToGraph(stream, graph, nullptr, nullptr, 0,
hipStreamCaptureModeGlobal);
REQUIRE(hipErrorIllegalState == err);
HIP_CHECK(hipStreamEndCapture(stream, &graphLoc));
HIP_CHECK(hipGraphDestroy(graphLoc));
@@ -973,7 +913,7 @@ TEST_CASE("Unit_hipStreamBeginCaptureToGraph_StateTesting") {
HIP_CHECK(hipStreamIsCapturing(stream1, &captureStatus));
REQUIRE(captureStatus == hipStreamCaptureStatusNone);
HIP_CHECK(hipStreamBeginCaptureToGraph(stream1, graph, nullptr, nullptr, 0,
hipStreamCaptureModeGlobal));
hipStreamCaptureModeGlobal));
HIP_CHECK(hipStreamIsCapturing(stream1, &captureStatus));
REQUIRE(captureStatus == hipStreamCaptureStatusActive);
HIP_CHECK(hipEventRecord(e, stream1));
@@ -1017,7 +957,7 @@ TEST_CASE("Unit_hipStreamBeginCaptureToGraph_GetCaptureInfo") {
HIP_CHECK(hipStreamGetCaptureInfo(stream1, &captureStatus, &id_before));
REQUIRE(captureStatus == hipStreamCaptureStatusNone);
HIP_CHECK(hipStreamBeginCaptureToGraph(stream1, graph, nullptr, nullptr, 0,
hipStreamCaptureModeGlobal));
hipStreamCaptureModeGlobal));
HIP_CHECK(hipStreamGetCaptureInfo(stream1, &captureStatus, &id_strm1));
REQUIRE(captureStatus == hipStreamCaptureStatusActive);
HIP_CHECK(hipEventRecord(e, stream1));
@@ -1065,11 +1005,10 @@ TEST_CASE("Unit_hipStreamBeginCaptureToGraph_EndingWhileCaptureInProgress") {
hipEvent_t e;
HIP_CHECK(hipEventCreate(&e));
HIP_CHECK(hipStreamBeginCaptureToGraph(stream1, graph, nullptr, nullptr, 0,
hipStreamCaptureModeGlobal));
hipStreamCaptureModeGlobal));
HIP_CHECK(hipEventRecord(e, stream1));
HIP_CHECK(hipStreamWaitEvent(stream2, e, 0));
HIP_CHECK(hipMemcpyAsync(A_d, A_h.data(), Nbytes, hipMemcpyHostToDevice,
stream1));
HIP_CHECK(hipMemcpyAsync(A_d, A_h.data(), Nbytes, hipMemcpyHostToDevice, stream1));
REQUIRE(hipSuccess == hipStreamEndCapture(stream1, &graph));
HIP_CHECK(hipEventDestroy(e));
}
@@ -1079,19 +1018,15 @@ TEST_CASE("Unit_hipStreamBeginCaptureToGraph_EndingWhileCaptureInProgress") {
HIP_CHECK(hipEventCreate(&e1));
HIP_CHECK(hipEventCreate(&e2));
HIP_CHECK(hipStreamBeginCaptureToGraph(stream1, graph, nullptr, nullptr, 0,
hipStreamCaptureModeGlobal));
HIP_CHECK(hipMemcpyAsync(A_d, A_h.data(), Nbytes, hipMemcpyHostToDevice,
stream1));
hipStreamCaptureModeGlobal));
HIP_CHECK(hipMemcpyAsync(A_d, A_h.data(), Nbytes, hipMemcpyHostToDevice, stream1));
HIP_CHECK(hipEventRecord(e1, stream1));
HIP_CHECK(hipStreamWaitEvent(stream2, e1, 0));
HIP_CHECK(hipMemcpyAsync(B_d, A_h.data(), Nbytes, hipMemcpyHostToDevice,
stream2));
HIP_CHECK(hipMemcpyAsync(B_d, A_h.data(), Nbytes, hipMemcpyHostToDevice, stream2));
HIP_CHECK(hipEventRecord(e2, stream2));
HIP_CHECK(hipStreamWaitEvent(stream1, e2, 0));
HIP_CHECK(hipMemcpyAsync(C_d, A_h.data(), Nbytes, hipMemcpyHostToDevice,
stream2));
REQUIRE(hipErrorStreamCaptureUnjoined == hipStreamEndCapture(stream1,
&graph));
HIP_CHECK(hipMemcpyAsync(C_d, A_h.data(), Nbytes, hipMemcpyHostToDevice, stream2));
REQUIRE(hipErrorStreamCaptureUnjoined == hipStreamEndCapture(stream1, &graph));
HIP_CHECK(hipEventDestroy(e2));
HIP_CHECK(hipEventDestroy(e1));
}
@@ -1114,16 +1049,11 @@ TEST_CASE("Unit_hipStreamBeginCaptureToGraph_EndingWhileCaptureInProgress") {
* ------------------------
* - HIP_VERSION >= 6.2
*/
enum class strmFlag {
defFlag,
sameFlag,
diffFlag,
diffPrio
};
enum class strmFlag { defFlag, sameFlag, diffFlag, diffPrio };
TEST_CASE("Unit_hipStreamBeginCaptureToGraph_MultipleFlags") {
strmFlag flag = GENERATE(strmFlag::defFlag, strmFlag::sameFlag,
strmFlag::diffFlag, strmFlag::diffPrio);
strmFlag flag =
GENERATE(strmFlag::defFlag, strmFlag::sameFlag, strmFlag::diffFlag, strmFlag::diffPrio);
int *A_d, *B_d, *C_d;
std::vector<int> A_h(N), B_h(N), C_h(N);
size_t Nbytes = N * sizeof(int);
@@ -1133,8 +1063,8 @@ TEST_CASE("Unit_hipStreamBeginCaptureToGraph_MultipleFlags") {
// Fill with data
for (size_t i = 0; i < N; i++) {
A_h[i] = 2*i;
B_h[i] = 2*i + 1;
A_h[i] = 2 * i;
B_h[i] = 2 * i + 1;
}
if (flag == strmFlag::sameFlag) {
HIP_CHECK(hipStreamCreateWithFlags(&stream1, hipStreamNonBlocking));
@@ -1145,10 +1075,8 @@ TEST_CASE("Unit_hipStreamBeginCaptureToGraph_MultipleFlags") {
} else if (flag == strmFlag::diffPrio) {
int minPriority = 0, maxPriority = 0;
HIP_CHECK(hipDeviceGetStreamPriorityRange(&minPriority, &maxPriority));
HIP_CHECK(hipStreamCreateWithPriority(&stream1, hipStreamDefault,
minPriority));
HIP_CHECK(hipStreamCreateWithPriority(&stream2, hipStreamDefault,
maxPriority));
HIP_CHECK(hipStreamCreateWithPriority(&stream1, hipStreamDefault, minPriority));
HIP_CHECK(hipStreamCreateWithPriority(&stream2, hipStreamDefault, maxPriority));
} else {
HIP_CHECK(hipStreamCreateWithFlags(&stream1, hipStreamDefault));
HIP_CHECK(hipStreamCreateWithFlags(&stream2, hipStreamDefault));
@@ -1158,14 +1086,11 @@ TEST_CASE("Unit_hipStreamBeginCaptureToGraph_MultipleFlags") {
HIP_CHECK(hipMalloc(&B_d, Nbytes));
HIP_CHECK(hipMalloc(&C_d, Nbytes));
bool verifyStreamSync = false;
SECTION("Verify after hipGraphExecDestroy()") {
verifyStreamSync = false;
}
SECTION("Verify after hipStreamSynchronize()") {
verifyStreamSync = true;
}
SECTION("Verify after hipGraphExecDestroy()") { verifyStreamSync = false; }
SECTION("Verify after hipStreamSynchronize()") { verifyStreamSync = true; }
ret = CaptureStreamAndLaunchGraph(A_d, B_d, C_d, A_h.data(), B_h.data(), C_h.data(),
hipStreamCaptureModeGlobal, stream1, stream2, graph, verifyStreamSync);
hipStreamCaptureModeGlobal, stream1, stream2, graph,
verifyStreamSync);
REQUIRE(ret == true);
HIP_CHECK(hipStreamDestroy(stream1));
@@ -1187,32 +1112,26 @@ TEST_CASE("Unit_hipStreamBeginCaptureToGraph_MultipleFlags") {
* ------------------------
* - HIP_VERSION >= 6.2
*/
static void threadCaptureEnd(hipStream_t *streamCapt, hipGraph_t *graph,
int *A_d, int *B_d, int *C_d, int *C_h, size_t N) {
static void threadCaptureEnd(hipStream_t* streamCapt, hipGraph_t* graph, int* A_d, int* B_d,
int* C_d, int* C_h, size_t N) {
size_t Nbytes = N * sizeof(int);
HipTest::vectorSUB<<< dim3(blocks), dim3(threadsPerBlock), 0, *streamCapt >>>
(A_d, B_d, C_d, N);
HIP_CHECK(hipMemcpyAsync(C_h, C_d, Nbytes, hipMemcpyDeviceToHost,
*streamCapt));
HipTest::vectorSUB<<<dim3(blocks), dim3(threadsPerBlock), 0, *streamCapt>>>(A_d, B_d, C_d, N);
HIP_CHECK(hipMemcpyAsync(C_h, C_d, Nbytes, hipMemcpyDeviceToHost, *streamCapt));
HIP_CHECK(hipStreamEndCapture(*streamCapt, graph));
}
static void threadCaptureStart(hipStream_t *streamCapt,
hipStream_t *streamFork,
hipGraph_t *graph, int *A_d, int *B_d,
int *C_d, int *A_h, int *B_h, size_t N) {
static void threadCaptureStart(hipStream_t* streamCapt, hipStream_t* streamFork, hipGraph_t* graph,
int* A_d, int* B_d, int* C_d, int* A_h, int* B_h, size_t N) {
size_t Nbytes = N * sizeof(int);
hipEvent_t e;
HIP_CHECK(hipEventCreate(&e));
HIP_CHECK(hipStreamBeginCaptureToGraph(*streamCapt, *graph, nullptr,
nullptr, 0, hipStreamCaptureModeRelaxed));
HIP_CHECK(hipStreamBeginCaptureToGraph(*streamCapt, *graph, nullptr, nullptr, 0,
hipStreamCaptureModeRelaxed));
HIP_CHECK(hipEventRecord(e, *streamCapt));
HIP_CHECK(hipStreamWaitEvent(*streamFork, e, 0));
HIP_CHECK(hipMemsetAsync(C_d, 0, Nbytes, *streamCapt));
HIP_CHECK(hipMemcpyAsync(A_d, A_h, Nbytes, hipMemcpyHostToDevice,
*streamCapt));
HIP_CHECK(hipMemcpyAsync(B_d, B_h, Nbytes, hipMemcpyHostToDevice,
*streamFork));
HIP_CHECK(hipMemcpyAsync(A_d, A_h, Nbytes, hipMemcpyHostToDevice, *streamCapt));
HIP_CHECK(hipMemcpyAsync(B_d, B_h, Nbytes, hipMemcpyHostToDevice, *streamFork));
HIP_CHECK(hipEventRecord(e, *streamFork));
HIP_CHECK(hipStreamWaitEvent(*streamCapt, e, 0));
}
@@ -1237,11 +1156,10 @@ TEST_CASE("Unit_hipStreamBeginCaptureToGraph_CapturePartialInThreads") {
HIP_CHECK(hipMalloc(&B_d, Nbytes));
HIP_CHECK(hipMalloc(&C_d, Nbytes));
// Launch threads to capture graph
std::thread startCaptureThread(threadCaptureStart, &stream1, &stream2,
&graph, A_d, B_d, C_d, A_h.data(), B_h.data(), N);
std::thread startCaptureThread(threadCaptureStart, &stream1, &stream2, &graph, A_d, B_d, C_d,
A_h.data(), B_h.data(), N);
startCaptureThread.join();
std::thread endCaptureThread(threadCaptureEnd, &stream1, &graph, A_d, B_d,
C_d, C_h.data(), N);
std::thread endCaptureThread(threadCaptureEnd, &stream1, &graph, A_d, B_d, C_d, C_h.data(), N);
endCaptureThread.join();
// Instantiate and execute the graph
hipGraphExec_t graphExec{nullptr};
@@ -1275,13 +1193,12 @@ TEST_CASE("Unit_hipStreamBeginCaptureToGraph_CapturePartialInThreads") {
#ifdef __linux__
// Currently disabled due to defect raised.
static std::atomic<int> retValG(1);
void threadCaptureExec(int *A_d, int *B_d, int *C_d,
int *A_h, int *B_h, int *C_h,
hipStream_t *stream1, hipStream_t *stream2,
hipGraph_t *graph, bool verifyStreamSync) {
void threadCaptureExec(int* A_d, int* B_d, int* C_d, int* A_h, int* B_h, int* C_h,
hipStream_t* stream1, hipStream_t* stream2, hipGraph_t* graph,
bool verifyStreamSync) {
bool ret = false;
ret = CaptureStreamAndLaunchGraph(A_d, B_d, C_d, A_h, B_h, C_h, hipStreamCaptureModeRelaxed,
*stream1, *stream2, *graph, verifyStreamSync);
*stream1, *stream2, *graph, verifyStreamSync);
int val = 0;
if (ret) {
val = 1;
@@ -1300,8 +1217,8 @@ TEST_CASE("Unit_hipStreamBeginCaptureToGraph_IndepGraphsThreads") {
// Fill with data
for (size_t i = 0; i < N; i++) {
A2_h[i] = A1_h[i] = 2*i;
B2_h[i] = B1_h[i] = 2*i + 1;
A2_h[i] = A1_h[i] = 2 * i;
B2_h[i] = B1_h[i] = 2 * i + 1;
}
// Create stream and empty graph
@@ -1323,20 +1240,14 @@ TEST_CASE("Unit_hipStreamBeginCaptureToGraph_IndepGraphsThreads") {
// Capture an independent graph from stream
bool verifyStreamSync = false;
SECTION("Verify after hipGraphExecDestroy()") {
verifyStreamSync = false;
}
SECTION("Verify after hipGraphExecDestroy()") { verifyStreamSync = false; }
SECTION("Verify after hipStreamSynchronize()") {
verifyStreamSync = true;
}
SECTION("Verify after hipStreamSynchronize()") { verifyStreamSync = true; }
std::thread thread1(threadCaptureExec, A1_d, B1_d, C1_d,
A1_h.data(), B1_h.data(), C1_h.data(),
std::thread thread1(threadCaptureExec, A1_d, B1_d, C1_d, A1_h.data(), B1_h.data(), C1_h.data(),
&stream1, &stream2, &graph1, verifyStreamSync);
std::thread thread2(threadCaptureExec, A2_d, B2_d, C2_d,
A2_h.data(), B2_h.data(), C2_h.data(),
std::thread thread2(threadCaptureExec, A2_d, B2_d, C2_d, A2_h.data(), B2_h.data(), C2_h.data(),
&stream3, &stream4, &graph2, verifyStreamSync);
thread1.join();
thread2.join();