1 /* 2 Copyright (c) 2019-2021 Intel Corporation 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 #ifndef __TBB_info_H 18 #define __TBB_info_H 19 20 #include "detail/_config.h" 21 #include "detail/_namespace_injection.h" 22 23 #if __TBB_ARENA_BINDING 24 #include <vector> 25 26 namespace tbb { 27 namespace detail { 28 29 namespace d1{ 30 31 using numa_node_id = int; 32 using core_type_id = int; 33 34 // TODO: consider version approach to resolve backward compatibility potential issues. 35 struct constraints { 36 #if !__TBB_CPP20_PRESENT 37 constraints(numa_node_id id = -1, int maximal_concurrency = -1) 38 : numa_id(id) 39 , max_concurrency(maximal_concurrency) 40 #if __TBB_PREVIEW_TASK_ARENA_CONSTRAINTS_EXTENSION_PRESENT 41 , core_type(-1) 42 , max_threads_per_core(-1) 43 #endif 44 {} 45 #endif /*!__TBB_CPP20_PRESENT*/ 46 47 constraints& set_numa_id(numa_node_id id) { 48 numa_id = id; 49 return *this; 50 } 51 constraints& set_max_concurrency(int maximal_concurrency) { 52 max_concurrency = maximal_concurrency; 53 return *this; 54 } 55 #if __TBB_PREVIEW_TASK_ARENA_CONSTRAINTS_EXTENSION_PRESENT 56 constraints& set_core_type(core_type_id id) { 57 core_type = id; 58 return *this; 59 } 60 constraints& set_max_threads_per_core(int threads_number) { 61 max_threads_per_core = threads_number; 62 return *this; 63 } 64 #endif 65 66 numa_node_id numa_id = -1; 67 int max_concurrency = -1; 68 #if __TBB_PREVIEW_TASK_ARENA_CONSTRAINTS_EXTENSION_PRESENT 69 core_type_id core_type = -1; 70 int max_threads_per_core = -1; 71 #endif 72 }; 73 74 } // namespace d1 75 76 namespace r1 { 77 TBB_EXPORT unsigned __TBB_EXPORTED_FUNC numa_node_count(); 78 TBB_EXPORT void __TBB_EXPORTED_FUNC fill_numa_indices(int* index_array); 79 TBB_EXPORT int __TBB_EXPORTED_FUNC numa_default_concurrency(int numa_id); 80 81 // Reserved fields are required to save binary backward compatibility in case of future changes. 82 // They must be defined to 0 at this moment. 83 TBB_EXPORT unsigned __TBB_EXPORTED_FUNC core_type_count(intptr_t reserved = 0); 84 TBB_EXPORT void __TBB_EXPORTED_FUNC fill_core_type_indices(int* index_array, intptr_t reserved = 0); 85 86 TBB_EXPORT int __TBB_EXPORTED_FUNC constraints_default_concurrency(const d1::constraints& c, intptr_t reserved = 0); 87 TBB_EXPORT int __TBB_EXPORTED_FUNC constraints_threads_per_core(const d1::constraints& c, intptr_t reserved = 0); 88 } // namespace r1 89 90 namespace d1 { 91 92 inline std::vector<numa_node_id> numa_nodes() { 93 std::vector<numa_node_id> node_indices(r1::numa_node_count()); 94 r1::fill_numa_indices(node_indices.data()); 95 return node_indices; 96 } 97 98 inline int default_concurrency(numa_node_id id = -1) { 99 return r1::numa_default_concurrency(id); 100 } 101 102 #if __TBB_PREVIEW_TASK_ARENA_CONSTRAINTS_EXTENSION_PRESENT 103 inline std::vector<core_type_id> core_types() { 104 std::vector<int> core_type_indexes(r1::core_type_count()); 105 r1::fill_core_type_indices(core_type_indexes.data()); 106 return core_type_indexes; 107 } 108 109 inline int default_concurrency(constraints c) { 110 if (c.max_concurrency > 0) { return c.max_concurrency; } 111 return r1::constraints_default_concurrency(c); 112 } 113 #endif /*__TBB_PREVIEW_TASK_ARENA_CONSTRAINTS_EXTENSION_PRESENT*/ 114 115 } // namespace d1 116 } // namespace detail 117 118 inline namespace v1 { 119 using detail::d1::numa_node_id; 120 #if __TBB_PREVIEW_TASK_ARENA_CONSTRAINTS_EXTENSION_PRESENT 121 using detail::d1::core_type_id; 122 #endif 123 124 namespace info { 125 using detail::d1::numa_nodes; 126 #if __TBB_PREVIEW_TASK_ARENA_CONSTRAINTS_EXTENSION_PRESENT 127 using detail::d1::core_types; 128 #endif 129 130 using detail::d1::default_concurrency; 131 } // namespace info 132 } // namespace v1 133 134 } // namespace tbb 135 136 #endif /*__TBB_ARENA_BINDING*/ 137 138 #endif /*__TBB_info_H*/ 139