Skip to content

Commit 71cfb7e

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

File tree

10 files changed

+371
-0
lines changed

10 files changed

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

0 commit comments

Comments
 (0)