-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Setting parallel to tbb static partitioner or tbb auto partitoner by thread pool #30167
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Setting parallel to tbb static partitioner or tbb auto partitoner by thread pool #30167
Conversation
src/plugins/intel_cpu/src/nodes/executors/dnnl/dnnl_matmul_primitive.cpp
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With this design you decoupled ThreadPool and CpuParallel, but in fact the ThreadPool
should be a wrapper over CpuParallel object. I can only guess that this has been done to avoid circular dependency of storing CpuParallel
as a shared pointer in ThreadPool
. But CpuParallel
can be stored as a reference or week_ptr, the latter is less preferable due to performance implications though.
Could you please store CpuParallel
as a const reference inside ThreadPool
and redirect all the calls to this object?
class ThreadPool : public dnnl::threadpool_interop::threadpool_iface {
public:
ThreadPool() = delete;
ThreadPool(ThreadPool&) = delete;
ThreadPool& operator(ThreadPool&) = delete;
ThreadPool(ThreadPool&&) = delete;
ThreadPool& operator(ThreadPool&&) = delete;
explicit ThreadPool(const CpuParallel& cpu_parallel) : m_cpu_parallel(cpu_parallel) {}
[[nodiscard]] int get_num_threads() const override {
return m_cpu_parallel.get_num_threads();
}
[[nodiscard]] bool get_in_parallel() const override {
return false;
}
[[nodiscard]] uint64_t get_flags() const override {
return 0;
}
void parallel_for(int n, const std::function<void(int, int)>& fn) override {
m_cpu_parallel.parallel_simple(n, fn);
}
private:
const CpuParallel& cpu_parallel;
}
Also, just not to prolong the lifespan of the ThreadPool object more than the CpuParallel object, it does make sense to return a raw pointer instead of shared_ptr. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, decoupling ThreadPool and CpuParalle is to avoid circular dependency. If store CpuParallel as a reference in ThreadPool, this problem is still exists. In order to solve this issue, I abstracted a ICpuParallel which has the methods ThreadPool needed. Please take a look.
} | ||
|
||
private: | ||
const ICpuParallel& m_cpu_parallel; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please elaborate on why do we need ICpuParallel
here? Why can't we simply store const CpuParallel&
?
Suspect the reason might be in some dependency of the includes. But it looks like it may be resolved using forward declaration.
Also the virtual methods of the dnnl::threadpool_interop::threadpool_iface
can be defined in the .cpp
file as those are virtual functions anyway and aren't expected to be inline.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because there was a compilation problem before, it has been fixed now. ICpuParallel
is no longer needed, it was removed now.
|
||
template <typename T0, typename F> | ||
void cpu_parallel_for(const T0& D0, const F& func) const { | ||
void cpu_parallel_for(const T0& D0, const F& func) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please elaborate on the reason behind removing the const
qualifier?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added const again.
Details:
Tickets: