Commits

Matthew Turk committed 615a91d

Simple summing of grids. Takes a very long time, thanks to dynamic compilation for every sum() operation.

Comments (0)

Files changed (1)

simple_grid_sum.py

+import matplotlib;matplotlib.use("Agg");import pylab
+from yt.config import ytcfg
+from yt.mods import *
+import pyopencl as cl
+import pyopencl.array as cl_array
+from contextlib import contextmanager
+
+times = {}
+
+@contextmanager
+def time_func(name):
+    t1 = time.time()
+    yield
+    t2 = time.time()
+    print "%s took %0.3e seconds" % (name, t2-t1)
+    times[name] = t2-t1
+
+pf = load("JHK-DD0030/galaxy0030")
+#pf = load("DD0087/DD0087")
+
+# This part is specific to Hex
+platforms = cl.get_platforms()
+GPU = platforms[0]
+CPU = platforms[1]
+devices = GPU.get_devices()
+
+gformat = cl.ImageFormat(cl.channel_order.R,
+                         cl.channel_type.FLOAT)
+
+context = cl.Context(devices)
+command_queue = cl.CommandQueue(context)
+
+with time_func("Load from disk"):
+    for g in pf.h.grids: g["Density"]
+
+GPUARR = {}
+
+with time_func("Copy to GPU"):
+    for g in pf.h.grids:
+        GPUARR[g.id] = cl_array.to_device(command_queue, g["Density"])
+        cl.enqueue_barrier(command_queue)
+
+with time_func("Sum on GPU1"):
+    val_gpu1 = 0.0
+    for g in pf.h.grids:
+        val_gpu1 += cl_array.sum(GPUARR[g.id]).get()
+        cl.enqueue_barrier(command_queue)
+
+with time_func("Sum on GPU2"):
+    val_gpu2 = 0.0
+    for g in pf.h.grids:
+        val_gpu2 += cl_array.sum(GPUARR[g.id]).get()
+        cl.enqueue_barrier(command_queue)
+
+#val_gpu = val_gpu.get()[0]
+#print "On GPU calculated a sum of: %0.9e" % (val_gpu)
+
+with time_func("De-allocate on GPU"):
+    for g in pf.h.grids: del GPUARR[g.id]
+    cl.enqueue_barrier(command_queue)
+
+with time_func("Sum with NumPy"):
+    val_cpu = sum(g["Density"].sum() * (g.RightEdge - g.LeftEdge).prod()
+                  for g in pf.h.grids)
+
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.