Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
22 changes: 11 additions & 11 deletions sycl/include/sycl/backend.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,13 @@
#include <sycl/event.hpp> // for event, get_native
#include <sycl/exception.hpp> // for make_error_code
#include <sycl/feature_test.hpp> // for SYCL_BACKEND_OP...
#include <sycl/handler.hpp> // for buffer
#include <sycl/image.hpp> // for image, image_al...
#include <sycl/kernel.hpp> // for kernel, get_native
#include <sycl/kernel_bundle.hpp> // for kernel_bundle
#include <sycl/kernel_bundle_enums.hpp> // for bundle_state
#include <sycl/platform.hpp> // for platform, get_n...
#include <sycl/property_list.hpp> // for property_list
#include <sycl/queue.hpp> // for queue, get_native
#include <ur_api.h> // for ur_native_handle_t
#include <sycl/kernel_bundle_enums.hpp> // for bundle_state
#include <sycl/platform.hpp> // for platform, get_n...
#include <sycl/property_list.hpp> // for property_list
#include <sycl/queue.hpp>
#include <ur_api.h> // for ur_native_handle_t

#if SYCL_BACKEND_OPENCL
#include <sycl/detail/backend_traits_opencl.hpp> // for interop
Expand All @@ -47,7 +45,7 @@
#include <sycl/detail/backend_traits_hip.hpp>
#endif
#if SYCL_EXT_ONEAPI_BACKEND_LEVEL_ZERO
#include <sycl/detail/backend_traits_level_zero.hpp> // for _ze_command_lis...
// #include <sycl/detail/backend_traits_level_zero.hpp> // for _ze_command_lis...
#endif

