59 q.
submit(depends_list, [&, idx](sycl::handler &cgh) {
60 cgh.copy(acc + idx, dest, 1);
71 sycl::queue &q, sycl::buffer<T> &buf,
u32 idx, T val,
bool discard_write =
false) {
74 q.submit([&, idx, val](sycl::handler &cgh) {
75 sycl::accessor acc{buf, cgh, sycl::write_only, sycl::no_init};
76 cgh.single_task([=]() {
81 q.submit([&, idx, val](sycl::handler &cgh) {
82 sycl::accessor acc{buf, cgh, sycl::write_only};
83 cgh.single_task([=]() {
98 sycl::buffer<T>
vec_to_buf(
const std::vector<T> &buf);
120 sycl::buffer<T> tmp(1);
121 q.submit([&](sycl::handler &cgh) {
122 sycl::accessor a{buf, cgh, sycl::read_write};
123 sycl::accessor b{tmp, cgh, sycl::write_only, sycl::no_init};
125 cgh.single_task([=]() {
140 inline void buf_fill(sycl::queue &q, sycl::buffer<T> &buf, T value) {
142 q.submit([&, value](sycl::handler &cgh) {
143 sycl::accessor acc{buf, cgh, sycl::write_only};
144 shambase::parallel_for(cgh, buf.size(),
"buf_fill", [=](
u64 id_a) {
161 q.submit([&, value](sycl::handler &cgh) {
162 sycl::accessor acc{buf, cgh, sycl::write_only, sycl::no_init};
164 shambase::parallel_for(cgh, buf.size(),
"buff_fill_discard", [=](
u64 id_a) {
181 inline void print_buf(sycl::buffer<T> &buf,
u32 len,
u32 column_count, std::string_view fmt) {
183 sycl::host_accessor acc{buf, sycl::read_only};
187 for (
u32 i = 0; i < len; i++) {
189 if (i % column_count == 0) {
191 accum += shambase::format(
"{:8} : ", i);
193 accum += shambase::format(
"\n{:8} : ", i);
200 logger::raw_ln(accum);
204 void copybuf_discard(sycl::queue &q, sycl::buffer<T> &source, sycl::buffer<T> &dest,
u32 cnt) {
205 q.submit([&](sycl::handler &cgh) {
206 sycl::accessor src{source, cgh, sycl::read_only};
207 sycl::accessor dst{dest, cgh, sycl::write_only, sycl::no_init};
209 shambase::parallel_for(cgh, cnt,
"copybuf_discard", [=](
u64 i) {
216 void copybuf(sycl::queue &q, sycl::buffer<T> &source, sycl::buffer<T> &dest,
u32 cnt) {
217 q.submit([&](sycl::handler &cgh) {
218 sycl::accessor src{source, cgh, sycl::read_only};
219 sycl::accessor dst{dest, cgh, sycl::write_only};
221 shambase::parallel_for(cgh, cnt,
"copybuf", [=](
u64 i) {
228 void add_with_factor_to(
229 sycl::queue &q, sycl::buffer<T> &buf, T factor, sycl::buffer<T> &op,
u32 cnt) {
230 q.submit([&](sycl::handler &cgh) {
231 sycl::accessor acc{buf, cgh, sycl::read_write};
232 sycl::accessor dd{op, cgh, sycl::read_only};
236 shambase::parallel_for(cgh, cnt,
"add_with_factor_to", [=](
u64 i) {
237 acc[i] += fac * dd[i];
243 void write_with_offset_into(
245 sycl::buffer<T> &buf_ctn,
246 sycl::buffer<T> &buf_in,
249 q.submit([&](sycl::handler &cgh) {
250 sycl::accessor source{buf_in, cgh, sycl::read_only};
251 sycl::accessor dest{buf_ctn, cgh, sycl::write_only, sycl::no_init};
253 cgh.parallel_for(sycl::range{element_count}, [=](sycl::item<1> item) {
254 dest[item.get_id(0) + off] = source[item];
271 void write_with_offset_into(
282 auto e = q.
submit(depends_list, [&](sycl::handler &cgh) {
284 cgh.parallel_for(sycl::range{element_count}, [=](sycl::item<1> item) {
285 dest[item.get_id(0) + off] = source[item];
304 void write_with_offset_into(
306 sycl::buffer<T> &buf_ctn,
314 auto e = q.
submit(depends_list, [&](sycl::handler &cgh) {
315 sycl::accessor dest{buf_ctn, cgh, sycl::write_only, sycl::no_init};
317 cgh.parallel_for(sycl::range{element_count}, [=](sycl::item<1> item) {
318 dest[item.get_id(0) + off] = source[item];
326 void write_with_offset_into(
327 sycl::queue &q, sycl::buffer<T> &buf_ctn, T val,
u32 offset,
u32 element_count) {
328 q.submit([&, val](sycl::handler &cgh) {
329 sycl::accessor dest{buf_ctn, cgh, sycl::write_only, sycl::no_init};
331 cgh.parallel_for(sycl::range{element_count}, [=](sycl::item<1> item) {
332 dest[item.get_id(0) + off] = val;
338 std::unique_ptr<sycl::buffer<T>> duplicate(
339 sycl::queue &q,
const std::unique_ptr<sycl::buffer<T>> &buf_in) {
341 auto buf = std::make_unique<sycl::buffer<T>>(buf_in->size());
342 copybuf_discard(q, *buf_in, *buf, buf_in->size());
343 return std::move(buf);
349 sycl::buffer<T> vector_to_buf(sycl::queue &q, std::vector<T> &&vec) {
351 u32 cnt = vec.size();
352 sycl::buffer<T> ret(cnt);
354 sycl::buffer<T> alias(vec.data(), cnt);
356 shamalgs::memory::copybuf_discard(q, alias, ret, cnt);
364 return std::move(ret);
376 sycl::buffer<T> vector_to_buf(sycl::queue &q, std::vector<T> &vec) {
378 u32 cnt = vec.size();
379 sycl::buffer<T> ret(cnt);
381 sycl::buffer<T> alias(vec.data(), cnt);
383 shamalgs::memory::copybuf_discard(q, alias, ret, cnt);
391 return std::move(ret);
std::uint32_t u32
32 bit unsigned integer
std::uint64_t u64
64 bit unsigned integer
A buffer allocated in USM (Unified Shared Memory)
void complete_event_state(sycl::event e) const
Complete the event state of the buffer.
T * get_write_access(sham::EventList &depends_list, SourceLocation src_loc=SourceLocation{})
Get a read-write pointer to the buffer's data.
const T * get_read_access(sham::EventList &depends_list, SourceLocation src_loc=SourceLocation{}) const
Get a read-only pointer to the buffer's data.
A SYCL queue associated with a device and a context.
sycl::event submit(Fct &&fct)
Submits a kernel to the SYCL queue.
Class to manage a list of SYCL events.
memory manipulation algorithms
void buf_fill_discard(sycl::queue &q, sycl::buffer< T > &buf, T value)
Fill a buffer with a given value (sycl::no_init mode)
void buf_fill(sycl::queue &q, sycl::buffer< T > &buf, T value)
Fill a buffer with a given value.
T extract_element(sycl::queue &q, sycl::buffer< T > &buf, u32 idx)
extract a value of a buffer
void print_buf(sycl::buffer< T > &buf, u32 len, u32 column_count, std::string_view fmt)
Print the content of a sycl::buffer
sycl::buffer< T > vec_to_buf(const std::vector< T > &buf)
Convert a std::vector to a sycl::buffer
void move_buffer_on_queue(sycl::queue &q, sycl::buffer< T > &buf)
enqueue a do nothing kernel to force the buffer to move
std::vector< T > buf_to_vec(sycl::buffer< T > &buf, u32 len)
Convert a sycl::buffer to a std::vector
void throw_with_loc(std::string message, SourceLocation loc=SourceLocation{})
Throw an exception and append the source location to it.