Re: Alternative to copy-in/copy-out?

"Liam M. Healy" <[email protected]> Wed, 23 Oct 2002 13:40:42 -0400
Newsgroups gmane.lisp.uffi.general
Message-ID <[email protected]>
>>>>> "Kevin" == Kevin Rosenberg <kevin-HJRc7zDS/[email protected]> writes:

    Kevin> Liam M. Healy wrote:
    >> When using the ACL interface I could directly pass CL objects to and
    >> from foreign code.  I am looking for the analogue in UFFI.
    >> In c-test-fns.lisp there is a function

    Kevin> Yes, ACL does have an efficiency there.

    >> (defun t2 ()
    >> (let ((vec (make-array +double-vec-length+ :element-type 'double-float)))
    >> (dotimes (i +double-vec-length+)
    >> (setf (aref vec i) (coerce i 'double-float)))
    >> (half-double-vector +double-vec-length+ vec)
    >> vec))
    >> does, and is much simpler, and should be more efficient.  However,
    >> it doesn't work for me.   

    Kevin> t2 is non-portable, that's why it is not included in the actual
    Kevin> testing. On what platform does it fail, ACL?

CL-USER(16): (t2)
#(0.0 1.118751109680031e-154 1.4916681462400413e-154 1.8645851828000517e-154 2.237502219360062e-154
  2.4239607376400672e-154 2.6104192559200724e-154 2.7968777742000775e-154 2.983336292480083e-154 9.0)
CL-USER(17): (lisp-implementation-version)
"6.2 [Linux (x86)] (Oct 4, 2002 16:57)"
CL-USER(18): (software-type)
"Linux 2.x, Redhat 6.x and 7.x"
CL-USER(19): (software-version)
"Linux shadow 2.4.18-xfs #1 Tue Jun 11 12:09:02 EDT 2002 i686 unknown"
CL-USER(20): (lisp-implementation-type)
"Allegro CL Enterprise Edition"

Here's how I would implement a direct call in ACL:

(ff:def-foreign-call (half-double-vector "half_double_vector")
    ((size :int)
     (vec (:array :double)))
  :returning :void)

then
(t2)
#(0.0 0.5 1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5)
as expected, with t2 as in c-test-fns.

    Kevin> As you can see in the code, there is also t3 which is an attempt to
    Kevin> doing somethin similar in cmucl.

    Kevin> I don't know if Lispworks or OpenMCL have an implementation specific
    Kevin> way of avoiding the copy-in and copy-out.

I have a copy of Lispworks and I don't see an option to do this, but
I'm no expert.

    >> Is there a way to avoid copy-in and copy-out when making foreign
    >> calls through UFFI? 

    Kevin> At this point, there is not a portable way across all 7 supported UFFI
    Kevin> implementations (ACL, LW, SBCL, CMUCL, SCL, OpenMCL, MCL) to do this.
    Kevin> As you can see from the t3 code, for CMUCL & SCL it is faily
    Kevin> complicated to do this. 

Well, there are a couple additional forms over t2 - system:without-gcing and
system:vector-sap.  Of course, I see your point that it defeats portability.

    Kevin> At some point, UFFI could be extended to wrap this functionality
    Kevin> around each implementation's method.

    Kevin> Is ACL your primary platform? If so, maybe you can make the majority
    Kevin> of your code plain UFFI, but then we can work together on a work
    Kevin> around where you can have a #+allegro in your code that handles ACL
    Kevin> specific optimizations and then #-allegro which does it via
    Kevin> copy-in/copy-out.

Yes it is.  At this point my foreign calling needs are minor, and
there is no loss in using UFFI all the way, except the esthetic one.
I can see that if all the implementations don't support a particular
model, then it's going to be less desirable to implement.

Liam