diff --git a/libs/blueprint b/libs/blueprint index e623116..8c8ef7c 160000 --- a/libs/blueprint +++ b/libs/blueprint @@ -1 +1 @@ -Subproject commit e62311622e1ead03fb053c01623dcf22431f4ab8 +Subproject commit 8c8ef7c89d6a5cd3a367809a86161afa6964148c diff --git a/mlir-assigner/include/mlir-assigner/components/fixedpoint/trigonometric.hpp b/mlir-assigner/include/mlir-assigner/components/fixedpoint/trigonometric.hpp index f664b84..71ceabc 100644 --- a/mlir-assigner/include/mlir-assigner/components/fixedpoint/trigonometric.hpp +++ b/mlir-assigner/include/mlir-assigner/components/fixedpoint/trigonometric.hpp @@ -59,6 +59,28 @@ namespace nil { 1, 1); fill_trace(component, input, operation, frame, bp, assignment, start_row); } + + template + void handle_tan( + mlir::KrnlTanOp &operation, + stack_frame> &frame, + circuit_proxy> &bp, + assignment_proxy> + &assignment, + std::uint32_t start_row) { + using component_type = components::fix_tan< + crypto3::zk::snark::plonk_constraint_system, + BlueprintFieldType, basic_non_native_policy>; + + auto input = PREPARE_UNARY_INPUT(mlir::KrnlTanOp); + using manifest_reader = detail::ManifestReader; + const auto p = detail::PolicyManager::get_parameters( + detail::ManifestReader::get_witness(0, 1, 1)); + + component_type component(p.witness, manifest_reader::get_constants(), manifest_reader::get_public_inputs(), + 1, 1); + fill_trace(component, input, operation, frame, bp, assignment, start_row); + } template void handle_tanh( mlir::math::TanhOp &operation, diff --git a/mlir-assigner/include/mlir-assigner/components/handle_component.hpp b/mlir-assigner/include/mlir-assigner/components/handle_component.hpp index 39bbd9f..d38c0b2 100644 --- a/mlir-assigner/include/mlir-assigner/components/handle_component.hpp +++ b/mlir-assigner/include/mlir-assigner/components/handle_component.hpp @@ -31,6 +31,7 @@ #include #include #include +#include #include #include #include diff --git a/mlir-assigner/include/mlir-assigner/parser/evaluator.hpp b/mlir-assigner/include/mlir-assigner/parser/evaluator.hpp index ab0ed2c..069e33f 100644 --- a/mlir-assigner/include/mlir-assigner/parser/evaluator.hpp +++ b/mlir-assigner/include/mlir-assigner/parser/evaluator.hpp @@ -669,6 +669,7 @@ namespace zk_ml_toolchain { void handleKrnlOpeeration(Operation *op) { // Print the operation itself and some of its properties // Print the operation attributes + std::uint32_t start_row = assignmnt.allocated_rows(); std::string opName = op->getName().getIdentifier().str(); logger.debug("visiting %s", opName); if (KrnlGlobalOp operation = llvm::dyn_cast(op)) { @@ -807,7 +808,7 @@ namespace zk_ml_toolchain { } else if (KrnlAsinhOp operation = llvm::dyn_cast(op)) { UNREACHABLE(std::string("TODO KrnlSinh: link to bluebrint component")); } else if (KrnlTanOp operation = llvm::dyn_cast(op)) { - UNREACHABLE("TODO: component for tan not ready"); + handle_tan(operation, frames.back(), bp, assignmnt, start_row); } else if (KrnlAtanOp operation = llvm::dyn_cast(op)) { UNREACHABLE("TODO: component for atan not ready"); } else if (KrnlAtanhOp operation = llvm::dyn_cast(op)) { diff --git a/mlir-assigner/tests/Ops/NeedsBlueprintComponent/Tan/TanSimple.mlir b/mlir-assigner/tests/Ops/NeedsBlueprintComponent/Tan/TanSimple.mlir deleted file mode 100644 index dad340f..0000000 --- a/mlir-assigner/tests/Ops/NeedsBlueprintComponent/Tan/TanSimple.mlir +++ /dev/null @@ -1,14 +0,0 @@ -module attributes {llvm.data_layout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128", llvm.target_triple = "x86_64-pc-linux-gnu", "onnx-mlir.symbol-postfix" = "tansimple.mlir"} { - func.func @main_graph(%arg0: memref<1x10xf32>) -> memref<1x10xf32> attributes {input_names = ["in_a"], llvm.emit_c_interface, output_names = ["out_a"]} { - %alloc = memref.alloc() {alignment = 16 : i64} : memref<1x10xf32> - affine.for %arg1 = 0 to 1 { - affine.for %arg2 = 0 to 10 { - %0 = affine.load %arg0[%arg1, %arg2] : memref<1x10xf32> - %1 = "krnl.tan"(%0) : (f32) -> f32 - affine.store %1, %alloc[%arg1, %arg2] : memref<1x10xf32> - } - } - return %alloc : memref<1x10xf32> - } - "krnl.entry_point"() {func = @main_graph, numInputs = 1 : i32, numOutputs = 1 : i32, signature = "[ { \22type\22 : \22f32\22 , \22dims\22 : [1 , 10] , \22name\22 : \22in_a\22 }\0A\0A]\00@[ { \22type\22 : \22f32\22 , \22dims\22 : [1 , 10] , \22name\22 : \22out_a\22 }\0A\0A]\00"} : () -> () -} diff --git a/mlir-assigner/tests/Ops/NeedsBlueprintComponent/Tan/TanSimple.json b/mlir-assigner/tests/Ops/Onnx/Tan/TanSimple.json similarity index 100% rename from mlir-assigner/tests/Ops/NeedsBlueprintComponent/Tan/TanSimple.json rename to mlir-assigner/tests/Ops/Onnx/Tan/TanSimple.json diff --git a/mlir-assigner/tests/Ops/NeedsBlueprintComponent/Tan/TanSimple.onnx b/mlir-assigner/tests/Ops/Onnx/Tan/TanSimple.onnx similarity index 100% rename from mlir-assigner/tests/Ops/NeedsBlueprintComponent/Tan/TanSimple.onnx rename to mlir-assigner/tests/Ops/Onnx/Tan/TanSimple.onnx diff --git a/mlir-assigner/tests/Ops/NeedsBlueprintComponent/Tan/TanSimple.res b/mlir-assigner/tests/Ops/Onnx/Tan/TanSimple.res similarity index 93% rename from mlir-assigner/tests/Ops/NeedsBlueprintComponent/Tan/TanSimple.res rename to mlir-assigner/tests/Ops/Onnx/Tan/TanSimple.res index 4c2e324..bb58e8a 100644 --- a/mlir-assigner/tests/Ops/NeedsBlueprintComponent/Tan/TanSimple.res +++ b/mlir-assigner/tests/Ops/Onnx/Tan/TanSimple.res @@ -1,3 +1,3 @@ Result: memref<1x10xf32>[0.21356424689292908, 0.43476253747940063, 0.9388334155082703, 1.4897156953811646, 0.5585304498672485, 0.6736464500427246, 1.0364264249801636, 0.7319538593292236, 0.01287913043051958, 0.3991353213787079] -ADD THE ROWS HERE \ No newline at end of file +20 diff --git a/mlir-assigner/tests/Ops/Onnx/zkml-onnx-compiler b/mlir-assigner/tests/Ops/Onnx/zkml-onnx-compiler new file mode 100755 index 0000000..692ea8b Binary files /dev/null and b/mlir-assigner/tests/Ops/Onnx/zkml-onnx-compiler differ