Skip to content

Commit dc7597c

Browse files
committed
Clarify spec around isNativeHandleOwned.
1 parent 71a5eab commit dc7597c

14 files changed

+100
-89
lines changed

scripts/core/PROG.rst

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,3 +340,39 @@ through ${x}_usm_desc_t structure. Allocations that specify different pool handl
340340
isolated and not reside on the same page. Memory pool is subject to limits specified during pool creation.
341341

342342
Even if no ${x}_usm_pool_handle_t is provided to an allocation function, each adapter may still perform memory pooling.
343+
344+
Native Handles
345+
==============
346+
347+
In addition to the regular object creation APIs, ${X} objects can be
348+
constructed with handles obtained directly from an adapter's associated
349+
backend. This is achieved by casting the backend handle to a
350+
${x}_native_handle_t and passing it to the relevant ``CreateWithNativeHandle``
351+
entry point.
352+
353+
354+
.. note::
355+
Not all backends have a 1:1 equivalent for every ${X} handle type, as such
356+
any ``CreateWithNativeHandle`` or ``GetNativeHandle`` entry point *may* fail
357+
with the error code ${X}_RESULT_ERROR_UNSUPPORTED_FEATURE for a given
358+
adapter.
359+
360+
Native Handle Ownership
361+
-----------------------
362+
363+
By default a ${X} object constructed from a native handle doesn't own the
364+
native handle, it is guaranteed not to modify the native handle's reference
365+
count or otherwise cause its resources to be released. A ${X} object that
366+
doesn't own its associated native handle **must** be destroyed before the
367+
native handle is.
368+
369+
Ownership of the native handle can be tranferred to the ${X} object by passing
370+
``isNativeHandleOwned = true`` in the native properties struct when calling the
371+
``CreateWithNativeHandle`` entry point. A ${X} object that owns a native handle
372+
will attempt to release the native resources associated with that handle on
373+
destruction. The same native handle **must not** have its ownership transferred
374+
to more than one ${X} object.
375+
376+
Ownership of a native handle obtained from a ${X} object via a
377+
``GetNativeHandle`` entry point **must not** be transferred to a new ${X}
378+
object.

scripts/core/context.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -209,9 +209,9 @@ members:
209209
- type: bool
210210
name: isNativeHandleOwned
211211
desc: |
212-
[in] Indicates UR owns the native handle or if it came from an interoperability
213-
operation in the application that asked to not transfer the ownership to
214-
the unified-runtime.
212+
[in] If true then ownership of the native handle is tranferred to
213+
the resultant object. This means the object will be responsible for
214+
releasing the native resources at the end of its lifetime.
215215
--- #--------------------------------------------------------------------------
216216
type: function
217217
desc: "Create runtime context object from native context handle."

scripts/core/device.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -803,10 +803,10 @@ base: $x_base_properties_t
803803
members:
804804
- type: bool
805805
name: isNativeHandleOwned
806-
desc: >
807-
[in] Indicates UR owns the native handle or if it came from an
808-
interoperability operation in the application that asked to not
809-
transfer the ownership to the unified-runtime.
806+
desc: |
807+
[in] If true then ownership of the native handle is tranferred to
808+
the resultant object. This means the object will be responsible for
809+
releasing the native resources at the end of its lifetime.
810810
--- #--------------------------------------------------------------------------
811811
type: function
812812
desc: "Create runtime device object from native device handle."

scripts/core/event.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -289,9 +289,9 @@ members:
289289
- type: bool
290290
name: isNativeHandleOwned
291291
desc: |
292-
[in] Indicates UR owns the native handle or if it came from an interoperability
293-
operation in the application that asked to not transfer the ownership to
294-
the unified-runtime.
292+
[in] If true then ownership of the native handle is tranferred to
293+
the resultant object. This means the object will be responsible for
294+
releasing the native resources at the end of its lifetime.
295295
--- #--------------------------------------------------------------------------
296296
type: function
297297
desc: "Create runtime event object from native event handle."

