将 MMX 与托管 C 结合使用
据我了解,JIT 不会将 MSIL 编译为将在 x86 上使用 MMX 指令的本机机器代码。如果这是真的(因为我很难找到有关此事的最新信息),那么我想要一种在我的代码中利用 MMX 的方法。我正在开发一个应用程序,它将执行几乎所有单精度浮点数乘法(它是人工神经网络)。我基本上对此事有几个疑问。
我的第一个问题是,如果我在同一个项目中混合托管和非托管代码,难道不是因为“它可以工作”而全部编译成 MSIL 吗?如果我将非托管部分制作为静态或动态库,编译它们并在我的托管项目中使用它们,我会获得最佳性能吗?
CUDA)一起使用,但它无法在 ATI 上工作:( ),但如果我要这样做,是否必须从非托管 c++ 调用编译后的 GPU 代码?
我还考虑过将我的 GPU 与 OpenCL(或 所有,我只是在寻找获得最快浮点算法的最佳方法,同时仍然能够使用我的托管 GUI 和多线程,并且使用 MMX 等扩展似乎是我的最佳选择(如果我只想使用 CPU)。做这样的事情最好的方法是什么?
谢谢。
From what I understand, the JIT does not compile the MSIL into native machine code that will utilize MMX instructions on x86. If this is true (as I'm having a hard time finding up to date information on the matter), then I want a way to utilize MMX in my code. I am working on an application that will be doing almost all single precision floating point number multiplication (it's artificial neural networks). I basically have several questions around the matter.
My first is, if I mix managed and unmanaged code in the same project, isn't it all compiled into MSIL because "It Just Works"? Would I get the best performance if I made the unmanaged parts as static or dynamic libraries, compiled them, and used them in my managed project?
I have also looked into using my GPU with OpenCL (or CUDA, but then it wouldn't work on ATI :( ) but if I was to do that, wouldn't the compiled GPU code have to be called from unmanaged c++?
Over all, I am just looking for the best way to get the fastest floating point arthmitic while still being able to use my managed GUI and Multithreading and using extensions like MMX seem to be my best option (if I only want to use the CPU). What is the best way there may be to go about doing such a thing?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
MMX 是整数指令集,而不是浮点数。它仅支持 64 位打包字节、字和双字整数。 SSE 有浮点支持。使用代码中管理的#pragma 在机器代码和 MSIL 生成之间切换。
MMX is an integer instruction set, not floating point. It only supports 64-bit packed byte, word and double-word integers. SSE has floating point support. Use #pragma managed in your code to switch between machine code and MSIL generation.
您可以混合托管和非托管代码。仅托管被编译为 MSIL。其余的都是原生的。
托管和非托管之间存在成本……但还不错。
因此,我会编写一个本机库来完成所有高性能工作,然后从托管代码中使用它。
you can mix managed and unmanaged code. Only the managed is compiled to MSIL. The rest is native.
There is a cost going between managed and unmanaged....but not too bad.
So I'd write a native lib that did all your high performance stuff and then use it from your managed code.
不。如果你不使用
/clr:pure
进行编译,本机代码可以保持本机并与 .NET 代码混合。这称为混合模式装配。 (使用/clr:pure
,一切都变成了IL,并且你根本不能使用本机代码。)本机代码将保持本机。No. If you don't compile with
/clr:pure
, native code can stay native and be mixed in with .NET code. This is called a mixed-mode assembly. (With/clr:pure
, everything is turned into IL, and you can't use native code at all.) Native code will stay native.