diff --git a/libspu/compiler/codegen/BUILD.bazel b/libspu/compiler/codegen/BUILD.bazel index 2585dae3..18c81585 100644 --- a/libspu/compiler/codegen/BUILD.bazel +++ b/libspu/compiler/codegen/BUILD.bazel @@ -23,6 +23,7 @@ spu_cc_library( srcs = ["codegen.cc"], hdrs = ["codegen.h"], deps = [ + "//libspu:version", "//libspu/dialect/pphlo/IR:dialect", ], ) diff --git a/libspu/compiler/codegen/codegen.cc b/libspu/compiler/codegen/codegen.cc index 1c628b9c..b0c25d21 100644 --- a/libspu/compiler/codegen/codegen.cc +++ b/libspu/compiler/codegen/codegen.cc @@ -16,9 +16,15 @@ #include "llvm/Support/raw_ostream.h" +#include "libspu/version.h" + namespace spu::compiler { std::string CodeGen::doit(mlir::ModuleOp module) { + // Add ir version attr + module->setAttr("pphlo.version", + mlir::StringAttr::get(module->getContext(), getVersionStr())); + // Emit module std::string ir_dump; llvm::raw_string_ostream stream(ir_dump); module.print(stream); diff --git a/libspu/compiler/tests/interpret/abs.mlir b/libspu/compiler/tests/interpret/abs.mlir index 584fc87a..dd655bf1 100644 --- a/libspu/compiler/tests/interpret/abs.mlir +++ b/libspu/compiler/tests/interpret/abs.mlir @@ -1,4 +1,6 @@ -// RUN: spu-translate --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=1 --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=2 --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=3 --interpret -split-input-file %s // AUTO GENERATED, DO NOT EDIT func.func @abs_op_test_i64_i64_p() { diff --git a/libspu/compiler/tests/interpret/add.mlir b/libspu/compiler/tests/interpret/add.mlir index 9244b346..a763c0ae 100644 --- a/libspu/compiler/tests/interpret/add.mlir +++ b/libspu/compiler/tests/interpret/add.mlir @@ -1,4 +1,6 @@ -// RUN: spu-translate --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=1 --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=2 --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=3 --interpret -split-input-file %s // AUTO GENERATED, DO NOT EDIT func.func @add_op_test_i8_i8_pp() { diff --git a/libspu/compiler/tests/interpret/and.mlir b/libspu/compiler/tests/interpret/and.mlir index c06920e1..6e3cdfa6 100644 --- a/libspu/compiler/tests/interpret/and.mlir +++ b/libspu/compiler/tests/interpret/and.mlir @@ -1,4 +1,6 @@ -// RUN: spu-translate --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=1 --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=2 --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=3 --interpret -split-input-file %s // AUTO GENERATED, DO NOT EDIT func.func @and_op_test_i8_i8_pp() { diff --git a/libspu/compiler/tests/interpret/atan2.mlir b/libspu/compiler/tests/interpret/atan2.mlir index 73acce5f..e1938852 100644 --- a/libspu/compiler/tests/interpret/atan2.mlir +++ b/libspu/compiler/tests/interpret/atan2.mlir @@ -1,4 +1,6 @@ -// RUN: spu-translate --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=1 --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=2 --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=3 --interpret -split-input-file %s // AUTO GENERATED, DO NOT EDIT func.func @atan2_op_test_f64_f64_pp() { diff --git a/libspu/compiler/tests/interpret/broadcast.mlir b/libspu/compiler/tests/interpret/broadcast.mlir index 34a1d934..1d0e9a63 100644 --- a/libspu/compiler/tests/interpret/broadcast.mlir +++ b/libspu/compiler/tests/interpret/broadcast.mlir @@ -1,4 +1,6 @@ -// RUN: spu-translate --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=1 --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=2 --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=3 --interpret -split-input-file %s func.func @broadcast_in_dim() { %operand = pphlo.constant dense<[[1], [2], [3]]> : tensor<3x1xi64> diff --git a/libspu/compiler/tests/interpret/case.mlir b/libspu/compiler/tests/interpret/case.mlir index 9beae82b..543fbf86 100644 --- a/libspu/compiler/tests/interpret/case.mlir +++ b/libspu/compiler/tests/interpret/case.mlir @@ -1,4 +1,6 @@ -// RUN: spu-translate --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=1 --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=2 --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=3 --interpret -split-input-file %s func.func @case_negative_index_default() { %index = pphlo.constant dense<-1> : tensor diff --git a/libspu/compiler/tests/interpret/ceil.mlir b/libspu/compiler/tests/interpret/ceil.mlir index 5a7d2e35..d4f74b8b 100644 --- a/libspu/compiler/tests/interpret/ceil.mlir +++ b/libspu/compiler/tests/interpret/ceil.mlir @@ -1,4 +1,6 @@ -// RUN: spu-translate --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=1 --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=2 --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=3 --interpret -split-input-file %s // AUTO GENERATED, DO NOT EDIT func.func @ceil_op_test_f16_f16_p() { diff --git a/libspu/compiler/tests/interpret/clamp.mlir b/libspu/compiler/tests/interpret/clamp.mlir index cf193911..69c05696 100644 --- a/libspu/compiler/tests/interpret/clamp.mlir +++ b/libspu/compiler/tests/interpret/clamp.mlir @@ -1,4 +1,6 @@ -// RUN: spu-translate --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=1 --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=2 --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=3 --interpret -split-input-file %s func.func @clamp_op_test_si64() { %min = pphlo.constant dense<[1, 5, -5]> : tensor<3xi64> diff --git a/libspu/compiler/tests/interpret/concatenate.mlir b/libspu/compiler/tests/interpret/concatenate.mlir index e16c5e1f..1d0d7655 100644 --- a/libspu/compiler/tests/interpret/concatenate.mlir +++ b/libspu/compiler/tests/interpret/concatenate.mlir @@ -1,4 +1,6 @@ -// RUN: spu-translate --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=1 --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=2 --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=3 --interpret -split-input-file %s func.func @concatenate() { %input0 = pphlo.constant dense<[[1, 2], [3, 4], [5, 6]]> : tensor<3x2xi64> diff --git a/libspu/compiler/tests/interpret/convert.mlir b/libspu/compiler/tests/interpret/convert.mlir index 64c6fa15..747047ee 100644 --- a/libspu/compiler/tests/interpret/convert.mlir +++ b/libspu/compiler/tests/interpret/convert.mlir @@ -1,4 +1,6 @@ -// RUN: spu-translate --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=1 --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=2 --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=3 --interpret -split-input-file %s func.func @convert_op_test_1() { %0 = pphlo.constant dense<[0, 1, 8, -9, 0]> : tensor<5xi32> diff --git a/libspu/compiler/tests/interpret/convolution.mlir b/libspu/compiler/tests/interpret/convolution.mlir index 81a12c05..294cdd36 100644 --- a/libspu/compiler/tests/interpret/convolution.mlir +++ b/libspu/compiler/tests/interpret/convolution.mlir @@ -1,4 +1,6 @@ -// RUN: spu-translate --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=1 --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=2 --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=3 --interpret -split-input-file %s func.func @main() { %0 = pphlo.constant dense<[[[[ 1.0, 2.0, 3.0, 4.0], diff --git a/libspu/compiler/tests/interpret/cosine.mlir b/libspu/compiler/tests/interpret/cosine.mlir index 2b89d421..72d6f249 100644 --- a/libspu/compiler/tests/interpret/cosine.mlir +++ b/libspu/compiler/tests/interpret/cosine.mlir @@ -1,4 +1,6 @@ -// RUN: spu-translate --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=1 --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=2 --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=3 --interpret -split-input-file %s // AUTO GENERATED, DO NOT EDIT func.func @cosine_op_test_f16_f16_p() { diff --git a/libspu/compiler/tests/interpret/divide.mlir b/libspu/compiler/tests/interpret/divide.mlir index 6b5a95e1..56ce53c2 100644 --- a/libspu/compiler/tests/interpret/divide.mlir +++ b/libspu/compiler/tests/interpret/divide.mlir @@ -1,4 +1,6 @@ -// RUN: spu-translate --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=1 --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=2 --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=3 --interpret -split-input-file %s // AUTO GENERATED, DO NOT EDIT func.func @divide_op_test_i64_i64_pp() { diff --git a/libspu/compiler/tests/interpret/dot_general.mlir b/libspu/compiler/tests/interpret/dot_general.mlir index b97f06f7..29023c81 100644 --- a/libspu/compiler/tests/interpret/dot_general.mlir +++ b/libspu/compiler/tests/interpret/dot_general.mlir @@ -1,4 +1,6 @@ -// RUN: spu-translate --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=1 --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=2 --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=3 --interpret -split-input-file %s func.func @dot_general_op_test_si64() { %lhs = pphlo.constant dense<[[[1, 2], [3, 4]], diff --git a/libspu/compiler/tests/interpret/dynamic_slice.mlir b/libspu/compiler/tests/interpret/dynamic_slice.mlir index a72577c6..672ace7c 100644 --- a/libspu/compiler/tests/interpret/dynamic_slice.mlir +++ b/libspu/compiler/tests/interpret/dynamic_slice.mlir @@ -1,4 +1,6 @@ -// RUN: spu-translate --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=1 --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=2 --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=3 --interpret -split-input-file %s func.func @dynamic_slice() { %operand = pphlo.constant dense<[[1, 1, 1], @@ -12,3 +14,22 @@ func.func @dynamic_slice() { pphlo.custom_call @expect_eq (%result, %operand) : (tensor<3x3xi64>,tensor<3x3xi64>)->() func.return } + +// ----- + +func.func @dynamic_slice() { + %operand = pphlo.constant dense<[[1, 2, 3], + [4, 5, 6], + [7, 8, 9]]> : tensor<3x3xi64> + %i0 = pphlo.constant dense<1> : tensor + %start_indices0 = pphlo.convert %i0 : (tensor) -> tensor> + %start_indices1 = pphlo.constant dense<1> : tensor + %r = "pphlo.dynamic_slice"(%operand, %start_indices0, %start_indices1) { + slice_sizes = array + } : (tensor<3x3xi64>, tensor>, tensor) -> tensor<2x2x!pphlo.secret> + %result = pphlo.convert %r : (tensor<2x2x!pphlo.secret>) -> tensor<2x2xi64> + %expected = pphlo.constant dense<[[5, 6], + [8, 9]]> : tensor<2x2xi64> + pphlo.custom_call @expect_eq (%result, %expected) : (tensor<2x2xi64>,tensor<2x2xi64>)->() + func.return +} diff --git a/libspu/compiler/tests/interpret/dynamic_update_slice.mlir b/libspu/compiler/tests/interpret/dynamic_update_slice.mlir index 9177f938..a7053428 100644 --- a/libspu/compiler/tests/interpret/dynamic_update_slice.mlir +++ b/libspu/compiler/tests/interpret/dynamic_update_slice.mlir @@ -1,4 +1,6 @@ -// RUN: spu-translate --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=1 --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=2 --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=3 --interpret -split-input-file %s func.func @dynamic_update_slice() { %operand = pphlo.constant dense<[[1, 1, 1, 1], diff --git a/libspu/compiler/tests/interpret/equal.mlir b/libspu/compiler/tests/interpret/equal.mlir index c29d51e4..f5364638 100644 --- a/libspu/compiler/tests/interpret/equal.mlir +++ b/libspu/compiler/tests/interpret/equal.mlir @@ -1,4 +1,6 @@ -// RUN: spu-translate --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=1 --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=2 --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=3 --interpret -split-input-file %s // AUTO GENERATED, DO NOT EDIT func.func @equal_op_test_i64_i1_pp() { diff --git a/libspu/compiler/tests/interpret/exponential.mlir b/libspu/compiler/tests/interpret/exponential.mlir index 4b505e63..a85c5bb6 100644 --- a/libspu/compiler/tests/interpret/exponential.mlir +++ b/libspu/compiler/tests/interpret/exponential.mlir @@ -1,4 +1,6 @@ -// RUN: spu-translate --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=1 --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=2 --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=3 --interpret -split-input-file %s // AUTO GENERATED, DO NOT EDIT func.func @exponential_op_test_f64_f64_p() { diff --git a/libspu/compiler/tests/interpret/exponential_minus_one.mlir b/libspu/compiler/tests/interpret/exponential_minus_one.mlir index 46cf91f1..1a337a21 100644 --- a/libspu/compiler/tests/interpret/exponential_minus_one.mlir +++ b/libspu/compiler/tests/interpret/exponential_minus_one.mlir @@ -1,4 +1,6 @@ -// RUN: spu-translate --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=1 --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=2 --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=3 --interpret -split-input-file %s // AUTO GENERATED, DO NOT EDIT func.func @exponential_minus_one_op_test_f64_f64_p() { diff --git a/libspu/compiler/tests/interpret/floor.mlir b/libspu/compiler/tests/interpret/floor.mlir index 734266b9..97ccdb1e 100644 --- a/libspu/compiler/tests/interpret/floor.mlir +++ b/libspu/compiler/tests/interpret/floor.mlir @@ -1,4 +1,6 @@ -// RUN: spu-translate --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=1 --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=2 --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=3 --interpret -split-input-file %s // AUTO GENERATED, DO NOT EDIT func.func @floor_op_test_f16_f16_p() { diff --git a/libspu/compiler/tests/interpret/generate_mlir_tests.py b/libspu/compiler/tests/interpret/generate_mlir_tests.py index 114e66a0..f9bdef86 100755 --- a/libspu/compiler/tests/interpret/generate_mlir_tests.py +++ b/libspu/compiler/tests/interpret/generate_mlir_tests.py @@ -90,7 +90,15 @@ def TestCase(inputs, expected, checker='expect_eq', tol=None): with open(f"{test_name}.mlir", "w+") as f: # emit run command - f.write("// RUN: spu-translate --interpret -split-input-file %s\n") + f.write( + "// RUN: spu-translate --protocol_kind=1 --interpret -split-input-file %s\n" + ) + f.write( + "// RUN: spu-translate --protocol_kind=2 --interpret -split-input-file %s\n" + ) + f.write( + "// RUN: spu-translate --protocol_kind=3 --interpret -split-input-file %s\n" + ) f.write("// AUTO GENERATED, DO NOT EDIT\n\n") # Emit cases diff --git a/libspu/compiler/tests/interpret/greater.mlir b/libspu/compiler/tests/interpret/greater.mlir index e6b6b0d1..7f8e76be 100644 --- a/libspu/compiler/tests/interpret/greater.mlir +++ b/libspu/compiler/tests/interpret/greater.mlir @@ -1,4 +1,6 @@ -// RUN: spu-translate --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=1 --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=2 --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=3 --interpret -split-input-file %s // AUTO GENERATED, DO NOT EDIT func.func @greater_op_test_i64_i1_pp() { diff --git a/libspu/compiler/tests/interpret/greater_equal.mlir b/libspu/compiler/tests/interpret/greater_equal.mlir index b1b32c14..305aaff5 100644 --- a/libspu/compiler/tests/interpret/greater_equal.mlir +++ b/libspu/compiler/tests/interpret/greater_equal.mlir @@ -1,4 +1,6 @@ -// RUN: spu-translate --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=1 --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=2 --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=3 --interpret -split-input-file %s // AUTO GENERATED, DO NOT EDIT func.func @greater_equal_op_test_i64_i1_pp() { diff --git a/libspu/compiler/tests/interpret/if.mlir b/libspu/compiler/tests/interpret/if.mlir index 7f98d8b0..cc98b65d 100644 --- a/libspu/compiler/tests/interpret/if.mlir +++ b/libspu/compiler/tests/interpret/if.mlir @@ -1,4 +1,6 @@ -// RUN: spu-translate --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=1 --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=2 --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=3 --interpret -split-input-file %s func.func @if_ops_true_branch() { %pred = pphlo.constant dense : tensor diff --git a/libspu/compiler/tests/interpret/iota.mlir b/libspu/compiler/tests/interpret/iota.mlir index 40f7800d..a7ee86ed 100644 --- a/libspu/compiler/tests/interpret/iota.mlir +++ b/libspu/compiler/tests/interpret/iota.mlir @@ -1,4 +1,6 @@ -// RUN: spu-translate --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=1 --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=2 --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=3 --interpret -split-input-file %s func.func @iota_op_test_si8_dim_0() { %0 = pphlo.iota dim = 0 : tensor<3x4xi8> diff --git a/libspu/compiler/tests/interpret/less.mlir b/libspu/compiler/tests/interpret/less.mlir index 21f12d45..58444a29 100644 --- a/libspu/compiler/tests/interpret/less.mlir +++ b/libspu/compiler/tests/interpret/less.mlir @@ -1,4 +1,6 @@ -// RUN: spu-translate --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=1 --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=2 --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=3 --interpret -split-input-file %s // AUTO GENERATED, DO NOT EDIT func.func @less_op_test_i64_i1_pp() { diff --git a/libspu/compiler/tests/interpret/less_equal.mlir b/libspu/compiler/tests/interpret/less_equal.mlir index 2715e3c6..9951a569 100644 --- a/libspu/compiler/tests/interpret/less_equal.mlir +++ b/libspu/compiler/tests/interpret/less_equal.mlir @@ -1,4 +1,6 @@ -// RUN: spu-translate --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=1 --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=2 --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=3 --interpret -split-input-file %s // AUTO GENERATED, DO NOT EDIT func.func @less_equal_op_test_i64_i1_pp() { diff --git a/libspu/compiler/tests/interpret/log.mlir b/libspu/compiler/tests/interpret/log.mlir index 56c51db7..af61d86a 100644 --- a/libspu/compiler/tests/interpret/log.mlir +++ b/libspu/compiler/tests/interpret/log.mlir @@ -1,4 +1,6 @@ -// RUN: spu-translate --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=1 --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=2 --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=3 --interpret -split-input-file %s // AUTO GENERATED, DO NOT EDIT func.func @log_op_test_f64_f64_p() { diff --git a/libspu/compiler/tests/interpret/log_plus_one.mlir b/libspu/compiler/tests/interpret/log_plus_one.mlir index 721f72b9..3aec9184 100644 --- a/libspu/compiler/tests/interpret/log_plus_one.mlir +++ b/libspu/compiler/tests/interpret/log_plus_one.mlir @@ -1,4 +1,6 @@ -// RUN: spu-translate --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=1 --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=2 --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=3 --interpret -split-input-file %s // AUTO GENERATED, DO NOT EDIT func.func @log_plus_one_op_test_f64_f64_p() { diff --git a/libspu/compiler/tests/interpret/logistic.mlir b/libspu/compiler/tests/interpret/logistic.mlir index 886ef64a..eeac6fab 100644 --- a/libspu/compiler/tests/interpret/logistic.mlir +++ b/libspu/compiler/tests/interpret/logistic.mlir @@ -1,4 +1,6 @@ -// RUN: spu-translate --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=1 --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=2 --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=3 --interpret -split-input-file %s // AUTO GENERATED, DO NOT EDIT func.func @logistic_op_test_f64_f64_p() { diff --git a/libspu/compiler/tests/interpret/maximum.mlir b/libspu/compiler/tests/interpret/maximum.mlir index f05a0048..b90553e7 100644 --- a/libspu/compiler/tests/interpret/maximum.mlir +++ b/libspu/compiler/tests/interpret/maximum.mlir @@ -1,4 +1,6 @@ -// RUN: spu-translate --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=1 --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=2 --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=3 --interpret -split-input-file %s // AUTO GENERATED, DO NOT EDIT func.func @maximum_op_test_i8_i8_pp() { diff --git a/libspu/compiler/tests/interpret/minimum.mlir b/libspu/compiler/tests/interpret/minimum.mlir index 763aa66b..74bb2b83 100644 --- a/libspu/compiler/tests/interpret/minimum.mlir +++ b/libspu/compiler/tests/interpret/minimum.mlir @@ -1,4 +1,6 @@ -// RUN: spu-translate --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=1 --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=2 --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=3 --interpret -split-input-file %s // AUTO GENERATED, DO NOT EDIT func.func @minimum_op_test_i8_i8_pp() { diff --git a/libspu/compiler/tests/interpret/multiply.mlir b/libspu/compiler/tests/interpret/multiply.mlir index 930b6458..82b780f3 100644 --- a/libspu/compiler/tests/interpret/multiply.mlir +++ b/libspu/compiler/tests/interpret/multiply.mlir @@ -1,4 +1,6 @@ -// RUN: spu-translate --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=1 --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=2 --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=3 --interpret -split-input-file %s // AUTO GENERATED, DO NOT EDIT func.func @multiply_op_test_i8_i8_pp() { diff --git a/libspu/compiler/tests/interpret/negate.mlir b/libspu/compiler/tests/interpret/negate.mlir index fa5fe4c3..8c5e74c3 100644 --- a/libspu/compiler/tests/interpret/negate.mlir +++ b/libspu/compiler/tests/interpret/negate.mlir @@ -1,4 +1,6 @@ -// RUN: spu-translate --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=1 --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=2 --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=3 --interpret -split-input-file %s // AUTO GENERATED, DO NOT EDIT func.func @negate_op_test_i8_i8_p() { diff --git a/libspu/compiler/tests/interpret/not.mlir b/libspu/compiler/tests/interpret/not.mlir index 77c91d25..0fdf44e4 100644 --- a/libspu/compiler/tests/interpret/not.mlir +++ b/libspu/compiler/tests/interpret/not.mlir @@ -1,4 +1,6 @@ -// RUN: spu-translate --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=1 --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=2 --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=3 --interpret -split-input-file %s // AUTO GENERATED, DO NOT EDIT func.func @not_op_test_i8_i8_p() { diff --git a/libspu/compiler/tests/interpret/not_equal.mlir b/libspu/compiler/tests/interpret/not_equal.mlir index aabacc0b..1bbbd5b3 100644 --- a/libspu/compiler/tests/interpret/not_equal.mlir +++ b/libspu/compiler/tests/interpret/not_equal.mlir @@ -1,4 +1,6 @@ -// RUN: spu-translate --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=1 --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=2 --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=3 --interpret -split-input-file %s // AUTO GENERATED, DO NOT EDIT func.func @not_equal_op_test_i64_i1_pp() { diff --git a/libspu/compiler/tests/interpret/or.mlir b/libspu/compiler/tests/interpret/or.mlir index 2856bba6..79836813 100644 --- a/libspu/compiler/tests/interpret/or.mlir +++ b/libspu/compiler/tests/interpret/or.mlir @@ -1,4 +1,6 @@ -// RUN: spu-translate --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=1 --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=2 --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=3 --interpret -split-input-file %s // AUTO GENERATED, DO NOT EDIT func.func @or_op_test_i8_i8_pp() { diff --git a/libspu/compiler/tests/interpret/pad.mlir b/libspu/compiler/tests/interpret/pad.mlir index 85436480..abedc73a 100644 --- a/libspu/compiler/tests/interpret/pad.mlir +++ b/libspu/compiler/tests/interpret/pad.mlir @@ -1,4 +1,6 @@ -// RUN: spu-translate --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=1 --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=2 --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=3 --interpret -split-input-file %s func.func @pad() { %operand = pphlo.constant dense<[[0, 0, 0, 0], diff --git a/libspu/compiler/tests/interpret/popcnt.mlir b/libspu/compiler/tests/interpret/popcnt.mlir index 8d741134..e5f83152 100644 --- a/libspu/compiler/tests/interpret/popcnt.mlir +++ b/libspu/compiler/tests/interpret/popcnt.mlir @@ -1,4 +1,6 @@ -// RUN: spu-translate --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=1 --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=2 --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=3 --interpret -split-input-file %s // AUTO GENERATED, DO NOT EDIT func.func @popcnt_op_test_i64_i64_p() { diff --git a/libspu/compiler/tests/interpret/power.mlir b/libspu/compiler/tests/interpret/power.mlir index 8041418a..dd950ef1 100644 --- a/libspu/compiler/tests/interpret/power.mlir +++ b/libspu/compiler/tests/interpret/power.mlir @@ -1,4 +1,6 @@ -// RUN: spu-translate --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=1 --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=2 --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=3 --interpret -split-input-file %s // AUTO GENERATED, DO NOT EDIT func.func @power_op_test_i64_i64_pp() { diff --git a/libspu/compiler/tests/interpret/reduce.mlir b/libspu/compiler/tests/interpret/reduce.mlir index 8fc4ced7..3b34bf3e 100644 --- a/libspu/compiler/tests/interpret/reduce.mlir +++ b/libspu/compiler/tests/interpret/reduce.mlir @@ -1,4 +1,6 @@ -// RUN: spu-translate --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=1 --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=2 --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=3 --interpret -split-input-file %s func.func @reduce() { %input = pphlo.constant dense<[[0, 1, 2, 3, 4, 5]]> : tensor<1x6xi64> diff --git a/libspu/compiler/tests/interpret/reduce_window.mlir b/libspu/compiler/tests/interpret/reduce_window.mlir index 1b28aef1..5385ab04 100644 --- a/libspu/compiler/tests/interpret/reduce_window.mlir +++ b/libspu/compiler/tests/interpret/reduce_window.mlir @@ -1,4 +1,6 @@ -// RUN: spu-translate --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=1 --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=2 --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=3 --interpret -split-input-file %s func.func @reduce_window() { %input = pphlo.constant dense<[[1, 2], [3, 4], [5, 6]]> : tensor<3x2xi64> diff --git a/libspu/compiler/tests/interpret/reshape.mlir b/libspu/compiler/tests/interpret/reshape.mlir index fa3551c6..9e483b77 100644 --- a/libspu/compiler/tests/interpret/reshape.mlir +++ b/libspu/compiler/tests/interpret/reshape.mlir @@ -1,4 +1,6 @@ -// RUN: spu-translate --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=1 --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=2 --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=3 --interpret -split-input-file %s // AUTO GENERATED, DO NOT EDIT func.func @reshape_op_test_i32_i32_p() { diff --git a/libspu/compiler/tests/interpret/reverse.mlir b/libspu/compiler/tests/interpret/reverse.mlir index 0489311b..63ab9590 100644 --- a/libspu/compiler/tests/interpret/reverse.mlir +++ b/libspu/compiler/tests/interpret/reverse.mlir @@ -1,4 +1,6 @@ -// RUN: spu-translate --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=1 --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=2 --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=3 --interpret -split-input-file %s func.func @reverse() { %operand = pphlo.constant dense<[[1, 2], [3, 4], [5, 6]]> : tensor<3x2xi64> diff --git a/libspu/compiler/tests/interpret/ring_cast.mlir b/libspu/compiler/tests/interpret/ring_cast.mlir new file mode 100644 index 00000000..94b53241 --- /dev/null +++ b/libspu/compiler/tests/interpret/ring_cast.mlir @@ -0,0 +1,13 @@ +// RUN: spu-translate --protocol_kind=1 --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=2 --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=3 --interpret -split-input-file %s + +func.func @cast_1() { + %c0 = pphlo.constant dense<[[1, 2], [3, 4], [5, 6]]> : tensor<3x2xi32> + %operand = pphlo.convert %c0 : (tensor<3x2xi32>)->tensor<3x2x!pphlo.secret> + %r = pphlo.convert %operand : (tensor<3x2x!pphlo.secret>) -> tensor<3x2x!pphlo.secret> + %expected = pphlo.constant dense<[[1, 2], [3, 4], [5, 6]]> : tensor<3x2xi64> + %result = pphlo.convert %r : (tensor<3x2x!pphlo.secret>)->tensor<3x2xi64> + pphlo.custom_call @expect_eq (%result, %expected) : (tensor<3x2xi64>,tensor<3x2xi64>)->() + func.return +} diff --git a/libspu/compiler/tests/interpret/round_nearest_afz.mlir b/libspu/compiler/tests/interpret/round_nearest_afz.mlir index 79eba66d..6601fa1d 100644 --- a/libspu/compiler/tests/interpret/round_nearest_afz.mlir +++ b/libspu/compiler/tests/interpret/round_nearest_afz.mlir @@ -1,4 +1,6 @@ -// RUN: spu-translate --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=1 --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=2 --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=3 --interpret -split-input-file %s // AUTO GENERATED, DO NOT EDIT func.func @round_nearest_afz_op_test_f64_f64_p() { diff --git a/libspu/compiler/tests/interpret/rsqrt.mlir b/libspu/compiler/tests/interpret/rsqrt.mlir index 0ef05654..ef6470c9 100644 --- a/libspu/compiler/tests/interpret/rsqrt.mlir +++ b/libspu/compiler/tests/interpret/rsqrt.mlir @@ -1,4 +1,6 @@ -// RUN: spu-translate --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=1 --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=2 --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=3 --interpret -split-input-file %s // AUTO GENERATED, DO NOT EDIT func.func @rsqrt_op_test_f64_f64_p() { diff --git a/libspu/compiler/tests/interpret/select.mlir b/libspu/compiler/tests/interpret/select.mlir index eb15e544..33e9a9c7 100644 --- a/libspu/compiler/tests/interpret/select.mlir +++ b/libspu/compiler/tests/interpret/select.mlir @@ -1,4 +1,6 @@ -// RUN: spu-translate --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=1 --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=2 --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=3 --interpret -split-input-file %s func.func @select_op_test_si64() { %pred = pphlo.constant dense<[true, false, true]> : tensor<3xi1> diff --git a/libspu/compiler/tests/interpret/select_and_scatter.mlir b/libspu/compiler/tests/interpret/select_and_scatter.mlir index 6ae7fc19..5e55dc59 100644 --- a/libspu/compiler/tests/interpret/select_and_scatter.mlir +++ b/libspu/compiler/tests/interpret/select_and_scatter.mlir @@ -1,4 +1,6 @@ -// RUN: spu-translate --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=1 --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=2 --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=3 --interpret -split-input-file %s // FIXME func.func @select_and_scatter_op_test() { diff --git a/libspu/compiler/tests/interpret/shift_right_arithmetic.mlir b/libspu/compiler/tests/interpret/shift_right_arithmetic.mlir index 7cc71a93..494666ae 100644 --- a/libspu/compiler/tests/interpret/shift_right_arithmetic.mlir +++ b/libspu/compiler/tests/interpret/shift_right_arithmetic.mlir @@ -1,4 +1,6 @@ -// RUN: spu-translate --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=1 --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=2 --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=3 --interpret -split-input-file %s // AUTO GENERATED, DO NOT EDIT func.func @shift_right_arithmetic_op_test_i64_i64_pp() { diff --git a/libspu/compiler/tests/interpret/shift_right_logical.mlir b/libspu/compiler/tests/interpret/shift_right_logical.mlir index f7331033..253d6cc3 100644 --- a/libspu/compiler/tests/interpret/shift_right_logical.mlir +++ b/libspu/compiler/tests/interpret/shift_right_logical.mlir @@ -1,4 +1,6 @@ -// RUN: spu-translate --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=1 --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=2 --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=3 --interpret -split-input-file %s // AUTO GENERATED, DO NOT EDIT func.func @shift_right_logical_op_test_i64_i64_pp() { diff --git a/libspu/compiler/tests/interpret/sign.mlir b/libspu/compiler/tests/interpret/sign.mlir index 3c1b2bed..b153a373 100644 --- a/libspu/compiler/tests/interpret/sign.mlir +++ b/libspu/compiler/tests/interpret/sign.mlir @@ -1,4 +1,6 @@ -// RUN: spu-translate --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=1 --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=2 --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=3 --interpret -split-input-file %s // AUTO GENERATED, DO NOT EDIT func.func @sign_op_test_i64_i64_p() { diff --git a/libspu/compiler/tests/interpret/sine.mlir b/libspu/compiler/tests/interpret/sine.mlir index 52825da5..f0b59e5c 100644 --- a/libspu/compiler/tests/interpret/sine.mlir +++ b/libspu/compiler/tests/interpret/sine.mlir @@ -1,4 +1,6 @@ -// RUN: spu-translate --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=1 --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=2 --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=3 --interpret -split-input-file %s // AUTO GENERATED, DO NOT EDIT func.func @sine_op_test_f16_f16_p() { diff --git a/libspu/compiler/tests/interpret/slice.mlir b/libspu/compiler/tests/interpret/slice.mlir index e6ce68b2..b4b8bdbe 100644 --- a/libspu/compiler/tests/interpret/slice.mlir +++ b/libspu/compiler/tests/interpret/slice.mlir @@ -1,4 +1,6 @@ -// RUN: spu-translate --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=1 --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=2 --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=3 --interpret -split-input-file %s func.func @slice_op() { %operand = pphlo.constant dense<[[0, 0, 1, 0, 0, 1], diff --git a/libspu/compiler/tests/interpret/sort.mlir b/libspu/compiler/tests/interpret/sort.mlir index c0def6c4..837ded37 100644 --- a/libspu/compiler/tests/interpret/sort.mlir +++ b/libspu/compiler/tests/interpret/sort.mlir @@ -1,4 +1,6 @@ -// RUN: spu-translate --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=1 --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=2 --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=3 --interpret -split-input-file %s func.func @sort_stable() { %input0 = pphlo.constant dense<[[1, 2, 3], [3, 2, 1]]> : tensor<2x3xi64> diff --git a/libspu/compiler/tests/interpret/sqrt.mlir b/libspu/compiler/tests/interpret/sqrt.mlir index 249355fa..9248077a 100644 --- a/libspu/compiler/tests/interpret/sqrt.mlir +++ b/libspu/compiler/tests/interpret/sqrt.mlir @@ -1,4 +1,6 @@ -// RUN: spu-translate --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=1 --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=2 --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=3 --interpret -split-input-file %s // AUTO GENERATED, DO NOT EDIT func.func @sqrt_op_test_f64_f64_p() { diff --git a/libspu/compiler/tests/interpret/subtract.mlir b/libspu/compiler/tests/interpret/subtract.mlir index 3cab82eb..ce8b9633 100644 --- a/libspu/compiler/tests/interpret/subtract.mlir +++ b/libspu/compiler/tests/interpret/subtract.mlir @@ -1,4 +1,6 @@ -// RUN: spu-translate --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=1 --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=2 --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=3 --interpret -split-input-file %s // AUTO GENERATED, DO NOT EDIT func.func @subtract_op_test_i8_i8_pp() { diff --git a/libspu/compiler/tests/interpret/tanh.mlir b/libspu/compiler/tests/interpret/tanh.mlir index 4f42bbf7..413dc6d2 100644 --- a/libspu/compiler/tests/interpret/tanh.mlir +++ b/libspu/compiler/tests/interpret/tanh.mlir @@ -1,4 +1,6 @@ -// RUN: spu-translate --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=1 --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=2 --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=3 --interpret -split-input-file %s // AUTO GENERATED, DO NOT EDIT func.func @tanh_op_test_f16_f16_p() { diff --git a/libspu/compiler/tests/interpret/transpose.mlir b/libspu/compiler/tests/interpret/transpose.mlir index 126660db..d5ce9b6e 100644 --- a/libspu/compiler/tests/interpret/transpose.mlir +++ b/libspu/compiler/tests/interpret/transpose.mlir @@ -1,4 +1,6 @@ -// RUN: spu-translate --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=1 --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=2 --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=3 --interpret -split-input-file %s func.func @transpose_op_test_si32() { %0 = pphlo.constant dense<[[[1,2],[3,4],[5,6]], [[7,8],[9,10],[11,12]]]> : tensor<2x3x2xi32> diff --git a/libspu/compiler/tests/interpret/while.mlir b/libspu/compiler/tests/interpret/while.mlir index 2bcbd3ff..32789fae 100644 --- a/libspu/compiler/tests/interpret/while.mlir +++ b/libspu/compiler/tests/interpret/while.mlir @@ -1,4 +1,6 @@ -// RUN: spu-translate --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=1 --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=2 --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=3 --interpret -split-input-file %s func.func @while() { // int i = 0; diff --git a/libspu/compiler/tests/interpret/xor.mlir b/libspu/compiler/tests/interpret/xor.mlir index 21d3484d..c2e1f1ee 100644 --- a/libspu/compiler/tests/interpret/xor.mlir +++ b/libspu/compiler/tests/interpret/xor.mlir @@ -1,4 +1,6 @@ -// RUN: spu-translate --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=1 --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=2 --interpret -split-input-file %s +// RUN: spu-translate --protocol_kind=3 --interpret -split-input-file %s // AUTO GENERATED, DO NOT EDIT func.func @xor_op_test_i8_i8_pp() { diff --git a/libspu/compiler/tools/spu-translate.cc b/libspu/compiler/tools/spu-translate.cc index a37bd465..423321a5 100644 --- a/libspu/compiler/tools/spu-translate.cc +++ b/libspu/compiler/tools/spu-translate.cc @@ -46,6 +46,10 @@ template struct fmt::formatter> : ostream_formatter {}; +llvm::cl::opt ProtocolKind( + "protocol_kind", llvm::cl::init(1), + llvm::cl::desc("1 for REF2k, 2 for SEMI2k, 3 for ABY3, 4 for Cheetah")); + namespace mlir { namespace { @@ -215,9 +219,29 @@ void evalModule(ModuleOp module) { runPasses(module); ::spu::RuntimeConfig conf; - conf.set_protocol(::spu::REF2K); conf.set_field(::spu::FM64); conf.set_enable_type_checker(true); + int numParties = 1; + + switch (ProtocolKind.getValue()) { + case 1: { + conf.set_protocol(::spu::REF2K); + numParties = 1; + break; + } + case 2: { + conf.set_protocol(::spu::SEMI2K); + numParties = 2; + break; + } + case 3: { + conf.set_protocol(::spu::ABY3); + numParties = 3; + break; + } + } + + SPDLOG_INFO(conf.DebugString()); auto entry_function = spu::get_entrypoint(module); SPU_ENFORCE(entry_function, "main module not found"); @@ -227,7 +251,7 @@ void evalModule(ModuleOp module) { ::spu::device::ExecutionOptions opts; ::spu::mpc::utils::simulate( - 1, [&](const std::shared_ptr &lctx) { + numParties, [&](const std::shared_ptr &lctx) { auto sctx = ::spu::kernel::test::makeSPUContext(conf, lctx); runRegion(&executor, &sctx, nullptr, entry_function.getBody(), {}, diff --git a/libspu/device/BUILD.bazel b/libspu/device/BUILD.bazel index 1a071162..a821980c 100644 --- a/libspu/device/BUILD.bazel +++ b/libspu/device/BUILD.bazel @@ -53,6 +53,7 @@ spu_cc_library( srcs = ["executor.cc"], hdrs = ["executor.h"], deps = [ + ":intrinsic_table", ":symbol_table", "//libspu:spu_cc_proto", "//libspu/core:context", @@ -68,6 +69,7 @@ spu_cc_library( hdrs = ["api.h"], deps = [ ":executor", + "//libspu:version", "//libspu/device/pphlo:pphlo_executor", "//libspu/device/utils:debug_dump_constant", "//libspu/dialect/utils", diff --git a/libspu/device/api.cc b/libspu/device/api.cc index 97077a93..5535ad85 100644 --- a/libspu/device/api.cc +++ b/libspu/device/api.cc @@ -29,6 +29,7 @@ #include "libspu/device/utils/debug_dump_constant.h" #include "libspu/dialect/pphlo/IR/dialect.h" #include "libspu/dialect/utils/utils.h" +#include "libspu/version.h" namespace spu::device { namespace { @@ -290,6 +291,22 @@ void executeImpl(OpExecutor *executor, spu::SPUContext *sctx, SPU_ENFORCE(moduleOpRef, "MLIR parser failure"); + if (!moduleOpRef.get()->hasAttr("pphlo.version")) { + // There are tests that has no version attributes. + // So treats this as a warning + SPDLOG_WARN("Missing ir version"); + } else { + auto ir_version = mlir::dyn_cast( + moduleOpRef.get()->getAttr("pphlo.version")) + .str(); + if (ir_version != getVersionStr()) { + SPU_THROW( + "IR was generted by compiler {} and does not match current runtime " + "{}", + ir_version, getVersionStr()); + } + } + auto entry_function = mlir::spu::get_entrypoint(moduleOpRef.get()); SPU_ENFORCE(entry_function, "main module not found"); diff --git a/libspu/device/executor.cc b/libspu/device/executor.cc index 9093b628..5d03db2d 100644 --- a/libspu/device/executor.cc +++ b/libspu/device/executor.cc @@ -24,6 +24,8 @@ #include "libspu/core/context.h" #include "libspu/core/prelude.h" #include "libspu/core/value.h" +#include "libspu/device/intrinsic_table.h" +#include "libspu/dialect/pphlo/IR/ops.h" namespace spu::device { @@ -166,12 +168,15 @@ class OpExecTask final { OpExecTask() = default; explicit OpExecTask(std::unique_ptr sctx, OpExecutor *executor, SymbolScope *sscope, mlir::Operation *op, - SymbolTableEvent *event) + SymbolTableEvent *event, + const llvm::SmallVector &extra_dependencies) : sctx_(std::move(sctx)), executor_(executor), sscope_(sscope), op_(op), - event_(event) { + event_(event), + extra_dependencies_(extra_dependencies.begin(), + extra_dependencies.end()) { // If a op has nested regions, it may depend on more values than operands // FIXME: (azheng) Implement a better notify mechanism if (op->getNumRegions() > 0) { @@ -228,8 +233,21 @@ class BlockParallelRunner final { std::vector run(mlir::Block &block) { SymbolTableEvent st_event; + llvm::SmallVector extra_dependencies; for (auto &op : block.without_terminator()) { - task_queue_.emplace(sctx_->fork(), executor_, sscope_, &op, &st_event); + task_queue_.emplace(sctx_->fork(), executor_, sscope_, &op, &st_event, + extra_dependencies); + // FIXME(jimi): DBG_PRINT has side effect but has no outputs. We should + // use more formal scheduling policy + if (auto custom_call = llvm::dyn_cast(op); + custom_call && custom_call.getCallTargetName() == DBG_PRINT) { + continue; + } + auto hasSideEffect = op.getAttrOfType("has_side_effect"); + if (hasSideEffect && hasSideEffect.getValue()) { + extra_dependencies.append(op.getResults().begin(), + op.getResults().end()); + } } threads_.reserve(opts_.concurrency); diff --git a/libspu/device/intrinsic_table.h b/libspu/device/intrinsic_table.h index d56c5be9..c83d74d7 100644 --- a/libspu/device/intrinsic_table.h +++ b/libspu/device/intrinsic_table.h @@ -22,7 +22,8 @@ #define PREFER_A "spu.prefer_a" #define DBG_PRINT "spu.dbg_print" #define GATHER "spu.gather" -#define MAKE_CACHE_VAR "spu.make_cache_var" +// should be consistent with python level +#define MAKE_CACHED_VAR "spu.make_cached_var" #define DROP_CACHED_VAR "spu.drop_cached_var" // clang-format on diff --git a/libspu/device/pphlo/pphlo_intrinsic_executor.cc b/libspu/device/pphlo/pphlo_intrinsic_executor.cc index 01cb2565..7bfafc3b 100644 --- a/libspu/device/pphlo/pphlo_intrinsic_executor.cc +++ b/libspu/device/pphlo/pphlo_intrinsic_executor.cc @@ -50,7 +50,7 @@ std::vector intrinsic_dispatcher(SPUContext* ctx, return {zeros}; } - if (name == MAKE_CACHE_VAR) { + if (name == MAKE_CACHED_VAR) { if (ctx->hasKernel("beaver_cache")) { SPU_ENFORCE(inputs.size() == 1); dynDispatch(ctx, "beaver_cache", inputs[0], true); diff --git a/libspu/mpc/api.cc b/libspu/mpc/api.cc index a27e81d0..2008e8aa 100644 --- a/libspu/mpc/api.cc +++ b/libspu/mpc/api.cc @@ -225,7 +225,7 @@ Type common_type_s(SPUContext* ctx, const Type& a, const Type& b) { } else if (a.isa() && b.isa()) { return b; } else if (a.isa() && b.isa()) { - return common_type_b(ctx, b, b); + return common_type_b(ctx, a, b); } else { SPU_THROW("should not be here, a={}, b={}", a, b); } diff --git a/requirements.txt b/requirements.txt index 695a2f1f..bea5a7d1 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,5 @@ grpcio>=1.42.0,!=1.48.0 -numpy>=1.22.0 +numpy>=1.22.0, < 2 protobuf>=4, <5 cloudpickle>=2.0.0 multiprocess>=0.70.12.2 diff --git a/spu/tests/spu_runtime_test.py b/spu/tests/spu_runtime_test.py index 938b4672..84d1956b 100644 --- a/spu/tests/spu_runtime_test.py +++ b/spu/tests/spu_runtime_test.py @@ -76,6 +76,31 @@ def test_raise(self): with self.assertRaisesRegex(RuntimeError, "stacktrace:.*"): sim(executable, x, y) + def test_wrong_version(self): + wsize = 1 + config = spu_pb2.RuntimeConfig( + protocol=spu_pb2.ProtocolKind.REF2K, + field=spu_pb2.FieldType.FM64, + ) + + sim = Simulator(wsize, config) + + # Give some insane ir + code = """ +module @no_version attributes {pphlo.version = "0.0.1"} { + func.func @main() -> tensor<1xf32> { + %0 = pphlo.constant dense<[1.0]> : tensor<1xf32> + return %0 : tensor<1xf32> + } +}""" + executable = spu_pb2.ExecutableProto( + name="test", + code=code.encode(), + ) + + with self.assertRaisesRegex(RuntimeError, "IR was generted by compiler.*"): + sim(executable) + if __name__ == '__main__': unittest.main()