diff options
author | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2013-05-31 20:19:03 +0400 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2013-05-31 20:19:03 +0400 |
commit | 2d0a586c29e482d646dec0cf62880f577ff77657 (patch) | |
tree | e8ae7b03728ce3215592b7e76567c46facddf91e /intern/cycles/util | |
parent | db42a596aafeb7b33bee63c6bc8da205582b5257 (diff) |
Cycles OpenCL: keep the opencl context and program around for quicker rendering
the second time, as for example Intel CPU startup time is 9 seconds.
* Adds an cache for contexts and programs for each platform and device pair,
which also ensure now no two threads try to compile and write the binary cache
file at the same time.
* Change clFinish to clFlush so we don't block until the result is done, instead
it will block at the moment we copy back memory.
* Fix error in Cycles time_sleep implementation, does not affect any active code
though.
* Adds some (disabled) debugging code in the task scheduler.
Patch #35559 by Doug Gale.
Diffstat (limited to 'intern/cycles/util')
-rw-r--r-- | intern/cycles/util/util_opencl.cpp | 9 | ||||
-rw-r--r-- | intern/cycles/util/util_task.cpp | 24 | ||||
-rw-r--r-- | intern/cycles/util/util_time.cpp | 17 |
3 files changed, 42 insertions, 8 deletions
diff --git a/intern/cycles/util/util_opencl.cpp b/intern/cycles/util/util_opencl.cpp index c146c14b10c..1e67afb3fa8 100644 --- a/intern/cycles/util/util_opencl.cpp +++ b/intern/cycles/util/util_opencl.cpp @@ -114,6 +114,7 @@ PFNCLGETEXTENSIONFUNCTIONADDRESS __clewGetExtensionFunctionAddress = NULL; #endif // CLCC_GENERATE_DOCUMENTATION +#if 0 //! \brief Unloads OpenCL dynamic library, should not be called directly static void clewExit(void) { @@ -124,6 +125,7 @@ static void clewExit(void) module = NULL; } } +#endif //! \param path path to dynamic library to load //! \return CLEW_ERROR_OPEN_FAILED if the library could not be opened @@ -138,7 +140,6 @@ int clLibraryInit() #else const char *path = "libOpenCL.so"; #endif - int error = 0; // OpenCL disabled for now, only works with this environment variable set if(!getenv("CYCLES_OPENCL_TEST")) @@ -159,8 +160,11 @@ int clLibraryInit() return 0; } + // Disabled because we retain OpenCL context and it's difficult to ensure + // this will exit after releasing the context +#if 0 // Set unloading - error = atexit(clewExit); + int error = atexit(clewExit); if (error) { @@ -170,6 +174,7 @@ int clLibraryInit() return 0; } +#endif // Determine function entry-points __clewGetPlatformIDs = (PFNCLGETPLATFORMIDS )CLCC_DYNLIB_IMPORT(module, "clGetPlatformIDs"); diff --git a/intern/cycles/util/util_task.cpp b/intern/cycles/util/util_task.cpp index 43f15ba0ce6..abcb05561bd 100644 --- a/intern/cycles/util/util_task.cpp +++ b/intern/cycles/util/util_task.cpp @@ -21,6 +21,15 @@ #include "util_system.h" #include "util_task.h" +//#define THREADING_DEBUG_ENABLED + +#ifdef THREADING_DEBUG_ENABLED +#include <stdio.h> +#define THREADING_DEBUG(...) do { printf(__VA_ARGS__); fflush(stdout); } while(0) +#else +#define THREADING_DEBUG(...) +#endif + CCL_NAMESPACE_BEGIN /* Task Pool */ @@ -95,8 +104,11 @@ void TaskPool::wait_work() if(num == 0) break; - if(!found_entry) + if(!found_entry) { + THREADING_DEBUG("num==%d, Waiting for condition in TaskPool::wait_work !found_entry\n", num); num_cond.wait(num_lock); + THREADING_DEBUG("num==%d, condition wait done in TaskPool::wait_work !found_entry\n", num); + } } } @@ -109,8 +121,11 @@ void TaskPool::cancel() { thread_scoped_lock num_lock(num_mutex); - while(num) + while(num) { + THREADING_DEBUG("num==%d, Waiting for condition in TaskPool::cancel\n", num); num_cond.wait(num_lock); + THREADING_DEBUG("num==%d condition wait done in TaskPool::cancel\n", num); + } } do_cancel = false; @@ -134,8 +149,10 @@ void TaskPool::num_decrease(int done) num -= done; assert(num >= 0); - if(num == 0) + if(num == 0) { + THREADING_DEBUG("num==%d, notifying all in TaskPool::num_decrease\n", num); num_cond.notify_all(); + } num_mutex.unlock(); } @@ -144,6 +161,7 @@ void TaskPool::num_increase() { thread_scoped_lock num_lock(num_mutex); num++; + THREADING_DEBUG("num==%d, notifying all in TaskPool::num_increase\n", num); num_cond.notify_all(); } diff --git a/intern/cycles/util/util_time.cpp b/intern/cycles/util/util_time.cpp index 5f543fc7f91..4edd59780a2 100644 --- a/intern/cycles/util/util_time.cpp +++ b/intern/cycles/util/util_time.cpp @@ -58,12 +58,23 @@ double time_dt() return now.tv_sec + now.tv_usec*1e-6; } +/* sleep t seconds */ void time_sleep(double t) { - if(t >= 1.0) - sleep((int)t); + /* get whole seconds */ + int s = (int)t; - usleep((int)(t*1e6)); + if(s >= 1) { + sleep(s); + + /* adjust parameter to remove whole seconds */ + t -= s; + } + + /* get microseconds */ + int us = (int)(t * 1e6); + if (us > 0) + usleep(us); } CCL_NAMESPACE_END |