1 // RUN: mlir-opt %s -convert-scf-to-std -convert-vector-to-llvm -convert-memref-to-llvm -convert-std-to-llvm -reconcile-unrealized-casts | \
2 // RUN: mlir-cpu-runner -e entry -entry-point-result=void \
3 // RUN: -shared-libs=%mlir_integration_test_dir/libmlir_c_runner_utils%shlibext | \
6 func @scatter8(%base: memref<?xf32>,
7 %indices: vector<8xi32>,
8 %mask: vector<8xi1>, %value: vector<8xf32>) {
9 %c0 = arith.constant 0: index
10 vector.scatter %base[%c0][%indices], %mask, %value
11 : memref<?xf32>, vector<8xi32>, vector<8xi1>, vector<8xf32>
15 func @printmem8(%A: memref<?xf32>) {
16 %c0 = arith.constant 0: index
17 %c1 = arith.constant 1: index
18 %c8 = arith.constant 8: index
19 %z = arith.constant 0.0: f32
20 %m = vector.broadcast %z : f32 to vector<8xf32>
21 %mem = scf.for %i = %c0 to %c8 step %c1
22 iter_args(%m_iter = %m) -> (vector<8xf32>) {
23 %c = memref.load %A[%i] : memref<?xf32>
24 %i32 = arith.index_cast %i : index to i32
25 %m_new = vector.insertelement %c, %m_iter[%i32 : i32] : vector<8xf32>
26 scf.yield %m_new : vector<8xf32>
28 vector.print %mem : vector<8xf32>
34 %c0 = arith.constant 0: index
35 %c1 = arith.constant 1: index
36 %c8 = arith.constant 8: index
37 %A = memref.alloc(%c8) : memref<?xf32>
38 scf.for %i = %c0 to %c8 step %c1 {
39 %i32 = arith.index_cast %i : index to i32
40 %fi = arith.sitofp %i32 : i32 to f32
41 memref.store %fi, %A[%i] : memref<?xf32>
45 %i0 = arith.constant 0: i32
46 %i1 = arith.constant 1: i32
47 %i2 = arith.constant 2: i32
48 %i3 = arith.constant 3: i32
49 %i4 = arith.constant 4: i32
50 %i5 = arith.constant 5: i32
51 %i6 = arith.constant 6: i32
52 %i7 = arith.constant 7: i32
53 %0 = vector.broadcast %i7 : i32 to vector<8xi32>
54 %1 = vector.insert %i0, %0[1] : i32 into vector<8xi32>
55 %2 = vector.insert %i1, %1[2] : i32 into vector<8xi32>
56 %3 = vector.insert %i6, %2[3] : i32 into vector<8xi32>
57 %4 = vector.insert %i2, %3[4] : i32 into vector<8xi32>
58 %5 = vector.insert %i4, %4[5] : i32 into vector<8xi32>
59 %6 = vector.insert %i5, %5[6] : i32 into vector<8xi32>
60 %idx = vector.insert %i3, %6[7] : i32 into vector<8xi32>
62 // Set up value vector.
63 %f0 = arith.constant 0.0: f32
64 %f1 = arith.constant 1.0: f32
65 %f2 = arith.constant 2.0: f32
66 %f3 = arith.constant 3.0: f32
67 %f4 = arith.constant 4.0: f32
68 %f5 = arith.constant 5.0: f32
69 %f6 = arith.constant 6.0: f32
70 %f7 = arith.constant 7.0: f32
71 %7 = vector.broadcast %f0 : f32 to vector<8xf32>
72 %8 = vector.insert %f1, %7[1] : f32 into vector<8xf32>
73 %9 = vector.insert %f2, %8[2] : f32 into vector<8xf32>
74 %10 = vector.insert %f3, %9[3] : f32 into vector<8xf32>
75 %11 = vector.insert %f4, %10[4] : f32 into vector<8xf32>
76 %12 = vector.insert %f5, %11[5] : f32 into vector<8xf32>
77 %13 = vector.insert %f6, %12[6] : f32 into vector<8xf32>
78 %val = vector.insert %f7, %13[7] : f32 into vector<8xf32>
81 %t = arith.constant 1: i1
82 %none = vector.constant_mask [0] : vector<8xi1>
83 %some = vector.constant_mask [4] : vector<8xi1>
84 %more = vector.insert %t, %some[7] : i1 into vector<8xi1>
85 %all = vector.constant_mask [8] : vector<8xi1>
91 vector.print %idx : vector<8xi32>
92 // CHECK: ( 7, 0, 1, 6, 2, 4, 5, 3 )
94 call @printmem8(%A) : (memref<?xf32>) -> ()
95 // CHECK: ( 0, 1, 2, 3, 4, 5, 6, 7 )
97 call @scatter8(%A, %idx, %none, %val)
98 : (memref<?xf32>, vector<8xi32>, vector<8xi1>, vector<8xf32>) -> ()
99 call @printmem8(%A) : (memref<?xf32>) -> ()
100 // CHECK: ( 0, 1, 2, 3, 4, 5, 6, 7 )
102 call @scatter8(%A, %idx, %some, %val)
103 : (memref<?xf32>, vector<8xi32>, vector<8xi1>, vector<8xf32>) -> ()
104 call @printmem8(%A) : (memref<?xf32>) -> ()
105 // CHECK: ( 1, 2, 2, 3, 4, 5, 3, 0 )
107 call @scatter8(%A, %idx, %more, %val)
108 : (memref<?xf32>, vector<8xi32>, vector<8xi1>, vector<8xf32>) -> ()
109 call @printmem8(%A) : (memref<?xf32>) -> ()
110 // CHECK: ( 1, 2, 2, 7, 4, 5, 3, 0 )
112 call @scatter8(%A, %idx, %all, %val)
113 : (memref<?xf32>, vector<8xi32>, vector<8xi1>, vector<8xf32>) -> ()
114 call @printmem8(%A) : (memref<?xf32>) -> ()
115 // CHECK: ( 1, 2, 4, 7, 5, 6, 3, 0 )
117 memref.dealloc %A : memref<?xf32>