From ababc2aa39d699687bb56984acd56f6b9f7b741b Mon Sep 17 00:00:00 2001 From: Alexandru Fikl Date: Thu, 14 Nov 2019 11:37:52 -0600 Subject: [PATCH 1/5] constants: make to_string handle more values This is mostly implemented for `clGetKernelArgInfo` [1] called with `CL_KERNEL_ARG_TYPE_QUALIFIER`. Since an argument can have multiple type qualifiers (e.g. `const` and `volatile`), this returns the bitwise or of the flags that we need to separate. [1] https://www.khronos.org/registry/OpenCL/sdk/1.2/docs/man/xhtml/clGetKernelArgInfo.html --- pyopencl/__init__.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/pyopencl/__init__.py b/pyopencl/__init__.py index 02fa08e1..0b68de82 100644 --- a/pyopencl/__init__.py +++ b/pyopencl/__init__.py @@ -1269,9 +1269,16 @@ def _add_functionality(): } def to_string(cls, value, default_format=None): + names = [] for name in dir(cls): - if (not name.startswith("_") and getattr(cls, name) == value): - return name + attr = getattr(cls, name) + if name.startswith('_') or type(attr) is not type(value): + continue + if attr == value or attr & value: + names.append(name) + + if names: + return " ".join(names) if default_format is None: raise ValueError("a name for value %d was not found in %s" -- GitLab From 3011e292d4f4f328b08435efdeb5fdfc9d565f2c Mon Sep 17 00:00:00 2001 From: Alexandru Fikl Date: Thu, 14 Nov 2019 16:22:41 -0600 Subject: [PATCH 2/5] constants: only bitfields can have extra values --- pyopencl/__init__.py | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/pyopencl/__init__.py b/pyopencl/__init__.py index 0b68de82..7177cf9d 100644 --- a/pyopencl/__init__.py +++ b/pyopencl/__init__.py @@ -217,6 +217,9 @@ CONSTANT_CLASSES = tuple( if _inspect.isclass(getattr(_cl, name)) and name[0].islower() and name not in ["zip", "map", "range"]) +BITFIELD_CONSTANT_CLASSES = ( + _cl.kernel_arg_type_qualifier, + ) # {{{ diagnostics @@ -1269,16 +1272,21 @@ def _add_functionality(): } def to_string(cls, value, default_format=None): - names = [] - for name in dir(cls): - attr = getattr(cls, name) - if name.startswith('_') or type(attr) is not type(value): - continue - if attr == value or attr & value: - names.append(name) - - if names: - return " ".join(names) + if cls._is_bitfield: + names = [] + for name in dir(cls): + attr = getattr(cls, name) + if not isinstance(attr, int): + continue + if attr == value or attr & value: + names.append(name) + if names: + return " ".join(names) + else: + for name in dir(cls): + if (not name.startswith("_") + and getattr(cls, name) == value): + return name if default_format is None: raise ValueError("a name for value %d was not found in %s" @@ -1287,6 +1295,7 @@ def _add_functionality(): return default_format % value for cls in CONSTANT_CLASSES: + cls._is_bitfield = cls in BITFIELD_CONSTANT_CLASSES cls.to_string = classmethod(to_string) # {{{ get_info attributes ------------------------------------------------- -- GitLab From e50096a8846a95fbc5e10039e275c0af0118e598 Mon Sep 17 00:00:00 2001 From: Alexandru Fikl Date: Thu, 14 Nov 2019 17:11:44 -0600 Subject: [PATCH 3/5] constants: mark all cl_bitfield from cl.h --- pyopencl/__init__.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/pyopencl/__init__.py b/pyopencl/__init__.py index 7177cf9d..1fe13c3e 100644 --- a/pyopencl/__init__.py +++ b/pyopencl/__init__.py @@ -218,9 +218,29 @@ CONSTANT_CLASSES = tuple( and name[0].islower() and name not in ["zip", "map", "range"]) BITFIELD_CONSTANT_CLASSES = ( + _cl.device_type, + _cl.device_fp_config, + _cl.device_exec_capabilities, + _cl.command_queue_properties, + _cl.mem_flags, + _cl.map_flags, _cl.kernel_arg_type_qualifier, ) +if get_cl_header_version() >= (1, 2): + BITFIELD_CONSTANT_CLASSES += ( + _cl.device_affinity_domain, + _cl.mem_migration_flags, + ) + +if get_cl_header_version() >= (2, 0): + BITFIELD_CONSTANT_CLASSES += ( + _cl.device_svm_capabilities, + _cl.queue_properties, + _cl.svm_mem_flags, + ) + + # {{{ diagnostics class CompilerWarning(UserWarning): -- GitLab From 0b598cb558c94511c373dda77a118f00c08ddb5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20Kl=C3=B6ckner?= Date: Fri, 15 Nov 2019 01:13:33 +0100 Subject: [PATCH 4/5] Remove CL version query for BITFIELD_CONSTANT_CLASSES --- pyopencl/__init__.py | 8 -------- 1 file changed, 8 deletions(-) diff --git a/pyopencl/__init__.py b/pyopencl/__init__.py index 1fe13c3e..8660a77b 100644 --- a/pyopencl/__init__.py +++ b/pyopencl/__init__.py @@ -225,16 +225,8 @@ BITFIELD_CONSTANT_CLASSES = ( _cl.mem_flags, _cl.map_flags, _cl.kernel_arg_type_qualifier, - ) - -if get_cl_header_version() >= (1, 2): - BITFIELD_CONSTANT_CLASSES += ( _cl.device_affinity_domain, _cl.mem_migration_flags, - ) - -if get_cl_header_version() >= (2, 0): - BITFIELD_CONSTANT_CLASSES += ( _cl.device_svm_capabilities, _cl.queue_properties, _cl.svm_mem_flags, -- GitLab From e8871f73434607c5c3661c455764cf0cbe84c760 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20Kl=C3=B6ckner?= Date: Fri, 15 Nov 2019 01:14:16 +0100 Subject: [PATCH 5/5] Use | as separator when stringifying bitfields --- pyopencl/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyopencl/__init__.py b/pyopencl/__init__.py index 8660a77b..02ec97ff 100644 --- a/pyopencl/__init__.py +++ b/pyopencl/__init__.py @@ -1293,7 +1293,7 @@ def _add_functionality(): if attr == value or attr & value: names.append(name) if names: - return " ".join(names) + return " | ".join(names) else: for name in dir(cls): if (not name.startswith("_") -- GitLab