Skip to content

Commit 9fdef43

Browse files
[SYCL][ABI-Break] ABI-neutralize has-kernel (#13447)
Signed-off-by: Byoungro So <byoungro.so@intel.com> Co-authored-by: Steffen Larsen <steffen.larsen@intel.com>
1 parent 2bac63f commit 9fdef43

File tree

5 files changed

+142
-54
lines changed

5 files changed

+142
-54
lines changed

sycl/include/sycl/kernel_bundle.hpp

Lines changed: 73 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -186,9 +186,13 @@ class __SYCL_EXPORT kernel_bundle_plain {
186186

187187
bool native_specialization_constant() const noexcept;
188188

189-
bool ext_oneapi_has_kernel(const std::string &name);
189+
bool ext_oneapi_has_kernel(const std::string &name) {
190+
return ext_oneapi_has_kernel(detail::string_view{name});
191+
}
190192

191-
kernel ext_oneapi_get_kernel(const std::string &name);
193+
kernel ext_oneapi_get_kernel(const std::string &name) {
194+
return ext_oneapi_get_kernel(detail::string_view{name});
195+
}
192196

193197
protected:
194198
// \returns a kernel object which represents the kernel identified by
@@ -214,6 +218,10 @@ class __SYCL_EXPORT kernel_bundle_plain {
214218
bool is_specialization_constant_set(const char *SpecName) const noexcept;
215219

216220
detail::KernelBundleImplPtr impl;
221+
222+
private:
223+
bool ext_oneapi_has_kernel(detail::string_view name);
224+
kernel ext_oneapi_get_kernel(detail::string_view name);
217225
};
218226

219227
} // namespace detail
@@ -897,26 +905,84 @@ __SYCL_EXPORT bool is_source_kernel_bundle_supported(backend BE,
897905
source_language Language);
898906

899907
__SYCL_EXPORT kernel_bundle<bundle_state::ext_oneapi_source>
908+
make_kernel_bundle_from_source(
909+
const context &SyclContext, source_language Language,
910+
sycl::detail::string_view Source,
911+
std::vector<std::pair<sycl::detail::string_view, sycl::detail::string_view>>
912+
IncludePairsVec);
913+
914+
inline kernel_bundle<bundle_state::ext_oneapi_source>
900915
make_kernel_bundle_from_source(
901916
const context &SyclContext, source_language Language,
902917
const std::string &Source,
903-
std::vector<std::pair<std::string, std::string>> IncludePairsVec);
918+
std::vector<std::pair<std::string, std::string>> IncludePairsVec) {
919+
size_t n = IncludePairsVec.size();
920+
std::vector<std::pair<sycl::detail::string_view, sycl::detail::string_view>>
921+
PairVec;
922+
PairVec.reserve(n);
923+
for (auto &Pair : IncludePairsVec)
924+
PairVec.push_back({sycl::detail::string_view{Pair.first},
925+
sycl::detail::string_view{Pair.second}});
926+
927+
return make_kernel_bundle_from_source(
928+
SyclContext, Language, sycl::detail::string_view{Source}, PairVec);
929+
}
904930

905931
#if (!defined(_HAS_STD_BYTE) || _HAS_STD_BYTE != 0)
906932
__SYCL_EXPORT kernel_bundle<bundle_state::ext_oneapi_source>
907933
make_kernel_bundle_from_source(
908934
const context &SyclContext, source_language Language,
909935
const std::vector<std::byte> &Bytes,
910-
std::vector<std::pair<std::string, std::string>> IncludePairsVec);
936+
std::vector<std::pair<sycl::detail::string_view, sycl::detail::string_view>>
937+
IncludePairsVec);
938+
939+
inline kernel_bundle<bundle_state::ext_oneapi_source>
940+
make_kernel_bundle_from_source(
941+
const context &SyclContext, source_language Language,
942+
const std::vector<std::byte> &Bytes,
943+
std::vector<std::pair<std::string, std::string>> IncludePairsVec) {
944+
size_t n = IncludePairsVec.size();
945+
std::vector<std::pair<sycl::detail::string_view, sycl::detail::string_view>>
946+
PairVec;
947+
PairVec.reserve(n);
948+
for (auto &Pair : IncludePairsVec)
949+
PairVec.push_back({sycl::detail::string_view{Pair.first},
950+
sycl::detail::string_view{Pair.second}});
951+
952+
return make_kernel_bundle_from_source(SyclContext, Language, Bytes, PairVec);
953+
}
911954
#endif
912955

