From b704448c716d89a258dce1ccd3da47ecf63acc93 Mon Sep 17 00:00:00 2001 From: Justin Patera Date: Fri, 2 Dec 2016 20:52:37 -0500 Subject: [PATCH 1/4] skeleton for using cffi... kinda like the one for autowrap, just... different --- arrayfire-lisp.asd | 19 +++++++++++++++++++ src/cffi.lisp | 6 ++++++ src/package.lisp | 38 ++++++++++++++++++++++++++++++++++++++ src/utils.lisp | 22 ++++++++++++++++++++++ 4 files changed, 85 insertions(+) create mode 100644 arrayfire-lisp.asd create mode 100644 src/cffi.lisp create mode 100644 src/package.lisp create mode 100644 src/utils.lisp diff --git a/arrayfire-lisp.asd b/arrayfire-lisp.asd new file mode 100644 index 0000000..9f3cb74 --- /dev/null +++ b/arrayfire-lisp.asd @@ -0,0 +1,19 @@ +;;;; arrayfire-lisp.asd +;;;; +;;;; Copyright (c) 2016 ArrayFire +;;;; Copyright (c) 2016 Justin Patera + +(asdf:defsystem #:arrayfire-lisp + :description "ArrayFire Bindings for Common Lisp" + :author "Justin Patera " + :license "BSD 3-Clause License" + + :depends-on (#:cffi + #:trivial-garbage) + + :serial t + :pathname "src" + :components + ((:file "package") + (:file "cffi") + (:file "utils"))) diff --git a/src/cffi.lisp b/src/cffi.lisp new file mode 100644 index 0000000..38198bd --- /dev/null +++ b/src/cffi.lisp @@ -0,0 +1,6 @@ +;;;; cffi.lisp +;;;; +;;;; Copyright (c) 2016 ArrayFire +;;;; Copyright (c) 2016 Justin Patera + +;; cffi stub diff --git a/src/package.lisp b/src/package.lisp new file mode 100644 index 0000000..53ac96f --- /dev/null +++ b/src/package.lisp @@ -0,0 +1,38 @@ +;;;; package.lisp +;;;; +;;;; Copyright (c) 2016 ArrayFire +;;;; Copyright (c) 2016 Justin Patera + +(in-package :cl) + +(defpackage #:arrayfire + (:use #:cl) + ; as these will probably pose a small issue... + (:shadow ; Arithmatic Ops + #:+ #:- #:* #:/ + ; Complex Ops + #:complex #:real + ; Exponential & Logarithmic Fns + #:exp #:log #:sqrt + ; Logical Ops + #:and #:eq #:not #:or + ; Numeric Fns + #:abs #:floor #:max #:min #:mod #:rem #:round + ; Trigonometric & Hyberbolic Fns + #:acos #:asin #:atan #:cos #:sin #:tan + #:acosh #:asinh #:atanh #:cosh #:sinh #:tanh) + + (:export ;; lots more than this... + ; Arithmatic Ops + #:+ #:- #:* #:/ + ; Complex Ops + #:complex #:real + ; Exponential & Logarithmic Fns + #:exp #:log #:sqrt + ; Logical Ops + #:and #:eq #:not #:or + ; Numeric Fns + #:abs #:floor #:max #:min #:mod #:rem #:round + ; Trigonometric & Hyberbolic Fns + #:acos #:asin #:atan #:cos #:sin #:tan + #:acosh #:asinh #:atanh #:cosh #:sinh #:tanh)) diff --git a/src/utils.lisp b/src/utils.lisp new file mode 100644 index 0000000..310d208 --- /dev/null +++ b/src/utils.lisp @@ -0,0 +1,22 @@ +;;;; autowrap.lisp +;;;; +;;;; Copyright (c) 2016 ArrayFire +;;;; Copyright (c) 2016 Justin Patera + +; add utils here + +; because FizzBuzz is *essential* to our success!!! +(defun fizzbuzz (n) + (if (< 0 n) + (fizzbuzz-helper 1 n) + (error "The Fizzing And The Buzzing And The FizzBuzzing Needs Numbers Greater Than Zero"))) + +(defun fizzbuzz-helper (n x) + (if (<= n x) + (cons + (case (mod n 15) + (0 "FizzBuzz") + ((3 6 9 12) "Fizz") + ((5 10) "Buzz") + (otherwise n)) + (fizzbuzz-helper (+ 1 n) x)))) From 02b4e44cab0dc35dba970b26ac5de0dc02e1b264 Mon Sep 17 00:00:00 2001 From: Justin Patera Date: Fri, 2 Dec 2016 21:26:03 -0500 Subject: [PATCH 2/4] small changes, makes it better --- arrayfire-lisp.asd => arrayfire.asd | 38 +++++++------- src/cffi.lisp | 2 + src/package.lisp | 77 +++++++++++++++-------------- src/utils.lisp | 46 ++++++++--------- 4 files changed, 84 insertions(+), 79 deletions(-) rename arrayfire-lisp.asd => arrayfire.asd (89%) diff --git a/arrayfire-lisp.asd b/arrayfire.asd similarity index 89% rename from arrayfire-lisp.asd rename to arrayfire.asd index 9f3cb74..efaab6e 100644 --- a/arrayfire-lisp.asd +++ b/arrayfire.asd @@ -1,19 +1,19 @@ -;;;; arrayfire-lisp.asd -;;;; -;;;; Copyright (c) 2016 ArrayFire -;;;; Copyright (c) 2016 Justin Patera - -(asdf:defsystem #:arrayfire-lisp - :description "ArrayFire Bindings for Common Lisp" - :author "Justin Patera " - :license "BSD 3-Clause License" - - :depends-on (#:cffi - #:trivial-garbage) - - :serial t - :pathname "src" - :components - ((:file "package") - (:file "cffi") - (:file "utils"))) +;;;; arrayfire-lisp.asd +;;;; +;;;; Copyright (c) 2016 ArrayFire +;;;; Copyright (c) 2016 Justin Patera + +(asdf:defsystem #:arrayfire + :description "ArrayFire Bindings for Common Lisp" + :author "Justin Patera " + :license "BSD 3-Clause License" + + :depends-on (#:cffi + #:trivial-garbage) + + :serial t + :pathname "src" + :components + ((:file "package") + (:file "cffi") + (:file "utils"))) diff --git a/src/cffi.lisp b/src/cffi.lisp index 38198bd..0de306f 100644 --- a/src/cffi.lisp +++ b/src/cffi.lisp @@ -3,4 +3,6 @@ ;;;; Copyright (c) 2016 ArrayFire ;;;; Copyright (c) 2016 Justin Patera +(in-package :arrayfire) + ;; cffi stub diff --git a/src/package.lisp b/src/package.lisp index 53ac96f..0d5b4fe 100644 --- a/src/package.lisp +++ b/src/package.lisp @@ -1,38 +1,39 @@ -;;;; package.lisp -;;;; -;;;; Copyright (c) 2016 ArrayFire -;;;; Copyright (c) 2016 Justin Patera - -(in-package :cl) - -(defpackage #:arrayfire - (:use #:cl) - ; as these will probably pose a small issue... - (:shadow ; Arithmatic Ops - #:+ #:- #:* #:/ - ; Complex Ops - #:complex #:real - ; Exponential & Logarithmic Fns - #:exp #:log #:sqrt - ; Logical Ops - #:and #:eq #:not #:or - ; Numeric Fns - #:abs #:floor #:max #:min #:mod #:rem #:round - ; Trigonometric & Hyberbolic Fns - #:acos #:asin #:atan #:cos #:sin #:tan - #:acosh #:asinh #:atanh #:cosh #:sinh #:tanh) - - (:export ;; lots more than this... - ; Arithmatic Ops - #:+ #:- #:* #:/ - ; Complex Ops - #:complex #:real - ; Exponential & Logarithmic Fns - #:exp #:log #:sqrt - ; Logical Ops - #:and #:eq #:not #:or - ; Numeric Fns - #:abs #:floor #:max #:min #:mod #:rem #:round - ; Trigonometric & Hyberbolic Fns - #:acos #:asin #:atan #:cos #:sin #:tan - #:acosh #:asinh #:atanh #:cosh #:sinh #:tanh)) +;;;; package.lisp +;;;; +;;;; Copyright (c) 2016 ArrayFire +;;;; Copyright (c) 2016 Justin Patera + +(in-package :cl) + +(defpackage #:arrayfire + (:nicknames #:af) + (:use #:cl) + ; as these will probably pose a small issue... + (:shadow ; Arithmatic Ops + #:+ #:- #:* #:/ + ; Complex Ops + #:complex #:real + ; Exponential & Logarithmic Fns + #:exp #:log #:sqrt + ; Logical Ops + #:and #:eq #:not #:or + ; Numeric Fns + #:abs #:floor #:max #:min #:mod #:rem #:round + ; Trigonometric & Hyberbolic Fns + #:acos #:asin #:atan #:cos #:sin #:tan + #:acosh #:asinh #:atanh #:cosh #:sinh #:tanh) + + (:export ;; lots more than this... + ; Arithmatic Ops + #:+ #:- #:* #:/ + ; Complex Ops + #:complex #:real + ; Exponential & Logarithmic Fns + #:exp #:log #:sqrt + ; Logical Ops + #:and #:eq #:not #:or + ; Numeric Fns + #:abs #:floor #:max #:min #:mod #:rem #:round + ; Trigonometric & Hyberbolic Fns + #:acos #:asin #:atan #:cos #:sin #:tan + #:acosh #:asinh #:atanh #:cosh #:sinh #:tanh)) diff --git a/src/utils.lisp b/src/utils.lisp index 310d208..2a61380 100644 --- a/src/utils.lisp +++ b/src/utils.lisp @@ -1,22 +1,24 @@ -;;;; autowrap.lisp -;;;; -;;;; Copyright (c) 2016 ArrayFire -;;;; Copyright (c) 2016 Justin Patera - -; add utils here - -; because FizzBuzz is *essential* to our success!!! -(defun fizzbuzz (n) - (if (< 0 n) - (fizzbuzz-helper 1 n) - (error "The Fizzing And The Buzzing And The FizzBuzzing Needs Numbers Greater Than Zero"))) - -(defun fizzbuzz-helper (n x) - (if (<= n x) - (cons - (case (mod n 15) - (0 "FizzBuzz") - ((3 6 9 12) "Fizz") - ((5 10) "Buzz") - (otherwise n)) - (fizzbuzz-helper (+ 1 n) x)))) +;;;; autowrap.lisp +;;;; +;;;; Copyright (c) 2016 ArrayFire +;;;; Copyright (c) 2016 Justin Patera + +(in-package :arrayfire) + +; add utils here + +; because FizzBuzz is *essential* to our success!!! +(defun fizzbuzz (n) + (if (< 0 n) + (fizzbuzz-helper 1 n) + (error "The Fizzing And The Buzzing And The FizzBuzzing Needs Numbers Greater Than Zero"))) + +(defun fizzbuzz-helper (n x) + (if (<= n x) + (cons + (case (mod n 15) + (0 "FizzBuzz") + ((3 6 9 12) "Fizz") + ((5 10) "Buzz") + (otherwise n)) + (fizzbuzz-helper (+ 1 n) x)))) From 301e4152919044af9c7f9a9d73f0d9b445f2d300 Mon Sep 17 00:00:00 2001 From: Justin Patera Date: Thu, 8 Jun 2017 19:55:08 -0400 Subject: [PATCH 3/4] small --- src/utils.lisp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/utils.lisp b/src/utils.lisp index 2a61380..dd2c13e 100644 --- a/src/utils.lisp +++ b/src/utils.lisp @@ -16,9 +16,9 @@ (defun fizzbuzz-helper (n x) (if (<= n x) (cons - (case (mod n 15) + (case (cl:mod n 15) (0 "FizzBuzz") ((3 6 9 12) "Fizz") ((5 10) "Buzz") (otherwise n)) - (fizzbuzz-helper (+ 1 n) x)))) + (fizzbuzz-helper (1+ n) x)))) From 53f3bb48906f2693c51e9854a660218f57683130 Mon Sep 17 00:00:00 2001 From: Justin Patera Date: Fri, 9 Jun 2017 10:51:54 -0400 Subject: [PATCH 4/4] adding types & testing functionality --- src/cffi.lisp | 59 +++++++++++++++++++++++++++++++++++++++++++++++- src/package.lisp | 2 +- 2 files changed, 59 insertions(+), 2 deletions(-) diff --git a/src/cffi.lisp b/src/cffi.lisp index 0de306f..e173380 100644 --- a/src/cffi.lisp +++ b/src/cffi.lisp @@ -5,4 +5,61 @@ (in-package :arrayfire) -;; cffi stub +(define-foreign-library arrayfire + (t (:default "af"))) + +(use-foreign-library arrayfire) + +; make array +(defctype af-array :pointer) +(defctype dim-t :long-long) + +(defcenum af-dtype + :f32 + :c32 + :f64 + :c64 + :b8 + :s32 + :u32 + :u8 + :s64 + :u64 + :s16 + :u16) + + +(defcenum af-err + :af-success + :af-err-no-mem + :af-err-driver + :af-err-runtime + :af-err-invalid-array + :af-err-arg + :af-err-size + :af-err-type + :af-err-diff-type + :af-err-batch + :af-err-device + :af-err-not-supported + :af-err-not-configured + :af-err-nonfree + :af-err-no-dbl + :af-err-no-gfx + :af-err-load-lib + :af-err-load-sym + :af-err-arr-bknd-mismatch + :af-err-internal + :af-err-unknown ) + + + +(defcfun "af_create_array" af-err + (arr af-array) + (data :pointer) + (ndims :unsigned-int) + (dims dim-t) + (type af-dtype)) + +;(let ((arr)) +; (af-create-array arr 0 1 1 :b8)) diff --git a/src/package.lisp b/src/package.lisp index 0d5b4fe..63cac98 100644 --- a/src/package.lisp +++ b/src/package.lisp @@ -7,7 +7,7 @@ (defpackage #:arrayfire (:nicknames #:af) - (:use #:cl) + (:use #:cl #:cffi) ; as these will probably pose a small issue... (:shadow ; Arithmatic Ops #:+ #:- #:* #:/