-
Notifications
You must be signed in to change notification settings - Fork 175
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
[bugfix, enhancement] enable proper GPU offloading with fp64 support when DPCtl unavailable #2152
base: main
Are you sure you want to change the base?
Changes from 56 commits
a1c9df5
7a18a1d
92f8c03
8b08af0
0941eb2
3aaa59c
ca25fdc
36fc5a2
f20252f
e5284db
085c170
d47b05f
56ec2a6
350c5d7
0c03531
58202f4
1ab22fd
70dd06f
f18abc9
c21af6d
4278de3
e4129d5
2f4c476
bb04233
02ae4ed
fd35cc9
6f5e4a2
1613b07
381114b
7b56d73
eace58c
8d3cbc6
db8e5b6
5e7946d
4cdae49
45482f3
034c5c8
675eea7
5193b9a
cacd8d7
3ddbf5b
fadf40d
b182a14
565ccef
d993182
92f507e
6f17e92
77e020a
e72d916
51126d7
368895a
a14206b
380d2d3
660aaf1
7bdb533
e59b4c5
f3c6a80
781271b
589c5d9
a55a56f
4cb1564
1f287fe
b4d137c
563612f
6710772
f2161cb
91522f4
e71e7c0
89e369b
e237c2c
d43ca05
b083ff3
4e3e82d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/******************************************************************************* | ||
* Copyright 2024 Intel Corporation | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*******************************************************************************/ | ||
|
||
#pragma once | ||
|
||
#include <string> | ||
#include <cstdint> | ||
|
||
#ifdef ONEDAL_DATA_PARALLEL | ||
#include <sycl/sycl.hpp> | ||
#endif // ONEDAL_DATA_PARALLEL | ||
|
||
#include <pybind11/pybind11.h> | ||
|
||
#include "oneapi/dal/detail/policy.hpp" | ||
|
||
#include "onedal/common/sycl_interfaces.hpp" | ||
|
||
namespace py = pybind11; | ||
|
||
namespace oneapi::dal::python { | ||
|
||
#ifdef ONEDAL_DATA_PARALLEL | ||
|
||
using dp_policy_t = detail::data_parallel_policy; | ||
|
||
dp_policy_t make_dp_policy(std::uint32_t id); | ||
dp_policy_t make_dp_policy(const py::object& syclobj); | ||
dp_policy_t make_dp_policy(const std::string& filter); | ||
inline dp_policy_t make_dp_policy(const dp_policy_t& policy) { | ||
return dp_policy_t{ policy }; | ||
} | ||
|
||
#endif // ONEDAL_DATA_PARALLEL | ||
|
||
template <typename Policy> | ||
inline auto& instantiate_host_policy(py::class_<Policy>& policy) { | ||
policy.def(py::init<>()); | ||
policy.def(py::init<Policy>()); | ||
policy.def("get_device_id", [](const Policy&) -> std::uint32_t { | ||
return std::uint32_t{ 0u }; | ||
}); | ||
policy.def("get_device_name", [](const Policy&) -> std::string { | ||
return std::string{ "cpu" }; | ||
}); | ||
return policy; | ||
} | ||
|
||
} // namespace oneapi::dal::python |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/******************************************************************************* | ||
* Copyright 2024 Intel Corporation | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*******************************************************************************/ | ||
|
||
#include "onedal/common/sycl_interfaces.hpp" | ||
#include "onedal/common/pybind11_helpers.hpp" | ||
|
||
namespace py = pybind11; | ||
|
||
namespace oneapi::dal::python { | ||
|
||
#ifdef ONEDAL_DATA_PARALLEL | ||
|
||
void instantiate_sycl_interfaces(py::module& m){ | ||
py::class_<sycl::queue> syclqueue(m, "SyclQueue"); | ||
syclqueue.def(py::init<const sycl::device&>()) | ||
.def(py::init([](const std::string& filter) { | ||
return get_queue_by_filter_string(filter); | ||
}) | ||
) | ||
.def(py::init([](const py::int_& obj) { | ||
return get_queue_by_pylong_pointer(obj); | ||
}) | ||
Comment on lines
+37
to
+39
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you please share the case when it is needed? Does it covered by tests? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. https://github.com/pytorch/pytorch/blob/main/torch/csrc/xpu/Stream.cpp#L72, waiting on a compiler compatibility fix here: pytorch/pytorch#139775 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add a comment somewhere that this is needed to accept pytorch tensors. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've now left a note @Vika-F please let me know what you think! |
||
) | ||
.def(py::init([](const py::object& syclobj) { | ||
return get_queue_from_python(syclobj); | ||
}) | ||
) | ||
.def("_get_capsule",[](const sycl::queue& queue) { | ||
return pack_queue(std::make_shared<sycl::queue>(queue)); | ||
} | ||
) | ||
.def_property_readonly("sycl_device", &sycl::queue::get_device); | ||
|
||
// expose limited sycl device features to python for oneDAL analysis | ||
py::class_<sycl::device> sycldevice(m, "SyclDevice"); | ||
sycldevice.def(py::init([](std::uint32_t id) { | ||
return get_device_by_id(id).value(); | ||
}) | ||
) | ||
.def_property_readonly("has_aspect_fp64",[](const sycl::device& device) { | ||
return device.has(sycl::aspect::fp64); | ||
} | ||
) | ||
.def_property_readonly("has_aspect_fp16",[](const sycl::device& device) { | ||
return device.has(sycl::aspect::fp16); | ||
} | ||
) | ||
.def_property_readonly("filter_string",[](const sycl::device& device) { | ||
// assumes we are not working with accelerators | ||
std::string filter = get_device_name(device); | ||
py::int_ id(get_device_id(device).value()); | ||
return py::str(filter + ":") + py::str(id); | ||
} | ||
) | ||
.def_property_readonly("is_cpu", &sycl::device::is_cpu) | ||
.def_property_readonly("is_gpu", &sycl::device::is_gpu); | ||
} | ||
|
||
ONEDAL_PY_INIT_MODULE(sycl) { | ||
instantiate_sycl_interfaces(m); | ||
} | ||
#endif | ||
|
||
} // namespace oneapi::dal::python |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please write a comment about the purpose of this class. I.e. that it implements sycl queue interface in case dpctl's sycl queue is not available.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, let me know what you think