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#include <cstdint>
26
27namespace tbb {
28namespace detail {
29
30namespace d1{
31
32using numa_node_id = int;
33using core_type_id = int;
34
35// TODO: consider version approach to resolve backward compatibility potential issues.
36struct constraints {
37#if !__TBB_CPP20_PRESENT
38 constraints(numa_node_id id = -1, int maximal_concurrency = -1)
39 : numa_id(id)
40 , max_concurrency(maximal_concurrency)
41#if __TBB_PREVIEW_TASK_ARENA_CONSTRAINTS_EXTENSION_PRESENT
42 , core_type(-1)
43 , max_threads_per_core(-1)
44#endif
45 {}
46#endif /*!__TBB_CPP20_PRESENT*/
47
48 constraints& set_numa_id(numa_node_id id) {
49 numa_id = id;
50 return *this;
51 }
52 constraints& set_max_concurrency(int maximal_concurrency) {
53 max_concurrency = maximal_concurrency;
54 return *this;
55 }
56#if __TBB_PREVIEW_TASK_ARENA_CONSTRAINTS_EXTENSION_PRESENT
57 constraints& set_core_type(core_type_id id) {
58 core_type = id;
59 return *this;
60 }
61 constraints& set_max_threads_per_core(int threads_number) {
62 max_threads_per_core = threads_number;
63 return *this;
64 }
65#endif
66
67 numa_node_id numa_id = -1;
68 int max_concurrency = -1;
69#if __TBB_PREVIEW_TASK_ARENA_CONSTRAINTS_EXTENSION_PRESENT
70 core_type_id core_type = -1;
71 int max_threads_per_core = -1;
72#endif
73};
74
75} // namespace d1
76
77namespace r1 {
78TBB_EXPORT unsigned __TBB_EXPORTED_FUNC numa_node_count();
79TBB_EXPORT void __TBB_EXPORTED_FUNC fill_numa_indices(int* index_array);
80TBB_EXPORT int __TBB_EXPORTED_FUNC numa_default_concurrency(int numa_id);
81
82// Reserved fields are required to save binary backward compatibility in case of future changes.
83// They must be defined to 0 at this moment.
84TBB_EXPORT unsigned __TBB_EXPORTED_FUNC core_type_count(intptr_t reserved = 0);
85TBB_EXPORT void __TBB_EXPORTED_FUNC fill_core_type_indices(int* index_array, intptr_t reserved = 0);
86
87TBB_EXPORT int __TBB_EXPORTED_FUNC constraints_default_concurrency(const d1::constraints& c, intptr_t reserved = 0);
88TBB_EXPORT int __TBB_EXPORTED_FUNC constraints_threads_per_core(const d1::constraints& c, intptr_t reserved = 0);
89} // namespace r1
90
91namespace d1 {
92
93inline std::vector<numa_node_id> numa_nodes() {
94 std::vector<numa_node_id> node_indices(r1::numa_node_count());
95 r1::fill_numa_indices(index_array: node_indices.data());
96 return node_indices;
97}
98
99inline int default_concurrency(numa_node_id id = -1) {
100 return r1::numa_default_concurrency(numa_id: id);
101}
102
103#if __TBB_PREVIEW_TASK_ARENA_CONSTRAINTS_EXTENSION_PRESENT
104inline std::vector<core_type_id> core_types() {
105 std::vector<int> core_type_indexes(r1::core_type_count());
106 r1::fill_core_type_indices(core_type_indexes.data());
107 return core_type_indexes;
108}
109
110inline int default_concurrency(constraints c) {
111 if (c.max_concurrency > 0) { return c.max_concurrency; }
112 return r1::constraints_default_concurrency(c);
113}
114#endif /*__TBB_PREVIEW_TASK_ARENA_CONSTRAINTS_EXTENSION_PRESENT*/
115
116} // namespace d1
117} // namespace detail
118
119inline namespace v1 {
120using detail::d1::numa_node_id;
121#if __TBB_PREVIEW_TASK_ARENA_CONSTRAINTS_EXTENSION_PRESENT
122using detail::d1::core_type_id;
123#endif
124
125namespace info {
126using detail::d1::numa_nodes;
127#if __TBB_PREVIEW_TASK_ARENA_CONSTRAINTS_EXTENSION_PRESENT
128using detail::d1::core_types;
129#endif
130
131using detail::d1::default_concurrency;
132} // namespace info
133} // namespace v1
134
135} // namespace tbb
136
137#endif /*__TBB_ARENA_BINDING*/
138
139#endif /*__TBB_info_H*/
140

source code of include/oneapi/tbb/info.h