Skip to content

Commit

Permalink
Revert "common: thread: move parallel methods to std::function"
Browse files Browse the repository at this point in the history
This reverts commit 6bfbce3.
  • Loading branch information
antonvor committed Dec 20, 2021
1 parent dc53b55 commit 7cd4218
Show file tree
Hide file tree
Showing 2 changed files with 210 additions and 220 deletions.
103 changes: 2 additions & 101 deletions src/common/dnnl_thread.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
#define COMMON_DNNL_THREAD_HPP

#include <algorithm>
#include <functional>
#include <mutex>

#include "utils.hpp"
Expand Down Expand Up @@ -237,109 +236,11 @@ void balance2D(U nthr, U ithr, T ny, T &ny_start, T &ny_end, T nx, T &nx_start,
balance211(ny, grp_nthr, grp_ithr, ny_start, ny_end);
}

/* Functions:
* - parallel(nthr, f) - executes f in parallel using at
* most nthr threads. If nthr equals
* 0 dnnl_get_current_num_threads() threads
* is used
* - for_nd(ithr, nthr, dims..., f) - multidimensional for loop for
* already created threads
* - for_nd_ext(ithr, nthr, dims..., f) - multidimensional for loop for
* already created threads that passes
* ithr and nthr
* - parallel_nd(dims..., f) - creates a parallel section and then
* calls for_nd
* - parallel_nd_ext(dims..., f) - creates a parallel section and then
* calls for_nd_ext
* - parallel_nd_in_omp(dims..., f) - queries current nthr and ithr and
* then calls for_nd (mostly for
* convenience)
*/

/* general parallelization */
void DNNL_API parallel(int nthr, const std::function<void(int, int)> &f);

/* for_nd section */
void for_nd(const int ithr, const int nthr, dim_t D0,
const std::function<void(dim_t)> &f);
void for_nd(const int ithr, const int nthr, dim_t D0, dim_t D1,
const std::function<void(dim_t, dim_t)> &f);
void for_nd(const int ithr, const int nthr, dim_t D0, dim_t D1, dim_t D2,
const std::function<void(dim_t, dim_t, dim_t)> &f);
void for_nd(const int ithr, const int nthr, dim_t D0, dim_t D1, dim_t D2,
dim_t D3, const std::function<void(dim_t, dim_t, dim_t, dim_t)> &f);
void for_nd(const int ithr, const int nthr, dim_t D0, dim_t D1, dim_t D2,
dim_t D3, dim_t D4,
const std::function<void(dim_t, dim_t, dim_t, dim_t, dim_t)> &f);
void for_nd(const int ithr, const int nthr, dim_t D0, dim_t D1, dim_t D2,
dim_t D3, dim_t D4, dim_t D5,
const std::function<void(dim_t, dim_t, dim_t, dim_t, dim_t, dim_t)> &f);
/* for_nd_ext section */
void for_nd_ext(const int ithr, const int nthr, dim_t D0,
const std::function<void(int, int, dim_t)> &f);
void for_nd_ext(const int ithr, const int nthr, dim_t D0, dim_t D1,
const std::function<void(int, int, dim_t, dim_t)> &f);
void for_nd_ext(const int ithr, const int nthr, dim_t D0, dim_t D1, dim_t D2,
const std::function<void(int, int, dim_t, dim_t, dim_t)> &f);
void for_nd_ext(const int ithr, const int nthr, dim_t D0, dim_t D1, dim_t D2,
dim_t D3,
const std::function<void(int, int, dim_t, dim_t, dim_t, dim_t)> &f);
void for_nd_ext(const int ithr, const int nthr, dim_t D0, dim_t D1, dim_t D2,
dim_t D3, dim_t D4,
const std::function<void(int, int, dim_t, dim_t, dim_t, dim_t, dim_t)>
&f);
void for_nd_ext(const int ithr, const int nthr, dim_t D0, dim_t D1, dim_t D2,
dim_t D3, dim_t D4, dim_t D5,
const std::function<void(
int, int, dim_t, dim_t, dim_t, dim_t, dim_t, dim_t)> &f);
/* parallel_nd_ext section */
void parallel_nd_ext(
int nthr, dim_t D0, const std::function<void(int, int, dim_t)> &f);
void parallel_nd_ext(int nthr, dim_t D0, dim_t D1,
const std::function<void(int, int, dim_t, dim_t)> &f);
void parallel_nd_ext(int nthr, dim_t D0, dim_t D1, dim_t D2,
const std::function<void(int, int, dim_t, dim_t, dim_t)> &f);
void parallel_nd_ext(int nthr, dim_t D0, dim_t D1, dim_t D2, dim_t D3,
const std::function<void(int, int, dim_t, dim_t, dim_t, dim_t)> &f);
void parallel_nd_ext(int nthr, dim_t D0, dim_t D1, dim_t D2, dim_t D3, dim_t D4,
const std::function<void(int, int, dim_t, dim_t, dim_t, dim_t, dim_t)>
&f);
void parallel_nd_ext(int nthr, dim_t D0, dim_t D1, dim_t D2, dim_t D3, dim_t D4,
dim_t D5,
const std::function<void(
int, int, dim_t, dim_t, dim_t, dim_t, dim_t, dim_t)> &f);
/* parallel_nd section */
void DNNL_API parallel_nd(dim_t D0, const std::function<void(dim_t)> &f);
void DNNL_API parallel_nd(
dim_t D0, dim_t D1, const std::function<void(dim_t, dim_t)> &f);
void DNNL_API parallel_nd(dim_t D0, dim_t D1, dim_t D2,
const std::function<void(dim_t, dim_t, dim_t)> &f);
void DNNL_API parallel_nd(dim_t D0, dim_t D1, dim_t D2, dim_t D3,
const std::function<void(dim_t, dim_t, dim_t, dim_t)> &f);
void DNNL_API parallel_nd(dim_t D0, dim_t D1, dim_t D2, dim_t D3, dim_t D4,
const std::function<void(dim_t, dim_t, dim_t, dim_t, dim_t)> &f);
void DNNL_API parallel_nd(dim_t D0, dim_t D1, dim_t D2, dim_t D3, dim_t D4,
dim_t D5,
const std::function<void(dim_t, dim_t, dim_t, dim_t, dim_t, dim_t)> &f);
/* parallel_nd_in_omp section */

template <typename... Args>
void parallel_nd_in_omp(Args &&... args) {
#if DNNL_CPU_THREADING_RUNTIME == DNNL_RUNTIME_SEQ
for_nd(0, 1, utils::forward<Args>(args)...);
#elif DNNL_CPU_THREADING_RUNTIME == DNNL_RUNTIME_OMP
for_nd(omp_get_thread_num(), omp_get_num_threads(),
utils::forward<Args>(args)...);
#elif (DNNL_CPU_THREADING_RUNTIME == DNNL_RUNTIME_TBB \
|| DNNL_CPU_THREADING_RUNTIME == DNNL_RUNTIME_TBB_AUTO \
|| DNNL_CPU_THREADING_RUNTIME == DNNL_RUNTIME_THREADPOOL)
assert(!"parallel_nd_in_omp() is not supported by this DNNL_CPU_RUNTIME");
#endif
}

} // namespace impl
} // namespace dnnl

#include "dnnl_thread_parallel_nd.hpp"

#endif

// vim: et ts=4 sw=4 cindent cino+=l0,\:4,N-s
Loading

0 comments on commit 7cd4218

Please sign in to comment.