File: TableTests.hs

package info (click to toggle)
haskell-futhark 0.25.32-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 18,236 kB
  • sloc: haskell: 100,484; ansic: 12,100; python: 3,440; yacc: 785; sh: 561; javascript: 558; lisp: 399; makefile: 277
file content (257 lines) | stat: -rw-r--r-- 10,939 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
module Futhark.Analysis.PrimExp.TableTests (tests) where

import Control.Monad.State.Strict
import Data.Map.Strict qualified as M
import Futhark.Analysis.PrimExp
import Futhark.Analysis.PrimExp.Table
import Futhark.IR.GPU
import Futhark.IR.GPUTests ()
import Futhark.IR.MC
import Futhark.IR.MCTests ()
import Test.Tasty
import Test.Tasty.HUnit

tests :: TestTree
tests = testGroup "AnalyzePrim" [stmToPrimExpsTests]

stmToPrimExpsTests :: TestTree
stmToPrimExpsTests =
  testGroup
    "stmToPrimExps"
    [stmToPrimExpsTestsGPU, stmToPrimExpsTestsMC]

stmToPrimExpsTestsGPU :: TestTree
stmToPrimExpsTestsGPU =
  testGroup
    "GPU"
    $ do
      let scope =
            M.fromList
              [ ("n_5142", FParamName "i64"),
                ("m_5143", FParamName "i64"),
                ("xss_5144", FParamName "[n_5142][m_5143]i64"),
                ("segmap_group_size_5201", LetName "i64"),
                ("segmap_usable_groups_5202", LetName "i64"),
                ("defunc_0_map_res_5203", LetName "[n_5142]i64"),
                ("defunc_0_f_res_5207", LetName "i64"),
                ("i_5208", IndexName Int64),
                ("acc_5209", FParamName "i64"),
                ("b_5210", LetName "i64"),
                ("defunc_0_f_res_5211", LetName "i64")
              ]
      [ testCase "BinOp" $ do
          let stm = "let {defunc_0_f_res_5211 : i64} = add64(acc_5209, b_5210)"
          let res = execState (stmToPrimExps scope stm) mempty
          let expected =
                M.fromList
                  [ ( "defunc_0_f_res_5211",
                      Just
                        ( BinOpExp
                            (Add Int64 OverflowWrap)
                            (LeafExp "acc_5209" (IntType Int64))
                            (LeafExp "b_5210" (IntType Int64))
                        )
                    )
                  ]
          res @?= expected,
        testCase "Index" $ do
          let stm = "let {b_5210 : i64} = xss_5144[gtid_5204, i_5208]"
          let res = execState (stmToPrimExps scope stm) mempty
          let expected = M.fromList [("b_5210", Nothing)]
          res @?= expected,
        testCase "Loop" $ do
          let stm = "let {defunc_0_f_res_5207 : i64} = loop {acc_5209 : i64} = {0i64} for i_5208:i64 < m_5143 do { {defunc_0_f_res_5211} }"
          let res = execState (stmToPrimExps scope stm) mempty
          let expected =
                M.fromList
                  [ ("defunc_0_f_res_5207", Nothing),
                    ("i_5208", Just (LeafExp "i_5208" (IntType Int64))),
                    ("acc_5209", Just (LeafExp "acc_5209" (IntType Int64)))
                  ]
          res @?= expected,
        testCase "Loop body" $ do
          let stm = "let {defunc_0_f_res_5207 : i64} = loop {acc_5209 : i64} = {0i64} for i_5208:i64 < m_5143 do { let {b_5210 : i64} = xss_5144[gtid_5204, i_5208] let {defunc_0_f_res_5211 : i64} = add64(acc_5209, b_5210) in {defunc_0_f_res_5211} }"
          let res = execState (stmToPrimExps scope stm) mempty
          let expected =
                M.fromList
                  [ ("defunc_0_f_res_5207", Nothing),
                    ("i_5208", Just (LeafExp "i_5208" (IntType Int64))),
                    ("acc_5209", Just (LeafExp "acc_5209" (IntType Int64))),
                    ("b_5210", Nothing),
                    ( "defunc_0_f_res_5211",
                      Just
                        ( BinOpExp
                            (Add Int64 OverflowWrap)
                            (LeafExp "acc_5209" (IntType Int64))
                            (LeafExp "b_5210" (IntType Int64))
                        )
                    )
                  ]
          res @?= expected,
        testCase "SegMap" $
          do
            let stm =
                  "let {defunc_0_map_res_5125 : [n_5142]i64} =\
                  \  segmap(thread; ; grid=segmap_usable_groups_5124; blocksize=segmap_group_size_5123)\
                  \  (gtid_5126 < n_5142) (~phys_tid_5127) : {i64} {\
                  \  return {returns lifted_lambda_res_5129} \
                  \}"
            let res = execState (stmToPrimExps scope stm) mempty
            let expected =
                  M.fromList
                    [ ("defunc_0_map_res_5125", Nothing),
                      ("gtid_5126", Just (LeafExp "gtid_5126" (IntType Int64)))
                    ]
            res @?= expected,
        testCase "SegMap body" $
          do
            let stm :: Stm GPU
                stm =
                  "let {defunc_0_map_res_5125 : [n_5142]i64} =\
                  \  segmap(thread; ; grid=segmap_usable_groups_5124; blocksize=segmap_group_size_5123)\
                  \  (gtid_5126 < n_5142) (~phys_tid_5127) : {i64} {\
                  \    let {eta_p_5128 : i64} =\
                  \      xs_5093[gtid_5126]\
                  \    let {lifted_lambda_res_5129 : i64} =\
                  \      add64(2i64, eta_p_5128)\
                  \    return {returns lifted_lambda_res_5129}\
                  \  }"
            let res = execState (stmToPrimExps scope stm) mempty
            let expected =
                  M.fromList
                    [ ("defunc_0_map_res_5125", Nothing),
                      ("gtid_5126", Just (LeafExp "gtid_5126" (IntType Int64))),
                      ("eta_p_5128", Nothing),
                      ( "lifted_lambda_res_5129",
                        Just
                          ( BinOpExp
                              (Add Int64 OverflowWrap)
                              (ValueExp (IntValue (Int64Value 2)))
                              (LeafExp "eta_p_5128" (IntType Int64))
                          )
                      )
                    ]
            res @?= expected
        ]

