Matrix multiplication in swift using Accelerate platform 32 bit vs 64 bit

I am trying to do matrix multiplication in Swift using the Accelerate framework. Used vDSP_mmulD. This worked fine on iPhone6, 6 plus, iPad Air simulator (all 64-bit architecture), but did not work with any of the 32-bit architecture devices. He sees that vDSP_mmulD is not recognized by the 32-bit architecture, and the program does not create. The error message "using unresolved identifier" vDSP_mmulD "is displayed. Has anyone else seen this error? Please share your thoughts. I am using Xcode 6.1. Thanks.

+3


source to share


3 answers


Simple solution: use cblas_dgemm

(also speedup part) instead . It's at least as fast as it is vDSP_mmulD

on all systems, and much faster on some (in iOS 8 and Yosemite, vDSP_mmulD

really just a wrapper around cblas_dgemm

), and it should really work here.

I suspect your build is not working for a 32 bit simulator; on i386 vDSP_mmulD is actually a macro around mmulD and Swift does not fully support C language macros.



Note. I have a suspicion that you might be working with 3x3 or 4x4 matrices, in which case none of the Accelerate routines are really needed (they target larger matrices); you need inline vector sequences like the ones defined in <simd/matrix.h>

. Unfortunately Swift does not support SIMD vectors, so this is not an option. Your best bet at this point is to simply write a rudimentary computation and report the error so that the Swift query will support interfaces <simd/simd.h>

.

+2


source


So, this is all speculative since I don't have a 32-bit device to test right now and I can't find any documentation to support this, but perhaps Accelerate works with different floating point types on two different architectures - Float

in 32 -bit architecture and Double

64-bit architecture. D

at the end vDSP_mmulD

means Double

, so you will need to use a version Float

for 32-bit architecture in your code: vDSP_mmul

.

You can use the preprocessing block #if...#else...#endif

to switch between the methods you are using (information at the bottom of this page ). One trick to get around Swift's strong static typing is to place something like this preprocessing block at the top of your file:

#if arch(x86_64) || arch(arm64)
    typealias M_Float = Double
    let M_vDSP_mmul = vDSP_mmulD
    // add Double versions of other Accelerate functions you need
#else
    typealias M_Float = Float
    let M_vDSP_mmul = vDSP_mmul
    // add Float versions of other Accelerate functions you need
#endif

      



Then, instead of having to choose whether you are working with Float

or Double

, or which method to use everything in your code, you can simply use M_Float

your versions M_...

of the acceleration functions as well

var number: M_Float = 0    // Double on 64-bit, Float on 32-bit
M_vDSP_mmul(...)           // correct version either way

      

Hope it helps!

+1


source


0


source







All Articles