Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support inplace multiplication. #22

Open
Islam0mar opened this issue Feb 9, 2023 · 0 comments
Open

Support inplace multiplication. #22

Islam0mar opened this issue Feb 9, 2023 · 0 comments

Comments

@Islam0mar
Copy link

I was benchmarking cl-cxx-eigen, numcl and your lib..
with the following code:

(ql:quickload :cxx-eigen)
(cxx-eigen:init)
(defvar x (cxx-eigen:create-matrix2  3 3))
(defvar y (cxx-eigen:create-matrix2  3 3))
(defparameter A #1a(1.0d0 2.0d0 3.0d0
                          4.0d0 5.0d0 6.0d0
                          4.0d0 5.0d0 6.0d0
                          4.0d0 5.0d0 6.0d0
                          4.0d0 5.0d0 6.0d0
                          4.0d0 5.0d0 6.0d0
                          7.0d0 8.0d0 9.0d0))
(defparameter B #1a(1.0d0 1.0d0 1.0d0
                          1.0d0 1.0d0 1.0d0
                          1.0d0 1.0d0 1.0d0
                          1.0d0 1.0d0 1.0d0
                          1.0d0 1.0d0 1.0d0
                          1.0d0 1.0d0 1.0d0
                          1.0d0 1.0d0 1.0d0))

(cxx-eigen:m.set-from-array x  A 7 3 )
(cxx-eigen:m.set-from-array y  B 3 7 )


(cxx-eigen:m.print x)
(cxx-eigen:m.print y)

;; numcl part
(ql:quickload :numcl)
(defparameter An (numcl:reshape (numcl:asarray A) '(7 3)))
(defparameter Bn (numcl:reshape (numcl:asarray B) '(3 7)))
(numcl:matmul An Bn)

;; peta part
(ql:quickload :petalisp)
(ql:quickload :petalisp.examples)

(defparameter Al (petalisp:lazy-reshape A (petalisp:~ 7 petalisp:~ 3)))
(defparameter Bl (petalisp:lazy-reshape B (petalisp:~ 3 petalisp:~ 7)))

(defun present (&rest arrays)
  (format t "~{~& => ~A~}" (petalisp:compute-list-of-arrays arrays)))

(present Al)
(present Bl)


(ql:quickload :the-cost-of-nothing)
(defparameter cnt 20)
(defparameter r (numcl:asarray (make-array '(7 7) :element-type 'double-float)))
(the-cost-of-nothing:benchmark
 (dotimes (i cnt)
   (petalisp.examples.linear-algebra:matmul Al Bl)))
(the-cost-of-nothing:benchmark
  (dotimes (i cnt)
    (cxx-eigen:m* x y)))
(the-cost-of-nothing:benchmark
  (dotimes (i cnt)
    (numcl:matmul An Bn r)))

Results:

  • petalisp is faster than non-inplace version of numcl multiplication.
  • cpp data boxing/unboxing was >10x faster than inplace version of numcl multiplication.

I want to measure the time of petalisp without allocations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant