37 (
"the buffer is not allocated, the head cannot be moved"));
49 auto source = accbufstg;
51 auto e = q.
submit(depends_list, [dest, source](sycl::handler &cgh) {
52 cgh.memcpy(dest, source,
sizeof(
u64));
67 auto dest = accbufstg;
68 auto source = &prehead;
70 auto e = q.
submit(depends_list, [dest, source](sycl::handler &cgh) {
71 cgh.memcpy(dest, source,
sizeof(
u64));
82 #define ACPP_WAIT .wait()
87std::vector<u8> extract_header(
90 std::vector<u8> storage_header = std::vector<u8>(header_size);
92 if (header_size > 0) {
93 sycl::buffer<u8> attach(storage_header.data(), header_size);
98 auto e = q.
submit(depends_list, [&, pre_head_length](sycl::handler &cgh) {
99 sycl::accessor buf_header{attach, cgh, sycl::write_only, sycl::no_init};
101 cgh.parallel_for(sycl::range<1>{header_size}, [=](sycl::item<1> id) {
102 buf_header[id] = accbufstg[
id + pre_head_length];
112 return storage_header;
118 std::vector<u8> &storage_header,
120 u64 pre_head_length) {
122 if (header_size > 0) {
123 sycl::buffer<u8> attach(storage_header.data(), header_size);
128 auto e = q.
submit(depends_list, [&, pre_head_length](sycl::handler &cgh) {
129 sycl::accessor buf_header{attach, cgh, sycl::read_only};
131 cgh.parallel_for(sycl::range<1>{header_size}, [=](sycl::item<1> id) {
132 accbufstg[
id + pre_head_length] = buf_header[id];
142u64 shamalgs::SerializeHelper::pre_head_length() {
143 return shamalgs::details::serialize_byte_size<shamalgs::SerializeHelper::alignment, u64>()
147void shamalgs::SerializeHelper::allocate(SerializeSize szinfo) {
149 u64 bytelen = szinfo.head_size + szinfo.content_size + pre_head_length();
152 header_size = szinfo.head_size;
153 storage_header.resize(header_size);
155 shamlog_debug_sycl_ln(
"SerializeHelper",
"allocate()", bytelen, header_size);
157 write_prehead(dev_sched->get_queue(), szinfo.head_size, storage);
160 head_device = pre_head_length() + header_size;
166 shamlog_debug_sycl_ln(
"SerializeHelper",
"finalize()", storage.
get_size(), header_size);
168 write_header(dev_sched->get_queue(), storage, storage_header, header_size, pre_head_length());
170 return std::move(storage);
173shamalgs::SerializeHelper::SerializeHelper(std::shared_ptr<sham::DeviceScheduler> _dev_sched)
174 : dev_sched(
std::move(_dev_sched)), storage(0, _dev_sched) {}
176shamalgs::SerializeHelper::SerializeHelper(
178 : dev_sched(
std::move(_dev_sched)), storage(
std::forward<
sham::DeviceBuffer<
u8>>(input)) {
180 header_size = extract_preahead(dev_sched->get_queue(), storage);
182 shamlog_debug_sycl_ln(
185 "Init SerializeHelper from buffer\n storage size : {},\n header_size : {}",
190 = extract_header(dev_sched->get_queue(), storage, header_size, pre_head_length());
192 head_device = pre_head_length() + header_size;
std::uint8_t u8
8 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.
void resize(size_t new_size, bool keep_data=true)
Resizes the buffer to a given size.
T * get_write_access(sham::EventList &depends_list, SourceLocation src_loc=SourceLocation{})
Get a read-write pointer to the buffer's data.
size_t get_size() const
Gets the number of elements in the buffer.
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.
namespace for backends this one is named only sham since shambackends is too long to write
void throw_with_loc(std::string message, SourceLocation loc=SourceLocation{})
Throw an exception and append the source location to it.
Utilities for safe type narrowing conversions.
void write_header(MPI_File fh, std::string s, u64 &file_head_ptr)
Writes a string to a file using MPI and updates the file head pointer. The string is preceded by its ...