Skip to content

Commit 8cec943

Browse files
[NFC][SYCL] Prepare backend.cpp for getSyclObjImpl to return raw ref (#19248)
I'm planning to change `getSyclObjImpl` to return a raw reference in a later patch, uploading a bunch of PRs in preparation to that to make the subsequent review easier.
1 parent 80b1f60 commit 8cec943

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

sycl/source/backend.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -172,15 +172,15 @@ __SYCL_EXPORT event make_event(ur_native_handle_t NativeHandle,
172172
const context &Context, bool KeepOwnership,
173173
backend Backend) {
174174
const adapter_impl &Adapter = getAdapter(Backend);
175-
const auto &ContextImpl = getSyclObjImpl(Context);
175+
context_impl &ContextImpl = *getSyclObjImpl(Context);
176176

177177
ur_event_handle_t UrEvent = nullptr;
178178
ur_event_native_properties_t Properties{};
179179
Properties.stype = UR_STRUCTURE_TYPE_EVENT_NATIVE_PROPERTIES;
180180
Properties.isNativeHandleOwned = !KeepOwnership;
181181

182182
Adapter.call<UrApiKind::urEventCreateWithNativeHandle>(
183-
NativeHandle, ContextImpl->getHandleRef(), &Properties, &UrEvent);
183+
NativeHandle, ContextImpl.getHandleRef(), &Properties, &UrEvent);
184184
event Event = detail::createSyclObjFromImpl<event>(
185185
event_impl::create_from_handle(UrEvent, Context));
186186

@@ -194,21 +194,21 @@ make_kernel_bundle(ur_native_handle_t NativeHandle,
194194
const context &TargetContext, bool KeepOwnership,
195195
bundle_state State, backend Backend) {
196196
const adapter_impl &Adapter = getAdapter(Backend);
197-
const auto &ContextImpl = getSyclObjImpl(TargetContext);
197+
context_impl &ContextImpl = *getSyclObjImpl(TargetContext);
198198

199199
ur_program_handle_t UrProgram = nullptr;
200200
ur_program_native_properties_t Properties{};
201201
Properties.stype = UR_STRUCTURE_TYPE_PROGRAM_NATIVE_PROPERTIES;
202202
Properties.isNativeHandleOwned = !KeepOwnership;
203203

204204
Adapter.call<UrApiKind::urProgramCreateWithNativeHandle>(
205-
NativeHandle, ContextImpl->getHandleRef(), &Properties, &UrProgram);
205+
NativeHandle, ContextImpl.getHandleRef(), &Properties, &UrProgram);
206206
if (UrProgram == nullptr)
207207
throw sycl::exception(
208208
sycl::make_error_code(sycl::errc::invalid),
209209
"urProgramCreateWithNativeHandle resulted in a null program handle.");
210210

211-
if (ContextImpl->getBackend() == backend::opencl)
211+
if (ContextImpl.getBackend() == backend::opencl)
212212
__SYCL_OCL_CALL(clRetainProgram, ur::cast<cl_program>(NativeHandle));
213213

214214
std::vector<ur_device_handle_t> ProgramDevices;
@@ -234,7 +234,7 @@ make_kernel_bundle(ur_native_handle_t NativeHandle,
234234
UrProgram, 1, &Dev, nullptr);
235235
if (Res == UR_RESULT_ERROR_UNSUPPORTED_FEATURE) {
236236
Res = Adapter.call_nocheck<UrApiKind::urProgramCompile>(
237-
ContextImpl->getHandleRef(), UrProgram, nullptr);
237+
ContextImpl.getHandleRef(), UrProgram, nullptr);
238238
}
239239
Adapter.checkUrResult<errc::build>(Res);
240240
}
@@ -244,7 +244,7 @@ make_kernel_bundle(ur_native_handle_t NativeHandle,
244244
UrProgram, 1, &Dev, nullptr);
245245
if (Res == UR_RESULT_ERROR_UNSUPPORTED_FEATURE) {
246246
Res = Adapter.call_nocheck<UrApiKind::urProgramBuild>(
247-
ContextImpl->getHandleRef(), UrProgram, nullptr);
247+
ContextImpl.getHandleRef(), UrProgram, nullptr);
248248
}
249249
Adapter.checkUrResult<errc::build>(Res);
250250
}
@@ -260,11 +260,11 @@ make_kernel_bundle(ur_native_handle_t NativeHandle,
260260
if (State == bundle_state::executable) {
261261
ur_program_handle_t UrLinkedProgram = nullptr;
262262
auto Res = Adapter.call_nocheck<UrApiKind::urProgramLinkExp>(
263-
ContextImpl->getHandleRef(), 1, &Dev, 1, &UrProgram, nullptr,
263+
ContextImpl.getHandleRef(), 1, &Dev, 1, &UrProgram, nullptr,
264264
&UrLinkedProgram);
265265
if (Res == UR_RESULT_ERROR_UNSUPPORTED_FEATURE) {
266266
Res = Adapter.call_nocheck<UrApiKind::urProgramLink>(
267-
ContextImpl->getHandleRef(), 1, &UrProgram, nullptr,
267+
ContextImpl.getHandleRef(), 1, &UrProgram, nullptr,
268268
&UrLinkedProgram);
269269
}
270270
Adapter.checkUrResult<errc::build>(Res);
@@ -322,7 +322,7 @@ kernel make_kernel(const context &TargetContext,
322322
ur_native_handle_t NativeHandle, bool KeepOwnership,
323323
backend Backend) {
324324
const auto &Adapter = getAdapter(Backend);
325-
const auto &ContextImpl = getSyclObjImpl(TargetContext);
325+
context_impl &ContextImpl = *getSyclObjImpl(TargetContext);
326326
kernel_bundle_impl &KernelBundleImpl = *getSyclObjImpl(KernelBundle);
327327

328328
// For Level-Zero expect exactly one device image in the bundle. This is
@@ -342,8 +342,8 @@ kernel make_kernel(const context &TargetContext,
342342

343343
const device_image<bundle_state::executable> &DeviceImage =
344344
*KernelBundle.begin();
345-
const auto &DeviceImageImpl = getSyclObjImpl(DeviceImage);
346-
UrProgram = DeviceImageImpl->get_ur_program_ref();
345+
device_image_impl &DeviceImageImpl = *getSyclObjImpl(DeviceImage);
346+
UrProgram = DeviceImageImpl.get_ur_program_ref();
347347
}
348348

349349
// Create UR kernel first.
@@ -352,15 +352,15 @@ kernel make_kernel(const context &TargetContext,
352352
Properties.stype = UR_STRUCTURE_TYPE_KERNEL_NATIVE_PROPERTIES;
353353
Properties.isNativeHandleOwned = !KeepOwnership;
354354
Adapter.call<UrApiKind::urKernelCreateWithNativeHandle>(
355-
NativeHandle, ContextImpl->getHandleRef(), UrProgram, &Properties,
355+
NativeHandle, ContextImpl.getHandleRef(), UrProgram, &Properties,
356356
&UrKernel);
357357

358358
if (Backend == backend::opencl)
359359
__SYCL_OCL_CALL(clRetainKernel, ur::cast<cl_kernel>(NativeHandle));
360360

361361
// Construct the SYCL queue from UR queue.
362362
return detail::createSyclObjFromImpl<kernel>(
363-
std::make_shared<kernel_impl>(UrKernel, *ContextImpl, &KernelBundleImpl));
363+
std::make_shared<kernel_impl>(UrKernel, ContextImpl, &KernelBundleImpl));
364364
}
365365

366366
kernel make_kernel(ur_native_handle_t NativeHandle,

0 commit comments

Comments
 (0)