Skip to content

Commit 97c9702

Browse files
Added a Cython extension to be built in place and used in tests to test Cython API functions
The extension is built in temp folder. Added cython as Cython test dependency Pass --cov-config option to pytest with coverage. This works around coverage config discrepancy between the main process and a subprocess. See pytest-dev/pytest-cov#243 added _cython_api.pyx to flake exception list Exclude dpctl/tests/* and dpctl/_version from coverage reporting Fix loading of Cython extension _cython_api on Windows Add test for property=int usage
1 parent 9ac1e2f commit 97c9702

File tree

8 files changed

+84
-3
lines changed

8 files changed

+84
-3
lines changed

.flake8

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ per-file-ignores =
2424
dpctl/program/_program.pyx: E999, E225, E226, E227
2525
dpctl/tensor/_usmarray.pyx: E999, E225, E226, E227
2626
dpctl/tensor/numpy_usm_shared.py: F821
27+
dpctl/tests/_cython_api.pyx: E999, E225, E227, E402
2728
examples/cython/sycl_buffer/_buffer_example.pyx: E999, E225, E402
2829
examples/cython/sycl_direct_linkage/_buffer_example.pyx: E999, E225, E402
2930
examples/cython/usm_memory/blackscholes.pyx: E999, E225, E226, E402

.github/workflows/generate-coverage.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ jobs:
8787
source /opt/intel/oneapi/setvars.sh
8888
python setup.py develop --coverage=True
8989
python -c "import dpctl; print(dpctl.__version__); dpctl.lsplatform()"
90-
pytest -q -ra --disable-warnings --cov dpctl --cov-report term-missing --pyargs dpctl -vv
90+
pytest -q -ra --disable-warnings --cov-config pyproject.toml --cov dpctl --cov-report term-missing --pyargs dpctl -vv
9191
9292
- name: Install coverall dependencies
9393
shell: bash -l {0}

MANIFEST.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ include dpctl/memory/_memory_api.h
1414
include dpctl/tensor/_usmarray.h
1515
include dpctl/tensor/_usmarray_api.h
1616
include dpctl/tests/input_files/*
17+
include dpctl/tests/*.pyx

conda-recipe/meta.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ requirements:
3232

3333
test:
3434
requires:
35+
- cython
3536
- pytest
3637
- pytest-cov
3738

dpctl/tests/_cython_api.pyx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# cython: language=c++
2+
# cython: language_level=3
3+
4+
cimport dpctl as c_dpctl
5+
6+
import dpctl
7+
8+
9+
def call_create_from_context_and_devices():
10+
cdef c_dpctl.SyclQueue q
11+
d = dpctl.SyclDevice()
12+
ctx = dpctl.SyclContext(d)
13+
# calling static method
14+
q = c_dpctl.SyclQueue._create_from_context_and_device(
15+
<c_dpctl.SyclContext> ctx,
16+
<c_dpctl.SyclDevice> d
17+
)
18+
return q

dpctl/tests/setup_cython_api.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import setuptools
2+
3+
import dpctl
4+
5+
ext = setuptools.Extension(
6+
"_cython_api",
7+
["_cython_api.pyx"],
8+
include_dirs=[dpctl.get_include()],
9+
language="c++",
10+
)
11+
12+
setuptools.setup(name="_cython_api", version="0.0.0", ext_modules=[ext])

dpctl/tests/test_sycl_queue.py

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -433,15 +433,15 @@ def test_queue_submit_barrier(valid_filter):
433433

434434

435435
def test_queue__repr__():
436-
q1 = dpctl.SyclQueue()
436+
q1 = dpctl.SyclQueue(property=0)
437437
r1 = q1.__repr__()
438438
q2 = dpctl.SyclQueue(property="in_order")
439439
r2 = q2.__repr__()
440440
q3 = dpctl.SyclQueue(property="enable_profiling")
441441
r3 = q3.__repr__()
442442
q4 = dpctl.SyclQueue(property="default")
443443
r4 = q4.__repr__()
444-
q5 = dpctl.SyclQueue(property=["in_order", "enable_profiling"])
444+
q5 = dpctl.SyclQueue(property=["in_order", "enable_profiling", 0])
445445
r5 = q5.__repr__()
446446
assert type(r1) is str
447447
assert type(r2) is str
@@ -552,3 +552,45 @@ def test_queue_memops():
552552
q.prefetch(list(), 512)
553553
with pytest.raises(TypeError):
554554
q.mem_advise(list(), 512, 0)
555+
556+
557+
@pytest.fixture(scope="session")
558+
def dpctl_cython_extension(tmp_path_factory):
559+
import os.path
560+
import shutil
561+
import subprocess
562+
import sys
563+
import sysconfig
564+
565+
curr_dir = os.path.dirname(__file__)
566+
dr = tmp_path_factory.mktemp("_cython_api")
567+
for fn in ["_cython_api.pyx", "setup_cython_api.py"]:
568+
shutil.copy(
569+
src=os.path.join(curr_dir, fn),
570+
dst=dr,
571+
follow_symlinks=False,
572+
)
573+
res = subprocess.run(
574+
[sys.executable, "setup_cython_api.py", "build_ext", "--inplace"],
575+
cwd=dr,
576+
)
577+
if res.returncode == 0:
578+
import glob
579+
from importlib.util import module_from_spec, spec_from_file_location
580+
581+
sfx = sysconfig.get_config_vars()["EXT_SUFFIX"]
582+
pth = glob.glob(os.path.join(dr, "_cython_api*" + sfx))
583+
if not pth:
584+
pytest.skip("Cython extension was not built")
585+
spec = spec_from_file_location("_cython_api", pth[0])
586+
builder_module = module_from_spec(spec)
587+
spec.loader.exec_module(builder_module)
588+
return builder_module
589+
else:
590+
pytest.skip("Cython extension could not be built")
591+
592+
593+
def test_cython_api(dpctl_cython_extension):
594+
q = dpctl_cython_extension.call_create_from_context_and_devices()
595+
d = dpctl.SyclDevice()
596+
assert q.sycl_device == d

pyproject.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ omit = [
2424
"dpctl/_version.py",
2525
]
2626

27+
[tool.coverage.report]
28+
omit = [
29+
"dpctl/tests/*",
30+
"dpctl/_version.py",
31+
]
32+
2733
[tool.pytest.ini.options]
2834
minversion = "6.0"
2935
norecursedirs= [

0 commit comments

Comments
 (0)