Skip to content

Commit

Permalink
feat: added tan component and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
0xThemis committed Jan 9, 2024
1 parent ff582cd commit 640bc38
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,28 @@ namespace nil {
1, 1);
fill_trace(component, input, operation, frame, bp, assignment, start_row);
}

template<typename BlueprintFieldType, typename ArithmetizationParams>
void handle_tan(
mlir::KrnlTanOp &operation,
stack_frame<crypto3::zk::snark::plonk_variable<typename BlueprintFieldType::value_type>> &frame,
circuit_proxy<crypto3::zk::snark::plonk_constraint_system<BlueprintFieldType, ArithmetizationParams>> &bp,
assignment_proxy<crypto3::zk::snark::plonk_constraint_system<BlueprintFieldType, ArithmetizationParams>>
&assignment,
std::uint32_t start_row) {
using component_type = components::fix_tan<
crypto3::zk::snark::plonk_constraint_system<BlueprintFieldType, ArithmetizationParams>,
BlueprintFieldType, basic_non_native_policy<BlueprintFieldType>>;

auto input = PREPARE_UNARY_INPUT(mlir::KrnlTanOp);
using manifest_reader = detail::ManifestReader<component_type, ArithmetizationParams, 1, 1>;
const auto p = detail::PolicyManager::get_parameters(
detail::ManifestReader<component_type, ArithmetizationParams, 1, 1>::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<typename BlueprintFieldType, typename ArithmetizationParams>
void handle_tanh(
mlir::math::TanhOp &operation,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include <nil/blueprint/components/algebra/fixedpoint/plonk/to_fixedpoint.hpp>
#include <nil/blueprint/components/algebra/fixedpoint/plonk/sin.hpp>
#include <nil/blueprint/components/algebra/fixedpoint/plonk/cos.hpp>
#include <nil/blueprint/components/algebra/fixedpoint/plonk/tan.hpp>
#include <nil/blueprint/components/algebra/fixedpoint/plonk/tanh.hpp>
#include <nil/blueprint/components/algebra/fixedpoint/plonk/argmin.hpp>
#include <nil/blueprint/components/algebra/fixedpoint/plonk/argmax.hpp>
Expand Down
3 changes: 2 additions & 1 deletion mlir-assigner/include/mlir-assigner/parser/evaluator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<KrnlGlobalOp>(op)) {
Expand Down Expand Up @@ -807,7 +808,7 @@ namespace zk_ml_toolchain {
} else if (KrnlAsinhOp operation = llvm::dyn_cast<KrnlAsinhOp>(op)) {
UNREACHABLE(std::string("TODO KrnlSinh: link to bluebrint component"));
} else if (KrnlTanOp operation = llvm::dyn_cast<KrnlTanOp>(op)) {
UNREACHABLE("TODO: component for tan not ready");
handle_tan(operation, frames.back(), bp, assignmnt, start_row);
} else if (KrnlAtanOp operation = llvm::dyn_cast<KrnlAtanOp>(op)) {
UNREACHABLE("TODO: component for atan not ready");
} else if (KrnlAtanhOp operation = llvm::dyn_cast<KrnlAtanhOp>(op)) {
Expand Down
14 changes: 0 additions & 14 deletions mlir-assigner/tests/Ops/NeedsBlueprintComponent/Tan/TanSimple.mlir

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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
20
Binary file added mlir-assigner/tests/Ops/Onnx/zkml-onnx-compiler
Binary file not shown.

0 comments on commit 640bc38

Please sign in to comment.