Haskell中的INLINE_FUSED编译指示

时间:2014-05-17 13:31:22

标签: haskell optimization vector inline vectorization

我正在浏览矢量库并注意到{-# INLINE_FUSED transform #-},我想知道它的作用是什么?我看到它在vector.h中定义,但在其他任何地方都没有。

1 个答案:

答案 0 :(得分:12)

定义表示INLINE_FUSEDINLINE [1]相同; INLINE_INNERINLINE [0]相同。 [1][0]是用于排序内联阶段的标准ghc。请参阅标题 7.13.5.5下的讨论。 http://www.haskell.org/ghc/docs/7.0.4/html/users_guide/pragmas.html

中的阶段控制

vector需要控制ghc内联各种定义的阶段。首先,它希望公开函数streamunstream的所有用法,以便(最重要的)stream.unstream可以被id替换,并且在其他情况下也是如此,根据(重写)RULE pragma分布在整个。

向量函数的典型向量写为unstream . f . stream,其中f是Stream to Stream函数。 unstreamStream在内存中构建实际向量; stream将实数向量读入Stream。游戏的目的是减少构建的实际向量的数量。所以三个向量到向量函数的组成

 f_vector . g_vector . h_vector

真的是

 unstream . f_stream . stream . unstream . g_stream . stream . unstream . h_stream . stream

他改写为

 unstream . f_stream . g_stream . h_stream . stream

等等。所以我们写了一个新的向量而不是三个。

transform的规则比这更有趣,但属于同一个微妙的排序系统:

 transform f g (unstream s) = unstream (Bundle.inplace f g s)
 transform f1 g1 (transform f2 g2 p) = transform (f1 . f2) (g1 . g2) p
https://github.com/haskell/vector/blob/master/Data/Vector/Generic/New.hs#L76

中的

所以你可以看到表格内联的内容:

unstream . h_stream . stream . transform f1 g1 . transform f2 g2 
                    . unstream . j_stream . stream $ input_vector

将被重写。