// RUN: mlir-opt -split-input-file -verify-diagnostics %s func.func @test_conv_op_not_linalg_op(%arg0 : tensor, %arg1 : tensor, %arg2 : tensor) -> tensor { // expected-error @+1 {{expected a LinalgOp}} %0 = "test.conv_op_not_linalg_op"(%arg0, %arg1, %arg2) : (tensor, tensor, tensor) -> tensor return %0 : tensor } // ----- // Check for number of operands being >= 2. #map = affine_map<(d0) -> (d0)> func.func @test_conv_op_wrong_num_operands(%arg0 : tensor, %arg1 : tensor) -> tensor { // expected-error @+1 {{expected op with 2 inputs and 1 output}} %0 = test.linalg_conv_op { indexing_maps = [#map, #map], iterator_types = [#test.iterator_type]} ins(%arg0 : tensor) outs(%arg1 : tensor) { ^bb0(%arg2 : f32, %arg3 : f32): linalg.yield %arg3 : f32 } -> tensor return %0 : tensor } // ----- func.func @test_conv_op_wrong_input_indexing_map1(%arg0 : tensor, %arg1 : tensor, %arg2 : tensor) -> tensor { // expected-error @+1 {{unexpected input index map for convolution}} %0 = test.linalg_conv_op { indexing_maps = [affine_map<(d0, d1) -> (d0 * 2)>, affine_map<(d0, d1) -> (d1)>, affine_map<(d0, d1) -> (d0)>], iterator_types = [#test.iterator_type, #test.iterator_type]} ins(%arg0, %arg1 : tensor, tensor) outs(%arg2 : tensor) { ^bb0(%arg3 : f32, %arg4 : f32, %arg5 : f32): linalg.yield %arg5 : f32 } -> tensor return %0 : tensor } // ----- func.func @test_conv_op_wrong_input_indexing_map2(%arg0 : tensor, %arg1 : tensor, %arg2 : tensor) -> tensor { // expected-error @+1 {{unexpected input index map for convolution}} %0 = test.linalg_conv_op { indexing_maps = [affine_map<(d0, d1) -> (d0 + d1, d0)>, affine_map<(d0, d1) -> (d1)>, affine_map<(d0, d1) -> (d0)>], iterator_types = [#test.iterator_type, #test.iterator_type]} ins(%arg0, %arg1 : tensor, tensor) outs(%arg2 : tensor) { ^bb0(%arg3 : f32, %arg4 : f32, %arg5 : f32): linalg.yield %arg5 : f32 } -> tensor return %0 : tensor } // ----- func.func @test_conv_op_filter_index_map_not_projection(%arg0 : tensor, %arg1 : tensor, %arg2 : tensor) -> tensor { // expected-error @+1 {{expected output/filter indexing maps to be projected permutations}} %0 = test.linalg_conv_op { indexing_maps = [affine_map<(d0, d1) -> (d1)>, affine_map<(d0, d1) -> (d1 + d0)>, affine_map<(d0, d1) -> (d0)>], iterator_types = [#test.iterator_type, #test.iterator_type]} ins(%arg0, %arg1 : tensor, tensor) outs(%arg2 : tensor) { ^bb0(%arg3 : f32, %arg4 : f32, %arg5 : f32): linalg.yield %arg5 : f32 } -> tensor return %0 : tensor } // ----- func.func @test_conv_op_output_index_map_not_projection(%arg0 : tensor, %arg1 : tensor, %arg2 : tensor) -> tensor { // expected-error @+1 {{expected output/filter indexing maps to be projected permutations}} %0 = test.linalg_conv_op { indexing_maps = [affine_map<(d0, d1) -> (d0)>, affine_map<(d0, d1) -> (d1)>, affine_map<(d0, d1) -> (d0 + d1)>], iterator_types = [#test.iterator_type, #test.iterator_type]} ins(%arg0, %arg1 : tensor, tensor) outs(%arg2 : tensor) { ^bb0(%arg3 : f32, %arg4 : f32, %arg5 : f32): linalg.yield %arg5 : f32 } -> tensor return %0 : tensor } // ----- // Convolution op illegal if a loop dimension is used to access // output, filter and is convolved. func.func @test_conv_op_output_filter_convolved(%arg0 : tensor, %arg1 : tensor, %arg2 : tensor) -> tensor { // expected-error @+1 {{unexpected loop dimension for convolution op}} %0 = test.linalg_conv_op { indexing_maps = [affine_map<(d0, d1) -> (d0 + d1)>, affine_map<(d0, d1) -> (d1)>, affine_map<(d0, d1) -> (d0, d1)>], iterator_types = [#test.iterator_type, #test.iterator_type]} ins(%arg0, %arg1 : tensor, tensor) outs(%arg2 : tensor) { ^bb0(%arg3 : f32, %arg4 : f32, %arg5 : f32): linalg.yield %arg5 : f32 } -> tensor return %0 : tensor } // ----- // Convolution op illegal if a loop dimension is used only in the output. func.func @test_conv_op_output_only_dim(%arg0 : tensor, %arg1 : tensor, %arg2 : tensor) -> tensor { // expected-error @+1 {{unexpected loop dimension for convolution op}} %0 = test.linalg_conv_op { indexing_maps = [affine_map<(d0, d1, d2) -> (d0 + d1)>, affine_map<(d0, d1, d2) -> (d1)>, affine_map<(d0, d1, d2) -> (d0, d2)>], iterator_types = [#test.iterator_type, #test.iterator_type, #test.iterator_type]} ins(%arg0, %arg1 : tensor, tensor) outs(%arg2 : tensor) { ^bb0(%arg3 : f32, %arg4 : f32, %arg5 : f32): linalg.yield %arg5 : f32 } -> tensor return %0 : tensor } // ----- // Convolution op illegal if a loop dimension is used only in the filter. func.func @test_conv_op_filter_only_dim(%arg0 : tensor, %arg1 : tensor, %arg2 : tensor) -> tensor { // expected-error @+1 {{unexpected loop dimension for convolution op}} %0 = test.linalg_conv_op { indexing_maps = [affine_map<(d0, d1, d2) -> (d0 + d1)>, affine_map<(d0, d1, d2) -> (d1, d2)>, affine_map<(d0, d1, d2) -> (d0)>], iterator_types = [#test.iterator_type, #test.iterator_type, #test.iterator_type]} ins(%arg0, %arg1 : tensor, tensor) outs(%arg2 : tensor) { ^bb0(%arg3 : f32, %arg4 : f32, %arg5 : f32): linalg.yield %arg5 : f32 } -> tensor return %0 : tensor } // ----- // Convolution op illegal if a loop dimension is used only in the input. func.func @test_conv_op_input_only_dim(%arg0 : tensor, %arg1 : tensor, %arg2 : tensor) -> tensor { // expected-error @+1 {{unexpected loop dimension for convolution op}} %0 = test.linalg_conv_op { indexing_maps = [affine_map<(d0, d1, d2) -> (d0 + d1, d2)>, affine_map<(d0, d1, d2) -> (d1)>, affine_map<(d0, d1, d2) -> (d0)>], iterator_types = [#test.iterator_type, #test.iterator_type, #test.iterator_type]} ins(%arg0, %arg1 : tensor, tensor) outs(%arg2 : tensor) { ^bb0(%arg3 : f32, %arg4 : f32, %arg5 : f32): linalg.yield %arg5 : f32 } -> tensor return %0 : tensor } // ----- // Convolution op illegal if a loop dimension accessing output is not parallel. func.func @test_conv_op_non_output_access_loop_parallel(%arg0 : tensor, %arg1 : tensor, %arg2 : tensor) -> tensor { // expected-error @+1 {{expected all iterators not used to access outputs to be reduction}} %0 = test.linalg_conv_op { indexing_maps = [affine_map<(d0, d1) -> (d0 + d1)>, affine_map<(d0, d1) -> (d1)>, affine_map<(d0, d1) -> (d0)>], iterator_types = [#test.iterator_type, #test.iterator_type]} ins(%arg0, %arg1 : tensor, tensor) outs(%arg2 : tensor) { ^bb0(%arg3 : f32, %arg4 : f32, %arg5 : f32): linalg.yield %arg5 : f32 } -> tensor return %0 : tensor }