Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory handling of 2 reads at the same address in the same clock cycle #1561

Merged
merged 1 commit into from
Nov 18, 2024

Conversation

plafer
Copy link
Contributor

@plafer plafer commented Nov 1, 2024

Closes #1560

Copy link
Contributor

@bobbinth bobbinth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Thank you!

@Al-Kindi-0
Copy link
Collaborator

I would personally not treat this at the constraint system unless there is a real use case or a good reason for allowing reading the same address at the same cycles in the same context.
Nevertheless, if we go with this approach, we would have to update the constraints to take into account the changes in this PR. For example the following constraints needs to be updated as the cycles need not anymore be monotonically increasing
montonicaly_increasing

There could be others so we should double check all constraints which rely on assumptions changes with this PR.

@bobbinth
Copy link
Contributor

bobbinth commented Nov 3, 2024

we would have to update the constraints to take into account the changes in this PR. For example the following constraints needs to be updated as the cycles need not anymore be monotonically increasing

Ah - good point. I guess there are a few ways we can go:

  1. Go through with this PR and fix the constraints (either in this or a follow-up PR).
  2. Make it explicit that reading from the same address in the same cycle is not allowed (and have a proper error for this).
  3. Tackle it as a part of a bigger memory refactoring we'll do in December. For example, maybe it would make sense to introduce a "multiplicity" column for reads. This way this constraint would stay the same. Though, it may introduce more complexities.

Overall, to keep track of the things we may want to address with memory subsystem refactoring:

  • Fix the current soundness bug for single element writes.
  • Enable support for basic read-only memory.
  • Potentially enable support for element-addressable memory.
  • Potentially enable multiple reads from the same address at the same cycle.
  • Maybe something else as well.

@Al-Kindi-0
Copy link
Collaborator

we would have to update the constraints to take into account the changes in this PR. For example the following constraints needs to be updated as the cycles need not anymore be monotonically increasing

Ah - good point. I guess there are a few ways we can go:

1. Go through with this PR and fix the constraints (either in this or a follow-up PR).

2. Make it explicit that reading from the same address in the same cycle is not allowed (and have a proper error for this).

3. Tackle it as a part of a bigger memory refactoring we'll do in December. For example, maybe it would make sense to introduce a "multiplicity" column for reads. This way this constraint would stay the same. Though, it may introduce more complexities.

Makes sense!
Up to you guys, I would prefer option 2 at the moment but given the work in this PR option 1 is fine as well.

Overall, to keep track of the things we may want to address with memory subsystem refactoring:

* Fix the current soundness bug for single element writes.

* Enable support for basic read-only memory.

* Potentially enable support for element-addressable memory.

* Potentially enable multiple reads from the same address at the same cycle.

* Maybe something else as well.

I think that's all

@plafer
Copy link
Contributor Author

plafer commented Nov 4, 2024

I would personally not treat this at the constraint system unless there is a real use case or a good reason for allowing reading the same address at the same cycles in the same context.

Ah yes you're right! Re-reading this now, it does seem like the right approach is to simply return an error in the processor, instead of changing the constraints to allow it. We currently never need to read/write the same location twice, and so it doesn't make sense to allow it.

I will update the PR accordingly.

@plafer
Copy link
Contributor Author

plafer commented Nov 5, 2024

Implementation changed to return an error when a memory address is accessed twice in the same clock cycle.

Interestingly the rcombine_main() test was never incrementing the clock and so was reading & writing the same memory address in the same clock cycle (now fixed).

Copy link
Collaborator

@Al-Kindi-0 Al-Kindi-0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, thank you!

processor/src/operations/comb_ops.rs Show resolved Hide resolved
Copy link
Contributor

@bobbinth bobbinth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Thank you! I left a few doc-related comments inline. Once these are addressed, we can merge.

processor/src/chiplets/memory/segment.rs Show resolved Hide resolved
processor/src/chiplets/memory/segment.rs Outdated Show resolved Hide resolved
processor/src/chiplets/memory/mod.rs Outdated Show resolved Hide resolved
processor/src/chiplets/memory/mod.rs Outdated Show resolved Hide resolved
miden/tests/integration/operations/io_ops/mem_ops.rs Outdated Show resolved Hide resolved
@plafer plafer merged commit 190f9b5 into next Nov 18, 2024
9 checks passed
@plafer plafer deleted the plafer-1560-fix-memory-bug branch November 18, 2024 13:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants