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

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