Skip to content

Used clang-format off, clang-format on to avoid include reordering #588

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 2 commits into from
Sep 16, 2021
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: 4 additions & 0 deletions examples/pybind11/use_dpctl_syclqueue/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
41 changes: 39 additions & 2 deletions examples/pybind11/use_dpctl_syclqueue/pybind11_example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@
#include <pybind11/numpy.h>
#include <pybind11/pybind11.h>

// 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;

Expand All @@ -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<PySyclDeviceObject *>(device_pycapi));
sycl::device *d_ptr = reinterpret_cast<sycl::device *>(DRef);
return d_ptr->get_info<sycl::info::device::global_mem_size>();
}
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<PySyclDeviceObject *>(device_pycapi));
sycl::device *d_ptr = reinterpret_cast<sycl::device *>(DRef);
return d_ptr->get_info<sycl::info::device::local_mem_size>();
}
else {
throw std::runtime_error("expected dpctl.SyclDevice as argument");
}
}

py::array_t<int64_t>
offloaded_array_mod(py::object queue,
py::array_t<int64_t, py::array::c_style> array,
Expand Down Expand Up @@ -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");
}