Skip to content

Commit 6df710b

Browse files
committed
[SYCL][NFC] Make kernel_impl::getAdapter() return by reference
1 parent 4aef322 commit 6df710b

File tree

6 files changed

+37
-37
lines changed

6 files changed

+37
-37
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 & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ void handleErrorOrWarning(ur_result_t, const device_impl &, ur_kernel_handle_t,
3232
namespace kernel_get_group_info {
3333
/// Analyzes error code of urKernelGetGroupInfo.
3434
void handleErrorOrWarning(ur_result_t, ur_kernel_group_info_t,
35-
const AdapterPtr &);
35+
adapter_impl &);
3636
} // namespace kernel_get_group_info
3737

3838
} // 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: 9 additions & 9 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,
78+
getAdapter().call<UrApiKind::urKernelGetNativeHandle>(MKernel,
7979
&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,15 @@ kernel_impl::queryMaxNumWorkGroups(queue Queue,
373373
WG[2] = WorkGroupSize[2];
374374

375375
uint32_t GroupCount{0};
376-
if (auto Result = Adapter->call_nocheck<
376+
if (auto Result = Adapter.call_nocheck<
377377
UrApiKind::urKernelSuggestMaxCooperativeGroupCount>(
378378
Handle, DeviceHandleRef, Dimensions, WG, DynamicLocalMemorySize,
379379
&GroupCount);
380380
Result != UR_RESULT_ERROR_UNSUPPORTED_FEATURE &&
381381
Result != UR_RESULT_ERROR_INVALID_WORK_GROUP_SIZE) {
382382
// The feature is supported and the group size is valid. Check for other
383383
// errors and throw if any.
384-
Adapter->checkUrResult(Result);
384+
Adapter.checkUrResult(Result);
385385
return GroupCount;
386386
}
387387

@@ -452,12 +452,12 @@ inline typename syclex::info::kernel_queue_specific::max_work_group_size::
452452
kernel_impl::ext_oneapi_get_info<
453453
syclex::info::kernel_queue_specific::max_work_group_size>(
454454
queue Queue) const {
455-
const auto &Adapter = getAdapter();
455+
adapter_impl &Adapter = getAdapter();
456456
const auto DeviceNativeHandle =
457457
getSyclObjImpl(Queue.get_device())->getHandleRef();
458458

459459
size_t KernelWGSize = 0;
460-
Adapter->call<UrApiKind::urKernelGetGroupInfo>(
460+
Adapter.call<UrApiKind::urKernelGetGroupInfo>(
461461
MKernel, DeviceNativeHandle, UR_KERNEL_GROUP_INFO_WORK_GROUP_SIZE,
462462
sizeof(size_t), &KernelWGSize, nullptr);
463463
return KernelWGSize;
@@ -508,11 +508,11 @@ ADD_TEMPLATE_METHOD_SPEC(3)
508508
if (WG.size() == 0) \
509509
throw exception(sycl::make_error_code(errc::invalid), \
510510
"The work-group size cannot be zero."); \
511-
const auto &Adapter = getAdapter(); \
511+
adapter_impl &Adapter = getAdapter(); \
512512
const auto DeviceNativeHandle = \
513513
getSyclObjImpl(Queue.get_device())->getHandleRef(); \
514514
uint32_t KernelSubWGSize = 0; \
515-
Adapter->call<UrApiKind::Kind>(MKernel, DeviceNativeHandle, Reg, \
515+
Adapter.call<UrApiKind::Kind>(MKernel, DeviceNativeHandle, Reg, \
516516
sizeof(uint32_t), &KernelSubWGSize, \
517517
nullptr); \
518518
return KernelSubWGSize; \

sycl/source/detail/kernel_info.hpp

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -45,32 +45,32 @@ 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,
54+
Adapter.call<UrApiKind::urKernelGetInfo>(Kernel, UrInfoCode<Param>::value, 0,
5555
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,
61+
Adapter.call<UrApiKind::urKernelGetInfo>(Kernel, UrInfoCode<Param>::value,
6262
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,
73+
Adapter.call<UrApiKind::urKernelGetInfo>(Kernel, UrInfoCode<Param>::value,
7474
sizeof(uint32_t), &Result, nullptr);
7575
return Result;
7676
}
@@ -80,18 +80,18 @@ 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,
93+
adapter_impl &Adapter, void *Result, size_t Size) {
94+
Adapter.call<UrApiKind::urKernelGetInfo>(Kernel, UrInfoCode<Param>::value,
9595
Size, Result, nullptr);
9696
}
9797

@@ -100,9 +100,9 @@ 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,33 +171,33 @@ 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,
190+
Adapter.call<UrApiKind::urKernelGetInfo>(Kernel, UR_KERNEL_INFO_PROGRAM,
191191
sizeof(ur_program_handle_t),
192192
&Program, nullptr);
193193
// Retrieve the associated device list
194194
size_t URDevicesSize = 0;
195-
Adapter->call<UrApiKind::urProgramGetInfo>(Program, UR_PROGRAM_INFO_DEVICES,
195+
Adapter.call<UrApiKind::urProgramGetInfo>(Program, UR_PROGRAM_INFO_DEVICES,
196196
0, 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,
200+
Adapter.call<UrApiKind::urProgramGetInfo>(Program, UR_PROGRAM_INFO_DEVICES,
201201
URDevicesSize, URDevices.data(),
202202
nullptr);
203203
assert(Device2SpillMap.size() == URDevices.size());

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)