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

[SYCL] Remove half from global namespace #4818

Merged
merged 1 commit into from
Oct 26, 2021

Conversation

vladimirlaz
Copy link
Contributor

@vladimirlaz vladimirlaz commented Oct 26, 2021

API removal has been approved.

@vladimirlaz vladimirlaz requested a review from a team as a code owner October 26, 2021 05:39
@vladimirlaz
Copy link
Contributor Author

/summary:run

@bader bader changed the title Remove half from global namespace [SYCL] Remove half from global namespace Oct 26, 2021
@bader bader merged commit c9128e6 into intel:sycl Oct 26, 2021
npmiller added a commit to npmiller/oneMKL that referenced this pull request Nov 16, 2021
`half` has been removed from the global scope in DPC++, see
intel/llvm#4818
mkrainiuk pushed a commit to uxlfoundation/oneMath that referenced this pull request Nov 17, 2021
* [cublas] Fix race condition in cublas handle deletion

This was causing segmentation faults at the end of the program when
running tests.

Cublas handles need to be created per thread and per context, therefore
they're currently being stored in a `static thread_local` map, mapping
contexts to cublas handles.

These handles are deleted in two places, the map destructor called when
the thread is deleted, or the context destructor, where a callback is
registered on the context to delete the cublas handle.

Since there is two places where a handle can be deleted and that these
two will likely run in separate threads, the handle was placed in an
C++ atomic to avoid race conditions, and allocated on the heap so that
it can stay alive when one of either the thread or the context is
deleted.

But there was two issues with this, the main one is that the callback
registered on the context was not given the pointer to the atomic
handle, rather the pointer to the slot in the `thread_local` map where
the atomic pointer was stored. Which meant that whenever the thread
would be deleted before the context, the pointer available to the
callback would be invalid as the map was deleted. The solution for that
is to simply pass directly the pointer to the atomic handle to the
callback.

The second issue is that both of these places were deleting the atomic
in all cases, which means one of the deletion was invalid. The solution
for this is to only do the deletion in the last one being called, that
is to say the one which will get a `nullptr` when atomically accessing
the handle pointer.

With these two patches the tests are running fine.

* [cublas] Fix formatting of cublas handle patch

* Fix half types for DPC++

`half` has been removed from the global scope in DPC++, see
intel/llvm#4818
sbalint98 pushed a commit to sbalint98/oneMKL that referenced this pull request Dec 6, 2021
)

* [cublas] Fix race condition in cublas handle deletion

This was causing segmentation faults at the end of the program when
running tests.

Cublas handles need to be created per thread and per context, therefore
they're currently being stored in a `static thread_local` map, mapping
contexts to cublas handles.

These handles are deleted in two places, the map destructor called when
the thread is deleted, or the context destructor, where a callback is
registered on the context to delete the cublas handle.

Since there is two places where a handle can be deleted and that these
two will likely run in separate threads, the handle was placed in an
C++ atomic to avoid race conditions, and allocated on the heap so that
it can stay alive when one of either the thread or the context is
deleted.

But there was two issues with this, the main one is that the callback
registered on the context was not given the pointer to the atomic
handle, rather the pointer to the slot in the `thread_local` map where
the atomic pointer was stored. Which meant that whenever the thread
would be deleted before the context, the pointer available to the
callback would be invalid as the map was deleted. The solution for that
is to simply pass directly the pointer to the atomic handle to the
callback.

The second issue is that both of these places were deleting the atomic
in all cases, which means one of the deletion was invalid. The solution
for this is to only do the deletion in the last one being called, that
is to say the one which will get a `nullptr` when atomically accessing
the handle pointer.

With these two patches the tests are running fine.

* [cublas] Fix formatting of cublas handle patch

* Fix half types for DPC++

`half` has been removed from the global scope in DPC++, see
intel/llvm#4818
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