88
99#pragma once
1010
11- #include < cstddef>
1211#include < sycl/accessor.hpp> // for detail::AccessorBaseHost
1312#include < sycl/context.hpp> // for context
1413#include < sycl/detail/export.hpp> // for __SYCL_EXPORT
2120#include < sycl/device.hpp> // for device
2221#include < sycl/ext/oneapi/experimental/detail/properties/graph_properties.hpp> // for graph properties classes
2322#include < sycl/ext/oneapi/experimental/work_group_memory.hpp> // for dynamic_work_group_memory
24- #include < sycl/nd_range.hpp> // for range, nd_range
23+ #include < sycl/ext/oneapi/properties/properties.hpp> // for empty_properties_t
24+ #include < sycl/nd_range.hpp> // for range, nd_range
2525#include < sycl/properties/property_traits.hpp> // for is_property, is_property_of
2626#include < sycl/property_list.hpp> // for property_list
2727
@@ -49,6 +49,7 @@ enum class graph_state {
4949// Forward declare ext::oneapi::experimental classes
5050template <graph_state State> class command_graph ;
5151class raw_kernel_arg ;
52+ template <typename , typename > class work_group_memory ;
5253
5354namespace detail {
5455// List of sycl features and extensions which are not supported by graphs. Used
@@ -503,6 +504,7 @@ class command_graph<graph_state::executable>
503504namespace detail {
504505class __SYCL_EXPORT dynamic_parameter_base {
505506public:
507+ dynamic_parameter_base () = default ;
506508 dynamic_parameter_base (
507509 sycl::ext::oneapi::experimental::command_graph<graph_state::modifiable>
508510 Graph);
@@ -548,12 +550,13 @@ class dynamic_work_group_memory_base
548550public:
549551 dynamic_work_group_memory_base () = default ;
550552 dynamic_work_group_memory_base (
551- experimental::command_graph<graph_state::modifiable> Graph, size_t Size)
552- :
553+ [[maybe_unused]] experimental::command_graph<graph_state::modifiable>
554+ Graph,
555+ [[maybe_unused]] size_t Size)
553556#ifndef __SYCL_DEVICE_ONLY__
554- dynamic_parameter_base (Graph),
557+ : dynamic_parameter_base(Graph), BufferSize(Size)
555558#endif
556- BufferSize (Size) {
559+ {
557560 }
558561
559562private:
@@ -565,23 +568,23 @@ class dynamic_work_group_memory_base
565568};
566569} // namespace detail
567570
568- template <typename DataT,
569- typename = std::enable_if_t <detail::is_unbounded_array_v<DataT>>>
571+ template <typename DataT, typename PropertyListT = empty_properties_t >
570572class __SYCL_SPECIAL_CLASS
571573__SYCL_TYPE (dynamic_work_group_memory) dynamic_work_group_memory
572574 : public detail::dynamic_work_group_memory_base {
573- private:
574- work_group_memory<DataT> WorkGroupMem;
575-
576- #ifdef __SYCL_DEVICE_ONLY__
577- using value_type = std::remove_all_extents_t <DataT>;
578- using decoratedPtr = typename sycl::detail::DecoratedType<
579- value_type, access::address_space::local_space>::type *;
575+ public:
576+ // Check that DataT is an unbounded array type.
577+ static_assert (std::is_array_v<DataT> && std::extent_v<DataT, 0 > == 0 );
578+ static_assert (std::is_same_v<PropertyListT, empty_properties_t >);
580579
581- void __init (decoratedPtr Ptr) { this ->WorkGroupMem .__init (Ptr); }
582- #endif
580+ // Frontend requires special types to have a default constructor in order to
581+ // have a uniform way of initializing an object of special type to then call
582+ // the __init method on it. This is purely an implementation detail and not
583+ // part of the spec.
584+ // TODO: Revisit this once https://github.com/intel/llvm/issues/16061 is
585+ // closed.
586+ dynamic_work_group_memory () = default ;
583587
584- public:
585588 // / Constructs a new dynamic_work_group_memory object.
586589 // / @param Graph The graph associated with this object.
587590 // / @param Num Number of elements in the unbounded array DataT.
@@ -590,24 +593,35 @@ __SYCL_TYPE(dynamic_work_group_memory) dynamic_work_group_memory
590593 : detail::dynamic_work_group_memory_base (
591594 Graph, Num * sizeof (std::remove_extent_t <DataT>)) {}
592595
596+ work_group_memory<DataT, PropertyListT> get () const {
597+ #ifndef __SYCL_DEVICE_ONLY__
598+ throw sycl::exception (sycl::make_error_code (errc::invalid),
599+ " Error: dynamic_work_group_memory::get() can be only "
600+ " called on the device!" );
601+ #endif
602+ return WorkGroupMem;
603+ }
604+
593605 // / Updates on the host this dynamic_work_group_memory and all registered
594606 // / nodes with a new buffer size.
595607 // / @param Num The new number of elements in the unbounded array.
596- void update (size_t Num) {
608+ void update ([[maybe_unused]] size_t Num) {
597609#ifndef __SYCL_DEVICE_ONLY__
598610 detail::dynamic_parameter_base::updateWorkGroupMem (
599611 Num * sizeof (std::remove_extent_t <DataT>));
600612#endif
601613 }
602- work_group_memory<DataT> get () const { return WorkGroupMem; }
603614
604- // Frontend requires special types to have a default constructor in order to
605- // have a uniform way of initializing an object of special type to then call
606- // the __init method on it. This is purely an implementation detail and not
607- // part of the spec.
608- // TODO: Revisit this once https://github.com/intel/llvm/issues/16061 is
609- // closed.
610- dynamic_work_group_memory () = default ;
615+ private:
616+ work_group_memory<DataT, PropertyListT> WorkGroupMem;
617+
618+ #ifdef __SYCL_DEVICE_ONLY__
619+ using value_type = std::remove_all_extents_t <DataT>;
620+ using decoratedPtr = typename sycl::detail::DecoratedType<
621+ value_type, access::address_space::local_space>::type *;
622+
623+ void __init (decoratedPtr Ptr) { this ->WorkGroupMem .__init (Ptr); }
624+ #endif
611625};
612626
613627template <typename ValueT>
@@ -684,4 +698,14 @@ struct hash<sycl::ext::oneapi::experimental::dynamic_parameter<ValueT>> {
684698 return std::hash<decltype (ID)>()(ID);
685699 }
686700};
701+
702+ template <typename DataT>
703+ struct hash <sycl::ext::oneapi::experimental::dynamic_work_group_memory<DataT>> {
704+ size_t operator ()(
705+ const sycl::ext::oneapi::experimental::dynamic_work_group_memory<DataT>
706+ &DynWorkGroupMem) const {
707+ auto ID = sycl::detail::getSyclObjImpl (DynWorkGroupMem)->getID ();
708+ return std::hash<decltype (ID)>()(ID);
709+ }
710+ };
687711} // namespace std
0 commit comments