← Back to C-Kernel-Engine Docs Doxygen Source Documentation
Loading...
Searching...
No Matches
checked_parallel.h File Reference
#include "ck_threadpool.h"
#include "ckernel_engine.h"
#include <limits.h>

Go to the source code of this file.

Data Structures

struct  ck_checked_range

Typedefs

typedef void(* ck_checked_range_fn) (size_t begin, size_t end, void *args)

Functions

static void ck_checked_parallel_for (size_t count, int grain, ck_checked_range_fn fn, void *args)
static void ck_checked_pool_range (int begin, int end, void *data)

Typedef Documentation

◆ ck_checked_range_fn

typedef void(* ck_checked_range_fn) (size_t begin, size_t end, void *args)

Definition at line 9 of file checked_parallel.h.

Function Documentation

◆ ck_checked_parallel_for()

void ck_checked_parallel_for ( size_t count,
int grain,
ck_checked_range_fn fn,
void * args )
inlinestatic

Definition at line 24 of file checked_parallel.h.

25{
26 if (count <= (size_t)grain) {
27 fn(0, count, args);
28 return;
29 }
30 ck_threadpool_t *pool = ck_threadpool_global();
31 if (!pool || ck_threadpool_in_dispatch(pool)) {
32 fn(0, count, args);
33 return;
34 }
35 int threads = ck_threadpool_n_threads(pool);
36 const int requested = ck_get_num_threads();
37 if (threads > requested) threads = requested;
38 const size_t ranges = count / (size_t)grain + (count % (size_t)grain != 0);
39 if (ranges < (size_t)threads) threads = (int)ranges;
40 struct ck_checked_range range = {fn, args, 0};
41 const int limit = INT_MAX - grain * (CK_THREADPOOL_MAX_THREADS + 1);
42 while (range.offset < count) {
43 const size_t remaining = count - range.offset;
44 const int extent = remaining > (size_t)limit ? limit : (int)remaining;
45 ck_threadpool_parallel_for_n(pool, threads, 0, extent, grain, ck_checked_pool_range, &range);
46 range.offset += (size_t)extent;
47 }
48}
static void ck_checked_pool_range(int begin, int end, void *data)
void ck_threadpool_parallel_for_n(ck_threadpool_t *pool, int active_threads, int begin, int end, int grain_size, ck_range_fn_t fn, void *args)
#define CK_THREADPOOL_MAX_THREADS
ck_threadpool_t * ck_threadpool_global(void)
int ck_threadpool_in_dispatch(const ck_threadpool_t *pool)
int ck_threadpool_n_threads(const ck_threadpool_t *pool)
int ck_get_num_threads(void)
static int extent(size_t rows, size_t cols, size_t stride, size_t size)
ck_checked_range_fn fn
const uint8_t size_t count
Definition true_bpe.h:211

References ck_checked_range::args, ck_checked_pool_range(), ck_get_num_threads(), ck_threadpool_global(), ck_threadpool_in_dispatch(), CK_THREADPOOL_MAX_THREADS, ck_threadpool_n_threads(), ck_threadpool_parallel_for_n(), count, extent(), ck_checked_range::fn, and ck_checked_range::offset.

Referenced by affine_pointwise_u8_i8_f32(), affine_pointwise_u8_i8_u8(), affine_spatial_u8_i8_u8(), attention_full_token_major_online_bf16_exp_checked(), attention_impl(), attention_ranges_checked(), ck_attention_spatial_terms_bf16_checked(), ck_linear_rows_bf16_packed_checked(), ck_linear_rows_bias_bf16_avx2_panel_checked(), ck_linear_rows_panel32_checked(), depth_residual_mix_checked_f32(), gelu_impl(), gqa_relative_sink_checked(), image_conv_hwc_f32(), linear_rows_bf16_checked(), linear_rows_checked_f32(), linear_rows_nvfp4_q8_0_checked_f32(), linear_rows_packed_checked(), linear_rows_packed_k_q8_k_checked(), linear_rows_q8_0_checked(), mamba2_rmsnorm_gate_f32(), norm_impl(), routed_softcapped_experts(), and video_conv_run().

◆ ck_checked_pool_range()

void ck_checked_pool_range ( int begin,
int end,
void * data )
inlinestatic

Definition at line 17 of file checked_parallel.h.

18{
19 struct ck_checked_range *range = data;
20 range->fn(range->offset + (size_t)begin, range->offset + (size_t)end, range->args);
21}
uint32_t end
Definition utf8.c:215

References ck_checked_range::args, end, ck_checked_range::fn, and ck_checked_range::offset.

Referenced by ck_checked_parallel_for().