88
99#pragma once
1010
11+ #include < cstddef>
1112#include < sycl/accessor.hpp> // for detail::AccessorBaseHost
1213#include < sycl/context.hpp> // for context
1314#include < sycl/detail/export.hpp> // for __SYCL_EXPORT
1718#ifdef __INTEL_PREVIEW_BREAKING_CHANGES
1819#include < sycl/detail/string_view.hpp>
1920#endif
20- #include < sycl/device.hpp> // for device
21+ #include < sycl/device.hpp> // for device
2122#include < sycl/ext/oneapi/experimental/detail/properties/graph_properties.hpp> // for graph properties classes
23+ #include < sycl/ext/oneapi/experimental/work_group_memory.hpp> // for dynamic_work_group_memory
2224#include < sycl/nd_range.hpp> // for range, nd_range
2325#include < sycl/properties/property_traits.hpp> // for is_property, is_property_of
2426#include < sycl/property_list.hpp> // for property_list
@@ -501,6 +503,9 @@ class command_graph<graph_state::executable>
501503namespace detail {
502504class __SYCL_EXPORT dynamic_parameter_base {
503505public:
506+ dynamic_parameter_base (
507+ sycl::ext::oneapi::experimental::command_graph<graph_state::modifiable>
508+ Graph);
504509 dynamic_parameter_base (
505510 sycl::ext::oneapi::experimental::command_graph<graph_state::modifiable>
506511 Graph,
@@ -525,14 +530,86 @@ class __SYCL_EXPORT dynamic_parameter_base {
525530 void updateValue (const raw_kernel_arg *NewRawValue, size_t Size);
526531
527532 void updateAccessor (const sycl::detail::AccessorBaseHost *Acc);
533+
534+ void updateWorkGroupMem (size_t BufferSize);
535+
528536 std::shared_ptr<dynamic_parameter_impl> impl;
529537
530538 template <class Obj >
531539 friend const decltype (Obj::impl) &
532540 sycl::detail::getSyclObjImpl(const Obj &SyclObject);
533541};
542+
543+ class dynamic_work_group_memory_base
544+ #ifndef __SYCL_DEVICE_ONLY__
545+ : public dynamic_parameter_base
546+ #endif
547+ {
548+ public:
549+ dynamic_work_group_memory_base () = default ;
550+ dynamic_work_group_memory_base (
551+ experimental::command_graph<graph_state::modifiable> Graph, size_t Size)
552+ :
553+ #ifndef __SYCL_DEVICE_ONLY__
554+ dynamic_parameter_base (Graph),
555+ #endif
556+ BufferSize (Size) {
557+ }
558+
559+ private:
560+ #ifdef __SYCL_DEVICE_ONLY__
561+ [[maybe_unused]] unsigned char Padding[sizeof (dynamic_parameter_base)];
562+ #endif
563+ size_t BufferSize{};
564+ friend class sycl ::handler;
565+ };
534566} // namespace detail
535567
568+ template <typename DataT,
569+ typename = std::enable_if_t <detail::is_unbounded_array_v<DataT>>>
570+ class __SYCL_SPECIAL_CLASS
571+ __SYCL_TYPE (dynamic_work_group_memory) dynamic_work_group_memory
572+ : 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 *;
580+
581+ void __init (decoratedPtr Ptr) { this ->WorkGroupMem .__init (Ptr); }
582+ #endif
583+
584+ public:
585+ // / Constructs a new dynamic_work_group_memory object.
586+ // / @param Graph The graph associated with this object.
587+ // / @param Num Number of elements in the unbounded array DataT.
588+ dynamic_work_group_memory (
589+ experimental::command_graph<graph_state::modifiable> Graph, size_t Num)
590+ : detail::dynamic_work_group_memory_base (
591+ Graph, Num * sizeof (std::remove_extent_t <DataT>)) {}
592+
593+ // / Updates on the host this dynamic_work_group_memory and all registered
594+ // / nodes with a new buffer size.
595+ // / @param Num The new number of elements in the unbounded array.
596+ void update (size_t Num) {
597+ #ifndef __SYCL_DEVICE_ONLY__
598+ detail::dynamic_parameter_base::updateWorkGroupMem (
599+ Num * sizeof (std::remove_extent_t <DataT>));
600+ #endif
601+ }
602+ work_group_memory<DataT> get () const { return WorkGroupMem; }
603+
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 ;
611+ };
612+
536613template <typename ValueT>
537614class dynamic_parameter : public detail ::dynamic_parameter_base {
538615 static constexpr bool IsAccessor =
0 commit comments