-
Notifications
You must be signed in to change notification settings - Fork 68
multithread the MD5/IQM model CPU code using OpenMP #1838
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
Merged
+307
−74
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
01d5855
framework: add Omp facilities
illwieckz a161068
engine: initialize Omp
illwieckz 5810d73
tr_surface: prepare Tess_SurfaceIQM() for parallelism
illwieckz a026935
tr_surface: parallelize Tess_SurfaceIQM()
illwieckz 8d700a8
tr_surface: prepare Tess_SurfaceMD5() for parallelism
illwieckz 4a37a9b
tr_surface: parallelize Tess_SurfaceMD5()
illwieckz deacc4d
tr_init: report OpenMP support in /gfxinfo
illwieckz 2f24482
cmake: add OpenMP support
illwieckz 731fa58
cmake: remove unused CompileFeatures
illwieckz 6e20a1b
cmake: make AddApplication() able to pass linker flags
illwieckz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
| /* | ||
| =========================================================================== | ||
| Daemon BSD Source Code | ||
| Copyright (c) 2025, Daemon Developers | ||
| All rights reserved. | ||
|
|
||
| Redistribution and use in source and binary forms, with or without | ||
| modification, are permitted provided that the following conditions are met: | ||
| * Redistributions of source code must retain the above copyright | ||
| notice, this list of conditions and the following disclaimer. | ||
| * Redistributions in binary form must reproduce the above copyright | ||
| notice, this list of conditions and the following disclaimer in the | ||
| documentation and/or other materials provided with the distribution. | ||
| * Neither the name of the Daemon developers nor the | ||
| names of its contributors may be used to endorse or promote products | ||
| derived from this software without specific prior written permission. | ||
|
|
||
| THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | ||
| ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
| WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
| DISCLAIMED. IN NO EVENT SHALL DAEMON DEVELOPERS BE LIABLE FOR ANY | ||
| DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
| (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
| ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
| (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
| SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| =========================================================================== | ||
| */ | ||
|
|
||
| #include <algorithm> | ||
|
|
||
| #include "CvarSystem.h" | ||
| #include "OmpSystem.h" | ||
|
|
||
| #if defined(_OPENMP) | ||
| #include "omp.h" | ||
| #endif | ||
|
|
||
| #if defined(_OPENMP) | ||
| static Cvar::Range<Cvar::Cvar<int>> common_ompThreads( | ||
| "common.ompThreads", "OpenMP threads", Cvar::NONE, 0, 0, 32 ); | ||
| #endif | ||
|
|
||
| namespace Omp { | ||
| #if defined(_OPENMP) | ||
| static int ompMaxThreads = 1; | ||
| #endif | ||
|
|
||
| static int ompThreads = 1; | ||
|
|
||
| static void ReadMaxThreads() | ||
| { | ||
| #if defined(_OPENMP) | ||
| ompMaxThreads = omp_get_max_threads(); | ||
| #endif | ||
| } | ||
|
|
||
| void EnlistThreads() | ||
| { | ||
| #if defined(_OPENMP) | ||
| omp_set_num_threads( ompThreads ); | ||
| #endif | ||
| } | ||
|
|
||
| void SetupThreads() | ||
| { | ||
| #if defined(_OPENMP) | ||
| if ( common_ompThreads.Get() ) | ||
| { | ||
| ompThreads = common_ompThreads.Get(); | ||
| } | ||
| else | ||
| { | ||
| switch( ompMaxThreads ) | ||
| { | ||
| case 1: | ||
| ompThreads = 1; | ||
| break; | ||
| case 2: | ||
| case 3: | ||
| ompThreads = 2; | ||
| break; | ||
| default: | ||
| /* Using half threads than available is known to work best with: | ||
| - 2 threads on Low-end 4-cores (no SMP) Ryzen 3 3200G, | ||
| - 16 threads on High-end 16-cores/32-threads Ryzen Threadripper PRO 3955WX | ||
|
|
||
| It has not been tested on a system where ompMaxThreads / 2 > 16. */ | ||
| ompThreads = std::min( ompMaxThreads / 2, 16 ); | ||
| } | ||
| } | ||
| #endif | ||
|
|
||
| EnlistThreads(); | ||
| } | ||
|
|
||
| void Init() | ||
| { | ||
| ReadMaxThreads(); | ||
| SetupThreads(); | ||
| } | ||
|
|
||
| int GetThreads() | ||
| { | ||
| return ompThreads; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| /* | ||
| =========================================================================== | ||
| Daemon BSD Source Code | ||
| Copyright (c) 2025, Daemon Developers | ||
| All rights reserved. | ||
|
|
||
| Redistribution and use in source and binary forms, with or without | ||
| modification, are permitted provided that the following conditions are met: | ||
| * Redistributions of source code must retain the above copyright | ||
| notice, this list of conditions and the following disclaimer. | ||
| * Redistributions in binary form must reproduce the above copyright | ||
| notice, this list of conditions and the following disclaimer in the | ||
| documentation and/or other materials provided with the distribution. | ||
| * Neither the name of the Daemon developers nor the | ||
| names of its contributors may be used to endorse or promote products | ||
| derived from this software without specific prior written permission. | ||
|
|
||
| THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | ||
| ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
| WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
| DISCLAIMED. IN NO EVENT SHALL DAEMON DEVELOPERS BE LIABLE FOR ANY | ||
| DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
| (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
| ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
| (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
| SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| =========================================================================== | ||
| */ | ||
|
|
||
| #ifndef COMMON_OMP_SYSTEM_H_ | ||
| #define COMMON_OMP_SYSTEM_H_ | ||
|
|
||
| namespace Omp { | ||
| void EnlistThreads(); | ||
| void SetupThreads(); | ||
| void Init(); | ||
| int GetThreads(); | ||
| }; | ||
|
|
||
| #endif // COMMON_OMP_SYSTEM_H_ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bad spacing
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
PS: Please comment on the problematic line itself, not the line above it.
Earlier in the day I fixed bad spacing on the
${OMPLIST}line so I first believed your cache was obsolete, until I notice you talked about the${COMMON_DIR}/Util.hline below it (which GitHub doesn't show in main PR thread).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well I just see two lines that are not matching. I don't know which one is supposedly correct.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you comment on the last line not matching, GitHub will display both of them (and disclose the mismatch). If you comment on the first line not matching, GitHub will only display the first mismatching one (and hide the mismatch).
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's because GitHub displays the commented line and above, not the commented line and below.