Skip to content

Cleanup/c extensions with dpctl#604

Merged
oleksandr-pavlyk merged 2 commits intomasterfrom
cleanup/c-extensions-with-dpctl
Sep 29, 2021
Merged

Cleanup/c extensions with dpctl#604
oleksandr-pavlyk merged 2 commits intomasterfrom
cleanup/c-extensions-with-dpctl

Conversation

@oleksandr-pavlyk
Copy link
Copy Markdown
Contributor

Closes #585

(idp) [13:46:33 ansatnuc04 issue_c_cython_dpctl]$ ls
a.pyx
(idp) [13:46:34 ansatnuc04 issue_c_cython_dpctl]$ cythonize a.pyx
Compiling /localdisk/work/opavlyk/repos/wd/issue_c_cython_dpctl/a.pyx because it changed.
[1/1] Cythonizing /localdisk/work/opavlyk/repos/wd/issue_c_cython_dpctl/a.pyx
(idp) [13:46:40 ansatnuc04 issue_c_cython_dpctl]$ gcc -fmax-errors=1 a.c -fPIC -I$(python -c "import dpctl; print(dpctl.get_include())") -I$(python3-config --includes) $(python3-config --ldflags) -fno-lto -shared -oa$(python3-config --extension-suffix)
(idp) [13:46:44 ansatnuc04 issue_c_cython_dpctl]$ python -c "import a"
(idp) [13:46:51 ansatnuc04 issue_c_cython_dpctl]$ python -c "import a; print(dir(a))"
['__builtins__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__pyx_unpickle_Enum', '__spec__', '__test__', 'dpctl', 'foo']

Native Pybind11-generated extension implemented Python type bound to
DMatrix C++ class which allocates USM memory using sycl::usm_allocator.

The Python object implements __sycl_usm_array_interface__, which allows
dpctl.memory.as_usm_memory to create a view into that native USM allocation.
The example.py modifies that memory from Python, and uses object's own
.tolist() method to retrieve the memory using C++, demonstrating that
values changed.

Also added license missing headers to .cpp and .hpp files from other
examples
Adds `#include <stdbool.h>` conditionally for C compilers.

Then the cython generate C source file can be compiled using gcc 9.3
as follows:

```
gcc -fmax-errors=1 a.c -fPIC -I$(python -c "import dpctl; print(dpctl.get_include())") -I$(python3-config --includes) $(pyt
hon3-config --ldflags) -fno-lto -shared -oa$(python3-config --extension-suffix)
```
@coveralls
Copy link
Copy Markdown
Collaborator

Coverage Status

Coverage remained the same at 74.162% when pulling a8fa412 on cleanup/c-extensions-with-dpctl into 15c9d82 on master.

@oleksandr-pavlyk
Copy link
Copy Markdown
Contributor Author

Would like to merge tomorrow.

@oleksandr-pavlyk oleksandr-pavlyk merged commit 281d0de into master Sep 29, 2021
@oleksandr-pavlyk oleksandr-pavlyk deleted the cleanup/c-extensions-with-dpctl branch September 29, 2021 21:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cython extension cimporting dpctl fails to compile in C

2 participants