-
Notifications
You must be signed in to change notification settings - Fork 69
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
base: master
Are you sure you want to change the base?
Changes from all commits
30170ab
71e4cbb
c6e49c8
4147657
6285386
4867415
905210c
d6d57f8
5f15aff
4d35d34
9803547
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| /* | ||
| =========================================================================== | ||
| 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 if ( ompMaxThreads <= 4 ) | ||
| { | ||
| ompThreads = ompMaxThreads; | ||
| } | ||
| else if ( ompMaxThreads <= 16 ) | ||
| { | ||
| ompThreads = ompMaxThreads - ( ompMaxThreads / 4 ); | ||
| } | ||
| else | ||
| { | ||
| ompThreads = 16; | ||
| } | ||
| #endif | ||
|
|
||
| EnlistThreads(); | ||
| } | ||
|
|
||
| void Init() | ||
| { | ||
| ReadMaxThreads(); | ||
| SetupThreads(); | ||
| } | ||
|
|
||
| int GetThreads() | ||
| { | ||
| return ompThreads; | ||
| } | ||
| } |
| 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_ |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,6 +23,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
| // tr_init.c -- functions that are not called every frame | ||
| #include "tr_local.h" | ||
| #include "framework/CvarSystem.h" | ||
| #include "framework/OmpSystem.h" | ||
| #include "DetectGLVendors.h" | ||
| #include "Material.h" | ||
| #include "GeometryCache.h" | ||
|
|
@@ -1057,6 +1058,21 @@ ScreenshotCmd screenshotPNGRegistration("screenshotPNG", ssFormat_t::SSF_PNG, "p | |
| Log::Notice("Using dual processor acceleration." ); | ||
| } | ||
|
|
||
| #if defined(_OPENMP) | ||
| int ompThreads = Omp::GetThreads(); | ||
|
|
||
| if ( ompThreads == 1 ) | ||
| { | ||
| Log::Notice("%sNot using OpenMP parallelism: only one thread.", Color::ToString( Color::Red ) ); | ||
| } | ||
| else | ||
| { | ||
| Log::Notice("%sUsing OpenMP parallelism with %d threads.", Color::ToString( Color::Green ), ompThreads ); | ||
| } | ||
| #else | ||
| Log::Notice("%sNot using OpenMP parallelism: unavailable.", Color::ToString( Color::Red ) ); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think it makes sense to output this in red, which is presumably even worse than a yellow warning, since the OpenMP would only be used by a minority of players with the worst GPUs.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah yes. I can change that. |
||
| #endif | ||
|
|
||
| if ( r_finish->integer ) | ||
| { | ||
| Log::Notice("Forcing glFinish." ); | ||
|
|
||
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.
@slipher Maybe it's a better place there? Given the previous line I assume the Cvar system is already initialized.
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.
Seems OK