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

target: Add VLT_NUM_THREADS to configure threads used by verilator #148

Closed

Conversation

zero9178
Copy link
Contributor

@zero9178 zero9178 commented Jun 5, 2024

Using more threads in the simulation may lead to a speedup in simulation time, especially when the program running in the simulator makes use of multiple cores. This PR therefore adds the VLT_NUM_THREADS option to make to allow users to set the thread number used in the simulator. For backwards compatibility, and since the number of threads is environment and code dependent, the default value of 1 was kept.

Using more threads in the simulation may lead to a speedup in simulation time, especially when the program running in the simulator makes use of multiple cores.
This PR therefore adds the `VLT_NUM_THREADS` option to `make` to allow users to set the thread number used in the simulator. For backwards compatibility, and since the number of threads is environment and code dependent, the default value of 1 was kept.
@zero9178 zero9178 changed the title target: Add VLT_NUM_THREADS to threads used by verilator target: Add VLT_NUM_THREADS to configure threads used by verilator Jun 5, 2024
Copy link
Collaborator

@colluca colluca left a comment

Choose a reason for hiding this comment

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

Thanks for the valuable contribution @zero9178!

I have just a few comments to simplify the change further. Let me know if you think it could work.

Also, I would perhaps update the CI to use the multi-threaded version, even with just two threads, to verify the implementation.

Comment on lines 90 to 92
ifneq ($(VLT_NUM_THREADS), 1)
VLT_FLAGS += --threads $(VLT_NUM_THREADS)
endif
Copy link
Collaborator

Choose a reason for hiding this comment

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

I believe we can drop the if statement, as Verilator should by default behave as if --threads 1 is passed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I believe this is true for Verilator 5 but not the verilator 4 that the repo currently supports until #76 lands.
That said I think you're right and we can drop this as this is almost certainly a premature optimization and I doubt single-threaded usage will see a measureable difference.

Comment on lines 94 to 96
ifneq ($(VLT_NUM_THREADS), 1)
VLT_CFLAGS += -DVL_THREADED=1
endif
Copy link
Collaborator

Choose a reason for hiding this comment

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

Couldn't find much information on this, but perhaps we can also always add this flag, and remove the if statement. I guess it shouldn't break the single-threaded case.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Information is sadly very sparse on the flag and I only found it referenced through GitHub issues such as verilator/verilator#3668 (comment)
I had to add it as I was getting compilation errors as verilator requires it to be defined when using multiple threads.
I added a comment to clarify.

target/snitch_cluster/Makefile Outdated Show resolved Hide resolved
@zero9178 zero9178 requested a review from colluca June 5, 2024 14:53
@zero9178 zero9178 marked this pull request as draft June 5, 2024 16:48
@zero9178
Copy link
Contributor Author

zero9178 commented Jun 5, 2024

I am seeing issues with the simulation where it seemingly gets stuck/deadlocks for non-obvious reasons. While the PR itself is okay its probably not a good idea to actually use any value but 1 for the time being.

@colluca
Copy link
Collaborator

colluca commented Jun 6, 2024

I am seeing issues with the simulation where it seemingly gets stuck/deadlocks for non-obvious reasons. While the PR itself is okay its probably not a good idea to actually use any value but 1 for the time being.

See also issue #116.

@and-ivanov may know something more about this. Tagging him in case he might have further comments.

@colluca
Copy link
Collaborator

colluca commented Jul 8, 2024

Dear @zero9178,

I opened a new PR upgrading the supported Verilator version to 5.006 (#158). I tentatively added your multi-threading contributions from this PR. If you would like to try it, perhaps it fixes the issues you mentioned above. If this is the case we can close this PR in favour of #158 and merge it.

Best,
Luca

@zero9178
Copy link
Contributor Author

zero9178 commented Jul 8, 2024

Dear @zero9178,

I opened a new PR upgrading the supported Verilator version to 5.006 (#158). I tentatively added your multi-threading contributions from this PR. If you would like to try it, perhaps it fixes the issues you mentioned above. If this is the case we can close this PR in favour of #158 and merge it.

Best, Luca

That's amazing! Let me run the verilator model from your PR through our stack and I'll get back to you whether it works (I'll respond on that PR). If yes then I think we can close this. If the multithreading part does not work then I'd either leave this open and/or make this an issue.

@colluca
Copy link
Collaborator

colluca commented Aug 1, 2024

Finally merged in #158. Thanks again for the help @zero9178!

@colluca colluca closed this Aug 1, 2024
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.

2 participants