如何在Java中使用Intel AVX? [英] How to use the Intel AVX in Java?

查看:445
本文介绍了如何在Java中使用Intel AVX?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用Java中的Intel AVX向量指令集?这是一个简单的问题,但答案似乎很难找到.

解决方案

据我所知,大多数当前的Java JVM JITter不支持自动矢量化,或者只是为了非常简单的循环而这样做,所以您很不走运./p>

在Mono的.NET实现中,有Mono.Simd用于手动矢量代码发射,然后后来MS引入了System.Numeric.Vectors.不幸的是,Java中没有类似的东西.我不知道Java的向量类是否使用SIMD进行向量化,但我认为它不是.

如果要使用特定于CPU的功能(例如AVX),则唯一的选择是JNI.用C或C ++编写瓶颈部分,然后从Java调用它

Scala的另一种解决方案是使用矢量化代码而不修改您可以在我们如何使JVM快40倍


更新:

现在,正在开发一种新的Vector API,用于手动编写矢量代码

提供孵化器模块jdk.incubator.vector的初始迭代,以表达向量计算,该向量计算在运行时可靠地编译为支持的CPU架构上的最佳向量硬件指令,从而实现优于同等标量计算的性能.

https://openjdk.java.net/jeps/338

How do I use the Intel AVX vector instruction set from Java? It's a simple question but the answer seems to be hard to find.

解决方案

As I know, most current Java JVM JITters don't support automatic vectorization or just do that for very simple loops, so you're out of luck.

In Mono's .NET implementation there's Mono.Simd for manual vector code emission and then later MS introduced the System.Numeric.Vectors. Unfortunately there's nothing similar in Java. I don't know if Java's vector class is vectorized using SIMD or not but I don't think it is.

If you want to use CPU-specific features like AVX then your only choice is JNI. Write your bottle neck part in C or C++ and call it from Java

There's another solution by Scala to use vectorized code without modifying the JVM that you can read in How we made the JVM 40x faster


Update:

Now there's a new Vector API being developed for writing vector code manually

Provide an initial iteration of an incubator module, jdk.incubator.vector, to express vector computations that reliably compile at runtime to optimal vector hardware instructions on supported CPU architectures and thus achieve superior performance to equivalent scalar computations.

https://openjdk.java.net/jeps/338


Read more:

这篇关于如何在Java中使用Intel AVX?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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