Skip to content

Commit 21cbdd6

Browse files
committed
add deprecation tests
also fix broken tests
1 parent 3e4e76a commit 21cbdd6

1 file changed

Lines changed: 60 additions & 3 deletions

File tree

dpctl/tests/test_sycl_compiler.py

Lines changed: 60 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,15 @@
1717
"""Defines unit test cases for the SyclKernelBundle and SyclKernel classes"""
1818

1919
import os
20+
import warnings
2021

2122
import numpy as np
2223
import pytest
2324

2425
import dpctl
2526
import dpctl.compiler as dpc
2627
import dpctl.memory as dpm
28+
import dpctl.program as dpp
2729
from dpctl.compiler.utils import parse_spirv_specializations
2830

2931

@@ -106,6 +108,7 @@ def _check_cpython_api_SyclKernelBundle_Make(kb):
106108
kb2 = make_kb_fn(kb.addressof_ref())
107109
assert kb2.has_sycl_kernel("add")
108110
assert kb2.has_sycl_kernel("axpy")
111+
return kb2
109112

110113

111114
def _check_cpython_api_SyclKernel_GetKernelRef(krn):
@@ -210,9 +213,9 @@ def _check_multi_kernel_bundle(kb):
210213
assert type(cmsgsz) is int
211214

212215
_check_cpython_api_SyclKernelBundle_GetKernelBundleRef(kb)
213-
p2 = _check_cpython_api_SyclKernelBundle_Make(kb)
214-
assert p2.has_sycl_kernel("add")
215-
assert p2.has_sycl_kernel("axpy")
216+
kb2 = _check_cpython_api_SyclKernelBundle_Make(kb)
217+
assert kb2.has_sycl_kernel("add")
218+
assert kb2.has_sycl_kernel("axpy")
216219

217220

218221
def test_create_kernel_bundle_from_source_ocl():
@@ -703,3 +706,57 @@ def test_sycl_source_vector_add_correctness(queue_selector):
703706
ev4 = q.memcpy_async(dest=out, src=out_usm, count=out.nbytes, dEvents=[ev3])
704707
ev4.wait()
705708
assert np.array_equal(out, expected)
709+
710+
711+
@pytest.mark.parametrize(
712+
"deprecated_name, replacement",
713+
[
714+
("SyclProgram", dpc.SyclKernelBundle),
715+
("SyclProgramCompilationError", dpc.SyclKernelBundleCompilationError),
716+
],
717+
)
718+
def test_program_deprecated_aliases(deprecated_name, replacement):
719+
with pytest.warns(DeprecationWarning, match=deprecated_name):
720+
alias = getattr(dpp, deprecated_name)
721+
722+
assert alias is replacement
723+
724+
725+
def test_program_all_names_are_reachable():
726+
with warnings.catch_warnings():
727+
warnings.simplefilter("ignore", DeprecationWarning)
728+
for name in dpp.__all__:
729+
assert getattr(dpp, name) is not None
730+
731+
732+
def test_create_program_from_source_is_deprecated():
733+
q = _get_opencl_queue_or_skip()
734+
oclSrc = " \
735+
kernel void add(global int* a, global int* b, global int* c) { \
736+
size_t index = get_global_id(0); \
737+
c[index] = a[index] + b[index]; \
738+
}"
739+
with pytest.warns(
740+
DeprecationWarning, match="create_program_from_source is deprecated"
741+
):
742+
kb = dpp.create_program_from_source(q, oclSrc)
743+
744+
assert type(kb) is dpc.SyclKernelBundle
745+
assert kb.has_sycl_kernel("add")
746+
747+
748+
def test_create_program_from_spirv_is_deprecated():
749+
import dpctl.program as dpp
750+
751+
q = _get_opencl_queue_or_skip()
752+
spirv_file = get_spirv_abspath("multi_kernel.spv")
753+
with open(spirv_file, "rb") as fin:
754+
spirv = fin.read()
755+
with pytest.warns(
756+
DeprecationWarning, match="create_program_from_spirv is deprecated"
757+
):
758+
kb = dpp.create_program_from_spirv(q, spirv)
759+
760+
assert type(kb) is dpc.SyclKernelBundle
761+
assert kb.has_sycl_kernel("add")
762+
assert kb.has_sycl_kernel("axpy")

0 commit comments

Comments
 (0)