Skip to content

Commit c4fa95f

Browse files
authored
[SYCL] Add SYCL 2020 info::device::built_in_kernel_ids support (#4996)
- Add `ProgramManager::getBuiltInKernelID`, which generates and caches built-in kernel IDs. - Use that API to generate or look up built-in kernel IDs, when queried. - Throw an exception in program manager when actually trying to use built-in kernels, since they are not yet fully supported. - Add SYCL 2020 deprecation warning for `built_in_kernels` (old query).
1 parent b0f9a81 commit c4fa95f

File tree

9 files changed

+95
-23
lines changed

9 files changed

+95
-23
lines changed

sycl/include/CL/sycl/info/device_traits.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ __SYCL_PARAM_TRAITS_SPEC(device, is_linker_available, bool)
5858
__SYCL_PARAM_TRAITS_SPEC(device, execution_capabilities,
5959
std::vector<info::execution_capability>)
6060
__SYCL_PARAM_TRAITS_SPEC(device, queue_profiling, bool)
61+
__SYCL_PARAM_TRAITS_SPEC(device, built_in_kernel_ids, std::vector<kernel_id>)
6162
__SYCL_PARAM_TRAITS_SPEC(device, built_in_kernels, std::vector<std::string>)
6263
__SYCL_PARAM_TRAITS_SPEC(device, platform, cl::sycl::platform)
6364
__SYCL_PARAM_TRAITS_SPEC(device, name, std::string)

sycl/include/CL/sycl/info/info_desc.hpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class program;
2020
#endif
2121
class device;
2222
class platform;
23+
class kernel_id;
2324

2425
// TODO: stop using OpenCL directly, use PI.
2526
namespace info {
@@ -109,7 +110,8 @@ enum class device : cl_device_info {
109110
is_linker_available = CL_DEVICE_LINKER_AVAILABLE,
110111
execution_capabilities = CL_DEVICE_EXECUTION_CAPABILITIES,
111112
queue_profiling = CL_DEVICE_QUEUE_PROPERTIES,
112-
built_in_kernels = CL_DEVICE_BUILT_IN_KERNELS,
113+
built_in_kernels __SYCL2020_DEPRECATED("use built_in_kernel_ids instead") =
114+
CL_DEVICE_BUILT_IN_KERNELS,
113115
platform = CL_DEVICE_PLATFORM,
114116
name = CL_DEVICE_NAME,
115117
vendor = CL_DEVICE_VENDOR,
@@ -136,6 +138,7 @@ enum class device : cl_device_info {
136138
sub_group_sizes = CL_DEVICE_SUB_GROUP_SIZES_INTEL,
137139
partition_type_property,
138140
kernel_kernel_pipe_support,
141+
built_in_kernel_ids,
139142
// USM
140143
usm_device_allocations = PI_USM_DEVICE_SUPPORT,
141144
usm_host_allocations = PI_USM_HOST_SUPPORT,

sycl/source/detail/device_impl.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
#include <CL/sycl/aspects.hpp>
1212
#include <CL/sycl/detail/pi.hpp>
13+
#include <CL/sycl/kernel_bundle.hpp>
1314
#include <CL/sycl/stl.hpp>
1415
#include <detail/device_info.hpp>
1516
#include <detail/platform_impl.hpp>

sycl/source/detail/device_info.hpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <detail/platform_impl.hpp>
2020
#include <detail/platform_util.hpp>
2121
#include <detail/plugin.hpp>
22+
#include <detail/program_manager/program_manager.hpp>
2223

2324
#include <chrono>
2425
#include <thread>
@@ -279,6 +280,25 @@ struct get_device_info<std::vector<info::execution_capability>,
279280
}
280281
};
281282

283+
// Specialization for built in kernel identifiers
284+
template <>
285+
struct get_device_info<std::vector<kernel_id>,
286+
info::device::built_in_kernel_ids> {
287+
static std::vector<kernel_id> get(RT::PiDevice dev, const plugin &Plugin) {
288+
std::string result =
289+
get_device_info<std::string, info::device::built_in_kernels>::get(
290+
dev, Plugin);
291+
auto names = split_string(result, ';');
292+
293+
std::vector<kernel_id> ids;
294+
ids.reserve(names.size());
295+
for (const auto &name : names) {
296+
ids.push_back(ProgramManager::getInstance().getBuiltInKernelID(name));
297+
}
298+
return ids;
299+
}
300+
};
301+
282302
// Specialization for built in kernels, splits the string returned by OpenCL
283303
template <>
284304
struct get_device_info<std::vector<std::string>,
@@ -979,6 +999,12 @@ template <> inline bool get_device_info_host<info::device::queue_profiling>() {
979999
return true;
9801000
}
9811001

1002+
template <>
1003+
inline std::vector<kernel_id>
1004+
get_device_info_host<info::device::built_in_kernel_ids>() {
1005+
return {};
1006+
}
1007+
9821008
template <>
9831009
inline std::vector<std::string>
9841010
get_device_info_host<info::device::built_in_kernels>() {

sycl/source/detail/program_manager/program_manager.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1341,6 +1341,19 @@ std::vector<kernel_id> ProgramManager::getAllSYCLKernelIDs() {
13411341
return AllKernelIDs;
13421342
}
13431343

1344+
kernel_id ProgramManager::getBuiltInKernelID(const std::string &KernelName) {
1345+
std::lock_guard<std::mutex> BuiltInKernelIDsGuard(m_BuiltInKernelIDsMutex);
1346+
1347+
auto KernelID = m_BuiltInKernelIDs.find(KernelName);
1348+
if (KernelID == m_BuiltInKernelIDs.end()) {
1349+
auto Impl = std::make_shared<kernel_id_impl>(KernelName);
1350+
auto CachedID = createSyclObjFromImpl<kernel_id>(Impl);
1351+
KernelID = m_BuiltInKernelIDs.insert({KernelName, CachedID}).first;
1352+
}
1353+
1354+
return KernelID->second;
1355+
}
1356+
13441357
std::vector<device_image_plain>
13451358
ProgramManager::getSYCLDeviceImagesWithCompatibleState(
13461359
const context &Ctx, const std::vector<device> &Devs,
@@ -1511,6 +1524,17 @@ std::vector<device_image_plain> ProgramManager::getSYCLDeviceImages(
15111524
std::vector<device_image_plain> ProgramManager::getSYCLDeviceImages(
15121525
const context &Ctx, const std::vector<device> &Devs,
15131526
const std::vector<kernel_id> &KernelIDs, bundle_state TargetState) {
1527+
{
1528+
std::lock_guard<std::mutex> BuiltInKernelIDsGuard(m_BuiltInKernelIDsMutex);
1529+
1530+
for (const kernel_id &ID : KernelIDs) {
1531+
if (m_BuiltInKernelIDs.find(ID.get_name()) != m_BuiltInKernelIDs.end())
1532+
throw sycl::exception(make_error_code(errc::kernel_argument),
1533+
"Attempting to use a built-in kernel. They are "
1534+
"not fully supported");
1535+
}
1536+
}
1537+
15141538
// Collect device images with compatible state
15151539
std::vector<device_image_plain> DeviceImages =
15161540
getSYCLDeviceImagesWithCompatibleState(Ctx, Devs, TargetState);

sycl/source/detail/program_manager/program_manager.hpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,10 @@ class ProgramManager {
178178
// in SYCL device images.
179179
std::vector<kernel_id> getAllSYCLKernelIDs();
180180

181+
// The function returns the unique SYCL kernel identifier associated with a
182+
// built-in kernel name.
183+
kernel_id getBuiltInKernelID(const std::string &KernelName);
184+
181185
// The function returns a vector of SYCL device images that are compiled with
182186
// the required state and at least one device from the passed list of devices.
183187
std::vector<device_image_plain>
@@ -327,6 +331,13 @@ class ProgramManager {
327331
/// Access must be guarded by the m_KernelIDsMutex mutex.
328332
std::unordered_set<std::string> m_ExportedSymbols;
329333

334+
/// Maps names of built-in kernels to their unique kernel IDs.
335+
/// Access must be guarded by the m_BuiltInKernelIDsMutex mutex.
336+
std::unordered_map<std::string, kernel_id> m_BuiltInKernelIDs;
337+
338+
/// Protects built-in kernel ID cache.
339+
std::mutex m_BuiltInKernelIDsMutex;
340+
330341
// Keeps track of pi_program to image correspondence. Needed for:
331342
// - knowing which specialization constants are used in the program and
332343
// injecting their current values before compiling the SPIR-V; the binary

sycl/test/abi/sycl_symbols_linux.dump

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4109,9 +4109,14 @@ _ZNK2cl4sycl6device3hasENS0_6aspectE
41094109
_ZNK2cl4sycl6device6is_cpuEv
41104110
_ZNK2cl4sycl6device6is_gpuEv
41114111
_ZNK2cl4sycl6device7is_hostEv
4112+
_ZNK2cl4sycl6device8get_infoILNS0_4info6deviceE131072EEENS3_12param_traitsIS4_XT_EE11return_typeEv
4113+
_ZNK2cl4sycl6device8get_infoILNS0_4info6deviceE131073EEENS3_12param_traitsIS4_XT_EE11return_typeEv
4114+
_ZNK2cl4sycl6device8get_infoILNS0_4info6deviceE131074EEENS3_12param_traitsIS4_XT_EE11return_typeEv
4115+
_ZNK2cl4sycl6device8get_infoILNS0_4info6deviceE131075EEENS3_12param_traitsIS4_XT_EE11return_typeEv
41124116
_ZNK2cl4sycl6device8get_infoILNS0_4info6deviceE16648EEENS3_12param_traitsIS4_XT_EE11return_typeEv
41134117
_ZNK2cl4sycl6device8get_infoILNS0_4info6deviceE16649EEENS3_12param_traitsIS4_XT_EE11return_typeEv
41144118
_ZNK2cl4sycl6device8get_infoILNS0_4info6deviceE16650EEENS3_12param_traitsIS4_XT_EE11return_typeEv
4119+
_ZNK2cl4sycl6device8get_infoILNS0_4info6deviceE16651EEENS3_12param_traitsIS4_XT_EE11return_typeEv
41154120
_ZNK2cl4sycl6device8get_infoILNS0_4info6deviceE16784EEENS3_12param_traitsIS4_XT_EE11return_typeEv
41164121
_ZNK2cl4sycl6device8get_infoILNS0_4info6deviceE16785EEENS3_12param_traitsIS4_XT_EE11return_typeEv
41174122
_ZNK2cl4sycl6device8get_infoILNS0_4info6deviceE16786EEENS3_12param_traitsIS4_XT_EE11return_typeEv
@@ -4244,6 +4249,7 @@ _ZNK2cl4sycl6streamneERKS1_
42444249
_ZNK2cl4sycl7context11get_backendEv
42454250
_ZNK2cl4sycl7context11get_devicesEv
42464251
_ZNK2cl4sycl7context12get_platformEv
4252+
_ZNK2cl4sycl7context12get_propertyINS0_3ext6oneapi4cuda8property7context19use_primary_contextEEET_v
42474253
_ZNK2cl4sycl7context12get_propertyINS0_3ext6oneapi8property6buffer22use_pinned_host_memoryEEET_v
42484254
_ZNK2cl4sycl7context12get_propertyINS0_8property5image12use_host_ptrEEET_v
42494255
_ZNK2cl4sycl7context12get_propertyINS0_8property5image13context_boundEEET_v
@@ -4256,6 +4262,7 @@ _ZNK2cl4sycl7context12get_propertyINS0_8property6noinitEEET_v
42564262
_ZNK2cl4sycl7context12get_propertyINS0_8property7context4cuda19use_primary_contextEEET_v
42574263
_ZNK2cl4sycl7context12get_propertyINS0_8property7no_initEEET_v
42584264
_ZNK2cl4sycl7context12get_propertyINS0_8property9reduction22initialize_to_identityEEET_v
4265+
_ZNK2cl4sycl7context12has_propertyINS0_3ext6oneapi4cuda8property7context19use_primary_contextEEEbv
42594266
_ZNK2cl4sycl7context12has_propertyINS0_3ext6oneapi8property6buffer22use_pinned_host_memoryEEEbv
42604267
_ZNK2cl4sycl7context12has_propertyINS0_8property5image12use_host_ptrEEEbv
42614268
_ZNK2cl4sycl7context12has_propertyINS0_8property5image13context_boundEEEbv
@@ -4268,8 +4275,6 @@ _ZNK2cl4sycl7context12has_propertyINS0_8property6noinitEEEbv
42684275
_ZNK2cl4sycl7context12has_propertyINS0_8property7context4cuda19use_primary_contextEEEbv
42694276
_ZNK2cl4sycl7context12has_propertyINS0_8property7no_initEEEbv
42704277
_ZNK2cl4sycl7context12has_propertyINS0_8property9reduction22initialize_to_identityEEEbv
4271-
_ZNK2cl4sycl7context12get_propertyINS0_3ext6oneapi4cuda8property7context19use_primary_contextEEET_v
4272-
_ZNK2cl4sycl7context12has_propertyINS0_3ext6oneapi4cuda8property7context19use_primary_contextEEEbv
42734278
_ZNK2cl4sycl7context3getEv
42744279
_ZNK2cl4sycl7context7is_hostEv
42754280
_ZNK2cl4sycl7context8get_infoILNS0_4info7contextE4224EEENS3_12param_traitsIS4_XT_EE11return_typeEv
@@ -4288,6 +4293,7 @@ _ZNK2cl4sycl7program11get_backendEv
42884293
_ZNK2cl4sycl7program11get_contextEv
42894294
_ZNK2cl4sycl7program11get_devicesEv
42904295
_ZNK2cl4sycl7program12get_binariesEv
4296+
_ZNK2cl4sycl7program12get_propertyINS0_3ext6oneapi4cuda8property7context19use_primary_contextEEET_v
42914297
_ZNK2cl4sycl7program12get_propertyINS0_3ext6oneapi8property6buffer22use_pinned_host_memoryEEET_v
42924298
_ZNK2cl4sycl7program12get_propertyINS0_8property5image12use_host_ptrEEET_v
42934299
_ZNK2cl4sycl7program12get_propertyINS0_8property5image13context_boundEEET_v
@@ -4298,9 +4304,9 @@ _ZNK2cl4sycl7program12get_propertyINS0_8property6buffer13context_boundEEET_v
42984304
_ZNK2cl4sycl7program12get_propertyINS0_8property6buffer9use_mutexEEET_v
42994305
_ZNK2cl4sycl7program12get_propertyINS0_8property6noinitEEET_v
43004306
_ZNK2cl4sycl7program12get_propertyINS0_8property7context4cuda19use_primary_contextEEET_v
4301-
_ZNK2cl4sycl7program12get_propertyINS0_3ext6oneapi4cuda8property7context19use_primary_contextEEET_v
43024307
_ZNK2cl4sycl7program12get_propertyINS0_8property7no_initEEET_v
43034308
_ZNK2cl4sycl7program12get_propertyINS0_8property9reduction22initialize_to_identityEEET_v
4309+
_ZNK2cl4sycl7program12has_propertyINS0_3ext6oneapi4cuda8property7context19use_primary_contextEEEbv
43044310
_ZNK2cl4sycl7program12has_propertyINS0_3ext6oneapi8property6buffer22use_pinned_host_memoryEEEbv
43054311
_ZNK2cl4sycl7program12has_propertyINS0_8property5image12use_host_ptrEEEbv
43064312
_ZNK2cl4sycl7program12has_propertyINS0_8property5image13context_boundEEEbv
@@ -4311,7 +4317,6 @@ _ZNK2cl4sycl7program12has_propertyINS0_8property6buffer13context_boundEEEbv
43114317
_ZNK2cl4sycl7program12has_propertyINS0_8property6buffer9use_mutexEEEbv
43124318
_ZNK2cl4sycl7program12has_propertyINS0_8property6noinitEEEbv
43134319
_ZNK2cl4sycl7program12has_propertyINS0_8property7context4cuda19use_primary_contextEEEbv
4314-
_ZNK2cl4sycl7program12has_propertyINS0_3ext6oneapi4cuda8property7context19use_primary_contextEEEbv
43154320
_ZNK2cl4sycl7program12has_propertyINS0_8property7no_initEEEbv
43164321
_ZNK2cl4sycl7program12has_propertyINS0_8property9reduction22initialize_to_identityEEEbv
43174322
_ZNK2cl4sycl7program16get_link_optionsB5cxx11Ev
@@ -4324,6 +4329,7 @@ _ZNK2cl4sycl7program8get_infoILNS0_4info7programE4449EEENS3_12param_traitsIS4_XT
43244329
_ZNK2cl4sycl7program8get_infoILNS0_4info7programE4451EEENS3_12param_traitsIS4_XT_EE11return_typeEv
43254330
_ZNK2cl4sycl7program9getNativeEv
43264331
_ZNK2cl4sycl7program9get_stateEv
4332+
_ZNK2cl4sycl7sampler12get_propertyINS0_3ext6oneapi4cuda8property7context19use_primary_contextEEET_v
43274333
_ZNK2cl4sycl7sampler12get_propertyINS0_3ext6oneapi8property6buffer22use_pinned_host_memoryEEET_v
43284334
_ZNK2cl4sycl7sampler12get_propertyINS0_8property5image12use_host_ptrEEET_v
43294335
_ZNK2cl4sycl7sampler12get_propertyINS0_8property5image13context_boundEEET_v
@@ -4336,7 +4342,7 @@ _ZNK2cl4sycl7sampler12get_propertyINS0_8property6noinitEEET_v
43364342
_ZNK2cl4sycl7sampler12get_propertyINS0_8property7context4cuda19use_primary_contextEEET_v
43374343
_ZNK2cl4sycl7sampler12get_propertyINS0_8property7no_initEEET_v
43384344
_ZNK2cl4sycl7sampler12get_propertyINS0_8property9reduction22initialize_to_identityEEET_v
4339-
_ZNK2cl4sycl7sampler12get_propertyINS0_3ext6oneapi4cuda8property7context19use_primary_contextEEET_v
4345+
_ZNK2cl4sycl7sampler12has_propertyINS0_3ext6oneapi4cuda8property7context19use_primary_contextEEEbv
43404346
_ZNK2cl4sycl7sampler12has_propertyINS0_3ext6oneapi8property6buffer22use_pinned_host_memoryEEEbv
43414347
_ZNK2cl4sycl7sampler12has_propertyINS0_8property5image12use_host_ptrEEEbv
43424348
_ZNK2cl4sycl7sampler12has_propertyINS0_8property5image13context_boundEEEbv
@@ -4349,7 +4355,6 @@ _ZNK2cl4sycl7sampler12has_propertyINS0_8property6noinitEEEbv
43494355
_ZNK2cl4sycl7sampler12has_propertyINS0_8property7context4cuda19use_primary_contextEEEbv
43504356
_ZNK2cl4sycl7sampler12has_propertyINS0_8property7no_initEEEbv
43514357
_ZNK2cl4sycl7sampler12has_propertyINS0_8property9reduction22initialize_to_identityEEEbv
4352-
_ZNK2cl4sycl7sampler12has_propertyINS0_3ext6oneapi4cuda8property7context19use_primary_contextEEEbv
43534358
_ZNK2cl4sycl7sampler18get_filtering_modeEv
43544359
_ZNK2cl4sycl7sampler19get_addressing_modeEv
43554360
_ZNK2cl4sycl7sampler33get_coordinate_normalization_modeEv
@@ -4377,7 +4382,3 @@ _ZNK2cl4sycl9exception8categoryEv
43774382
_ZNK2cl4sycl9kernel_id8get_nameEv
43784383
__sycl_register_lib
43794384
__sycl_unregister_lib
4380-
_ZNK2cl4sycl6device8get_infoILNS0_4info6deviceE131072EEENS3_12param_traitsIS4_XT_EE11return_typeEv
4381-
_ZNK2cl4sycl6device8get_infoILNS0_4info6deviceE131075EEENS3_12param_traitsIS4_XT_EE11return_typeEv
4382-
_ZNK2cl4sycl6device8get_infoILNS0_4info6deviceE131074EEENS3_12param_traitsIS4_XT_EE11return_typeEv
4383-
_ZNK2cl4sycl6device8get_infoILNS0_4info6deviceE131073EEENS3_12param_traitsIS4_XT_EE11return_typeEv

0 commit comments

Comments
 (0)