-
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.
* to int working (except 8bits version) * pinned blueprint to latest version
- Loading branch information
Showing
18 changed files
with
177 additions
and
65 deletions.
There are no files selected for viewing
Submodule blueprint
updated
4 files
133 changes: 133 additions & 0 deletions
133
mlir-assigner/include/mlir-assigner/components/fixedpoint/conversion.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,133 @@ | ||
#ifndef CRYPTO3_ASSIGNER_FIXEDPOINT_TO_FIXEDPOINT_HPP | ||
#define CRYPTO3_ASSIGNER_FIXEDPOINT_TO_FIXEDPOINT_HPP | ||
|
||
#include "mlir/Dialect/zkml/IR/DotProduct.h" | ||
#include <cstdint> | ||
#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, typename MlirOp> | ||
void handle_to_fixedpoint( | ||
MlirOp &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(MlirOp); | ||
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 detail { | ||
template<typename BlueprintFieldType, typename ArithmetizationParams, typename MlirOp, uint8_t OutputType> | ||
void handle_to_int( | ||
MlirOp &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_to_int< | ||
crypto3::zk::snark::plonk_constraint_system<BlueprintFieldType, ArithmetizationParams>, | ||
BlueprintFieldType, basic_non_native_policy<BlueprintFieldType>>; | ||
typename component_type::OutputType outputType = | ||
static_cast<typename component_type::OutputType>(OutputType); | ||
auto input = PREPARE_UNARY_INPUT(MlirOp); | ||
using manifest_reader = detail::ManifestReader<component_type, ArithmetizationParams, 1, 1, OutputType>; | ||
const auto p = detail::PolicyManager::get_parameters(manifest_reader::get_witness(0)); | ||
|
||
component_type component(p.witness, manifest_reader::get_constants(), | ||
manifest_reader::get_public_inputs(), 1, 1, outputType); | ||
fill_trace(component, input, operation, frame, bp, assignment, start_row); | ||
} | ||
} // namespace detail | ||
|
||
#define HANDLE_TO_INT(TY) \ | ||
detail::handle_to_int<BlueprintFieldType, ArithmetizationParams, mlir::arith::FPToSIOp, TY>( \ | ||
operation, frame, bp, assignment, start_row); | ||
|
||
#define HANDLE_TO_UINT(TY) \ | ||
detail::handle_to_int<BlueprintFieldType, ArithmetizationParams, mlir::arith::FPToUIOp, TY>( \ | ||
operation, frame, bp, assignment, start_row); | ||
template<typename BlueprintFieldType, typename ArithmetizationParams> | ||
void handle_to_int( | ||
mlir::arith::FPToSIOp &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_to_int< | ||
crypto3::zk::snark::plonk_constraint_system<BlueprintFieldType, ArithmetizationParams>, | ||
BlueprintFieldType, basic_non_native_policy<BlueprintFieldType>>; | ||
switch (operation->getResult(0).getType().getIntOrFloatBitWidth()) { | ||
case 8: | ||
HANDLE_TO_INT(component_type::OutputType::I8); | ||
break; | ||
case 16: | ||
HANDLE_TO_INT(component_type::OutputType::I16); | ||
break; | ||
case 32: | ||
HANDLE_TO_INT(component_type::OutputType::I32); | ||
break; | ||
case 64: | ||
HANDLE_TO_INT(component_type::OutputType::I64); | ||
break; | ||
} | ||
} | ||
|
||
template<typename BlueprintFieldType, typename ArithmetizationParams> | ||
void handle_to_int( | ||
mlir::arith::FPToUIOp &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_to_int< | ||
crypto3::zk::snark::plonk_constraint_system<BlueprintFieldType, ArithmetizationParams>, | ||
BlueprintFieldType, basic_non_native_policy<BlueprintFieldType>>; | ||
switch (operation->getResult(0).getType().getIntOrFloatBitWidth()) { | ||
case 8: | ||
HANDLE_TO_UINT(component_type::OutputType::U8); | ||
break; | ||
case 16: | ||
HANDLE_TO_UINT(component_type::OutputType::U16); | ||
break; | ||
case 32: | ||
HANDLE_TO_UINT(component_type::OutputType::U32); | ||
break; | ||
case 64: | ||
HANDLE_TO_UINT(component_type::OutputType::U64); | ||
break; | ||
} | ||
} | ||
|
||
#undef HANDLE_TO_INT | ||
#undef HANDLE_TO_UINT | ||
} // namespace blueprint | ||
} // namespace nil | ||
|
||
#endif // CRYPTO3_ASSIGNER_FIXEDPOINT_TO_FIXEDPOINT_HPP |
44 changes: 0 additions & 44 deletions
44
mlir-assigner/include/mlir-assigner/components/fixedpoint/to_fixpoint.hpp
This file was deleted.
Oops, something went wrong.
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: 0 additions & 1 deletion
1
mlir-assigner/tests/Ops/NeedsBlueprintComponent/Cast/CastToInt64.json
This file was deleted.
Oops, something went wrong.
14 changes: 0 additions & 14 deletions
14
mlir-assigner/tests/Ops/NeedsBlueprintComponent/Cast/CastToInt64.mlir
This file was deleted.
Oops, something went wrong.
3 changes: 0 additions & 3 deletions
3
mlir-assigner/tests/Ops/NeedsBlueprintComponent/Cast/CastToInt64.res
This file was deleted.
Oops, something went wrong.
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": [-4.334595012532761, 92.92536192655963, -83.79716946092812, -47.00000000000001, -58.99999999999999, 68.14344958903294, 97.32986424021, 43.620091845482136, 75.29771234198004, 57.999999999999], "dims": [1, 10], "type": "f32"}}] |
File renamed without changes.
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<1x10xi64>[-4, 92, -83, -47, -58, 68, 97, 43, 75, 57] | ||
12 |
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": [4.000000000000001, 92.92536192655963, 83.79716946092812, 47.67719849791331, 58.17853088366004, 68.14344958903294, 97.32986424021, 43.620091845482136, 75.29771234198004, 57.999999999999], "dims": [1, 10], "type": "f32"}}] |
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 @@ | ||
:_ | ||
in_aout_a"Cast* | ||
to�CastToUInt64Z | ||
in_a | ||
b | ||
out_a | ||
B | ||
|
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<1x10xui64>[4, 92, 83, 47, 58, 68, 97, 43, 75, 57] | ||
12 |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.