#include <sycl/detail/ur.hpp>
Expand All @@ -60,13 +58,13 @@
namespace sycl {
inline namespace _V1 {

template<bundle_state State>
class kernel_bundle;

namespace detail {
// TODO each backend can have its own custom errc enumeration
// but the details for this are not fully specified yet
enum class backend_errc : unsigned int {};

// Convert from UR backend to SYCL backend enum
backend convertUrBackend(ur_platform_backend_t UrBackend);
} // namespace detail

template <backend Backend> class backend_traits {
Expand Down Expand Up @@ -154,13 +152,15 @@ auto get_native(const queue &Obj) -> backend_return_t<BackendName, queue> {
int32_t IsImmCmdList;
ur_native_handle_t Handle = Obj.getNative(IsImmCmdList);
backend_return_t<BackendName, queue> RetVal;
#if 0 && SYCL_EXT_ONEAPI_BACKEND_LEVEL_ZERO
if constexpr (BackendName == backend::ext_oneapi_level_zero)
RetVal = IsImmCmdList
? backend_return_t<BackendName, queue>{reinterpret_cast<
ze_command_list_handle_t>(Handle)}
: backend_return_t<BackendName, queue>{
reinterpret_cast<ze_command_queue_handle_t>(Handle)};
else
#endif
RetVal = reinterpret_cast<backend_return_t<BackendName, queue>>(Handle);

return RetVal;
Expand Down
1 change: 0 additions & 1 deletion sycl/include/sycl/detail/backend_traits_cuda.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
#include <sycl/detail/backend_traits.hpp>
#include <sycl/device.hpp>
#include <sycl/event.hpp>
#include <sycl/kernel_bundle.hpp>
#include <sycl/queue.hpp>

typedef int CUdevice;
Expand Down
1 change: 0 additions & 1 deletion sycl/include/sycl/detail/backend_traits_hip.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
#include <sycl/detail/backend_traits.hpp>
#include <sycl/device.hpp>
#include <sycl/event.hpp>
#include <sycl/kernel_bundle.hpp>
#include <sycl/queue.hpp>

typedef int HIPdevice;
Expand Down
6 changes: 3 additions & 3 deletions sycl/include/sycl/detail/backend_traits_level_zero.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,12 @@
#include <sycl/device.hpp> // for device
#include <sycl/event.hpp> // for event
#include <sycl/ext/oneapi/backend/level_zero_ownership.hpp> // for ownership
#include <sycl/handler.hpp> // for buffer
#include <sycl/image.hpp> // for image
#include <sycl/kernel.hpp> // for kernel
#include <sycl/kernel_bundle.hpp> // for kernel_b...
#include <sycl/kernel_bundle.hpp>
#include <sycl/kernel_bundle_enums.hpp> // for bundle_s...
#include <sycl/platform.hpp> // for platform
#include <sycl/property_list.hpp> // for property...
#include <sycl/queue.hpp> // for queue
#include <sycl/range.hpp> // for range

#include <variant> // for variant
Expand All @@ -46,6 +44,8 @@ typedef struct _ze_module_handle_t *ze_module_handle_t;

namespace sycl {
inline namespace _V1 {
class queue;

namespace detail {

// Forward declarations
Expand Down
8 changes: 5 additions & 3 deletions sycl/include/sycl/detail/backend_traits_opencl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,19 @@
#include <sycl/detail/ur.hpp> // for assertion and ur handles
#include <sycl/device.hpp> // for device
#include <sycl/event.hpp> // for event
#include <sycl/handler.hpp> // for buffer
#include <sycl/kernel.hpp> // for kernel
#include <sycl/kernel_bundle.hpp> // for kernel_bundle
#include <sycl/kernel_bundle_enums.hpp> // for bundle_state
#include <sycl/platform.hpp> // for platform
#include <sycl/queue.hpp> // for queue

#include <vector> // for vector

namespace sycl {
inline namespace _V1 {

template<bundle_state State>
class kernel_bundle;
class queue;

namespace detail {

// TODO the interops for context, device, event, platform and program
Expand Down
5 changes: 4 additions & 1 deletion sycl/include/sycl/ext/oneapi/backend/level_zero.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
#include <sycl/ext/oneapi/backend/level_zero_ownership.hpp> // for ownership
#include <sycl/image.hpp> // for image
#include <sycl/kernel.hpp> // for kernel
#include <sycl/kernel_bundle.hpp> // for kernel_bu...
#include <sycl/kernel_bundle_enums.hpp> // for bundle_state
#include <sycl/platform.hpp> // for platform
#include <sycl/properties/image_properties.hpp> // for image
Expand All @@ -40,6 +39,10 @@

namespace sycl {
inline namespace _V1 {

template <bundle_state State>
class kernel_bundle;
Copy link
Contributor

@aelovikov-intel aelovikov-intel Nov 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've been thinking about providing sycl/[detail/]fwd/<something.hpp> includes for quite some time, but always proceeded without it. Do you find such an idea attractive? My main concern was structure/granularity for such forward declarations.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I was working on #16030 and putting even more forward-declarations everywhere, I though that having a dedicated version of every header which only provides forward declarations would actually be cool.

Because some classes are templated, their forward-declaration may not be trivial and it may require more forward-declarations. Having a ready-to-use "canonical" forward-declaration in form of a separate header would shorten the codebase and make it simpler (i.e. that would just be a #include list without any extra lines of code).

There is a thing that some headers provide multiple classes and functions and therefore we could "import" more forward-declarations than we need, but I assume that it would be cheaper anyway that including the original header, so I don't think that it is a strong enough point against the idea.


namespace ext::oneapi::level_zero::detail {
__SYCL_EXPORT device make_device(const platform &Platform,
ur_native_handle_t NativeHandle);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#include <sycl/detail/backend_traits.hpp>
#include <sycl/device.hpp>
#include <sycl/event.hpp>
#include <sycl/kernel_bundle.hpp>
#include <sycl/queue.hpp>

#include <vector>
Expand Down
11 changes: 11 additions & 0 deletions sycl/include/sycl/ext/oneapi/get_kernel_info.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,21 @@
#include <sycl/detail/export.hpp>
#include <sycl/detail/info_desc_helpers.hpp>
#include <sycl/device.hpp>
#include <sycl/kernel_bundle_enums.hpp>
#include <sycl/queue.hpp>

#include <vector>

namespace sycl {
inline namespace _V1 {

template<bundle_state State>
class kernel_bundle;

template <typename KernelName, bundle_state State>
kernel_bundle<State> get_kernel_bundle(const context &,
const std::vector<device> &);

namespace ext::oneapi {

template <typename KernelName, typename Param>
Expand Down
7 changes: 6 additions & 1 deletion sycl/include/sycl/ext/oneapi/owner_less.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
#include <sycl/event.hpp> // for event
#include <sycl/ext/oneapi/weak_object.hpp> // for weak_object
#include <sycl/kernel.hpp> // for kernel
#include <sycl/kernel_bundle.hpp> // for kernel_id
#include <sycl/kernel_bundle_enums.hpp> // for bundle_state
#include <sycl/platform.hpp> // for platform
#include <sycl/properties/image_properties.hpp> // for sampled_i...
Expand All @@ -27,6 +26,12 @@ namespace sycl {
inline namespace _V1 {
namespace ext::oneapi {

class kernel_id;
template<bundle_state State>
class kernel_bundle;
template<bundle_state State>
class device_image;

namespace detail {
template <typename SyclObject> struct owner_less_base {
bool operator()(const SyclObject &lhs, const SyclObject &rhs) const noexcept {
Expand Down
36 changes: 10 additions & 26 deletions sycl/include/sycl/handler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
#include <sycl/id.hpp>
#include <sycl/item.hpp>
#include <sycl/kernel.hpp>
#include <sycl/kernel_bundle.hpp>
#include <sycl/kernel_bundle_enums.hpp>
#include <sycl/kernel_handler.hpp>
#include <sycl/nd_item.hpp>
Expand Down Expand Up @@ -152,6 +151,8 @@ inline namespace _V1 {

// Forward declaration

template<bundle_state State>
class kernel_bundle;
class handler;
template <typename T, int Dimensions, typename AllocatorT, typename Enable>
class buffer;
Expand All @@ -173,6 +174,7 @@ class graph_impl;
} // namespace ext::oneapi::experimental::detail
namespace detail {

class kernel_bundle_impl;
class work_group_memory_impl;
class handler_impl;
class kernel_impl;
Expand Down Expand Up @@ -1727,36 +1729,18 @@ class __SYCL_EXPORT handler {
handler &operator=(const handler &) = delete;
handler &operator=(handler &&) = delete;

// This is somewhat radical, but to make handler.hpp independtent from
// kernel_bundle.hpp, we define those methods within kernel_bundle.hpp
// header. Independence is needed in context of potential upcoming split of
// sycl.hpp so that users could do fine-grained include's, saving on
// compilation time by avoiding using headers for features they don't use.
template <auto &SpecName>
void set_specialization_constant(
typename std::remove_reference_t<decltype(SpecName)>::value_type Value) {

setStateSpecConstSet();

std::shared_ptr<detail::kernel_bundle_impl> KernelBundleImplPtr =
getOrInsertHandlerKernelBundle(/*Insert=*/true);

detail::createSyclObjFromImpl<kernel_bundle<bundle_state::input>>(
KernelBundleImplPtr)
.set_specialization_constant<SpecName>(Value);
}
typename std::remove_reference_t<decltype(SpecName)>::value_type Value);

template <auto &SpecName>
typename std::remove_reference_t<decltype(SpecName)>::value_type
get_specialization_constant() const {

if (isStateExplicitKernelBundle())
throw sycl::exception(make_error_code(errc::invalid),
"Specialization constants cannot be read after "
"explicitly setting the used kernel bundle");

std::shared_ptr<detail::kernel_bundle_impl> KernelBundleImplPtr =
getOrInsertHandlerKernelBundle(/*Insert=*/true);

return detail::createSyclObjFromImpl<kernel_bundle<bundle_state::input>>(
KernelBundleImplPtr)
.get_specialization_constant<SpecName>();
}
get_specialization_constant() const;

void
use_kernel_bundle(const kernel_bundle<bundle_state::executable> &ExecBundle);
Expand Down
36 changes: 34 additions & 2 deletions sycl/include/sycl/kernel_bundle.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@
#include <sycl/detail/kernel_desc.hpp> // for get_spec_constant_symboli...
#include <sycl/detail/owner_less_base.hpp> // for OwnerLessBase
#include <sycl/detail/string_view.hpp>
#include <sycl/detail/ur.hpp> // for cast
#include <sycl/device.hpp> // for device
#include <sycl/detail/ur.hpp> // for cast
#include <sycl/device.hpp> // for device
#include <sycl/handler.hpp>
#include <sycl/kernel.hpp> // for kernel, kernel_bundle
#include <sycl/kernel_bundle_enums.hpp> // for bundle_state
#include <sycl/property_list.hpp> // for property_list
Expand Down Expand Up @@ -1135,6 +1136,37 @@ build(kernel_bundle<bundle_state::ext_oneapi_source> &SourceKB,

} // namespace ext::oneapi::experimental

template <auto &SpecName>
void handler::set_specialization_constant(
typename std::remove_reference_t<decltype(SpecName)>::value_type Value) {

setStateSpecConstSet();

std::shared_ptr<detail::kernel_bundle_impl> KernelBundleImplPtr =
getOrInsertHandlerKernelBundle(/*Insert=*/true);

detail::createSyclObjFromImpl<kernel_bundle<bundle_state::input>>(
KernelBundleImplPtr)
.set_specialization_constant<SpecName>(Value);
}

template <auto &SpecName>
typename std::remove_reference_t<decltype(SpecName)>::value_type
handler::get_specialization_constant() const {

if (isStateExplicitKernelBundle())
throw sycl::exception(make_error_code(errc::invalid),
"Specialization constants cannot be read after "
"explicitly setting the used kernel bundle");

std::shared_ptr<detail::kernel_bundle_impl> KernelBundleImplPtr =
getOrInsertHandlerKernelBundle(/*Insert=*/true);

return detail::createSyclObjFromImpl<kernel_bundle<bundle_state::input>>(
KernelBundleImplPtr)
.get_specialization_constant<SpecName>();
}

} // namespace _V1
} // namespace sycl

Expand Down
2 changes: 1 addition & 1 deletion sycl/source/detail/allowlist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include <detail/device_impl.hpp>
#include <detail/device_info.hpp>
#include <detail/platform_info.hpp>
#include <sycl/backend.hpp>
#include <sycl/backend_types.hpp>

#include <algorithm>
#include <regex>
Expand Down
1 change: 1 addition & 0 deletions sycl/source/detail/kernel_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <sycl/device.hpp>
#include <sycl/ext/oneapi/experimental/root_group.hpp>
#include <sycl/info/info_desc.hpp>
#include <sycl/queue.hpp>

#include <cassert>
#include <memory>
Expand Down
2 changes: 1 addition & 1 deletion sycl/source/detail/platform_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include <detail/platform_impl.hpp>
#include <detail/platform_info.hpp>
#include <detail/ur_info_code.hpp>
#include <sycl/backend.hpp>
#include <sycl/backend_types.hpp>
#include <sycl/detail/iostream_proxy.hpp>
#include <sycl/detail/ur.hpp>
#include <sycl/detail/util.hpp>
Expand Down
4 changes: 2 additions & 2 deletions sycl/source/detail/platform_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

#include <detail/adapter.hpp>
#include <detail/platform_info.hpp>
#include <detail/ur.hpp>
#include <detail/ur_info_code.hpp>
#include <sycl/backend.hpp>
#include <sycl/backend_types.hpp>
#include <sycl/detail/cl.h>
#include <sycl/detail/common.hpp>
Expand Down Expand Up @@ -46,7 +46,7 @@ class platform_impl {
AAdapter->call_nocheck<UrApiKind::urPlatformGetInfo>(
APlatform, UR_PLATFORM_INFO_BACKEND, sizeof(ur_platform_backend_t),
&UrBackend, nullptr);
MBackend = convertUrBackend(UrBackend);
MBackend = detail::convertUrBackend(UrBackend);
}

~platform_impl() = default;
Expand Down
1 change: 1 addition & 0 deletions sycl/source/detail/sampler_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <detail/context_impl.hpp>
#include <detail/sampler_impl.hpp>
#include <sycl/property_list.hpp>
#include <sycl/sampler.hpp>

namespace sycl {
inline namespace _V1 {
Expand Down
4 changes: 4 additions & 0 deletions sycl/source/detail/ur.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ initializeUr(ur_loader_config_handle_t LoaderConfig = nullptr);
// Get the adapter serving given backend.
template <backend BE> const AdapterPtr &getAdapter();
} // namespace ur

// Convert from UR backend to SYCL backend enum
backend convertUrBackend(ur_platform_backend_t UrBackend);

} // namespace detail
} // namespace _V1
} // namespace sycl
1 change: 1 addition & 0 deletions sycl/test-e2e/WeakObject/weak_object_owner_less.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include "weak_object_utils.hpp"

#include <sycl/kernel_bundle.hpp>
#include <sycl/ext/oneapi/owner_less.hpp>

#include <map>
Expand Down
2 changes: 0 additions & 2 deletions sycl/test/include_deps/sycl_detail_core.hpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,6 @@
// CHECK-NEXT: ext/oneapi/experimental/virtual_functions.hpp
// CHECK-NEXT: ext/oneapi/kernel_properties/properties.hpp
// CHECK-NEXT: kernel.hpp
// CHECK-NEXT: kernel_bundle.hpp
// CHECK-NEXT: ext/oneapi/experimental/free_function_traits.hpp
Comment on lines -135 to -136
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any removals here are good and desirable, I think :)

Also, feel free to add any new tests here (e.g. for kernel_bundle.hpp itself) if you'd find that beneficial to highlight the improvements (either this PR or any other of the same spirit).

// CHECK-NEXT: sampler.hpp
// CHECK-NEXT: feature_test.hpp
// CHECK-EMPTY:
Loading
Loading