stmToPrimExpsTestsMC :: TestTree
stmToPrimExpsTestsMC =
  testGroup
    "MC"
    $ do
      let scope =
            M.fromList
              [ ("n_5142", FParamName "i64"),
                ("m_5143", FParamName "i64"),
                ("xss_5144", FParamName "[n_5142][5143]i64"),
                ("segmap_group_size_5201", LetName "i64"),
                ("segmap_usable_groups_5202", LetName "i64"),
                ("defunc_0_map_res_5203", LetName "[n_5142]i64"),
                ("defunc_0_f_res_5207", LetName "i64"),
                ("i_5208", IndexName Int64),
                ("acc_5209", FParamName "i64"),
                ("b_5210", LetName "i64"),
                ("defunc_0_f_res_5211", LetName "i64")
              ]
      [ testCase "BinOp" $ do
          let stm = "let {defunc_0_f_res_5211 : i64} = add64(acc_5209, b_5210)"
          let res = execState (stmToPrimExps scope stm) mempty
          let expected =
                M.fromList
                  [ ( "defunc_0_f_res_5211",
                      Just
                        ( BinOpExp
                            (Add Int64 OverflowWrap)
                            (LeafExp "acc_5209" (IntType Int64))
                            (LeafExp "b_5210" (IntType Int64))
                        )
                    )
                  ]
          res @?= expected,
        testCase "Index" $ do
          let stm = "let {b_5210 : i64} = xss_5144[gtid_5204, i_5208]"
          let res = execState (stmToPrimExps scope stm) mempty
          let expected = M.fromList [("b_5210", Nothing)]
          res @?= expected,
        testCase "Loop" $ do
          let stm = "let {defunc_0_f_res_5207 : i64} = loop {acc_5209 : i64} = {0i64} for i_5208:i64 < m_5143 do { {defunc_0_f_res_5211} }"
          let res = execState (stmToPrimExps scope stm) mempty
          let expected =
                M.fromList
                  [ ("defunc_0_f_res_5207", Nothing),
                    ("i_5208", Just (LeafExp "i_5208" (IntType Int64))),
                    ("acc_5209", Just (LeafExp "acc_5209" (IntType Int64)))
                  ]
          res @?= expected,
        testCase "Loop body" $ do
          let stm =
                "\
                \let {defunc_0_f_res_5207 : i64} =\
                \  loop {acc_5209 : i64} = {0i64}\
                \  for i_5208:i64 < m_5143 do {\
                \    let {b_5210 : i64} =\
                \      xss_5144[gtid_5204, i_5208]\
                \    let {defunc_0_f_res_5211 : i64} =\
                \      add64(acc_5209, b_5210)\
                \    in {defunc_0_f_res_5211}\
                \  }"
          let res = execState (stmToPrimExps scope stm) mempty
          let expected =
                M.fromList
                  [ ("defunc_0_f_res_5207", Nothing),
                    ("i_5208", Just (LeafExp "i_5208" (IntType Int64))),
                    ("acc_5209", Just (LeafExp "acc_5209" (IntType Int64))),
                    ("b_5210", Nothing),
                    ( "defunc_0_f_res_5211",
                      Just
                        ( BinOpExp
                            (Add Int64 OverflowWrap)
                            (LeafExp "acc_5209" (IntType Int64))
                            (LeafExp "b_5210" (IntType Int64))
                        )
                    )
                  ]
          res @?= expected,
        testCase "SegMap" $ do
          let stm =
                "let {defunc_0_map_res_5125 : [n_5142]i64} =\
                \  segmap()\
                \  (gtid_5126 < n_5142) (~flat_tid_5112) : {i64} {\
                \    return {returns lifted_lambda_res_5129}\
                \  }"
          let res = execState (stmToPrimExps scope stm) mempty
          let expected =
                M.fromList
                  [ ("defunc_0_map_res_5125", Nothing),
                    ("gtid_5126", Just (LeafExp "gtid_5126" (IntType Int64)))
                  ]
          res @?= expected,
        testCase "SegMap body" $ do
          let stm :: Stm MC
              stm =
                "let {defunc_0_map_res_5125 : [n_5142]i64} =\
                \  segmap()\
                \  (gtid_5126 < n_5142) (~flat_tid_5112) : {i64} {\
                \    let {eta_p_5128 : i64} =\
                \      xs_5093[gtid_5126]\
                \    let {lifted_lambda_res_5129 : i64} =\
                \      add64(2i64, eta_p_5128)\
                \    return {returns lifted_lambda_res_5129}\
                \  }"
          let res = execState (stmToPrimExps scope stm) mempty
          let expected =
                M.fromList
                  [ ("defunc_0_map_res_5125", Nothing),
                    ("gtid_5126", Just (LeafExp "gtid_5126" (IntType Int64))),
                    ("eta_p_5128", Nothing),
                    ( "lifted_lambda_res_5129",
                      Just
                        ( BinOpExp
                            (Add Int64 OverflowWrap)
                            (ValueExp (IntValue (Int64Value 2)))
                            (LeafExp "eta_p_5128" (IntType Int64))
                        )
                    )
                  ]
          res @?= expected
        ]