Skip to content

Commit 1ae9715

Browse files
committed
Review comments #1
Signed-off-by: Sergey V Maslov <[email protected]>
1 parent 48d6393 commit 1ae9715

File tree

3 files changed

+33
-17
lines changed

3 files changed

+33
-17
lines changed

sycl/doc/extensions/LevelZeroBackend/LevelZeroBackend.md

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ a SYCL object that encapsulates a corresponding Level-Zero object:
8787
|-------------|:------------|
8888
|``` make<platform>(ze_driver_handle_t);```|Constructs a SYCL platform instance from a Level-Zero ```ze_driver_handle_t```.|
8989
|``` make<device>(const platform &, ze_device_handle_t);```|Constructs a SYCL device instance from a Level-Zero ```ze_device_handle_t```. The platform argument gives a SYCL platform, encapsulating a Level-Zero driver supporting the passed Level-Zero device.|
90-
|``` make<context>(const vector_class<device> &, ze_context_handle_t);```| Constructs a SYCL context instance from a Level-Zero ```ze_context_handle_t```. The context is created against the devices passed in. There must be at least one device given and all the devices must be from the same SYCL platform and thus from the same Level-Zero driver.|
90+
|``` make<context>(const vector_class<device> &, ze_context_handle_t, ownership = transfer);```| Constructs a SYCL context instance from a Level-Zero ```ze_context_handle_t```. The context is created against the devices passed in. There must be at least one device given and all the devices must be from the same SYCL platform and thus from the same Level-Zero driver. The ```ownership``` argument specifies if SYCL RT should take ownership of the passed native handle. The default behavior is to transfer the ownership to SYCL RT. See section 4.4 for details.|
9191
|``` make<queue>(const context &, ze_command_queue_handle_t);```| Constructs a SYCL queue instance from a Level-Zero ```ze_command_queue_handle_t```. The context argument must be a valid SYCL context encapsulating a Level-Zero context. The queue is attached to the first device in the passed SYCL context.|
9292
|``` make<program>(const context &, ze_module_handle_t);```| Constructs a SYCL program instance from a Level-Zero ```ze_module_handle_t```. The context argument must be a valid SYCL context encapsulating a Level-Zero context. The Level-Zero module must be fully linked (i.e. not require further linking through [```zeModuleDynamicLink```](https://spec.oneapi.com/level-zero/latest/core/api.html?highlight=zemoduledynamiclink#_CPPv419zeModuleDynamicLink8uint32_tP18ze_module_handle_tP28ze_module_build_log_handle_t)), and thus the SYCL program is created in the "linked" state.|
9393
@@ -96,23 +96,37 @@ NOTE: We shall consider adding other interoperability as needed, if possible.
9696
### 4.4 Level-Zero handles' ownership and thread-safety
9797
9898
The Level-Zero runtime doesn't do reference-counting of its objects, so it is crucial to adhere to these
99-
practices of how Level-Zero handles are manged.
99+
practices of how Level-Zero handles are manged. By default, the ownership us transferred to SYCL RT, but
100+
some interoparability API supports overriding this behavior and keep the ownership in the application.
101+
Use this enumeration for explicit specification of the ownership:
102+
``` C++
103+
enum ownership { transfer, keep };
104+
```
100105
101-
#### 4.4.1 SYCL runtime takes ownership
106+
#### 4.4.1 SYCL runtime takes ownership (default)
102107
103108
Whenever the application creates a SYCL object from the corresponding Level-Zero handle via one of the ```make<T>()``` functions,
104-
the SYCL runtime takes ownership of the Level-Zero handle. The application must not use the Level-Zero handle after
105-
the last host copy of the SYCL object is destroyed (as described in the core SYCL specification under
106-
"Common reference semantics"), and the application must not destroy the Level-Zero handle itself.
109+
the SYCL runtime takes ownership of the Level-Zero handle, if no explicit ```ownership::keep``` was specified.
110+
The application must not use the Level-Zero handle after the last host copy of the SYCL object is destroyed (
111+
as described in the core SYCL specification under "Common reference semantics"), and the application must not
112+
destroy the Level-Zero handle itself.
107113

108-
#### 4.4.2 SYCL runtime assumes ownership
114+
#### 4.4.2 SYCL runtime assumes ownership (default)
109115

110116
The application may call the ```get_native<T>()``` member function of a SYCL object to retrieve the underlying Level-Zero handle,
111-
however, the SYCL runtime continues to retain ownership of this handle. The application must not use this handle after
112-
the last host copy of the SYCL object is destroyed (as described in the core SYCL specification under
113-
"Common reference semantics"), and the application must not destroy the Level-Zero handle.
117+
however, the SYCL runtime continues to retain ownership of this handle, unless SYCL object was created with interoperability API that asked
118+
to keep the ownership by the application with ```ownership::keep```. The application must not use this handle after the last host copy of
119+
the SYCL object is destroyed (as described in the core SYCL specification under "Common reference semantics"), and the application must
120+
not destroy the Level-Zero handle.
121+
122+
#### 4.4.3 Application keeps ownership (explicit)
123+
124+
If SYCL object is created with an interoperability API explicitly asking to keep the native handle ownership in the application with
125+
```ownership::keep``` then SYCL RT does not take the ownership and will not destroy the Level-Zero handle at the destruction of the SYCL object.
126+
Application is responsible for destroying the native handle when it no longer needs it, but not earlier than the SYCL object created with that
127+
handle is EOL.
114128

115-
#### 4.4.3 Considerations for multi-threaded environment
129+
#### 4.4.4 Considerations for multi-threaded environment
116130

117131
The Level-Zero API is not thread-safe, refer to <https://spec.oneapi.com/level-zero/latest/core/INTRO.html#multithreading-and-concurrency>.
118132
Applications must make sure that the Level-Zero handles themselves aren't used simultaneously from different threads.
@@ -123,4 +137,5 @@ the application should not attempt further direct use of those handles.
123137
|Rev|Date|Author|Changes|
124138
|-------------|:------------|:------------|:------------|
125139
|1|2021-01-26|Sergey Maslov|Initial public working draft
140+
|2|2021-02-21|Sergey Maslov|Introduced explicit ownership for context
126141

sycl/include/CL/sycl/detail/pi.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,10 @@
3434
// pi_device_binary_property_set PropertySetsBegin;
3535
// pi_device_binary_property_set PropertySetsEnd;
3636
// 2. A number of types needed to define pi_device_binary_property_set added.
37+
// 3. Added new ownership argument to piextContextCreateWithNativeHandle.
3738
//
38-
#define _PI_H_VERSION_MAJOR 2
39-
#define _PI_H_VERSION_MINOR 3
39+
#define _PI_H_VERSION_MAJOR 3
40+
#define _PI_H_VERSION_MINOR 4
4041

4142
#define _PI_STRING_HELPER(a) #a
4243
#define _PI_CONCAT(a, b) _PI_STRING_HELPER(a.b)

sycl/test/abi/sycl_symbols_linux.dump

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3592,7 +3592,7 @@ _ZN2cl10__host_std9u_sub_satEmm
35923592
_ZN2cl10__host_std9u_sub_satEtt
35933593
_ZN2cl4sycl10level_zero10make_queueERKNS0_7contextEm
35943594
_ZN2cl4sycl10level_zero11make_deviceERKNS0_8platformEm
3595-
_ZN2cl4sycl10level_zero12make_contextERKSt6vectorINS0_6deviceESaIS3_EEm
3595+
_ZN2cl4sycl10level_zero12make_contextERKSt6vectorINS0_6deviceESaIS3_EEmb
35963596
_ZN2cl4sycl10level_zero12make_programERKNS0_7contextEm
35973597
_ZN2cl4sycl10level_zero13make_platformEm
35983598
_ZN2cl4sycl11malloc_hostEmRKNS0_5queueE
@@ -3616,6 +3616,8 @@ _ZN2cl4sycl20aligned_alloc_sharedEmmRKNS0_5queueE
36163616
_ZN2cl4sycl20aligned_alloc_sharedEmmRKNS0_6deviceERKNS0_7contextE
36173617
_ZN2cl4sycl4freeEPvRKNS0_5queueE
36183618
_ZN2cl4sycl4freeEPvRKNS0_7contextE
3619+
_ZN2cl4sycl5INTEL15online_compilerILNS1_15source_languageE0EE7compileIJSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaISC_EEEEES6_IhSaIhEERKSC_DpRKT_
3620+
_ZN2cl4sycl5INTEL15online_compilerILNS1_15source_languageE1EE7compileIJSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaISC_EEEEES6_IhSaIhEERKSC_DpRKT_
36193621
_ZN2cl4sycl5event13get_wait_listEv
36203622
_ZN2cl4sycl5event14wait_and_throwERKSt6vectorIS1_SaIS1_EE
36213623
_ZN2cl4sycl5event14wait_and_throwEv
@@ -3627,8 +3629,6 @@ _ZN2cl4sycl5eventC1Ev
36273629
_ZN2cl4sycl5eventC2EP9_cl_eventRKNS0_7contextE
36283630
_ZN2cl4sycl5eventC2ESt10shared_ptrINS0_6detail10event_implEE
36293631
_ZN2cl4sycl5eventC2Ev
3630-
_ZN2cl4sycl5INTEL15online_compilerILNS1_15source_languageE0EE7compileIJSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaISC_EEEEES6_IhSaIhEERKSC_DpRKT_
3631-
_ZN2cl4sycl5INTEL15online_compilerILNS1_15source_languageE1EE7compileIJSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaISC_EEEEES6_IhSaIhEERKSC_DpRKT_
36323632
_ZN2cl4sycl5queue10mem_adviseEPKvm14_pi_mem_advice
36333633
_ZN2cl4sycl5queue10wait_proxyERKNS0_6detail13code_locationE
36343634
_ZN2cl4sycl5queue11submit_implESt8functionIFvRNS0_7handlerEEERKNS0_6detail13code_locationE
@@ -3964,6 +3964,7 @@ _ZNK2cl4sycl6device8get_infoILNS0_4info6deviceE16785EEENS3_12param_traitsIS4_XT_
39643964
_ZNK2cl4sycl6device8get_infoILNS0_4info6deviceE16786EEENS3_12param_traitsIS4_XT_EE11return_typeEv
39653965
_ZNK2cl4sycl6device8get_infoILNS0_4info6deviceE16787EEENS3_12param_traitsIS4_XT_EE11return_typeEv
39663966
_ZNK2cl4sycl6device8get_infoILNS0_4info6deviceE16788EEENS3_12param_traitsIS4_XT_EE11return_typeEv
3967+
_ZNK2cl4sycl6device8get_infoILNS0_4info6deviceE16915EEENS3_12param_traitsIS4_XT_EE11return_typeEv
39673968
_ZNK2cl4sycl6device8get_infoILNS0_4info6deviceE4096EEENS3_12param_traitsIS4_XT_EE11return_typeEv
39683969
_ZNK2cl4sycl6device8get_infoILNS0_4info6deviceE4097EEENS3_12param_traitsIS4_XT_EE11return_typeEv
39693970
_ZNK2cl4sycl6device8get_infoILNS0_4info6deviceE4098EEENS3_12param_traitsIS4_XT_EE11return_typeEv
@@ -4039,7 +4040,6 @@ _ZNK2cl4sycl6device8get_infoILNS0_4info6deviceE4168EEENS3_12param_traitsIS4_XT_E
40394040
_ZNK2cl4sycl6device8get_infoILNS0_4info6deviceE4169EEENS3_12param_traitsIS4_XT_EE11return_typeEv
40404041
_ZNK2cl4sycl6device8get_infoILNS0_4info6deviceE4188EEENS3_12param_traitsIS4_XT_EE11return_typeEv
40414042
_ZNK2cl4sycl6device8get_infoILNS0_4info6deviceE4189EEENS3_12param_traitsIS4_XT_EE11return_typeEv
4042-
_ZNK2cl4sycl6device8get_infoILNS0_4info6deviceE16915EEENS3_12param_traitsIS4_XT_EE11return_typeEv
40434043
_ZNK2cl4sycl6device8get_infoILNS0_4info6deviceE65568EEENS3_12param_traitsIS4_XT_EE11return_typeEv
40444044
_ZNK2cl4sycl6device8get_infoILNS0_4info6deviceE65569EEENS3_12param_traitsIS4_XT_EE11return_typeEv
40454045
_ZNK2cl4sycl6device8get_infoILNS0_4info6deviceE65570EEENS3_12param_traitsIS4_XT_EE11return_typeEv

0 commit comments

Comments
 (0)