1/*******************************************************************************
2* Copyright 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#include "tests/test_thread.hpp"
18
19#include "utils/parallel.hpp"
20
21#if DNNL_CPU_THREADING_RUNTIME == DNNL_RUNTIME_THREADPOOL
22#define ACTIVATE_THREADPOOL \
23 dnnl::testing::scoped_tp_activation_t scoped_activation
24#else
25#define ACTIVATE_THREADPOOL
26#endif
27
28// Note: no need in deactivation as `scoped_activation` object will deactivate
29// it automatically at destruction.
30
31void benchdnn_parallel_nd(int64_t D0, const std::function<void(int64_t)> &f) {
32 ACTIVATE_THREADPOOL;
33 dnnl::impl::parallel_nd(D0, f);
34}
35
36void benchdnn_parallel_nd(int64_t D0, int64_t D1,
37 const std::function<void(int64_t, int64_t)> &f) {
38 ACTIVATE_THREADPOOL;
39 dnnl::impl::parallel_nd(D0, D1, f);
40}
41
42void benchdnn_parallel_nd(int64_t D0, int64_t D1, int64_t D2,
43 const std::function<void(int64_t, int64_t, int64_t)> &f) {
44 ACTIVATE_THREADPOOL;
45 dnnl::impl::parallel_nd(D0, D1, D2, f);
46}
47
48void benchdnn_parallel_nd(int64_t D0, int64_t D1, int64_t D2, int64_t D3,
49 const std::function<void(int64_t, int64_t, int64_t, int64_t)> &f) {
50 ACTIVATE_THREADPOOL;
51 dnnl::impl::parallel_nd(D0, D1, D2, D3, f);
52}
53
54void benchdnn_parallel_nd(int64_t D0, int64_t D1, int64_t D2, int64_t D3,
55 int64_t D4,
56 const std::function<void(int64_t, int64_t, int64_t, int64_t, int64_t)>
57 &f) {
58 ACTIVATE_THREADPOOL;
59 dnnl::impl::parallel_nd(D0, D1, D2, D3, D4, f);
60}
61
62void benchdnn_parallel_nd(int64_t D0, int64_t D1, int64_t D2, int64_t D3,
63 int64_t D4, int64_t D5,
64 const std::function<void(
65 int64_t, int64_t, int64_t, int64_t, int64_t, int64_t)> &f) {
66 ACTIVATE_THREADPOOL;
67 dnnl::impl::parallel_nd(D0, D1, D2, D3, D4, D5, f);
68}
69