File: IxFunTests.hs

package info (click to toggle)
haskell-futhark 0.25.32-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, 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 (571 lines) | stat: -rw-r--r-- 21,294 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
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
{-# OPTIONS_GHC -fno-warn-orphans #-}

module Futhark.IR.Mem.IxFunTests
  ( tests,
  )
where

import Data.Bifunctor
import Data.Function ((&))
import Data.List qualified as L
import Data.Map qualified as M
import Data.Text qualified as T
import Futhark.Analysis.PrimExp.Convert
import Futhark.IR.Mem.IxFun.Alg qualified as IxFunAlg
import Futhark.IR.Mem.IxFunWrapper
import Futhark.IR.Mem.IxFunWrapper qualified as IxFunWrap
import Futhark.IR.Mem.LMAD qualified as IxFunLMAD
import Futhark.IR.Prop
import Futhark.IR.Syntax
import Futhark.IR.Syntax.Core ()
import Futhark.Util.IntegralExp qualified as IE
import Futhark.Util.Pretty
import Test.Tasty
import Test.Tasty.HUnit
import Prelude hiding (span)
import Prelude qualified as P

instance IE.IntegralExp Int where
  quot = P.quot
  rem = P.rem
  div = P.div
  mod = P.mod
  pow = (P.^)
  sgn = Just . P.signum

allPoints :: [Int] -> [[Int]]
allPoints dims =
  let total = product dims
      strides = drop 1 $ L.reverse $ scanl (*) 1 $ L.reverse dims
   in map (unflatInd strides) [0 .. total - 1]
  where
    unflatInd :: [Int] -> Int -> [Int]
    unflatInd strides x =
      fst $
        foldl
          ( \(res, acc) span ->
              (res ++ [acc `P.div` span], acc `P.mod` span)
          )
          ([], x)
          strides

compareIxFuns :: Maybe (IxFunLMAD.LMAD Int) -> IxFunAlg.IxFun Int -> Assertion
compareIxFuns (Just ixfunLMAD) ixfunAlg =
  let lmadShape = IxFunLMAD.shape ixfunLMAD
      algShape = IxFunAlg.shape ixfunAlg
      points = allPoints lmadShape
      resLMAD = map (IxFunLMAD.index ixfunLMAD) points
      resAlg = map (IxFunAlg.index ixfunAlg) points
      errorMessage =
        T.unpack . docText $
          "lmad ixfun:  "
            <> pretty ixfunLMAD
              </> "alg ixfun:   "
            <> pretty ixfunAlg
              </> "lmad shape:  "
            <> pretty lmadShape
              </> "alg shape:   "
            <> pretty algShape
              </> "lmad points length: "
            <> pretty (length resLMAD)
              </> "alg points length:  "
            <> pretty (length resAlg)
              </> "lmad points: "
            <> pretty resLMAD
              </> "alg points:  "
            <> pretty resAlg
   in (lmadShape == algShape && resLMAD == resAlg) @? errorMessage
compareIxFuns Nothing ixfunAlg =
  assertFailure $
    unlines
      [ "lmad ixfun: Nothing",
        "alg ixfun:  " <> prettyString ixfunAlg
      ]

compareOps :: IxFunWrap.IxFun Int -> Assertion
compareOps (ixfunLMAD, ixfunAlg) = compareIxFuns ixfunLMAD ixfunAlg

compareOpsFailure :: IxFunWrap.IxFun Int -> Assertion
compareOpsFailure (Nothing, _) = pure ()
compareOpsFailure (Just ixfunLMAD, ixfunAlg) =
  assertFailure . T.unpack . docText $
    "Not supposed to be representable as LMAD."
      </> "lmad ixfun: "
      <> pretty ixfunLMAD
        </> "alg ixfun:  "
      <> pretty ixfunAlg

-- XXX: Clean this up.
n :: Int
n = 19

slice3 :: Slice Int
slice3 =
  Slice
    [ DimSlice 2 (n `P.div` 3) 3,
      DimFix (n `P.div` 2),
      DimSlice 1 (n `P.div` 2) 2
    ]

-- Actual tests.
tests :: TestTree
tests =
  testGroup "IxFunTests" $
    concat
      [ test_iota,
        test_slice_iota,
        test_slice_reshape_iota1,
        test_permute_slice_iota,
        test_reshape_iota,
        test_reshape_permute_iota,
        test_slice_reshape_iota2,
        test_reshape_slice_iota3,
        test_flatten_strided,
        test_complex1,
        test_complex2,
        test_expand1,
        test_expand2,
        test_expand3,
        test_expand4,
        test_flatSlice_iota,
        test_slice_flatSlice_iota,
        test_flatSlice_flatSlice_iota,
        test_flatSlice_slice_iota,
        test_flatSlice_transpose_slice_iota
        -- TODO: Without z3, these tests fail. Ideally, our internal simplifier
        -- should be able to handle them:
        --
        -- test_disjoint3
      ]

singleton :: TestTree -> [TestTree]
singleton = (: [])

test_iota :: [TestTree]
test_iota =
  singleton . testCase "iota" . compareOps $
    iota [n]

test_slice_iota :: [TestTree]
test_slice_iota =
  singleton . testCase "slice . iota" . compareOps $
    slice (iota [n, n, n]) slice3

test_slice_reshape_iota1 :: [TestTree]
test_slice_reshape_iota1 =
  singleton . testCase "slice . reshape . iota 1" . compareOps $
    slice (reshape (iota [n, n, n]) [n `P.div` 2, n `P.div` 3, 1]) slice3

test_permute_slice_iota :: [TestTree]
test_permute_slice_iota =
  singleton . testCase "permute . slice . iota" . compareOps $
    permute (slice (iota [n, n, n]) slice3) [1, 0]

test_reshape_iota :: [TestTree]
test_reshape_iota =
  -- This tests a pattern that occurs with ScalarSpace.
  singleton . testCase "reshape . zeroslice . iota" . compareOps $
    let s = Slice [DimSlice 0 n 0, DimSlice 0 n 1]
     in reshape (slice (iota [n, n]) s) [1, n, 1, n]

test_reshape_permute_iota :: [TestTree]
test_reshape_permute_iota =
  -- negative reshape test
  singleton . testCase "reshape . permute . iota" . compareOpsFailure $
    let newdims = [n * n, n]
     in reshape (permute (iota [n, n, n]) [1, 2, 0]) newdims

test_slice_reshape_iota2 :: [TestTree]
test_slice_reshape_iota2 =
  singleton . testCase "slice . reshape . iota 2" . compareOps $
    let newdims = [n * n, n]
        slc =
          Slice
            [ DimFix (n `P.div` 2),
              DimSlice 0 n 1
            ]
     in slice (reshape (iota [n, n, n, n]) newdims) slc

test_reshape_slice_iota3 :: [TestTree]
test_reshape_slice_iota3 =
  -- negative reshape test
  singleton . testCase "reshape . slice . iota 3" . compareOpsFailure $
    let newdims = [n * n, n]
        slc =
          Slice
            [ DimFix (n `P.div` 2),
              DimSlice 0 n 1,
              DimSlice 0 (n `P.div` 2) 1,
              DimSlice 0 n 1
            ]
     in reshape (slice (iota [n, n, n, n]) slc) newdims

-- Tests flattening something that is strided - this can occur after
-- memory expansion.
test_flatten_strided :: [TestTree]
test_flatten_strided =
  singleton . testCase "reshape . fix . iota 3d" . compareOps $
    let slc = Slice [DimSlice 0 n 1, DimSlice 0 2 1, DimFix 1]
     in reshape (slice (iota [n, 2, n * n]) slc) [2 * 10]

test_complex1 :: [TestTree]
test_complex1 =
  singleton . testCase "permute . slice . permute . slice . iota 1" . compareOps $
    let slice33 =
          Slice
            [ DimSlice (n - 1) (n `P.div` 3) (-1),
              DimSlice (n - 1) n (-1),
              DimSlice (n - 1) n (-1),
              DimSlice 0 n 1
            ]
        ixfun = permute (slice (iota [n, n, n, n, n]) slice33) [3, 1, 2, 0]
        m = n `P.div` 3
        slice1 =
          Slice
            [ DimSlice 0 n 1,
              DimSlice (n - 1) n (-1),
              DimSlice (n - 1) n (-1),
              DimSlice 1 (m - 2) (-1)
            ]
        ixfun' = slice ixfun slice1
     in ixfun'

test_complex2 :: [TestTree]
test_complex2 =
  singleton . testCase "permute . slice . permute . slice . iota 2" . compareOps $
    let slc2 =
          Slice
            [ DimFix (n `P.div` 2),
              DimSlice (n - 1) (n `P.div` 3) (-1),
              DimSlice (n - 1) n (-1),
              DimSlice (n - 1) n (-1),
              DimSlice 0 n 1
            ]
        ixfun = permute (slice (iota [n, n, n, n, n]) slc2) [3, 1, 2, 0]
        m = n `P.div` 3
        slice1 =
          Slice
            [ DimSlice 0 n 1,
              DimSlice (n - 1) n (-1),
              DimSlice (n - 1) n (-1),
              DimSlice 1 (m - 2) (-1)
            ]
        ixfun' = slice ixfun slice1
     in ixfun'

-- Imitates a case from memory expansion.
test_expand1 :: [TestTree]
test_expand1 =
  [ testCase "expand . iota1d" . compareOps $
      expand t nt (iota [n])
  ]
  where
    t = 3
    nt = 7

-- Imitates another case from memory expansion.
test_expand2 :: [TestTree]
test_expand2 =
  [ testCase "expand . iota2d" . compareOps $
      expand t nt (iota [n, n])
  ]
  where
    t = 3
    nt = 7

test_expand3 :: [TestTree]
test_expand3 =
  [ testCase "expand . permute . iota2d" . compareOps $
      expand t nt (permute (iota [n, n `div` 2]) [1, 0])
  ]
  where
    t = 3
    nt = 7

test_expand4 :: [TestTree]
test_expand4 =
  [ testCase "expand . slice . iota1d" . compareOps $
      expand t nt (slice (iota [n]) (Slice [DimSlice (n `div` 2) (n `div` 2) 1]))
  ]
  where
    t = 3
    nt = 7

test_flatSlice_iota :: [TestTree]
test_flatSlice_iota =
  singleton . testCase "flatSlice . iota" . compareOps $
    flatSlice (iota [n * n * n * n]) $
      FlatSlice 2 [FlatDimIndex (n * 2) 4, FlatDimIndex n 3, FlatDimIndex 1 2]

test_slice_flatSlice_iota :: [TestTree]
test_slice_flatSlice_iota =
  singleton . testCase "slice . flatSlice . iota " . compareOps $
    slice (flatSlice (iota [2 + n * n * n]) flat_slice) $
      Slice [DimFix 2, DimSlice 0 n 1, DimFix 0]
  where
    flat_slice = FlatSlice 2 [FlatDimIndex (n * n) 1, FlatDimIndex n 1, FlatDimIndex 1 1]

test_flatSlice_flatSlice_iota :: [TestTree]
test_flatSlice_flatSlice_iota =
  singleton . testCase "flatSlice . flatSlice . iota " . compareOps $
    flatSlice (flatSlice (iota [10 * 10]) flat_slice_1) flat_slice_2
  where
    flat_slice_1 = FlatSlice 17 [FlatDimIndex 3 27, FlatDimIndex 3 10, FlatDimIndex 3 1]
    flat_slice_2 = FlatSlice 2 [FlatDimIndex 2 (-2)]

test_flatSlice_slice_iota :: [TestTree]
test_flatSlice_slice_iota =
  singleton . testCase "flatSlice . slice . iota " . compareOps $
    flatSlice (slice (iota [210, 100]) $ Slice [DimSlice 10 100 2, DimFix 10]) flat_slice_1
  where
    flat_slice_1 = FlatSlice 17 [FlatDimIndex 3 27, FlatDimIndex 3 10, FlatDimIndex 3 1]

test_flatSlice_transpose_slice_iota :: [TestTree]
test_flatSlice_transpose_slice_iota =
  singleton . testCase "flatSlice . transpose . slice . iota " . compareOps $
    flatSlice (permute (slice (iota [20, 20]) $ Slice [DimSlice 1 5 2, DimSlice 0 5 2]) [1, 0]) flat_slice_1
  where
    flat_slice_1 = FlatSlice 1 [FlatDimIndex 2 2]

-- test_disjoint2 :: [TestTree]
-- test_disjoint2 =
--   let add_nw64 = (+)

--       mul_nw64 = (*)

--       sub64 = (-)

--       vname s i = VName (nameFromString s) i
--    in [ let gtid_8472 = TPrimExp $ LeafExp (vname "gtid" 8472) $ IntType Int64

--             gtid_8473 = TPrimExp $ LeafExp (vname "gtid" 8473) $ IntType Int64

--             gtid_8474 = TPrimExp $ LeafExp (vname "gtid" 8474) $ IntType Int64

--             num_blocks_8284 = TPrimExp $ LeafExp (vname "num_blocks" 8284) $ IntType Int64

--             nonnegs = freeIn [gtid_8472, gtid_8473, gtid_8474, num_blocks_8284]

--             j_m_i_8287 :: TPrimExp Int64 VName
--             j_m_i_8287 = num_blocks_8284 - 1

--             lessthans :: [(VName, PrimExp VName)]
--             lessthans =
--               [ (head $ namesToList $ freeIn gtid_8472, untyped j_m_i_8287),
--                 (head $ namesToList $ freeIn gtid_8473, untyped j_m_i_8287),
--                 (head $ namesToList $ freeIn gtid_8474, untyped (16 :: TPrimExp Int64 VName))
--               ]

--             lm1 :: IxFunLMAD.LMAD (TPrimExp Int64 VName)
--             lm1 =
--               IxFunLMAD.LMAD
--                 256
--                 [ IxFunLMAD.LMADDim 256 0 (sub64 (num_blocks_8284) 1) 0 ,
--                   IxFunLMAD.LMADDim 1 0 16 1 ,
--                   IxFunLMAD.LMADDim 16 0 16 2
--                 ]
--             lm2 :: IxFunLMAD.LMAD (TPrimExp Int64 VName)
--             lm2 =
--               IxFunLMAD.LMAD
--                 (add_nw64 (add_nw64 (add_nw64 (add_nw64 (mul_nw64 (256) (num_blocks_8284)) (256)) (mul_nw64 (gtid_8472) (mul_nw64 (256) (num_blocks_8284)))) (mul_nw64 (gtid_8473) (256))) (mul_nw64 (gtid_8474) (16)))
--                 [IxFunLMAD.LMADDim 1 0 16 0 ]
--          in testCase (pretty lm1 <> " and " <> pretty lm2) $ IxFunLMAD.disjoint2 lessthans nonnegs lm1 lm2 @? "Failed"
--       ]

-- test_lessThanish :: [TestTree]
-- test_lessThanish =
--   [testCase "0 < 1" $ IxFunLMAD.lessThanish mempty mempty 0 1 @? "Failed"]

-- test_lessThanOrEqualish :: [TestTree]
-- test_lessThanOrEqualish =
--   [testCase "1 <= 1" $ IxFunLMAD.lessThanOrEqualish mempty mempty 1 1 @? "Failed"]

_test_disjoint3 :: [TestTree]
_test_disjoint3 =
  let foo s = VName (nameFromString s)
      add_nw64 = (+)
      add64 = (+)
      mul_nw64 = (*)
      mul64 = (*)
      sub64 = (-)
      sdiv64 = IE.div
      sub_nw64 = (-)
      disjointTester asserts lessthans lm1 lm2 =
        let nonnegs = map (`LeafExp` IntType Int64) $ namesToList $ freeIn lm1 <> freeIn lm2

            scmap =
              M.fromList $
                map (\x -> (x, Prim $ IntType Int64)) $
                  namesToList $
                    freeIn lm1 <> freeIn lm2 <> freeIn lessthans <> freeIn asserts
         in IxFunLMAD.disjoint3 scmap asserts lessthans nonnegs lm1 lm2
   in [ testCase "lm1 and lm2" $
          let lessthans =
                [ ( i_12214,
                    sdiv64 (sub64 n_blab 1) block_size_12121
                  ),
                  (gtid_12553, add64 1 i_12214)
                ]
                  & map (\(v, p) -> (head $ namesToList $ freeIn v, untyped p))

              asserts =
                [ untyped ((2 * block_size_12121 :: TPrimExp Int64 VName) .<. n_blab :: TPrimExp Bool VName),
                  untyped ((3 :: TPrimExp Int64 VName) .<. n_blab :: TPrimExp Bool VName)
                ]

              block_size_12121 = TPrimExp $ LeafExp (foo "block_size" 12121) $ IntType Int64
              i_12214 = TPrimExp $ LeafExp (foo "i" 12214) $ IntType Int64
              n_blab = TPrimExp $ LeafExp (foo "n" 1337) $ IntType Int64
              gtid_12553 = TPrimExp $ LeafExp (foo "gtid" 12553) $ IntType Int64

              lm1 =
                IxFunLMAD.LMAD
                  (add_nw64 (mul64 block_size_12121 i_12214) (mul_nw64 (add_nw64 gtid_12553 1) (sub64 (mul64 block_size_12121 n_blab) block_size_12121)))
                  [ IxFunLMAD.LMADDim (add_nw64 (mul_nw64 block_size_12121 n_blab) (mul_nw64 (-1) block_size_12121)) (sub_nw64 (sub_nw64 (add64 1 i_12214) gtid_12553) 1),
                    IxFunLMAD.LMADDim 1 (block_size_12121 + 1)
                  ]

              lm2 =
                IxFunLMAD.LMAD
                  (block_size_12121 * i_12214)
                  [ IxFunLMAD.LMADDim (add_nw64 (mul_nw64 block_size_12121 n_blab) (mul_nw64 (-1) block_size_12121)) gtid_12553,
                    IxFunLMAD.LMADDim 1 (1 + block_size_12121)
                  ]

              lm_w =
                IxFunLMAD.LMAD
                  (add_nw64 (add64 (add64 1 n_blab) (mul64 block_size_12121 i_12214)) (mul_nw64 gtid_12553 (sub64 (mul64 block_size_12121 n_blab) block_size_12121)))
                  [ IxFunLMAD.LMADDim n_blab block_size_12121,
                    IxFunLMAD.LMADDim 1 block_size_12121
                  ]

              lm_blocks =
                IxFunLMAD.LMAD
                  (block_size_12121 * i_12214 + n_blab + 1)
                  [ IxFunLMAD.LMADDim (add_nw64 (mul_nw64 block_size_12121 n_blab) (mul_nw64 (-1) block_size_12121)) (i_12214 + 1),
                    IxFunLMAD.LMADDim n_blab block_size_12121,
                    IxFunLMAD.LMADDim 1 block_size_12121
                  ]

              lm_lower_per =
                IxFunLMAD.LMAD
                  (block_size_12121 * i_12214)
                  [ IxFunLMAD.LMADDim (add_nw64 (mul_nw64 block_size_12121 n_blab) (mul_nw64 (-1) block_size_12121)) (i_12214 + 1),
                    IxFunLMAD.LMADDim 1 (block_size_12121 + 1)
                  ]

              res1 = disjointTester asserts lessthans lm1 lm_w
              res2 = disjointTester asserts lessthans lm2 lm_w
              res3 = disjointTester asserts lessthans lm_lower_per lm_blocks
           in res1 && res2 && res3 @? "Failed",
        testCase "nw second half" $ do
          let lessthans =
                [ ( i_12214,
                    sdiv64 (sub64 n_blab 1) block_size_12121
                  ),
                  (gtid_12553, add64 1 i_12214)
                ]
                  & map (\(v, p) -> (head $ namesToList $ freeIn v, untyped p))

              asserts =
                [ untyped ((2 * block_size_12121 :: TPrimExp Int64 VName) .<. n_blab :: TPrimExp Bool VName),
                  untyped ((3 :: TPrimExp Int64 VName) .<. n_blab :: TPrimExp Bool VName)
                ]

              block_size_12121 = TPrimExp $ LeafExp (foo "block_size" 12121) $ IntType Int64
              i_12214 = TPrimExp $ LeafExp (foo "i" 12214) $ IntType Int64
              n_blab = TPrimExp $ LeafExp (foo "n" 1337) $ IntType Int64
              gtid_12553 = TPrimExp $ LeafExp (foo "gtid" 12553) $ IntType Int64

              lm1 =
                IxFunLMAD.LMAD
                  (add_nw64 (add64 n_blab (sub64 (sub64 (mul64 n_blab (add64 1 (mul64 block_size_12121 (add64 1 i_12214)))) block_size_12121) 1)) (mul_nw64 (add_nw64 gtid_12553 1) (sub64 (mul64 block_size_12121 n_blab) block_size_12121)))
                  [ IxFunLMAD.LMADDim (add_nw64 (mul_nw64 block_size_12121 n_blab) (mul_nw64 (-1) block_size_12121)) (sub_nw64 (sub_nw64 (sub64 (sub64 (sdiv64 (sub64 n_blab 1) block_size_12121) i_12214) 1) gtid_12553) 1),
                    IxFunLMAD.LMADDim n_blab block_size_12121
                  ]

              lm2 =
                IxFunLMAD.LMAD
                  (add_nw64 (sub64 (sub64 (mul64 n_blab (add64 1 (mul64 block_size_12121 (add64 1 i_12214)))) block_size_12121) 1) (mul_nw64 (add_nw64 gtid_12553 1) (sub64 (mul64 block_size_12121 n_blab) block_size_12121)))
                  [ IxFunLMAD.LMADDim (add_nw64 (mul_nw64 block_size_12121 n_blab) (mul_nw64 (-1) block_size_12121)) (sub_nw64 (sub_nw64 (sub64 (sub64 (sdiv64 (sub64 n_blab 1) block_size_12121) i_12214) 1) gtid_12553) 1),
                    IxFunLMAD.LMADDim 1 (1 + block_size_12121)
                  ]

              lm3 =
                IxFunLMAD.LMAD
                  (add64 n_blab (sub64 (sub64 (mul64 n_blab (add64 1 (mul64 block_size_12121 (add64 1 i_12214)))) block_size_12121) 1))
                  [ IxFunLMAD.LMADDim (add_nw64 (mul_nw64 block_size_12121 n_blab) (mul_nw64 (-1) block_size_12121)) gtid_12553,
                    IxFunLMAD.LMADDim n_blab block_size_12121
                  ]

              lm4 =
                IxFunLMAD.LMAD
                  (sub64 (sub64 (mul64 n_blab (add64 1 (mul64 block_size_12121 (add64 1 i_12214)))) block_size_12121) 1)
                  [ IxFunLMAD.LMADDim
                      (add_nw64 (mul_nw64 block_size_12121 n_blab) (mul_nw64 (-1) block_size_12121))
                      gtid_12553,
                    IxFunLMAD.LMADDim
                      1
                      (1 + block_size_12121)
                  ]

              lm_w =
                IxFunLMAD.LMAD
                  (add_nw64 (sub64 (mul64 n_blab (add64 2 (mul64 block_size_12121 (add64 1 i_12214)))) block_size_12121) (mul_nw64 gtid_12553 (sub64 (mul64 block_size_12121 n_blab) block_size_12121)))
                  [ IxFunLMAD.LMADDim n_blab block_size_12121,
                    IxFunLMAD.LMADDim 1 block_size_12121
                  ]

              res1 = disjointTester asserts lessthans lm1 lm_w
              res2 = disjointTester asserts lessthans lm2 lm_w
              res3 = disjointTester asserts lessthans lm3 lm_w
              res4 = disjointTester asserts lessthans lm4 lm_w
           in res1 && res2 && res3 && res4 @? "Failed " <> show [res1, res2, res3, res4],
        testCase "lud long" $
          let lessthans =
                [ bimap
                    (head . namesToList . freeIn)
                    untyped
                    (step, num_blocks - 1 :: TPrimExp Int64 VName)
                ]

              step = TPrimExp $ LeafExp (foo "step" 1337) $ IntType Int64

              num_blocks = TPrimExp $ LeafExp (foo "n" 1338) $ IntType Int64

              lm1 =
                IxFunLMAD.LMAD
                  (1024 * num_blocks * (1 + step) + 1024 * step)
                  [ IxFunLMAD.LMADDim (1024 * num_blocks) (num_blocks - step - 1),
                    IxFunLMAD.LMADDim 32 32,
                    IxFunLMAD.LMADDim 1 32
                  ]

              lm_w1 =
                IxFunLMAD.LMAD
                  (1024 * num_blocks * step + 1024 * step)
                  [ IxFunLMAD.LMADDim 32 32,
                    IxFunLMAD.LMADDim 1 32
                  ]

              lm_w2 =
                IxFunLMAD.LMAD
                  ((1 + step) * 1024 * num_blocks + (1 + step) * 1024)
                  [ IxFunLMAD.LMADDim (1024 * num_blocks) (num_blocks - step - 1),
                    IxFunLMAD.LMADDim 1024 (num_blocks - step - 1),
                    IxFunLMAD.LMADDim 1024 1,
                    IxFunLMAD.LMADDim 32 1,
                    IxFunLMAD.LMADDim 128 8,
                    IxFunLMAD.LMADDim 4 8,
                    IxFunLMAD.LMADDim 32 4,
                    IxFunLMAD.LMADDim 1 4
                  ]

              asserts =
                [ untyped ((1 :: TPrimExp Int64 VName) .<. num_blocks :: TPrimExp Bool VName)
                ]

              res1 = disjointTester asserts lessthans lm1 lm_w1
              res2 = disjointTester asserts lessthans lm1 lm_w2
           in res1 && res2 @? "Failed"
      ]