From 47fdd1a55f2d2bfe3c4af4f4a5c0b4e6d227e3ba Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Mon, 14 Sep 2020 21:52:45 -0500 Subject: [PATCH] Add Program.set_specialization_constant and related error codes --- doc/make_constants.py | 4 ++++ doc/runtime_program.rst | 6 ++++++ src/wrap_cl.hpp | 12 ++++++++++++ src/wrap_cl_part_2.cpp | 5 +++++ src/wrap_constants.cpp | 5 +++++ 5 files changed, 32 insertions(+) diff --git a/doc/make_constants.py b/doc/make_constants.py index 803a52d0..28eebe6c 100644 --- a/doc/make_constants.py +++ b/doc/make_constants.py @@ -31,6 +31,7 @@ cl_12 = ("CL_1.2", "2011.2") cl_12_2015 = ("CL_1.2", "2015.2") cl_20 = ("CL_2.0", "2015.2") cl_21 = ("CL_2.1", "2016.2") +cl_22 = ("CL_2.1", "2020.3") cl_30 = ("CL_3.0", "2020.3") amd_devattr = ("cl_amd_device_attribute_query", "2013.2") qcom_hp_devattr = ("cl_qcom_ext_host_ptr", "2016.2") @@ -83,6 +84,9 @@ const_ext_lookup = { "INVALID_PIPE_SIZE": cl_20, "INVALID_DEVICE_QUEUE": cl_20, + "INVALID_SPEC_ID": cl_22, + "MAX_SIZE_RESTRICTION_EXCEEDED": cl_22, + }, cl.device_info: { diff --git a/doc/runtime_program.rst b/doc/runtime_program.rst index 18d831eb..31de0ac2 100644 --- a/doc/runtime_program.rst +++ b/doc/runtime_program.rst @@ -110,6 +110,12 @@ Program Returns a list of all :class:`Kernel` objects in the :class:`Program`. + .. method:: set_specialization_constant(spec_id, buffer) + + Only available with CL 2.2 and newer. + + .. versionadded:: 2020.3 + .. automethod:: from_int_ptr .. autoattribute:: int_ptr diff --git a/src/wrap_cl.hpp b/src/wrap_cl.hpp index ded51a42..05c746a5 100644 --- a/src/wrap_cl.hpp +++ b/src/wrap_cl.hpp @@ -41,6 +41,8 @@ // clCloneKernel // clEnqueueSVMMigrateMem +// CL 2.2 complete + // CL 3.0 missing: // clCreateBufferWithProperties // clCreateImageWithProperties @@ -3858,6 +3860,16 @@ namespace pyopencl 0, 0)); } #endif + +#if PYOPENCL_CL_VERSION >= 0x2020 + void set_specialization_constant(cl_uint spec_id, py::object py_buffer) + { + py_buffer_wrapper bufwrap; + bufwrap.get(py_buffer.ptr(), PyBUF_ANY_CONTIGUOUS); + PYOPENCL_CALL_GUARDED(clSetProgramSpecializationConstant, + (m_program, spec_id, bufwrap.m_buf.len, bufwrap.m_buf.buf)); + } +#endif }; diff --git a/src/wrap_cl_part_2.cpp b/src/wrap_cl_part_2.cpp index 175b5aa5..6735d41f 100644 --- a/src/wrap_cl_part_2.cpp +++ b/src/wrap_cl_part_2.cpp @@ -400,6 +400,11 @@ void pyopencl_expose_part_2(py::module &m) py::arg("options")="", py::arg("devices")=py::none() ) +#endif +#if PYOPENCL_CL_VERSION >= 0x2020 + .def("set_specialization_constant", &cls::set_specialization_constant, + py::arg("spec_id"), + py::arg("buffer")) #endif .def(py::self == py::self) .def(py::self != py::self) diff --git a/src/wrap_constants.cpp b/src/wrap_constants.cpp index dcda80d1..a5abb38a 100644 --- a/src/wrap_constants.cpp +++ b/src/wrap_constants.cpp @@ -240,6 +240,11 @@ void pyopencl_expose_constants(py::module &m) ADD_ATTR(, INVALID_DEVICE_QUEUE); #endif +#if PYOPENCL_CL_VERSION >= 0x2020 + ADD_ATTR(, INVALID_SPEC_ID); + ADD_ATTR(, MAX_SIZE_RESTRICTION_EXCEEDED); +#endif + #if defined(cl_ext_device_fission) && defined(PYOPENCL_USE_DEVICE_FISSION) ADD_ATTR(, DEVICE_PARTITION_FAILED_EXT); ADD_ATTR(, INVALID_PARTITION_COUNT_EXT); -- GitLab