-
Notifications
You must be signed in to change notification settings - Fork 787
[NFC][SYCL] Use context_impl &
in sampler_impl
ctor and near it
#19153
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
againull
merged 1 commit into
intel:sycl
from
aelovikov-intel:context_impl-sampler_impl
Jun 25, 2025
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,15 +24,14 @@ sampler_impl::sampler_impl(coordinate_normalization_mode normalizationMode, | |
verifyProps(MPropList); | ||
} | ||
|
||
sampler_impl::sampler_impl(cl_sampler clSampler, | ||
const ContextImplPtr &syclContext) { | ||
const AdapterPtr &Adapter = syclContext->getAdapter(); | ||
sampler_impl::sampler_impl(cl_sampler clSampler, context_impl &syclContext) { | ||
const AdapterPtr &Adapter = syclContext.getAdapter(); | ||
ur_sampler_handle_t Sampler{}; | ||
Adapter->call<UrApiKind::urSamplerCreateWithNativeHandle>( | ||
reinterpret_cast<ur_native_handle_t>(clSampler), | ||
syclContext->getHandleRef(), nullptr, &Sampler); | ||
syclContext.getHandleRef(), nullptr, &Sampler); | ||
|
||
MContextToSampler[syclContext] = Sampler; | ||
MContextToSampler[syclContext.shared_from_this()] = Sampler; | ||
bool NormalizedCoords; | ||
|
||
Adapter->call<UrApiKind::urSamplerGetInfo>( | ||
|
@@ -95,10 +94,14 @@ sampler_impl::~sampler_impl() { | |
} | ||
|
||
ur_sampler_handle_t | ||
sampler_impl::getOrCreateSampler(const ContextImplPtr &ContextImpl) { | ||
sampler_impl::getOrCreateSampler(context_impl &ContextImpl) { | ||
// Just for the `MContextToSampler` lookups. Could probably be changed once we | ||
// move to C++20 and would have heterogeneous lookup. | ||
std::shared_ptr<context_impl> ContextImplPtr = ContextImpl.shared_from_this(); | ||
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. This is extra overhead, but we have unconditional mutex lock below (and another one near return on non-exceptional code path), so shouldn't matter. |
||
|
||
{ | ||
std::lock_guard<std::mutex> Lock(MMutex); | ||
auto It = MContextToSampler.find(ContextImpl); | ||
auto It = MContextToSampler.find(ContextImplPtr); | ||
if (It != MContextToSampler.end()) | ||
return It->second; | ||
} | ||
|
@@ -135,18 +138,18 @@ sampler_impl::getOrCreateSampler(const ContextImplPtr &ContextImpl) { | |
|
||
ur_result_t errcode_ret = UR_RESULT_SUCCESS; | ||
ur_sampler_handle_t resultSampler = nullptr; | ||
const AdapterPtr &Adapter = ContextImpl->getAdapter(); | ||
const AdapterPtr &Adapter = ContextImpl.getAdapter(); | ||
|
||
errcode_ret = Adapter->call_nocheck<UrApiKind::urSamplerCreate>( | ||
ContextImpl->getHandleRef(), &desc, &resultSampler); | ||
ContextImpl.getHandleRef(), &desc, &resultSampler); | ||
|
||
if (errcode_ret == UR_RESULT_ERROR_UNSUPPORTED_FEATURE) | ||
throw sycl::exception(sycl::errc::feature_not_supported, | ||
"Images are not supported by this device."); | ||
|
||
Adapter->checkUrResult(errcode_ret); | ||
std::lock_guard<std::mutex> Lock(MMutex); | ||
MContextToSampler[ContextImpl] = resultSampler; | ||
MContextToSampler[ContextImplPtr] = resultSampler; | ||
|
||
return resultSampler; | ||
} | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
std::unordered_map::operator[]
was performing a copy internally before, now it can just move (and rvalue-ref overload is C++11, so available to us), so no significant (if at all) overhead here.