Skip to content

Commit 3b675fc

Browse files
committed
make examples free-threading compatible
1 parent 31f0dbb commit 3b675fc

7 files changed

Lines changed: 26 additions & 14 deletions

File tree

examples/c/py_sycl_ls/src/py_sycl-ls.c

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -63,25 +63,35 @@ static PyMethodDef SyclLSMethods[] = {
6363
{NULL, NULL, 0, NULL} /* Sentinel */
6464
};
6565

66+
static int syclls_module_exec(PyObject *m)
67+
{
68+
(void)(m);
69+
import_dpctl();
70+
if (PyErr_Occurred()) {
71+
return -1;
72+
}
73+
return 0;
74+
}
75+
76+
static PyModuleDef_Slot syclls_module_slots[] = {
77+
{Py_mod_exec, syclls_module_exec},
78+
#if PY_VERSION_HEX >= 0x030D0000
79+
{Py_mod_gil, Py_MOD_GIL_NOT_USED},
80+
#endif
81+
{0, NULL}};
82+
6683
static struct PyModuleDef syclls_module = {
6784
PyModuleDef_HEAD_INIT,
6885
"_py_sycl_ls", /* name of module */
6986
"", /* module documentation, may be NULL */
70-
-1, /* size of per-interpreter state of the module,
71-
or -1 if the module keeps state in global variables. */
87+
0, /* size of per-interpreter state of the module */
7288
SyclLSMethods,
73-
NULL,
89+
syclls_module_slots,
7490
NULL,
7591
NULL,
7692
NULL};
7793

7894
PyMODINIT_FUNC PyInit__py_sycl_ls(void)
7995
{
80-
PyObject *m;
81-
82-
import_dpctl();
83-
84-
m = PyModule_Create(&syclls_module);
85-
86-
return m;
96+
return PyModuleDef_Init(&syclls_module);
8797
}

examples/cython/sycl_buffer/syclbuffer/_syclbuffer.pyx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
# distutils: language = c++
1818
# cython: language_level=3
19+
# cython: freethreading_compatible = True
1920

2021
cimport cython
2122

examples/cython/use_dpctl_sycl/use_dpctl_sycl/_cython_api.pyx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
# distutils: language = c++
1818
# cython: language_level=3
1919
# cython: linetrace=True
20+
# cython: freethreading_compatible = True
2021

2122
cimport libcpp.string
2223

examples/pybind11/external_usm_allocation/external_usm_allocation/_usm_alloc_example.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ dpctl::memory::usm_memory make_zeroed_device_memory(size_t nbytes,
141141
return dpctl::memory::usm_memory(data, nbytes, q, shptr);
142142
}
143143

144-
PYBIND11_MODULE(_external_usm_alloc, m)
144+
PYBIND11_MODULE(_external_usm_alloc, m, py::mod_gil_not_used())
145145
{
146146
py::class_<DMatrix> dm(m, "DMatrix");
147147
dm.def(py::init(&create_matrix),

examples/pybind11/onemkl_gemv/sycl_gemm/_onemkl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,7 @@ int py_cg_solve(sycl::queue exec_q,
521521
}
522522
}
523523

524-
PYBIND11_MODULE(_onemkl, m)
524+
PYBIND11_MODULE(_onemkl, m, py::mod_gil_not_used())
525525
{
526526
m.def("gemv", &py_gemv, "Uses oneMKL to compute dot(matrix, vector)",
527527
py::arg("exec_queue"), py::arg("Amatrix"), py::arg("xvec"),

examples/pybind11/use_dpctl_sycl_kernel/use_kernel/_example.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ void submit_custom_kernel(sycl::queue &q,
7575
return;
7676
}
7777

78-
PYBIND11_MODULE(_use_kernel, m)
78+
PYBIND11_MODULE(_use_kernel, m, py::mod_gil_not_used())
7979
{
8080
m.def("submit_custom_kernel", &submit_custom_kernel,
8181
"Submit given kernel with arguments (int *, int *) to queue",

examples/pybind11/use_dpctl_sycl_queue/use_queue_device/_example.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ std::uint32_t get_partition_max_sub_devices(const sycl::device &d)
9595
return d.get_info<sycl::info::device::partition_max_sub_devices>();
9696
}
9797

98-
PYBIND11_MODULE(_use_queue_device, m)
98+
PYBIND11_MODULE(_use_queue_device, m, py::mod_gil_not_used())
9999
{
100100
m.def(
101101
"get_max_compute_units",

0 commit comments

Comments
 (0)