带条件复制的SIMD指令

时间:2016-05-03 17:29:35

标签: fortran vectorization intel simd

我有一个看起来像这样的热点。这里聚集的某种矢量会很好...有关如何让编译器喜欢这个的任何建议吗?

        do ii = 1, N
           if (diff(ii) .le. M ) then
              i = i0 + ii - 1
              rbuf( irb ) = i 
              irb = irb + 1               
           end if
        end do

使用ifort 16.0.2我的opt报告看起来像

LOOP BEGIN at code.f(197,13)
   remark #25084: Preprocess Loopnests: Moving Out Store    [ code.f(203,13) ]
     remark #15344: loop was not vectorized: vector dependence prevents vectorization
     remark #15346: vector dependence: assumed FLOW dependence between irb line 201 and irb line 200
     remark #15346: vector dependence: assumed ANTI dependence between irb line 200 and irb line 201
     remark #15346: vector dependence: assumed ANTI dependence between irb line 200 and irb line 201
     remark #15346: vector dependence: assumed FLOW dependence between irb line 201 and irb line 200
     remark #25439: unrolled with remainder by 2
     remark #25015: Estimate of max trip count of loop=1600
  LOOP END

这是小型测试程序

program vect

integer :: ii, i0, irb
integer, parameter :: N=32
integer, parameter :: M=8
integer, dimension(N) :: diff
integer, dimension(2*N) :: rbuf

rbuf = 0

!only some values of diff will meet condition
!could be random
do ii=1, N
   diff(ii) = ii
end do

!from an outer loop
i0=1003

!this is code for filling up a buffer for an expensive vectorized
!subroutine with full vectors, irb < 2*N
irb=3

do ii = 1, N
   if (diff(ii) .le. M ) then
      i = i0 + ii - 1
      rbuf( irb ) = i 
      irb = irb + 1               
   end if
end do


!check 
do ii = 1, 2*N
   write(*,*) ii, rbuf(ii)
end do

end

1 个答案:

答案 0 :(得分:1)

根据目标架构,我能够让编译器使用指令进行矢量化。

!CDIR$ IVDEP
do ii = 1, N
 if (diff(ii) .le. M ) then
   i = i0 + ii - 1
   rbuf( irb ) = i 
   irb = irb + 1               
 end if
end do

-xMIC-AVX512-mmic将为这些架构提供矢量说明。 e.g。

vpcompressd %zmm0, -4+vect_$RBUF.0.1(,%rax,4){%k1}      #29.15 c1

对于AVX2,我认为人们已经诉诸于@Peter Cordes在他的评论中建议的内在函数/ asm,但很高兴知道编译器可以在未来解决这个问题。