diff --git a/doc/misc.rst b/doc/misc.rst index 3fda67b1e9afa7811be889e072b3ec17665e6e4f..8acd53e1710ec846ce42033fb114cb3dd717b608 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 b0e8159c4d1f3579e79842dd96f0918350063cf6..bf646511d64a0e1b94e1ce8695eb2f9b4cd6c944 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 2390e28ee9e8ef39d2758c30ad1f07284928e6dc..2d7d42d7c78106490d556bbd5bfb67b8d80decdf 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