913-
__SYCL_EXPORT kernel_bundle<bundle_state::executable>
956+
__SYCL_EXPORT kernel_bundle<bundle_state::executable> build_from_source(
957+
kernel_bundle<bundle_state::ext_oneapi_source> &SourceKB,
958+
const std::vector<device> &Devices,
959+
const std::vector<sycl::detail::string_view> &BuildOptions,
960+
sycl::detail::string *LogPtr,
961+
const std::vector<sycl::detail::string_view> &RegisteredKernelNames);
962+
963+
inline kernel_bundle<bundle_state::executable>
914964
build_from_source(kernel_bundle<bundle_state::ext_oneapi_source> &SourceKB,
915965
const std::vector<device> &Devices,
916966
const std::vector<std::string> &BuildOptions,
917967
std::string *LogPtr,
918-
const std::vector<std::string> &RegisteredKernelNames);
919-
968+
const std::vector<std::string> &RegisteredKernelNames) {
969+
std::vector<sycl::detail::string_view> Options;
970+
for (const std::string &opt : BuildOptions)
971+
Options.push_back(sycl::detail::string_view{opt});
972+
973+
std::vector<sycl::detail::string_view> KernelNames;
974+
for (const std::string &name : RegisteredKernelNames)
975+
KernelNames.push_back(sycl::detail::string_view{name});
976+
977+
if (LogPtr) {
978+
sycl::detail::string Log;
979+
auto result =
980+
build_from_source(SourceKB, Devices, Options, &Log, KernelNames);
981+
*LogPtr = Log.c_str();
982+
return result;
983+
}
984+
return build_from_source(SourceKB, Devices, Options, nullptr, KernelNames);
985+
}
920986
} // namespace detail
921987

922988
/////////////////////////

sycl/source/kernel_bundle.cpp

Lines changed: 42 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -115,12 +115,12 @@ bool kernel_bundle_plain::is_specialization_constant_set(
115115
return impl->is_specialization_constant_set(SpecName);
116116
}
117117

