Skip to content

Commit 90c3ff2

Browse files
committed
style: remove structs that have been made redundant
1 parent bcef472 commit 90c3ff2

File tree

4 files changed

+33
-39
lines changed

4 files changed

+33
-39
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#pragma once
2+
3+
#include <cstdint>
4+
#include <cstddef>
5+
6+
template <size_t CHUNK, size_t BLOCKS> struct MemoryInventoryRecord {
7+
uint32_t address_space;
8+
uint32_t ptr;
9+
uint32_t timestamps[BLOCKS];
10+
uint32_t values[CHUNK];
11+
};

crates/vm/cuda/src/system/boundary.cu

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,13 @@
33
#include "primitives/less_than.cuh"
44
#include "primitives/shared_buffer.cuh"
55
#include "primitives/trace_access.h"
6+
#include "system/records.cuh"
67
#include <cassert>
78

89
inline constexpr size_t PERSISTENT_CHUNK = 8;
910
inline constexpr size_t BLOCKS_PER_CHUNK = 2;
1011
inline constexpr size_t VOLATILE_CHUNK = 1;
1112

12-
template <size_t CHUNK, size_t BLOCKS> struct BoundaryRecord {
13-
uint32_t address_space;
14-
uint32_t ptr;
15-
uint32_t timestamps[BLOCKS];
16-
uint32_t values[CHUNK];
17-
};
18-
1913
template <typename T> struct PersistentBoundaryCols {
2014
T expand_direction;
2115
T address_space;
@@ -43,7 +37,7 @@ __global__ void cukernel_persistent_boundary_tracegen(
4337
size_t height,
4438
size_t width,
4539
uint8_t const *const *initial_mem,
46-
BoundaryRecord<PERSISTENT_CHUNK, BLOCKS_PER_CHUNK> *records,
40+
MemoryInventoryRecord<PERSISTENT_CHUNK, BLOCKS_PER_CHUNK> *records,
4741
size_t num_records,
4842
FpArray<16> *poseidon2_buffer,
4943
uint32_t *poseidon2_buffer_idx,
@@ -54,7 +48,7 @@ __global__ void cukernel_persistent_boundary_tracegen(
5448
RowSlice row = RowSlice(trace + row_idx, height);
5549

5650
if (record_idx < num_records) {
57-
BoundaryRecord<PERSISTENT_CHUNK, BLOCKS_PER_CHUNK> record = records[record_idx];
51+
MemoryInventoryRecord<PERSISTENT_CHUNK, BLOCKS_PER_CHUNK> record = records[record_idx];
5852
Poseidon2Buffer poseidon2(poseidon2_buffer, poseidon2_buffer_idx, poseidon2_capacity);
5953
COL_WRITE_VALUE(row, PersistentBoundaryCols, address_space, record.address_space);
6054
COL_WRITE_VALUE(row, PersistentBoundaryCols, leaf_label, record.ptr / PERSISTENT_CHUNK);
@@ -114,7 +108,7 @@ __global__ void cukernel_volatile_boundary_tracegen(
114108
Fp *trace,
115109
size_t height,
116110
size_t width,
117-
BoundaryRecord<VOLATILE_CHUNK, 1> const *records,
111+
MemoryInventoryRecord<VOLATILE_CHUNK, 1> const *records,
118112
size_t num_records,
119113
uint32_t *range_checker,
120114
size_t range_checker_num_bins,
@@ -131,7 +125,7 @@ __global__ void cukernel_volatile_boundary_tracegen(
131125
// For the sake of always filling `addr_lt_aux`
132126
row.fill_zero(0, width);
133127
}
134-
BoundaryRecord<VOLATILE_CHUNK, 1> record = records[idx];
128+
MemoryInventoryRecord<VOLATILE_CHUNK, 1> record = records[idx];
135129
rc.decompose(
136130
record.address_space,
137131
as_max_bits,
@@ -150,7 +144,7 @@ __global__ void cukernel_volatile_boundary_tracegen(
150144
COL_WRITE_VALUE(row, VolatileBoundaryCols, is_valid, Fp::one());
151145

152146
if (idx != num_records - 1) {
153-
BoundaryRecord<VOLATILE_CHUNK, 1> next_record = records[idx + 1];
147+
MemoryInventoryRecord<VOLATILE_CHUNK, 1> next_record = records[idx + 1];
154148
uint32_t curr[ADDR_ELTS] = {record.address_space, record.ptr};
155149
uint32_t next[ADDR_ELTS] = {next_record.address_space, next_record.ptr};
156150
IsLessThanArray::generate_subrow(
@@ -198,8 +192,8 @@ extern "C" int _persistent_boundary_tracegen(
198192
size_t poseidon2_capacity
199193
) {
200194
auto [grid, block] = kernel_launch_params(height);
201-
BoundaryRecord<PERSISTENT_CHUNK, BLOCKS_PER_CHUNK> *d_records =
202-
reinterpret_cast<BoundaryRecord<PERSISTENT_CHUNK, BLOCKS_PER_CHUNK> *>(d_raw_records);
195+
MemoryInventoryRecord<PERSISTENT_CHUNK, BLOCKS_PER_CHUNK> *d_records =
196+
reinterpret_cast<MemoryInventoryRecord<PERSISTENT_CHUNK, BLOCKS_PER_CHUNK> *>(d_raw_records);
203197
FpArray<16> *d_poseidon2_buffer = reinterpret_cast<FpArray<16> *>(d_poseidon2_raw_buffer);
204198
cukernel_persistent_boundary_tracegen<<<grid, block>>>(
205199
d_trace,
@@ -227,7 +221,8 @@ extern "C" int _volatile_boundary_tracegen(
227221
size_t ptr_max_bits
228222
) {
229223
auto [grid, block] = kernel_launch_params(height, 512);
230-
auto d_records = reinterpret_cast<BoundaryRecord<VOLATILE_CHUNK, 1> const *>(d_raw_records);
224+
auto d_records =
225+
reinterpret_cast<MemoryInventoryRecord<VOLATILE_CHUNK, 1> const *>(d_raw_records);
231226
cukernel_volatile_boundary_tracegen<<<grid, block>>>(
232227
d_trace,
233228
height,

crates/vm/cuda/src/system/inventory.cu

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,15 @@
11
#include "launcher.cuh"
2+
#include "system/records.cuh"
23
#include <cub/device/device_scan.cuh>
34
#include <cstddef>
45
#include <cstdint>
56

6-
template <size_t CHUNK, size_t BLOCKS> struct MemoryInventoryRecord {
7-
uint32_t address_space;
8-
uint32_t ptr;
9-
uint32_t timestamps[BLOCKS];
10-
uint32_t values[CHUNK];
11-
};
12-
13-
147
const uint32_t IN_BLOCK_SIZE = 4;
158
const uint32_t OUT_BLOCK_SIZE = 8;
169

1710
using InRec = MemoryInventoryRecord<IN_BLOCK_SIZE, 1>;
1811
using OutRec = MemoryInventoryRecord<OUT_BLOCK_SIZE, 2>;
1912

20-
2113
__device__ inline bool same_output_block(
2214
InRec const *in,
2315
size_t lhs_idx,

crates/vm/cuda/src/system/memory/merkle_tree.cu

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include "poseidon2.cuh"
33
#include "primitives/shared_buffer.cuh"
44
#include "primitives/trace_access.h"
5+
#include "system/records.cuh"
56

67
#include <cub/cub.cuh>
78

@@ -159,12 +160,7 @@ template <typename T> struct MerkleCols {
159160
T right_direction_different;
160161
};
161162

162-
struct LabeledDigest {
163-
uint32_t address_space;
164-
uint32_t ptr;
165-
uint32_t timestamps[2];
166-
uint32_t digest_raw[CELLS_OUT];
167-
};
163+
using LabeledDigest = MemoryInventoryRecord<CELLS_OUT, 2>;
168164

169165
__global__ void prepare_for_updating(
170166
uint32_t *child_buf,
@@ -177,9 +173,9 @@ __global__ void prepare_for_updating(
177173
}
178174
child_buf[gid] = gid;
179175
Fp cells[CELLS] = {0};
180-
COPY_DIGEST(cells, leaves[gid].digest_raw);
176+
COPY_DIGEST(cells, leaves[gid].values);
181177
poseidon2_mix(cells);
182-
COPY_DIGEST(leaves[gid].digest_raw, cells);
178+
COPY_DIGEST(leaves[gid].values, cells);
183179
leaves[gid].address_space -= 1;
184180
leaves[gid].ptr /= CELLS_OUT;
185181
leaves[gid].timestamps[0] =
@@ -339,13 +335,13 @@ __global__ void update_merkle_layer(
339335
{ // new values trace row + actual update
340336
bool left_new = false;
341337
if (auto const child_ptr = child_ptrs[2 * idx]; child_ptr != MISSING_CHILD) {
342-
COPY_DIGEST(&subtree_layer[2 * parent_label], layer[child_ptr].digest_raw);
338+
COPY_DIGEST(&subtree_layer[2 * parent_label], layer[child_ptr].values);
343339
left_new = true;
344340
}
345341
COPY_DIGEST(cells, old_left_digest);
346342
bool right_new = false;
347343
if (auto const child_ptr = child_ptrs[2 * idx + 1]; child_ptr != MISSING_CHILD) {
348-
COPY_DIGEST(&subtree_layer[2 * parent_label + 1], layer[child_ptr].digest_raw);
344+
COPY_DIGEST(&subtree_layer[2 * parent_label + 1], layer[child_ptr].values);
349345
right_new = true;
350346
}
351347
COPY_DIGEST(cells + CELLS_OUT, old_right_digest);
@@ -361,7 +357,7 @@ __global__ void update_merkle_layer(
361357
right_new,
362358
poseidon2
363359
);
364-
COPY_DIGEST(layer[parent_ptr].digest_raw, cells);
360+
COPY_DIGEST(layer[parent_ptr].values, cells);
365361
}
366362
}
367363

@@ -392,7 +388,7 @@ __global__ void update_to_root(
392388
auto const address_space_idx = layer[idx].address_space;
393389
layer[idx].ptr = num_roots - 1 + address_space_idx;
394390
if (subtrees[address_space_idx]) {
395-
COPY_DIGEST(subtrees[address_space_idx], layer[idx].digest_raw);
391+
COPY_DIGEST(subtrees[address_space_idx], layer[idx].values);
396392
}
397393
}
398394

@@ -425,7 +421,7 @@ __global__ void update_to_root(
425421
for (auto i : {0, 1}) {
426422
if (children_ids[i] != MISSING_CHILD) {
427423
COPY_DIGEST(
428-
&out[2 * out_idx + 1 + i], layer[layer_ids[children_ids[i]]].digest_raw
424+
&out[2 * out_idx + 1 + i], layer[layer_ids[children_ids[i]]].values
429425
);
430426
}
431427
COPY_DIGEST(cells + CELLS_OUT * i, &out[2 * out_idx + 1 + i]);
@@ -450,11 +446,11 @@ __global__ void update_to_root(
450446
children_ids[1] != MISSING_CHILD,
451447
poseidon2
452448
);
453-
COPY_DIGEST(layer[layer_ids[surely_surviving_child]].digest_raw, cells);
449+
COPY_DIGEST(layer[layer_ids[surely_surviving_child]].values, cells);
454450
COL_WRITE_VALUE(row, MerkleCols, height_section, true);
455451
}
456452
}
457-
COPY_DIGEST(out, layer[layer_ids[0]].digest_raw);
453+
COPY_DIGEST(out, layer[layer_ids[0]].values);
458454
for (auto i : {0, 1}) {
459455
RowSlice row(merkle_trace + i, trace_height);
460456
COL_WRITE_VALUE(row, MerkleCols, is_root, true);

0 commit comments

Comments
 (0)