Skip to content

[SYCL] interim kernel compiler with SYCL support #14172

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
c285518
checkpoint
cperkinsintel Apr 9, 2024
6c2c911
prepare to be templated
cperkinsintel Apr 9, 2024
60d7759
scaffolding
cperkinsintel Apr 10, 2024
06deabf
kernel_compiler testing, preliminary
cperkinsintel Apr 10, 2024
4ea7836
working e2e. next: flags, errors, removal of is_source_kernel_bundle…
cperkinsintel Apr 10, 2024
54be4d0
housekeeping before continuing. also, clang-format sux
cperkinsintel Apr 10, 2024
1a9cf00
flags and testing of such
cperkinsintel Apr 10, 2024
b21ee06
implemented sycl_compilation_available
cperkinsintel Apr 10, 2024
1bff1f6
move is_source_kernel_bundle_supported out of API into detail. minor …
cperkinsintel Apr 11, 2024
dcb54ce
win
cperkinsintel Apr 11, 2024
16e3d69
interim registered_kernel_names implementation. this is NOT final
cperkinsintel May 20, 2024
7163a1d
merge conflics and test bump
cperkinsintel Jun 13, 2024
3c048c3
clang-format and linux symbols
cperkinsintel Jun 19, 2024
8dbc79b
test updates
cperkinsintel Jun 19, 2024
a417f55
Merge branch 'sycl' into cperkins-kernel_compiler-sycl-cherry-picked
cperkinsintel Jun 20, 2024
ae8f936
resolve merge conflicts and bump counter for the #include <sycl.hpp> …
cperkinsintel Jun 20, 2024
531bcbc
win fix and symbols
cperkinsintel Jun 20, 2024
e3cc1d2
std::byte screen
cperkinsintel Jun 20, 2024
4445525
patch from rajiv for name mangling fix on extern C and concominant te…
cperkinsintel Jun 24, 2024
424da1b
excluding kernel_compiler+sycl from GCC<8 b.c. std:filesystem.
cperkinsintel Jun 24, 2024
0c9d024
clang-format?
cperkinsintel Jun 24, 2024
934d8fa
clang-format and ns fix
cperkinsintel Jun 26, 2024
27ad9d7
reviewer feedback
cperkinsintel Jun 27, 2024
ad634bd
reviewer feedback, but needs cleanup
cperkinsintel Jun 27, 2024
cec9a7d
clean up and test improvements
cperkinsintel Jun 27, 2024
7eb8f44
more reviewer feedback
cperkinsintel Jun 28, 2024
132525c
add esimd_kernel to testing
cperkinsintel Jul 1, 2024
3cf1fc6
resolve merge conflicts. need to regen win syms
cperkinsintel Jul 1, 2024
b71925c
win symbols
cperkinsintel Jul 2, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 16 additions & 10 deletions clang/lib/Sema/SemaSYCL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1111,18 +1111,24 @@ static std::pair<std::string, std::string> constructFreeFunctionKernelName(
SemaSYCL &SemaSYCLRef, const FunctionDecl *FreeFunc, MangleContext &MC) {
SmallString<256> Result;
llvm::raw_svector_ostream Out(Result);
std::string NewName;
std::string StableName;

MC.mangleName(FreeFunc, Out);
std::string MangledName(Out.str());
size_t StartNums = MangledName.find_first_of("0123456789");
size_t EndNums = MangledName.find_first_not_of("0123456789", StartNums);
size_t NameLength =
std::stoi(MangledName.substr(StartNums, EndNums - StartNums));
size_t NewNameLength = 14 /*length of __sycl_kernel_*/ + NameLength;
std::string NewName = MangledName.substr(0, StartNums) +
std::to_string(NewNameLength) + "__sycl_kernel_" +
MangledName.substr(EndNums);
// Handle extern "C"
if (FreeFunc->getLanguageLinkage() == CLanguageLinkage) {
const IdentifierInfo *II = FreeFunc->getIdentifier();
NewName = "__sycl_kernel_" + II->getName().str();
} else {
MC.mangleName(FreeFunc, Out);
std::string MangledName(Out.str());
size_t StartNums = MangledName.find_first_of("0123456789");
size_t EndNums = MangledName.find_first_not_of("0123456789", StartNums);
size_t NameLength =
std::stoi(MangledName.substr(StartNums, EndNums - StartNums));
size_t NewNameLength = 14 /*length of __sycl_kernel_*/ + NameLength;
NewName = MangledName.substr(0, StartNums) + std::to_string(NewNameLength) +
"__sycl_kernel_" + MangledName.substr(EndNums);
}
StableName = NewName;
return {NewName, StableName};
}
Expand Down
4 changes: 3 additions & 1 deletion sycl/include/sycl/ext/oneapi/properties/property.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,10 @@ enum PropKind : uint32_t {
CallsIndirectly = 68,
InputDataPlacement = 69,
OutputDataPlacement = 70,
IncludeFiles = 71,
RegisteredKernelNames = 72,
// PropKindSize must always be the last value.
PropKindSize = 71,
PropKindSize = 73,
};

