38 src.materialize(range, dst.data());
58 src.materialize(selection.slice(range), dst.data());
77 src.materialize_compressed(indices.slice(range), dst.slice(range).data());
104 for (
const int i : indices) {
112 for (const int i : indices.slice(range)) {
113 atomic_add_and_fetch_int32(&counts[i], 1);
130 Array<int> &local_counts = counts_by_thread.local();
131 for (const int i : indices.slice(range)) {
139 for (
const Array<int> &local_counts : counts_by_thread) {
140 for (
const int64_t i : range) {
141 counts[i] += local_counts[i];
152 const int64_t groups_num = std::max<int64_t>(counts.
size(), 1);
156 constexpr int64_t max_thread_local_groups = 1 << 18;
157 if (groups_num <= max_thread_local_groups) {
160 constexpr int64_t min_groups_per_index = 10;
161 const int64_t max_threads = std::clamp<int64_t>(
166 constexpr int64_t min_parallel_indices = 1 << 16;
167 const int64_t min_thread_local_indices = min_parallel_indices + indices_num / max_threads +
168 max_threads * groups_num / min_groups_per_index;
170 if (indices_num < min_thread_local_indices) {
180 constexpr int64_t min_atomic_indices = 1 << 19;
181 if (indices_num < min_atomic_indices) {
205 Array<int, 64> first_elem(ids_range, std::numeric_limits<int>::max());
206 mask.foreach_index_optimized<
int>(
208 std::atomic_ref<int> first(first_elem[ids[i] - id_min]);
209 int prev = first.load(std::memory_order_relaxed);
210 while (i < prev && !first.compare_exchange_weak(prev, i, std::memory_order_relaxed)) {
219 mask, memory, [&](
const int i) {
return first_elem[ids[i] - id_min] == i; });
221 [&](
const int i,
const int group) { first_elem[ids[i] - id_min] = group; },
225 mask.foreach_index_optimized<
int>(
226 [&](
const int i,
const int pos) { r_group_indices[pos] = first_elem[ids[i] - id_min]; },
229 if (r_first_indices) {
230 r_first_indices->
resize(first_indices.
size());
233 return first_indices.
size();
249 if (ids_range <
mask.size() * 4) {
260 mask.foreach_index_optimized<
int>([&](
const int i,
const int pos) {
261 const int group = unique_ids.index_of_or_add(ids[i]);
262 if (r_first_indices && group == r_first_indices->
size()) {
263 r_first_indices->
append(i);
265 r_group_indices[pos] = group;
267 return unique_ids.size();
274 for (const int i : range) {
288 return std::all_of(span.
begin(), span.
end(), [&](
const bool value) { return value == test; });
294 range.
begin(), range.
end(), [&](
const int64_t i) { return varray[i] == test; });
356 return *
static_cast<const bool *
>(info.
data) ? varray.
size() : 0;
365 const Span<bool> slice = span.slice(range);
366 return init + std::count(slice.begin(), slice.end(), true);
375 int64_t value = init;
377 for (const int64_t i : range) {
378 value += int64_t(varray[i]);
386 return *
static_cast<const bool *
>(info.
data) ?
mask.size() : 0;
389 mask.foreach_segment([&](
const IndexMaskSegment segment) {
390 for (
const int64_t i : segment) {
402 return *
static_cast<const bool *
>(info.
data) == value;
415 if (std::optional<IndexRange> range = sliced_mask.to_range()) {
416 return span.slice(*range).contains(value);
419 const IndexMaskSegment segment = sliced_mask.segment(segment_i);
420 for (const int i : segment) {
421 if (span[i] == value) {
430 return threading::parallel_reduce(
431 indices_to_check.index_range(),
434 [&](
const IndexRange range,
const bool init) {
438 constexpr int64_t MaxChunkSize = 512;
439 const int64_t slice_end = range.one_after_last();
440 for (
int64_t start = range.start(); start < slice_end; start += MaxChunkSize) {
441 const int64_t end = std::min<int64_t>(start + MaxChunkSize, slice_end);
442 const int64_t size = end - start;
443 const IndexMask sliced_mask = indices_to_check.slice(start, size);
444 std::array<bool, MaxChunkSize> values;
445 std::array<bool, MaxChunkSize>::iterator values_end = values.begin() + size;
446 varray.materialize_compressed(sliced_mask, values);
447 if (std::find(values.begin(), values_end, value) != values_end) {
474 [&](
const int i) {
return range.
contains(values[i]); },
485 if (indices.
size() != range.
size()) {
493 [&](
const IndexRange part,
const bool is_range) {
494 const Span<int> local_indices = indices.slice(part);
495 const IndexRange local_range = range.slice(part);
497 std::equal(local_indices.begin(), local_indices.end(), local_range.begin());
499 std::logical_and<>());
#define PRF_scope_with_name(ui_name, category)
#define PRF_scope(category)
Provides wrapper around system-specific atomic primitives, and some extensions (faked-atomic operatio...
void copy_from(GSpan values)
GMutableSpan slice(const int64_t start, int64_t size) const
const CPPType & type() const
GSpan slice(const int64_t start, int64_t size) const
const CPPType & type() const
void materialize(void *dst) const
IndexRange index_range() const
void materialize_compressed(const IndexMask &mask, void *dst) const
static GVArray from_span(GSpan span)
static IndexMask from_predicate(const IndexMask &universe, LinearAllocator<> &memory, Fn &&predicate, exec_mode::Mode mode=exec_mode::parallel)
constexpr int64_t first() const
constexpr Iterator end() const
constexpr int64_t size() const
constexpr Iterator begin() const
constexpr bool contains(int64_t value) const
constexpr IndexRange index_range() const
constexpr int64_t size() const
constexpr IndexRange index_range() const
constexpr Span slice(int64_t start, int64_t size) const
constexpr const T & first() const
constexpr int64_t size() const
constexpr const T * end() const
constexpr IndexRange index_range() const
constexpr const T * begin() const
IndexRange index_range() const
CommonVArrayInfo common_info() const
void append(const T &value)
void resize(const int64_t new_size)
MutableSpan< T > as_mutable_span()
void foreach_index_optimized(Fn &&fn, Mode mode=exec_mode::serial) const
IndexMask slice(IndexRange range) const
void to_indices(MutableSpan< T > r_indices) const
int64_t min_array_size() const
IndexRange index_range() const
void foreach_index(Fn &&fn, Mode mode=exec_mode::serial) const
ccl_device_inline float2 mask(const MaskType mask, const float2 a)
IndexMask indices_in_range(const IndexMask &universe, Span< int > values, IndexRange range, LinearAllocator<> &memory)
void gather(const GVArray &src, const IndexMask &indices, GMutableSpan dst, exec_mode::Mode mode=exec_mode::parallel)
static void count_indices_atomics(const Span< int > indices, MutableSpan< int > counts)
void invert_booleans(MutableSpan< bool > span)
void count_indices(Span< int > indices, MutableSpan< int > counts)
IndexMask indices_non_negative(const IndexMask &universe, Span< int > values, LinearAllocator<> &memory)
bool indices_are_range(Span< int > indices, IndexRange range)
void copy_group_to_group(OffsetIndices< int > src_offsets, OffsetIndices< int > dst_offsets, const IndexMask &selection, GSpan src, GMutableSpan dst)
static void count_indices_thread_local(const Span< int > indices, MutableSpan< int > counts, const int64_t max_threads)
void copy(const GVArray &src, GMutableSpan dst, exec_mode::Mode mode=exec_mode::parallel)
BooleanMix booleans_mix_calc(const VArray< bool > &varray, IndexRange range_to_check)
bool contains(const VArray< bool > &varray, const IndexMask &indices_to_check, bool value)
constexpr int64_t calc_copy_grain_size(const exec_mode::Tag auto mode, const int64_t type_size)
static bool all_equal(const Span< bool > span, const bool test)
int group_ids_to_indices(Span< int > ids, const IndexMask &mask, MutableSpan< int > r_group_indices, Vector< int > *r_first_indices=nullptr)
static void count_indices_serial(const Span< int > indices, MutableSpan< int > counts)
static int count_indices_with_table(const Span< int > ids, const IndexMask &mask, const Bounds< int > &id_bounds, MutableSpan< int > r_group_indices, Vector< int > *r_first_indices)
int64_t count_booleans(const VArray< bool > &varray)
std::optional< Bounds< T > > min_max(const std::optional< Bounds< T > > &a, const T &b)
constexpr ParallelGrainSize grain_size(int grain_size)
void max_threads_task(const int max_threads, const Function &function)
void parallel_for(const IndexRange range, const int64_t grain_size, const Function &function, const TaskSizeHints &size_hints=detail::TaskSizeHints_Static(1))
Value parallel_reduce(IndexRange range, int64_t grain_size, const Value &identity, const Function &function, const Reduction &reduction)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
int BLI_system_thread_count()
PythonProbingStrategy<> DefaultProbingStrategy