49 sycl::buffer<T>
vec_to_buf(
const std::vector<T> &buf);
71 sycl::buffer<T> tmp(1);
72 q.submit([&](sycl::handler &cgh) {
73 sycl::accessor a{buf, cgh, sycl::read_write};
74 sycl::accessor b{tmp, cgh, sycl::write_only, sycl::no_init};
76 cgh.single_task([=]() {
93 q.submit([&, value](sycl::handler &cgh) {
94 sycl::accessor acc{buf, cgh, sycl::write_only, sycl::no_init};
96 shambase::parallel_for(cgh, buf.size(),
"buff_fill_discard", [=](
u64 id_a) {
113 inline void print_buf(sycl::buffer<T> &buf,
u32 len,
u32 column_count, std::string_view fmt) {
115 sycl::host_accessor acc{buf, sycl::read_only};
119 for (
u32 i = 0; i < len; i++) {
121 if (i % column_count == 0) {
123 accum += sham::format(
"{:8} : ", i);
125 accum += sham::format(
"\n{:8} : ", i);
129 accum += sham::vformat(fmt, fmt::make_format_args(acc[i]));
136 void copybuf_discard(sycl::queue &q, sycl::buffer<T> &source, sycl::buffer<T> &dest,
u32 cnt) {
137 q.submit([&](sycl::handler &cgh) {
138 sycl::accessor src{source, cgh, sycl::read_only};
139 sycl::accessor dst{dest, cgh, sycl::write_only, sycl::no_init};
141 shambase::parallel_for(cgh, cnt,
"copybuf_discard", [=](
u64 i) {
148 void write_with_offset_into(
150 sycl::buffer<T> &buf_ctn,
151 sycl::buffer<T> &buf_in,
154 q.submit([&](sycl::handler &cgh) {
155 sycl::accessor source{buf_in, cgh, sycl::read_only};
156 sycl::accessor dest{buf_ctn, cgh, sycl::write_only, sycl::no_init};
158 cgh.parallel_for(sycl::range{element_count}, [=](sycl::item<1> item) {
159 dest[item.get_id(0) + off] = source[item];
176 void write_with_offset_into(
187 auto e = q.
submit(depends_list, [&](sycl::handler &cgh) {
189 cgh.parallel_for(sycl::range{element_count}, [=](sycl::item<1> item) {
190 dest[item.get_id(0) + off] = source[item];
209 void write_with_offset_into(
211 sycl::buffer<T> &buf_ctn,
219 auto e = q.
submit(depends_list, [&](sycl::handler &cgh) {
220 sycl::accessor dest{buf_ctn, cgh, sycl::write_only, sycl::no_init};
222 cgh.parallel_for(sycl::range{element_count}, [=](sycl::item<1> item) {
223 dest[item.get_id(0) + off] = source[item];
231 void write_with_offset_into(
232 sycl::queue &q, sycl::buffer<T> &buf_ctn, T val,
u32 offset,
u32 element_count) {
233 q.submit([&, val](sycl::handler &cgh) {
234 sycl::accessor dest{buf_ctn, cgh, sycl::write_only, sycl::no_init};
236 cgh.parallel_for(sycl::range{element_count}, [=](sycl::item<1> item) {
237 dest[item.get_id(0) + off] = val;
243 std::unique_ptr<sycl::buffer<T>> duplicate(
244 sycl::queue &q,
const std::unique_ptr<sycl::buffer<T>> &buf_in) {
246 auto buf = std::make_unique<sycl::buffer<T>>(buf_in->size());
247 copybuf_discard(q, *buf_in, *buf, buf_in->size());
248 return std::move(buf);
254 sycl::buffer<T> vector_to_buf(sycl::queue &q, std::vector<T> &&vec) {
256 u32 cnt = vec.size();
257 sycl::buffer<T> ret(cnt);
259 sycl::buffer<T> alias(vec.data(), cnt);
261 shamalgs::memory::copybuf_discard(q, alias, ret, cnt);
269 return std::move(ret);
281 sycl::buffer<T> vector_to_buf(sycl::queue &q, std::vector<T> &vec) {
283 u32 cnt = vec.size();
284 sycl::buffer<T> ret(cnt);
286 sycl::buffer<T> alias(vec.data(), cnt);
288 shamalgs::memory::copybuf_discard(q, alias, ret, cnt);
296 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).
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 raw_ln(Types... var2)
Prints a log message with multiple arguments followed by a newline.
shambase::details::BasicStackEntry StackEntry
Alias for shambase::details::BasicStackEntry.