Skip to content

Improve type casters#837

Merged
oleksandr-pavlyk merged 3 commits intomasterfrom
improve-type-casters
May 18, 2022
Merged

Improve type casters#837
oleksandr-pavlyk merged 3 commits intomasterfrom
improve-type-casters

Conversation

@oleksandr-pavlyk
Copy link
Copy Markdown
Contributor

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
Copy Markdown

@coveralls
Copy link
Copy Markdown
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
Copy Markdown
Contributor 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
Copy Markdown

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