aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMarat Dukhan <maratek@google.com>2020-03-26 14:19:30 -0700
committerMarat Dukhan <maratek@google.com>2020-03-26 14:19:30 -0700
commit76042155a8b1e189c8f141429fd72219472c32e1 (patch)
tree0fc182011d2fe74c23115b411181b0c0f1dbe236 /src
parent6469659dd404768fd80f1989dfd66930a6587bf8 (diff)
downloadpthreadpool-76042155a8b1e189c8f141429fd72219472c32e1.tar.gz
Microarchitecture-aware parallelization functions
Diffstat (limited to 'src')
-rw-r--r--src/threadpool-pthreads.c424
-rw-r--r--src/threadpool-shim.c83
2 files changed, 497 insertions, 10 deletions
diff --git a/src/threadpool-pthreads.c b/src/threadpool-pthreads.c
index 6ebd521..0a9c06d 100644
--- a/src/threadpool-pthreads.c
+++ b/src/threadpool-pthreads.c
@@ -9,6 +9,10 @@
#include <pthread.h>
#include <unistd.h>
+#ifndef PTHREADPOOL_USE_CPUINFO
+ #define PTHREADPOOL_USE_CPUINFO 0
+#endif
+
#ifndef PTHREADPOOL_USE_FUTEX
#if defined(__linux__)
#define PTHREADPOOL_USE_FUTEX 1
@@ -19,6 +23,10 @@
#endif
#endif
+#if PTHREADPOOL_USE_CPUINFO
+ #include <cpuinfo.h>
+#endif
+
/* Futex-specific headers */
#if PTHREADPOOL_USE_FUTEX
#if defined(__linux__)
@@ -164,6 +172,17 @@ struct PTHREADPOOL_CACHELINE_ALIGNED thread_info {
PTHREADPOOL_STATIC_ASSERT(sizeof(struct thread_info) % PTHREADPOOL_CACHELINE_SIZE == 0, "thread_info structure must occupy an integer number of cache lines (64 bytes)");
+struct pthreadpool_1d_with_uarch_params {
+ /**
+ * Copy of the default uarch index argument passed to a microarchitecture-aware parallelization function.
+ */
+ uint32_t default_uarch_index;
+ /**
+ * Copy of the max uarch index argument passed to a microarchitecture-aware parallelization function.
+ */
+ uint32_t max_uarch_index;
+};
+
struct PTHREADPOOL_CACHELINE_ALIGNED pthreadpool {
/**
* The number of threads that are processing an operation.
@@ -195,6 +214,13 @@ struct PTHREADPOOL_CACHELINE_ALIGNED pthreadpool {
*/
pthreadpool_atomic_void_p argument;
/**
+ * Additional parallelization parameters.
+ * These parameters are specific for each thread_function.
+ */
+ union {
+ struct pthreadpool_1d_with_uarch_params parallelize_1d_with_uarch;
+ } params;
+ /**
* Copy of the flags passed to a parallelization function.
*/
pthreadpool_atomic_uint32_t flags;
@@ -220,8 +246,14 @@ struct PTHREADPOOL_CACHELINE_ALIGNED pthreadpool {
*/
pthread_cond_t command_condvar;
#endif
+#if PTHREADPOOL_USE_CPUINFO
/**
- * The number of threads in the thread pool. Never changes after initialization.
+ * Indication whether cpuinfo library initialized successfully. Never changes after pthreadpool_create.
+ */
+ bool cpuinfo_is_initialized;
+#endif
+ /**
+ * The number of threads in the thread pool. Never changes after pthreadpool_create.
*/
size_t threads_count;
/**
@@ -356,6 +388,45 @@ static void thread_parallelize_1d(struct pthreadpool* threadpool, struct thread_
pthreadpool_fence_release();
}
+static void thread_parallelize_1d_with_uarch(struct pthreadpool* threadpool, struct thread_info* thread) {
+ const pthreadpool_task_1d_with_id_t task = (pthreadpool_task_1d_with_id_t) pthreadpool_load_relaxed_void_p(&threadpool->task);
+ void *const argument = pthreadpool_load_relaxed_void_p(&threadpool->argument);
+
+ const uint32_t default_uarch_index = threadpool->params.parallelize_1d_with_uarch.default_uarch_index;
+ uint32_t uarch_index = default_uarch_index;
+ #if PTHREADPOOL_USE_CPUINFO
+ if (threadpool && threadpool->cpuinfo_is_initialized) {
+ uarch_index = cpuinfo_get_current_uarch_index();
+ if (uarch_index > threadpool->params.parallelize_1d_with_uarch.max_uarch_index) {
+ uarch_index = default_uarch_index;
+ }
+ }
+ #endif
+
+ /* Process thread's own range of items */
+ size_t range_start = pthreadpool_load_relaxed_size_t(&thread->range_start);
+ while (atomic_decrement(&thread->range_length)) {
+ task(argument, uarch_index, range_start++);
+ }
+
+ /* There still may be other threads with work */
+ const size_t thread_number = thread->thread_number;
+ const size_t threads_count = threadpool->threads_count;
+ for (size_t tid = modulo_decrement(thread_number, threads_count);
+ tid != thread_number;
+ tid = modulo_decrement(tid, threads_count))
+ {
+ struct thread_info* other_thread = &threadpool->threads[tid];
+ while (atomic_decrement(&other_thread->range_length)) {
+ const size_t item_id = pthreadpool_fetch_sub_relaxed_size_t(&other_thread->range_end, 1) - 1;
+ task(argument, uarch_index, item_id);
+ }
+ }
+
+ /* Make changes by this thread visible to other threads */
+ pthreadpool_fence_release();
+}
+
static uint32_t wait_for_new_command(
struct pthreadpool* threadpool,
uint32_t last_command,
@@ -501,6 +572,9 @@ struct pthreadpool* pthreadpool_create(size_t threads_count) {
for (size_t tid = 0; tid < threads_count; tid++) {
threadpool->threads[tid].thread_number = tid;
}
+ #if PTHREADPOOL_USE_CPUINFO
+ threadpool->cpuinfo_is_initialized = cpuinfo_initialize();
+ #endif
/* Thread pool with a single thread computes everything on the caller thread. */
if (threads_count > 1) {
@@ -539,6 +613,8 @@ size_t pthreadpool_get_threads_count(struct pthreadpool* threadpool) {
static void pthreadpool_parallelize(
struct pthreadpool* threadpool,
thread_function_t thread_function,
+ const void* params,
+ size_t params_size,
void* task,
void* context,
size_t linear_range,
@@ -570,6 +646,11 @@ static void pthreadpool_parallelize(
pthreadpool_store_relaxed_uint32_t(&threadpool->has_active_threads, 1);
#endif
+ if (params_size != 0) {
+ memcpy(&threadpool->params, params, params_size);
+ pthreadpool_fence_release();
+ }
+
/* Spread the work between threads */
size_t range_start = 0;
for (size_t tid = 0; tid < threads_count; tid++) {
@@ -659,11 +740,55 @@ void pthreadpool_parallelize_1d(
}
} else {
pthreadpool_parallelize(
- threadpool, &thread_parallelize_1d,
+ threadpool, &thread_parallelize_1d, NULL, 0,
(void*) task, argument, range, flags);
}
}
+void pthreadpool_parallelize_1d_with_uarch(
+ pthreadpool_t threadpool,
+ pthreadpool_task_1d_with_id_t task,
+ void* argument,
+ uint32_t default_uarch_index,
+ uint32_t max_uarch_index,
+ size_t range,
+ uint32_t flags)
+{
+ if (threadpool == NULL || threadpool->threads_count <= 1 || range <= 1) {
+ /* No thread pool used: execute task sequentially on the calling thread */
+
+ uint32_t uarch_index = default_uarch_index;
+ #if PTHREADPOOL_USE_CPUINFO
+ if (threadpool && threadpool->cpuinfo_is_initialized) {
+ uarch_index = cpuinfo_get_current_uarch_index();
+ if (uarch_index > max_uarch_index) {
+ uarch_index = default_uarch_index;
+ }
+ }
+ #endif
+
+ struct fpu_state saved_fpu_state = { 0 };
+ if (flags & PTHREADPOOL_FLAG_DISABLE_DENORMALS) {
+ saved_fpu_state = get_fpu_state();
+ disable_fpu_denormals();
+ }
+ for (size_t i = 0; i < range; i++) {
+ task(argument, uarch_index, i);
+ }
+ if (flags & PTHREADPOOL_FLAG_DISABLE_DENORMALS) {
+ set_fpu_state(saved_fpu_state);
+ }
+ } else {
+ const struct pthreadpool_1d_with_uarch_params params = {
+ .default_uarch_index = default_uarch_index,
+ .max_uarch_index = max_uarch_index,
+ };
+ pthreadpool_parallelize(
+ threadpool, &thread_parallelize_1d_with_uarch, &params, sizeof(params),
+ task, argument, range, flags);
+ }
+}
+
struct compute_1d_tile_1d_context {
pthreadpool_task_1d_tile_1d_t task;
void* argument;
@@ -709,7 +834,7 @@ void pthreadpool_parallelize_1d_tile_1d(
.tile = tile
};
pthreadpool_parallelize(
- threadpool, &thread_parallelize_1d,
+ threadpool, &thread_parallelize_1d, NULL, 0,
(void*) compute_1d_tile_1d, &context, tile_range, flags);
}
}
@@ -757,7 +882,7 @@ void pthreadpool_parallelize_2d(
.range_j = fxdiv_init_size_t(range_j)
};
pthreadpool_parallelize(
- threadpool, &thread_parallelize_1d,
+ threadpool, &thread_parallelize_1d, NULL, 0,
(void*) compute_2d, &context, range_i * range_j, flags);
}
}
@@ -817,7 +942,7 @@ void pthreadpool_parallelize_2d_tile_1d(
.tile_j = tile_j
};
pthreadpool_parallelize(
- threadpool, &thread_parallelize_1d,
+ threadpool, &thread_parallelize_1d, NULL, 0,
(void*) compute_2d_tile_1d, &context, range_i * tile_range_j, flags);
}
}
@@ -883,11 +1008,94 @@ void pthreadpool_parallelize_2d_tile_2d(
.tile_j = tile_j
};
pthreadpool_parallelize(
- threadpool, &thread_parallelize_1d,
+ threadpool, &thread_parallelize_1d, NULL, 0,
(void*) compute_2d_tile_2d, &context, tile_range_i * tile_range_j, flags);
}
}
+struct compute_2d_tile_2d_with_uarch_context {
+ pthreadpool_task_2d_tile_2d_with_id_t task;
+ void* argument;
+ struct fxdiv_divisor_size_t tile_range_j;
+ size_t range_i;
+ size_t range_j;
+ size_t tile_i;
+ size_t tile_j;
+};
+
+static void compute_2d_tile_2d_with_uarch(const struct compute_2d_tile_2d_with_uarch_context* context, uint32_t uarch_index, size_t linear_index) {
+ const struct fxdiv_divisor_size_t tile_range_j = context->tile_range_j;
+ const struct fxdiv_result_size_t tile_index = fxdiv_divide_size_t(linear_index, tile_range_j);
+ const size_t max_tile_i = context->tile_i;
+ const size_t max_tile_j = context->tile_j;
+ const size_t index_i = tile_index.quotient * max_tile_i;
+ const size_t index_j = tile_index.remainder * max_tile_j;
+ const size_t tile_i = min(max_tile_i, context->range_i - index_i);
+ const size_t tile_j = min(max_tile_j, context->range_j - index_j);
+ context->task(context->argument, uarch_index, index_i, index_j, tile_i, tile_j);
+}
+
+void pthreadpool_parallelize_2d_tile_2d_with_uarch(
+ pthreadpool_t threadpool,
+ pthreadpool_task_2d_tile_2d_with_id_t task,
+ void* argument,
+ uint32_t default_uarch_index,
+ uint32_t max_uarch_index,
+ size_t range_i,
+ size_t range_j,
+ size_t tile_i,
+ size_t tile_j,
+ uint32_t flags)
+{
+ if (threadpool == NULL || threadpool->threads_count <= 1 || (range_i <= tile_i && range_j <= tile_j)) {
+ /* No thread pool used: execute task sequentially on the calling thread */
+
+ uint32_t uarch_index = default_uarch_index;
+ #if PTHREADPOOL_USE_CPUINFO
+ if (threadpool && threadpool->cpuinfo_is_initialized) {
+ uarch_index = cpuinfo_get_current_uarch_index();
+ if (uarch_index > max_uarch_index) {
+ uarch_index = default_uarch_index;
+ }
+ }
+ #endif
+
+ struct fpu_state saved_fpu_state = { 0 };
+ if (flags & PTHREADPOOL_FLAG_DISABLE_DENORMALS) {
+ saved_fpu_state = get_fpu_state();
+ disable_fpu_denormals();
+ }
+ for (size_t i = 0; i < range_i; i += tile_i) {
+ for (size_t j = 0; j < range_j; j += tile_j) {
+ task(argument, uarch_index, i, j, min(range_i - i, tile_i), min(range_j - j, tile_j));
+ }
+ }
+ if (flags & PTHREADPOOL_FLAG_DISABLE_DENORMALS) {
+ set_fpu_state(saved_fpu_state);
+ }
+ } else {
+ /* Execute in parallel on the thread pool using linearized index */
+ const size_t tile_range_i = divide_round_up(range_i, tile_i);
+ const size_t tile_range_j = divide_round_up(range_j, tile_j);
+ const struct pthreadpool_1d_with_uarch_params params = {
+ .default_uarch_index = default_uarch_index,
+ .max_uarch_index = max_uarch_index,
+ };
+ struct compute_2d_tile_2d_with_uarch_context context = {
+ .task = task,
+ .argument = argument,
+ .tile_range_j = fxdiv_init_size_t(tile_range_j),
+ .range_i = range_i,
+ .range_j = range_j,
+ .tile_i = tile_i,
+ .tile_j = tile_j
+ };
+ pthreadpool_parallelize(
+ threadpool, &thread_parallelize_1d_with_uarch, &params, sizeof(params),
+ (void*) compute_2d_tile_2d_with_uarch, &context, tile_range_i * tile_range_j, flags);
+ }
+}
+
struct compute_3d_tile_2d_context {
pthreadpool_task_3d_tile_2d_t task;
void* argument;
@@ -957,11 +1165,102 @@ void pthreadpool_parallelize_3d_tile_2d(
.tile_k = tile_k
};
pthreadpool_parallelize(
- threadpool, &thread_parallelize_1d,
+ threadpool, &thread_parallelize_1d, NULL, 0,
(void*) compute_3d_tile_2d, &context, range_i * tile_range_j * tile_range_k, flags);
}
}
+struct compute_3d_tile_2d_with_uarch_context {
+ pthreadpool_task_3d_tile_2d_with_id_t task;
+ void* argument;
+ struct fxdiv_divisor_size_t tile_range_j;
+ struct fxdiv_divisor_size_t tile_range_k;
+ size_t range_j;
+ size_t range_k;
+ size_t tile_j;
+ size_t tile_k;
+};
+
+static void compute_3d_tile_2d_with_uarch(const struct compute_3d_tile_2d_with_uarch_context* context, uint32_t uarch_index, size_t linear_index) {
+ const struct fxdiv_divisor_size_t tile_range_k = context->tile_range_k;
+ const struct fxdiv_result_size_t tile_index_ij_k = fxdiv_divide_size_t(linear_index, tile_range_k);
+ const struct fxdiv_divisor_size_t tile_range_j = context->tile_range_j;
+ const struct fxdiv_result_size_t tile_index_i_j = fxdiv_divide_size_t(tile_index_ij_k.quotient, tile_range_j);
+ const size_t max_tile_j = context->tile_j;
+ const size_t max_tile_k = context->tile_k;
+ const size_t index_i = tile_index_i_j.quotient;
+ const size_t index_j = tile_index_i_j.remainder * max_tile_j;
+ const size_t index_k = tile_index_ij_k.remainder * max_tile_k;
+ const size_t tile_j = min(max_tile_j, context->range_j - index_j);
+ const size_t tile_k = min(max_tile_k, context->range_k - index_k);
+ context->task(context->argument, uarch_index, index_i, index_j, index_k, tile_j, tile_k);
+}
+
+void pthreadpool_parallelize_3d_tile_2d_with_uarch(
+ pthreadpool_t threadpool,
+ pthreadpool_task_3d_tile_2d_with_id_t task,
+ void* argument,
+ uint32_t default_uarch_index,
+ uint32_t max_uarch_index,
+ size_t range_i,
+ size_t range_j,
+ size_t range_k,
+ size_t tile_j,
+ size_t tile_k,
+ uint32_t flags)
+{
+ if (threadpool == NULL || threadpool->threads_count <= 1 || (range_i <= 1 && range_j <= tile_j && range_k <= tile_k)) {
+ /* No thread pool used: execute task sequentially on the calling thread */
+
+ uint32_t uarch_index = default_uarch_index;
+ #if PTHREADPOOL_USE_CPUINFO
+ if (threadpool && threadpool->cpuinfo_is_initialized) {
+ uarch_index = cpuinfo_get_current_uarch_index();
+ if (uarch_index > max_uarch_index) {
+ uarch_index = default_uarch_index;
+ }
+ }
+ #endif
+
+ struct fpu_state saved_fpu_state = { 0 };
+ if (flags & PTHREADPOOL_FLAG_DISABLE_DENORMALS) {
+ saved_fpu_state = get_fpu_state();
+ disable_fpu_denormals();
+ }
+ for (size_t i = 0; i < range_i; i++) {
+ for (size_t j = 0; j < range_j; j += tile_j) {
+ for (size_t k = 0; k < range_k; k += tile_k) {
+ task(argument, uarch_index, i, j, k, min(range_j - j, tile_j), min(range_k - k, tile_k));
+ }
+ }
+ }
+ if (flags & PTHREADPOOL_FLAG_DISABLE_DENORMALS) {
+ set_fpu_state(saved_fpu_state);
+ }
+ } else {
+ /* Execute in parallel on the thread pool using linearized index */
+ const size_t tile_range_j = divide_round_up(range_j, tile_j);
+ const size_t tile_range_k = divide_round_up(range_k, tile_k);
+ const struct pthreadpool_1d_with_uarch_params params = {
+ .default_uarch_index = default_uarch_index,
+ .max_uarch_index = max_uarch_index,
+ };
+ struct compute_3d_tile_2d_with_uarch_context context = {
+ .task = task,
+ .argument = argument,
+ .tile_range_j = fxdiv_init_size_t(tile_range_j),
+ .tile_range_k = fxdiv_init_size_t(tile_range_k),
+ .range_j = range_j,
+ .range_k = range_k,
+ .tile_j = tile_j,
+ .tile_k = tile_k
+ };
+ pthreadpool_parallelize(
+ threadpool, &thread_parallelize_1d_with_uarch, &params, sizeof(params),
+ (void*) compute_3d_tile_2d_with_uarch, &context, range_i * tile_range_j * tile_range_k, flags);
+ }
+}
+
struct compute_4d_tile_2d_context {
pthreadpool_task_4d_tile_2d_t task;
void* argument;
@@ -1040,11 +1339,111 @@ void pthreadpool_parallelize_4d_tile_2d(
.tile_l = tile_l
};
pthreadpool_parallelize(
- threadpool, &thread_parallelize_1d,
+ threadpool, &thread_parallelize_1d, NULL, 0,
(void*) compute_4d_tile_2d, &context, range_i * range_j * tile_range_k * tile_range_l, flags);
}
}
+struct compute_4d_tile_2d_with_uarch_context {
+ pthreadpool_task_4d_tile_2d_with_id_t task;
+ void* argument;
+ struct fxdiv_divisor_size_t tile_range_kl;
+ struct fxdiv_divisor_size_t range_j;
+ struct fxdiv_divisor_size_t tile_range_l;
+ size_t range_k;
+ size_t range_l;
+ size_t tile_k;
+ size_t tile_l;
+};
+
+static void compute_4d_tile_2d_with_uarch(const struct compute_4d_tile_2d_with_uarch_context* context, uint32_t uarch_index, size_t linear_index) {
+ const struct fxdiv_divisor_size_t tile_range_kl = context->tile_range_kl;
+ const struct fxdiv_result_size_t tile_index_ij_kl = fxdiv_divide_size_t(linear_index, tile_range_kl);
+ const struct fxdiv_divisor_size_t range_j = context->range_j;
+ const struct fxdiv_result_size_t tile_index_i_j = fxdiv_divide_size_t(tile_index_ij_kl.quotient, range_j);
+ const struct fxdiv_divisor_size_t tile_range_l = context->tile_range_l;
+ const struct fxdiv_result_size_t tile_index_k_l = fxdiv_divide_size_t(tile_index_ij_kl.remainder, tile_range_l);
+ const size_t max_tile_k = context->tile_k;
+ const size_t max_tile_l = context->tile_l;
+ const size_t index_i = tile_index_i_j.quotient;
+ const size_t index_j = tile_index_i_j.remainder;
+ const size_t index_k = tile_index_k_l.quotient * max_tile_k;
+ const size_t index_l = tile_index_k_l.remainder * max_tile_l;
+ const size_t tile_k = min(max_tile_k, context->range_k - index_k);
+ const size_t tile_l = min(max_tile_l, context->range_l - index_l);
+ context->task(context->argument, uarch_index, index_i, index_j, index_k, index_l, tile_k, tile_l);
+}
+
+void pthreadpool_parallelize_4d_tile_2d_with_uarch(
+ pthreadpool_t threadpool,
+ pthreadpool_task_4d_tile_2d_with_id_t task,
+ void* argument,
+ uint32_t default_uarch_index,
+ uint32_t max_uarch_index,
+ size_t range_i,
+ size_t range_j,
+ size_t range_k,
+ size_t range_l,
+ size_t tile_k,
+ size_t tile_l,
+ uint32_t flags)
+{
+ if (threadpool == NULL || threadpool->threads_count <= 1 || ((range_i | range_j) <= 1 && range_k <= tile_k && range_l <= tile_l)) {
+ /* No thread pool used: execute task sequentially on the calling thread */
+
+ uint32_t uarch_index = default_uarch_index;
+ #if PTHREADPOOL_USE_CPUINFO
+ if (threadpool && threadpool->cpuinfo_is_initialized) {
+ uarch_index = cpuinfo_get_current_uarch_index();
+ if (uarch_index > max_uarch_index) {
+ uarch_index = default_uarch_index;
+ }
+ }
+ #endif
+
+ struct fpu_state saved_fpu_state = { 0 };
+ if (flags & PTHREADPOOL_FLAG_DISABLE_DENORMALS) {
+ saved_fpu_state = get_fpu_state();
+ disable_fpu_denormals();
+ }
+ for (size_t i = 0; i < range_i; i++) {
+ for (size_t j = 0; j < range_j; j++) {
+ for (size_t k = 0; k < range_k; k += tile_k) {
+ for (size_t l = 0; l < range_l; l += tile_l) {
+ task(argument, uarch_index, i, j, k, l,
+ min(range_k - k, tile_k), min(range_l - l, tile_l));
+ }
+ }
+ }
+ }
+ if (flags & PTHREADPOOL_FLAG_DISABLE_DENORMALS) {
+ set_fpu_state(saved_fpu_state);
+ }
+ } else {
+ /* Execute in parallel on the thread pool using linearized index */
+ const size_t tile_range_k = divide_round_up(range_k, tile_k);
+ const size_t tile_range_l = divide_round_up(range_l, tile_l);
+ const struct pthreadpool_1d_with_uarch_params params = {
+ .default_uarch_index = default_uarch_index,
+ .max_uarch_index = max_uarch_index,
+ };
+ struct compute_4d_tile_2d_with_uarch_context context = {
+ .task = task,
+ .argument = argument,
+ .tile_range_kl = fxdiv_init_size_t(tile_range_k * tile_range_l),
+ .range_j = fxdiv_init_size_t(range_j),
+ .tile_range_l = fxdiv_init_size_t(tile_range_l),
+ .range_k = range_k,
+ .range_l = range_l,
+ .tile_k = tile_k,
+ .tile_l = tile_l
+ };
+ pthreadpool_parallelize(
+ threadpool, &thread_parallelize_1d_with_uarch, &params, sizeof(params),
+ (void*) compute_4d_tile_2d_with_uarch, &context, range_i * range_j * tile_range_k * tile_range_l, flags);
+ }
+}
+
struct compute_5d_tile_2d_context {
pthreadpool_task_5d_tile_2d_t task;
void* argument;
@@ -1132,7 +1531,7 @@ void pthreadpool_parallelize_5d_tile_2d(
.tile_m = tile_m,
};
pthreadpool_parallelize(
- threadpool, &thread_parallelize_1d,
+ threadpool, &thread_parallelize_1d, NULL, 0,
(void*) compute_5d_tile_2d, &context, range_i * range_j * range_k * tile_range_l * tile_range_m, flags);
}
}
@@ -1232,7 +1631,7 @@ void pthreadpool_parallelize_6d_tile_2d(
.tile_n = tile_n,
};
pthreadpool_parallelize(
- threadpool, &thread_parallelize_1d,
+ threadpool, &thread_parallelize_1d, NULL, 0,
(void*) compute_6d_tile_2d, &context, range_i * range_j * range_k * range_l * tile_range_m * tile_range_n, flags);
}
}
@@ -1289,6 +1688,11 @@ void pthreadpool_destroy(struct pthreadpool* threadpool) {
pthread_cond_destroy(&threadpool->command_condvar);
#endif
}
+ #if PTHREADPOOL_USE_CPUINFO
+ if (threadpool->cpuinfo_is_initialized) {
+ cpuinfo_deinitialize();
+ }
+ #endif
#ifdef _WIN32
_aligned_free(threadpool);
#else
diff --git a/src/threadpool-shim.c b/src/threadpool-shim.c
index c8ef51d..b5670ea 100644
--- a/src/threadpool-shim.c
+++ b/src/threadpool-shim.c
@@ -28,6 +28,20 @@ void pthreadpool_parallelize_1d(
}
}
+void pthreadpool_parallelize_1d_with_uarch(
+ pthreadpool_t threadpool,
+ pthreadpool_task_1d_with_id_t task,
+ void* argument,
+ uint32_t default_uarch_index,
+ uint32_t max_uarch_index,
+ size_t range,
+ uint32_t flags)
+{
+ for (size_t i = 0; i < range; i++) {
+ task(argument, default_uarch_index, i);
+ }
+}
+
void pthreadpool_parallelize_1d_tile_1d(
pthreadpool_t threadpool,
pthreadpool_task_1d_tile_1d_t task,
@@ -89,6 +103,26 @@ void pthreadpool_parallelize_2d_tile_2d(
}
}
+void pthreadpool_parallelize_2d_tile_2d_with_uarch(
+ pthreadpool_t threadpool,
+ pthreadpool_task_2d_tile_2d_with_id_t task,
+ void* argument,
+ uint32_t default_uarch_index,
+ uint32_t max_uarch_index,
+ size_t range_i,
+ size_t range_j,
+ size_t tile_i,
+ size_t tile_j,
+ uint32_t flags)
+{
+ for (size_t i = 0; i < range_i; i += tile_i) {
+ for (size_t j = 0; j < range_j; j += tile_j) {
+ task(argument, default_uarch_index, i, j,
+ min(range_i - i, tile_i), min(range_j - j, tile_j));
+ }
+ }
+}
+
void pthreadpool_parallelize_3d_tile_2d(
pthreadpool_t threadpool,
pthreadpool_task_3d_tile_2d_t task,
@@ -110,6 +144,29 @@ void pthreadpool_parallelize_3d_tile_2d(
}
}
+void pthreadpool_parallelize_3d_tile_2d_with_uarch(
+ pthreadpool_t threadpool,
+ pthreadpool_task_3d_tile_2d_with_id_t task,
+ void* argument,
+ uint32_t default_uarch_index,
+ uint32_t max_uarch_index,
+ size_t range_i,
+ size_t range_j,
+ size_t range_k,
+ size_t tile_j,
+ size_t tile_k,
+ uint32_t flags)
+{
+ for (size_t i = 0; i < range_i; i++) {
+ for (size_t j = 0; j < range_j; j += tile_j) {
+ for (size_t k = 0; k < range_k; k += tile_k) {
+ task(argument, default_uarch_index, i, j, k,
+ min(range_j - j, tile_j), min(range_k - k, tile_k));
+ }
+ }
+ }
+}
+
void pthreadpool_parallelize_4d_tile_2d(
pthreadpool_t threadpool,
pthreadpool_task_4d_tile_2d_t task,
@@ -134,6 +191,32 @@ void pthreadpool_parallelize_4d_tile_2d(
}
}
+void pthreadpool_parallelize_4d_tile_2d_with_uarch(
+ pthreadpool_t threadpool,
+ pthreadpool_task_4d_tile_2d_with_id_t task,
+ void* argument,
+ uint32_t default_uarch_index,
+ uint32_t max_uarch_index,
+ size_t range_i,
+ size_t range_j,
+ size_t range_k,
+ size_t range_l,
+ size_t tile_k,
+ size_t tile_l,
+ uint32_t flags)
+{
+ for (size_t i = 0; i < range_i; i++) {
+ for (size_t j = 0; j < range_j; j++) {
+ for (size_t k = 0; k < range_k; k += tile_k) {
+ for (size_t l = 0; l < range_l; l += tile_l) {
+ task(argument, default_uarch_index, i, j, k, l,
+ min(range_k - k, tile_k), min(range_l - l, tile_l));
+ }
+ }
+ }
+ }
+}
+
void pthreadpool_parallelize_5d_tile_2d(
pthreadpool_t threadpool,
pthreadpool_task_5d_tile_2d_t task,