@@ -95,3 +95,84 @@ TEST_P(urUSMFreeTest, InvalidNullPtrMem) {
9595 ASSERT_EQ_RESULT (UR_RESULT_ERROR_INVALID_NULL_POINTER,
9696 urUSMFree (context, nullptr ));
9797}
98+
99+ // This goal of this test is to ensure urUSMFree blocks and waits for operations
100+ // accessing the given allocation to finish before actually freeing the memory.
101+ struct urUSMFreeDuringExecutionTest : uur::urKernelExecutionTest {
102+ void SetUp () {
103+ program_name = " fill_usm" ;
104+ UUR_RETURN_ON_FATAL_FAILURE (urKernelExecutionTest::SetUp ());
105+ }
106+
107+ void *allocation = nullptr ;
108+ size_t array_size = 256 ;
109+ size_t allocation_size = array_size * sizeof (uint32_t );
110+ uint32_t data = 42 ;
111+ size_t wg_offset = 0 ;
112+ };
113+ UUR_INSTANTIATE_KERNEL_TEST_SUITE_P (urUSMFreeDuringExecutionTest);
114+
115+ TEST_P (urUSMFreeDuringExecutionTest, SuccessHost) {
116+ ur_device_usm_access_capability_flags_t host_usm_flags = 0 ;
117+ ASSERT_SUCCESS (uur::GetDeviceUSMHostSupport (device, host_usm_flags));
118+ if (!(host_usm_flags & UR_DEVICE_USM_ACCESS_CAPABILITY_FLAG_ACCESS)) {
119+ GTEST_SKIP () << " Host USM is not supported." ;
120+ }
121+
122+ ASSERT_SUCCESS (urUSMHostAlloc (context, nullptr , nullptr , allocation_size,
123+ &allocation));
124+ ASSERT_NE (allocation, nullptr );
125+
126+ EXPECT_SUCCESS (urKernelSetArgPointer (kernel, 0 , nullptr , allocation));
127+ EXPECT_SUCCESS (
128+ urKernelSetArgValue (kernel, 1 , sizeof (data), nullptr , &data));
129+ EXPECT_SUCCESS (urEnqueueKernelLaunch (queue, kernel, 1 , &wg_offset,
130+ &array_size, nullptr , 0 , nullptr ,
131+ nullptr ));
132+ ASSERT_SUCCESS (urUSMFree (context, allocation));
133+ ASSERT_SUCCESS (urQueueFinish (queue));
134+ }
135+
136+ TEST_P (urUSMFreeDuringExecutionTest, SuccessDevice) {
137+ ur_device_usm_access_capability_flags_t device_usm_flags = 0 ;
138+ ASSERT_SUCCESS (uur::GetDeviceUSMDeviceSupport (device, device_usm_flags));
139+ if (!(device_usm_flags & UR_DEVICE_USM_ACCESS_CAPABILITY_FLAG_ACCESS)) {
140+ GTEST_SKIP () << " Device USM is not supported." ;
141+ }
142+
143+ ASSERT_SUCCESS (urUSMDeviceAlloc (context, device, nullptr , nullptr ,
144+ allocation_size, &allocation));
145+ ASSERT_NE (allocation, nullptr );
146+
147+ EXPECT_SUCCESS (urKernelSetArgPointer (kernel, 0 , nullptr , allocation));
148+ EXPECT_SUCCESS (
149+ urKernelSetArgValue (kernel, 1 , sizeof (data), nullptr , &data));
150+
151+ EXPECT_SUCCESS (urEnqueueKernelLaunch (queue, kernel, 1 , &wg_offset,
152+ &array_size, nullptr , 0 , nullptr ,
153+ nullptr ));
154+ ASSERT_SUCCESS (urUSMFree (context, allocation));
155+ ASSERT_SUCCESS (urQueueFinish (queue));
156+ }
157+
158+ TEST_P (urUSMFreeDuringExecutionTest, SuccessShared) {
159+ ur_device_usm_access_capability_flags_t shared_usm_flags = 0 ;
160+ ASSERT_SUCCESS (
161+ uur::GetDeviceUSMSingleSharedSupport (device, shared_usm_flags));
162+ if (!(shared_usm_flags & UR_DEVICE_USM_ACCESS_CAPABILITY_FLAG_ACCESS)) {
163+ GTEST_SKIP () << " Shared USM is not supported." ;
164+ }
165+
166+ ASSERT_SUCCESS (urUSMSharedAlloc (context, device, nullptr , nullptr ,
167+ allocation_size, &allocation));
168+ ASSERT_NE (allocation, nullptr );
169+
170+ EXPECT_SUCCESS (urKernelSetArgPointer (kernel, 0 , nullptr , allocation));
171+ EXPECT_SUCCESS (
172+ urKernelSetArgValue (kernel, 1 , sizeof (data), nullptr , &data));
173+ EXPECT_SUCCESS (urEnqueueKernelLaunch (queue, kernel, 1 , &wg_offset,
174+ &array_size, nullptr , 0 , nullptr ,
175+ nullptr ));
176+ ASSERT_SUCCESS (urUSMFree (context, allocation));
177+ ASSERT_SUCCESS (urQueueFinish (queue));
178+ }
0 commit comments