Skip to content

Conversation

sunxiaoxia2022
Copy link
Contributor

@sunxiaoxia2022 sunxiaoxia2022 commented Apr 16, 2025

Details:

Tickets:

@sunxiaoxia2022 sunxiaoxia2022 requested review from a team as code owners April 16, 2025 03:43
@github-actions github-actions bot added category: Core OpenVINO Core (aka ngraph) category: CPU OpenVINO CPU plugin category: build OpenVINO cmake script / infra category: CPP API OpenVINO CPP API bindings labels Apr 16, 2025
@mlukasze mlukasze requested a review from ilya-lavrenov April 17, 2025 07:04
@maxnick maxnick self-assigned this Apr 22, 2025
@github-actions github-actions bot removed category: Core OpenVINO Core (aka ngraph) category: CPP API OpenVINO CPP API bindings labels Apr 30, 2025
@sunxiaoxia2022
Copy link
Contributor Author

Could you please create a oneDNN fork PR to make the review more convenient?

@maxnick Yes, created oneDNN PR291

Copy link
Contributor

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?

Copy link
Contributor Author

@sunxiaoxia2022 sunxiaoxia2022 Sep 26, 2025

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.

@maxnick maxnick added this to the 2025.4 milestone Sep 23, 2025
}

private:
const ICpuParallel& m_cpu_parallel;
Copy link
Contributor

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.

Copy link
Contributor Author

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) {
Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added const again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category: build OpenVINO cmake script / infra category: Core OpenVINO Core (aka ngraph) category: CPP API OpenVINO CPP API bindings category: CPU OpenVINO CPU plugin category: inference OpenVINO Runtime library - Inference category: Python API OpenVINO Python bindings
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants