// RUN: mlir-opt %s \ // RUN: -func-bufferize -tensor-bufferize -arith-bufferize --canonicalize \ // RUN: -convert-scf-to-cf --convert-complex-to-standard \ // RUN: -convert-memref-to-llvm -convert-math-to-llvm -convert-math-to-libm \ // RUN: -convert-vector-to-llvm -convert-complex-to-llvm \ // RUN: -convert-func-to-llvm -reconcile-unrealized-casts |\ // RUN: mlir-cpu-runner \ // RUN: -e entry -entry-point-result=void \ // RUN: -shared-libs=%mlir_integration_test_dir/libmlir_c_runner_utils%shlibext |\ // RUN: FileCheck %s func.func @test_unary(%input: tensor>, %func: (complex) -> complex) { %c0 = arith.constant 0 : index %c1 = arith.constant 1 : index %size = tensor.dim %input, %c0: tensor> scf.for %i = %c0 to %size step %c1 { %elem = tensor.extract %input[%i]: tensor> %val = func.call_indirect %func(%elem) : (complex) -> complex %real = complex.re %val : complex %imag = complex.im %val: complex vector.print %real : f32 vector.print %imag : f32 scf.yield } func.return } func.func @sqrt(%arg: complex) -> complex { %sqrt = complex.sqrt %arg : complex func.return %sqrt : complex } // %input contains pairs of lhs, rhs, i.e. [lhs_0, rhs_0, lhs_1, rhs_1,...] func.func @test_binary(%input: tensor>, %func: (complex, complex) -> complex) { %c0 = arith.constant 0 : index %c1 = arith.constant 1 : index %c2 = arith.constant 2 : index %size = tensor.dim %input, %c0: tensor> scf.for %i = %c0 to %size step %c2 { %lhs = tensor.extract %input[%i]: tensor> %i_next = arith.addi %i, %c1 : index %rhs = tensor.extract %input[%i_next]: tensor> %val = func.call_indirect %func(%lhs, %rhs) : (complex, complex) -> complex %real = complex.re %val : complex %imag = complex.im %val: complex vector.print %real : f32 vector.print %imag : f32 scf.yield } func.return } func.func @atan2(%lhs: complex, %rhs: complex) -> complex { %atan2 = complex.atan2 %lhs, %rhs : complex func.return %atan2 : complex } func.func @entry() { // complex.sqrt test %sqrt_test = arith.constant dense<[ (-1.0, -1.0), // CHECK: 0.455 // CHECK-NEXT: -1.098 (-1.0, 1.0), // CHECK-NEXT: 0.455 // CHECK-NEXT: 1.098 (0.0, 0.0), // CHECK-NEXT: 0 // CHECK-NEXT: 0 (0.0, 1.0), // CHECK-NEXT: 0.707 // CHECK-NEXT: 0.707 (1.0, -1.0), // CHECK-NEXT: 1.098 // CHECK-NEXT: -0.455 (1.0, 0.0), // CHECK-NEXT: 1 // CHECK-NEXT: 0 (1.0, 1.0) // CHECK-NEXT: 1.098 // CHECK-NEXT: 0.455 ]> : tensor<7xcomplex> %sqrt_test_cast = tensor.cast %sqrt_test : tensor<7xcomplex> to tensor> %sqrt_func = func.constant @sqrt : (complex) -> complex call @test_unary(%sqrt_test_cast, %sqrt_func) : (tensor>, (complex) -> complex) -> () // complex.atan2 test %atan2_test = arith.constant dense<[ (1.0, 2.0), (2.0, 1.0), // CHECK: 0.785 // CHECK-NEXT: 0.346 (1.0, 1.0), (1.0, 0.0), // CHECK-NEXT: 1.017 // CHECK-NEXT: 0.402 (1.0, 1.0), (1.0, 1.0) // CHECK-NEXT: 0.785 // CHECK-NEXT: 0 ]> : tensor<6xcomplex> %atan2_test_cast = tensor.cast %atan2_test : tensor<6xcomplex> to tensor> %atan2_func = func.constant @atan2 : (complex, complex) -> complex call @test_binary(%atan2_test_cast, %atan2_func) : (tensor>, (complex, complex) -> complex) -> () func.return }