Permalink
Browse files

NvOptimus Win support: always run on dedicated GPU

  • Loading branch information...
1 parent b96e756 commit 1f464adeb13560cf926417bce99d338c82020b59 jK committed Nov 29, 2012
Showing with 486 additions and 1 deletion.
  1. +28 −0 LICENSE
  2. +23 −1 rts/System/Main.cpp
  3. +435 −0 rts/lib/SOP/SOP.hpp
View
28 LICENSE
@@ -17,3 +17,31 @@ see [GNU GPL v2 (gpl-2.0.txt)](gpl-2.0.html)
and [v3 (gpl-3.0.txt)](gpl-3.0.html).
For a list of authors of this software, see [AUTHORS](AUTHORS.html).
+
+## Third Parties
+
+### file SOP.hpp
+Copyright (c) 2012, Daniel Cornel. Published on drivenbynostalgia.com.
+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 copyright holder 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 THE COPYRIGHT HOLDER 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.
View
@@ -22,6 +22,7 @@
#endif
#ifdef WIN32
+ #include "lib/SOP/SOP.hpp" // NvOptimus
#include <stdlib.h>
#include <process.h>
#define execv _execv
@@ -69,9 +70,12 @@ int Run(int argc, char* argv[])
return ret;
}
+
+/**
+ * Set some performance relevant OpenMP EnvVars.
+ */
static void SetOpenMpEnvVars(char* argv[])
{
- // set some performance relevant openmp envvars
bool restart = false;
/*if (!getenv("OMP_WAIT_POLICY")) {
// omp threads will use a spinlock instead of yield'ing when waiting
@@ -93,6 +97,23 @@ static void SetOpenMpEnvVars(char* argv[])
}
+/**
+ * Always run on dedicated GPU.
+ */
+static void SetNvOptimusProfile(char* argv[])
+{
+#ifdef WIN32
+ if (SOP_CheckProfile("Spring"))
+ return;
+
+ const std::string exename = argv[0];
+ const int res = SOP_SetProfile("Spring", exename);
+ if (res == SOP_RESULT_CHANGE)
+ execv(argv[0], argv);
+#endif
+}
+
+
/**
* @brief main
@@ -104,6 +125,7 @@ static void SetOpenMpEnvVars(char* argv[])
*/
int main(int argc, char* argv[])
{
+ SetNvOptimusProfile(argv);
SetOpenMpEnvVars(argv);
return Run(argc, argv);
}
Oops, something went wrong.

0 comments on commit 1f464ad

Please sign in to comment.