scalesim-project / scale-sim-v2

Repository to host and maintain scale-sim-v2 code
MIT License
232 stars 99 forks source link

next_line_prefetch_idx in read_buffer.py #111

Open hcysky opened 1 month ago

hcysky commented 1 month ago

Hello, I have a question regarding the calculation the next_line_prefetch_idx in read_buffer.py. The relevant code block from lines 309-312 (def prefetch_active_buffer(self, start_cycle)) of read_buffer.py is as following:

    if requested_data_size > self.active_buf_size: # Set the line to be prefetched next
        self.next_line_prefetch_idx = num_lines % self.fetch_matrix.shape[0]
    else:
        self.next_line_prefetch_idx = (num_lines + 1) % self.fetch_matrix.shape[0]

To enhance the correctness of the logic, I suggest the following modification:

    if requested_data_size > self.active_buf_size: # Set the line to be prefetched next
        self.next_line_prefetch_idx = (num_lines - 1) % self.fetch_matrix.shape[0]
    else:
        self.next_line_prefetch_idx = num_lines % self.fetch_matrix.shape[0]

The reason for this modification is as follows: The row indices for fetch_matrix start from 0. When requested_data_size > self.active_buf_size, it indicates that the last line of the current prefetch requests(prefetch_requests[num_lines-1]) cannot be entirely accommodated within active_buf. Therefore, self.next_line_prefetch_idx is set to (num_lines-1) % self.fetch_matrix.shape[0], which starts from prefetch_requests[num_lines-1]. Similarly, when requested_data_size <= self.active_buf_size, it suggests that the last line of the current prefetch requests(prefetch_requests[num_lines-1]) can fit entirely within active_buf. Hence, self.next_line_prefetch_idx is set to num_lines % self.fetch_matrix.shape[0], which starts from prefetch_requests[num_lines].

Looking forward to your feedback and suggestions. Thank you.