Skip to content

[SYCL] Add Level-Zero interop with specification of ownership for kernel and kernel_bundle. #4542

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from

Conversation

rbegam
Copy link
Contributor

@rbegam rbegam commented Sep 10, 2021

The L0 backend interop functions take the ownership of the passed L0 handles.
This is problematic for some cases as the users can not use the original handle
when they go out of scope and destroyed. This PR provides a way for users of
SYCL - L0 interop to retain the ownership of the L0 handles for the kernel
and kernel_bundle.

Signed-off-by: rehana begam rehana.begam@intel.com

kernel_bundle.

The L0 backend interop functions take the ownership of the passed L0 handles.
This is problematic for some cases as the users can not use the original handle
when they go out of scope and destroyed. This PR provides a way for users of
SYCL - L0 interop to retain the ownership of the L0 handles for the kernel
and kernel_bundle.

Signed-off-by: rehana begam <rehana.begam@intel.com>
@rbegam rbegam requested review from kbobrovs, smaslov-intel and a team as code owners September 10, 2021 19:08
@rbegam rbegam changed the title [SYCL] Add Level-Zero interop with specification of ownership for kernel_bundle. [SYCL] Add Level-Zero interop with specification of ownership for kernel and kernel_bundle. Sep 10, 2021
Signed-off-by: rehana begam <rehana.begam@intel.com>
Signed-off-by: rehana begam <rehana.begam@intel.com>
@@ -90,7 +90,8 @@ a SYCL object that encapsulates a corresponding Level-Zero object:
|``` 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 the SYCL runtime should take ownership of the passed native handle. The default behavior is to transfer the ownership to the SYCL runtime. See section 4.4 for details.|
|``` make<queue>(const context &, ze_command_queue_handle_t, ownership = transfer);```| 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. The ```ownership``` argument specifies if the SYCL runtime should take ownership of the passed native handle. The default behavior is to transfer the ownership to the SYCL runtime. See section 4.4 for details.|
|``` make<event>(const context &, ze_event_handle_t, ownership = transfer);```| Constructs a SYCL event instance from a Level-Zero ```ze_event_handle_t```. The context argument must be a valid SYCL context encapsulating a Level-Zero context. The Level-Zero event should be allocated from an event pool created in the same context. The ```ownership``` argument specifies if the SYCL runtime should take ownership of the passed native handle. The default behavior is to transfer the ownership to the SYCL runtime. See section 4.4 for details.|
|``` 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.|
|``` make<kernel>(const context &, ze_kernel_handle_t, ownership = transfer);```| Constructs a SYCL kernel from a Level-Zero ```ze_kernel_handle_t```. The context argument must be a valid SYCL context encapsulating a Level-Zero context. The ```ownership``` argument specifies if the SYCL runtime should take ownership of the passed native handle. The default behavior is to transfer the ownership to the SYCL runtime. See section 4.4 for details.|
|``` make<kernel_bundle>(const context &, ze_module_handle_t, ownership = transfer);```| 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. The ```ownership``` argument specifies if the SYCL runtime should take ownership of the passed native handle. The default behavior is to transfer the ownership to the SYCL runtime. See section 4.4 for details.|
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have several comments about these APIs:

  • It seems like make<kernel>() might also need a ze_module_handle_t parameter. There is a SYCL API kernel::get_kernel_bundle() which returns the kernel bundle that contains a kernel. How will you implement this if you don't know the underlying Level Zero module handle?

  • Both APIs should be more precise about the requirements of the context parameter. For make<kernel_bundle>(), I think it is required that the ze_module_handle_t be created from the same context. Likewise, for make<kernel>(), I think it is required that the ze_kernel_handle_t come from a module that is created from that context.

  • I think we probably need to document another requirement for make<kernel_bundle>() when ownership is transfer. Since the runtime takes ownership of the L0 handle in this case, I think the application must also promise not to have any outstanding ze_kernel_handle_t handles to the underlying ze_module_handle_t. Otherwise, the runtime won't be able to deallocate that ze_module_handle_t.

  • The prototype for make<kernel_bundle> isn't correct because kernel_bundle is a template type. Instead, I think you want to say make<kernel_bundle<bundle_state::executable>>. You can then remove the wording in the description "and thus the SYCL program is created in the "linked" state" because this is clear from the prototype.

  • The wording for make<kernel_bundle> should be updated: "Constructs a SYCL program instance". Instead say "Construct a SYCL kernel bundle instance".

I also have a general word of caution about this API. We made a decision for the last release that this document should describe the existing API even thought it does not conform to the SYCL 2020 spec, with the understanding that we would update the extension document and the API implementation to conform "soon". We should do that sooner, rather than later. All of these APIs will end up getting deprecated because none of them conform to the spec, so it would be better to migrate to a conformant API before adding too many more additions. What do you think @smaslov-intel ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My recent commit #4512 makes all of the current Level-Zero interop following SYCL-2020 and deprecates prior functions. Update of https://github.com/intel/llvm/blob/sycl/sycl/doc/extensions/LevelZeroBackend/LevelZeroBackend.md is WIP. Further additions like in this PR should follow SYCL-2020 from the beginning.

@smaslov-intel
Copy link
Contributor

Continued in #4576

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants