使用32位和64位加速框架快速进行矩阵乘法 [英] matrix multiplication in swift using Accelerate framework 32 bit vs 64 bit
问题描述
我正在尝试使用Accelerate框架在Swift中进行矩阵乘法。使用了vDSP_mmulD。这在iPhone6、6及更高版本的iPad Air模拟器(所有64位体系结构)中完美运行,但不适用于任何32位体系结构设备。
看起来vDSP_mmulD无法被32位体系结构识别,并且该程序无法构建。显示的错误消息是使用无法解析的标识符'vDSP_mmulD'其他人看到此错误了吗?请让我知道你的想法。我正在使用Xcode 6.1。
谢谢。
简单的解决方案:使用 cblas_dgemm
代替(也是Accelerate的一部分)。在所有系统上,它的速度至少与 vDSP_mmulD
一样快,而在某些系统上则要快得多(在iOS 8和Yosemite中, vDSP_mmulD
实际上只是一个 cblas_dgemm
的包装,它实际上应该在这里工作。
我怀疑您的构建是对于32位模拟器失败;在i386上,vDSP_mmulD实际上是mmulD周围的一个宏,而Swift不完全支持C语言宏。
注意:我怀疑您可能正在使用3x3或4x4矩阵,在这种情况下,任何Accelerate例程都不是您真正想要的(它们针对更大的矩阵);您需要内联矢量序列,例如< simd / matrix.h>
中定义的序列。不幸的是,Swift不支持SIMD向量,因此这不是一种选择。此时最好的选择是简单地写出元素计算,并报告一个错误以要求Swift支持< simd / simd.h>
接口。 / p>
I am trying to do matrix multiplication in Swift using the Accelerate framework. Used the vDSP_mmulD. This worked perfectly in the iPhone6 , 6 plus, iPad Air simulator (all 64 bit architecture) but did not work with any of the 32 bit architecture devices. It sees like vDSP_mmulD is not recognized by the 32 bit architecture and the program does not build. Error message displayed is "use of unresolved identifier 'vDSP_mmulD'" Has anybody else seen this error? Please let me know your thoughts. I am using Xcode 6.1. Thanks.
Simple solution: use cblas_dgemm
instead (also part of Accelerate). It's at least as fast as vDSP_mmulD
on all systems, and much faster on some (in iOS 8 and Yosemite, vDSP_mmulD
is actually just a wrapper around cblas_dgemm
), and it should actually work here.
I suspect that your build is failing for the 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 may be working with 3x3 or 4x4 matrices, in which case none of the Accelerate routines are really what you want (they're aimed a larger matrices); you want inline vector sequences like the ones defined in <simd/matrix.h>
. Unfortunately, Swift doesn't support SIMD vectors, so that's not an option. Your best bet at this point may be to simply write out the elementwise computation, and report a bug to request that Swift support the <simd/simd.h>
interfaces.
这篇关于使用32位和64位加速框架快速进行矩阵乘法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!