diff --git a/doc/index.rst b/doc/index.rst index 1687f4c8ee912c1e53879861dc548ca1333770b5..4443e82c7281b3742368b6678ab38a6487dd8218 100644 --- a/doc/index.rst +++ b/doc/index.rst @@ -12,15 +12,17 @@ model. Here's a very simple example of how to double the entries of a vector using loopy: .. literalinclude:: ../examples/hello-loopy.py + :end-before: ENDEXAMPLE -The following kernel is generated, compiled, and executed behind your back (and -also printed at the end): +This example is included in the :mod:`loopy` distribution as +:download:`examples/hello-loopy.py <../examples/hello-loopy.py>`. + +When you run this script, the following kernel is generated, compiled, and executed: .. literalinclude:: ../examples/hello-loopy.cl :language: c -This file is included in the :mod:`loopy` distribution as -:file:`examples/hello-loopy.py`. +(See the full example for how to print the generated code.) .. toctree:: :maxdepth: 2 diff --git a/examples/hello-loopy.py b/examples/hello-loopy.py index a835005ab53fe9c15323eff5b4624d3b5b023125..2c8ff4c3bbdfe331596eec1c0dcb49f6bd8b6e46 100644 --- a/examples/hello-loopy.py +++ b/examples/hello-loopy.py @@ -3,31 +3,28 @@ import loopy as lp import pyopencl as cl import pyopencl.array -# ----------------------------------------------------------------------------- # setup -# ----------------------------------------------------------------------------- +# ----- ctx = cl.create_some_context() queue = cl.CommandQueue(ctx) n = 15 * 10**6 a = cl.array.arange(queue, n, dtype=np.float32) -# ----------------------------------------------------------------------------- -# generation (loopy bits start here) -# ----------------------------------------------------------------------------- +# create +# ------ knl = lp.make_kernel(ctx.devices[0], "{ [i]: 0<=i