|
| 1 | +#include "launcher.cuh" |
| 2 | +#include "native/sumcheck.cuh" |
| 3 | +#include "native/utils.cuh" |
| 4 | +#include "primitives/trace_access.h" |
| 5 | +#include "system/memory/controller.cuh" |
| 6 | + |
| 7 | +using namespace native; |
| 8 | + |
| 9 | +__device__ void fill_sumcheck_specific(RowSlice row, MemoryAuxColsFactory &mem_helper) { |
| 10 | + RowSlice specific = row.slice_from(COL_INDEX(NativeSumcheckCols, specific)); |
| 11 | + uint32_t start_timestamp = row[COL_INDEX(NativeSumcheckCols, start_timestamp)].asUInt32(); |
| 12 | + |
| 13 | + if (row[COL_INDEX(NativeSumcheckCols, header_row)] == Fp::one()) { |
| 14 | + for (uint32_t i = 0; i < 7; ++i) { |
| 15 | + mem_fill_base( |
| 16 | + mem_helper, |
| 17 | + start_timestamp + i, |
| 18 | + specific.slice_from(COL_INDEX(HeaderSpecificCols, read_records[i].base)) |
| 19 | + ); |
| 20 | + } |
| 21 | + uint32_t last_timestamp = row[COL_INDEX(NativeSumcheckCols, last_timestamp)].asUInt32(); |
| 22 | + mem_fill_base( |
| 23 | + mem_helper, |
| 24 | + last_timestamp - 1, |
| 25 | + specific.slice_from(COL_INDEX(HeaderSpecificCols, write_records.base)) |
| 26 | + ); |
| 27 | + } else if (row[COL_INDEX(NativeSumcheckCols, prod_row)] == Fp::one()) { |
| 28 | + mem_fill_base( |
| 29 | + mem_helper, |
| 30 | + start_timestamp, |
| 31 | + specific.slice_from(COL_INDEX(ProdSpecificCols, read_records[0].base)) |
| 32 | + ); |
| 33 | + if (row[COL_INDEX(NativeSumcheckCols, within_round_limit)] == Fp::one()) { |
| 34 | + mem_fill_base( |
| 35 | + mem_helper, |
| 36 | + start_timestamp + 1, |
| 37 | + specific.slice_from(COL_INDEX(ProdSpecificCols, read_records[1].base)) |
| 38 | + ); |
| 39 | + mem_fill_base( |
| 40 | + mem_helper, |
| 41 | + start_timestamp + 2, |
| 42 | + specific.slice_from(COL_INDEX(ProdSpecificCols, write_record.base)) |
| 43 | + ); |
| 44 | + } |
| 45 | + } else if (row[COL_INDEX(NativeSumcheckCols, logup_row)] == Fp::one()) { |
| 46 | + mem_fill_base( |
| 47 | + mem_helper, |
| 48 | + start_timestamp, |
| 49 | + specific.slice_from(COL_INDEX(LogupSpecificCols, read_records[0].base)) |
| 50 | + ); |
| 51 | + if (row[COL_INDEX(NativeSumcheckCols, within_round_limit)] == Fp::one()) { |
| 52 | + mem_fill_base( |
| 53 | + mem_helper, |
| 54 | + start_timestamp + 1, |
| 55 | + specific.slice_from(COL_INDEX(LogupSpecificCols, read_records[1].base)) |
| 56 | + ); |
| 57 | + mem_fill_base( |
| 58 | + mem_helper, |
| 59 | + start_timestamp + 2, |
| 60 | + specific.slice_from(COL_INDEX(LogupSpecificCols, write_records[0].base)) |
| 61 | + ); |
| 62 | + mem_fill_base( |
| 63 | + mem_helper, |
| 64 | + start_timestamp + 3, |
| 65 | + specific.slice_from(COL_INDEX(LogupSpecificCols, write_records[1].base)) |
| 66 | + ); |
| 67 | + } |
| 68 | + } |
| 69 | +} |
| 70 | + |
| 71 | +__global__ void native_sumcheck_tracegen( |
| 72 | + Fp *trace, |
| 73 | + size_t height, |
| 74 | + size_t width, |
| 75 | + const Fp *records, |
| 76 | + size_t rows_used, |
| 77 | + uint32_t *range_checker_ptr, |
| 78 | + uint32_t range_checker_num_bins, |
| 79 | + uint32_t timestamp_max_bits |
| 80 | +) { |
| 81 | + uint32_t idx = blockIdx.x * blockDim.x + threadIdx.x; |
| 82 | + if (idx >= height) { |
| 83 | + return; |
| 84 | + } |
| 85 | + |
| 86 | + RowSlice row(trace + idx, height); |
| 87 | + if (idx < rows_used) { |
| 88 | + const Fp *record = records + idx * width; |
| 89 | + for (uint32_t col = 0; col < width; ++col) { |
| 90 | + row[col] = record[col]; |
| 91 | + } |
| 92 | + MemoryAuxColsFactory mem_helper( |
| 93 | + VariableRangeChecker(range_checker_ptr, range_checker_num_bins), timestamp_max_bits |
| 94 | + ); |
| 95 | + fill_sumcheck_specific(row, mem_helper); |
| 96 | + } else { |
| 97 | + row.fill_zero(0, width); |
| 98 | + COL_WRITE_VALUE(row, NativeSumcheckCols, is_end, Fp::one()); |
| 99 | + } |
| 100 | +} |
| 101 | + |
| 102 | +extern "C" int _native_sumcheck_tracegen( |
| 103 | + Fp *d_trace, |
| 104 | + size_t height, |
| 105 | + size_t width, |
| 106 | + const Fp *d_records, |
| 107 | + size_t rows_used, |
| 108 | + uint32_t *d_range_checker, |
| 109 | + uint32_t range_checker_num_bins, |
| 110 | + uint32_t timestamp_max_bits |
| 111 | +) { |
| 112 | + assert((height & (height - 1)) == 0); |
| 113 | + assert(width == sizeof(NativeSumcheckCols<uint8_t>)); |
| 114 | + auto [grid, block] = kernel_launch_params(height); |
| 115 | + native_sumcheck_tracegen<<<grid, block>>>( |
| 116 | + d_trace, |
| 117 | + height, |
| 118 | + width, |
| 119 | + d_records, |
| 120 | + rows_used, |
| 121 | + d_range_checker, |
| 122 | + range_checker_num_bins, |
| 123 | + timestamp_max_bits |
| 124 | + ); |
| 125 | + return CHECK_KERNEL(); |
| 126 | +} |
0 commit comments