summaryrefslogtreecommitdiff
path: root/t
diff options
context:
space:
mode:
authorThomas Albers <thomas@thomaslabs.org>2023-03-04 22:47:28 +0100
committerThomas Albers <thomas@thomaslabs.org>2023-03-04 22:47:28 +0100
commit6fe823a614279cceb2d48507bd8e93b0efd87f94 (patch)
tree579e3c5db456667ce2aeda94f909703513179ce1 /t
Initial commit
Diffstat (limited to 't')
-rw-r--r--t/test.cl10
-rw-r--r--t/test.lisp51
2 files changed, 61 insertions, 0 deletions
diff --git a/t/test.cl b/t/test.cl
new file mode 100644
index 0000000..89ed7eb
--- /dev/null
+++ b/t/test.cl
@@ -0,0 +1,10 @@
+kernel void vecAdd(global float *a,
+ global float *b,
+ global float *c,
+ const unsigned int n)
+{
+ int id = get_global_id(0);
+ if(id < n) {
+ c[id] = a[id] + b[id];
+ }
+}
diff --git a/t/test.lisp b/t/test.lisp
new file mode 100644
index 0000000..98e9a89
--- /dev/null
+++ b/t/test.lisp
@@ -0,0 +1,51 @@
+(asdf:load-systems :slynk :opencl :alexandria)
+
+(in-package #:ocl)
+
+;; (slynk:create-server)
+
+(defun print-platform (platform)
+ (loop :for info :in '(:platform-profile
+ :platform-version
+ :platform-name
+ :platform-vendor
+ :platform-extensions
+ :platform-host-timer-resolution)
+ :do
+ (format t "~A: ~A~%" info (get-platform-info platform info))))
+
+(defun main (context kernel queue)
+ (let* ((a (make-array 3 :element-type 'single-float :initial-contents '(1.0 2.0 3.0)))
+ (b (make-array 3 :element-type 'single-float :initial-contents '(2.0 2.0 3.0)))
+ (c (make-array 3 :element-type 'single-float))
+ (size (* (cffi:foreign-type-size :float) 3)))
+ (with-buffer-from-array (a-buffer context '(:mem-copy-host-ptr :mem-read-only) a)
+ (with-buffer-from-array (b-buffer context '(:mem-copy-host-ptr :mem-read-only) b)
+ (with-buffer (c-buffer context :mem-write-only size)
+
+ (set-kernel-arg kernel 0 'cl-mem a-buffer)
+ (set-kernel-arg kernel 1 'cl-mem b-buffer)
+ (set-kernel-arg kernel 2 'cl-mem c-buffer)
+ (set-kernel-arg kernel 3 :unsigned-int 3)
+
+ (enqueue-nd-range-kernel queue kernel 0 3 1)
+
+ (finish queue)
+
+ (copy-buffer-to-array queue c-buffer c)
+
+ (dotimes (i 3)
+ (format t "~A~%" (aref c i))))))))
+
+(let ((platforms (get-platform-ids)))
+ (format t "~&Found ~A OpenCL platforms!~%" (length platforms))
+ (print-platform (first platforms))
+ (let ((devices (get-device-ids (first platforms) :device-type-cpu)))
+ (format t "Found ~A devices!~%Type: ~A~%" (length devices)
+ (get-device-info (first devices) :device-type))
+ (with-context (context devices :platform (first platforms))
+ (with-program-from-source (program context (alexandria:read-file-into-string "test.cl"))
+ (build-program program (first devices))
+ (with-command-queue (queue context (first devices))
+ (with-kernel (kernel program "vecAdd")
+ (main context kernel queue)))))))