scripts/core/kernel.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -513,9 +513,9 @@ members:
513513
- type: bool
514514
name: isNativeHandleOwned
515515
desc: |
516-
[in] Indicates UR owns the native handle or if it came from an interoperability
517-
operation in the application that asked to not transfer the ownership to
518-
the unified-runtime.
516+
[in] If true then ownership of the native handle is tranferred to
517+
the resultant object. This means the object will be responsible for
518+
releasing the native resources at the end of its lifetime.
519519
--- #--------------------------------------------------------------------------
520520
type: function
521521
desc: "Create runtime kernel object from native kernel handle."

scripts/core/memory.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -474,10 +474,10 @@ base: $x_base_properties_t
474474
members:
475475
- type: bool
476476
name: isNativeHandleOwned
477-
desc: >
478-
[in] Indicates UR owns the native handle or if it came from an
479-
interoperability operation in the application that asked to not
480-
transfer the ownership to the unified-runtime.
477+
desc: |
478+
[in] If true then ownership of the native handle is tranferred to
479+
the resultant object. This means the object will be responsible for
480+
releasing the native resources at the end of its lifetime.
481481
--- #--------------------------------------------------------------------------
482482
type: function
483483
desc: "Create runtime buffer memory object from native memory handle."

scripts/core/platform.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -202,10 +202,10 @@ base: $x_base_properties_t
202202
members:
203203
- type: bool
204204
name: isNativeHandleOwned
205-
desc: >
206-
[in] Indicates UR owns the native handle or if it came from an
207-
interoperability operation in the application that asked to not
208-
transfer the ownership to the unified-runtime.
205+
desc: |
206+
[in] If true then ownership of the native handle is tranferred to
207+
the resultant object. This means the object will be responsible for
208+
releasing the native resources at the end of its lifetime.
209209
--- #--------------------------------------------------------------------------
210210
type: function
211211
desc: "Create runtime platform object from native platform handle."

scripts/core/program.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -584,10 +584,10 @@ base: $x_base_properties_t
584584
members:
585585
- type: bool
586586
name: isNativeHandleOwned
587-
desc: >
588-
[in] Indicates UR owns the native handle or if it came from an
589-
interoperability operation in the application that asked to not
590-
transfer the ownership to the unified-runtime.
587+
desc: |
588+
[in] If true then ownership of the native handle is tranferred to
589+
the resultant object. This means the object will be responsible for
590+
releasing the native resources at the end of its lifetime.
591591
--- #--------------------------------------------------------------------------
592592
type: function
593593
desc: "Create runtime program object from native program handle."

scripts/core/queue.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -262,9 +262,9 @@ members:
262262
- type: bool
263263
name: isNativeHandleOwned
264264
desc: |
265-
[in] Indicates UR owns the native handle or if it came from an interoperability
266-
operation in the application that asked to not transfer the ownership to
267-
the unified-runtime.
265+
[in] If true then ownership of the native handle is tranferred to
266+
the resultant object. This means the object will be responsible for
267+
releasing the native resources at the end of its lifetime.
268268
--- #--------------------------------------------------------------------------
269269
type: function
270270
desc: "Create runtime queue object from native queue handle."

scripts/core/sampler.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -206,10 +206,10 @@ base: $x_base_properties_t
206206
members:
207207
- type: bool
208208
name: isNativeHandleOwned
209-
desc: >
210-
[in] Indicates UR owns the native handle or if it came from an
211-
interoperability operation in the application that asked to not
212-
transfer the ownership to the unified-runtime.
209+
desc: |
210+
[in] If true then ownership of the native handle is tranferred to
211+
the resultant object. This means the object will be responsible for
212+
releasing the native resources at the end of its lifetime.
213213
--- #--------------------------------------------------------------------------
214214
type: function
215215
desc: "Create runtime sampler object from native sampler handle."

0 commit comments

Comments
 (0)