Skip to content

Commit

Permalink
batched logup in opcodes
Browse files Browse the repository at this point in the history
  • Loading branch information
ohad-starkware committed Dec 19, 2024
1 parent 7b89d37 commit dc3a595
Show file tree
Hide file tree
Showing 50 changed files with 2,439 additions and 2,569 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ impl Claim {
pub fn log_sizes(&self) -> TreeVec<Vec<u32>> {
let log_size = std::cmp::max(self.n_calls.next_power_of_two().ilog2(), LOG_N_LANES);
let trace_log_sizes = vec![log_size; 10];
let interaction_log_sizes = vec![log_size; SECURE_EXTENSION_DEGREE * 5];
let interaction_log_sizes = vec![log_size; SECURE_EXTENSION_DEGREE * 3];
let preprocessed_log_sizes = vec![log_size];
TreeVec::new(vec![
preprocessed_log_sizes,
Expand Down Expand Up @@ -206,7 +206,7 @@ impl FrameworkEval for Eval {
],
));

eval.finalize_logup();
eval.finalize_logup_in_pairs();
eval
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#![allow(unused_parens)]
#![allow(unused_imports)]
use std::iter::zip;

use air_structs_derive::SubComponentInputs;
use itertools::{chain, zip_eq, Itertools};
use num_traits::{One, Zero};
Expand Down Expand Up @@ -198,7 +200,7 @@ pub fn write_trace_simd(
.unpack(),
);

lookup_data.verify_instruction[0].push([
lookup_data.verify_instruction_0.push([
input_pc_col0,
M31_32767,
M31_32767,
Expand Down Expand Up @@ -231,7 +233,7 @@ pub fn write_trace_simd(
sub_components_inputs.memory_address_to_id_inputs[0]
.extend(((input_ap_col1) + ((offset2_col3) - (M31_32768))).unpack());

lookup_data.memory_address_to_id[0].push([
lookup_data.memory_address_to_id_0.push([
((input_ap_col1) + ((offset2_col3) - (M31_32768))),
op1_id_col4,
]);
Expand All @@ -254,7 +256,7 @@ pub fn write_trace_simd(
trace[9].data[row_index] = op1_limb_2_col9;
sub_components_inputs.memory_id_to_big_inputs[0].extend(op1_id_col4.unpack());

lookup_data.memory_id_to_big[0].push([
lookup_data.memory_id_to_big_0.push([
op1_id_col4,
op1_limb_0_col7,
op1_limb_1_col8,
Expand Down Expand Up @@ -286,8 +288,10 @@ pub fn write_trace_simd(
((msb_col5) * (M31_256)),
]);

lookup_data.opcodes[0].push([input_pc_col0, input_ap_col1, input_fp_col2]);
lookup_data.opcodes[1].push([
lookup_data
.opcodes_0
.push([input_pc_col0, input_ap_col1, input_fp_col2]);
lookup_data.opcodes_1.push([
((input_pc_col0) + (M31_1)),
((input_ap_col1)
+ (((((op1_limb_0_col7) + ((op1_limb_1_col8) * (M31_512)))
Expand All @@ -303,19 +307,21 @@ pub fn write_trace_simd(
}

pub struct LookupData {
pub memory_address_to_id: [Vec<[PackedM31; 2]>; 1],
pub memory_id_to_big: [Vec<[PackedM31; 29]>; 1],
pub opcodes: [Vec<[PackedM31; 3]>; 2],
pub verify_instruction: [Vec<[PackedM31; 19]>; 1],
memory_address_to_id_0: Vec<[PackedM31; 2]>,
memory_id_to_big_0: Vec<[PackedM31; 29]>,
opcodes_0: Vec<[PackedM31; 3]>,
opcodes_1: Vec<[PackedM31; 3]>,
verify_instruction_0: Vec<[PackedM31; 19]>,
}
impl LookupData {
#[allow(unused_variables)]
fn with_capacity(capacity: usize) -> Self {
Self {
memory_address_to_id: [Vec::with_capacity(capacity)],
memory_id_to_big: [Vec::with_capacity(capacity)],
opcodes: [Vec::with_capacity(capacity), Vec::with_capacity(capacity)],
verify_instruction: [Vec::with_capacity(capacity)],
memory_address_to_id_0: Vec::with_capacity(capacity),
memory_id_to_big_0: Vec::with_capacity(capacity),
opcodes_0: Vec::with_capacity(capacity),
opcodes_1: Vec::with_capacity(capacity),
verify_instruction_0: Vec::with_capacity(capacity),
}
}
}
Expand All @@ -328,10 +334,10 @@ impl InteractionClaimGenerator {
pub fn write_interaction_trace<MC: MerkleChannel>(
self,
tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, MC>,
memory_address_to_id_lookup_elements: &relations::MemoryAddressToId,
memory_id_to_big_lookup_elements: &relations::MemoryIdToBig,
opcodes_lookup_elements: &relations::Opcodes,
verify_instruction_lookup_elements: &relations::VerifyInstruction,
memory_address_to_id: &relations::MemoryAddressToId,
memory_id_to_big: &relations::MemoryIdToBig,
opcodes: &relations::Opcodes,
verify_instruction: &relations::VerifyInstruction,
) -> InteractionClaim
where
SimdBackend: BackendForChannel<MC>,
Expand All @@ -340,42 +346,35 @@ impl InteractionClaimGenerator {
let mut logup_gen = LogupTraceGenerator::new(log_size);

let mut col_gen = logup_gen.new_col();
let lookup_row = &self.lookup_data.verify_instruction[0];
for (i, lookup_values) in lookup_row.iter().enumerate() {
let denom = verify_instruction_lookup_elements.combine(lookup_values);
col_gen.write_frac(i, PackedQM31::one(), denom);
}
col_gen.finalize_col();

let mut col_gen = logup_gen.new_col();
let lookup_row = &self.lookup_data.memory_address_to_id[0];
for (i, lookup_values) in lookup_row.iter().enumerate() {
let denom = memory_address_to_id_lookup_elements.combine(lookup_values);
col_gen.write_frac(i, PackedQM31::one(), denom);
}
col_gen.finalize_col();

let mut col_gen = logup_gen.new_col();
let lookup_row = &self.lookup_data.memory_id_to_big[0];
for (i, lookup_values) in lookup_row.iter().enumerate() {
let denom = memory_id_to_big_lookup_elements.combine(lookup_values);
col_gen.write_frac(i, PackedQM31::one(), denom);
for (i, (v0, v1)) in zip(
&self.lookup_data.verify_instruction_0,
&self.lookup_data.memory_address_to_id_0,
)
.enumerate()
{
let p0: PackedQM31 = verify_instruction.combine(v0);
let p1: PackedQM31 = memory_address_to_id.combine(v1);
col_gen.write_frac(i, p0 + p1, p0 * p1);
}
col_gen.finalize_col();

let mut col_gen = logup_gen.new_col();
let lookup_row = &self.lookup_data.opcodes[0];
for (i, lookup_values) in lookup_row.iter().enumerate() {
let denom = opcodes_lookup_elements.combine(lookup_values);
col_gen.write_frac(i, PackedQM31::one(), denom);
for (i, (v0, v1)) in zip(
&self.lookup_data.memory_id_to_big_0,
&self.lookup_data.opcodes_0,
)
.enumerate()
{
let p0: PackedQM31 = memory_id_to_big.combine(v0);
let p1: PackedQM31 = opcodes.combine(v1);
col_gen.write_frac(i, p0 + p1, p0 * p1);
}
col_gen.finalize_col();

let mut col_gen = logup_gen.new_col();
let lookup_row = &self.lookup_data.opcodes[1];
for (i, lookup_values) in lookup_row.iter().enumerate() {
let denom = opcodes_lookup_elements.combine(lookup_values);
col_gen.write_frac(i, -PackedQM31::one(), denom);
for (i, v0) in self.lookup_data.opcodes_1.iter().enumerate() {
let p0 = opcodes.combine(v0);
col_gen.write_frac(i, -PackedQM31::one(), p0);
}
col_gen.finalize_col();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ impl Claim {
pub fn log_sizes(&self) -> TreeVec<Vec<u32>> {
let log_size = std::cmp::max(self.n_calls.next_power_of_two().ilog2(), LOG_N_LANES);
let trace_log_sizes = vec![log_size; 10];
let interaction_log_sizes = vec![log_size; SECURE_EXTENSION_DEGREE * 5];
let interaction_log_sizes = vec![log_size; SECURE_EXTENSION_DEGREE * 3];
let preprocessed_log_sizes = vec![log_size];
TreeVec::new(vec![
preprocessed_log_sizes,
Expand Down Expand Up @@ -206,7 +206,7 @@ impl FrameworkEval for Eval {
],
));

eval.finalize_logup();
eval.finalize_logup_in_pairs();
eval
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#![allow(unused_parens)]
#![allow(unused_imports)]
use std::iter::zip;

use air_structs_derive::SubComponentInputs;
use itertools::{chain, zip_eq, Itertools};
use num_traits::{One, Zero};
Expand Down Expand Up @@ -198,7 +200,7 @@ pub fn write_trace_simd(
.unpack(),
);

lookup_data.verify_instruction[0].push([
lookup_data.verify_instruction_0.push([
input_pc_col0,
M31_32767,
M31_32767,
Expand Down Expand Up @@ -231,7 +233,7 @@ pub fn write_trace_simd(
sub_components_inputs.memory_address_to_id_inputs[0]
.extend(((input_fp_col2) + ((offset2_col3) - (M31_32768))).unpack());

lookup_data.memory_address_to_id[0].push([
lookup_data.memory_address_to_id_0.push([
((input_fp_col2) + ((offset2_col3) - (M31_32768))),
op1_id_col4,
]);
Expand All @@ -254,7 +256,7 @@ pub fn write_trace_simd(
trace[9].data[row_index] = op1_limb_2_col9;
sub_components_inputs.memory_id_to_big_inputs[0].extend(op1_id_col4.unpack());

lookup_data.memory_id_to_big[0].push([
lookup_data.memory_id_to_big_0.push([
op1_id_col4,
op1_limb_0_col7,
op1_limb_1_col8,
Expand Down Expand Up @@ -286,8 +288,10 @@ pub fn write_trace_simd(
((msb_col5) * (M31_256)),
]);

lookup_data.opcodes[0].push([input_pc_col0, input_ap_col1, input_fp_col2]);
lookup_data.opcodes[1].push([
lookup_data
.opcodes_0
.push([input_pc_col0, input_ap_col1, input_fp_col2]);
lookup_data.opcodes_1.push([
((input_pc_col0) + (M31_1)),
((input_ap_col1)
+ (((((op1_limb_0_col7) + ((op1_limb_1_col8) * (M31_512)))
Expand All @@ -303,19 +307,21 @@ pub fn write_trace_simd(
}

pub struct LookupData {
pub memory_address_to_id: [Vec<[PackedM31; 2]>; 1],
pub memory_id_to_big: [Vec<[PackedM31; 29]>; 1],
pub opcodes: [Vec<[PackedM31; 3]>; 2],
pub verify_instruction: [Vec<[PackedM31; 19]>; 1],
memory_address_to_id_0: Vec<[PackedM31; 2]>,
memory_id_to_big_0: Vec<[PackedM31; 29]>,
opcodes_0: Vec<[PackedM31; 3]>,
opcodes_1: Vec<[PackedM31; 3]>,
verify_instruction_0: Vec<[PackedM31; 19]>,
}
impl LookupData {
#[allow(unused_variables)]
fn with_capacity(capacity: usize) -> Self {
Self {
memory_address_to_id: [Vec::with_capacity(capacity)],
memory_id_to_big: [Vec::with_capacity(capacity)],
opcodes: [Vec::with_capacity(capacity), Vec::with_capacity(capacity)],
verify_instruction: [Vec::with_capacity(capacity)],
memory_address_to_id_0: Vec::with_capacity(capacity),
memory_id_to_big_0: Vec::with_capacity(capacity),
opcodes_0: Vec::with_capacity(capacity),
opcodes_1: Vec::with_capacity(capacity),
verify_instruction_0: Vec::with_capacity(capacity),
}
}
}
Expand All @@ -328,10 +334,10 @@ impl InteractionClaimGenerator {
pub fn write_interaction_trace<MC: MerkleChannel>(
self,
tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, MC>,
memory_address_to_id_lookup_elements: &relations::MemoryAddressToId,
memory_id_to_big_lookup_elements: &relations::MemoryIdToBig,
opcodes_lookup_elements: &relations::Opcodes,
verify_instruction_lookup_elements: &relations::VerifyInstruction,
memory_address_to_id: &relations::MemoryAddressToId,
memory_id_to_big: &relations::MemoryIdToBig,
opcodes: &relations::Opcodes,
verify_instruction: &relations::VerifyInstruction,
) -> InteractionClaim
where
SimdBackend: BackendForChannel<MC>,
Expand All @@ -340,42 +346,35 @@ impl InteractionClaimGenerator {
let mut logup_gen = LogupTraceGenerator::new(log_size);

let mut col_gen = logup_gen.new_col();
let lookup_row = &self.lookup_data.verify_instruction[0];
for (i, lookup_values) in lookup_row.iter().enumerate() {
let denom = verify_instruction_lookup_elements.combine(lookup_values);
col_gen.write_frac(i, PackedQM31::one(), denom);
}
col_gen.finalize_col();

let mut col_gen = logup_gen.new_col();
let lookup_row = &self.lookup_data.memory_address_to_id[0];
for (i, lookup_values) in lookup_row.iter().enumerate() {
let denom = memory_address_to_id_lookup_elements.combine(lookup_values);
col_gen.write_frac(i, PackedQM31::one(), denom);
}
col_gen.finalize_col();

let mut col_gen = logup_gen.new_col();
let lookup_row = &self.lookup_data.memory_id_to_big[0];
for (i, lookup_values) in lookup_row.iter().enumerate() {
let denom = memory_id_to_big_lookup_elements.combine(lookup_values);
col_gen.write_frac(i, PackedQM31::one(), denom);
for (i, (v0, v1)) in zip(
&self.lookup_data.verify_instruction_0,
&self.lookup_data.memory_address_to_id_0,
)
.enumerate()
{
let p0: PackedQM31 = verify_instruction.combine(v0);
let p1: PackedQM31 = memory_address_to_id.combine(v1);
col_gen.write_frac(i, p0 + p1, p0 * p1);
}
col_gen.finalize_col();

let mut col_gen = logup_gen.new_col();
let lookup_row = &self.lookup_data.opcodes[0];
for (i, lookup_values) in lookup_row.iter().enumerate() {
let denom = opcodes_lookup_elements.combine(lookup_values);
col_gen.write_frac(i, PackedQM31::one(), denom);
for (i, (v0, v1)) in zip(
&self.lookup_data.memory_id_to_big_0,
&self.lookup_data.opcodes_0,
)
.enumerate()
{
let p0: PackedQM31 = memory_id_to_big.combine(v0);
let p1: PackedQM31 = opcodes.combine(v1);
col_gen.write_frac(i, p0 + p1, p0 * p1);
}
col_gen.finalize_col();

let mut col_gen = logup_gen.new_col();
let lookup_row = &self.lookup_data.opcodes[1];
for (i, lookup_values) in lookup_row.iter().enumerate() {
let denom = opcodes_lookup_elements.combine(lookup_values);
col_gen.write_frac(i, -PackedQM31::one(), denom);
for (i, v0) in self.lookup_data.opcodes_1.iter().enumerate() {
let p0 = opcodes.combine(v0);
col_gen.write_frac(i, -PackedQM31::one(), p0);
}
col_gen.finalize_col();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ impl Claim {
pub fn log_sizes(&self) -> TreeVec<Vec<u32>> {
let log_size = std::cmp::max(self.n_calls.next_power_of_two().ilog2(), LOG_N_LANES);
let trace_log_sizes = vec![log_size; 9];
let interaction_log_sizes = vec![log_size; SECURE_EXTENSION_DEGREE * 5];
let interaction_log_sizes = vec![log_size; SECURE_EXTENSION_DEGREE * 3];
let preprocessed_log_sizes = vec![log_size];
TreeVec::new(vec![
preprocessed_log_sizes,
Expand Down Expand Up @@ -203,7 +203,7 @@ impl FrameworkEval for Eval {
],
));

eval.finalize_logup();
eval.finalize_logup_in_pairs();
eval
}
}
Loading

0 comments on commit dc3a595

Please sign in to comment.