diff --git a/examples/pybind11/use_dpctl_syclqueue/example.py b/examples/pybind11/use_dpctl_syclqueue/example.py index 88860c1569..4c53bfafe2 100644 --- a/examples/pybind11/use_dpctl_syclqueue/example.py +++ b/examples/pybind11/use_dpctl_syclqueue/example.py @@ -25,9 +25,13 @@ # Pass dpctl.SyclQueue to Pybind11 extension eu_count = eg.get_max_compute_units(q) +global_mem_size = eg.get_device_global_mem_size(q.sycl_device) +local_mem_size = eg.get_device_local_mem_size(q.sycl_device) print(f"EU count returned by Pybind11 extension {eu_count}") print("EU count computed by dpctl {}".format(q.sycl_device.max_compute_units)) +print("Device's global memory size: {} bytes".format(global_mem_size)) +print("Device's local memory size: {} bytes".format(local_mem_size)) print("") print("Computing modular reduction using SYCL on a NumPy array") diff --git a/examples/pybind11/use_dpctl_syclqueue/pybind11_example.cpp b/examples/pybind11/use_dpctl_syclqueue/pybind11_example.cpp index a63f2bb617..9f1cc19ee2 100644 --- a/examples/pybind11/use_dpctl_syclqueue/pybind11_example.cpp +++ b/examples/pybind11/use_dpctl_syclqueue/pybind11_example.cpp @@ -3,9 +3,13 @@ #include #include +// clang-format off +#include "dpctl_sycl_types.h" #include "../_sycl_queue.h" #include "../_sycl_queue_api.h" -#include "dpctl_sycl_types.h" +#include "../_sycl_device.h" +#include "../_sycl_device_api.h" +// clang-format on namespace py = pybind11; @@ -25,6 +29,34 @@ size_t get_max_compute_units(py::object queue) } } +uint64_t get_device_global_mem_size(py::object device) +{ + PyObject *device_pycapi = device.ptr(); + if (PyObject_TypeCheck(device_pycapi, &PySyclDeviceType)) { + DPCTLSyclDeviceRef DRef = get_device_ref( + reinterpret_cast(device_pycapi)); + sycl::device *d_ptr = reinterpret_cast(DRef); + return d_ptr->get_info(); + } + else { + throw std::runtime_error("expected dpctl.SyclDevice as argument"); + } +} + +uint64_t get_device_local_mem_size(py::object device) +{ + PyObject *device_pycapi = device.ptr(); + if (PyObject_TypeCheck(device_pycapi, &PySyclDeviceType)) { + DPCTLSyclDeviceRef DRef = get_device_ref( + reinterpret_cast(device_pycapi)); + sycl::device *d_ptr = reinterpret_cast(DRef); + return d_ptr->get_info(); + } + else { + throw std::runtime_error("expected dpctl.SyclDevice as argument"); + } +} + py::array_t offloaded_array_mod(py::object queue, py::array_t array, @@ -82,11 +114,16 @@ offloaded_array_mod(py::object queue, PYBIND11_MODULE(pybind11_example, m) { - // Import the dpctl._sycl_queue extension + // Import the dpctl._sycl_queue, dpctl._sycl_device extensions + import_dpctl___sycl_device(); import_dpctl___sycl_queue(); m.def("get_max_compute_units", &get_max_compute_units, "Computes max_compute_units property of the device underlying given " "dpctl.SyclQueue"); + m.def("get_device_global_mem_size", &get_device_global_mem_size, + "Computes amount of global memory of the given dpctl.SyclDevice"); + m.def("get_device_local_mem_size", &get_device_local_mem_size, + "Computes amount of local memory of the given dpctl.SyclDevice"); m.def("offloaded_array_mod", &offloaded_array_mod, "Compute offloaded modular reduction of integer-valued NumPy array"); }