-
Notifications
You must be signed in to change notification settings - Fork 872
Xnnpack disable workspace nonlock #17780
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
base: main
Are you sure you want to change the base?
Changes from all commits
21d9bdd
7f4bb96
ccdbca7
019327b
3871367
93e9e76
1a97263
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -56,6 +56,7 @@ XNNWorkspaceManager::get_or_create_workspace(uintptr_t program_id) const { | |
| return create_result.error(); | ||
| } | ||
|
|
||
| create_result.get()->disable_locking(); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: Can we pass this in as a arg to XNNWorkspace::create? |
||
| return create_result.get(); | ||
| } else if (mode == WorkspaceSharingMode::PerModel) { | ||
| return get_or_create_model_workspace(program_id); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -107,6 +107,18 @@ TEST_F(XNNWorkspaceManagerTest, DisabledMode) { | |
| workspace2->unsafe_get_workspace(), workspace3->unsafe_get_workspace()); | ||
| } | ||
|
|
||
| TEST_F(XNNWorkspaceManagerTest, DisabledModeAcquireDoesNotLock) { | ||
| workspace_manager_->set_sharing_mode(WorkspaceSharingMode::Disabled); | ||
|
|
||
| auto workspace_result = workspace_manager_->get_or_create_workspace(12345); | ||
| ASSERT_TRUE(workspace_result.ok()); | ||
| auto workspace = workspace_result.get(); | ||
|
|
||
| auto [lock, ptr] = workspace->acquire(); | ||
| ASSERT_NE(ptr, nullptr); | ||
| EXPECT_FALSE(lock.owns_lock()); | ||
| } | ||
|
|
||
| TEST_F(XNNWorkspaceManagerTest, PerModelMode) { | ||
| // In PerModel mode, calls with the same program_id should return the same | ||
| // workspace. | ||
|
|
@@ -139,6 +151,18 @@ TEST_F(XNNWorkspaceManagerTest, PerModelMode) { | |
| workspace1->unsafe_get_workspace(), workspace3->unsafe_get_workspace()); | ||
| } | ||
|
|
||
| TEST_F(XNNWorkspaceManagerTest, PerModelAcquireStillLocks) { | ||
| workspace_manager_->set_sharing_mode(WorkspaceSharingMode::PerModel); | ||
|
|
||
| auto workspace_result = workspace_manager_->get_or_create_workspace(12345); | ||
| ASSERT_TRUE(workspace_result.ok()); | ||
| auto workspace = workspace_result.get(); | ||
|
|
||
| auto [lock, ptr] = workspace->acquire(); | ||
| ASSERT_NE(ptr, nullptr); | ||
| EXPECT_TRUE(lock.owns_lock()); | ||
| } | ||
|
Comment on lines
+154
to
+164
|
||
|
|
||
| TEST_F(XNNWorkspaceManagerTest, GlobalMode) { | ||
| // In Global mode, all calls should return the same workspace. | ||
| workspace_manager_->set_sharing_mode(WorkspaceSharingMode::Global); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
lock_required_field is a plainboolthat is written bydisable_locking()and read byacquire(). Although the current single call site inXNNWorkspaceManager.cppcallsdisable_locking()before the workspace is shared with any other thread (making it safe in practice), the publicdisable_locking()method has no documented threading constraints, and calling it on an already-shared workspace whileacquire()is being called concurrently from another thread would be an undefined behavior data race. Consider makinglock_required_astd::atomic<bool>to ensure correctness regardless of call order, or at minimum add a comment documenting the thread-safety requirement (that it must only be called before the workspace is shared with other threads).