From 1dc7e3e17f5a4a658be1185f72809a1d1912f541 Mon Sep 17 00:00:00 2001 From: Troels Henriksen Date: Thu, 9 Jan 2025 12:00:50 +0100 Subject: [PATCH] Fix GPU compilation of array values. --- CHANGELOG.md | 2 ++ src/Futhark/CodeGen/ImpGen/GPU/Base.hs | 3 +++ src/Futhark/CodeGen/ImpGen/GPU/Block.hs | 2 ++ 3 files changed, 7 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 41b98b198e..72b91381ac 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. * `futhark pkg`: fixed parsing of Git timestamps in Z time zone. +* GPU backends did not handle array constants correctly in some cases. + ## [0.25.25] ### Added diff --git a/src/Futhark/CodeGen/ImpGen/GPU/Base.hs b/src/Futhark/CodeGen/ImpGen/GPU/Base.hs index 5e4045e1a9..4ef1f02eeb 100644 --- a/src/Futhark/CodeGen/ImpGen/GPU/Base.hs +++ b/src/Futhark/CodeGen/ImpGen/GPU/Base.hs @@ -184,6 +184,9 @@ compileThreadExp :: ExpCompiler GPUMem KernelEnv Imp.KernelOp compileThreadExp (Pat [pe]) (BasicOp (Opaque _ se)) = -- Cannot print in GPU code. copyDWIM (patElemName pe) [] se [] +-- The static arrays stuff does not work inside kernels. +compileThreadExp (Pat [dest]) (BasicOp (ArrayVal vs t)) = + compileThreadExp (Pat [dest]) (BasicOp (ArrayLit (map Constant vs) (Prim t))) compileThreadExp (Pat [dest]) (BasicOp (ArrayLit es _)) = forM_ (zip [0 ..] es) $ \(i, e) -> copyDWIMFix (patElemName dest) [fromIntegral (i :: Int64)] e [] diff --git a/src/Futhark/CodeGen/ImpGen/GPU/Block.hs b/src/Futhark/CodeGen/ImpGen/GPU/Block.hs index 0fecff17e9..128e79a873 100644 --- a/src/Futhark/CodeGen/ImpGen/GPU/Block.hs +++ b/src/Futhark/CodeGen/ImpGen/GPU/Block.hs @@ -278,6 +278,8 @@ compileBlockExp (Pat [pe]) (BasicOp (Opaque _ se)) = -- Cannot print in GPU code. copyDWIM (patElemName pe) [] se [] -- The static arrays stuff does not work inside kernels. +compileBlockExp (Pat [dest]) (BasicOp (ArrayVal vs t)) = + compileBlockExp (Pat [dest]) (BasicOp (ArrayLit (map Constant vs) (Prim t))) compileBlockExp (Pat [dest]) (BasicOp (ArrayLit es _)) = forM_ (zip [0 ..] es) $ \(i, e) -> copyDWIMFix (patElemName dest) [fromIntegral (i :: Int64)] e []