diff --git a/sycl/include/sycl/backend.hpp b/sycl/include/sycl/backend.hpp index 6010804c0ec00..a79825eb10e86 100644 --- a/sycl/include/sycl/backend.hpp +++ b/sycl/include/sycl/backend.hpp @@ -25,7 +25,6 @@ #include // for SYCL_BACKEND_OP... #include // for image, image_al... #include // for kernel, get_native -#include #include // for bundle_state #include // for platform, get_n... #include // for property_list @@ -46,7 +45,7 @@ #include #endif #if SYCL_EXT_ONEAPI_BACKEND_LEVEL_ZERO -#include // for _ze_command_lis... +// #include // for _ze_command_lis... #endif #include @@ -59,6 +58,9 @@ namespace sycl { inline namespace _V1 { +template +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 @@ -150,6 +152,7 @@ auto get_native(const queue &Obj) -> backend_return_t { int32_t IsImmCmdList; ur_native_handle_t Handle = Obj.getNative(IsImmCmdList); backend_return_t RetVal; +#if 0 && SYCL_EXT_ONEAPI_BACKEND_LEVEL_ZERO if constexpr (BackendName == backend::ext_oneapi_level_zero) RetVal = IsImmCmdList ? backend_return_t{reinterpret_cast< @@ -157,6 +160,7 @@ auto get_native(const queue &Obj) -> backend_return_t { : backend_return_t{ reinterpret_cast(Handle)}; else +#endif RetVal = reinterpret_cast>(Handle); return RetVal; diff --git a/sycl/include/sycl/ext/oneapi/get_kernel_info.hpp b/sycl/include/sycl/ext/oneapi/get_kernel_info.hpp index bd435426dfcd1..77892020f25eb 100644 --- a/sycl/include/sycl/ext/oneapi/get_kernel_info.hpp +++ b/sycl/include/sycl/ext/oneapi/get_kernel_info.hpp @@ -11,10 +11,21 @@ #include #include #include +#include #include +#include + namespace sycl { inline namespace _V1 { + +template +class kernel_bundle; + +template +kernel_bundle get_kernel_bundle(const context &, + const std::vector &); + namespace ext::oneapi { template diff --git a/sycl/include/sycl/ext/oneapi/owner_less.hpp b/sycl/include/sycl/ext/oneapi/owner_less.hpp index 8ece12202f973..53b704426be4f 100644 --- a/sycl/include/sycl/ext/oneapi/owner_less.hpp +++ b/sycl/include/sycl/ext/oneapi/owner_less.hpp @@ -29,6 +29,8 @@ namespace ext::oneapi { class kernel_id; template class kernel_bundle; +template +class device_image; namespace detail { template struct owner_less_base { diff --git a/sycl/include/sycl/handler.hpp b/sycl/include/sycl/handler.hpp index 164621d310635..0d7d9c5babe36 100644 --- a/sycl/include/sycl/handler.hpp +++ b/sycl/include/sycl/handler.hpp @@ -43,7 +43,6 @@ #include #include #include -#include #include #include #include @@ -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 void set_specialization_constant( - typename std::remove_reference_t::value_type Value) { - - setStateSpecConstSet(); - - std::shared_ptr KernelBundleImplPtr = - getOrInsertHandlerKernelBundle(/*Insert=*/true); - - detail::createSyclObjFromImpl>( - KernelBundleImplPtr) - .set_specialization_constant(Value); - } + typename std::remove_reference_t::value_type Value); template typename std::remove_reference_t::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 KernelBundleImplPtr = - getOrInsertHandlerKernelBundle(/*Insert=*/true); - - return detail::createSyclObjFromImpl>( - KernelBundleImplPtr) - .get_specialization_constant(); - } + get_specialization_constant() const; void use_kernel_bundle(const kernel_bundle &ExecBundle); diff --git a/sycl/include/sycl/kernel_bundle.hpp b/sycl/include/sycl/kernel_bundle.hpp index 1237bc0651b40..d279b2924c8e7 100644 --- a/sycl/include/sycl/kernel_bundle.hpp +++ b/sycl/include/sycl/kernel_bundle.hpp @@ -14,8 +14,9 @@ #include // for get_spec_constant_symboli... #include // for OwnerLessBase #include -#include // for cast -#include // for device +#include // for cast +#include // for device +#include #include // for kernel, kernel_bundle #include // for bundle_state #include // for property_list @@ -1135,6 +1136,37 @@ build(kernel_bundle &SourceKB, } // namespace ext::oneapi::experimental +template +void handler::set_specialization_constant( + typename std::remove_reference_t::value_type Value) { + + setStateSpecConstSet(); + + std::shared_ptr KernelBundleImplPtr = + getOrInsertHandlerKernelBundle(/*Insert=*/true); + + detail::createSyclObjFromImpl>( + KernelBundleImplPtr) + .set_specialization_constant(Value); +} + +template +typename std::remove_reference_t::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 KernelBundleImplPtr = + getOrInsertHandlerKernelBundle(/*Insert=*/true); + + return detail::createSyclObjFromImpl>( + KernelBundleImplPtr) + .get_specialization_constant(); +} + } // namespace _V1 } // namespace sycl diff --git a/sycl/source/detail/handler_proxy.cpp b/sycl/source/detail/handler_proxy.cpp index 1be993d734062..05ea058cc5d3b 100644 --- a/sycl/source/detail/handler_proxy.cpp +++ b/sycl/source/detail/handler_proxy.cpp @@ -8,8 +8,6 @@ #include -// FIXME: that's a hack -#include #include namespace sycl { diff --git a/sycl/test/include_deps/sycl_detail_core.hpp.cpp b/sycl/test/include_deps/sycl_detail_core.hpp.cpp index e9555d3ad95d1..3c813fafe2f61 100644 --- a/sycl/test/include_deps/sycl_detail_core.hpp.cpp +++ b/sycl/test/include_deps/sycl_detail_core.hpp.cpp @@ -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: diff --git a/sycl/test/self-contained-handler-hpp.cpp b/sycl/test/self-contained-handler-hpp.cpp new file mode 100644 index 0000000000000..e71a02104b019 --- /dev/null +++ b/sycl/test/self-contained-handler-hpp.cpp @@ -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 + +void foo(sycl::handler &h) {}