Blender V5.0
parallel_prefix_sum.h
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2021-2022 Blender Foundation
2 *
3 * SPDX-License-Identifier: Apache-2.0 */
4
5#pragma once
6
8
9/* Parallel prefix sum.
10 *
11 * TODO: actually make this work in parallel.
12 *
13 * This is used for an array the size of the number of shaders in the scene
14 * which is not usually huge, so might not be a significant bottleneck. */
15
16#include "util/atomic.h"
17
18__device__ void gpu_parallel_prefix_sum(const int global_id,
19 ccl_global int *counter,
20 ccl_global int *prefix_sum,
21 const int num_values)
22{
23 if (global_id != 0) {
24 return;
25 }
26
27 int offset = 0;
28 for (int i = 0; i < num_values; i++) {
29 const int new_offset = offset + counter[i];
30 prefix_sum[i] = offset;
31 counter[i] = 0;
32 offset = new_offset;
33 }
34}
35
#define ccl_global
#define CCL_NAMESPACE_END
#define __device__
CCL_NAMESPACE_BEGIN __device__ void gpu_parallel_prefix_sum(const int global_id, ccl_global int *counter, ccl_global int *prefix_sum, const int num_values)
i
Definition text_draw.cc:230