-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* added AveragePool; int to fix no range check * added sin,sinh,cos,cosh * rest of trigonometric tests
- Loading branch information
Showing
53 changed files
with
510 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
mlir-assigner/include/mlir-assigner/components/fixedpoint/to_fixpoint.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#ifndef CRYPTO3_ASSIGNER_FIXEDPOINT_TO_FIXEDPOINT_HPP | ||
#define CRYPTO3_ASSIGNER_FIXEDPOINT_TO_FIXEDPOINT_HPP | ||
|
||
#include "mlir/Dialect/zkml/IR/DotProduct.h" | ||
#include <mlir/Dialect/Arith/IR/Arith.h> | ||
|
||
#include <nil/crypto3/zk/snark/arithmetization/plonk/constraint_system.hpp> | ||
|
||
#include <nil/blueprint/component.hpp> | ||
#include <nil/blueprint/basic_non_native_policy.hpp> | ||
#include <nil/blueprint/components/algebra/fixedpoint/lookup_tables/tester.hpp> // TODO: check if there is a new mechanism for this in nil upstream | ||
|
||
#include <mlir-assigner/helper/asserts.hpp> | ||
#include <mlir-assigner/memory/stack_frame.hpp> | ||
#include <mlir-assigner/components/handle_component.hpp> | ||
|
||
namespace nil { | ||
namespace blueprint { | ||
|
||
template<typename BlueprintFieldType, typename ArithmetizationParams> | ||
void handle_to_fixedpoint( | ||
mlir::arith::SIToFPOp &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::int_to_fix< | ||
crypto3::zk::snark::plonk_constraint_system<BlueprintFieldType, ArithmetizationParams>, | ||
BlueprintFieldType, basic_non_native_policy<BlueprintFieldType>>; | ||
|
||
auto input = PREPARE_UNARY_INPUT(mlir::arith::SIToFPOp); | ||
using manifest_reader = detail::ManifestReader<component_type, ArithmetizationParams, 1, 1>; | ||
const auto p = detail::PolicyManager::get_parameters( | ||
detail::ManifestReader<component_type, ArithmetizationParams>::get_witness(0)); | ||
|
||
component_type component(p.witness, manifest_reader::get_constants(), manifest_reader::get_public_inputs(), | ||
1); | ||
fill_trace(component, input, operation, frame, bp, assignment, start_row); | ||
} | ||
} // namespace blueprint | ||
} // namespace nil | ||
|
||
#endif // CRYPTO3_ASSIGNER_FIXEDPOINT_TO_FIXEDPOINT_HPP |
65 changes: 65 additions & 0 deletions
65
mlir-assigner/include/mlir-assigner/components/fixedpoint/trigonometric.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
#ifndef CRYPTO3_ASSIGNER_FIXEDPOINT_TRIGONOMETRIC_HPP | ||
#define CRYPTO3_ASSIGNER_FIXEDPOINT_TRIGONOMETRIC_HPP | ||
|
||
#include "mlir/Dialect/zkml/IR/DotProduct.h" | ||
#include <mlir/Dialect/Arith/IR/Arith.h> | ||
|
||
#include <nil/crypto3/zk/snark/arithmetization/plonk/constraint_system.hpp> | ||
|
||
#include <nil/blueprint/component.hpp> | ||
#include <nil/blueprint/basic_non_native_policy.hpp> | ||
#include <nil/blueprint/components/algebra/fixedpoint/lookup_tables/tester.hpp> // TODO: check if there is a new mechanism for this in nil upstream | ||
|
||
#include <mlir-assigner/helper/asserts.hpp> | ||
#include <mlir-assigner/memory/stack_frame.hpp> | ||
#include <mlir-assigner/components/handle_component.hpp> | ||
|
||
namespace nil { | ||
namespace blueprint { | ||
|
||
template<typename BlueprintFieldType, typename ArithmetizationParams> | ||
void handle_sin( | ||
mlir::math::SinOp &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_sin< | ||
crypto3::zk::snark::plonk_constraint_system<BlueprintFieldType, ArithmetizationParams>, | ||
BlueprintFieldType, basic_non_native_policy<BlueprintFieldType>>; | ||
|
||
auto input = PREPARE_UNARY_INPUT(mlir::math::SinOp); | ||
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_cos( | ||
mlir::math::CosOp &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_cos< | ||
crypto3::zk::snark::plonk_constraint_system<BlueprintFieldType, ArithmetizationParams>, | ||
BlueprintFieldType, basic_non_native_policy<BlueprintFieldType>>; | ||
|
||
auto input = PREPARE_UNARY_INPUT(mlir::math::CosOp); | ||
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); | ||
} | ||
} // namespace blueprint | ||
} // namespace nil | ||
|
||
#endif // CRYPTO3_ASSIGNER_FIXEDPOINT_TRIGONOMETRIC_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
mlir-assigner/tests/Ops/NeedsBlueprintComponent/Acos/AcosSimple.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
[{"memref": {"data": [0.6515045166015625, 0.259490966796875, 0.200439453125, 0.084564208984375, 0.223297119140625, 0.867034912109375, 0.0014801025390625, 0.4618377685546875, 0.059051513671875, 0.2735137939453125], "dims": [1, 10], "type": "f32"}}] |
14 changes: 14 additions & 0 deletions
14
mlir-assigner/tests/Ops/NeedsBlueprintComponent/Acos/AcosSimple.mlir
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
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" = "acossimple.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.acos"(%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"} : () -> () | ||
} |
14 changes: 14 additions & 0 deletions
14
mlir-assigner/tests/Ops/NeedsBlueprintComponent/Acos/AcosSimple.onnx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
:R | ||
in_aout_a"Acos | ||
AcosSimpleZ | ||
in_a | ||
b | ||
out_a | ||
B |
3 changes: 3 additions & 0 deletions
3
mlir-assigner/tests/Ops/NeedsBlueprintComponent/Acos/AcosSimple.res
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Result: | ||
memref<1x10xf32>[0.8612304329872131, 1.3083012104034424, 1.3689898252487183, 1.486130952835083, 1.3456006050109863, 0.5215762257575989, 1.5693162679672241, 1.0907303094863892, 1.5117104053497314, 1.2937520742416382] | ||
ADD THE ROWS HERE |
1 change: 1 addition & 0 deletions
1
mlir-assigner/tests/Ops/NeedsBlueprintComponent/Acosh/AcoshSimple.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
[{"memref": {"data": [0.5222625732421875, 0.6072845458984375, 0.3314361572265625, 0.698211669921875, 0.192108154296875, 0.699432373046875, 0.5330963134765625, 0.62982177734375, 0.908538818359375, 0.012664794921875], "dims": [1, 10], "type": "f32"}}] |
14 changes: 14 additions & 0 deletions
14
mlir-assigner/tests/Ops/NeedsBlueprintComponent/Acosh/AcoshSimple.mlir
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
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" = "acoshsimple.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.acosh"(%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"} : () -> () | ||
} |
13 changes: 13 additions & 0 deletions
13
mlir-assigner/tests/Ops/NeedsBlueprintComponent/Acosh/AcoshSimple.onnx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
:T | ||
in_aout_a"AcoshAcoshSimpleZ | ||
in_a | ||
b | ||
out_a | ||
B |
3 changes: 3 additions & 0 deletions
3
mlir-assigner/tests/Ops/NeedsBlueprintComponent/Acosh/AcoshSimple.res
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Result: | ||
memref<1x10xf32>['-nan', '-nan', '-nan', '-nan', '-nan', '-nan', '-nan', '-nan', '-nan', '-nan'] | ||
ADD THE ROWS HERE |
Oops, something went wrong.