Open3D (C++ API)  0.20.0
Loading...
Searching...
No Matches
ReduceSubarraysSumSYCL.h
Go to the documentation of this file.
1// ----------------------------------------------------------------------------
2// - Open3D: www.open3d.org -
3// ----------------------------------------------------------------------------
4// Copyright (c) 2018-2026 www.open3d.org
5// SPDX-License-Identifier: MIT
6// ----------------------------------------------------------------------------
7
8// SYCL implementation of ReduceSubarraysSum — ports ReduceSubarraysSum.cuh.
9// One work-group per sub-array: work-items grid-stride over
10// values[row_splits[i]..row_splits[i+1]) accumulating a partial sum, then
11// sycl::reduce_over_group combines them (same pattern as FillColumnSYCL's
12// normalizer in impl/sparse_conv/SparseConvSYCLKernels.cpp). Test tolerance
13// for floating-point dtypes (rtol=1e-5) permits the reassociated summation
14// order; integer dtypes remain exact.
15
16#pragma once
17
18#include <sycl/sycl.hpp>
19
20namespace open3d {
21namespace ml {
22namespace impl {
23
24namespace {
25// Work-group size for the per-sub-array reduction: 256, a sensible default
26// for launches that have no hardware-specific tuning of their own (unlike
27// e.g. the conv FillColumn kernels' warp-per-point=32, which deliberately
28// mirrors the CUDA design).
29constexpr size_t kReduceSubarraysSumWGSize = 256;
30} // namespace
31
34template <class T>
35void ReduceSubarraysSumSYCL(sycl::queue& queue,
36 const T* const values,
37 const size_t values_size,
38 const int64_t* const row_splits,
39 const size_t num_arrays,
40 T* out_sums) {
41 if (num_arrays == 0) return;
42
43 const size_t wg = kReduceSubarraysSumWGSize;
44 queue.submit([&](sycl::handler& cgh) {
45 cgh.parallel_for(
46 sycl::nd_range<1>(sycl::range<1>(num_arrays * wg),
47 sycl::range<1>(wg)),
48 [=](sycl::nd_item<1> item) {
49 const size_t i = item.get_group(0);
50 const size_t lid = item.get_local_id(0);
51 const size_t begin_idx = static_cast<size_t>(row_splits[i]);
52 const size_t end_idx =
53 static_cast<size_t>(row_splits[i + 1]);
54
55 T local_sum = T(0);
56 for (size_t j = begin_idx + lid; j < end_idx; j += wg) {
57 local_sum += values[j];
58 }
59 T sum = sycl::reduce_over_group(item.get_group(), local_sum,
60 sycl::plus<T>());
61 if (lid == 0) {
62 out_sums[i] = sum;
63 }
64 });
65 });
66}
67
68} // namespace impl
69} // namespace ml
70} // namespace open3d
sycl::queue queue
Definition SYCLContext.cpp:88
void ReduceSubarraysSumSYCL(sycl::queue &queue, const T *const values, const size_t values_size, const int64_t *const row_splits, const size_t num_arrays, T *out_sums)
Definition ReduceSubarraysSumSYCL.h:35
Definition PinholeCameraIntrinsic.cpp:16