From 5d2c1649f408ccd6a2bce8ef29fc78f743e1cbfc Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Wed, 9 Sep 2020 14:12:30 -0500 Subject: [PATCH 01/38] Add OpenCL 3 constants --- doc/make_constants.py | 55 ++++++++++++++++++++++++-- pyopencl/__init__.py | 7 ++++ src/wrap_constants.cpp | 87 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 145 insertions(+), 4 deletions(-) diff --git a/doc/make_constants.py b/doc/make_constants.py index 2e20383b..cca0b7ce 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_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") intel_me_devattr = ("cl_intel_advanced_motion_estimation", "2016.2") @@ -58,6 +59,7 @@ def get_extra_lines(tup): yield " .. versionadded:: %s" % pyopencl_ver yield "" + const_ext_lookup = { cl.status_code: { "PLATFORM_NOT_FOUND_KHR": ("cl_khr_icd", "2011.1"), @@ -184,6 +186,21 @@ const_ext_lookup = { "IL_VERSION": cl_21, "MAX_NUM_SUB_GROUPS": cl_21, "SUB_GROUP_INDEPENDENT_FORWARD_PROGRESS": cl_21, + + "NUMERIC_VERSION": cl_30, + "EXTENSIONS_WITH_VERSION": cl_30, + "ILS_WITH_VERSION": cl_30, + "BUILT_IN_KERNELS_WITH_VERSION": cl_30, + "ATOMIC_MEMORY_CAPABILITIES": cl_30, + "ATOMIC_FENCE_CAPABILITIES": cl_30, + "NON_UNIFORM_WORK_GROUP_SUPPORT": cl_30, + "OPENCL_C_ALL_VERSIONS": cl_30, + "PREFERRED_WORK_GROUP_SIZE_MULTIPLE": cl_30, + "WORK_GROUP_COLLECTIVE_FUNCTIONS_SUPPORT": cl_30, + "GENERIC_ADDRESS_SPACE_SUPPORT": cl_30, + "OPENCL_C_FEATURES": cl_30, + "DEVICE_ENQUEUE_SUPPORT": cl_30, + "PIPE_SUPPORT": cl_30, }, cl.mem_object_type: { @@ -251,6 +268,7 @@ const_ext_lookup = { "MIP_FILTER_MODE": cl_20, "LOD_MIN": cl_20, "LOD_MAX": cl_20, + "PROPERTIES": cl_30, }, cl.event_info: { @@ -271,6 +289,12 @@ const_ext_lookup = { "NUM_SAMPLES": cl_12, }, + cl.pipe_info: { + "PACKET_SIZE": ("CL_2.0", "2020.3"), + "MAX_PACKETS": ("CL_2.0", "2020.3"), + "PROPERTIES": cl_30, + }, + cl.map_flags: { "WRITE_INVALIDATE_REGION": cl_12, }, @@ -343,6 +367,7 @@ const_ext_lookup = { "SVM_MEMFILL": cl_20, "SVM_MAP": cl_20, "SVM_UNMAP": cl_20, + "SVM_MIGRATE_MEM": cl_30, }, cl.command_queue_info: { @@ -396,6 +421,16 @@ const_ext_lookup = { "NEXT_PARITIONNABLE": cl_12, }, + cl.device_atomic_capabilities: { + "ORDER_RELAXED": cl_30, + "ORDER_ACQ_REL": cl_30, + "ORDER_SEQ_CST": cl_30, + "SCOPE_WORK_ITEM": cl_30, + "SCOPE_WORK_GROUP": cl_30, + "SCOPE_DEVICE": cl_30, + "SCOPE_ALL_DEVICES": cl_30, + }, + cl.profiling_info: { "COMPLETE": cl_20, }, @@ -405,6 +440,18 @@ const_ext_lookup = { "CONTENT_UNDEFINED": cl_12, }, + cl.version_bits: { + "MAJOR_BITS": cl_30, + "MINOR_BITS": cl_30, + "PATCH_BITS": cl_30, + "MAJOR_MASK": cl_30, + "MINOR_MASK": cl_30, + "PATCH_MASK": cl_30, + }, + + cl.khronos_vendor_id: { + "CODEPLAY": cl_30, + }, } try: gl_ci = cl.gl_context_info @@ -433,8 +480,8 @@ def doc_class(cls): print() if cls in cls_ext_lookup: - for l in get_extra_lines(cls_ext_lookup[cls]): - print(l) + for ln in get_extra_lines(cls_ext_lookup[cls]): + print(ln) cls_const_ext = const_ext_lookup.get(cls, {}) for name in sorted(dir(cls)): @@ -442,8 +489,8 @@ def doc_class(cls): print(" .. attribute :: %s" % name) if name in cls_const_ext: - for l in get_extra_lines(cls_const_ext[name]): - print(" "+l) + for ln in get_extra_lines(cls_const_ext[name]): + print(" "+ln) print(" .. method :: to_string(value)") print() diff --git a/pyopencl/__init__.py b/pyopencl/__init__.py index 4e2ef296..354b942b 100644 --- a/pyopencl/__init__.py +++ b/pyopencl/__init__.py @@ -79,6 +79,7 @@ from pyopencl._cl import ( # noqa mem_object_type, mem_info, image_info, + pipe_info, addressing_mode, filter_mode, sampler_info, @@ -102,6 +103,10 @@ from pyopencl._cl import ( # noqa mem_migration_flags, device_partition_property, device_affinity_domain, + device_atomic_capabilities, + + version_bits, + khronos_vendor_id, Error, MemoryError, LogicError, RuntimeError, @@ -229,6 +234,8 @@ BITFIELD_CONSTANT_CLASSES = ( _cl.device_svm_capabilities, _cl.queue_properties, _cl.svm_mem_flags, + _cl.device_atomic_capabilities, + _cl.version_bits, ) diff --git a/src/wrap_constants.cpp b/src/wrap_constants.cpp index 2420be38..6fc5658f 100644 --- a/src/wrap_constants.cpp +++ b/src/wrap_constants.cpp @@ -58,6 +58,7 @@ namespace class mem_object_type { }; class mem_info { }; class image_info { }; + class pipe_info { }; class addressing_mode { }; class filter_mode { }; class sampler_info { }; @@ -82,6 +83,10 @@ namespace class device_partition_property { }; class device_affinity_domain { }; + class device_atomic_capabilities { }; + + class version_bits { }; + class khronos_vendor_id { }; class gl_object_type { }; class gl_texture_info { }; @@ -249,6 +254,13 @@ void pyopencl_expose_constants(py::module &m) ADD_ATTR(PLATFORM_, VENDOR); #if !(defined(CL_PLATFORM_NVIDIA) && CL_PLATFORM_NVIDIA == 0x3001) ADD_ATTR(PLATFORM_, EXTENSIONS); +#endif +#if PYOPENCL_CL_VERSION >= 0x2010 + ADD_ATTR(PLATFORM_, HOST_TIMER_RESOLUTION); +#endif +#if PYOPENCL_CL_VERSION >= 0x3000 + ADD_ATTR(PLATFORM_, NUMERIC_VERSION); + ADD_ATTR(PLATFORM_, EXTENSIONS_WITH_VERSION); #endif } @@ -459,6 +471,22 @@ void pyopencl_expose_constants(py::module &m) #ifdef CL_DEVICE_ME_VERSION_INTEL ADD_ATTR(DEVICE_, ME_VERSION_INTEL); #endif +#if PYOPENCL_CL_VERSION >= 0x3000 + ADD_ATTR(DEVICE_, NUMERIC_VERSION); + ADD_ATTR(DEVICE_, EXTENSIONS_WITH_VERSION); + ADD_ATTR(DEVICE_, ILS_WITH_VERSION); + ADD_ATTR(DEVICE_, BUILT_IN_KERNELS_WITH_VERSION); + ADD_ATTR(DEVICE_, ATOMIC_MEMORY_CAPABILITIES); + ADD_ATTR(DEVICE_, ATOMIC_FENCE_CAPABILITIES); + ADD_ATTR(DEVICE_, NON_UNIFORM_WORK_GROUP_SUPPORT); + ADD_ATTR(DEVICE_, OPENCL_C_ALL_VERSIONS); + ADD_ATTR(DEVICE_, PREFERRED_WORK_GROUP_SIZE_MULTIPLE); + ADD_ATTR(DEVICE_, WORK_GROUP_COLLECTIVE_FUNCTIONS_SUPPORT); + ADD_ATTR(DEVICE_, GENERIC_ADDRESS_SPACE_SUPPORT); + ADD_ATTR(DEVICE_, OPENCL_C_FEATURES); + ADD_ATTR(DEVICE_, DEVICE_ENQUEUE_SUPPORT); + ADD_ATTR(DEVICE_, PIPE_SUPPORT); +#endif /* cl_qcom_ext_host_ptr */ #ifdef CL_DEVICE_EXT_MEM_PADDING_IN_BYTES_QCOM @@ -595,6 +623,9 @@ void pyopencl_expose_constants(py::module &m) ADD_ATTR(QUEUE_, DEVICE); ADD_ATTR(QUEUE_, REFERENCE_COUNT); ADD_ATTR(QUEUE_, PROPERTIES); +#if PYOPENCL_CL_VERSION >= 0x3000 + ADD_ATTR(QUEUE_, PROPERTIES_ARRAY); +#endif } { @@ -602,6 +633,9 @@ void pyopencl_expose_constants(py::module &m) #if PYOPENCL_CL_VERSION >= 0x2000 ADD_ATTR(QUEUE_, PROPERTIES); ADD_ATTR(QUEUE_, SIZE); +#endif +#if PYOPENCL_CL_VERSION >= 0x2010 + ADD_ATTR(QUEUE_, DEVICE_DEFAULT); #endif } @@ -712,6 +746,9 @@ void pyopencl_expose_constants(py::module &m) #endif #if PYOPENCL_CL_VERSION >= 0x2000 ADD_ATTR(MEM_, USES_SVM_POINTER); +#endif +#if PYOPENCL_CL_VERSION >= 0x3000 + ADD_ATTR(MEM_, PROPERTIES); #endif } @@ -732,6 +769,16 @@ void pyopencl_expose_constants(py::module &m) #endif } + { + py::class_ cls(m, "pipe_info"); +#if PYOPENCL_CL_VERSION >= 0x2000 + ADD_ATTR(PIPE_, PACKET_SIZE); + ADD_ATTR(PIPE_, MAX_PACKETS); +#endif +#if PYOPENCL_CL_VERSION >= 0x3000 + ADD_ATTR(PIPE_, PROPERTIES); +#endif + } { py::class_ cls(m, "addressing_mode"); ADD_ATTR(ADDRESS_, NONE); @@ -760,6 +807,9 @@ void pyopencl_expose_constants(py::module &m) ADD_ATTR(SAMPLER_, MIP_FILTER_MODE); ADD_ATTR(SAMPLER_, LOD_MIN); ADD_ATTR(SAMPLER_, LOD_MAX); +#endif +#if PYOPENCL_CL_VERSION >= 0x3000 + ADD_ATTR(SAMPLER_, PROPERTIES); #endif } @@ -938,6 +988,9 @@ void pyopencl_expose_constants(py::module &m) ADD_ATTR(COMMAND_, SVM_MEMFILL); ADD_ATTR(COMMAND_, SVM_MAP); ADD_ATTR(COMMAND_, SVM_UNMAP); +#endif +#if PYOPENCL_CL_VERSION >= 0x3000 + ADD_ATTR(COMMAND_, SVM_MIGRATE_MEM); #endif } @@ -1001,6 +1054,40 @@ void pyopencl_expose_constants(py::module &m) #endif } + { + py::class_ cls(m, "device_atomic_capabilities"); +#if PYOPENCL_CL_VERSION >= 0x3000 + ADD_ATTR(DEVICE_ATOMIC_, ORDER_RELAXED); + ADD_ATTR(DEVICE_ATOMIC_, ORDER_ACQ_REL); + ADD_ATTR(DEVICE_ATOMIC_, ORDER_SEQ_CST); + ADD_ATTR(DEVICE_ATOMIC_, SCOPE_WORK_ITEM); + ADD_ATTR(DEVICE_ATOMIC_, SCOPE_WORK_GROUP); + ADD_ATTR(DEVICE_ATOMIC_, SCOPE_DEVICE); + ADD_ATTR(DEVICE_ATOMIC_, SCOPE_ALL_DEVICES); +#endif + } + + { + py::class_ cls(m, "version_bits"); +#if PYOPENCL_CL_VERSION >= 0x3000 + ADD_ATTR(VERSION_, MAJOR_BITS); + ADD_ATTR(VERSION_, MINOR_BITS); + ADD_ATTR(VERSION_, PATCH_BITS); + + ADD_ATTR(VERSION_, MAJOR_MASK); + ADD_ATTR(VERSION_, MINOR_MASK); + ADD_ATTR(VERSION_, PATCH_MASK); +#endif + } + + { + py::class_ cls(m, "khronos_vendor_id"); +#if PYOPENCL_CL_VERSION >= 0x3000 + ADD_ATTR(KHRONOS_VENDOR_ID_, CODEPLAY); +#endif + } + + #ifdef HAVE_GL { py::class_ cls(m, "gl_object_type"); -- GitLab From dc006debb0f54ae67284b103b7a9c07c6992c676 Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Sun, 13 Sep 2020 13:45:18 -0500 Subject: [PATCH 02/38] Fix version handling --- src/wrap_cl.hpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/wrap_cl.hpp b/src/wrap_cl.hpp index 42ee4c11..d939fe1a 100644 --- a/src/wrap_cl.hpp +++ b/src/wrap_cl.hpp @@ -52,7 +52,7 @@ #else // elsewhere ------------------------------------------------------------------ -#define CL_TARGET_OPENCL_VERSION 220 +#define CL_TARGET_OPENCL_VERSION 300 #include #include "pyopencl_ext.h" @@ -91,7 +91,9 @@ #define PYOPENCL_CL_VERSION PYOPENCL_PRETEND_CL_VERSION #else -#if defined(CL_VERSION_2_2) +#if defined(CL_VERSION_3_0) +#define PYOPENCL_CL_VERSION 0x3000 +#elif defined(CL_VERSION_2_2) #define PYOPENCL_CL_VERSION 0x2020 #elif defined(CL_VERSION_2_1) #define PYOPENCL_CL_VERSION 0x2010 -- GitLab From 6c8a624dddf934dc778c2b59a142dcf83a04ebdd Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Sun, 13 Sep 2020 13:45:43 -0500 Subject: [PATCH 03/38] Move around a device info constant --- src/wrap_constants.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/wrap_constants.cpp b/src/wrap_constants.cpp index 5f3e4324..0b6653c5 100644 --- a/src/wrap_constants.cpp +++ b/src/wrap_constants.cpp @@ -480,10 +480,6 @@ void pyopencl_expose_constants(py::module &m) ADD_ATTR(DEVICE_, IL_VERSION); ADD_ATTR(DEVICE_, MAX_NUM_SUB_GROUPS); ADD_ATTR(DEVICE_, SUB_GROUP_INDEPENDENT_FORWARD_PROGRESS); -#endif - /* cl_intel_advanced_motion_estimation */ -#ifdef CL_DEVICE_ME_VERSION_INTEL - ADD_ATTR(DEVICE_, ME_VERSION_INTEL); #endif #if PYOPENCL_CL_VERSION >= 0x3000 ADD_ATTR(DEVICE_, NUMERIC_VERSION); @@ -501,6 +497,10 @@ void pyopencl_expose_constants(py::module &m) ADD_ATTR(DEVICE_, DEVICE_ENQUEUE_SUPPORT); ADD_ATTR(DEVICE_, PIPE_SUPPORT); #endif + /* cl_intel_advanced_motion_estimation */ +#ifdef CL_DEVICE_ME_VERSION_INTEL + ADD_ATTR(DEVICE_, ME_VERSION_INTEL); +#endif /* cl_qcom_ext_host_ptr */ #ifdef CL_DEVICE_EXT_MEM_PADDING_IN_BYTES_QCOM -- GitLab From 92cee8032c854dee6b71e275efc3b6e6e38fdfef Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Sun, 13 Sep 2020 13:46:01 -0500 Subject: [PATCH 04/38] Wrap NameVersion --- src/wrap_constants.cpp | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/wrap_constants.cpp b/src/wrap_constants.cpp index 0b6653c5..a4f2f683 100644 --- a/src/wrap_constants.cpp +++ b/src/wrap_constants.cpp @@ -1127,6 +1127,40 @@ void pyopencl_expose_constants(py::module &m) // }}} + // {{{ cl_name_version +#if PYOPENCL_CL_VERSION >= 0x3000 + { + typedef cl_name_version cls; + py::class_(m, "NameVersion") + .def(py::init( + [](cl_version version, const char* name) + { + cl_name_version result; + result.version = version; + result.name[0] = '\0'; + // https://stackoverflow.com/a/1258577 + strncat(result.name, name, CL_NAME_VERSION_MAX_NAME_SIZE-1); + return result; + }), + py::arg("version")=0, + py::arg("name")=0) + + .def_property("version", + [](cls &t) { return t.version; }, + [](cls &t, cl_version val) { t.version = val; }) + .def_property("name", + [](cls &t) { return t.name; }, + [](cls &t, const char *name) + { + t.name[0] = '\0'; + // https://stackoverflow.com/a/1258577 + strncat(t.name, name, CL_NAME_VERSION_MAX_NAME_SIZE-1); + }) + ; + } +#endif + // }}} + // {{{ CL_DEVICE_TOPOLOGY_AMD #ifdef CL_DEVICE_TOPOLOGY_AMD -- GitLab From 4d85ce77d1aa303e00efa795e298cbb88c1533be Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Sun, 13 Sep 2020 13:45:03 -0500 Subject: [PATCH 05/38] Document NameVersion, DeviceTopologyAmd --- doc/runtime_const.rst | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/doc/runtime_const.rst b/doc/runtime_const.rst index 53ebf1fe..dc926360 100644 --- a/doc/runtime_const.rst +++ b/doc/runtime_const.rst @@ -4,3 +4,25 @@ OpenCL Runtime: Constants .. currentmodule:: pyopencl .. include:: constants.inc + +.. class:: NameVersion + Describes the version of a specific feature. + + .. note:: + + Only available with OpenCL 3.0 or newer. + + .. versionaddedd:: 2020.3 + + .. method:: __init__(version, name) + .. attribute:: version + .. attribute:: name + +.. class:: DeviceTopologyAmd + .. method:: __init__(bus, device, function) + .. attribute:: type + .. attribute:: bus + .. attribute:: device + .. attribute:: function + +.. vim: shiftwidth=4 -- GitLab From 0f9f1743d47f2d76d0acbea034017ee361d0fef1 Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Sun, 13 Sep 2020 13:46:23 -0500 Subject: [PATCH 06/38] Initialize type for DeviceTopologyAmd --- src/wrap_constants.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/wrap_constants.cpp b/src/wrap_constants.cpp index a4f2f683..dcda80d1 100644 --- a/src/wrap_constants.cpp +++ b/src/wrap_constants.cpp @@ -1171,6 +1171,7 @@ void pyopencl_expose_constants(py::module &m) [](cl_char bus, cl_char device, cl_char function) { cl_device_topology_amd result; + result.pcie.type = CL_DEVICE_TOPOLOGY_TYPE_PCIE_AMD; result.pcie.bus = bus; result.pcie.device = device; result.pcie.function = function; -- GitLab From 939ac7ef12e68b67658334fcfbc07797e0ccd3a0 Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Sun, 13 Sep 2020 13:46:44 -0500 Subject: [PATCH 07/38] Implement OpenCL 3 Platform, Device GetInfo queries --- src/wrap_cl.hpp | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/src/wrap_cl.hpp b/src/wrap_cl.hpp index d939fe1a..d969f234 100644 --- a/src/wrap_cl.hpp +++ b/src/wrap_cl.hpp @@ -580,6 +580,20 @@ namespace pyopencl #endif PYOPENCL_GET_STR_INFO(Platform, m_platform, param_name); +#if PYOPENCL_CL_VERSION >= 0x2010 + case CL_PLATFORM_HOST_TIMER_RESOLUTION: + PYOPENCL_GET_TYPED_INFO(Platform, m_platform, param_name, cl_ulong); +#endif +#if PYOPENCL_CL_VERSION >= 0x3000 + case CL_PLATFORM_NUMERIC_VERSION: + PYOPENCL_GET_TYPED_INFO(Platform, m_platform, param_name, cl_version); + case CL_PLATFORM_EXTENSIONS_WITH_VERSION: + { + std::vector result; + PYOPENCL_GET_VEC_INFO(Platform, m_platform, param_name, result); + PYOPENCL_RETURN_VECTOR(cl_name_version, result); + } +#endif default: throw error("Platform.get_info", CL_INVALID_VALUE); } @@ -916,6 +930,28 @@ namespace pyopencl case CL_DEVICE_MAX_NUM_SUB_GROUPS: DEV_GET_INT_INF(cl_uint); case CL_DEVICE_SUB_GROUP_INDEPENDENT_FORWARD_PROGRESS: DEV_GET_INT_INF(cl_bool); #endif +#if PYOPENCL_CL_VERSION >= 0x3000 + case CL_DEVICE_NUMERIC_VERSION: DEV_GET_INT_INF(cl_version); + case CL_DEVICE_EXTENSIONS_WITH_VERSION: + case CL_DEVICE_ILS_WITH_VERSION: + case CL_DEVICE_BUILT_IN_KERNELS_WITH_VERSION: + case CL_DEVICE_OPENCL_C_ALL_VERSIONS: + case CL_DEVICE_OPENCL_C_FEATURES: + { + std::vector result; + PYOPENCL_GET_VEC_INFO(Device, m_device, param_name, result); + PYOPENCL_RETURN_VECTOR(cl_name_version, result); + } + case CL_DEVICE_ATOMIC_MEMORY_CAPABILITIES: DEV_GET_INT_INF(cl_device_atomic_capabilities); + case CL_DEVICE_ATOMIC_FENCE_CAPABILITIES: DEV_GET_INT_INF(cl_device_atomic_capabilities); + case CL_DEVICE_NON_UNIFORM_WORK_GROUP_SUPPORT: DEV_GET_INT_INF(cl_bool); + case CL_DEVICE_PREFERRED_WORK_GROUP_SIZE_MULTIPLE: DEV_GET_INT_INF(size_t); + case CL_DEVICE_WORK_GROUP_COLLECTIVE_FUNCTIONS_SUPPORT: DEV_GET_INT_INF(cl_bool); + case CL_DEVICE_GENERIC_ADDRESS_SPACE_SUPPORT: DEV_GET_INT_INF(cl_bool); + case CL_DEVICE_DEVICE_ENQUEUE_SUPPORT: DEV_GET_INT_INF(cl_bool); + case CL_DEVICE_PIPE_SUPPORT: DEV_GET_INT_INF(cl_bool); +#endif + #ifdef CL_DEVICE_ME_VERSION_INTEL case CL_DEVICE_ME_VERSION_INTEL: DEV_GET_INT_INF(cl_uint); #endif -- GitLab From 772eaf1356f174bd83d3aa56d4f9ae1668caac1b Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Mon, 14 Sep 2020 17:22:56 -0500 Subject: [PATCH 08/38] Install dev-channel ocl-icd dev channel in CI --- .test-conda-env-py3.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.test-conda-env-py3.yml b/.test-conda-env-py3.yml index 498f1a6b..f57daef5 100644 --- a/.test-conda-env-py3.yml +++ b/.test-conda-env-py3.yml @@ -7,6 +7,7 @@ dependencies: - python=3 - git - numpy +- conda-forge/label/ocl-icd-dev::ocl-icd=3.0.0.dev0 - pocl - mako - pybind11 -- GitLab From 94b466c1eca475582a9e00c88b37ae92271909e6 Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Mon, 14 Sep 2020 21:47:26 -0500 Subject: [PATCH 09/38] Add inventory of missing stuff to wrap_cl --- src/wrap_cl.hpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/wrap_cl.hpp b/src/wrap_cl.hpp index d969f234..70c24abd 100644 --- a/src/wrap_cl.hpp +++ b/src/wrap_cl.hpp @@ -30,6 +30,21 @@ // CL 1.2 undecided: // clSetPrintfCallback +// CL 2.0 missing: +// pipes + +// CL 2.1 missing: +// clGetKernelSubGroupInfo +// clSetDefaultDeviceCommandQueue +// clGetDeviceAndHostTimer +// clGetHostTimer +// clCloneKernel +// clEnqueueSVMMigrateMem + +// CL 3.0 missing: +// clCreateBufferWithProperties +// clCreateImageWithProperties + // {{{ includes #define CL_USE_DEPRECATED_OPENCL_1_1_APIS -- GitLab From 9a201e6375d6332d1b16971c24587df7ceda3f92 Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Mon, 14 Sep 2020 21:48:07 -0500 Subject: [PATCH 10/38] Remove a premature line break --- src/wrap_cl.hpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/wrap_cl.hpp b/src/wrap_cl.hpp index 70c24abd..ded51a42 100644 --- a/src/wrap_cl.hpp +++ b/src/wrap_cl.hpp @@ -3701,8 +3701,7 @@ namespace pyopencl PYOPENCL_GET_OPAQUE_INFO(Program, m_program, param_name, cl_context, context); case CL_PROGRAM_NUM_DEVICES: - PYOPENCL_GET_TYPED_INFO(Program, m_program, param_name, - cl_uint); + PYOPENCL_GET_TYPED_INFO(Program, m_program, param_name, cl_uint); case CL_PROGRAM_DEVICES: { std::vector result; -- GitLab From 47fdd1a55f2d2bfe3c4af4f4a5c0b4e6d227e3ba Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Mon, 14 Sep 2020 21:52:45 -0500 Subject: [PATCH 11/38] 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 From b5d6fcdb3150ea5f9df7edd030b6f9b360fe547f Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Mon, 14 Sep 2020 21:54:21 -0500 Subject: [PATCH 12/38] Add cl_kernel_subgroup_info (CL 2.1) --- doc/make_constants.py | 9 +++++++++ src/wrap_constants.cpp | 12 ++++++++++++ 2 files changed, 21 insertions(+) diff --git a/doc/make_constants.py b/doc/make_constants.py index 28eebe6c..c4919cd0 100644 --- a/doc/make_constants.py +++ b/doc/make_constants.py @@ -30,6 +30,7 @@ cl_11 = ("CL_1.1", "0.92") cl_12 = ("CL_1.2", "2011.2") cl_12_2015 = ("CL_1.2", "2015.2") cl_20 = ("CL_2.0", "2015.2") +cl_21_late = ("CL_2.1", "2020.3") cl_21 = ("CL_2.1", "2016.2") cl_22 = ("CL_2.1", "2020.3") cl_30 = ("CL_3.0", "2020.3") @@ -268,6 +269,14 @@ const_ext_lookup = { "GLOBAL_WORK_SIZE": cl_12, }, + cl.kernel_sub_group_info: { + "MAX_SUB_GROUP_SIZE_FOR_NDRANGE": cl_21_late, + "SUB_GROUP_COUNT_FOR_NDRANGE": cl_21_late, + "LOCAL_SIZE_FOR_SUB_GROUP_COUNT": cl_21_late, + "MAX_NUM_SUB_GROUPS": cl_21_late, + "COMPILE_NUM_SUB_GROUPS": cl_21_late, + }, + cl.addressing_mode: { "MIRRORED_REPEAT": cl_11, }, diff --git a/src/wrap_constants.cpp b/src/wrap_constants.cpp index a5abb38a..1c93bdf0 100644 --- a/src/wrap_constants.cpp +++ b/src/wrap_constants.cpp @@ -75,6 +75,7 @@ namespace class kernel_arg_access_qualifier { }; class kernel_arg_type_qualifier { }; class kernel_work_group_info { }; + class kernel_sub_group_info { }; class event_info { }; class command_type { }; class command_execution_status { }; @@ -966,6 +967,17 @@ void pyopencl_expose_constants(py::module &m) #endif } + { + py::class_ cls(m, "kernel_sub_group_info"); +#if PYOPENCL_CL_VERSION >= 0x2010 + ADD_ATTR(KERNEL_, MAX_SUB_GROUP_SIZE_FOR_NDRANGE); + ADD_ATTR(KERNEL_, SUB_GROUP_COUNT_FOR_NDRANGE); + ADD_ATTR(KERNEL_, LOCAL_SIZE_FOR_SUB_GROUP_COUNT); + ADD_ATTR(KERNEL_, MAX_NUM_SUB_GROUPS); + ADD_ATTR(KERNEL_, COMPILE_NUM_SUB_GROUPS); +#endif + } + { py::class_ cls(m, "event_info"); ADD_ATTR(EVENT_, COMMAND_QUEUE); -- GitLab From 3b3e2cc46efc06e37b26c23603b001c96e6db5f9 Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Mon, 14 Sep 2020 21:55:29 -0500 Subject: [PATCH 13/38] Add missing Program GetInfos --- doc/make_constants.py | 3 +++ src/wrap_cl.hpp | 9 +++++++++ src/wrap_constants.cpp | 7 +++++++ 3 files changed, 19 insertions(+) diff --git a/doc/make_constants.py b/doc/make_constants.py index c4919cd0..0f78f019 100644 --- a/doc/make_constants.py +++ b/doc/make_constants.py @@ -319,6 +319,9 @@ const_ext_lookup = { cl.program_info: { "NUM_KERNELS": cl_12, "KERNEL_NAMES": cl_12, + "PROGRAM_IL": cl_21_late, + "SCOPE_GLOBAL_CTORS_PRESENT": cl_22, + "SCOPE_GLOBAL_DTORS_PRESENT": cl_22, }, cl.program_build_info: { diff --git a/src/wrap_cl.hpp b/src/wrap_cl.hpp index 05c746a5..cd350fe7 100644 --- a/src/wrap_cl.hpp +++ b/src/wrap_cl.hpp @@ -3773,6 +3773,15 @@ namespace pyopencl case CL_PROGRAM_KERNEL_NAMES: PYOPENCL_GET_STR_INFO(Program, m_program, param_name); #endif +#if PYOPENCL_CL_VERSION >= 0x2010 + case CL_PROGRAM_IL: + PYOPENCL_GET_STR_INFO(Program, m_program, param_name); +#endif +#if PYOPENCL_CL_VERSION >= 0x2020 + case CL_PROGRAM_SCOPE_GLOBAL_CTORS_PRESENT: + case CL_PROGRAM_SCOPE_GLOBAL_DTORS_PRESENT: + PYOPENCL_GET_TYPED_INFO(Program, m_program, param_name, cl_bool); +#endif default: throw error("Program.get_info", CL_INVALID_VALUE); diff --git a/src/wrap_constants.cpp b/src/wrap_constants.cpp index 1c93bdf0..67c14a56 100644 --- a/src/wrap_constants.cpp +++ b/src/wrap_constants.cpp @@ -868,6 +868,13 @@ void pyopencl_expose_constants(py::module &m) #if PYOPENCL_CL_VERSION >= 0x1020 ADD_ATTR(PROGRAM_, NUM_KERNELS); ADD_ATTR(PROGRAM_, KERNEL_NAMES); +#endif +#if PYOPENCL_CL_VERSION >= 0x2010 + ADD_ATTR(PROGRAM_, IL); +#endif +#if PYOPENCL_CL_VERSION >= 0x2020 + ADD_ATTR(PROGRAM_, SCOPE_GLOBAL_CTORS_PRESENT); + ADD_ATTR(PROGRAM_, SCOPE_GLOBAL_DTORS_PRESENT); #endif } -- GitLab From 82f1dc64e2968509ce9976dcc7ac7e28b64ef94d Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Mon, 14 Sep 2020 21:55:58 -0500 Subject: [PATCH 14/38] Implement missing CommandQueue GetInfos --- src/wrap_cl.hpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/wrap_cl.hpp b/src/wrap_cl.hpp index cd350fe7..8e3fb72e 100644 --- a/src/wrap_cl.hpp +++ b/src/wrap_cl.hpp @@ -1509,6 +1509,24 @@ namespace pyopencl case CL_QUEUE_PROPERTIES: PYOPENCL_GET_TYPED_INFO(CommandQueue, m_queue, param_name, cl_command_queue_properties); +#if PYOPENCL_CL_VERSION >= 0x2000 + case CL_QUEUE_SIZE: + PYOPENCL_GET_TYPED_INFO(CommandQueue, m_queue, param_name, + cl_uint); +#endif +#if PYOPENCL_CL_VERSION >= 0x2010 + case CL_QUEUE_DEVICE_DEFAULT: + PYOPENCL_GET_OPAQUE_INFO( + CommandQueue, m_queue, param_name, cl_command_queue, command_queue); +#endif +#if PYOPENCL_CL_VERSION >= 0x3000 + case CL_QUEUE_PROPERTIES_ARRAY: + { + std::vector result; + PYOPENCL_GET_VEC_INFO(CommandQueue, m_queue, param_name, result); + PYOPENCL_RETURN_VECTOR(cl_queue_properties, result); + } +#endif default: throw error("CommandQueue.get_info", CL_INVALID_VALUE); -- GitLab From b19315fa2239bcd9ab62a1f1a0681d5b5ebf91bb Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Mon, 14 Sep 2020 21:56:24 -0500 Subject: [PATCH 15/38] Implement missing MemObject GetInfos --- src/wrap_cl.hpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/wrap_cl.hpp b/src/wrap_cl.hpp index 8e3fb72e..1f21237d 100644 --- a/src/wrap_cl.hpp +++ b/src/wrap_cl.hpp @@ -4870,6 +4870,19 @@ namespace pyopencl PYOPENCL_GET_TYPED_INFO(MemObject, data(), param_name, size_t); #endif +#if PYOPENCL_CL_VERSION >= 0x2000 + case CL_MEM_USES_SVM_POINTER: + PYOPENCL_GET_TYPED_INFO(MemObject, data(), param_name, + cl_bool); +#endif +#if PYOPENCL_CL_VERSION >= 0x3000 + case CL_MEM_PROPERTIES: + { + std::vector result; + PYOPENCL_GET_VEC_INFO(MemObject, data(), param_name, result); + PYOPENCL_RETURN_VECTOR(cl_mem_properties, result); + } +#endif default: throw error("MemoryObjectHolder.get_info", CL_INVALID_VALUE); -- GitLab From 93350c19b6d505cb3a54da1a1a6ffc9f1bd35360 Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Mon, 14 Sep 2020 21:59:17 -0500 Subject: [PATCH 16/38] Add some missing sampler/channel stuff --- doc/make_constants.py | 14 +++++++++++--- src/wrap_cl.hpp | 17 +++++++++++++++++ src/wrap_constants.cpp | 13 +++++++++++++ 3 files changed, 41 insertions(+), 3 deletions(-) diff --git a/doc/make_constants.py b/doc/make_constants.py index 0f78f019..45a3009f 100644 --- a/doc/make_constants.py +++ b/doc/make_constants.py @@ -251,6 +251,11 @@ const_ext_lookup = { "INTEROP_USER_SYNC": cl_12, }, + cl.channel_type: { + "UNORM_INT24": ("CL_1.2", "2020.3"), + "UNORM_INT_101010_2": ("CL_2.1", "2020.3"), + }, + cl.channel_order: { "Rx": cl_11, "RGx": cl_11, @@ -282,9 +287,12 @@ const_ext_lookup = { }, cl.sampler_info: { - "MIP_FILTER_MODE": cl_20, - "LOD_MIN": cl_20, - "LOD_MAX": cl_20, + "MIP_FILTER_MODE": ("(deprecated)", "2015.2"), + "LOD_MIN": ("(deprecated)", "2015.2"), + "LOD_MAX": ("(deprecated)", "2015.2"), + "MIP_FILTER_MODE_KHR": ("cl_khr_mipmap_image", "2020.3"), + "LOD_MIN_KHR": ("cl_khr_mipmap_image", "2020.3"), + "LOD_MAX_KHR": ("cl_khr_mipmap_image", "2020.3"), "PROPERTIES": cl_30, }, diff --git a/src/wrap_cl.hpp b/src/wrap_cl.hpp index 1f21237d..4ffb10a4 100644 --- a/src/wrap_cl.hpp +++ b/src/wrap_cl.hpp @@ -3664,6 +3664,23 @@ namespace pyopencl case CL_SAMPLER_NORMALIZED_COORDS: PYOPENCL_GET_TYPED_INFO(Sampler, m_sampler, param_name, cl_bool); +#if PYOPENCL_CL_VERSION >= 0x3000 + case CL_SAMPLER_PROPERTIES: + { + std::vector result; + PYOPENCL_GET_VEC_INFO(Sampler, m_sampler, param_name, result); + PYOPENCL_RETURN_VECTOR(cl_sampler_properties, result); + } +#endif + +#ifdef CL_SAMPLER_MIP_FILTER_MODE_KHR + case CL_SAMPLER_MIP_FILTER_MODE_KHR: + PYOPENCL_GET_TYPED_INFO(Sampler, m_sampler, param_name, + cl_filter_mode); + case CL_SAMPLER_LOD_MIN_KHR: + case CL_SAMPLER_LOD_MAX_KHR: + PYOPENCL_GET_TYPED_INFO(Sampler, m_sampler, param_name, float); +#endif default: throw error("Sampler.get_info", CL_INVALID_VALUE); diff --git a/src/wrap_constants.cpp b/src/wrap_constants.cpp index 67c14a56..c8d904cb 100644 --- a/src/wrap_constants.cpp +++ b/src/wrap_constants.cpp @@ -740,6 +740,12 @@ void pyopencl_expose_constants(py::module &m) ADD_ATTR( , UNSIGNED_INT32); ADD_ATTR( , HALF_FLOAT); ADD_ATTR( , FLOAT); +#if PYOPENCL_CL_VERSION >= 0x1020 + ADD_ATTR( , UNORM_INT24); +#endif +#if PYOPENCL_CL_VERSION >= 0x2010 + ADD_ATTR( , UNORM_INT_101010_2); +#endif } { @@ -838,6 +844,13 @@ void pyopencl_expose_constants(py::module &m) #if PYOPENCL_CL_VERSION >= 0x3000 ADD_ATTR(SAMPLER_, PROPERTIES); #endif +// {{{ cl_khr_mipmap_image +#ifdef CL_SAMPLER_MIP_FILTER_MODE_KHR + ADD_ATTR(SAMPLER_, MIP_FILTER_MODE_KHR); + ADD_ATTR(SAMPLER_, LOD_MIN_KHR); + ADD_ATTR(SAMPLER_, LOD_MAX_KHR); +#endif +// }}} } { -- GitLab From 6b64e8ae346e06968910b8b43c02d0c6a96212e5 Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Mon, 14 Sep 2020 22:12:10 -0500 Subject: [PATCH 17/38] Accommodate Debian's broken CL3 headers --- doc/make_constants.py | 2 +- src/wrap_constants.cpp | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/doc/make_constants.py b/doc/make_constants.py index 45a3009f..5a725810 100644 --- a/doc/make_constants.py +++ b/doc/make_constants.py @@ -204,7 +204,7 @@ const_ext_lookup = { "WORK_GROUP_COLLECTIVE_FUNCTIONS_SUPPORT": cl_30, "GENERIC_ADDRESS_SPACE_SUPPORT": cl_30, "OPENCL_C_FEATURES": cl_30, - "DEVICE_ENQUEUE_SUPPORT": cl_30, + "DEVICE_ENQUEUE_CAPABILITIES": cl_30, "PIPE_SUPPORT": cl_30, }, diff --git a/src/wrap_constants.cpp b/src/wrap_constants.cpp index c8d904cb..1ea67fb4 100644 --- a/src/wrap_constants.cpp +++ b/src/wrap_constants.cpp @@ -500,7 +500,12 @@ void pyopencl_expose_constants(py::module &m) ADD_ATTR(DEVICE_, WORK_GROUP_COLLECTIVE_FUNCTIONS_SUPPORT); ADD_ATTR(DEVICE_, GENERIC_ADDRESS_SPACE_SUPPORT); ADD_ATTR(DEVICE_, OPENCL_C_FEATURES); - ADD_ATTR(DEVICE_, DEVICE_ENQUEUE_SUPPORT); +#ifdef CL_DEVICE_DEVICE_ENQUEUE_SUPPORT + // some busted headers shipped by Debian have this + cls.attr("DEVICE_ENQUEUE_CAPABILITIES") = CL_DEVICE_DEVICE_ENQUEUE_SUPPORT; +#else + ADD_ATTR(DEVICE_, DEVICE_ENQUEUE_CAPABILITIES); +#endif ADD_ATTR(DEVICE_, PIPE_SUPPORT); #endif /* cl_intel_advanced_motion_estimation */ -- GitLab From 5af2d551d5f9dea5d432b21a20a5776eaade3f27 Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Mon, 14 Sep 2020 22:38:30 -0500 Subject: [PATCH 18/38] Add cl.device_enqueue_capabilities, more old CL3 header accommodation --- doc/make_constants.py | 5 +++++ pyopencl/__init__.py | 2 ++ src/wrap_cl.hpp | 7 +++++++ src/wrap_constants.cpp | 8 ++++++++ 4 files changed, 22 insertions(+) diff --git a/doc/make_constants.py b/doc/make_constants.py index 5a725810..32b72ce1 100644 --- a/doc/make_constants.py +++ b/doc/make_constants.py @@ -459,6 +459,11 @@ const_ext_lookup = { "SCOPE_ALL_DEVICES": cl_30, }, + cl.device_enqueue_capabilities: { + "SUPPORTED": cl_30, + "REPLACEABLE_DEFAULT": cl_30, + }, + cl.profiling_info: { "COMPLETE": cl_20, }, diff --git a/pyopencl/__init__.py b/pyopencl/__init__.py index 1fa14a7b..b6c1ac26 100644 --- a/pyopencl/__init__.py +++ b/pyopencl/__init__.py @@ -105,6 +105,7 @@ from pyopencl._cl import ( # noqa: F401 device_partition_property, device_affinity_domain, device_atomic_capabilities, + device_enqueue_capabilities, version_bits, khronos_vendor_id, @@ -240,6 +241,7 @@ BITFIELD_CONSTANT_CLASSES = ( _cl.queue_properties, _cl.svm_mem_flags, _cl.device_atomic_capabilities, + _cl.device_enqueue_capabilities, _cl.version_bits, ) diff --git a/src/wrap_cl.hpp b/src/wrap_cl.hpp index 4ffb10a4..e9a84264 100644 --- a/src/wrap_cl.hpp +++ b/src/wrap_cl.hpp @@ -965,7 +965,14 @@ namespace pyopencl case CL_DEVICE_PREFERRED_WORK_GROUP_SIZE_MULTIPLE: DEV_GET_INT_INF(size_t); case CL_DEVICE_WORK_GROUP_COLLECTIVE_FUNCTIONS_SUPPORT: DEV_GET_INT_INF(cl_bool); case CL_DEVICE_GENERIC_ADDRESS_SPACE_SUPPORT: DEV_GET_INT_INF(cl_bool); + +#ifdef CL_DEVICE_DEVICE_ENQUEUE_SUPPORT case CL_DEVICE_DEVICE_ENQUEUE_SUPPORT: DEV_GET_INT_INF(cl_bool); +#endif +#ifdef CL_DEVICE_DEVICE_ENQUEUE_CAPABILITIES + case CL_DEVICE_DEVICE_ENQUEUE_CAPABILITIES: DEV_GET_INT_INF(cl_device_enqueue_capabilities); +#endif + case CL_DEVICE_PIPE_SUPPORT: DEV_GET_INT_INF(cl_bool); #endif diff --git a/src/wrap_constants.cpp b/src/wrap_constants.cpp index 1ea67fb4..785ea7dc 100644 --- a/src/wrap_constants.cpp +++ b/src/wrap_constants.cpp @@ -86,6 +86,7 @@ namespace class device_partition_property { }; class device_affinity_domain { }; class device_atomic_capabilities { }; + class device_enqueue_capabilities { }; class version_bits { }; class khronos_vendor_id { }; @@ -1129,6 +1130,13 @@ void pyopencl_expose_constants(py::module &m) ADD_ATTR(DEVICE_ATOMIC_, SCOPE_ALL_DEVICES); #endif } + { + py::class_ cls(m, "device_enqueue_capabilities"); +#if (PYOPENCL_CL_VERSION >= 0x3000) && defined(CL_DEVICE_DEVICE_ENQUEUE_CAPABILITIES) + ADD_ATTR(DEVICE_ENQUEUE, SUPPORTED); + ADD_ATTR(DEVICE_ENQUEUE, REPLACEABLE_DEFAULT); +#endif + } { py::class_ cls(m, "version_bits"); -- GitLab From a680911ed44aee6b1d2b1e9ccc5f7012c3d5c681 Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Mon, 14 Sep 2020 23:06:19 -0500 Subject: [PATCH 19/38] Add missing underscores in device_enqueue_capabilities --- src/wrap_constants.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/wrap_constants.cpp b/src/wrap_constants.cpp index 785ea7dc..fbd23f63 100644 --- a/src/wrap_constants.cpp +++ b/src/wrap_constants.cpp @@ -1133,8 +1133,8 @@ void pyopencl_expose_constants(py::module &m) { py::class_ cls(m, "device_enqueue_capabilities"); #if (PYOPENCL_CL_VERSION >= 0x3000) && defined(CL_DEVICE_DEVICE_ENQUEUE_CAPABILITIES) - ADD_ATTR(DEVICE_ENQUEUE, SUPPORTED); - ADD_ATTR(DEVICE_ENQUEUE, REPLACEABLE_DEFAULT); + ADD_ATTR(DEVICE_ENQUEUE_, SUPPORTED); + ADD_ATTR(DEVICE_ENQUEUE_, REPLACEABLE_DEFAULT); #endif } -- GitLab From 1e2038e61e979a12491faaadf8b5810251734265 Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Mon, 14 Sep 2020 23:10:06 -0500 Subject: [PATCH 20/38] Fix typos in device_enqueue_capabilities --- src/wrap_constants.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/wrap_constants.cpp b/src/wrap_constants.cpp index fbd23f63..19c6f336 100644 --- a/src/wrap_constants.cpp +++ b/src/wrap_constants.cpp @@ -1133,8 +1133,8 @@ void pyopencl_expose_constants(py::module &m) { py::class_ cls(m, "device_enqueue_capabilities"); #if (PYOPENCL_CL_VERSION >= 0x3000) && defined(CL_DEVICE_DEVICE_ENQUEUE_CAPABILITIES) - ADD_ATTR(DEVICE_ENQUEUE_, SUPPORTED); - ADD_ATTR(DEVICE_ENQUEUE_, REPLACEABLE_DEFAULT); + ADD_ATTR(DEVICE_QUEUE_, SUPPORTED); + ADD_ATTR(DEVICE_QUEUE_, REPLACEABLE_DEFAULT); #endif } -- GitLab From b3283e158f6144ffd6997d3f0a7d2d505b462b26 Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Mon, 14 Sep 2020 23:27:10 -0500 Subject: [PATCH 21/38] Typo: device_enqueue_capabilities -> device_device_enqueue_capabilities --- doc/make_constants.py | 2 +- pyopencl/__init__.py | 4 ++-- src/wrap_cl.hpp | 2 +- src/wrap_constants.cpp | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/doc/make_constants.py b/doc/make_constants.py index 32b72ce1..5f6f820b 100644 --- a/doc/make_constants.py +++ b/doc/make_constants.py @@ -459,7 +459,7 @@ const_ext_lookup = { "SCOPE_ALL_DEVICES": cl_30, }, - cl.device_enqueue_capabilities: { + cl.device_device_enqueue_capabilities: { "SUPPORTED": cl_30, "REPLACEABLE_DEFAULT": cl_30, }, diff --git a/pyopencl/__init__.py b/pyopencl/__init__.py index b6c1ac26..a0ddefe5 100644 --- a/pyopencl/__init__.py +++ b/pyopencl/__init__.py @@ -105,7 +105,7 @@ from pyopencl._cl import ( # noqa: F401 device_partition_property, device_affinity_domain, device_atomic_capabilities, - device_enqueue_capabilities, + device_device_enqueue_capabilities, version_bits, khronos_vendor_id, @@ -241,7 +241,7 @@ BITFIELD_CONSTANT_CLASSES = ( _cl.queue_properties, _cl.svm_mem_flags, _cl.device_atomic_capabilities, - _cl.device_enqueue_capabilities, + _cl.device_device_enqueue_capabilities, _cl.version_bits, ) diff --git a/src/wrap_cl.hpp b/src/wrap_cl.hpp index e9a84264..768a1fba 100644 --- a/src/wrap_cl.hpp +++ b/src/wrap_cl.hpp @@ -970,7 +970,7 @@ namespace pyopencl case CL_DEVICE_DEVICE_ENQUEUE_SUPPORT: DEV_GET_INT_INF(cl_bool); #endif #ifdef CL_DEVICE_DEVICE_ENQUEUE_CAPABILITIES - case CL_DEVICE_DEVICE_ENQUEUE_CAPABILITIES: DEV_GET_INT_INF(cl_device_enqueue_capabilities); + case CL_DEVICE_DEVICE_ENQUEUE_CAPABILITIES: DEV_GET_INT_INF(cl_device_device_enqueue_capabilities); #endif case CL_DEVICE_PIPE_SUPPORT: DEV_GET_INT_INF(cl_bool); diff --git a/src/wrap_constants.cpp b/src/wrap_constants.cpp index 19c6f336..57d435cd 100644 --- a/src/wrap_constants.cpp +++ b/src/wrap_constants.cpp @@ -86,7 +86,7 @@ namespace class device_partition_property { }; class device_affinity_domain { }; class device_atomic_capabilities { }; - class device_enqueue_capabilities { }; + class device_device_enqueue_capabilities { }; class version_bits { }; class khronos_vendor_id { }; @@ -1131,7 +1131,7 @@ void pyopencl_expose_constants(py::module &m) #endif } { - py::class_ cls(m, "device_enqueue_capabilities"); + py::class_ cls(m, "device_device_enqueue_capabilities"); #if (PYOPENCL_CL_VERSION >= 0x3000) && defined(CL_DEVICE_DEVICE_ENQUEUE_CAPABILITIES) ADD_ATTR(DEVICE_QUEUE_, SUPPORTED); ADD_ATTR(DEVICE_QUEUE_, REPLACEABLE_DEFAULT); -- GitLab From ec6b828b8774a95c1c2781d6d433ee7a4267a148 Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Mon, 14 Sep 2020 23:32:10 -0500 Subject: [PATCH 22/38] Export kernel_sub_group_info --- pyopencl/__init__.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pyopencl/__init__.py b/pyopencl/__init__.py index a0ddefe5..ac7760f8 100644 --- a/pyopencl/__init__.py +++ b/pyopencl/__init__.py @@ -96,6 +96,7 @@ from pyopencl._cl import ( # noqa: F401 kernel_arg_access_qualifier, kernel_arg_type_qualifier, kernel_work_group_info, + kernel_sub_group_info, event_info, command_type, -- GitLab From 4a552a8030387662177a89ad8b2511ac854e412b Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Tue, 15 Sep 2020 09:35:42 -0500 Subject: [PATCH 23/38] Fix rst directive typo in runtime_const.rst --- doc/runtime_const.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/runtime_const.rst b/doc/runtime_const.rst index dc926360..864a641c 100644 --- a/doc/runtime_const.rst +++ b/doc/runtime_const.rst @@ -12,7 +12,7 @@ OpenCL Runtime: Constants Only available with OpenCL 3.0 or newer. - .. versionaddedd:: 2020.3 + .. versionadded:: 2020.3 .. method:: __init__(version, name) .. attribute:: version -- GitLab From afc8ba24ddcd335f64beadbe9c184d32f56ecbbb Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Tue, 15 Sep 2020 09:37:03 -0500 Subject: [PATCH 24/38] Don't force installation of ocl-icd on Mac in Github CI --- .github/workflows/ci.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e7520a8c..914c5f7d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -66,7 +66,8 @@ jobs: - name: "Main Script" run: | export CC=gcc - CONDA_ENVIRONMENT=.test-conda-env-py3.yml + CONDA_ENVIRONMENT=.test-conda-env.yml + grep -v ocl-icd .test-conda-env-py3.yml > $CONDA_ENVIRONMENT curl -L -O -k https://gitlab.tiker.net/inducer/ci-support/raw/master/build-and-test-py-project-within-miniconda.sh ./configure.py --cxxflags= --ldflags= --cl-libname=OpenCL . ./build-and-test-py-project-within-miniconda.sh -- GitLab From d501579d0435631dc78b275866d3d4d67d29c92e Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Tue, 15 Sep 2020 09:38:11 -0500 Subject: [PATCH 25/38] Don't force installation of ocl-icd on Mac in Gitlab CI --- .gitlab-ci.yml | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 29c364fc..76b8a07d 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -154,12 +154,13 @@ Python 3 POCL (+GL and special functions): junit: test/pytest.xml Python 3 Conda Apple: - script: - - CONDA_ENVIRONMENT=.test-conda-env-py3.yml - - export CC=gcc - - curl -L -O -k https://gitlab.tiker.net/inducer/ci-support/raw/master/build-and-test-py-project-within-miniconda.sh - - "./configure.py --cxxflags= --ldflags= --cl-libname=OpenCL" - - ". ./build-and-test-py-project-within-miniconda.sh" + script: | + CONDA_ENVIRONMENT=.test-conda-env.yml + grep -v ocl-icd .test-conda-env-py3.yml > $CONDA_ENVIRONMENT + export CC=gcc + curl -L -O -k https://gitlab.tiker.net/inducer/ci-support/raw/master/build-and-test-py-project-within-miniconda.sh + ./configure.py --cxxflags= --ldflags= --cl-libname=OpenCL + . ./build-and-test-py-project-within-miniconda.sh tags: - apple except: -- GitLab From 4f0b98f0f5b61f90737326b5a792f0c11ae35a6c Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Wed, 16 Sep 2020 13:39:54 -0500 Subject: [PATCH 26/38] Remove PYOPENCL_STD_MOVE_IF_NEW_BUF_INTF --- src/wrap_cl.hpp | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/src/wrap_cl.hpp b/src/wrap_cl.hpp index 768a1fba..75a08a47 100644 --- a/src/wrap_cl.hpp +++ b/src/wrap_cl.hpp @@ -127,13 +127,6 @@ #endif -#if (PY_VERSION_HEX >= 0x03000000) or defined(PYPY_VERSION) -#define PYOPENCL_STD_MOVE_IF_NEW_BUF_INTF(s) std::move(s) -#else -#define PYOPENCL_STD_MOVE_IF_NEW_BUF_INTF(s) (s) -#endif - - #if defined(_WIN32) // MSVC does not understand variable-length arrays #define PYOPENCL_STACK_CONTAINER(TYPE, NAME, COUNT) std::vector NAME(COUNT) @@ -1983,12 +1976,12 @@ namespace pyopencl if (retain) PYOPENCL_CALL_GUARDED(clRetainMemObject, (mem)); - m_hostbuf = PYOPENCL_STD_MOVE_IF_NEW_BUF_INTF(hostbuf); + m_hostbuf = std::move(hostbuf); } memory_object(memory_object &src) : m_valid(true), m_mem(src.m_mem), - m_hostbuf(PYOPENCL_STD_MOVE_IF_NEW_BUF_INTF(src.m_hostbuf)) + m_hostbuf(std::move(src.m_hostbuf)) { PYOPENCL_CALL_GUARDED(clRetainMemObject, (m_mem)); } @@ -2126,7 +2119,7 @@ namespace pyopencl { public: buffer(cl_mem mem, bool retain, hostbuf_t hostbuf=hostbuf_t()) - : memory_object(mem, retain, PYOPENCL_STD_MOVE_IF_NEW_BUF_INTF(hostbuf)) + : memory_object(mem, retain, std::move(hostbuf)) { } #if PYOPENCL_CL_VERSION >= 0x1010 @@ -2232,7 +2225,7 @@ namespace pyopencl try { - return new buffer(mem, false, PYOPENCL_STD_MOVE_IF_NEW_BUF_INTF(retained_buf_obj)); + return new buffer(mem, false, std::move(retained_buf_obj)); } catch (...) { @@ -2545,7 +2538,7 @@ namespace pyopencl { public: image(cl_mem mem, bool retain, hostbuf_t hostbuf=hostbuf_t()) - : memory_object(mem, retain, PYOPENCL_STD_MOVE_IF_NEW_BUF_INTF(hostbuf)) + : memory_object(mem, retain, std::move(hostbuf)) { } py::object get_image_info(cl_image_info param_name) const @@ -2795,7 +2788,7 @@ namespace pyopencl try { - return new image(mem, false, PYOPENCL_STD_MOVE_IF_NEW_BUF_INTF(retained_buf_obj)); + return new image(mem, false, std::move(retained_buf_obj)); } catch (...) { @@ -2848,7 +2841,7 @@ namespace pyopencl try { - return new image(mem, false, PYOPENCL_STD_MOVE_IF_NEW_BUF_INTF(retained_buf_obj)); + return new image(mem, false, std::move(retained_buf_obj)); } catch (...) { @@ -4572,7 +4565,7 @@ namespace pyopencl { public: gl_buffer(cl_mem mem, bool retain, hostbuf_t hostbuf=hostbuf_t()) - : memory_object(mem, retain, PYOPENCL_STD_MOVE_IF_NEW_BUF_INTF(hostbuf)) + : memory_object(mem, retain, std::move(hostbuf)) { } }; @@ -4583,7 +4576,7 @@ namespace pyopencl { public: gl_renderbuffer(cl_mem mem, bool retain, hostbuf_t hostbuf=hostbuf_t()) - : memory_object(mem, retain, PYOPENCL_STD_MOVE_IF_NEW_BUF_INTF(hostbuf)) + : memory_object(mem, retain, std::move(hostbuf)) { } }; @@ -4594,7 +4587,7 @@ namespace pyopencl { public: gl_texture(cl_mem mem, bool retain, hostbuf_t hostbuf=hostbuf_t()) - : image(mem, retain, PYOPENCL_STD_MOVE_IF_NEW_BUF_INTF(hostbuf)) + : image(mem, retain, std::move(hostbuf)) { } py::object get_gl_texture_info(cl_gl_texture_info param_name) -- GitLab From 530845d345b1bd358355f64c941ae4fb67cf868c Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Wed, 16 Sep 2020 14:09:17 -0500 Subject: [PATCH 27/38] Add pipe support --- doc/runtime_memory.rst | 20 +++++++++++ pyopencl/__init__.py | 7 +++- src/wrap_cl.hpp | 79 ++++++++++++++++++++++++++++++++++++++++-- src/wrap_cl_part_2.cpp | 30 ++++++++++++++++ 4 files changed, 132 insertions(+), 4 deletions(-) diff --git a/doc/runtime_memory.rst b/doc/runtime_memory.rst index ce2ee222..fc121554 100644 --- a/doc/runtime_memory.rst +++ b/doc/runtime_memory.rst @@ -381,3 +381,23 @@ Samplers |comparable| +Pipes +----- + +.. class:: Pipe(context, flags, packet_size, max_packets, properties) + + See :class:`mem_flags` for values of *flags*. + + :arg properties: a sequence + of keys and values from :class:`pipe_properties` as accepted + by :c:func:`clCreatePipe`. The trailing *0* is added automatically + and does not need to be included. + + This function Requires OpenCL 2 or newer. + + .. versionadded:: 2020.3 + + .. method:: get_pipe_info(param) + + See :class:`pipe_info` for values of *param*. + diff --git a/pyopencl/__init__.py b/pyopencl/__init__.py index ac7760f8..91d6af10 100644 --- a/pyopencl/__init__.py +++ b/pyopencl/__init__.py @@ -156,6 +156,10 @@ from pyopencl._cl import ( # noqa: F401 Image, Sampler, + + # This class is available unconditionally, even though CL only + # has it on CL2.0 and newer. + Pipe, ) try: @@ -1014,7 +1018,7 @@ def _add_functionality(): class _ImageInfoGetter: def __init__(self, event): from warnings import warn - warn("Image.image.attr is deprecated. " + warn("Image.image.attr is deprecated and will go away in 2021. " "Use Image.attr directly, instead.") self.event = event @@ -1297,6 +1301,7 @@ def _add_functionality(): _cl.MemoryObjectHolder: (MemoryObjectHolder.get_info, _cl.mem_info, []), Image: (_cl.Image.get_image_info, _cl.image_info, []), + Pipe: (_cl.Image.get_pipe_info, _cl.pipe_info, []), Program: (Program.get_info, _cl.program_info, []), Kernel: (Kernel.get_info, _cl.kernel_info, []), _cl.Sampler: (Sampler.get_info, _cl.sampler_info, []), diff --git a/src/wrap_cl.hpp b/src/wrap_cl.hpp index 75a08a47..7cf2dc07 100644 --- a/src/wrap_cl.hpp +++ b/src/wrap_cl.hpp @@ -30,8 +30,7 @@ // CL 1.2 undecided: // clSetPrintfCallback -// CL 2.0 missing: -// pipes +// CL 2.0 complete // CL 2.1 missing: // clGetKernelSubGroupInfo @@ -2580,7 +2579,7 @@ namespace pyopencl #endif default: - throw error("MemoryObject.get_image_info", CL_INVALID_VALUE); + throw error("Image.get_image_info", CL_INVALID_VALUE); } } }; @@ -3059,6 +3058,80 @@ namespace pyopencl // }}} + // {{{ pipe + + class pipe : public memory_object + { + public: + pipe(cl_mem mem, bool retain) + : memory_object(mem, retain) + { } + + py::object get_pipe_info(cl_pipe_info param_name) const + { +#if PYOPENCL_CL_VERSION >= 0x2000 + switch (param_name) + { + case CL_PIPE_PACKET_SIZE: + case CL_PIPE_MAX_PACKETS: + PYOPENCL_GET_TYPED_INFO(Pipe, data(), param_name, cl_uint); + + default: + throw error("Pipe.get_pipe_info", CL_INVALID_VALUE); + } +#else + throw error("Pipes not available. PyOpenCL was not compiled against a CL2+ header.", + CL_INVALID_VALUE); +#endif + } + }; + +#if PYOPENCL_CL_VERSION >= 0x2000 + inline + pipe *create_pipe( + context const &ctx, + cl_mem_flags flags, + cl_uint pipe_packet_size, + cl_uint pipe_max_packets, + py::sequence py_props) + { + PYOPENCL_STACK_CONTAINER(cl_pipe_properties, props, py::len(py_props) + 1); + { + size_t i = 0; + for (auto prop: py_props) + props[i++] = py::cast(prop); + props[i++] = 0; + } + + cl_int status_code; + PYOPENCL_PRINT_CALL_TRACE("clCreatePipe"); + + cl_mem mem = clCreatePipe( + ctx.data(), + flags, + pipe_packet_size, + pipe_max_packets, + PYOPENCL_STACK_CONTAINER_GET_PTR(props), + &status_code); + + if (status_code != CL_SUCCESS) + throw pyopencl::error("Pipe", status_code); + + try + { + return new pipe(mem, false); + } + catch (...) + { + PYOPENCL_CALL_GUARDED(clReleaseMemObject, (mem)); + throw; + } +} +#endif + + // }}} + + // {{{ maps class memory_map { diff --git a/src/wrap_cl_part_2.cpp b/src/wrap_cl_part_2.cpp index 6735d41f..df56d0af 100644 --- a/src/wrap_cl_part_2.cpp +++ b/src/wrap_cl_part_2.cpp @@ -222,6 +222,36 @@ void pyopencl_expose_part_2(py::module &m) // }}} + // {{{ pipe + + { + typedef pyopencl::pipe cls; + py::class_(m, "Pipe", py::dynamic_attr()) +#if PYOPENCL_CL_VERSION >= 0x2000 + .def( + py::init( + []( + context const &ctx, + cl_mem_flags flags, + cl_uint pipe_packet_size, + cl_uint pipe_max_packets, + py::sequence py_props) + { + return create_pipe(ctx, flags, pipe_packet_size, pipe_max_packets, py_props); + }), + py::arg("context"), + py::arg("flags"), + py::arg("packet_size"), + py::arg("max_packets"), + py::arg("properties") + ) +#endif + .DEF_SIMPLE_METHOD(get_pipe_info) + ; + } + + // }}} + // {{{ memory_map { typedef memory_map cls; -- GitLab From f1124b5fc7d44fa98a99688fad14d6ff2c7d94aa Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Wed, 16 Sep 2020 14:19:37 -0500 Subject: [PATCH 28/38] Fix reference to get_pipe_info --- pyopencl/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyopencl/__init__.py b/pyopencl/__init__.py index 91d6af10..4994391b 100644 --- a/pyopencl/__init__.py +++ b/pyopencl/__init__.py @@ -1301,7 +1301,7 @@ def _add_functionality(): _cl.MemoryObjectHolder: (MemoryObjectHolder.get_info, _cl.mem_info, []), Image: (_cl.Image.get_image_info, _cl.image_info, []), - Pipe: (_cl.Image.get_pipe_info, _cl.pipe_info, []), + Pipe: (_cl.Pipe.get_pipe_info, _cl.pipe_info, []), Program: (Program.get_info, _cl.program_info, []), Kernel: (Kernel.get_info, _cl.kernel_info, []), _cl.Sampler: (Sampler.get_info, _cl.sampler_info, []), -- GitLab From 55347473b5d17c11408dceb66ddf4a2b57f8114f Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Wed, 16 Sep 2020 14:21:06 -0500 Subject: [PATCH 29/38] Add spec reference to clCreatePipe --- doc/misc.rst | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/doc/misc.rst b/doc/misc.rst index b8d5c22e..aaad2ad7 100644 --- a/doc/misc.rst +++ b/doc/misc.rst @@ -764,6 +764,10 @@ OpenCL Specification See the `CL specification `__. +.. c:function:: void clCreatePipe() + + See the `CL specification `__. + Internal Types -------------- -- GitLab From a074668791ea40aa369ee7eae0d65fe8db0be8de Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Wed, 16 Sep 2020 14:21:21 -0500 Subject: [PATCH 30/38] Add Kernel.clone --- doc/runtime_program.rst | 6 ++++++ src/wrap_cl.hpp | 22 ++++++++++++++++++++++ src/wrap_cl_part_2.cpp | 3 +++ 3 files changed, 31 insertions(+) diff --git a/doc/runtime_program.rst b/doc/runtime_program.rst index 31de0ac2..1c28a78c 100644 --- a/doc/runtime_program.rst +++ b/doc/runtime_program.rst @@ -150,6 +150,12 @@ Kernel may be used as attributes on instances of this class to directly query info attributes. + .. method:: clone() + + Only available with CL 2.1. + + .. versionadded:: 2020.3 + .. method:: get_info(param) See :class:`kernel_info` for values of *param*. diff --git a/src/wrap_cl.hpp b/src/wrap_cl.hpp index 7cf2dc07..d506a99f 100644 --- a/src/wrap_cl.hpp +++ b/src/wrap_cl.hpp @@ -4258,6 +4258,28 @@ namespace pyopencl PYOPENCL_EQUALITY_TESTS(kernel); +#if PYOPENCL_CL_VERSION >= 0x2010 + kernel *clone() + { + cl_int status_code; + + PYOPENCL_PRINT_CALL_TRACE("clCloneKernel"); + cl_kernel result = clCloneKernel(m_kernel, &status_code); + if (status_code != CL_SUCCESS) + throw pyopencl::error("clCloneKernel", status_code); + + try + { + return new kernel(result, /* retain */ false); + } + catch (...) + { + PYOPENCL_CALL_GUARDED_CLEANUP(clReleaseKernel, (result)); + throw; + } + } +#endif + void set_arg_null(cl_uint arg_index) { cl_mem m = 0; diff --git a/src/wrap_cl_part_2.cpp b/src/wrap_cl_part_2.cpp index df56d0af..a69c9299 100644 --- a/src/wrap_cl_part_2.cpp +++ b/src/wrap_cl_part_2.cpp @@ -462,6 +462,9 @@ void pyopencl_expose_part_2(py::module &m) .def(py::init()) .DEF_SIMPLE_METHOD(get_info) .DEF_SIMPLE_METHOD(get_work_group_info) +#if PYOPENCL_CL_VERSION >= 0x2000 + .DEF_SIMPLE_METHOD(clone) +#endif .def("_set_arg_null", &cls::set_arg_null) .def("_set_arg_buf", &cls::set_arg_buf) #if PYOPENCL_CL_VERSION >= 0x2000 -- GitLab From f4ab412a39a07e8625324e02911d627e64c7c886 Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Wed, 16 Sep 2020 15:36:57 -0500 Subject: [PATCH 31/38] Add cl.pipe_properties --- doc/make_constants.py | 5 +++++ pyopencl/__init__.py | 1 + src/wrap_constants.cpp | 9 +++++++++ 3 files changed, 15 insertions(+) diff --git a/doc/make_constants.py b/doc/make_constants.py index 5f6f820b..d2c7a42b 100644 --- a/doc/make_constants.py +++ b/doc/make_constants.py @@ -320,6 +320,11 @@ const_ext_lookup = { "PROPERTIES": cl_30, }, + cl.pipe_properties: { + "PACKET_SIZE": ("CL_2.0", "2020.3"), + "MAX_PACKETS": ("CL_2.0", "2020.3"), + }, + cl.map_flags: { "WRITE_INVALIDATE_REGION": cl_12, }, diff --git a/pyopencl/__init__.py b/pyopencl/__init__.py index 4994391b..0f4709d1 100644 --- a/pyopencl/__init__.py +++ b/pyopencl/__init__.py @@ -81,6 +81,7 @@ from pyopencl._cl import ( # noqa: F401 mem_info, image_info, pipe_info, + pipe_properties, addressing_mode, filter_mode, sampler_info, diff --git a/src/wrap_constants.cpp b/src/wrap_constants.cpp index 57d435cd..e816b677 100644 --- a/src/wrap_constants.cpp +++ b/src/wrap_constants.cpp @@ -60,6 +60,7 @@ namespace class mem_info { }; class image_info { }; class pipe_info { }; + class pipe_properties { }; class addressing_mode { }; class filter_mode { }; class sampler_info { }; @@ -818,6 +819,14 @@ void pyopencl_expose_constants(py::module &m) ADD_ATTR(PIPE_, PROPERTIES); #endif } + + { + py::class_ cls(m, "pipe_properties"); +#if PYOPENCL_CL_VERSION >= 0x2000 + ADD_ATTR(PIPE_, PACKET_SIZE); + ADD_ATTR(PIPE_, MAX_PACKETS); +#endif + } { py::class_ cls(m, "addressing_mode"); ADD_ATTR(ADDRESS_, NONE); -- GitLab From 7072d39ff2f9af78cff6dfca9ea4acdbe85885ca Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Wed, 16 Sep 2020 15:48:30 -0500 Subject: [PATCH 32/38] Fix typoe: pipe_info -> pipe_properties in wrap_constants --- src/wrap_constants.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wrap_constants.cpp b/src/wrap_constants.cpp index e816b677..0cc20d8f 100644 --- a/src/wrap_constants.cpp +++ b/src/wrap_constants.cpp @@ -821,7 +821,7 @@ void pyopencl_expose_constants(py::module &m) } { - py::class_ cls(m, "pipe_properties"); + py::class_ cls(m, "pipe_properties"); #if PYOPENCL_CL_VERSION >= 0x2000 ADD_ATTR(PIPE_, PACKET_SIZE); ADD_ATTR(PIPE_, MAX_PACKETS); -- GitLab From 20ff881e24fe29a52404e722b31056e04796a11a Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Wed, 16 Sep 2020 16:11:34 -0500 Subject: [PATCH 33/38] Mark clCloneKernel as done --- src/wrap_cl.hpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/wrap_cl.hpp b/src/wrap_cl.hpp index d506a99f..135b949d 100644 --- a/src/wrap_cl.hpp +++ b/src/wrap_cl.hpp @@ -37,7 +37,6 @@ // clSetDefaultDeviceCommandQueue // clGetDeviceAndHostTimer // clGetHostTimer -// clCloneKernel // clEnqueueSVMMigrateMem // CL 2.2 complete -- GitLab From acb753152c4c0e4e1e2d028f91cdef41201ec01a Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Wed, 16 Sep 2020 16:19:12 -0500 Subject: [PATCH 34/38] Add CL2.1 timer functions --- doc/runtime_platform.rst | 16 +++++++++++++++- src/wrap_cl.hpp | 19 +++++++++++++++++-- src/wrap_cl_part_1.cpp | 4 ++++ 3 files changed, 36 insertions(+), 3 deletions(-) diff --git a/doc/runtime_platform.rst b/doc/runtime_platform.rst index 51eecdba..96571685 100644 --- a/doc/runtime_platform.rst +++ b/doc/runtime_platform.rst @@ -45,6 +45,8 @@ Device .. class:: Device + Two instances of this class may be compared using *=="* and *"!="*. + .. attribute:: info Lower case versions of the :class:`device_info` constants @@ -88,7 +90,19 @@ Device .. versionadded:: 2011.2 - Two instances of this class may be compared using *=="* and *"!="*. + .. method:: device_and_host_timer + + :returns: a tuple ``(device_timestamp, host_timestamp)``. + + Only available with CL 2.0. + + .. versionadded:: 2020.3 + + .. method:: host_timer + + Only available with CL 2.0. + + .. versionadded:: 2020.3 Context ------- diff --git a/src/wrap_cl.hpp b/src/wrap_cl.hpp index 135b949d..55f5e058 100644 --- a/src/wrap_cl.hpp +++ b/src/wrap_cl.hpp @@ -35,8 +35,6 @@ // CL 2.1 missing: // clGetKernelSubGroupInfo // clSetDefaultDeviceCommandQueue -// clGetDeviceAndHostTimer -// clGetHostTimer // clEnqueueSVMMigrateMem // CL 2.2 complete @@ -1031,6 +1029,23 @@ namespace pyopencl } #endif +#if PYOPENCL_CL_VERSION >= 0x2010 + py::tuple device_and_host_timer() const + { + cl_ulong device_timestamp, host_timestamp; + PYOPENCL_CALL_GUARDED(clGetDeviceAndHostTimer, + (m_device, &device_timestamp, &host_timestamp)); + return py::make_tuple(device_timestamp, host_timestamp); + } + + cl_ulong host_timer() const + { + cl_ulong host_timestamp; + PYOPENCL_CALL_GUARDED(clGetHostTimer, + (m_device, &host_timestamp)); + return host_timestamp; + } +#endif }; diff --git a/src/wrap_cl_part_1.cpp b/src/wrap_cl_part_1.cpp index 9079d058..d62f6b40 100644 --- a/src/wrap_cl_part_1.cpp +++ b/src/wrap_cl_part_1.cpp @@ -68,6 +68,10 @@ void pyopencl_expose_part_1(py::module &m) .DEF_SIMPLE_METHOD(create_sub_devices) #endif PYOPENCL_EXPOSE_TO_FROM_INT_PTR(cl_device_id) +#if PYOPENCL_CL_VERSION >= 0x2010 + .DEF_SIMPLE_METHOD(device_and_host_timer) + .DEF_SIMPLE_METHOD(host_timer) +#endif ; } -- GitLab From 21424c0c7f9ebe396884f3c4c0151a2434af5612 Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Wed, 16 Sep 2020 16:58:09 -0500 Subject: [PATCH 35/38] Add clSetDefaultDeviceCommandQueue --- doc/runtime_platform.rst | 2 ++ src/wrap_cl.hpp | 15 ++++++++++++++- src/wrap_cl_part_1.cpp | 3 +++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/doc/runtime_platform.rst b/doc/runtime_platform.rst index 96571685..d6e2ecb8 100644 --- a/doc/runtime_platform.rst +++ b/doc/runtime_platform.rst @@ -174,6 +174,8 @@ Context .. automethod:: from_int_ptr .. autoattribute:: int_ptr + .. method:: set_default_device_command_queue(dev, queue) + |comparable| .. function:: create_some_context(interactive=True, answers=None, cache_dir=None) diff --git a/src/wrap_cl.hpp b/src/wrap_cl.hpp index 55f5e058..436317fe 100644 --- a/src/wrap_cl.hpp +++ b/src/wrap_cl.hpp @@ -34,7 +34,6 @@ // CL 2.1 missing: // clGetKernelSubGroupInfo -// clSetDefaultDeviceCommandQueue // clEnqueueSVMMigrateMem // CL 2.2 complete @@ -437,6 +436,7 @@ namespace pyopencl { class program; + class command_queue; // {{{ error class error : public std::runtime_error @@ -1229,6 +1229,10 @@ namespace pyopencl return major_ver << 12 | minor_ver << 4; } + +#if PYOPENCL_CL_VERSION >= 0x2010 + void set_default_device_command_queue(device const &dev, command_queue const &queue); +#endif }; @@ -4912,6 +4916,15 @@ namespace pyopencl // {{{ deferred implementation bits +#if PYOPENCL_CL_VERSION >= 0x2010 + inline void context::set_default_device_command_queue(device const &dev, command_queue const &queue) + { + PYOPENCL_CALL_GUARDED(clSetDefaultDeviceCommandQueue, + (m_context, dev.data(), queue.data())); + } +#endif + + inline program *error::get_program() const { return new program(m_program, /* retain */ true); diff --git a/src/wrap_cl_part_1.cpp b/src/wrap_cl_part_1.cpp index d62f6b40..4b0ec771 100644 --- a/src/wrap_cl_part_1.cpp +++ b/src/wrap_cl_part_1.cpp @@ -103,6 +103,9 @@ void pyopencl_expose_part_1(py::module &m) .def(py::self != py::self) .def("__hash__", &cls::hash) PYOPENCL_EXPOSE_TO_FROM_INT_PTR(cl_context) +#if PYOPENCL_CL_VERSION >= 0x2010 + .DEF_SIMPLE_METHOD(set_default_device_command_queue) +#endif ; } -- GitLab From f872301a37977d336d5bcc4a55a099fdff55a1b5 Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Wed, 16 Sep 2020 22:10:31 -0500 Subject: [PATCH 36/38] Add clGetKernelSubGroupInfo --- doc/runtime_program.rst | 11 +++++++ src/wrap_cl.hpp | 65 ++++++++++++++++++++++++++++++++++++++++- src/wrap_cl_part_2.cpp | 7 +++++ 3 files changed, 82 insertions(+), 1 deletion(-) diff --git a/doc/runtime_program.rst b/doc/runtime_program.rst index 1c28a78c..8cb2077c 100644 --- a/doc/runtime_program.rst +++ b/doc/runtime_program.rst @@ -170,6 +170,17 @@ Kernel Only available in OpenCL 1.2 and newer. + .. method:: get_sub_group_info(self, device, param, input_value=None) + + When the OpenCL spec requests *input_value* to be of type ``size_t``, + these may be passed directly as a number. When it requests + *input_value* to be of type ``size_t *``, a tuple of integers + may be passed. + + Only available in OpenCL 2.1 and newer. + + .. versionadded:: 2020.3 + .. method:: set_arg(self, index, arg) *arg* may be diff --git a/src/wrap_cl.hpp b/src/wrap_cl.hpp index 436317fe..599bb36a 100644 --- a/src/wrap_cl.hpp +++ b/src/wrap_cl.hpp @@ -33,7 +33,6 @@ // CL 2.0 complete // CL 2.1 missing: -// clGetKernelSubGroupInfo // clEnqueueSVMMigrateMem // CL 2.2 complete @@ -4511,6 +4510,70 @@ namespace pyopencl } } #endif + +#if PYOPENCL_CL_VERSION >= 0x2010 + py::object get_sub_group_info( + device const &dev, + cl_kernel_sub_group_info param_name, + py::object py_input_value) + { + switch (param_name) + { + // size_t * -> size_t + case CL_KERNEL_MAX_SUB_GROUP_SIZE_FOR_NDRANGE: + case CL_KERNEL_SUB_GROUP_COUNT_FOR_NDRANGE: + { + std::vector input_value; + COPY_PY_LIST(size_t, input_value); + + size_t param_value; + PYOPENCL_CALL_GUARDED(clGetKernelSubGroupInfo, + (m_kernel, dev.data(), param_name, + input_value.size()*sizeof(input_value.front()), + input_value.empty() ? nullptr : &input_value.front(), + sizeof(param_value), ¶m_value, 0)); + + return py::cast(param_value); + } + + // size_t -> size_t[] + case CL_KERNEL_LOCAL_SIZE_FOR_SUB_GROUP_COUNT: + { + size_t input_value = py::cast(py_input_value); + + std::vector result; + size_t size; + PYOPENCL_CALL_GUARDED(clGetKernelSubGroupInfo, + (m_kernel, dev.data(), param_name, + sizeof(input_value), &input_value, + 0, nullptr, &size)); + result.resize(size / sizeof(result.front())); + PYOPENCL_CALL_GUARDED(clGetKernelSubGroupInfo, + (m_kernel, dev.data(), param_name, + sizeof(input_value), &input_value, + size, result.empty() ? nullptr : &result.front(), 0)); + + PYOPENCL_RETURN_VECTOR(size_t, result); + } + + // () -> size_t + case CL_KERNEL_MAX_NUM_SUB_GROUPS: + case CL_KERNEL_COMPILE_NUM_SUB_GROUPS: + { + size_t param_value; + PYOPENCL_CALL_GUARDED(clGetKernelSubGroupInfo, + (m_kernel, dev.data(), param_name, + 0, nullptr, + sizeof(param_value), ¶m_value, 0)); + + return py::cast(param_value); + } + + default: + throw error("Kernel.get_sub_group_info", CL_INVALID_VALUE); + } + } +#endif }; diff --git a/src/wrap_cl_part_2.cpp b/src/wrap_cl_part_2.cpp index a69c9299..9644eea6 100644 --- a/src/wrap_cl_part_2.cpp +++ b/src/wrap_cl_part_2.cpp @@ -478,6 +478,13 @@ void pyopencl_expose_part_2(py::module &m) .def(py::self != py::self) .def("__hash__", &cls::hash) PYOPENCL_EXPOSE_TO_FROM_INT_PTR(cl_kernel) +#if PYOPENCL_CL_VERSION >= 0x1020 + .def("get_sub_group_info", &cls::get_sub_group_info, + py::arg("device"), + py::arg("param"), + py::arg("input_value")=py::none() + ) +#endif ; } -- GitLab From cfaa66274754439ef773c14129ce8462ffea76f4 Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Thu, 17 Sep 2020 10:48:47 -0500 Subject: [PATCH 37/38] Mark clEnqueueSVMMigrateMem as done --- src/wrap_cl.hpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/wrap_cl.hpp b/src/wrap_cl.hpp index 599bb36a..3601dd71 100644 --- a/src/wrap_cl.hpp +++ b/src/wrap_cl.hpp @@ -32,8 +32,7 @@ // CL 2.0 complete -// CL 2.1 missing: -// clEnqueueSVMMigrateMem +// CL 2.1 complete // CL 2.2 complete -- GitLab From 0da7c4248ab7b5277f0f77568b048c1b9c0b4d17 Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Thu, 17 Sep 2020 13:11:23 -0500 Subject: [PATCH 38/38] Record that clCreate{Buffer,Image}WithProperties will remain unwrapped for now --- src/wrap_cl.hpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/wrap_cl.hpp b/src/wrap_cl.hpp index 3601dd71..1ef99694 100644 --- a/src/wrap_cl.hpp +++ b/src/wrap_cl.hpp @@ -39,6 +39,9 @@ // CL 3.0 missing: // clCreateBufferWithProperties // clCreateImageWithProperties +// (no wrappers for now: OpenCL 3.0 does not define any optional properties for +// buffers or images, no implementations to test with.) + // {{{ includes -- GitLab