1 #include "dnnlowp_partition.h" 3 #include "caffe2/core/logging.h" 7 static size_t GetWorkPerThread_(
size_t work,
int nthreads,
int work_align) {
8 return ((work + work_align - 1) / work_align + nthreads - 1) / nthreads *
12 std::pair<size_t, size_t>
13 Get1DPartition(
size_t work,
int nthreads,
int tid,
int work_align ) {
14 size_t work_per_thread = GetWorkPerThread_(work, nthreads, work_align);
15 size_t work_begin = std::min(tid * work_per_thread, work);
16 size_t work_end = std::min(work_begin + work_per_thread, work);
17 return {work_begin, work_end};
32 std::tie(*m_begin, *m_end) = Get1DPartition(m, nthreads, tid);
39 int nthreads_per_row = nthreads / m;
40 *m_begin = std::max(std::min(tid / nthreads_per_row, m - 1), 0);
41 *m_end = std::min(*m_begin + 1, m);
43 int tid_of_m_begin = std::min(*m_begin * nthreads_per_row, nthreads);
44 int tid_of_m_end = std::min(
45 (*m_end == m) ? nthreads : (tid_of_m_begin + nthreads_per_row),
47 int nthreads_within_row = tid_of_m_end - tid_of_m_begin;
48 int tid_within_row = tid - tid_of_m_begin;
49 CAFFE_ENFORCE_GE(tid_within_row, 0);
50 CAFFE_ENFORCE_LT(tid_within_row, nthreads_within_row);
52 std::tie(*n_begin, *n_end) =
53 Get1DPartition(n, nthreads_within_row, tid_within_row, n_align);
A global dictionary that holds information about what Caffe2 modules have been loaded in the current ...
void Get1DPartitionOf2D(int m, int n, int nthreads, int tid, int *m_begin, int *m_end, int *n_begin, int *n_end, int n_align)
1D-partition m x n 2D work.