Skip to content

Updated pybind11 from 2.9.2 to 2.10.0 #874

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 3 commits into from
Aug 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ include(FetchContent)

FetchContent_Declare(
pybind11
URL https://github.com/pybind/pybind11/archive/refs/tags/v2.9.2.tar.gz
URL_HASH SHA256=6bd528c4dbe2276635dc787b6b1f2e5316cf6b49ee3e150264e455a0d68d19c1
URL https://github.com/pybind/pybind11/archive/refs/tags/v2.10.0.tar.gz
URL_HASH SHA256=eacf582fa8f696227988d08cfc46121770823839fe9e301a20fbce67e7cd70ec
)
FetchContent_MakeAvailable(pybind11)

Expand Down
103 changes: 10 additions & 93 deletions dpctl/apis/include/dpctl4pybind11.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -305,55 +305,13 @@ namespace memory
class usm_memory : public py::object
{
public:
// Use macro once Pybind11 2.9.3 is released instead of code bewteen
// START_TOKEN and END_TOKEN
/*
PYBIND11_OBJECT_CVT(
usm_memory,
py::object,
[](PyObject *o) -> bool{ return PyObject_TypeCheck(o, &Py_MemoryType)
!= 0;},
[](PyObject *o) -> PyObject* { return as_usm_memory(o); }
)
*/
// START_TOKEN

// these constructors do not validate, but since borrowed_t and stolen_t are
// protected struct members of the object, they can only be called
// internally.
usm_memory(py::handle h, borrowed_t) : py::object(h, borrowed_t{}) {}
usm_memory(py::handle h, stolen_t) : py::object(h, stolen_t{}) {}

static bool check_(py::handle h)
{
return h.ptr() != nullptr &&
PyObject_TypeCheck(h.ptr(), &Py_MemoryType);
}

template <typename Policy_>
/* NOLINTNEXTLINE(google-explicit-constructor) */
usm_memory(const py::detail::accessor<Policy_> &a)
: usm_memory(py::object(a))
{
}

usm_memory(const py::object &o)
: py::object(check_(o) ? o.inc_ref().ptr() : as_usm_memory(o.ptr()),
stolen_t{})
{
if (!m_ptr)
throw py::error_already_set();
}

/* NOLINTNEXTLINE(google-explicit-constructor) */
usm_memory(py::object &&o)
: py::object(check_(o) ? o.release().ptr() : as_usm_memory(o.ptr()),
stolen_t{})
{
if (!m_ptr)
throw py::error_already_set();
}
// END_TOKEN
PYBIND11_OBJECT_CVT(
usm_memory,
py::object,
[](PyObject *o) -> bool {
return PyObject_TypeCheck(o, &Py_MemoryType) != 0;
},
[](PyObject *o) -> PyObject * { return as_usm_memory(o); })

usm_memory()
: py::object(::dpctl::detail::dpctl_api::get().default_usm_memory_(),
Expand Down Expand Up @@ -412,50 +370,9 @@ namespace tensor
class usm_ndarray : public py::object
{
public:
// In Pybind11 2.9.3 replace code between START_TOKEN and END_TOKEN with
// macro
/*
PYBIND11_OBJECT(
usm_ndarray,
py::object,
[](PyObject *o) -> bool {return PyObject_TypeCheck(o, &PyUSMArrayType)
!= 0;}
)
*/

// START_TOKEN
static bool check_(py::handle h)
{
return h.ptr() != nullptr &&
PyObject_TypeCheck(h.ptr(), &PyUSMArrayType);
}

// these constructors do not validate, but since borrowed_t and stolen_t are
// protected struct members of the object, they can only be called
// internally.
usm_ndarray(py::handle h, borrowed_t) : py::object(h, borrowed_t{}) {}
usm_ndarray(py::handle h, stolen_t) : py::object(h, stolen_t{}) {}

template <typename Policy_>
/* NOLINTNEXTLINE(google-explicit-constructor) */
usm_ndarray(const py::detail::accessor<Policy_> &a)
: usm_ndarray(py::object(a))
{
}

usm_ndarray(const py::object &o) : py::object(o)
{
if (m_ptr && !check_(m_ptr))
throw PYBIND11_OBJECT_CHECK_FAILED(usm_ndarray, m_ptr);
}

/* NOLINTNEXTLINE(google-explicit-constructor) */
usm_ndarray(py::object &&o) : py::object(std::move(o))
{
if (m_ptr && !check_(m_ptr))
throw PYBIND11_OBJECT_CHECK_FAILED(usm_ndarray, m_ptr);
}
// END_TOKEN
PYBIND11_OBJECT(usm_ndarray, py::object, [](PyObject *o) -> bool {
return PyObject_TypeCheck(o, &PyUSMArrayType) != 0;
})

usm_ndarray()
: py::object(::dpctl::detail::dpctl_api::get().default_usm_ndarray_(),
Expand Down
4 changes: 2 additions & 2 deletions examples/pybind11/external_usm_allocation/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ set(CMAKE_CXX_STANDARD_REQUIRED True)
include(FetchContent)
FetchContent_Declare(
pybind11
URL https://github.com/pybind/pybind11/archive/refs/tags/v2.9.2.tar.gz
URL_HASH SHA256=6bd528c4dbe2276635dc787b6b1f2e5316cf6b49ee3e150264e455a0d68d19c1
URL https://github.com/pybind/pybind11/archive/refs/tags/v2.10.0.tar.gz
URL_HASH SHA256=eacf582fa8f696227988d08cfc46121770823839fe9e301a20fbce67e7cd70ec
)
FetchContent_MakeAvailable(pybind11)

Expand Down
4 changes: 2 additions & 2 deletions examples/pybind11/onemkl_gemv/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ include(GNUInstallDirs)
include(FetchContent)
FetchContent_Declare(
pybind11
URL https://github.com/pybind/pybind11/archive/refs/tags/v2.9.2.tar.gz
URL_HASH SHA256=6bd528c4dbe2276635dc787b6b1f2e5316cf6b49ee3e150264e455a0d68d19c1
URL https://github.com/pybind/pybind11/archive/refs/tags/v2.10.0.tar.gz
URL_HASH SHA256=eacf582fa8f696227988d08cfc46121770823839fe9e301a20fbce67e7cd70ec
)
FetchContent_MakeAvailable(pybind11)

Expand Down
4 changes: 2 additions & 2 deletions examples/pybind11/use_dpctl_syclqueue/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ set(CMAKE_CXX_STANDARD_REQUIRED True)
include(FetchContent)
FetchContent_Declare(
pybind11
URL https://github.com/pybind/pybind11/archive/refs/tags/v2.9.2.tar.gz
URL_HASH SHA256=6bd528c4dbe2276635dc787b6b1f2e5316cf6b49ee3e150264e455a0d68d19c1
URL https://github.com/pybind/pybind11/archive/refs/tags/v2.10.0.tar.gz
URL_HASH SHA256=eacf582fa8f696227988d08cfc46121770823839fe9e301a20fbce67e7cd70ec
)
FetchContent_MakeAvailable(pybind11)

Expand Down