Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
DeviceQueue.hpp
Go to the documentation of this file.
1// -------------------------------------------------------//
2//
3// SHAMROCK code for hydrodynamics
4// Copyright (c) 2021-2026 Timothée David--Cléris <tim.shamrock@proton.me>
5// SPDX-License-Identifier: CeCILL Free Software License Agreement v2.1
6// Shamrock is licensed under the CeCILL 2.1 License, see LICENSE for more information
7//
8// -------------------------------------------------------//
9
10#pragma once
11
18#include "shambase/memory.hpp"
22
23namespace sham {
24
33 public:
37 std::shared_ptr<DeviceContext> ctx;
38
42 sycl::queue q;
43
50 std::string queue_name;
51
60
70 bool wait_after_submit = false;
71
82 DeviceQueue(std::string queue_name, std::shared_ptr<DeviceContext> ctx, bool in_order);
83
100 template<class Fct>
101 sycl::event submit(Fct &&fct) {
102
103 auto e = q.submit([&](sycl::handler &h) {
104 fct(h);
105 });
106
107 if (wait_after_submit) {
108 e.wait_and_throw();
109 }
110
111 return e;
112 }
113
138 template<class Fct>
139 sycl::event submit(EventList &elist, Fct &&fct) {
140
141 elist.consumed = true;
142
143 auto e = q.submit([&](sycl::handler &h) {
144 elist.apply_dependency(h);
145 fct(h);
146 });
147
148 if (wait_after_submit) {
149 e.wait_and_throw();
150 }
151
152 return e;
153 }
154
166 return shambase::get_check_ref(ctx).device->prop;
167 }
168 };
169
170} // namespace sham
A SYCL queue associated with a device and a context.
std::string queue_name
The name of this queue.
DeviceProperties & get_device_prop()
Retrieves the properties of the associated device.
sycl::event submit(EventList &elist, Fct &&fct)
Submits a kernel to the SYCL queue, adding the events in the provided EventList as dependencies.
bool wait_after_submit
Whether to wait for the kernel to finish after submitting it.
std::shared_ptr< DeviceContext > ctx
The device context of this queue.
sycl::queue q
The SYCL queue associated with this context.
bool in_order
Whether the queue is in order.
sycl::event submit(Fct &&fct)
Submits a kernel to the SYCL queue.
Class to manage a list of SYCL events.
Definition EventList.hpp:31
void apply_dependency(sycl::handler &h)
Apply all events in the list as dependancies to a SYCL command group.
Definition EventList.hpp:49
namespace for backends this one is named only sham since shambackends is too long to write
T & get_check_ref(const std::unique_ptr< T > &ptr, SourceLocation loc=SourceLocation())
Takes a std::unique_ptr and returns a reference to the object it holds. It throws a std::runtime_erro...
Definition memory.hpp:110
Properties of a device.
Definition Device.hpp:84