Skip to content
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

[Documentation] Can CPUEP infer multithread with one session? #22967

Open
kq566 opened this issue Nov 28, 2024 · 5 comments
Open

[Documentation] Can CPUEP infer multithread with one session? #22967

kq566 opened this issue Nov 28, 2024 · 5 comments
Labels
documentation improvements or additions to documentation; typically submitted using template

Comments

@kq566
Copy link

kq566 commented Nov 28, 2024

Describe the documentation issue

I have one Ort::Session. Can I use multithreads with one session? My code is roughly set up like this and works, but during execution, it doesn't utilize all 16 CPU cores.

Ort::SessionOptions session_options;
session_options.SetIntraOpNumThreads(4);
Ort::Session session;

std::vector<std::thread> threads;
for (int i =0; i< 4; ++i)
{
    threads.push_back(session.Run());
}
for (auto t : threads)
{
    t.jion();
}

I would like to ask if this multi-threading approach is recommended. Is there a better way to implement multi-threaded inference to increase throughput?

Page / URL

No response

@kq566 kq566 added the documentation improvements or additions to documentation; typically submitted using template label Nov 28, 2024
@skottmckay
Copy link
Contributor

Sessions are stateless so you can call Run concurrently.

@kq566
Copy link
Author

kq566 commented Nov 29, 2024

Sessions are stateless so you can call Run concurrently.

Thank you very much for your reply. I have another question. Since Run can be called concurrently, does each Run in my example use 4 CPU cores? Is it possible to fully utilize all 16 CPU cores?

@wejoncy
Copy link
Contributor

wejoncy commented Dec 3, 2024

Try setting kOrtSessionOptionsConfigAllowIntraOpSpinning

static const char* const kOrtSessionOptionsConfigAllowIntraOpSpinning = "session.intra_op.allow_spinning";

to 0, which might help

@kq566
Copy link
Author

kq566 commented Dec 3, 2024

kOrtSessionOptionsConfigAllowIntraOpSpinning

@wejoncy Thank you very much for your reply. I tried this parameter, but it doesn't seem to work. I also noticed that when I set n threads, the total number of cores is n, and each thread seems to be limited to using only one CPU core? Are there any other settings that allow configuring the number of CPU cores each thread can use?

@wejoncy
Copy link
Contributor

wejoncy commented Dec 3, 2024

Actually, "use 4 CPU cores" in one session is expected in one session even you run this session concurrently. SetIntraOpNumThreads is the only one you can configure thread-nums.

you can set thread-numbers to 16 and run them in a batch. The session will use all cores then.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation improvements or additions to documentation; typically submitted using template
Projects
None yet
Development

No branches or pull requests

3 participants