@@ -21,13 +21,12 @@ namespace py = pybind11;
2121
2222namespace oneapi ::dal::python {
2323
24- #ifdef ONEDAL_DATA_PARALLEL
25-
2624void instantiate_sycl_interfaces (py::module & m) {
2725 // These classes mirror a subset of functionality of the dpctl python
2826 // package's `SyclQueue` and `SyclDevice` objects. In the case that dpctl
2927 // is not installed, these classes will enable scikit-learn-intelex to still
3028 // properly offload to other devices when built with the dpc backend.
29+ #ifdef ONEDAL_DATA_PARALLEL
3130 py::class_<sycl::queue> syclqueue (m, " SyclQueue" );
3231 syclqueue.def (py::init<const sycl::device&>())
3332 .def (py::init ([](const std::string& filter) {
@@ -81,11 +80,31 @@ void instantiate_sycl_interfaces(py::module& m) {
8180 })
8281 .def_property_readonly (" is_cpu" , &sycl::device::is_cpu)
8382 .def_property_readonly (" is_gpu" , &sycl::device::is_gpu);
83+ #else
84+ struct syclqueue {};
85+ py::class_<syclqueue> syclqueue (m, " SyclQueue" );
86+ // inspired from pybind11 PR#4698 which turns init into a no-op
87+ syclqueue
88+ .def (py::init ([]() {
89+ return nullptr ;
90+ }))
91+ .def_static (" __new__" , [](const py::object& cls, const py::object& obj) {
92+ // this object is defined for the host build, where SYCL support is not available.
93+ // This class acts as the failure point to target_offload, which will throw an
94+ // error in all circumstances if any value but the default value ("auto"), or a string
95+ // starting with "cpu". The returned "queue" is a None. Must be a class to work with
96+ // isinstance
97+ if (!py::isinstance<py::str>(obj) || obj.cast <std::string>() != " auto" ) {
98+ throw std::invalid_argument (
99+ " device use via `target_offload` is only supported with the DPC++ backend" );
100+ }
101+ return py::none ();
102+ });
103+ #endif
84104}
85105
86106ONEDAL_PY_INIT_MODULE (sycl) {
87107 instantiate_sycl_interfaces (m);
88108}
89- #endif
90109
91110} // namespace oneapi::dal::python
0 commit comments