1 // RUN: mlir-opt %s -convert-scf-to-std -convert-arith-to-llvm -convert-memref-to-llvm -convert-std-to-llvm -reconcile-unrealized-casts \
2 // RUN: | mlir-cpu-runner -e main -entry-point-result=void \
3 // RUN: -shared-libs=%mlir_runner_utils_dir/libmlir_runner_utils%shlibext,%mlir_runner_utils_dir/libmlir_c_runner_utils%shlibext \
6 func private @print_memref_f32(memref<*xf32>) attributes { llvm.emit_c_interface }
9 %c0 = arith.constant 0 : index
10 %c1 = arith.constant 1 : index
13 %input = memref.alloc() : memref<2x3xf32>
14 %dim_x = memref.dim %input, %c0 : memref<2x3xf32>
15 %dim_y = memref.dim %input, %c1 : memref<2x3xf32>
16 scf.parallel (%i, %j) = (%c0, %c0) to (%dim_x, %dim_y) step (%c1, %c1) {
17 %prod = arith.muli %i, %dim_y : index
18 %val = arith.addi %prod, %j : index
19 %val_i64 = arith.index_cast %val : index to i64
20 %val_f32 = arith.sitofp %val_i64 : i64 to f32
21 memref.store %val_f32, %input[%i, %j] : memref<2x3xf32>
23 %unranked_input = memref.cast %input : memref<2x3xf32> to memref<*xf32>
24 call @print_memref_f32(%unranked_input) : (memref<*xf32>) -> ()
25 // CHECK: rank = 2 offset = 0 sizes = [2, 3] strides = [3, 1]
26 // CHECK-NEXT: [0, 1, 2]
27 // CHECK-NEXT: [3, 4, 5]
29 %copy = memref.alloc() : memref<2x3xf32>
30 memref.copy %input, %copy : memref<2x3xf32> to memref<2x3xf32>
31 %unranked_copy = memref.cast %copy : memref<2x3xf32> to memref<*xf32>
32 call @print_memref_f32(%unranked_copy) : (memref<*xf32>) -> ()
33 // CHECK: rank = 2 offset = 0 sizes = [2, 3] strides = [3, 1]
34 // CHECK-NEXT: [0, 1, 2]
35 // CHECK-NEXT: [3, 4, 5]
37 %copy_two = memref.alloc() : memref<3x2xf32>
38 %copy_two_casted = memref.reinterpret_cast %copy_two to offset: [0], sizes: [2,3], strides:[1, 2]
39 : memref<3x2xf32> to memref<2x3xf32>
40 memref.copy %input, %copy_two_casted : memref<2x3xf32> to memref<2x3xf32>
41 %unranked_copy_two = memref.cast %copy_two : memref<3x2xf32> to memref<*xf32>
42 call @print_memref_f32(%unranked_copy_two) : (memref<*xf32>) -> ()
43 // CHECK: rank = 2 offset = 0 sizes = [3, 2] strides = [2, 1]
48 %input_empty = memref.alloc() : memref<3x0x1xf32>
49 %copy_empty = memref.alloc() : memref<3x0x1xf32>
50 // Copying an empty shape should do nothing (and should not crash).
51 memref.copy %input_empty, %copy_empty : memref<3x0x1xf32> to memref<3x0x1xf32>
52 memref.dealloc %copy_empty : memref<3x0x1xf32>
53 memref.dealloc %input_empty : memref<3x0x1xf32>
54 memref.dealloc %copy_two : memref<3x2xf32>
55 memref.dealloc %copy : memref<2x3xf32>
56 memref.dealloc %input : memref<2x3xf32>