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

Add capability to set a default device for all threads #699

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

jeremyfelder
Copy link
Collaborator

Describe the changes

This PR adds the capability to set a default device for all threads. Setting a default device does not override a thread's explicitly set device

eIcicleError set_default_device(const Device& dev)
{
if (!is_device_registered(dev.type)) {
THROW_ICICLE_ERR(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why not return an error and do nothing? instead of crashing

Copy link
Contributor

Choose a reason for hiding this comment

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

I assume that the user doesn't have a set_device on each thread so returning an error here will result on making the program run on cpu instead of what the user wanted

Copy link
Collaborator

Choose a reason for hiding this comment

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

Then he should not ignore errors. But ok

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I prefer not throwing here and allow the user to decide to terminate or fallback to CPU as the original default.

There are other areas in our code I think we should make this change but I was following what we did elsewhere

THROW_ICICLE_ERR(
eIcicleError::INVALID_DEVICE, "Device type " + std::string(dev.type) + " has not been registered");
}
m_default_device = dev;
Copy link
Collaborator

Choose a reason for hiding this comment

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

note that this is not thread safe. Not sure if it's a problem though, since users are not supposed to call this from multiple threads.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I will add docs for this and will mention it there

Copy link
Collaborator

@yshekel yshekel left a comment

Choose a reason for hiding this comment

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

Nice !!

@jeremyfelder jeremyfelder force-pushed the feat/set-default-device branch from 0604e41 to e61b6c6 Compare December 26, 2024 11:18
@jeremyfelder jeremyfelder force-pushed the feat/set-default-device branch from b6246a0 to f1dbb8a Compare December 30, 2024 13:35
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

Successfully merging this pull request may close these issues.

3 participants