Octave JIT 编译器。当前状态和展示效果的最小示例
Octave JIT compiler. Current state, and minimal example demonstrating effect
我听到关于 Octave 的实验性 JIT 编译器功能的非常矛盾的信息,范围从 "it was a toy project but it basically doesn't work" 到 "I've used it and I get a significant speedup"。
我知道要成功使用它需要
- 在配置时用
--enable-jit
编译八度
- 使用
--jit-compiler
选项启动 Octave
- 使用
jit_enable
和 jit_startcnt
命令在运行时指定 jit 编译首选项
但我无法令人信服地重现这些效果;不确定这是不是因为我错过了我不知道的任何其他步骤,或者它对我的机器没有太大影响。
问:成功使用该功能的人能否提供一个最小的工作示例来证明其正确使用及其在他们的机器上的效果(如果有)?
简而言之:
- 您无需执行任何操作即可使用 JIT,它应该可以正常工作并加速您的代码;
- 它几乎没用,因为它只适用于简单的循环;
- 它只不过是一个概念的证明;
- 目前没有人致力于改进它,因为:
- 这是一个复杂的问题;
- 它主要是对草率的 Octave 代码的修复;
- 使用的 LLVM 太不稳定了。
Q: Can someone who has used the feature successfully provide a minimal working example demonstrating its proper use and the effect it has (if any) on their machine?
没有什么可显示的。如果您使用 JIT 支持构建 Octave,Octave 将自动为某些循环使用更快的代码。唯一的区别在于速度,您不必更改代码(尽管您可以在运行时禁用 jit):
octave> jit_enable (1) # confirm JIT is enabled
octave> tic; x = 0; for i=1:100000, x += i; endfor, toc
Elapsed time is 0.00490594 seconds.
octave> jit_enable (0) # disable JIT
octave> tic; x = 0; for i=1:100000, x += i; endfor, toc
Elapsed time is 0.747599 seconds.
## but you should probably write it like this
octave> tic; x = sum (1:100000); toc
Elapsed time is 0.00327611 seconds.
## If Octave was built without JIT support, you will get the following
octave> jit_enable (1)
warning: jit_enable: support for JIT was unavailable or disabled when Octave was built
这是一个简单的示例,但您可以在 blog of the only person that worked on it, as well as his presentation at OctConf 2012. More details on the (outdated), Octave's JIT wiki page
上看到更好的示例和更多详细信息
请注意,Octave 的 JIT 仅适用于非常简单的循环。如此简单的循环,以至于熟悉该语言的人都不会首先编写它们。该功能作为概念证明存在,并且是任何可能想要扩展它的人的起点(我个人更喜欢编写矢量化代码,这就是该语言的设计目的)。
Octave 的 JIT 还有另外一个问题,那就是它使用了 LLVM。 Octave 开发人员发现它对于这个目的来说太不可靠了,因为它不断破坏向后兼容性。 LLVM 的每个次要版本都破坏了 Octave 构建,因此 Octave 开发人员在 LLVM 3.5 发布时停止修复并默认禁用它。
我听到关于 Octave 的实验性 JIT 编译器功能的非常矛盾的信息,范围从 "it was a toy project but it basically doesn't work" 到 "I've used it and I get a significant speedup"。
我知道要成功使用它需要
- 在配置时用
--enable-jit
编译八度 - 使用
--jit-compiler
选项启动 Octave - 使用
jit_enable
和jit_startcnt
命令在运行时指定 jit 编译首选项
但我无法令人信服地重现这些效果;不确定这是不是因为我错过了我不知道的任何其他步骤,或者它对我的机器没有太大影响。
问:成功使用该功能的人能否提供一个最小的工作示例来证明其正确使用及其在他们的机器上的效果(如果有)?
简而言之:
- 您无需执行任何操作即可使用 JIT,它应该可以正常工作并加速您的代码;
- 它几乎没用,因为它只适用于简单的循环;
- 它只不过是一个概念的证明;
- 目前没有人致力于改进它,因为:
- 这是一个复杂的问题;
- 它主要是对草率的 Octave 代码的修复;
- 使用的 LLVM 太不稳定了。
Q: Can someone who has used the feature successfully provide a minimal working example demonstrating its proper use and the effect it has (if any) on their machine?
没有什么可显示的。如果您使用 JIT 支持构建 Octave,Octave 将自动为某些循环使用更快的代码。唯一的区别在于速度,您不必更改代码(尽管您可以在运行时禁用 jit):
octave> jit_enable (1) # confirm JIT is enabled
octave> tic; x = 0; for i=1:100000, x += i; endfor, toc
Elapsed time is 0.00490594 seconds.
octave> jit_enable (0) # disable JIT
octave> tic; x = 0; for i=1:100000, x += i; endfor, toc
Elapsed time is 0.747599 seconds.
## but you should probably write it like this
octave> tic; x = sum (1:100000); toc
Elapsed time is 0.00327611 seconds.
## If Octave was built without JIT support, you will get the following
octave> jit_enable (1)
warning: jit_enable: support for JIT was unavailable or disabled when Octave was built
这是一个简单的示例,但您可以在 blog of the only person that worked on it, as well as his presentation at OctConf 2012. More details on the (outdated), Octave's JIT wiki page
上看到更好的示例和更多详细信息请注意,Octave 的 JIT 仅适用于非常简单的循环。如此简单的循环,以至于熟悉该语言的人都不会首先编写它们。该功能作为概念证明存在,并且是任何可能想要扩展它的人的起点(我个人更喜欢编写矢量化代码,这就是该语言的设计目的)。
Octave 的 JIT 还有另外一个问题,那就是它使用了 LLVM。 Octave 开发人员发现它对于这个目的来说太不可靠了,因为它不断破坏向后兼容性。 LLVM 的每个次要版本都破坏了 Octave 构建,因此 Octave 开发人员在 LLVM 3.5 发布时停止修复并默认禁用它。