From a3aae16434996d896383ebd42412a5199af089f0 Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Wed, 1 May 2013 00:53:07 -0400 Subject: [PATCH] Yet more example beautification. :) --- doc/index.rst | 10 ++++++---- examples/hello-loopy.py | 23 ++++++++++------------- loopy/kernel/__init__.py | 13 +++++++++++++ 3 files changed, 29 insertions(+), 17 deletions(-) diff --git a/doc/index.rst b/doc/index.rst index 1687f4c8e..4443e82c7 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 a835005ab..2c8ff4c3b 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