Skip to content

Commit 769bf81

Browse files
DBDuncankbenzie
authored andcommitted
Add support for timeline semaphores (#17395)
Add support for timeline semaphores on linux and windows for CUDA backend and preliminary support in L0 backend. Update vulkan_interop/sampled_images.cpp to remove redundant wait when using semaphores.
1 parent 04d880d commit 769bf81

File tree

9 files changed

+56
-15
lines changed

9 files changed

+56
-15
lines changed

include/ur_api.h

Lines changed: 8 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

include/ur_print.hpp

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scripts/core/EXP-BINDLESS-IMAGES.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,8 @@ Enums
123123
* ${X}_EXP_EXTERNAL_SEMAPHORE_TYPE_OPAQUE_FD
124124
* ${X}_EXP_EXTERNAL_SEMAPHORE_TYPE_WIN32_NT
125125
* ${X}_EXP_EXTERNAL_SEMAPHORE_TYPE_WIN32_NT_DX12_FENCE
126+
* ${X}_EXP_EXTERNAL_SEMAPHORE_TYPE_TIMELINE_FD
127+
* ${X}_EXP_EXTERNAL_SEMAPHORE_TYPE_TIMELINE_WIN32_NT
126128

127129
* ${x}_function_t
128130
* ${X}_FUNCTION_USM_PITCHED_ALLOC_EXP
@@ -258,6 +260,8 @@ Changelog
258260
| || Added support for DtoD usm pitch copies |
259261
| || Added support for HtoH copies |
260262
+----------+-------------------------------------------------------------+
263+
| 20.0 | Added timeline semaphores for CUDA and L0 backends |
264+
+----------+-------------------------------------------------------------+
261265

262266
Contributors
263267
--------------------------------------------------------------------------------

scripts/core/exp-bindless-images.yml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -207,11 +207,15 @@ class: $xBindlessImages
207207
name: $x_exp_external_semaphore_type_t
208208
etors:
209209
- name: OPAQUE_FD
210-
desc: "Opaque file descriptor"
210+
desc: "Binary semaphore opaque file descriptor"
211211
- name: WIN32_NT
212-
desc: "Win32 NT handle"
212+
desc: "Binary semaphore Win32 NT handle"
213213
- name: WIN32_NT_DX12_FENCE
214-
desc: "Win32 NT DirectX 12 fence handle"
214+
desc: "Fence semaphore Win32 NT DirectX 12 handle"
215+
- name: TIMELINE_FD
216+
desc: "Timeline semaphore opaque file descriptor"
217+
- name: TIMELINE_WIN32_NT
218+
desc: "Timeline semaphore Win32 NT handle"
215219
--- #--------------------------------------------------------------------------
216220
type: struct
217221
desc: "File descriptor"

source/adapters/cuda/image.cpp

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1234,7 +1234,17 @@ UR_APIEXPORT ur_result_t UR_APICALL urBindlessImagesImportExternalSemaphoreExp(
12341234
static_cast<const ur_exp_file_descriptor_t *>(pNext);
12351235

12361236
extSemDesc.handle.fd = FileDescriptor->fd;
1237-
extSemDesc.type = CU_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD;
1237+
switch (semHandleType) {
1238+
case UR_EXP_EXTERNAL_SEMAPHORE_TYPE_OPAQUE_FD:
1239+
extSemDesc.type = CU_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD;
1240+
break;
1241+
case UR_EXP_EXTERNAL_SEMAPHORE_TYPE_TIMELINE_FD:
1242+
extSemDesc.type =
1243+
CU_EXTERNAL_SEMAPHORE_HANDLE_TYPE_TIMELINE_SEMAPHORE_FD;
1244+
break;
1245+
default:
1246+
return UR_RESULT_ERROR_INVALID_VALUE;
1247+
}
12381248
} else if (BaseDesc->stype == UR_STRUCTURE_TYPE_EXP_WIN32_HANDLE) {
12391249
auto Win32Handle = static_cast<const ur_exp_win32_handle_t *>(pNext);
12401250
switch (semHandleType) {
@@ -1244,7 +1254,10 @@ UR_APIEXPORT ur_result_t UR_APICALL urBindlessImagesImportExternalSemaphoreExp(
12441254
case UR_EXP_EXTERNAL_SEMAPHORE_TYPE_WIN32_NT_DX12_FENCE:
12451255
extSemDesc.type = CU_EXTERNAL_SEMAPHORE_HANDLE_TYPE_D3D12_FENCE;
12461256
break;
1247-
case UR_EXP_EXTERNAL_SEMAPHORE_TYPE_OPAQUE_FD:
1257+
case UR_EXP_EXTERNAL_SEMAPHORE_TYPE_TIMELINE_WIN32_NT:
1258+
extSemDesc.type =
1259+
CU_EXTERNAL_SEMAPHORE_HANDLE_TYPE_TIMELINE_SEMAPHORE_WIN32;
1260+
break;
12481261
default:
12491262
return UR_RESULT_ERROR_INVALID_VALUE;
12501263
}

source/adapters/level_zero/image.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -799,7 +799,16 @@ ur_result_t urBindlessImagesImportExternalSemaphoreExp(
799799
static_cast<const ur_exp_file_descriptor_t *>(pNext);
800800
FDExpDesc.fd = FileDescriptor->fd;
801801
SemDesc.pNext = &FDExpDesc;
802-
SemDesc.flags = ZE_EXTERNAL_SEMAPHORE_EXP_FLAGS_OPAQUE_FD;
802+
switch (semHandleType) {
803+
case UR_EXP_EXTERNAL_SEMAPHORE_TYPE_OPAQUE_FD:
804+
SemDesc.flags = ZE_EXTERNAL_SEMAPHORE_EXP_FLAGS_OPAQUE_FD;
805+
break;
806+
case UR_EXP_EXTERNAL_SEMAPHORE_TYPE_TIMELINE_FD:
807+
SemDesc.flags = ZE_EXTERNAL_SEMAPHORE_EXP_FLAGS_TIMELINE_SEMAPHORE_FD;
808+
break;
809+
default:
810+
return UR_RESULT_ERROR_INVALID_VALUE;
811+
}
803812
} else if (BaseDesc->stype == UR_STRUCTURE_TYPE_EXP_WIN32_HANDLE) {
804813
SemDesc.pNext = &Win32ExpDesc;
805814
auto Win32Handle = static_cast<const ur_exp_win32_handle_t *>(pNext);
@@ -810,8 +819,9 @@ ur_result_t urBindlessImagesImportExternalSemaphoreExp(
810819
case UR_EXP_EXTERNAL_SEMAPHORE_TYPE_WIN32_NT_DX12_FENCE:
811820
SemDesc.flags = ZE_EXTERNAL_SEMAPHORE_EXP_FLAGS_D3D12_FENCE;
812821
break;
813-
case UR_EXP_EXTERNAL_SEMAPHORE_TYPE_OPAQUE_FD:
814-
SemDesc.flags = ZE_EXTERNAL_SEMAPHORE_EXP_FLAGS_OPAQUE_FD;
822+
case UR_EXP_EXTERNAL_SEMAPHORE_TYPE_TIMELINE_WIN32_NT:
823+
SemDesc.flags =
824+
ZE_EXTERNAL_SEMAPHORE_EXP_FLAGS_TIMELINE_SEMAPHORE_WIN32;
815825
break;
816826
default:
817827
return UR_RESULT_ERROR_INVALID_VALUE;

source/loader/layers/validation/ur_valddi.cpp

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

source/loader/ur_libapi.cpp

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

source/ur_api.cpp

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)