gcl-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Gcl-devel] Re: on incf


From: Camm Maguire
Subject: [Gcl-devel] Re: on incf
Date: 01 Jul 2005 17:21:21 -0400
User-agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2

Greetings, and thanks for the report!

I've always felt, as I think you do too, that all these explicit
declarations are against the spirit of lisp and the compiler should be
smart enough to put in many of them itself.  I'm just wrapping up a
set of list and sequence compiler mods, thanks to Paul's
random-type-prop tester, which allows one to get the same result
defining the functions as follows:

(defun ddot2 (x y)
  (declare ((vector double-float) x y))
  (let ((s 0.0))
    (declare (long-float s)) ;; should be able to get rid of this eventually
    (map nil (lambda (x y) (incf s (* x y))) x y)
    s))

(defun daxpy4 (x y)
  (declare ((vector double-float) x y))
  (let ((s 0.3d0))
    (map-into y (lambda (a b) (+ (* s a) b)) x y)))

This appears to be working in my local copy at the moment.

This is probably not of interest to anyone but me, but its been
nagging at me for a long time.

It would be nice to figure out why we're not getting in-cache gcc
performance at some point.

Lastly, its been on my todo for a long time to try to compile these
directly to optimized blas calls, but then one needs to ask oneself
whether the lisp user would not just rather invoke same him/herself
explicitly. 

Take care,


Robert Boyer <address@hidden> writes:

> Just confirming your remarks in
> 
>   http://lists.gnu.org/archive/html/gcl-devel/2004-07/msg00093.html about
> 
> incf.  Breathtaking to see gcl sometimes within a few percentage points of
> gcc on a floating point computation.
> 
> It was kind of Nicolas Neuss to propose such a simple way to calculate
> MFLOPs.
> 
> Bob
> 
> GCC 3.3.4 on http://www1.iwr.uni-heidelberg.de/~Nicolas.Neuss//misc/mflop.c
> ddot-long 311.25 MFLOPS
> ddot-short 1046.28 MFLOPS
> daxpy-long 177.16 MFLOPS
> daxpy-short 1329.71 MFLOPS
> 
> gcl 2.7.0 ANSI Jul  1 2005 on mflop.lisp (below)
> DDOT-long: 272.52 MFLOPS
> DDOT-short: 547.13 MFLOPS
> DAXPY-long: 172.63 MFLOPS
> DAXPY-short: 303.32 MFLOPS
> 
> cmucl 19a on mflop.lisp (below)
> DDOT-long: 193.82 MFLOPS
> DDOT-short: 219.13 MFLOPS
> DAXPY-long: 142.78 MFLOPS
> DAXPY-short: 159.31 MFLOPS
> 
> allegro 6.2 on mflop.lisp (below)
> DDOT-long: 11.69 MFLOPS
> DDOT-short: 11.71 MFLOPS
> DAXPY-long: 7.28 MFLOPS
> DAXPY-short: 6.76 MFLOPS
> 
> clisp on mflop.lisp (below)
> DOT-long: 3.72 MFLOPS
> DDOT-short: 3.91 MFLOPS
> DAXPY-long: 3.18 MFLOPS
> DAXPY-short: 2.99 MFLOPS
> 
> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
> ;;;;  mflop.lisp
> ;;;;  http://www1.iwr.uni-heidelberg.de/~Nicolas.Neuss//misc/mflop.lisp
> ;;;;  (C) Nicolas Neuss (address@hidden)
> ;;;;  mflop.lisp is in the public domain.
> ;;;;  -- later mangled by Bob Boyer with more declarations
> ;;;;  -- and manual incf expansion
> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
> 
> (defconstant +N-long+ #x100000)  ; does not fit in secondary cache
> (defconstant +N-short+ #x100)    ; fits in primary cache
> 
> (defparameter *mflop-delta* 5.0
>   "Time interval in seconds over which we measure performance.")
> 
> (defun make-double-float-array (size &optional (initial 0.0d0))
>    (make-array size :element-type 'double-float :initial-element initial))
> 
> (defun ddot (x y n)
>   (declare (type fixnum n)
>          (type (array double-float ) x y))
>   (declare (optimize (safety 0) (space 0) (debug 0) (speed 3)))
>   (loop for i of-type fixnum from 0 below n
>       summing (the double-float (* (aref x i) (aref y i))) double-float))
> 
> (defun daxpy (x y n)
>   (declare (type fixnum n)
>          (type (array double-float ) x y))
>   (declare (optimize (safety 0) (space 0) (debug 0) (speed 3)))
>   (loop with s of-type double-float = 0.3d0
>       for i of-type fixnum from 0 below n do
>       (setf (aref (the (array double-float ) y)
>                     i)
>               (the double-float
>                 (+ (the double-float (* (the double-float s)
>                                         (the double-float
>                                           (aref (the (array (double-float ))
>                                                   x)
>                                                 i))))
>                    (the double-float (aref (the (array double-float ) y)
>                                            i)))))))
> 
> (defun test (fn name size)
>   (let ((x (make-double-float-array +N-long+))
>       (y (make-double-float-array +N-long+)))
>     (format
>      t "~A-~A: ~$ MFLOPS~%"
>      name
>      (if (= size +N-long+) "long" "short")
>      (loop with after = 0
>          for before = (get-internal-run-time) then after
>          and count = 1 then (* count 2)
>          do
>          (loop repeat count do (funcall fn x y size))
>          (setq after (get-internal-run-time))
>          (when (> (/ (- after before) internal-time-units-per-second)
>                   *mflop-delta*)
>            (return (/ (* 2 size count internal-time-units-per-second)
>                       (* 1e6 (- after before)))))))))
> 
> (defun mflop-test ()
>   "Returns several numbers characteristic for the efficiency with which
> your CL implementation will process numeric code written in a C/Fortran
> style.  This results should be significant also for other code using arrays
> for achieving good data locality.  Please compare these numbers to those
> obtained by the C version in mflop.c."
>   (test #'ddot 'ddot +N-long+)
>   (test #'ddot 'ddot +N-short+)
>   (test #'daxpy 'daxpy +N-long+)
>   (test #'daxpy 'daxpy +N-short+))
> 
> (mflop-test)
> 
> 
> 

-- 
Camm Maguire                                            address@hidden
==========================================================================
"The earth is but one country, and mankind its citizens."  --  Baha'u'llah




reply via email to

[Prev in Thread] Current Thread [Next in Thread]