Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
groupReduction_usm.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#include "shamalgs/memory.hpp"
22#include "shambackends/math.hpp"
23#include "shambackends/sycl.hpp"
25#include "shambackends/vec.hpp"
26#include <stdexcept>
27
28namespace shamalgs::reduction::details {
29#ifdef SYCL2020_FEATURE_GROUP_REDUCTION
30
42 template<class T>
43 T sum_usm_group(
44 const sham::DeviceScheduler_ptr &sched,
45 const sham::DeviceBuffer<T> &buf1,
46 u32 start_id,
47 u32 end_id,
48 u32 work_group_size) {
49
50 // Empty range for sum should return 0
51 if (start_id >= end_id) {
53 }
54
55 return reduc_internal<T>(
56 sched,
57 buf1,
58 start_id,
59 end_id,
60 work_group_size,
61 [](sycl::group<1> g, T v) {
62 return sham::sum_over_group(g, v);
63 },
64 [](T lhs, T rhs) {
65 return lhs + rhs;
66 },
67 []() {
69 });
70 }
71
83 template<class T>
84 T max_usm_group(
85 const sham::DeviceScheduler_ptr &sched,
86 const sham::DeviceBuffer<T> &buf1,
87 u32 start_id,
88 u32 end_id,
89 u32 work_group_size) {
90
91 if (start_id >= end_id) {
93 "Empty range (or invalid range) not supported for max operation\n start_id = {}, "
94 "end_id = {}",
95 start_id,
96 end_id));
97 }
98
99 return reduc_internal<T>(
100 sched,
101 buf1,
102 start_id,
103 end_id,
104 work_group_size,
105 [](sycl::group<1> g, T v) {
106 return sham::max_over_group(g, v);
107 },
108 [](T lhs, T rhs) {
109 return sham::max(lhs, rhs);
110 },
111 []() {
113 });
114 }
115
127 template<class T>
128 T min_usm_group(
129 const sham::DeviceScheduler_ptr &sched,
130 const sham::DeviceBuffer<T> &buf1,
131 u32 start_id,
132 u32 end_id,
133 u32 work_group_size) {
134
135 if (start_id >= end_id) {
137 "Empty range (or invalid range) not supported for min operation\n start_id = {}, "
138 "end_id = {}",
139 start_id,
140 end_id));
141 }
142
143 return reduc_internal<T>(
144 sched,
145 buf1,
146 start_id,
147 end_id,
148 work_group_size,
149 [](sycl::group<1> g, T v) {
150 return sham::min_over_group(g, v);
151 },
152 [](T lhs, T rhs) {
153 return sham::min(lhs, rhs);
154 },
155 []() {
157 });
158 }
159#endif
160} // namespace shamalgs::reduction::details
161
162#ifndef DOXYGEN
163
164 #ifdef SYCL2020_FEATURE_GROUP_REDUCTION
165
166 #define XMAC_TYPES \
167 X(f32) \
168 X(f32_2) \
169 X(f32_3) \
170 X(f32_4) \
171 X(f32_8) \
172 X(f32_16) \
173 X(f64) \
174 X(f64_2) \
175 X(f64_3) \
176 X(f64_4) \
177 X(f64_8) \
178 X(f64_16) \
179 X(u32) \
180 X(u64) \
181 X(i32) \
182 X(i64) \
183 X(u32_3) \
184 X(u64_3) \
185 X(i64_3) \
186 X(i32_3)
187
188 #define X(_arg_) \
189 template _arg_ shamalgs::reduction::details::sum_usm_group<_arg_>( \
190 const sham::DeviceScheduler_ptr &sched, \
191 const sham::DeviceBuffer<_arg_> &buf1, \
192 u32 start_id, \
193 u32 end_id, \
194 u32 work_group_size); \
195 template _arg_ shamalgs::reduction::details::max_usm_group<_arg_>( \
196 const sham::DeviceScheduler_ptr &sched, \
197 const sham::DeviceBuffer<_arg_> &buf1, \
198 u32 start_id, \
199 u32 end_id, \
200 u32 work_group_size); \
201 template _arg_ shamalgs::reduction::details::min_usm_group<_arg_>( \
202 const sham::DeviceScheduler_ptr &sched, \
203 const sham::DeviceBuffer<_arg_> &buf1, \
204 u32 start_id, \
205 u32 end_id, \
206 u32 work_group_size);
207
208XMAC_TYPES
209 #undef X
210
211 #endif
212#endif
std::uint32_t u32
32 bit unsigned integer
A buffer allocated in USM (Unified Shared Memory)
void throw_with_loc(std::string message, SourceLocation loc=SourceLocation{})
Throw an exception and append the source location to it.
main include file for memory algorithms