Skip to content

[Question]: Way to set the number of threads? #1285

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

Closed
andredasilvapinto opened this issue Jan 31, 2025 · 1 comment
Closed

[Question]: Way to set the number of threads? #1285

andredasilvapinto opened this issue Jan 31, 2025 · 1 comment

Comments

@andredasilvapinto
Copy link

andredasilvapinto commented Jan 31, 2025

Description

We are seeing that a lot of native threads are being created (probably because the number is set as a multiple of the number of cores) and not really doing anything.

Is there a way to specify the number of threads?

Alternatives

No response

@andredasilvapinto
Copy link
Author

andredasilvapinto commented Feb 3, 2025

Answering my own question, in the version we are using (0.60.4) it seems we can do it via:

using var options = c_api.TF_NewSessionOptions();
var config = new ConfigProto
{
    InterOpParallelismThreads = X,
    IntraOpParallelismThreads = Y
};

var cfgByteArray = config.ToByteArray();
fixed (byte* cfgPtr = cfgByteArray)
{
    using var status = new Status();
    c_api.TF_SetConfig(options, (IntPtr)cfgPtr, (ulong)cfgByteArray.Length, status.Handle);
    status.Check(true);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant