Skip to content

Commit 3f0530c

Browse files
[SYCL][NFC] Make kernel_impl::getAdapter() return by reference (#19313)
It's a part of larger refactoring effort to pass adapter via reference instead of pointer everywhere in the codebase. Follow-up of: #19186 #19184 #19187 #19202 #19299 #19312
1 parent 92690a3 commit 3f0530c

File tree

6 files changed

+53
-53
lines changed

6 files changed

+53
-53
lines changed

sycl/source/detail/error_handling/error_handling.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ void handleErrorOrWarning(ur_result_t Error, const device_impl &DeviceImpl,
469469

470470
namespace detail::kernel_get_group_info {
471471
void handleErrorOrWarning(ur_result_t Error, ur_kernel_group_info_t Descriptor,
472-
const AdapterPtr &Adapter) {
472+
adapter_impl &Adapter) {
473473
assert(Error != UR_RESULT_SUCCESS &&
474474
"Success is expected to be handled on caller side");
475475
switch (Error) {
@@ -483,7 +483,7 @@ void handleErrorOrWarning(ur_result_t Error, ur_kernel_group_info_t Descriptor,
483483
break;
484484
// TODO: Handle other error codes
485485
default:
486-
Adapter->checkUrResult(Error);
486+
Adapter.checkUrResult(Error);
487487
break;
488488
}
489489
}

sycl/source/detail/error_handling/error_handling.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@ void handleErrorOrWarning(ur_result_t, const device_impl &, ur_kernel_handle_t,
3131

3232
namespace kernel_get_group_info {
3333
/// Analyzes error code of urKernelGetGroupInfo.
34-
void handleErrorOrWarning(ur_result_t, ur_kernel_group_info_t,
35-
const AdapterPtr &);
34+
void handleErrorOrWarning(ur_result_t, ur_kernel_group_info_t, adapter_impl &);
3635
} // namespace kernel_get_group_info
3736

3837
} // namespace detail

sycl/source/detail/kernel_impl.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ kernel_impl::kernel_impl(ur_kernel_handle_t Kernel, context_impl &Context,
2828
MIsInterop(true), MKernelArgMaskPtr{ArgMask} {
2929
ur_context_handle_t UrContext = nullptr;
3030
// Using the adapter from the passed ContextImpl
31-
getAdapter()->call<UrApiKind::urKernelGetInfo>(
31+
getAdapter().call<UrApiKind::urKernelGetInfo>(
3232
MKernel, UR_KERNEL_INFO_CONTEXT, sizeof(UrContext), &UrContext, nullptr);
3333
if (Context.getHandleRef() != UrContext)
3434
throw sycl::exception(
@@ -61,7 +61,7 @@ kernel_impl::kernel_impl(ur_kernel_handle_t Kernel, context_impl &ContextImpl,
6161
kernel_impl::~kernel_impl() {
6262
try {
6363
// TODO catch an exception and put it to list of asynchronous exceptions
64-
getAdapter()->call<UrApiKind::urKernelRelease>(MKernel);
64+
getAdapter().call<UrApiKind::urKernelRelease>(MKernel);
6565
} catch (std::exception &e) {
6666
__SYCL_REPORT_EXCEPTION_TO_STREAM("exception in ~kernel_impl", e);
6767
}
@@ -135,7 +135,7 @@ void kernel_impl::enableUSMIndirectAccess() const {
135135
// Some UR Adapters (like OpenCL) require this call to enable USM
136136
// For others, UR will turn this into a NOP.
137137
bool EnableAccess = true;
138-
getAdapter()->call<UrApiKind::urKernelSetExecInfo>(
138+
getAdapter().call<UrApiKind::urKernelSetExecInfo>(
139139
MKernel, UR_KERNEL_EXEC_INFO_USM_INDIRECT_ACCESS, sizeof(ur_bool_t),
140140
nullptr, &EnableAccess);
141141
}

sycl/source/detail/kernel_impl.hpp

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,13 @@ class kernel_impl {
7575
/// \return a valid cl_kernel instance
7676
cl_kernel get() const {
7777
ur_native_handle_t nativeHandle = 0;
78-
getAdapter()->call<UrApiKind::urKernelGetNativeHandle>(MKernel,
79-
&nativeHandle);
78+
getAdapter().call<UrApiKind::urKernelGetNativeHandle>(MKernel,
79+
&nativeHandle);
8080
__SYCL_OCL_CALL(clRetainKernel, ur::cast<cl_kernel>(nativeHandle));
8181
return ur::cast<cl_kernel>(nativeHandle);
8282
}
8383

84-
const AdapterPtr &getAdapter() const { return MContext->getAdapter(); }
84+
adapter_impl &getAdapter() const { return *MContext->getAdapter(); }
8585

8686
/// Query information from the kernel object using the info::kernel_info
8787
/// descriptor.
@@ -360,7 +360,7 @@ kernel_impl::queryMaxNumWorkGroups(queue Queue,
360360
throw exception(sycl::make_error_code(errc::invalid),
361361
"The launch work-group size cannot be zero.");
362362

363-
const auto &Adapter = getAdapter();
363+
adapter_impl &Adapter = getAdapter();
364364
const auto &Handle = getHandleRef();
365365
auto Device = Queue.get_device();
366366
auto DeviceHandleRef = sycl::detail::getSyclObjImpl(Device)->getHandleRef();
@@ -373,15 +373,16 @@ kernel_impl::queryMaxNumWorkGroups(queue Queue,
373373
WG[2] = WorkGroupSize[2];
374374

375375
uint32_t GroupCount{0};
376-
if (auto Result = Adapter->call_nocheck<
377-
UrApiKind::urKernelSuggestMaxCooperativeGroupCount>(
378-
Handle, DeviceHandleRef, Dimensions, WG, DynamicLocalMemorySize,
379-
&GroupCount);
376+
if (auto Result =
377+
Adapter
378+
.call_nocheck<UrApiKind::urKernelSuggestMaxCooperativeGroupCount>(
379+
Handle, DeviceHandleRef, Dimensions, WG,
380+
DynamicLocalMemorySize, &GroupCount);
380381
Result != UR_RESULT_ERROR_UNSUPPORTED_FEATURE &&
381382
Result != UR_RESULT_ERROR_INVALID_WORK_GROUP_SIZE) {
382383
// The feature is supported and the group size is valid. Check for other
383384
// errors and throw if any.
384-
Adapter->checkUrResult(Result);
385+
Adapter.checkUrResult(Result);
385386
return GroupCount;
386387
}
387388

@@ -452,12 +453,12 @@ inline typename syclex::info::kernel_queue_specific::max_work_group_size::
452453
kernel_impl::ext_oneapi_get_info<
453454
syclex::info::kernel_queue_specific::max_work_group_size>(
454455
queue Queue) const {
455-
const auto &Adapter = getAdapter();
456+
adapter_impl &Adapter = getAdapter();
456457
const auto DeviceNativeHandle =
457458
getSyclObjImpl(Queue.get_device())->getHandleRef();
458459

459460
size_t KernelWGSize = 0;
460-
Adapter->call<UrApiKind::urKernelGetGroupInfo>(
461+
Adapter.call<UrApiKind::urKernelGetGroupInfo>(
461462
MKernel, DeviceNativeHandle, UR_KERNEL_GROUP_INFO_WORK_GROUP_SIZE,
462463
sizeof(size_t), &KernelWGSize, nullptr);
463464
return KernelWGSize;
@@ -508,13 +509,13 @@ ADD_TEMPLATE_METHOD_SPEC(3)
508509
if (WG.size() == 0) \
509510
throw exception(sycl::make_error_code(errc::invalid), \
510511
"The work-group size cannot be zero."); \
511-
const auto &Adapter = getAdapter(); \
512+
adapter_impl &Adapter = getAdapter(); \
512513
const auto DeviceNativeHandle = \
513514
getSyclObjImpl(Queue.get_device())->getHandleRef(); \
514515
uint32_t KernelSubWGSize = 0; \
515-
Adapter->call<UrApiKind::Kind>(MKernel, DeviceNativeHandle, Reg, \
516-
sizeof(uint32_t), &KernelSubWGSize, \
517-
nullptr); \
516+
Adapter.call<UrApiKind::Kind>(MKernel, DeviceNativeHandle, Reg, \
517+
sizeof(uint32_t), &KernelSubWGSize, \
518+
nullptr); \
518519
return KernelSubWGSize; \
519520
}
520521

sycl/source/detail/kernel_info.hpp

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -45,33 +45,33 @@ template <typename Param>
4545
typename std::enable_if<
4646
std::is_same<typename Param::return_type, std::string>::value,
4747
std::string>::type
48-
get_kernel_info(ur_kernel_handle_t Kernel, const AdapterPtr &Adapter) {
48+
get_kernel_info(ur_kernel_handle_t Kernel, adapter_impl &Adapter) {
4949
static_assert(detail::is_kernel_info_desc<Param>::value,
5050
"Invalid kernel information descriptor");
5151
size_t ResultSize = 0;
5252

5353
// TODO catch an exception and put it to list of asynchronous exceptions
54-
Adapter->call<UrApiKind::urKernelGetInfo>(Kernel, UrInfoCode<Param>::value, 0,
55-
nullptr, &ResultSize);
54+
Adapter.call<UrApiKind::urKernelGetInfo>(Kernel, UrInfoCode<Param>::value, 0,
55+
nullptr, &ResultSize);
5656
if (ResultSize == 0) {
5757
return "";
5858
}
5959
std::vector<char> Result(ResultSize);
6060
// TODO catch an exception and put it to list of asynchronous exceptions
61-
Adapter->call<UrApiKind::urKernelGetInfo>(Kernel, UrInfoCode<Param>::value,
62-
ResultSize, Result.data(), nullptr);
61+
Adapter.call<UrApiKind::urKernelGetInfo>(Kernel, UrInfoCode<Param>::value,
62+
ResultSize, Result.data(), nullptr);
6363
return std::string(Result.data());
6464
}
6565

6666
template <typename Param>
6767
typename std::enable_if<
6868
std::is_same<typename Param::return_type, uint32_t>::value, uint32_t>::type
69-
get_kernel_info(ur_kernel_handle_t Kernel, const AdapterPtr &Adapter) {
69+
get_kernel_info(ur_kernel_handle_t Kernel, adapter_impl &Adapter) {
7070
ur_result_t Result = UR_RESULT_SUCCESS;
7171

7272
// TODO catch an exception and put it to list of asynchronous exceptions
73-
Adapter->call<UrApiKind::urKernelGetInfo>(Kernel, UrInfoCode<Param>::value,
74-
sizeof(uint32_t), &Result, nullptr);
73+
Adapter.call<UrApiKind::urKernelGetInfo>(Kernel, UrInfoCode<Param>::value,
74+
sizeof(uint32_t), &Result, nullptr);
7575
return Result;
7676
}
7777

@@ -80,29 +80,29 @@ template <typename Param>
8080
typename std::enable_if<IsSubGroupInfo<Param>::value>::type
8181
get_kernel_device_specific_info_helper(ur_kernel_handle_t Kernel,
8282
ur_device_handle_t Device,
83-
const AdapterPtr &Adapter, void *Result,
83+
adapter_impl &Adapter, void *Result,
8484
size_t Size) {
85-
Adapter->call<UrApiKind::urKernelGetSubGroupInfo>(
85+
Adapter.call<UrApiKind::urKernelGetSubGroupInfo>(
8686
Kernel, Device, UrInfoCode<Param>::value, Size, Result, nullptr);
8787
}
8888

8989
template <typename Param>
9090
typename std::enable_if<IsKernelInfo<Param>::value>::type
9191
get_kernel_device_specific_info_helper(
9292
ur_kernel_handle_t Kernel, [[maybe_unused]] ur_device_handle_t Device,
93-
const AdapterPtr &Adapter, void *Result, size_t Size) {
94-
Adapter->call<UrApiKind::urKernelGetInfo>(Kernel, UrInfoCode<Param>::value,
95-
Size, Result, nullptr);
93+
adapter_impl &Adapter, void *Result, size_t Size) {
94+
Adapter.call<UrApiKind::urKernelGetInfo>(Kernel, UrInfoCode<Param>::value,
95+
Size, Result, nullptr);
9696
}
9797

9898
template <typename Param>
9999
typename std::enable_if<!IsSubGroupInfo<Param>::value &&
100100
!IsKernelInfo<Param>::value>::type
101101
get_kernel_device_specific_info_helper(ur_kernel_handle_t Kernel,
102102
ur_device_handle_t Device,
103-
const AdapterPtr &Adapter, void *Result,
103+
adapter_impl &Adapter, void *Result,
104104
size_t Size) {
105-
ur_result_t Error = Adapter->call_nocheck<UrApiKind::urKernelGetGroupInfo>(
105+
ur_result_t Error = Adapter.call_nocheck<UrApiKind::urKernelGetGroupInfo>(
106106
Kernel, Device, UrInfoCode<Param>::value, Size, Result, nullptr);
107107
if (Error != UR_RESULT_SUCCESS)
108108
kernel_get_group_info::handleErrorOrWarning(Error, UrInfoCode<Param>::value,
@@ -115,7 +115,7 @@ typename std::enable_if<
115115
typename Param::return_type>::type
116116
get_kernel_device_specific_info(ur_kernel_handle_t Kernel,
117117
ur_device_handle_t Device,
118-
const AdapterPtr &Adapter) {
118+
adapter_impl &Adapter) {
119119
static_assert(is_kernel_device_specific_info_desc<Param>::value,
120120
"Unexpected kernel_device_specific information descriptor");
121121
typename Param::return_type Result = {};
@@ -131,7 +131,7 @@ typename std::enable_if<
131131
sycl::range<3>>::type
132132
get_kernel_device_specific_info(ur_kernel_handle_t Kernel,
133133
ur_device_handle_t Device,
134-
const AdapterPtr &Adapter) {
134+
adapter_impl &Adapter) {
135135
static_assert(is_kernel_device_specific_info_desc<Param>::value,
136136
"Unexpected kernel_device_specific information descriptor");
137137
size_t Result[3] = {0, 0, 0};
@@ -148,7 +148,7 @@ template <typename Param>
148148
uint32_t get_kernel_device_specific_info_with_input(ur_kernel_handle_t Kernel,
149149
ur_device_handle_t Device,
150150
sycl::range<3>,
151-
const AdapterPtr &Adapter) {
151+
adapter_impl &Adapter) {
152152
static_assert(is_kernel_device_specific_info_desc<Param>::value,
153153
"Unexpected kernel_device_specific information descriptor");
154154
static_assert(std::is_same<typename Param::return_type, uint32_t>::value,
@@ -159,7 +159,7 @@ uint32_t get_kernel_device_specific_info_with_input(ur_kernel_handle_t Kernel,
159159

160160
uint32_t Result = 0;
161161
// TODO catch an exception and put it to list of asynchronous exceptions
162-
Adapter->call<UrApiKind::urKernelGetSubGroupInfo>(
162+
Adapter.call<UrApiKind::urKernelGetSubGroupInfo>(
163163
Kernel, Device, UrInfoCode<Param>::value, sizeof(uint32_t), &Result,
164164
nullptr);
165165

@@ -171,35 +171,35 @@ inline ext::intel::info::kernel_device_specific::spill_memory_size::return_type
171171
get_kernel_device_specific_info<
172172
ext::intel::info::kernel_device_specific::spill_memory_size>(
173173
ur_kernel_handle_t Kernel, ur_device_handle_t Device,
174-
const AdapterPtr &Adapter) {
174+
adapter_impl &Adapter) {
175175
size_t ResultSize = 0;
176176

177177
// First call to get the number of device images
178-
Adapter->call<UrApiKind::urKernelGetInfo>(
178+
Adapter.call<UrApiKind::urKernelGetInfo>(
179179
Kernel, UR_KERNEL_INFO_SPILL_MEM_SIZE, 0, nullptr, &ResultSize);
180180

181181
size_t DeviceCount = ResultSize / sizeof(uint32_t);
182182

183183
// Second call to retrieve the data
184184
std::vector<uint32_t> Device2SpillMap(DeviceCount);
185-
Adapter->call<UrApiKind::urKernelGetInfo>(
185+
Adapter.call<UrApiKind::urKernelGetInfo>(
186186
Kernel, UR_KERNEL_INFO_SPILL_MEM_SIZE, ResultSize, Device2SpillMap.data(),
187187
nullptr);
188188

189189
ur_program_handle_t Program;
190-
Adapter->call<UrApiKind::urKernelGetInfo>(Kernel, UR_KERNEL_INFO_PROGRAM,
191-
sizeof(ur_program_handle_t),
192-
&Program, nullptr);
190+
Adapter.call<UrApiKind::urKernelGetInfo>(Kernel, UR_KERNEL_INFO_PROGRAM,
191+
sizeof(ur_program_handle_t),
192+
&Program, nullptr);
193193
// Retrieve the associated device list
194194
size_t URDevicesSize = 0;
195-
Adapter->call<UrApiKind::urProgramGetInfo>(Program, UR_PROGRAM_INFO_DEVICES,
196-
0, nullptr, &URDevicesSize);
195+
Adapter.call<UrApiKind::urProgramGetInfo>(Program, UR_PROGRAM_INFO_DEVICES, 0,
196+
nullptr, &URDevicesSize);
197197

198198
std::vector<ur_device_handle_t> URDevices(URDevicesSize /
199199
sizeof(ur_device_handle_t));
200-
Adapter->call<UrApiKind::urProgramGetInfo>(Program, UR_PROGRAM_INFO_DEVICES,
201-
URDevicesSize, URDevices.data(),
202-
nullptr);
200+
Adapter.call<UrApiKind::urProgramGetInfo>(Program, UR_PROGRAM_INFO_DEVICES,
201+
URDevicesSize, URDevices.data(),
202+
nullptr);
203203
assert(Device2SpillMap.size() == URDevices.size());
204204

205205
// Map the result back to the program devices. UR provides the following

sycl/source/detail/scheduler/commands.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2271,7 +2271,7 @@ static void adjustNDRangePerKernel(NDRDescT &NDR, ur_kernel_handle_t Kernel,
22712271
// avoid get_kernel_work_group_info on every kernel run
22722272
range<3> WGSize = get_kernel_device_specific_info<
22732273
sycl::info::kernel_device_specific::compile_work_group_size>(
2274-
Kernel, DeviceImpl.getHandleRef(), DeviceImpl.getAdapter());
2274+
Kernel, DeviceImpl.getHandleRef(), *DeviceImpl.getAdapter());
22752275

22762276
if (WGSize[0] == 0) {
22772277
WGSize = {1, 1, 1};

0 commit comments

Comments
 (0)