Skip to content
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

Improve type casters #837

Merged
merged 3 commits into from
May 18, 2022
Merged

Improve type casters #837

merged 3 commits into from
May 18, 2022

Conversation

oleksandr-pavlyk
Copy link
Collaborator

Improved efficiency of pybind11 classes and type casters.

Type casters in pybind11 generated with PYBIND11_TYPE_CASTER macro rely on default constructor of C++ type. The default constructed value is then overwritten by load method. C++ types such as sycl::device and sycl::queue do non-trivial amount of work in default constructor. This work was ranking high in certain workloads (such as example/pybind11/onemkl_gemv/sycl_timing_solver.py).

Same applies to auto-generated type-casters for classes dpctl::memory::usm_memory and dpctl::tensor::usm_ndarray.

This PR introduces DPCTL_TYPE_CASTER macro that defines unique_ptr to the C++ type, rather than the type itself. This avoids superfluous call to default constructor altogether.

Instead of redefining pyobject_caster automatically generated for dpctl::tensor::usm_ndarray and dpctl::memory::usm_memory a singleton class dpctl::detail::dpctl_api is added that creates objects used by default constructors of these classes.

  • Have you provided a meaningful PR description?
  • Have you added a test, reproducer or referred to an issue with a reproducer?
  • Have you tested your changes locally for CPU and GPU devices?
  • Have you made sure that new changes do not introduce compiler warnings?
  • If this PR is a work in progress, are you filing the PR as a draft?

@github-actions
Copy link

@coveralls
Copy link
Collaborator

coveralls commented May 16, 2022

Coverage Status

Coverage decreased (-0.008%) to 82.818% when pulling ba50f98 on improve-type-casters into 50be964 on master.

@oleksandr-pavlyk
Copy link
Collaborator Author

On my development Gen9 box this change speeds up the test suite run-time from 85 seconds to 54 seconds.

Now:

======================== 3107 passed, 173 skipped, 1 xfailed in 53.81s ===============================

Before:

====================== 3107 passed, 173 skipped, 1 xfailed in 84.72s (0:01:24) =======================

@oleksandr-pavlyk oleksandr-pavlyk merged commit fbe078e into master May 18, 2022
@oleksandr-pavlyk oleksandr-pavlyk deleted the improve-type-casters branch May 18, 2022 02:27
@github-actions
Copy link

Deleted rendered PR docs from intelpython.github.com/dpctl, latest should be updated shortly. 🤞

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