Skip to content

[SYCL][NFC] Return adapter by ref in KernelProgramCache #19186

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 3 commits into from
Jul 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions sycl/source/detail/kernel_program_cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@
//
//===----------------------------------------------------------------------===//

#include <detail/adapter_impl.hpp>
#include <detail/context_impl.hpp>
#include <detail/kernel_program_cache.hpp>

namespace sycl {
inline namespace _V1 {
namespace detail {
const AdapterPtr &KernelProgramCache::getAdapter() {
return MParentContext->getAdapter();
const adapter_impl &KernelProgramCache::getAdapter() {
return *(MParentContext->getAdapter());
}

ur_context_handle_t KernelProgramCache::getURContext() const {
Expand Down
28 changes: 14 additions & 14 deletions sycl/source/detail/kernel_program_cache.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,21 +112,21 @@ class KernelProgramCache {
};

struct ProgramBuildResult : public BuildResult<ur_program_handle_t> {
AdapterPtr MAdapter;
ProgramBuildResult(const AdapterPtr &AAdapter) : MAdapter(AAdapter) {
const adapter_impl &MAdapter;
ProgramBuildResult(const adapter_impl &Adapter) : MAdapter(Adapter) {
Val = nullptr;
}
ProgramBuildResult(const AdapterPtr &AAdapter, BuildState InitialState)
: MAdapter(AAdapter) {
ProgramBuildResult(const adapter_impl &Adapter, BuildState InitialState)
: MAdapter(Adapter) {
Val = nullptr;
this->State.store(InitialState);
}
~ProgramBuildResult() {
try {
if (Val) {
ur_result_t Err =
MAdapter->call_nocheck<UrApiKind::urProgramRelease>(Val);
__SYCL_CHECK_UR_CODE_NO_EXC(Err, MAdapter->getBackend());
MAdapter.call_nocheck<UrApiKind::urProgramRelease>(Val);
__SYCL_CHECK_UR_CODE_NO_EXC(Err, MAdapter.getBackend());
}
} catch (std::exception &e) {
__SYCL_REPORT_EXCEPTION_TO_STREAM("exception in ~ProgramBuildResult",
Expand Down Expand Up @@ -198,16 +198,16 @@ class KernelProgramCache {
using KernelArgMaskPairT =
std::pair<ur_kernel_handle_t, const KernelArgMask *>;
struct KernelBuildResult : public BuildResult<KernelArgMaskPairT> {
AdapterPtr MAdapter;
KernelBuildResult(const AdapterPtr &AAdapter) : MAdapter(AAdapter) {
const adapter_impl &MAdapter;
KernelBuildResult(const adapter_impl &Adapter) : MAdapter(Adapter) {
Val.first = nullptr;
}
~KernelBuildResult() {
try {
if (Val.first) {
ur_result_t Err =
MAdapter->call_nocheck<UrApiKind::urKernelRelease>(Val.first);
__SYCL_CHECK_UR_CODE_NO_EXC(Err, MAdapter->getBackend());
MAdapter.call_nocheck<UrApiKind::urKernelRelease>(Val.first);
__SYCL_CHECK_UR_CODE_NO_EXC(Err, MAdapter.getBackend());
}
} catch (std::exception &e) {
__SYCL_REPORT_EXCEPTION_TO_STREAM("exception in ~KernelBuildResult", e);
Expand Down Expand Up @@ -668,18 +668,18 @@ class KernelProgramCache {
// Store size of the program and check if we need to evict some entries.
// Get Size of the program.
size_t ProgramSize = 0;
auto Adapter = getAdapter();
const adapter_impl &Adapter = getAdapter();

try {
// Get number of devices this program was built for.
unsigned int DeviceNum = 0;
Adapter->call<UrApiKind::urProgramGetInfo>(
Adapter.call<UrApiKind::urProgramGetInfo>(
Program, UR_PROGRAM_INFO_NUM_DEVICES, sizeof(DeviceNum), &DeviceNum,
nullptr);

// Get binary sizes for each device.
std::vector<size_t> BinarySizes(DeviceNum);
Adapter->call<UrApiKind::urProgramGetInfo>(
Adapter.call<UrApiKind::urProgramGetInfo>(
Program, UR_PROGRAM_INFO_BINARY_SIZES,
sizeof(size_t) * BinarySizes.size(), BinarySizes.data(), nullptr);

Expand Down Expand Up @@ -868,7 +868,7 @@ class KernelProgramCache {

friend class ::MockKernelProgramCache;

const AdapterPtr &getAdapter();
const adapter_impl &getAdapter();
ur_context_handle_t getURContext() const;
};
} // namespace detail
Expand Down
Loading