// 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 } func.func @tanh(%arg: complex) -> complex { %tanh = complex.tanh %arg : complex func.return %tanh : complex } func.func @rsqrt(%arg: complex) -> complex { %sqrt = complex.rsqrt %arg : complex func.return %sqrt : complex } func.func @conj(%arg: complex) -> complex { %conj = complex.conj %arg : complex func.return %conj : 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 @pow(%lhs: complex, %rhs: complex) -> complex { %pow = complex.pow %lhs, %rhs : complex func.return %pow : complex } func.func @test_element(%input: tensor>, %func: (complex) -> f32) { %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) -> f32 vector.print %val : f32 scf.yield } func.return } func.func @angle(%arg: complex) -> f32 { %angle = complex.angle %arg : complex func.return %angle : f32 } 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) -> () // complex.pow test %pow_test = arith.constant dense<[ (0.0, 0.0), (0.0, 0.0), // CHECK: 1 // CHECK-NEXT: 0 (0.0, 0.0), (1.0, 0.0), // CHECK-NEXT: 0 // CHECK-NEXT: 0 (0.0, 0.0), (-1.0, 0.0), // CHECK-NEXT: -nan // CHECK-NEXT: -nan (1.0, 1.0), (1.0, 1.0) // CHECK-NEXT: 0.273 // CHECK-NEXT: 0.583 ]> : tensor<8xcomplex> %pow_test_cast = tensor.cast %pow_test : tensor<8xcomplex> to tensor> %pow_func = func.constant @pow : (complex, complex) -> complex call @test_binary(%pow_test_cast, %pow_func) : (tensor>, (complex, complex) -> complex) -> () // complex.tanh test %tanh_test = arith.constant dense<[ (-1.0, -1.0), // CHECK: -1.08392 // CHECK-NEXT: -0.271753 (-1.0, 1.0), // CHECK-NEXT: -1.08392 // CHECK-NEXT: 0.271753 (0.0, 0.0), // CHECK-NEXT: 0 // CHECK-NEXT: 0 (0.0, 1.0), // CHECK-NEXT: 0 // CHECK-NEXT: 1.5574 (1.0, -1.0), // CHECK-NEXT: 1.08392 // CHECK-NEXT: -0.271753 (1.0, 0.0), // CHECK-NEXT: 0.761594 // CHECK-NEXT: 0 (1.0, 1.0) // CHECK-NEXT: 1.08392 // CHECK-NEXT: 0.271753 ]> : tensor<7xcomplex> %tanh_test_cast = tensor.cast %tanh_test : tensor<7xcomplex> to tensor> %tanh_func = func.constant @tanh : (complex) -> complex call @test_unary(%tanh_test_cast, %tanh_func) : (tensor>, (complex) -> complex) -> () // complex.rsqrt test %rsqrt_test = arith.constant dense<[ (-1.0, -1.0), // CHECK: 0.321 // CHECK-NEXT: 0.776 (-1.0, 1.0), // CHECK-NEXT: 0.321 // CHECK-NEXT: -0.776 (0.0, 0.0), // CHECK-NEXT: nan // CHECK-NEXT: nan (0.0, 1.0), // CHECK-NEXT: 0.707 // CHECK-NEXT: -0.707 (1.0, -1.0), // CHECK-NEXT: 0.776 // CHECK-NEXT: 0.321 (1.0, 0.0), // CHECK-NEXT: 1 // CHECK-NEXT: 0 (1.0, 1.0) // CHECK-NEXT: 0.776 // CHECK-NEXT: -0.321 ]> : tensor<7xcomplex> %rsqrt_test_cast = tensor.cast %rsqrt_test : tensor<7xcomplex> to tensor> %rsqrt_func = func.constant @rsqrt : (complex) -> complex call @test_unary(%rsqrt_test_cast, %rsqrt_func) : (tensor>, (complex) -> complex) -> () // complex.conj test %conj_test = arith.constant dense<[ (-1.0, -1.0), // CHECK: -1 // CHECK-NEXT: 1 (-1.0, 1.0), // CHECK-NEXT: -1 // CHECK-NEXT: -1 (0.0, 0.0), // CHECK-NEXT: 0 // CHECK-NEXT: 0 (0.0, 1.0), // CHECK-NEXT: 0 // CHECK-NEXT: -1 (1.0, -1.0), // CHECK-NEXT: 1 // CHECK-NEXT: 1 (1.0, 0.0), // CHECK-NEXT: 1 // CHECK-NEXT: 0 (1.0, 1.0) // CHECK-NEXT: 1 // CHECK-NEXT: -1 ]> : tensor<7xcomplex> %conj_test_cast = tensor.cast %conj_test : tensor<7xcomplex> to tensor> %conj_func = func.constant @conj : (complex) -> complex call @test_unary(%conj_test_cast, %conj_func) : (tensor>, (complex) -> complex) -> () // complex.angle test %angle_test = arith.constant dense<[ (-1.0, -1.0), // CHECK: -2.356 (-1.0, 1.0), // CHECK-NEXT: 2.356 (0.0, 0.0), // CHECK-NEXT: 0 (0.0, 1.0), // CHECK-NEXT: 1.570 (1.0, -1.0), // CHECK-NEXT: -0.785 (1.0, 0.0), // CHECK-NEXT: 0 (1.0, 1.0) // CHECK-NEXT: 0.785 ]> : tensor<7xcomplex> %angle_test_cast = tensor.cast %angle_test : tensor<7xcomplex> to tensor> %angle_func = func.constant @angle : (complex) -> f32 call @test_element(%angle_test_cast, %angle_func) : (tensor>, (complex) -> f32) -> () func.return }