24template<
class morton_t,
class pos_t, u32 dim>
27template<
class morton_t,
class pos_t, u32 dim>
30template<
class morton_t,
class _pos_t, u32 dim>
33namespace shamrock::sfc {
36 void details::sycl_fill_trailling_buffer(
40 std::unique_ptr<sycl::buffer<T>> &buf_morton) {
42 shamlog_debug_sycl_ln(
"MortonKernels",
"submit : ", __PRETTY_FUNCTION__);
44 if (fill_count - morton_count == 0) {
45 shamlog_debug_sycl_ln(
46 "MortonKernels",
"sycl_fill_trailling_buffer skipping pow len 2 is ok");
50 sycl::range<1> range_npart{fill_count - morton_count};
52 auto ker_fill_trailling_buf = [&](sycl::handler &cgh) {
53 sycl::accessor m{*buf_morton, cgh, sycl::write_only, sycl::no_init};
56 m[morton_count + i.get_id()] = MortonInfo<T>::err_code;
60 queue.submit(ker_fill_trailling_buf);
63 template void details::sycl_fill_trailling_buffer<u32>(
67 std::unique_ptr<sycl::buffer<u32>> &buf_morton);
69 template void details::sycl_fill_trailling_buffer<u64>(
73 std::unique_ptr<sycl::buffer<u64>> &buf_morton);
75 template<
class morton_t,
class _pos_t, u32 dim>
79 sycl::buffer<pos_t> &in_positions,
80 pos_t bounding_box_min,
81 pos_t bounding_box_max,
82 std::unique_ptr<sycl::buffer<morton_t>> &out_morton) {
84 shamlog_debug_sycl_ln(
"MortonKernels",
"submit : ", __PRETTY_FUNCTION__);
86 sycl::range<1> range_cnt{pos_count};
88 queue.submit([&](sycl::handler &cgh) {
89 auto transf = get_transform(bounding_box_min, bounding_box_max);
91 sycl::accessor r{in_positions, cgh, sycl::read_only};
92 sycl::accessor m{*out_morton, cgh, sycl::write_only, sycl::no_init};
95 range_cnt, [=](sycl::item<1> item) {
96 int i = (int) item.get_id(0);
98 ipos_t mr = to_morton_grid(r[i], transf);
99 m[i] = Morton::icoord_to_morton(mr.x(), mr.y(), mr.z());
106 template<
class morton_t,
class _pos_t, u32 dim>
108 const sham::DeviceScheduler_ptr &dev_sched,
111 pos_t bounding_box_min,
112 pos_t bounding_box_max,
113 std::unique_ptr<sycl::buffer<morton_t>> &out_morton) {
115 shamlog_debug_sycl_ln(
"MortonKernels",
"submit : ", __PRETTY_FUNCTION__);
117 sycl::range<1> range_cnt{pos_count};
119 auto q = dev_sched->get_queue();
124 auto e = q.submit(el, [&](sycl::handler &cgh) {
125 auto transf = get_transform(bounding_box_min, bounding_box_max);
127 sycl::accessor m{*out_morton, cgh, sycl::write_only, sycl::no_init};
130 range_cnt, [=](sycl::item<1> item) {
131 int i = (int) item.get_id(0);
133 ipos_t mr = to_morton_grid(r[i], transf);
134 m[i] = Morton::icoord_to_morton(mr.x(), mr.y(), mr.z());
141 template<
class morton_t,
class _pos_t, u32 dim>
142 void MortonKernels<morton_t, _pos_t, dim>::sycl_irange_to_range(
145 pos_t bounding_box_min,
146 pos_t bounding_box_max,
147 std::unique_ptr<sycl::buffer<ipos_t>> &buf_pos_min_cell,
148 std::unique_ptr<sycl::buffer<ipos_t>> &buf_pos_max_cell,
149 std::unique_ptr<sycl::buffer<pos_t>> &out_buf_pos_min_cell_flt,
150 std::unique_ptr<sycl::buffer<pos_t>> &out_buf_pos_max_cell_flt) {
151 sycl::range<1> range_cell{buf_len};
153 constexpr u32 group_size = 256;
154 u32 max_len = buf_len;
156 group_cnt = group_cnt + (group_cnt % 4);
157 u32 corrected_len = group_cnt * group_size;
159 shamlog_debug_sycl_ln(
"MortonKernels",
"submit : ", __PRETTY_FUNCTION__);
161 auto ker_convert_cell_ranges = [&, max_len](sycl::handler &cgh) {
162 auto transf = get_transform(bounding_box_min, bounding_box_max);
164 auto pos_min_cell = sycl::accessor{*buf_pos_min_cell, cgh, sycl::read_only};
165 auto pos_max_cell = sycl::accessor{*buf_pos_max_cell, cgh, sycl::read_only};
167 auto pos_min_cell_flt
168 = sycl::accessor{*out_buf_pos_min_cell_flt, cgh, sycl::write_only, sycl::no_init};
169 auto pos_max_cell_flt
170 = sycl::accessor{*out_buf_pos_max_cell_flt, cgh, sycl::write_only, sycl::no_init};
173 sycl::nd_range<1>{corrected_len, group_size}, [=](sycl::nd_item<1> id) {
174 u32 local_id =
id.get_local_id(0);
175 u32 group_tile_id =
id.get_group_linear_id();
176 u32 gid = group_tile_id * group_size + local_id;
181 pos_min_cell_flt[gid] = to_real_space(pos_min_cell[gid], transf);
182 pos_max_cell_flt[gid] = to_real_space(pos_max_cell[gid], transf);
186 queue.submit(ker_convert_cell_ranges);
189 template class MortonKernels<u32, f32_3, 3>;
190 template class MortonKernels<u64, f32_3, 3>;
191 template class MortonKernels<u32, f64_3, 3>;
192 template class MortonKernels<u64, f64_3, 3>;
193 template class MortonKernels<u32, u32_3, 3>;
194 template class MortonKernels<u64, u32_3, 3>;
195 template class MortonKernels<u32, u64_3, 3>;
196 template class MortonKernels<u64, u64_3, 3>;
197 template class MortonKernels<u32, i64_3, 3>;
198 template class MortonKernels<u64, i64_3, 3>;
std::uint32_t u32
32 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.
const T * get_read_access(sham::EventList &depends_list, SourceLocation src_loc=SourceLocation{}) const
Get a read-only pointer to the buffer's data.
Class to manage a list of SYCL events.
static void sycl_xyz_to_morton(sycl::queue &queue, u32 pos_count, sycl::buffer< pos_t > &in_positions, pos_t bounding_box_min, pos_t bounding_box_max, std::unique_ptr< sycl::buffer< morton_t > > &out_morton)
convert a buffer of 3d positions to morton codes
Define the fmt formatters for sycl::vec.
constexpr u32 group_count(u32 len, u32 group_size)
Calculates the number of groups based on the length and group size.