Skip to content

Commit c7e3907

Browse files
committed
[UR] Add initial graph record & replay tests
1 parent 041422f commit c7e3907

File tree

10 files changed

+388
-0
lines changed

10 files changed

+388
-0
lines changed

unified-runtime/test/conformance/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ add_subdirectory(queue)
7070
add_subdirectory(sampler)
7171
add_subdirectory(virtual_memory)
7272
add_subdirectory(exp_usm_context_memcpy)
73+
add_subdirectory(exp_graph)
7374

7475
set(TEST_SUBDIRECTORIES_DPCXX
7576
"device_code"
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Copyright (C) 2025 Intel Corporation
2+
# Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM Exceptions.
3+
# See LICENSE.TXT
4+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
5+
6+
add_conformance_devices_test(exp_graph
7+
urEnqueueGraphExp.cpp
8+
urGraphCreateExp.cpp
9+
urGraphInstantiateGraphExp.cpp
10+
urGraphIsEmptyExp.cpp
11+
urQueueBeginCaptureIntoGraphExp.cpp
12+
urQueueBeginGraphCaptureExp.cpp
13+
urQueueIsGraphCaptureEnabledExp.cpp)
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
// Copyright (C) 2025 Intel Corporation
2+
// Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM
3+
// Exceptions. See LICENSE.TXT
4+
//
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
7+
#ifndef UR_CONFORMANCE_GRAPH_FIXTURES_H
8+
#define UR_CONFORMANCE_GRAPH_FIXTURES_H
9+
10+
#include "uur/fixtures.h"
11+
#include "uur/known_failure.h"
12+
#include "uur/raii.h"
13+
14+
namespace uur {
15+
16+
struct urGraphSupportedExpTest : uur::urQueueTest {
17+
void SetUp() override {
18+
UUR_RETURN_ON_FATAL_FAILURE(urQueueTest::SetUp());
19+
20+
UUR_KNOWN_FAILURE_ON(uur::CUDA{}, uur::HIP{}, uur::NativeCPU{},
21+
uur::OpenCL{}, uur::LevelZero{}, uur::LevelZeroV2{});
22+
}
23+
};
24+
25+
struct urGraphExpTest : urGraphSupportedExpTest {
26+
void SetUp() override {
27+
UUR_RETURN_ON_FATAL_FAILURE(urGraphSupportedExpTest::SetUp());
28+
29+
ASSERT_SUCCESS(urGraphCreateExp(context, &graph));
30+
}
31+
32+
void TearDown() override {
33+
if (graph) {
34+
ASSERT_SUCCESS(urGraphDestroyExp(graph));
35+
}
36+
37+
UUR_RETURN_ON_FATAL_FAILURE(urGraphSupportedExpTest::TearDown());
38+
}
39+
40+
ur_exp_graph_handle_t graph = nullptr;
41+
};
42+
43+
struct urGraphPopulatedExpTest : urGraphExpTest {
44+
void SetUp() override {
45+
UUR_RETURN_ON_FATAL_FAILURE(urGraphExpTest::SetUp());
46+
47+
ur_device_usm_access_capability_flags_t deviceUSMSupport = 0;
48+
ASSERT_SUCCESS(uur::GetDeviceUSMDeviceSupport(device, deviceUSMSupport));
49+
if (!deviceUSMSupport) {
50+
GTEST_SKIP() << "Device USM is not supported";
51+
}
52+
uur::generateMemFillPattern(pattern);
53+
54+
ASSERT_SUCCESS(urUSMDeviceAlloc(context, device, nullptr, nullptr,
55+
allocationSize, &deviceMem));
56+
57+
ASSERT_SUCCESS(urQueueBeginCaptureIntoGraphExp(queue, graph));
58+
59+
ASSERT_SUCCESS(urEnqueueUSMFill(queue, deviceMem, patternSize,
60+
pattern.data(), allocationSize, 0, nullptr,
61+
fillEvent.ptr()));
62+
ASSERT_SUCCESS(urQueueFinish(queue));
63+
64+
ur_exp_graph_handle_t sameGraph = nullptr;
65+
ASSERT_SUCCESS(urQueueEndGraphCaptureExp(queue, &sameGraph));
66+
ASSERT_EQ(graph, sameGraph);
67+
68+
ASSERT_NO_FATAL_FAILURE(verifyData(false));
69+
}
70+
71+
void TearDown() override {
72+
if (deviceMem) {
73+
ASSERT_SUCCESS(urUSMFree(context, deviceMem));
74+
}
75+
76+
UUR_RETURN_ON_FATAL_FAILURE(urGraphExpTest::TearDown());
77+
}
78+
79+
void verifyData(const bool shouldMatch) {
80+
ASSERT_SUCCESS(urEnqueueUSMMemcpy(queue, true, hostMem.data(), deviceMem,
81+
allocationSize, 0, nullptr, nullptr));
82+
83+
size_t patternIdx = 0;
84+
for (size_t i = 0; i < allocationSize; ++i) {
85+
uint8_t *hostPtr = hostMem.data();
86+
ASSERT_EQ((*(hostPtr + i) == pattern[patternIdx]), shouldMatch);
87+
88+
++patternIdx;
89+
if (patternIdx % pattern.size() == 0) {
90+
patternIdx = 0;
91+
}
92+
}
93+
}
94+
95+
const size_t allocationSize = 256;
96+
void *deviceMem{nullptr};
97+
std::vector<uint8_t> hostMem = std::vector<uint8_t>(allocationSize);
98+
const size_t patternSize = 64;
99+
std::vector<uint8_t> pattern = std::vector<uint8_t>(patternSize);
100+
uur::raii::Event fillEvent = nullptr;
101+
};
102+
103+
struct urGraphExecutableExpTest : urGraphPopulatedExpTest {
104+
void SetUp() override {
105+
UUR_RETURN_ON_FATAL_FAILURE(urGraphPopulatedExpTest::SetUp());
106+
107+
ASSERT_SUCCESS(urGraphInstantiateGraphExp(graph, &exGraph));
108+
}
109+
110+
void TearDown() override {
111+
if (exGraph) {
112+
ASSERT_SUCCESS(urGraphExecutableGraphDestroyExp(exGraph));
113+
}
114+
115+
UUR_RETURN_ON_FATAL_FAILURE(urGraphPopulatedExpTest::TearDown());
116+
}
117+
118+
ur_exp_executable_graph_handle_t exGraph = nullptr;
119+
};
120+
121+
} // namespace uur
122+
123+
#endif // UR_CONFORMANCE_GRAPH_FIXTURES_H
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// Copyright (C) 2025 Intel Corporation
2+
// Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM
3+
// Exceptions. See LICENSE.TXT
4+
//
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
7+
#include "fixtures.h"
8+
#include "uur/raii.h"
9+
10+
using urEnqueueGraphExpTest = uur::urGraphExecutableExpTest;
11+
12+
UUR_INSTANTIATE_DEVICE_TEST_SUITE(urEnqueueGraphExpTest);
13+
14+
TEST_P(urEnqueueGraphExpTest, Success) {
15+
verifyData(false);
16+
ASSERT_SUCCESS(urEnqueueGraphExp(queue, exGraph, 0, nullptr, nullptr));
17+
ASSERT_SUCCESS(urQueueFinish(queue));
18+
19+
ASSERT_NO_FATAL_FAILURE(verifyData(true));
20+
}
21+
22+
TEST_P(urEnqueueGraphExpTest, SuccessWithEvent) {
23+
uur::raii::Event graphEvent = nullptr;
24+
ASSERT_SUCCESS(
25+
urEnqueueGraphExp(queue, exGraph, 0, nullptr, graphEvent.ptr()));
26+
ASSERT_SUCCESS(urQueueFlush(queue));
27+
ASSERT_SUCCESS(urEventWait(1, graphEvent.ptr()));
28+
}
29+
30+
TEST_P(urEnqueueGraphExpTest, InvalidNullHandleQueue) {
31+
ASSERT_EQ_RESULT(UR_RESULT_ERROR_INVALID_NULL_HANDLE,
32+
urEnqueueGraphExp(nullptr, exGraph, 0, nullptr, nullptr));
33+
}
34+
35+
TEST_P(urEnqueueGraphExpTest, InvalidNullHandleExGraph) {
36+
ASSERT_EQ_RESULT(UR_RESULT_ERROR_INVALID_NULL_HANDLE,
37+
urEnqueueGraphExp(queue, nullptr, 0, nullptr, nullptr));
38+
}
39+
40+
TEST_P(urEnqueueGraphExpTest, InvalidEventWaitListArray) {
41+
ASSERT_EQ_RESULT(UR_RESULT_ERROR_INVALID_EVENT_WAIT_LIST,
42+
urEnqueueGraphExp(queue, nullptr, 1, nullptr, nullptr));
43+
}
44+
45+
TEST_P(urEnqueueGraphExpTest, InvalidEventWaitListSize) {
46+
ASSERT_EQ_RESULT(UR_RESULT_ERROR_INVALID_EVENT_WAIT_LIST,
47+
urEnqueueGraphExp(queue, nullptr, 0,
48+
(ur_event_handle_t *)0xC0FFEE, nullptr));
49+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Copyright (C) 2025 Intel Corporation
2+
// Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM
3+
// Exceptions. See LICENSE.TXT
4+
//
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
7+
#include "fixtures.h"
8+
9+
using urGraphCreateExpTest = uur::urGraphSupportedExpTest;
10+
11+
UUR_INSTANTIATE_DEVICE_TEST_SUITE(urGraphCreateExpTest);
12+
13+
TEST_P(urGraphCreateExpTest, Success) {
14+
ur_exp_graph_handle_t graph = nullptr;
15+
ASSERT_SUCCESS(urGraphCreateExp(context, &graph));
16+
ASSERT_SUCCESS(urGraphDestroyExp(graph));
17+
}
18+
19+
TEST_P(urGraphCreateExpTest, InvalidNullHandleContext) {
20+
ur_exp_graph_handle_t graph = nullptr;
21+
ASSERT_EQ_RESULT(UR_RESULT_ERROR_INVALID_NULL_HANDLE,
22+
urGraphCreateExp(nullptr, &graph));
23+
}
24+
25+
TEST_P(urGraphCreateExpTest, InvalidNullHandleGraph) {
26+
ASSERT_EQ_RESULT(UR_RESULT_ERROR_INVALID_NULL_HANDLE,
27+
urGraphCreateExp(context, nullptr));
28+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Copyright (C) 2025 Intel Corporation
2+
// Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM
3+
// Exceptions. See LICENSE.TXT
4+
//
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
7+
#include "fixtures.h"
8+
9+
using urGraphInstantiateGraphExpTest = uur::urGraphExpTest;
10+
11+
UUR_INSTANTIATE_DEVICE_TEST_SUITE(urGraphInstantiateGraphExpTest);
12+
13+
TEST_P(urGraphInstantiateGraphExpTest, InvalidEmptyGraph) {
14+
ur_exp_executable_graph_handle_t exGraph = nullptr;
15+
ASSERT_SUCCESS(urGraphInstantiateGraphExp(graph, &exGraph));
16+
ASSERT_SUCCESS(urGraphExecutableGraphDestroyExp(exGraph));
17+
}
18+
19+
TEST_P(urGraphInstantiateGraphExpTest, InvalidNullHandleGraph) {
20+
ur_exp_executable_graph_handle_t exGraph = nullptr;
21+
ASSERT_EQ_RESULT(UR_RESULT_ERROR_INVALID_NULL_HANDLE,
22+
urGraphInstantiateGraphExp(nullptr, &exGraph));
23+
}
24+
25+
TEST_P(urGraphInstantiateGraphExpTest, InvalidNullHandleExGraph) {
26+
ASSERT_EQ_RESULT(UR_RESULT_ERROR_INVALID_NULL_HANDLE,
27+
urGraphInstantiateGraphExp(graph, nullptr));
28+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Copyright (C) 2025 Intel Corporation
2+
// Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM
3+
// Exceptions. See LICENSE.TXT
4+
//
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
7+
#include "fixtures.h"
8+
9+
using urGraphNonEmptyExpTest = uur::urGraphPopulatedExpTest;
10+
11+
UUR_INSTANTIATE_DEVICE_TEST_SUITE(urGraphNonEmptyExpTest);
12+
13+
TEST_P(urGraphNonEmptyExpTest, SuccessFalse) {
14+
bool isEmpty = false;
15+
ASSERT_SUCCESS(urGraphIsEmptyExp(graph, &isEmpty));
16+
ASSERT_TRUE(isEmpty);
17+
}
18+
19+
using urGraphEmptyExpTest = uur::urGraphExpTest;
20+
21+
UUR_INSTANTIATE_DEVICE_TEST_SUITE(urGraphEmptyExpTest);
22+
23+
TEST_P(urGraphEmptyExpTest, SuccessTrue) {
24+
bool isEmpty = false;
25+
ASSERT_SUCCESS(urGraphIsEmptyExp(graph, &isEmpty));
26+
ASSERT_FALSE(isEmpty);
27+
}
28+
29+
TEST_P(urGraphEmptyExpTest, InvalidNullHandleQueue) {
30+
bool isEmpty = false;
31+
ASSERT_EQ_RESULT(UR_RESULT_ERROR_INVALID_NULL_HANDLE,
32+
urGraphIsEmptyExp(nullptr, &isEmpty));
33+
}
34+
35+
TEST_P(urGraphEmptyExpTest, InvalidNullPtrResult) {
36+
ASSERT_EQ_RESULT(UR_RESULT_ERROR_INVALID_NULL_POINTER,
37+
urGraphIsEmptyExp(graph, nullptr));
38+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright (C) 2025 Intel Corporation
2+
// Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM
3+
// Exceptions. See LICENSE.TXT
4+
//
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
7+
#include "fixtures.h"
8+
9+
using urQueueBeginCaptureIntoGraphExpTest = uur::urGraphExpTest;
10+
11+
UUR_INSTANTIATE_DEVICE_TEST_SUITE(urQueueBeginCaptureIntoGraphExpTest);
12+
13+
TEST_P(urQueueBeginCaptureIntoGraphExpTest, Success) {
14+
ASSERT_SUCCESS(urQueueBeginCaptureIntoGraphExp(queue, graph));
15+
}
16+
17+
TEST_P(urQueueBeginCaptureIntoGraphExpTest, InvalidNullHandleQueue) {
18+
ASSERT_EQ_RESULT(UR_RESULT_ERROR_INVALID_NULL_HANDLE,
19+
urQueueBeginCaptureIntoGraphExp(nullptr, graph));
20+
}
21+
22+
TEST_P(urQueueBeginCaptureIntoGraphExpTest, InvalidNullHandleGraph) {
23+
ASSERT_EQ_RESULT(UR_RESULT_ERROR_INVALID_NULL_HANDLE,
24+
urQueueBeginCaptureIntoGraphExp(queue, nullptr));
25+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Copyright (C) 2025 Intel Corporation
2+
// Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM
3+
// Exceptions. See LICENSE.TXT
4+
//
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
7+
#include "fixtures.h"
8+
9+
using urQueueBeginGraphCaptureExpTest = uur::urGraphExpTest;
10+
11+
UUR_INSTANTIATE_DEVICE_TEST_SUITE(urQueueBeginGraphCaptureExpTest);
12+
13+
TEST_P(urQueueBeginGraphCaptureExpTest, Success) {
14+
ASSERT_SUCCESS(urQueueBeginGraphCaptureExp(queue));
15+
16+
ur_exp_graph_handle_t graph = nullptr;
17+
ASSERT_SUCCESS(urQueueEndGraphCaptureExp(queue, &graph));
18+
ASSERT_SUCCESS(urGraphDestroyExp(graph));
19+
}
20+
21+
TEST_P(urQueueBeginGraphCaptureExpTest, InvalidNullHandleQueue) {
22+
ASSERT_EQ_RESULT(UR_RESULT_ERROR_INVALID_NULL_HANDLE,
23+
urQueueBeginGraphCaptureExp(nullptr));
24+
}

0 commit comments

Comments
 (0)