From 95914d8f76423345f047b4aa6ea6c32e663b6329 Mon Sep 17 00:00:00 2001
From: Yichao Yu <yyc1992@gmail.com>
Date: Mon, 23 Jun 2014 05:52:43 +0800
Subject: [PATCH] Platform._get_cl_version

---
 pyopencl/__init__.py | 24 ++++++++++++++----------
 test/test_wrapper.py |  6 ++----
 2 files changed, 16 insertions(+), 14 deletions(-)

diff --git a/pyopencl/__init__.py b/pyopencl/__init__.py
index a8bdea15..bb7e0fb7 100644
--- a/pyopencl/__init__.py
+++ b/pyopencl/__init__.py
@@ -340,7 +340,20 @@ def _add_functionality():
     def platform_repr(self):
         return "<pyopencl.Platform '%s' at 0x%x>" % (self.name, self.int_ptr)
 
+    def platform_get_cl_version(self):
+        import re
+        version_string = self.version
+        match = re.match(r"^OpenCL ([0-9]+)\.([0-9]+) .*$", version_string)
+        if match is None:
+            raise RuntimeError("platform %s returned non-conformant "
+                               "platform version string '%s'" %
+                               (self, version_string))
+
+        return int(match.group(1)), int(match.group(2))
+
+
     Platform.__repr__ = platform_repr
+    Platform._get_cl_version = platform_get_cl_version
 
     # }}}
 
@@ -367,16 +380,7 @@ def _add_functionality():
                 ", ".join(repr(dev) for dev in self.devices))
 
     def context_get_cl_version(self):
-        import re
-        platform = self.devices[0].platform
-        plat_version_string = platform.version
-        match = re.match(r"^OpenCL ([0-9]+)\.([0-9]+) .*$",
-                plat_version_string)
-        if match is None:
-            raise RuntimeError("platform %s returned non-conformant "
-                    "platform version string '%s'" % (platform, plat_version_string))
-
-        return int(match.group(1)), int(match.group(2))
+        return self.devices[0].platform._get_cl_version()
 
     Context.__repr__ = context_repr
     from pytools import memoize_method
diff --git a/test/test_wrapper.py b/test/test_wrapper.py
index 747397bd..c7ec91f9 100644
--- a/test/test_wrapper.py
+++ b/test/test_wrapper.py
@@ -629,10 +629,8 @@ def test_wait_for_events(ctx_factory):
     cl.wait_for_events([evt1, evt2])
 
 
-def test_unload_compiler(ctx_factory):
-    ctx = ctx_factory()
-    platform = ctx.devices[0].platform
-    if (ctx._get_cl_version() < (1, 2) or
+def test_unload_compiler(platform):
+    if (platform._get_cl_version() < (1, 2) or
             cl.get_cl_header_version() < (1, 2)):
         from pytest import skip
         skip("clUnloadPlatformCompiler is only available in OpenCL 1.2")
-- 
GitLab