1- // ==-------------------- kernel_name_based_cache_t .hpp ---------------------==//
1+ // ==---------------------- device_kernel_info .hpp - ---------------------==//
22//
33// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44// See https://llvm.org/LICENSE.txt for license information.
1010#include < detail/hashers.hpp>
1111#include < detail/kernel_arg_mask.hpp>
1212#include < emhash/hash_table8.hpp>
13+ #include < sycl/detail/compile_time_kernel_info.hpp>
14+ #include < sycl/detail/kernel_name_str_t.hpp>
1315#include < sycl/detail/spinlock.hpp>
1416#include < sycl/detail/ur.hpp>
1517
@@ -23,9 +25,9 @@ using FastKernelCacheKeyT = std::pair<ur_device_handle_t, ur_context_handle_t>;
2325
2426struct FastKernelCacheVal {
2527 Managed<ur_kernel_handle_t > MKernelHandle; /* UR kernel. */
26- std::mutex *MMutex; /* Mutex guarding this kernel. When
27- caching is disabled, the pointer is
28- nullptr. */
28+ std::mutex *MMutex; /* Mutex guarding this kernel. When
29+ caching is disabled, the pointer is
30+ nullptr. */
2931 const KernelArgMask *MKernelArgMask; /* Eliminated kernel argument mask. */
3032 Managed<ur_program_handle_t > MProgramHandle; /* UR program handle
3133 corresponding to this kernel. */
@@ -71,18 +73,53 @@ struct FastKernelEntryT {
7173
7274using FastKernelSubcacheEntriesT = std::vector<FastKernelEntryT>;
7375
76+ // Structure for caching built kernels with a specific name.
77+ // Used by instances of the kernel program cache class (potentially multiple).
7478struct FastKernelSubcacheT {
7579 FastKernelSubcacheEntriesT Entries;
7680 FastKernelSubcacheMutexT Mutex;
7781};
7882
79- struct KernelNameBasedCacheT {
80- FastKernelSubcacheT FastKernelSubcache;
81- std::optional<bool > UsesAssert;
82- // Implicit local argument position is represented by an optional int, this
83- // uses another optional on top of that to represent lazy initialization of
84- // the cached value.
85- std::optional<std::optional<int >> ImplicitLocalArgPos;
83+ // This class aggregates information specific to device kernels (i.e.
84+ // information that is uniform between different submissions of the same
85+ // kernel). Pointers to instances of this class are stored in header function
86+ // templates as a static variable to avoid repeated runtime lookup overhead.
87+ // TODO Currently this class duplicates information fetched from the program
88+ // manager. Instead, we should merge all of this information
89+ // into this structure and get rid of the other KernelName -> * maps.
90+ class DeviceKernelInfo : public CompileTimeKernelInfoTy {
91+ public:
92+ #ifndef __INTEL_PREVIEW_BREAKING_CHANGES
93+ // Needs to own the kernel name string in non-preview builds since we pass it
94+ // using a temporary string instead of a string view there.
95+ std::string Name;
96+ #endif
97+
98+ #ifndef __INTEL_PREVIEW_BREAKING_CHANGES
99+ DeviceKernelInfo () = default;
100+ #endif
101+ DeviceKernelInfo (const CompileTimeKernelInfoTy &Info);
102+
103+ void init (KernelNameStrRefT KernelName);
104+ #ifndef __INTEL_PREVIEW_BREAKING_CHANGES
105+ void initIfNeeded (KernelNameStrRefT KernelName);
106+ #endif
107+ void setCompileTimeInfoIfNeeded (const CompileTimeKernelInfoTy &Info);
108+
109+ FastKernelSubcacheT &getKernelSubcache ();
110+ bool usesAssert ();
111+ const std::optional<int > &getImplicitLocalArgPos ();
112+
113+ private:
114+ void assertInitialized ();
115+ bool isCompileTimeInfoSet () const ;
116+
117+ #ifndef __INTEL_PREVIEW_BREAKING_CHANGES
118+ std::atomic<bool > MInitialized = false ;
119+ #endif
120+ FastKernelSubcacheT MFastKernelSubcache;
121+ bool MUsesAssert;
122+ std::optional<int > MImplicitLocalArgPos;
86123};
87124
88125} // namespace detail
0 commit comments