Skip to content

Commit

Permalink
Minimise modulos when rotating multidim arrays.
Browse files Browse the repository at this point in the history
  • Loading branch information
athas committed Jun 18, 2023
1 parent 9fbe99c commit 64d97e8
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/Futhark/CodeGen/ImpGen.hs
Original file line number Diff line number Diff line change
Expand Up @@ -991,10 +991,11 @@ defCompileBasicOp _ Rearrange {} =
defCompileBasicOp (Pat [pe]) (Rotate rs arr) = do
shape <- arrayShape <$> lookupType arr
sLoopNest shape $ \is -> do
is' <- sequence $ zipWith3 rotate (shapeDims shape) rs is
is' <- sequence $ zipWith3 rotate (shapeDims shape) (map pe64 rs) is
copyDWIMFix (patElemName pe) is (Var arr) is'
where
rotate d r i = dPrimVE "rot_i" $ rotateIndex (pe64 d) (pe64 r) i
rotate _ 0 i = pure i
rotate d r i = dPrimVE "rot_i" $ rotateIndex (pe64 d) r i
defCompileBasicOp _ Reshape {} =
pure ()
defCompileBasicOp _ (UpdateAcc acc is vs) = sComment "UpdateAcc" $ do
Expand Down
1 change: 1 addition & 0 deletions src/Futhark/CodeGen/ImpGen/GPU/Base.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1418,6 +1418,7 @@ sRotateKernel dest rs src = do
is'' <- sequence $ zipWith3 rotate ds rs is'
copyDWIMFix dest is' (Var src) is''
where
rotate _ 0 i = pure i
rotate d r i = dPrimVE "rot_i" $ rotateIndex d r i

compileThreadResult ::
Expand Down
1 change: 1 addition & 0 deletions src/Futhark/CodeGen/ImpGen/Multicore.hs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ parallelRotate dest rs src = do
is' <- dIndexSpace' "rep_i" ds i
is'' <- sequence $ zipWith3 rotate ds rs is'
copyDWIMFix dest is' (Var src) is''
rotate _ 0 i = pure i
rotate d r i = dPrimVE "rot_i" $ rotateIndex d r i

topLevelOps, inThreadOps :: Operations MCMem HostEnv Imp.Multicore
Expand Down

0 comments on commit 64d97e8

Please sign in to comment.