|
17 | 17 | """Defines unit test cases for the SyclKernelBundle and SyclKernel classes""" |
18 | 18 |
|
19 | 19 | import os |
| 20 | +import warnings |
20 | 21 |
|
21 | 22 | import numpy as np |
22 | 23 | import pytest |
23 | 24 |
|
24 | 25 | import dpctl |
25 | 26 | import dpctl.compiler as dpc |
26 | 27 | import dpctl.memory as dpm |
| 28 | +import dpctl.program as dpp |
27 | 29 | from dpctl.compiler.utils import parse_spirv_specializations |
28 | 30 |
|
29 | 31 |
|
@@ -106,6 +108,7 @@ def _check_cpython_api_SyclKernelBundle_Make(kb): |
106 | 108 | kb2 = make_kb_fn(kb.addressof_ref()) |
107 | 109 | assert kb2.has_sycl_kernel("add") |
108 | 110 | assert kb2.has_sycl_kernel("axpy") |
| 111 | + return kb2 |
109 | 112 |
|
110 | 113 |
|
111 | 114 | def _check_cpython_api_SyclKernel_GetKernelRef(krn): |
@@ -210,9 +213,9 @@ def _check_multi_kernel_bundle(kb): |
210 | 213 | assert type(cmsgsz) is int |
211 | 214 |
|
212 | 215 | _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") |
216 | 219 |
|
217 | 220 |
|
218 | 221 | def test_create_kernel_bundle_from_source_ocl(): |
@@ -703,3 +706,57 @@ def test_sycl_source_vector_add_correctness(queue_selector): |
703 | 706 | ev4 = q.memcpy_async(dest=out, src=out_usm, count=out.nbytes, dEvents=[ev3]) |
704 | 707 | ev4.wait() |
705 | 708 | 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