使用 Accelerate 框架 32 位与 64 位快速矩阵乘法 [英] matrix multiplication in swift using Accelerate framework 32 bit vs 64 bit

查看:31
本文介绍了使用 Accelerate 框架 32 位与 64 位快速矩阵乘法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 Accelerate 框架在 Swift 中进行矩阵乘法.使用了 vDSP_mmulD.这在 iPhone6、6 plus、iPad Air 模拟器(所有 64 位架构)中完美运行,但不适用于任何 32 位架构设备.它看起来像 vDSP_mmulD 不被 32 位架构识别并且程序没有构建.显示的错误消息是使用未解析的标识符‘vDSP_mmulD’" 有没有其他人看到过这个错误?请让我知道你的想法.我正在使用 Xcode 6.1.谢谢.

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.

推荐答案

简单的解决方案:使用 cblas_dgemm 代替(也是 Accelerate 的一部分).它在所有系统上至少与 vDSP_mmulD 一样快,在某些系统上更快(在 iOS 8 和 Yosemite 中,vDSP_mmulD 实际上只是 cblas_dgemm 的包装器代码>),它应该在这里工作.

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.

我怀疑您的构建对于 32 位模拟器失败了;在i386上,vDSP_mmulD其实就是一个围绕mmulD的宏,Swift不完全支持C语言宏.

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.

注意:我怀疑您可能正在使用 3x3 或 4x4 矩阵,在这种情况下,没有一个 Accelerate 例程是您真正想要的(它们针对的是更大的矩阵);您需要内联向量序列,例如 中定义的那些.不幸的是,Swift 不支持 SIMD 向量,所以这不是一个选项.此时你最好的选择可能是简单地写出元素计算,并报告一个错误以请求 Swift 支持 接口.

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.

这篇关于使用 Accelerate 框架 32 位与 64 位快速矩阵乘法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