diff options
author | Sergey Sharybin <sergey.vfx@gmail.com> | 2019-01-11 20:09:05 +0300 |
---|---|---|
committer | Sergey Sharybin <sergey.vfx@gmail.com> | 2019-01-11 20:09:05 +0300 |
commit | 1c7695b8483dc9bbcfd9dac26a652922062ea2b7 (patch) | |
tree | 0e7fc3c9dc7de3338c49bebb1aba568d717154d9 /intern/cycles | |
parent | ba4e6d73af0a125c319cd087ff5db68a914bbabe (diff) | |
parent | 48506a3431fb5b4396f7cf2d9c6a8a208b3c0df5 (diff) |
Merge branch 'blender2.7'
Diffstat (limited to 'intern/cycles')
-rw-r--r-- | intern/cycles/util/util_system.cpp | 22 | ||||
-rw-r--r-- | intern/cycles/util/util_system.h | 4 | ||||
-rw-r--r-- | intern/cycles/util/util_task.cpp | 18 |
3 files changed, 34 insertions, 10 deletions
diff --git a/intern/cycles/util/util_system.cpp b/intern/cycles/util/util_system.cpp index cc2d7017fd8..a22bd25ce77 100644 --- a/intern/cycles/util/util_system.cpp +++ b/intern/cycles/util/util_system.cpp @@ -40,7 +40,7 @@ bool system_cpu_ensure_initialized() { static bool is_initialized = false; static bool result = false; - if (is_initialized) { + if(is_initialized) { return result; } is_initialized = true; @@ -71,8 +71,8 @@ int system_cpu_thread_count() { const int num_nodes = system_cpu_num_numa_nodes(); int num_threads = 0; - for (int node = 0; node < num_nodes; ++node) { - if (!system_cpu_is_numa_node_available(node)) { + for(int node = 0; node < num_nodes; ++node) { + if(!system_cpu_is_numa_node_available(node)) { continue; } num_threads += system_cpu_num_numa_node_processors(node); @@ -82,7 +82,7 @@ int system_cpu_thread_count() int system_cpu_num_numa_nodes() { - if (!system_cpu_ensure_initialized()) { + if(!system_cpu_ensure_initialized()) { /* Fallback to a single node with all the threads. */ return 1; } @@ -91,7 +91,7 @@ int system_cpu_num_numa_nodes() bool system_cpu_is_numa_node_available(int node) { - if (!system_cpu_ensure_initialized()) { + if(!system_cpu_ensure_initialized()) { return true; } return numaAPI_IsNodeAvailable(node); @@ -99,7 +99,7 @@ bool system_cpu_is_numa_node_available(int node) int system_cpu_num_numa_node_processors(int node) { - if (!system_cpu_ensure_initialized()) { + if(!system_cpu_ensure_initialized()) { return system_cpu_thread_count_fallback(); } return numaAPI_GetNumNodeProcessors(node); @@ -107,12 +107,20 @@ int system_cpu_num_numa_node_processors(int node) bool system_cpu_run_thread_on_node(int node) { - if (!system_cpu_ensure_initialized()) { + if(!system_cpu_ensure_initialized()) { return true; } return numaAPI_RunThreadOnNode(node); } +int system_cpu_num_active_group_processors() +{ + if(!system_cpu_ensure_initialized()) { + return system_cpu_thread_count_fallback(); + } + return numaAPI_GetNumCurrentNodesProcessors(); +} + #if !defined(_WIN32) || defined(FREE_WINDOWS) static void __cpuid(int data[4], int selector) { diff --git a/intern/cycles/util/util_system.h b/intern/cycles/util/util_system.h index 15f69bcf153..0c001f11f0e 100644 --- a/intern/cycles/util/util_system.h +++ b/intern/cycles/util/util_system.h @@ -44,6 +44,10 @@ int system_cpu_num_numa_node_processors(int node); * Returns truth if affinity has successfully changed. */ bool system_cpu_run_thread_on_node(int node); +/* Number of processors within the current CPU group (or within active thread + * thread affinity). */ +int system_cpu_num_active_group_processors(); + string system_cpu_brand_string(); int system_cpu_bits(); bool system_cpu_support_sse2(); diff --git a/intern/cycles/util/util_task.cpp b/intern/cycles/util/util_task.cpp index 7e9f7313fba..4241c4aa8cc 100644 --- a/intern/cycles/util/util_task.cpp +++ b/intern/cycles/util/util_task.cpp @@ -228,9 +228,21 @@ int get_num_total_processors(const vector<int>& num_per_node_processors) void distribute_threads_on_nodes(const vector<thread*>& threads) { const int num_threads = threads.size(); - /* TODO(sergey): Skip overriding affinity if threads fits into the current - * nodes/CPU group. This will allow user to tweak affinity for weird and - * wonderful reasons. */ + const int num_active_group_processors = + system_cpu_num_active_group_processors(); + VLOG(1) << "Detected " << num_active_group_processors << " processors " + << "in active group."; + if(num_active_group_processors >= num_threads) { + /* If the current thread is set up in a way that its affinity allows to + * use at least requested number of threads we do not explicitly set + * affinity to the worker therads. + * This way we allow users to manually edit affinity of the parent + * thread, and here we follow that affinity. This way it's possible to + * have two Cycles/Blender instances running manually set to a different + * dies on a CPU. */ + VLOG(1) << "Not setting thread group affinity."; + return; + } vector<int> num_per_node_processors; get_per_node_num_processors(&num_per_node_processors); if(num_per_node_processors.size() == 0) { |