Skip to content

Exclusive branches#551

Merged
tilk merged 17 commits intomasterfrom
tilk/exclusive-branches
Jan 2, 2024
Merged

Exclusive branches#551
tilk merged 17 commits intomasterfrom
tilk/exclusive-branches

Conversation

@tilk
Copy link
Copy Markdown
Member

@tilk tilk commented Dec 22, 2023

This work in progress PR is intended to improve readability and performance of code where Amaranth branches interact with Transactron. In particular:

  • Transactions/methods defined in different branches can be marked as conflict-free, as they can't run in the same cycle.
  • Calling the same method from different branches are allowed.

TODO:

  • Make exclusive branch detection correct.
  • Find places where a workaround for single call per body was used
  • Implement tests.

Closes #549.

@tilk tilk added enhancement New feature or request transactions Transaction framework (deprecated label, see Transactron repo) labels Dec 22, 2023
Comment thread coreblocks/stages/retirement.py Outdated
Comment on lines +114 to +124
m_csr.mcause.write(m, data=1 << (self.gen_params.isa.xlen - 1))
with m.Else():
# RISC-V synchronous exceptions - don't retire instruction that caused exception,
# and later resume from it.
# Value of ExceptionCauseRegister pc field is the instruction address.
m.d.av_comb += commit.eq(0)

m.d.av_comb += cause_entry.eq(cause_register.cause)
cause_entry = Cat(
cause_register.cause, C(0, self.gen_params.isa.xlen - len(cause_register.cause))
)
m_csr.mcause.write(m, data=cause_entry)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I would not like this particular logic to be changed, because previous way will look nicer with misprediction support (when some causes don't trigger architecture trap - this could be handled under one If with mepc and trap_entry)

Find places where a workaround for single call per body was

Other places that I remember this change would be useful are CSRUnit, and JumpBranchUnit (both related to report method)

@tilk tilk marked this pull request as ready for review December 28, 2023 12:16
@tilk tilk requested a review from lekcyjna123 December 28, 2023 12:34
Copy link
Copy Markdown
Contributor

@lekcyjna123 lekcyjna123 left a comment

Choose a reason for hiding this comment

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

Overall it is great change. I left some comments in code and please, add some documentation, docstrings, comments, markdown even in Quenya, but something is very needed.

Comment thread test/transactions/test_branches.py
Comment thread transactron/core.py Outdated
Comment thread transactron/core.py
def transactions_exclusive(trans1: Transaction, trans2: Transaction):
tms1 = [trans1] + method_map.methods_by_transaction[trans1]
tms2 = [trans2] + method_map.methods_by_transaction[trans2]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't see yet how the exclusiveness of methods propagates to exclusiveness of transactions.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Lets take such example:

with transaction().body(): #parent
  method1()
  with m.If(1):
    method2()
  with m.Else():
    with transaction.body(): #child
      method1()
      with m.If(1):
        method2()

Are parent and child transaction exclusive or not? According to the below comment they should be exclusive because there exists the method2 that is exclusive. But in parallel we have call to method1 which is obviously wrong and shouldn't be allowed.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

They are exclusive and the child transaction will never run. This situation was not detected by the previous check, and is still not detected in this PR. I think this should be considered a separate issue.

Comment thread transactron/core.py Outdated
Copy link
Copy Markdown
Contributor

@lekcyjna123 lekcyjna123 left a comment

Choose a reason for hiding this comment

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

Thanks. Now it is much cleaner.

@tilk tilk requested a review from awariac December 29, 2023 17:18
Copy link
Copy Markdown
Member

@awariac awariac 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!

Comment thread transactron/core.py Outdated
Co-authored-by: piotro888 <piotro@piotro.eu>
@tilk tilk merged commit cf30bbe into master Jan 2, 2024
@tilk tilk deleted the tilk/exclusive-branches branch January 2, 2024 12:26
github-actions Bot pushed a commit that referenced this pull request Jan 2, 2024
@tilk tilk mentioned this pull request Jan 2, 2024
tilk added a commit to kuznia-rdzeni/transactron that referenced this pull request Nov 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request transactions Transaction framework (deprecated label, see Transactron repo)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Use mutual exclusivity of branches in Transactron

3 participants