summaryrefslogtreecommitdiff
path: root/src/pyclblast
diff options
context:
space:
mode:
authorCedric Nugteren <web@cedricnugteren.nl>2019-01-22 21:14:43 +0100
committerCedric Nugteren <web@cedricnugteren.nl>2019-01-22 21:14:43 +0100
commit347f0df32f0ddcc673e1e62f299090ac60b240a4 (patch)
tree59083b78b34bc9f8c23e02c89c10235b6225e09b /src/pyclblast
parent23b9f655fae8d4d507301e7b56853394768d9813 (diff)
Added a (non-working) sample of half precision AXPY in Python
Diffstat (limited to 'src/pyclblast')
-rw-r--r--src/pyclblast/samples/haxpy.py37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/pyclblast/samples/haxpy.py b/src/pyclblast/samples/haxpy.py
new file mode 100644
index 00000000..d6c1fef0
--- /dev/null
+++ b/src/pyclblast/samples/haxpy.py
@@ -0,0 +1,37 @@
+#!/usr/bin/env python
+
+# This file is part of the CLBlast project. The project is licensed under Apache Version 2.0.
+# This file follows the PEP8 Python style guide and uses a max-width of 100 characters per line.
+#
+# Author(s):
+# Cedric Nugteren <www.cedricnugteren.nl>
+
+import numpy as np
+import pyopencl as cl
+from pyopencl.array import Array
+import pyclblast
+
+# Settings for this sample
+dtype = 'float16'
+alpha = np.array(1.0).astype(dtype=dtype).item()
+n = 4
+
+print("# Setting up OpenCL")
+ctx = cl.create_some_context()
+queue = cl.CommandQueue(ctx)
+
+print("# Setting up Numpy arrays")
+x = np.linspace(1.0, n, num=n).astype(dtype=dtype)
+y = np.linspace(1.0, n / 2, num=n).astype(dtype=dtype)
+
+print("# Setting up OpenCL arrays")
+clx = Array(queue, x.shape, x.dtype)
+cly = Array(queue, y.shape, y.dtype)
+clx.set(x)
+cly.set(y)
+
+print("# Example level-1 operation: AXPY")
+pyclblast.axpy(queue, n, clx, cly, alpha=alpha)
+queue.finish()
+print("# Result for vector y: %s" % cly.get())
+print("# Expected result: %s" % (alpha * x + y))