Skip to content

Remove workarounds to make device equality work. #338

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

Merged
merged 1 commit into from
Mar 31, 2021

Conversation

diptorupd
Copy link
Contributor

@diptorupd diptorupd commented Mar 28, 2021

  • dpcpp 2021.2 fixed device equality in the dpcpp runtime and we can
    now remove several workarounds in dpctl:

    • DPCTLDeviceMgr_GetDeviceAndContextPair is now renamed as
      DPCTLDeviceMgr_GetCachedContext and only returns a
      DPCTLSyclContextRef instead of a pair of DPCTLSyclContextRef
      and DPCTLSyclDeviceRef.
    • Remove the DPCTLDeviceMgr_AreEq function and related internal
      helper functions for hashing SYCL devices.
    • Remove DeviceWrapper class inside dpctl_sycl_device_manager.cpp.
    • Remove DPCTL_DeviceAndContextPair type form C API.
  • Make equivalent changes to the Python API.

@diptorupd diptorupd added this to the 0.7.0 milestone Mar 28, 2021
@diptorupd
Copy link
Contributor Author

@oleksandr-pavlyk dpcpp 2021.2 has the device equality fixes that makes my workaround redundant. This PR removed the DPCTL_DeviceAndContextPair. However, now we have a hard dependency on dpcpp version 2021.2 as anything lower will cause things to break. I have another PR coming up where I add a way to specify the dpcpp version requirement in the CMakeList.txt.

@diptorupd diptorupd mentioned this pull request Mar 28, 2021
@diptorupd diptorupd force-pushed the device_cache_changes branch 2 times, most recently from a502879 to 7febae7 Compare March 28, 2021 16:08
  - dpcpp 2021.2 fixed device equality in the dpcpp runtime and we can
    now remove several workarounds in dpctl:

    - DPCTLDeviceMgr_GetDeviceAndContextPair is now renamed as
      DPCTLDeviceMgr_GetCachedContext and only returns a
      DPCTLSyclContextRef instead of a pair of DPCTLSyclContextRef
      and DPCTLSyclDeviceRef.
    - Remove the DPCTLDeviceMgr_AreEq function and related internal
      helper functions for hashing SYCL devices.
    - Remove DeviceWrapper class inside dpctl_sycl_device_manager.cpp.
    - Remove DPCTL_DeviceAndContextPair type form C API.

  - Make equivalent changes to the Python API.
@diptorupd diptorupd force-pushed the device_cache_changes branch from 7febae7 to 6da77c9 Compare March 28, 2021 16:39
if (dev_ctx.CRef is NULL) or (dev_ctx.DRef is NULL):
CRef = DPCTLDeviceMgr_GetCachedContext(DRef)
if (CRef is NULL):
DPCTLDevice_Delete(DRef)
Copy link
Contributor

Choose a reason for hiding this comment

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

DRef is the input argument. We should not be deleting it.

Copy link
Contributor

Choose a reason for hiding this comment

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

If the argument device is a sub-device the look-up will fail. I thought we discussed that it would be better to create a new one instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

_init_queue_from_DPCTLSyclDeviceRef is returning an error code if the context look up fails. I assume the logic to handle creation of a context for sub-devices is not yet implemented? Do your upcoming changes to SyclContext have that change?

As for freeing DRef, in the current code it does not cause an issue. Does it? Are you saying from a design style perspective we should let caller free the object?

Since, _init_queue_from_DPCTLSyclDeviceRef is an internal helper that is invoked only by other internal helpers: _init_queue_from_filter_string, _init_queue_from_device, and _init_queue_default, freeing the DRef in _init_queue_from_DPCTLSyclDeviceRef when we know queue creation failed is fine IMO. But, I can change the code to free it in the callers on returning from _init_queue_from_DPCTLSyclDeviceRef at the cost of adding a check on the return code. Do note that I have a copy in _init_queue_from_device, the only place where deleting the DRef can have an external side-effect.

Copy link
Contributor Author

@diptorupd diptorupd Mar 29, 2021

Choose a reason for hiding this comment

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

As for freeing DRef, in the current code it does not cause an issue. Does it? Are you saying from a design style perspective we should let caller free the object?

I see the issue now. DRef will leak when queue creation succeeded. I will fix that.
Nope, still do not see it. If queue creation succeeds then the DRef is stored in the SyclDevice member of the queue and freed at that time.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

_init_queue_from_DPCTLSyclDeviceRef is returning an error code if the context look up fails. I assume the logic to handle creation of a context for sub-devices is not yet implemented? Do your upcoming changes to SyclContext have that change?

Ok #334 has the changes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@oleksandr-pavlyk in _init_queue_from_device we are taking the DRef from the SyclDevice argument and storing it in the SyclQueue if queue creation succeeded. I think we need a DPCTLDevice_Copy as I have done here. What happens when the SyclDevice is deleted thus deallocating the DPCTLSyclDeviceRef?

Copy link
Contributor

@oleksandr-pavlyk oleksandr-pavlyk left a comment

Choose a reason for hiding this comment

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

The change in memory management in Cython code is not good, and best be reverted.

@oleksandr-pavlyk
Copy link
Contributor

The change in memory management in Cython code is not good, and best be reverted.

The changes implement convention that most _init_* functions consuming an opaque reference would delete it. Callers need to call pass a copy if they intend to keep the object alive.

@diptorupd diptorupd merged commit 82ea16d into IntelPython:master Mar 31, 2021
@diptorupd diptorupd deleted the device_cache_changes branch March 31, 2021 03:20
diptorupd pushed a commit that referenced this pull request Apr 2, 2021
- dpcpp 2021.2 fixed device equality in the dpcpp runtime and we can
    now remove several workarounds in dpctl:

    - DPCTLDeviceMgr_GetDeviceAndContextPair is now renamed as
      DPCTLDeviceMgr_GetCachedContext and only returns a
      DPCTLSyclContextRef instead of a pair of DPCTLSyclContextRef
      and DPCTLSyclDeviceRef.
    - Remove the DPCTLDeviceMgr_AreEq function and related internal
      helper functions for hashing SYCL devices.
    - Remove DeviceWrapper class inside dpctl_sycl_device_manager.cpp.
    - Remove DPCTL_DeviceAndContextPair type form C API.

  - Make equivalent changes to the Python API.
diptorupd pushed a commit that referenced this pull request Apr 2, 2021
- dpcpp 2021.2 fixed device equality in the dpcpp runtime and we can
    now remove several workarounds in dpctl:

    - DPCTLDeviceMgr_GetDeviceAndContextPair is now renamed as
      DPCTLDeviceMgr_GetCachedContext and only returns a
      DPCTLSyclContextRef instead of a pair of DPCTLSyclContextRef
      and DPCTLSyclDeviceRef.
    - Remove the DPCTLDeviceMgr_AreEq function and related internal
      helper functions for hashing SYCL devices.
    - Remove DeviceWrapper class inside dpctl_sycl_device_manager.cpp.
    - Remove DPCTL_DeviceAndContextPair type form C API.

  - Make equivalent changes to the Python API.
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.

2 participants