Re: LW compiler optimizations
"David McClain (as dbm at refined-audiometrics dot com)" <[email protected]>
| Newsgroups | gmane.lisp.lispworks.general |
|---|---|
| Message-ID | <[email protected]> |
Thank you for sharing that. I tried the DOTIMES with a displaced array. And I incorporated your declare types. My timing is still > 15x slower than the vDSP called from Lisp.
Per MAC-pair, my timing shows 6.7 ns/pair, on a 2021 M1 iMac.
Specifically:
(defun fir-dotpr-loop (fir vec &key (start2 0))
;; Fastest so far - 335 μs
#F
(declare ((simple-array double-float (*)) fir vec)
(fixnum start2))
(let* ((sum 0d0)
(nel (length fir))
(v (make-array nel
:element-type 'double-float
:displaced-to vec
:displaced-index-offset start2)))
(declare (double-float sum)
(fixnum nel)
((vector double-float *) v)
(dynamic-extent v))
(dotimes (ix nel)
(declare (fixnum ix))
(setq sum
(+ sum
(* (aref fir ix)
(aref v ix)))))
sum))
;; ——————————————
(defparameter *nel* 5633) ;; * 2 arrays, * 4 steps = 45,064 MAC ops/test
(defparameter *tst-fir* (make-array *nel*
:allocation :pinnable
:element-type 'double-float
:initial-contents (map 'vector 'dfloat (vm:unoise *nel*))))
(defparameter *tst-arr* (make-array (+ *nel* 1024)
:allocation :pinnable
:element-type 'double-float
:initial-contents (map 'vector 'dfloat (vm:unoise (+ *nel* 1024)))))
(defun test-lisp-fir-dotpr-loop ()
;; 300 μs
(dotimes (ix 4)
(declare (fixnum ix))
(let* ((start (* ix 256)))
(declare (fixnum start))
(fir-dotpr-loop *tst-fir* *tst-arr* :start2 start) ;; simulate real part
(fir-dotpr-loop *tst-fir* *tst-arr* :start2 start))))
(time
;; 300 μs/iter, 37.5 μs/vdot, 6.7 ns/MAC
;; alloc 1,050 bytes/iter, 131 bytes/vdot
(loop repeat 1000 do (test-lisp-fir-dotpr-loop)))
> On Jan 14, 2025, at 10:47, Tim Bradshaw (as tfb at tfeb dot org) <[email protected]> wrote:
>
> https://github.com/tfeb/bench-df-aref
>
> I added some more variants since yesterday, and with the best of them LW is not slower than SBCL and neither is slower than C (or than my C): both are about 0.94ns/step on my M1 machine
>
> --tim
>
> _______________________________________________
> Lisp Hug - the mailing list for LispWorks users
> [email protected]
> http://www.lispworks.com/support/lisp-hug.html
_______________________________________________
Lisp Hug - the mailing list for LispWorks users
[email protected]
http://www.lispworks.com/support/lisp-hug.html