struct property_key_base_tag {};
Expand Down
141 changes: 113 additions & 28 deletions sycl/include/sycl/kernel_bundle.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -814,6 +814,32 @@ build(const kernel_bundle<bundle_state::input> &InputBundle,

namespace ext::oneapi::experimental {

namespace detail {
struct create_bundle_from_source_props;
struct build_source_bundle_props;
} // namespace detail

/////////////////////////
// PropertyT syclex::include_files
/////////////////////////
struct include_files
: detail::run_time_property_key<detail::PropKind::IncludeFiles> {
include_files();
include_files(const std::string &name, const std::string &content) {
record.emplace_back(std::make_pair(name, content));
}
void add(const std::string &name, const std::string &content) {
record.emplace_back(std::make_pair(name, content));
}
std::vector<std::pair<std::string, std::string>> record;
};
using include_files_key = include_files;

template <>
struct is_property_key_of<include_files_key,
detail::create_bundle_from_source_props>
: std::true_type {};

/////////////////////////
// PropertyT syclex::build_options
/////////////////////////
Expand All @@ -826,8 +852,7 @@ struct build_options
using build_options_key = build_options;

template <>
struct is_property_key_of<build_options_key,
sycl::kernel_bundle<bundle_state::ext_oneapi_source>>
struct is_property_key_of<build_options_key, detail::build_source_bundle_props>
: std::true_type {};

/////////////////////////
Expand All @@ -840,72 +865,132 @@ struct save_log : detail::run_time_property_key<detail::PropKind::BuildLog> {
using save_log_key = save_log;

template <>
struct is_property_key_of<save_log_key,
sycl::kernel_bundle<bundle_state::ext_oneapi_source>>
struct is_property_key_of<save_log_key, detail::build_source_bundle_props>
: std::true_type {};

/////////////////////////
// syclex::is_source_kernel_bundle_supported
// PropertyT syclex::registered_kernel_names
/////////////////////////
struct registered_kernel_names
: detail::run_time_property_key<detail::PropKind::RegisteredKernelNames> {
std::vector<std::string> kernel_names;
registered_kernel_names() {}
registered_kernel_names(const std::string &knArg) : kernel_names{knArg} {}
registered_kernel_names(const std::vector<std::string> &knsArg)
: kernel_names(knsArg) {}
void add(const std::string &name) { kernel_names.push_back(name); }
};
using registered_kernel_names_key = registered_kernel_names;

template <>
struct is_property_key_of<registered_kernel_names_key,
detail::build_source_bundle_props> : std::true_type {
};

namespace detail {
// forward decls
__SYCL_EXPORT bool is_source_kernel_bundle_supported(backend BE,
source_language Language);

/////////////////////////
// syclex::create_kernel_bundle_from_source
/////////////////////////

__SYCL_EXPORT kernel_bundle<bundle_state::ext_oneapi_source>
create_kernel_bundle_from_source(const context &SyclContext,
source_language Language,
const std::string &Source);
make_kernel_bundle_from_source(
const context &SyclContext, source_language Language,
const std::string &Source,
std::vector<std::pair<std::string, std::string>> IncludePairsVec);

#if (!defined(_HAS_STD_BYTE) || _HAS_STD_BYTE != 0)
__SYCL_EXPORT kernel_bundle<bundle_state::ext_oneapi_source>
create_kernel_bundle_from_source(const context &SyclContext,
source_language Language,
const std::vector<std::byte> &Bytes);
make_kernel_bundle_from_source(
const context &SyclContext, source_language Language,
const std::vector<std::byte> &Bytes,
std::vector<std::pair<std::string, std::string>> IncludePairsVec);
#endif

/////////////////////////
// syclex::build(source_kb) => exe_kb
/////////////////////////
namespace detail {
// forward decl
__SYCL_EXPORT kernel_bundle<bundle_state::executable>
build_from_source(kernel_bundle<bundle_state::ext_oneapi_source> &SourceKB,
const std::vector<device> &Devices,
const std::vector<std::string> &BuildOptions,
std::string *LogPtr);
std::string *LogPtr,
const std::vector<std::string> &RegisteredKernelNames);

} // namespace detail

/////////////////////////
// syclex::create_kernel_bundle_from_source
/////////////////////////
template <
typename PropertyListT = empty_properties_t,
typename = std::enable_if_t<
is_property_list_v<PropertyListT> &&
detail::all_props_are_keys_of<detail::create_bundle_from_source_props,
PropertyListT>::value>>
kernel_bundle<bundle_state::ext_oneapi_source> create_kernel_bundle_from_source(
const context &SyclContext, source_language Language,
const std::string &Source, PropertyListT props = {}) {
std::vector<std::pair<std::string, std::string>> IncludePairsVec;
if constexpr (props.template has_property<include_files>()) {
IncludePairsVec = props.template get_property<include_files>().record;
}

return detail::make_kernel_bundle_from_source(SyclContext, Language, Source,
IncludePairsVec);
}

#if (!defined(_HAS_STD_BYTE) || _HAS_STD_BYTE != 0)
template <
typename PropertyListT = empty_properties_t,
typename = std::enable_if_t<
is_property_list_v<PropertyListT> &&
detail::all_props_are_keys_of<detail::create_bundle_from_source_props,
PropertyListT>::value>>
kernel_bundle<bundle_state::ext_oneapi_source> create_kernel_bundle_from_source(
const context &SyclContext, source_language Language,
const std::vector<std::byte> &Bytes, PropertyListT props = {}) {
std::vector<std::pair<std::string, std::string>> IncludePairsVec;
if constexpr (props.template has_property<include_files>()) {
IncludePairsVec = props.template get_property<include_files>().record;
}

return detail::make_kernel_bundle_from_source(SyclContext, Language, Bytes,
IncludePairsVec);
}
#endif

/////////////////////////
// syclex::build(source_kb) => exe_kb
/////////////////////////

template <typename PropertyListT = empty_properties_t,
typename = std::enable_if_t<
is_property_list_v<PropertyListT> &&
detail::all_props_are_keys_of<
kernel_bundle<bundle_state::ext_oneapi_source>,
PropertyListT>::value>>
detail::all_props_are_keys_of<detail::build_source_bundle_props,
PropertyListT>::value>>

kernel_bundle<bundle_state::executable>
build(kernel_bundle<bundle_state::ext_oneapi_source> &SourceKB,
const std::vector<device> &Devices, PropertyListT props = {}) {
std::vector<std::string> BuildOptionsVec;
std::string *LogPtr = nullptr;
std::vector<std::string> RegisteredKernelNamesVec;
if constexpr (props.template has_property<build_options>()) {
BuildOptionsVec = props.template get_property<build_options>().opts;
}
if constexpr (props.template has_property<save_log>()) {
LogPtr = props.template get_property<save_log>().log;
}
return detail::build_from_source(SourceKB, Devices, BuildOptionsVec, LogPtr);
if constexpr (props.template has_property<registered_kernel_names>()) {
RegisteredKernelNamesVec =
props.template get_property<registered_kernel_names>().kernel_names;
}
return detail::build_from_source(SourceKB, Devices, BuildOptionsVec, LogPtr,
RegisteredKernelNamesVec);
}

template <typename PropertyListT = empty_properties_t,
typename = std::enable_if_t<
is_property_list_v<PropertyListT> &&
detail::all_props_are_keys_of<
kernel_bundle<bundle_state::ext_oneapi_source>,
PropertyListT>::value>>
detail::all_props_are_keys_of<detail::build_source_bundle_props,
PropertyListT>::value>>
kernel_bundle<bundle_state::executable>
build(kernel_bundle<bundle_state::ext_oneapi_source> &SourceKB,
PropertyListT props = {}) {
Expand Down
2 changes: 1 addition & 1 deletion sycl/include/sycl/kernel_bundle_enums.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ enum class bundle_state : char {

namespace ext::oneapi::experimental {

enum class source_language : int { opencl = 0, spirv = 1 /* sycl, cuda */ };
enum class source_language : int { opencl = 0, spirv = 1, sycl = 2 /* cuda */ };

// opencl versions
struct cl_version {
Expand Down
1 change: 1 addition & 0 deletions sycl/source/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ set(SYCL_COMMON_SOURCES
"detail/jit_compiler.cpp"
"detail/jit_device_binaries.cpp"
"detail/kernel_compiler/kernel_compiler_opencl.cpp"
"detail/kernel_compiler/kernel_compiler_sycl.cpp"
"detail/kernel_impl.cpp"
"detail/kernel_program_cache.cpp"
"detail/memory_manager.cpp"
Expand Down
3 changes: 2 additions & 1 deletion sycl/source/detail/device_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -862,7 +862,8 @@ bool device_impl::isGetDeviceAndHostTimerSupported() {
bool device_impl::extOneapiCanCompile(
ext::oneapi::experimental::source_language Language) {
try {
return is_source_kernel_bundle_supported(getBackend(), Language);
return sycl::ext::oneapi::experimental::detail::
is_source_kernel_bundle_supported(getBackend(), Language);
} catch (sycl::exception &) {
return false;
}
Expand Down
Loading
Loading