+
Skip to content

Change tensors to use Arc so they implement Send and Sync #236

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

Merged
merged 1 commit into from
Oct 12, 2022

Conversation

caelunshun
Copy link
Contributor

Currently, tensors use Rc to allow cloning the tensor without reallocating the data. However, Rc is neither Send or Sync, which prevents tensors and everything that contain them (most notably, Modules) from being moved to another thread.

For example, it is currently impossible to share a network across threads except via suboptimal workarounds like serializing the network to bytes on one thread and deserializing it on the other.

By using Arc, tensors now implement Send and Sync. The cost of using atomic operations should be negligible.

Currently, tensors use Rc to allow cloning the tensor without reallocating the data.
However, an Rc is neither Send or Sync, which prevents tensors and everything that contain
them (most notably, Modules) from being moved to another thread.

For example, it is currently impossible to share a network across threads except via suboptimal
workarounds like serializing the network to bytes on one thread and deserializing it on the other.

By using Arc, tensors now implement Send and Sync. The cost of using atomic operations should be negligible.
@coreylowman
Copy link
Owner

Hey thanks for this PR, this is a great minimal diff to look at and really big improvements to thread sharing! 😁 🚀

@coreylowman coreylowman merged commit c38bb9e into coreylowman:main Oct 12, 2022
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.

2 participants
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载