From eaa47de7d3b03e1f6a514cd84e24a47948feccfc Mon Sep 17 00:00:00 2001
From: Andreas Kloeckner <inform@tiker.net>
Date: Fri, 28 Jun 2013 20:20:01 -0400
Subject: [PATCH] Keep kernel source code around for capture_call

---
 pyopencl/__init__.py | 9 +--------
 1 file changed, 1 insertion(+), 8 deletions(-)

diff --git a/pyopencl/__init__.py b/pyopencl/__init__.py
index 2cd5be9b..20a07460 100644
--- a/pyopencl/__init__.py
+++ b/pyopencl/__init__.py
@@ -112,7 +112,6 @@ class Program(object):
 
             self._prg = _cl._Program(self._context, self._source)
             del self._context
-            del self._source
             return self._prg
 
     def get_info(self, arg):
@@ -130,6 +129,7 @@ class Program(object):
             # Nvidia does not raise errors even for invalid names,
             # but this will give an error if the kernel is invalid.
             knl.num_args
+            knl._source = getattr(self, "_source", None)
             return knl
         except LogicError:
             raise AttributeError("'%s' was not found as a program "
@@ -148,12 +148,9 @@ class Program(object):
         if forced_options:
             options = options + forced_options.split()
 
-        do_del_source = False
         if os.environ.get("PYOPENCL_NO_CACHE") and self._prg is None:
             self._prg = _cl._Program(self._context, self._source)
 
-            do_del_source = True
-
         if self._prg is not None:
             # uncached
 
@@ -172,10 +169,6 @@ class Program(object):
                     options=options, source=self._source)
 
             del self._context
-            do_del_source = True
-
-        if do_del_source:
-            del self._source
 
         return self
 
-- 
GitLab