Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexeySachkov committed Nov 7, 2024
1 parent 0ce7118 commit 8aafb3b
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 34 deletions.
8 changes: 6 additions & 2 deletions sycl/include/sycl/backend.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
#include <sycl/feature_test.hpp> // for SYCL_BACKEND_OP...
#include <sycl/image.hpp> // for image, image_al...
#include <sycl/kernel.hpp> // for kernel, get_native
#include <sycl/kernel_bundle.hpp>
#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
Expand All @@ -46,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 @@ -59,6 +58,9 @@
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
Expand Down Expand Up @@ -150,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
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
2 changes: 2 additions & 0 deletions sycl/include/sycl/ext/oneapi/owner_less.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ 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 {
Expand Down
33 changes: 7 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 @@ -1730,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: 0 additions & 2 deletions sycl/source/detail/handler_proxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@

#include <sycl/detail/handler_proxy.hpp>

// FIXME: that's a hack
#include <sycl/kernel_bundle.hpp>
#include <sycl/handler.hpp>

namespace sycl {
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
// CHECK-NEXT: sampler.hpp
// CHECK-NEXT: feature_test.hpp
// CHECK-EMPTY:
17 changes: 17 additions & 0 deletions sycl/test/self-contained-handler-hpp.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// RUN: %clangxx -fsycl -fsyntax-only -Xclang -verify %s
// expected-no-diagnostics
//
// The purpose of this test is to ensure that the header containing
// sycl::handler class definition is self-contained, i.e. we can use handler
// and no extra headers are needed.
//
// TODO: the test should be expanded to use various methods of the class. Due
// to their template nature we may not test all code paths until we trigger
// instantiation of a corresponding method.
// TODO: methods related to specialization constants were moved into
// kernel_bundle.hpp and therefore handler.hpp is known *not* to be
// self-contained.

#include <sycl/handler.hpp>

void foo(sycl::handler &h) {}

0 comments on commit 8aafb3b

Please sign in to comment.