118-
bool kernel_bundle_plain::ext_oneapi_has_kernel(const std::string &name) {
119-
return impl->ext_oneapi_has_kernel(name);
118+
bool kernel_bundle_plain::ext_oneapi_has_kernel(detail::string_view name) {
119+
return impl->ext_oneapi_has_kernel(name.data());
120120
}
121121

122-
kernel kernel_bundle_plain::ext_oneapi_get_kernel(const std::string &name) {
123-
return impl->ext_oneapi_get_kernel(name, impl);
122+
kernel kernel_bundle_plain::ext_oneapi_get_kernel(detail::string_view name) {
123+
return impl->ext_oneapi_get_kernel(name.data(), impl);
124124
}
125125

126126
//////////////////////////////////
@@ -391,14 +391,24 @@ bool is_source_kernel_bundle_supported(backend BE, source_language Language) {
391391
/////////////////////////
392392

393393
using include_pairs_t = std::vector<std::pair<std::string, std::string>>;
394-
395-
source_kb make_kernel_bundle_from_source(const context &SyclContext,
396-
source_language Language,
397-
const std::string &Source,
398-
include_pairs_t IncludePairs) {
394+
using include_pairs_view_t = std::vector<
395+
std::pair<sycl::detail::string_view, sycl::detail::string_view>>;
396+
397+
source_kb
398+
make_kernel_bundle_from_source(const context &SyclContext,
399+
source_language Language,
400+
sycl::detail::string_view SourceView,
401+
include_pairs_view_t IncludePairViews) {
399402
// TODO: if we later support a "reason" why support isn't present
400403
// (like a missing shared library etc.) it'd be nice to include it in
401404
// the exception message here.
405+
std::string Source{SourceView.data()};
406+
include_pairs_t IncludePairs;
407+
size_t n = IncludePairViews.size();
408+
IncludePairs.reserve(n);
409+
for (auto &p : IncludePairViews)
410+
IncludePairs.push_back({p.first.data(), p.second.data()});
411+
402412
backend BE = SyclContext.get_backend();
403413
if (!is_source_kernel_bundle_supported(BE, Language))
404414
throw sycl::exception(make_error_code(errc::invalid),
@@ -417,7 +427,7 @@ source_kb make_kernel_bundle_from_source(const context &SyclContext,
417427
source_kb make_kernel_bundle_from_source(const context &SyclContext,
418428
source_language Language,
419429
const std::vector<std::byte> &Bytes,
420-
include_pairs_t IncludePairs) {
430+
include_pairs_view_t IncludePairs) {
421431
(void)IncludePairs;
422432
backend BE = SyclContext.get_backend();
423433
if (!is_source_kernel_bundle_supported(BE, Language))
@@ -433,17 +443,32 @@ source_kb make_kernel_bundle_from_source(const context &SyclContext,
433443
// syclex::detail::build_from_source(source_kb) => exe_kb
434444
/////////////////////////
435445

436-
exe_kb
437-
build_from_source(source_kb &SourceKB, const std::vector<device> &Devices,
438-
const std::vector<std::string> &BuildOptions,
439-
std::string *LogPtr,
440-
const std::vector<std::string> &RegisteredKernelNames) {
446+
exe_kb build_from_source(
447+
source_kb &SourceKB, const std::vector<device> &Devices,
448+
const std::vector<sycl::detail::string_view> &BuildOptions,
449+
sycl::detail::string *LogView,
450+
const std::vector<sycl::detail::string_view> &RegisteredKernelNames) {
451+
std::vector<std::string> Options;
452+
for (const sycl::detail::string_view option : BuildOptions)
453+
Options.push_back(option.data());
454+
455+
std::vector<std::string> KernelNames;
456+
for (const sycl::detail::string_view name : RegisteredKernelNames)
457+
KernelNames.push_back(name.data());
458+
459+
std::string Log;
460+
std::string *LogPtr = nullptr;
461+
if (LogView)
462+
LogPtr = &Log;
441463
std::vector<device> UniqueDevices =
442464
sycl::detail::removeDuplicateDevices(Devices);
443465
std::shared_ptr<kernel_bundle_impl> sourceImpl = getSyclObjImpl(SourceKB);
444466
std::shared_ptr<kernel_bundle_impl> KBImpl = sourceImpl->build_from_source(
445-
UniqueDevices, BuildOptions, LogPtr, RegisteredKernelNames);
446-
return sycl::detail::createSyclObjFromImpl<exe_kb>(KBImpl);
467+
UniqueDevices, Options, LogPtr, KernelNames);
468+
auto result = sycl::detail::createSyclObjFromImpl<exe_kb>(KBImpl);
469+
if (LogView)
470+
*LogView = Log;
471+
return result;
447472
}
448473

449474
} // namespace detail

sycl/test/abi/sycl_abi_neutrality_test.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,6 @@
1818
// CHECK:_ZN4sycl3_V13ext5intel12experimental15online_compilerILNS3_15source_languageE0EE7compileIJSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaISE_EEEEES8_IhSaIhEERKSE_DpRKT_
1919
// CHECK:_ZN4sycl3_V13ext5intel12experimental15online_compilerILNS3_15source_languageE1EE7compileIJSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaISE_EEEEES8_IhSaIhEERKSE_DpRKT_
2020
// CHECK:_ZN4sycl3_V13ext5intel12experimental9pipe_base13get_pipe_nameB5cxx11EPKv
21-
// CHECK:_ZN4sycl3_V13ext6oneapi12experimental6detail17build_from_sourceERNS0_13kernel_bundleILNS0_12bundle_stateE3EEERKSt6vectorINS0_6deviceESaISA_EERKS9_INSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaISK_EEPSK_SO_
22-
// CHECK:_ZN4sycl3_V13ext6oneapi12experimental6detail30make_kernel_bundle_from_sourceERKNS0_7contextENS3_15source_languageERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESt6vectorISt4pairISE_SE_ESaISJ_EE
23-
// CHECK:_ZN4sycl3_V13ext6oneapi12experimental6detail30make_kernel_bundle_from_sourceERKNS0_7contextENS3_15source_languageERKSt6vectorISt4byteSaISA_EES9_ISt4pairINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESL_ESaISM_EE
24-
// CHECK:_ZN4sycl3_V16detail19kernel_bundle_plain21ext_oneapi_get_kernelERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
25-
// CHECK:_ZN4sycl3_V16detail19kernel_bundle_plain21ext_oneapi_has_kernelERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
2621
// CHECK:_ZN4sycl3_V16detail6OSUtil10getDirNameB5cxx11EPKc
2722
// CHECK:_ZN4sycl3_V16detail6OSUtil16getCurrentDSODirB5cxx11Ev
2823
// CHECK:_ZN4sycl3_V16opencl13has_extensionERKNS0_6deviceERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE

sycl/test/abi/sycl_symbols_linux.dump

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3059,7 +3059,7 @@ _ZN4sycl3_V13ext6oneapi12experimental6detail14image_mem_implC1ERKNS3_16image_des
30593059
_ZN4sycl3_V13ext6oneapi12experimental6detail14image_mem_implC2ERKNS3_16image_descriptorERKNS0_6deviceERKNS0_7contextE
30603060
_ZN4sycl3_V13ext6oneapi12experimental6detail14image_mem_implD1Ev
30613061
_ZN4sycl3_V13ext6oneapi12experimental6detail14image_mem_implD2Ev
3062-
_ZN4sycl3_V13ext6oneapi12experimental6detail17build_from_sourceERNS0_13kernel_bundleILNS0_12bundle_stateE3EEERKSt6vectorINS0_6deviceESaISA_EERKS9_INSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaISK_EEPSK_SO_
3062+
_ZN4sycl3_V13ext6oneapi12experimental6detail17build_from_sourceERNS0_13kernel_bundleILNS0_12bundle_stateE3EEERKSt6vectorINS0_6deviceESaISA_EERKS9_INS0_6detail11string_viewESaISG_EEPNSF_6stringESK_
30633063
_ZN4sycl3_V13ext6oneapi12experimental6detail22dynamic_parameter_base11updateValueEPKvm
30643064
_ZN4sycl3_V13ext6oneapi12experimental6detail22dynamic_parameter_base14updateAccessorEPKNS0_6detail16AccessorBaseHostE
30653065
_ZN4sycl3_V13ext6oneapi12experimental6detail22dynamic_parameter_baseC1ENS3_13command_graphILNS3_11graph_stateE0EEEmPKv
@@ -3083,8 +3083,8 @@ _ZN4sycl3_V13ext6oneapi12experimental6detail24modifiable_command_graphC1ERKNS0_5
30833083
_ZN4sycl3_V13ext6oneapi12experimental6detail24modifiable_command_graphC1ERKNS0_7contextERKNS0_6deviceERKNS0_13property_listE
30843084
_ZN4sycl3_V13ext6oneapi12experimental6detail24modifiable_command_graphC2ERKNS0_5queueERKNS0_13property_listE
30853085
_ZN4sycl3_V13ext6oneapi12experimental6detail24modifiable_command_graphC2ERKNS0_7contextERKNS0_6deviceERKNS0_13property_listE
3086-
_ZN4sycl3_V13ext6oneapi12experimental6detail30make_kernel_bundle_from_sourceERKNS0_7contextENS3_15source_languageERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESt6vectorISt4pairISE_SE_ESaISJ_EE
3087-
_ZN4sycl3_V13ext6oneapi12experimental6detail30make_kernel_bundle_from_sourceERKNS0_7contextENS3_15source_languageERKSt6vectorISt4byteSaISA_EES9_ISt4pairINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESL_ESaISM_EE
3086+
_ZN4sycl3_V13ext6oneapi12experimental6detail30make_kernel_bundle_from_sourceERKNS0_7contextENS3_15source_languageENS0_6detail11string_viewESt6vectorISt4pairISA_SA_ESaISD_EE
3087+
_ZN4sycl3_V13ext6oneapi12experimental6detail30make_kernel_bundle_from_sourceERKNS0_7contextENS3_15source_languageERKSt6vectorISt4byteSaISA_EES9_ISt4pairINS0_6detail11string_viewESH_ESaISI_EE
30883088
_ZN4sycl3_V13ext6oneapi12experimental6detail33is_source_kernel_bundle_supportedENS0_7backendENS3_15source_languageE
30893089
_ZN4sycl3_V13ext6oneapi12experimental6memcpyENS0_5queueEPvPKvmRKNS0_6detail13code_locationE
30903090
_ZN4sycl3_V13ext6oneapi12experimental6memsetENS0_5queueEPvimRKNS0_6detail13code_locationE
@@ -3256,8 +3256,8 @@ _ZN4sycl3_V16detail18get_kernel_id_implENS1_11string_viewE
32563256
_ZN4sycl3_V16detail18make_kernel_bundleEmRKNS0_7contextENS0_12bundle_stateENS0_7backendE
32573257
_ZN4sycl3_V16detail18make_kernel_bundleEmRKNS0_7contextEbNS0_12bundle_stateENS0_7backendE
32583258
_ZN4sycl3_V16detail18stringifyErrorCodeEi
3259-
_ZN4sycl3_V16detail19kernel_bundle_plain21ext_oneapi_get_kernelERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
3260-
_ZN4sycl3_V16detail19kernel_bundle_plain21ext_oneapi_has_kernelERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
3259+
_ZN4sycl3_V16detail19kernel_bundle_plain21ext_oneapi_get_kernelENS1_11string_viewE
3260+
_ZN4sycl3_V16detail19kernel_bundle_plain21ext_oneapi_has_kernelENS1_11string_viewE
32613261
_ZN4sycl3_V16detail19kernel_bundle_plain32set_specialization_constant_implEPKcPvm
32623262
_ZN4sycl3_V16detail20associateWithHandlerERNS0_7handlerEPNS1_16AccessorBaseHostENS0_6access6targetE
32633263
_ZN4sycl3_V16detail20associateWithHandlerERNS0_7handlerEPNS1_28SampledImageAccessorBaseHostENS0_12image_targetE
@@ -3501,24 +3501,24 @@ _ZN4sycl3_V17handler22ext_oneapi_fill2d_implEPvmPKvmmm
35013501
_ZN4sycl3_V17handler22memcpyFromDeviceGlobalEPvPKvbmm
35023502
_ZN4sycl3_V17handler22setHandlerKernelBundleENS0_6kernelE
35033503
_ZN4sycl3_V17handler22setHandlerKernelBundleERKSt10shared_ptrINS0_6detail18kernel_bundle_implEE
3504+
_ZN4sycl3_V17handler22setKernelClusterLaunchENS0_5rangeILi3EEEi
35043505
_ZN4sycl3_V17handler22setKernelIsCooperativeEb
35053506
_ZN4sycl3_V17handler24GetRangeRoundingSettingsERmS2_S2_
35063507
_ZN4sycl3_V17handler24ext_intel_read_host_pipeENS0_6detail11string_viewEPvmb
35073508
_ZN4sycl3_V17handler24ext_oneapi_memcpy2d_implEPvmPKvmmm
35083509
_ZN4sycl3_V17handler24ext_oneapi_memset2d_implEPvmimm
35093510
_ZN4sycl3_V17handler24registerDynamicParameterERNS0_3ext6oneapi12experimental6detail22dynamic_parameter_baseEi
35103511
_ZN4sycl3_V17handler25ext_intel_write_host_pipeENS0_6detail11string_viewEPvmb
3511-
_ZN4sycl3_V17handler26setNDRangeDescriptorPaddedENS0_5rangeILi3EEEbi
3512+
_ZN4sycl3_V17handler26associateWithHandlerCommonESt10shared_ptrINS0_6detail16AccessorImplHostEEi
35123513
_ZN4sycl3_V17handler26setNDRangeDescriptorPaddedENS0_5rangeILi3EEENS0_2idILi3EEEi
35133514
_ZN4sycl3_V17handler26setNDRangeDescriptorPaddedENS0_5rangeILi3EEES3_NS0_2idILi3EEEi
3514-
_ZN4sycl3_V17handler26associateWithHandlerCommonESt10shared_ptrINS0_6detail16AccessorImplHostEEi
3515+
_ZN4sycl3_V17handler26setNDRangeDescriptorPaddedENS0_5rangeILi3EEEbi
35153516
_ZN4sycl3_V17handler27addLifetimeSharedPtrStorageESt10shared_ptrIKvE
3516-
_ZN4sycl3_V17handler22setKernelClusterLaunchENS0_5rangeILi3EEEi
35173517
_ZN4sycl3_V17handler27computeFallbackKernelBoundsEmm
35183518
_ZN4sycl3_V17handler28extractArgsAndReqsFromLambdaEPcmPKNS0_6detail19kernel_param_desc_tEb
35193519
_ZN4sycl3_V17handler28memcpyToHostOnlyDeviceGlobalEPKvS3_mbmm
3520-
_ZN4sycl3_V17handler28setStateExplicitKernelBundleEv
35213520
_ZN4sycl3_V17handler28setArgsToAssociatedAccessorsEv
3521+
_ZN4sycl3_V17handler28setStateExplicitKernelBundleEv
35223522
_ZN4sycl3_V17handler30memcpyFromHostOnlyDeviceGlobalEPvPKvbmm
35233523
_ZN4sycl3_V17handler30verifyUsedKernelBundleInternalENS0_6detail11string_viewE
35243524
_ZN4sycl3_V17handler32verifyDeviceHasProgressGuaranteeENS0_3ext6oneapi12experimental26forward_progress_guaranteeENS4_15execution_scopeES6_

0 commit comments

Comments
 (0)