/usr/lib/python3/dist-packages/pyopencl/ipython.py is in python3-pyopencl 2014.1-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | from IPython.core.magic import (magics_class, Magics, cell_magic)
import pyopencl as cl
@magics_class
class PyOpenCLMagics(Magics):
@cell_magic
def cl_kernel(self, line, cell):
try:
ctx = self.shell.user_ns["cl_ctx"]
except KeyError:
ctx = None
if not isinstance(ctx, cl.Context):
ctx = None
if ctx is None:
try:
ctx = self.shell.user_ns["ctx"]
except KeyError:
ctx = None
if ctx is None:
raise RuntimeError("unable to locate cl context, which must be "
"present in namespace as 'cl_ctx' or 'ctx'")
prg = cl.Program(ctx, cell.encode("utf8")).build()
for knl in prg.all_kernels():
self.shell.user_ns[knl.function_name] = knl
def load_ipython_extension(ip):
ip.register_magics(PyOpenCLMagics)
|