Skip to content

Commit c8ec91f

Browse files
authored
[SYCL] Move Kernel specific data from handler_impl to a separate data structure (#19843)
This PR is a prerequisite for the handler-less API. Kernel-specific data and argument parsing logic are moved from the `handler_impl` to the new `KernelData` class that will be used in a handler-less path.
1 parent 4cb8441 commit c8ec91f

File tree

16 files changed

+754
-476
lines changed

16 files changed

+754
-476
lines changed

sycl/include/sycl/ext/oneapi/experimental/work_group_memory.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@
1818

1919
namespace sycl {
2020
inline namespace _V1 {
21-
class handler;
2221

2322
namespace detail {
23+
class KernelData;
24+
2425
template <typename T> struct is_unbounded_array : std::false_type {};
2526

2627
template <typename T> struct is_unbounded_array<T[]> : std::true_type {};
@@ -38,7 +39,7 @@ class work_group_memory_impl {
3839

3940
private:
4041
size_t buffer_size;
41-
friend class sycl::handler;
42+
friend class KernelData;
4243
};
4344

4445
} // namespace detail

sycl/include/sycl/handler.hpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -495,9 +495,7 @@ class __SYCL_EXPORT handler {
495495
template <class Kernel> void setDeviceKernelInfo(void *KernelFuncPtr) {
496496
constexpr auto Info = detail::CompileTimeKernelInfo<Kernel>;
497497
MKernelName = Info.Name;
498-
// TODO support ESIMD in no-integration-header case too.
499-
setKernelInfo(KernelFuncPtr, Info.NumParams, Info.ParamDescGetter,
500-
Info.IsESIMD, Info.HasSpecialCaptures);
498+
setKernelFunc(KernelFuncPtr);
501499
setDeviceKernelInfoPtr(&detail::getDeviceKernelInfo<Kernel>());
502500
setType(detail::CGType::Kernel);
503501
}
@@ -514,23 +512,21 @@ class __SYCL_EXPORT handler {
514512
extractArgsAndReqsFromLambda(char *LambdaPtr, size_t KernelArgsNum,
515513
const detail::kernel_param_desc_t *KernelArgs,
516514
bool IsESIMD);
517-
#endif
518515
/// Extracts and prepares kernel arguments from the lambda using information
519516
/// from the built-ins or integration header.
520517
void extractArgsAndReqsFromLambda(
521518
char *LambdaPtr, detail::kernel_param_desc_t (*ParamDescGetter)(int),
522519
size_t NumKernelParams, bool IsESIMD);
523-
520+
#endif
524521
/// Extracts and prepares kernel arguments set via set_arg(s).
525522
void extractArgsAndReqs();
526523

527-
#if defined(__INTEL_PREVIEW_BREAKING_CHANGES)
528-
// TODO: processArg need not to be public
529-
__SYCL_DLL_LOCAL
530-
#endif
524+
#ifndef __INTEL_PREVIEW_BREAKING_CHANGES
525+
// TODO: remove in the next ABI-breaking window.
531526
void processArg(void *Ptr, const detail::kernel_param_kind_t &Kind,
532527
const int Size, const size_t Index, size_t &IndexShift,
533528
bool IsKernelCreatedFromSource, bool IsESIMD);
529+
#endif
534530

535531
/// \return a string containing name of SYCL kernel.
536532
detail::ABINeutralKernelNameStrT getKernelName();
@@ -3604,7 +3600,10 @@ class __SYCL_EXPORT handler {
36043600

36053601
void addArg(detail::kernel_param_kind_t ArgKind, void *Req, int AccessTarget,
36063602
int ArgIndex);
3603+
#ifndef __INTEL_PREVIEW_BREAKING_CHANGES
3604+
// TODO: remove in the next ABI-breaking window
36073605
void clearArgs();
3606+
#endif
36083607
void setArgsToAssociatedAccessors();
36093608

36103609
bool HasAssociatedAccessor(detail::AccessorImplHost *Req,
@@ -3651,10 +3650,12 @@ class __SYCL_EXPORT handler {
36513650
void setNDRangeDescriptor(sycl::range<1> NumWorkItems, sycl::id<1> Offset);
36523651
void setNDRangeDescriptor(sycl::range<1> NumWorkItems,
36533652
sycl::range<1> LocalSize, sycl::id<1> Offset);
3654-
3653+
#ifndef __INTEL_PREVIEW_BREAKING_CHANGES
36553654
void setKernelInfo(void *KernelFuncPtr, int KernelNumArgs,
36563655
detail::kernel_param_desc_t (*KernelParamDescGetter)(int),
36573656
bool KernelIsESIMD, bool KernelHasSpecialCaptures);
3657+
#endif
3658+
void setKernelFunc(void *KernelFuncPtr);
36583659

36593660
void instantiateKernelOnHost(void *InstantiateKernelOnHostPtr);
36603661

sycl/include/sycl/stream.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ inline namespace _V1 {
4242
namespace detail {
4343

4444
class stream_impl;
45+
class KernelData;
4546

4647
using FmtFlags = unsigned int;
4748

@@ -1041,7 +1042,7 @@ class __SYCL_EXPORT __SYCL_SPECIAL_CLASS __SYCL_TYPE(stream) stream
10411042
}
10421043
#endif
10431044

1044-
friend class handler;
1045+
friend class detail::KernelData;
10451046

10461047
template <typename SYCLObjT> friend class ext::oneapi::weak_object;
10471048

sycl/source/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,7 @@ set(SYCL_COMMON_SOURCES
260260
"detail/device_filter.cpp"
261261
"detail/host_pipe_map.cpp"
262262
"detail/device_global_map.cpp"
263+
"detail/kernel_data.cpp"
263264
"detail/kernel_global_info.cpp"
264265
"detail/device_global_map_entry.cpp"
265266
"detail/device_image_impl.cpp"

sycl/source/detail/device_kernel_info.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,11 @@ void DeviceKernelInfo::setCompileTimeInfoIfNeeded(
6363
const CompileTimeKernelInfoTy &Info) {
6464
if (!isCompileTimeInfoSet())
6565
CompileTimeKernelInfoTy::operator=(Info);
66+
#ifdef __INTEL_PREVIEW_BREAKING_CHANGES
67+
// In case of 6.3 compatibility mode the KernelSize is not passed to the
68+
// runtime. So, it will always be 0 and this assert fails.
6669
assert(isCompileTimeInfoSet());
70+
#endif
6771
assert(Info == *this);
6872
}
6973

sycl/source/detail/graph/dynamic_impl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ void dynamic_command_group_impl::finalizeCGFList(
343343
MCommandGroups.push_back(std::shared_ptr<sycl::detail::CG>(RawCGPtr));
344344

345345
// Track dynamic_parameter usage in command-group
346-
auto &DynamicParams = Handler.impl->MDynamicParameters;
346+
auto &DynamicParams = Handler.impl->MKernelData.getDynamicParameters();
347347

348348
if (DynamicParams.size() > 0 &&
349349
Handler.getType() == sycl::detail::CGType::CodeplayHostTask) {

sycl/source/detail/graph/graph_impl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,7 @@ node_impl &graph_impl::add(std::function<void(handler &)> CGF,
471471

472472
// Retrieve any dynamic parameters which have been registered in the CGF and
473473
// register the actual nodes with them.
474-
auto &DynamicParams = Handler.impl->MDynamicParameters;
474+
auto &DynamicParams = Handler.impl->MKernelData.getDynamicParameters();
475475

476476
if (NodeType != node_type::kernel && DynamicParams.size() > 0) {
477477
throw sycl::exception(sycl::make_error_code(errc::invalid),

sycl/source/detail/handler_impl.hpp

Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "sycl/handler.hpp"
1212
#include <detail/cg.hpp>
1313
#include <detail/kernel_bundle_impl.hpp>
14+
#include <detail/kernel_data.hpp>
1415
#include <memory>
1516
#include <sycl/ext/oneapi/experimental/enqueue_types.hpp>
1617

@@ -61,8 +62,7 @@ class handler_impl {
6162
}
6263

6364
KernelNameStrRefT getKernelName() const {
64-
assert(MDeviceKernelInfoPtr);
65-
return static_cast<KernelNameStrRefT>(MDeviceKernelInfoPtr->Name);
65+
return MKernelData.getKernelName();
6666
}
6767

6868
/// Registers mutually exclusive submission states.
@@ -108,12 +108,6 @@ class handler_impl {
108108
// If the pipe operation is read or write, 1 for read 0 for write.
109109
bool HostPipeRead = true;
110110

111-
ur_kernel_cache_config_t MKernelCacheConfig = UR_KERNEL_CACHE_CONFIG_DEFAULT;
112-
113-
bool MKernelIsCooperative = false;
114-
bool MKernelUsesClusterLaunch = false;
115-
uint32_t MKernelWorkGroupMemorySize = 0;
116-
117111
// Extra information for bindless image copy
118112
ur_image_desc_t MSrcImageDesc = {};
119113
ur_image_desc_t MDstImageDesc = {};
@@ -138,29 +132,17 @@ class handler_impl {
138132
sycl::ext::oneapi::experimental::node_type MUserFacingNodeType =
139133
sycl::ext::oneapi::experimental::node_type::empty;
140134

141-
// Storage for any SYCL Graph dynamic parameters which have been flagged for
142-
// registration in the CG, along with the argument index for the parameter.
143-
std::vector<std::pair<
144-
ext::oneapi::experimental::detail::dynamic_parameter_impl *, int>>
145-
MDynamicParameters;
146-
147135
/// The storage for the arguments passed.
148136
/// We need to store a copy of values that are passed explicitly through
149137
/// set_arg, require and so on, because we need them to be alive after
150138
/// we exit the method they are passed in.
151139
detail::CG::StorageInitHelper CGData;
152140

153-
/// The list of arguments for the kernel.
154-
std::vector<detail::ArgDesc> MArgs;
155-
156141
/// The list of associated accessors with this handler.
157142
/// These accessors were created with this handler as argument or
158143
/// have become required for this handler via require method.
159144
std::vector<detail::ArgDesc> MAssociatedAccesors;
160145

161-
/// Struct that encodes global size, local size, ...
162-
detail::NDRDescT MNDRDesc;
163-
164146
/// Type of the command group, e.g. kernel, fill. Can also encode version.
165147
/// Use getType and setType methods to access this variable unless
166148
/// manipulations with version are required
@@ -241,16 +223,16 @@ class handler_impl {
241223
// Allocation ptr to be freed asynchronously.
242224
void *MFreePtr = nullptr;
243225

244-
// Store information about the kernel arguments.
245-
void *MKernelFuncPtr = nullptr;
226+
#ifndef __INTEL_PREVIEW_BREAKING_CHANGES
227+
// TODO: remove in the next ABI-breaking window
228+
// Today they are used only in the handler::setKernelNameBasedCachePtr
246229
int MKernelNumArgs = 0;
247230
detail::kernel_param_desc_t (*MKernelParamDescGetter)(int) = nullptr;
248231
bool MKernelIsESIMD = false;
249232
bool MKernelHasSpecialCaptures = true;
233+
#endif
250234

251-
// A pointer to device kernel information. Cached on the application side in
252-
// headers or retrieved from program manager.
253-
DeviceKernelInfo *MDeviceKernelInfoPtr = nullptr;
235+
KernelData MKernelData;
254236
};
255237

256238
} // namespace detail

0 commit comments

Comments
 (0)