Petalisp icon indicating copy to clipboard operation
Petalisp copied to clipboard

Support inplace multiplication.

Open Islam0mar opened this issue 3 years ago • 0 comments

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.

Islam0mar avatar Feb 09 '23 16:02 Islam0mar