Mailing Lists: Apple Mailing Lists
Image of Mac OS face in stamp
Re: basic math operations to very large arrays
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: basic math operations to very large arrays



Draggin up old threads is good...

I ask this question because I am having success using vImage in the
Accelerate.Framework.

The very large arrays of which I speak are merely image data in
memory.  I need to take one image and subtract it from another.
(imageDataA[i] - imageDataB[i] = imageDataC[c])
right now I just do it via indirection (pointers) in a for loop.  The
images are in the range of 8 megapixels so the calculations are in the
millions per image (time many images)

Unfortunately this simple subtraction problem is as complicated as it
gets for this one part of the app.

The data comes to me from a camera as an imageData array. (unsigned
char)  To use vDSP (as I understand) I would have to "vectorize" the
imageData array and then perform my simple math operation and then
translate it back into unsigned char.

Or am I wrong...
(wouldn't be the first time BTW)

On 11/1/06, Ian Ollmann <email@hidden> wrote:

On Oct 28, 2006, at 1:13 PM, Jan E. Schotsman wrote:

>
> On 28-okt-06, at 21:02, Bruce Johnson wrote:
>
>> I'm looking for help in performing math operations to very large
>> arrays.
>
> I don't think these simple operations are in the Accelerate framework.
> vForce only has special functions applied to arrays.
> So you need a third party library like macstl or just write the
> code yourself.
> In this case use vec_sub or vec_subs on Altivec and _mm_sub_epi8 or
> _mm_subs_epu8 on Intel.

(Sorry to drag up old threads, I just got back from vacation.)

Tiny little functions that do very little arithmetic on data like the
subtraction example provided don't perform very well on modern
processors. If you take the time to disassemble your code, you'd see
that for every subtract there are as many as 3x as many LSU
operations, which become the bottleneck and slow the calculation way
down.

You are almost always better off writing whatever complicated
arithmetic you need as a single function, rather than try to build it
out of a bunch of little ones.

If you *really* need these things, you can find some of them in
vDSP.h. However be warned that they are not the panacea that you may
think they are and when used in aggregate may actually perform slower
than scalar code in some cases. Something like MacSTL or writing your
own vector code is a better choice. vDSP provides them for the rare
case where the *only* thing you need to do is the simple operation.

Ian
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
PerfOptimization-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden



--
----
Bruce Johnson
email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
PerfOptimization-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >Re: basic math operations to very large arrays (From: Ian Ollmann <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2011 Apple Inc. All rights reserved.