From f3328211e5db0685bd011848ffc3eb27b6d5565f Mon Sep 17 00:00:00 2001
From: Alex Rothberg <agrothberg@gmail.com>
Date: Thu, 17 Jul 2014 18:11:20 -0400
Subject: [PATCH] specify the build options using the -o flag. Updated docs and
 example notebook

---
 doc/misc.rst                | 2 ++
 examples/ipython-demo.ipynb | 2 +-
 pyopencl/ipython_ext.py     | 4 +++-
 3 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/doc/misc.rst b/doc/misc.rst
index 3fda67b1..8acd53e1 100644
--- a/doc/misc.rst
+++ b/doc/misc.rst
@@ -37,6 +37,8 @@ and then use the ``%%cl_kernel`` 'cell-magic' command. See `this notebook
 <http://nbviewer.ipython.org/urls/raw.githubusercontent.com/pyopencl/pyopencl/master/examples/ipython-demo.ipynb>`_
 (which ships with PyOpenCL) for a demonstration.
 
+You can pass build options to be used for building the program executable by using the ``-o`` flag on the first line of the cell (next to the ``%%cl_kernel`` directive). For example: `%%cl_kernel -o "-cl-fast-relaxed-math"``.
+
 .. versionadded:: 2014.1
 
 Guidelines
diff --git a/examples/ipython-demo.ipynb b/examples/ipython-demo.ipynb
index b0e8159c..bf646511 100644
--- a/examples/ipython-demo.ipynb
+++ b/examples/ipython-demo.ipynb
@@ -106,7 +106,7 @@
      "cell_type": "code",
      "collapsed": false,
      "input": [
-      "%%cl_kernel\n",
+      "%%cl_kernel -o \"-cl-fast-relaxed-math\"\n",
       "\n",
       "__kernel void sum_vector(__global const float *a,\n",
       "__global const float *b, __global float *c)\n",
diff --git a/pyopencl/ipython_ext.py b/pyopencl/ipython_ext.py
index 2390e28e..2d7d42d7 100644
--- a/pyopencl/ipython_ext.py
+++ b/pyopencl/ipython_ext.py
@@ -33,7 +33,9 @@ class PyOpenCLMagics(Magics):
             raise RuntimeError("unable to locate cl context, which must be "
                     "present in namespace as 'cl_ctx' or 'ctx'")
 
-        prg = cl.Program(ctx, _try_to_utf8(cell)).build(options=_try_to_utf8(line).strip())
+        opts, args = self.parse_options(line,'o:')
+        build_options = opts.get('o', '')
+        prg = cl.Program(ctx, _try_to_utf8(cell)).build(options=_try_to_utf8(build_options).strip())
 
         for knl in prg.all_kernels():
             self.shell.user_ns[knl.function_name] = knl
-- 
GitLab