Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
avoidCopyMemory.cpp
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
20
21namespace shamalgs::memory::details {
22
23 template<class T>
24 T AvoidCopy<T>::extract_element(sycl::queue &q, sycl::buffer<T> &buf, u32 idx) {
25
26 if (!(idx < buf.size())) {
28 "you are trying to access out of bounds");
29 }
30
31 sycl::buffer<T> len_value{1};
32 q.submit([&](sycl::handler &cgh) {
33 sycl::accessor global_mem{buf, cgh, sycl::read_only};
34 sycl::accessor acc_rec{len_value, cgh, sycl::write_only, sycl::no_init};
35
36 u32 idx_ = idx;
37
38 cgh.single_task([=]() {
39 acc_rec[0] = global_mem[idx_];
40 });
41 });
42
43 T ret_val;
44 {
45 sycl::host_accessor acc{len_value, sycl::read_only};
46 ret_val = acc[0];
47 }
48
49 return ret_val;
50 }
51
52#define XMAC_TYPES \
53 X(f32) \
54 X(f32_2) \
55 X(f32_3) \
56 X(f32_4) \
57 X(f32_8) \
58 X(f32_16) \
59 X(f64) \
60 X(f64_2) \
61 X(f64_3) \
62 X(f64_4) \
63 X(f64_8) \
64 X(f64_16) \
65 X(u8) \
66 X(u32) \
67 X(u32_2) \
68 X(u32_3) \
69 X(u32_4) \
70 X(u32_8) \
71 X(u32_16) \
72 X(u64) \
73 X(u64_2) \
74 X(u64_3) \
75 X(u64_4) \
76 X(u64_8) \
77 X(u64_16) \
78 X(i64_3) \
79 X(i64)
80
81#define X(_arg_) template struct AvoidCopy<_arg_>;
82 XMAC_TYPES
83#undef X
84
85} // namespace shamalgs::memory::details
std::uint32_t u32
32 bit unsigned integer
This header file contains utility functions related to exception handling in the code.
void throw_with_loc(std::string message, SourceLocation loc=SourceLocation{})
Throw an exception and append the source location to it.