Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions common_thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,27 @@ static __inline int sme_level3_threads(int nthreads) {
#define sme_level3_threads(nthreads) (nthreads)
#endif

#if defined(USE_OPENMP) && defined(ARCH_ARM64) && defined(OS_DARWIN) && (defined(VORTEXM4) || defined(DYNAMIC_ARCH))
#ifdef DYNAMIC_ARCH
extern char *gotoblas_corename(void);
#endif
/* Apple M4 with OpenMP: libomp parks idle threads on Apple Silicon (KMP_BLOCKTIME
defaults to 0 there), and every threaded call wakes the rest of the OpenMP team,
about 3 us per thread on average. A unit-stride level-1 call that reads and writes
fewer than about 384 KB per thread that would be woken is faster on one thread;
bytes is the memory the call reads and writes. Calls with other strides run a
scalar loop and keep the team. Measured on M4 Pro only. */
static __inline int apple_omp_level1_threads(size_t bytes, int unit_stride, int nthreads) {
if (nthreads <= 1 || !unit_stride) return nthreads;
#ifdef DYNAMIC_ARCH
if (strcmp(gotoblas_corename(), "vortexm4") != 0) return nthreads;
#endif
return bytes < (size_t)(nthreads - 1) * 384 * 1024 ? 1 : nthreads;
}
#else
#define apple_omp_level1_threads(bytes, unit_stride, nthreads) (nthreads)
#endif

static __inline int num_cpu_avail(int level) {

#ifdef USE_OPENMP
Expand Down
22 changes: 1 addition & 21 deletions interface/axpy.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,23 +47,6 @@
#define MULTI_THREAD_MINIMAL 10000
#endif

#if defined(SMP) && defined(USE_OPENMP) && defined(ARCH_ARM64) && defined(OS_DARWIN) && \
(defined(DYNAMIC_ARCH) || defined(VORTEXM4))
#ifdef DYNAMIC_ARCH
extern char *gotoblas_corename(void);
#endif
/* Apple M4, OpenMP: libomp parks idle threads on Apple Silicon (KMP_BLOCKTIME
defaults to 0 there), and every call wakes the rest of the OpenMP team, about
3 us per thread on average. Stay on one thread until the vector takes longer
than that, about 128 KB per woken thread; measured on M4 Pro only. */
static int apple_axpy_threads(BLASLONG n, int nthreads) {
#ifdef DYNAMIC_ARCH
if (strcmp(gotoblas_corename(), "vortexm4") != 0) return nthreads;
#endif
return (size_t)n * sizeof(FLOAT) < (size_t)(nthreads - 1) * 128 * 1024 ? 1 : nthreads;
}
#endif

OPENBLAS_EXPORT
#ifndef CBLAS

Expand Down Expand Up @@ -117,10 +100,7 @@ void CNAME(blasint n, FLOAT alpha, FLOAT *x, blasint incx, FLOAT *y, blasint inc
else
nthreads = num_cpu_avail(1);

#if defined(USE_OPENMP) && defined(ARCH_ARM64) && defined(OS_DARWIN) && \
(defined(DYNAMIC_ARCH) || defined(VORTEXM4))
if (nthreads > 1) nthreads = apple_axpy_threads(n, nthreads);
#endif
nthreads = apple_omp_level1_threads(3 * (size_t)n * sizeof(FLOAT), incx == 1 && incy == 1, nthreads);

if (nthreads == 1) {
#endif
Expand Down
1 change: 1 addition & 0 deletions interface/zaxpy.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ void CNAME(blasint n, FLOAT *ALPHA, FLOAT *x, blasint incx, FLOAT *y, blasint in
nthreads = 1;
else
nthreads = num_cpu_avail(1);
nthreads = apple_omp_level1_threads(3 * (size_t)n * COMPSIZE * sizeof(FLOAT), incx == 1 && incy == 1, nthreads);

if (nthreads == 1) {
#endif
Expand Down
1 change: 1 addition & 0 deletions kernel/arm64/casum_thunderx2t99.c
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ FLOAT CNAME(BLASLONG n, FLOAT *x, BLASLONG inc_x)
nthreads = 1;
else
nthreads = num_cpu_avail(1);
nthreads = apple_omp_level1_threads((size_t)n * COMPSIZE * sizeof(FLOAT), inc_x == 1, nthreads);

if (nthreads == 1) {
asum = casum_compute(n, x, inc_x);
Expand Down
1 change: 1 addition & 0 deletions kernel/arm64/copy_thunderx2t99.c
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ int CNAME(BLASLONG n, FLOAT *x, BLASLONG inc_x, FLOAT *y, BLASLONG inc_y)
nthreads = 1;
else
nthreads = num_cpu_avail(1);
nthreads = apple_omp_level1_threads(2 * (size_t)n * COMPSIZE * sizeof(FLOAT), inc_x == 1 && inc_y == 1, nthreads);

if (nthreads == 1) {
do_copy(n, x, inc_x, y, inc_y);
Expand Down
1 change: 1 addition & 0 deletions kernel/arm64/csum_thunderx2t99.c
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ FLOAT CNAME(BLASLONG n, FLOAT *x, BLASLONG inc_x)
nthreads = 1;
else
nthreads = num_cpu_avail(1);
nthreads = apple_omp_level1_threads((size_t)n * COMPSIZE * sizeof(FLOAT), inc_x == 1, nthreads);

if (nthreads == 1) {
asum = casum_compute(n, x, inc_x);
Expand Down
1 change: 1 addition & 0 deletions kernel/arm64/dasum_thunderx2t99.c
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ FLOAT CNAME(BLASLONG n, FLOAT *x, BLASLONG inc_x)
nthreads = 1;
else
nthreads = num_cpu_avail(1);
nthreads = apple_omp_level1_threads((size_t)n * COMPSIZE * sizeof(FLOAT), inc_x == 1, nthreads);

if (nthreads == 1) {
asum = dasum_compute(n, x, inc_x);
Expand Down
1 change: 1 addition & 0 deletions kernel/arm64/dot.c
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ RETURN_TYPE CNAME(BLASLONG n, FLOAT *x, BLASLONG inc_x, FLOAT *y, BLASLONG inc_y
nthreads = 1;
else
nthreads = get_dot_optimal_nthreads(n);
nthreads = apple_omp_level1_threads(2 * (size_t)n * COMPSIZE * sizeof(FLOAT), inc_x == 1 && inc_y == 1, nthreads);

if (nthreads == 1) {
dot = dot_compute(n, x, inc_x, y, inc_y);
Expand Down
1 change: 1 addition & 0 deletions kernel/arm64/dsum_thunderx2t99.c
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ FLOAT CNAME(BLASLONG n, FLOAT *x, BLASLONG inc_x)
nthreads = 1;
else
nthreads = num_cpu_avail(1);
nthreads = apple_omp_level1_threads((size_t)n * COMPSIZE * sizeof(FLOAT), inc_x == 1, nthreads);

if (nthreads == 1) {
dsum = dsum_compute(n, x, inc_x);
Expand Down
1 change: 1 addition & 0 deletions kernel/arm64/iamax_thunderx2t99.c
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,7 @@ BLASLONG CNAME(BLASLONG n, FLOAT *x, BLASLONG inc_x)
nthreads = 1;
else
nthreads = num_cpu_avail(1);
nthreads = apple_omp_level1_threads((size_t)n * COMPSIZE * sizeof(FLOAT), inc_x == 1, nthreads);

if (nthreads == 1) {
max_index = iamax_compute(n, x, inc_x);
Expand Down
1 change: 1 addition & 0 deletions kernel/arm64/izamax_thunderx2t99.c
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@ BLASLONG CNAME(BLASLONG n, FLOAT *x, BLASLONG inc_x)
nthreads = 1;
else
nthreads = num_cpu_avail(1);
nthreads = apple_omp_level1_threads((size_t)n * COMPSIZE * sizeof(FLOAT), inc_x == 1, nthreads);

if (nthreads == 1) {
max_index = izamax_compute(n, x, inc_x);
Expand Down
1 change: 1 addition & 0 deletions kernel/arm64/sasum_thunderx2t99.c
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ FLOAT CNAME(BLASLONG n, FLOAT *x, BLASLONG inc_x)
nthreads = 1;
else
nthreads = num_cpu_avail(1);
nthreads = apple_omp_level1_threads((size_t)n * COMPSIZE * sizeof(FLOAT), inc_x == 1, nthreads);

if (nthreads == 1) {
asum = sasum_compute(n, x, inc_x);
Expand Down
1 change: 1 addition & 0 deletions kernel/arm64/ssum_thunderx2t99.c
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ FLOAT CNAME(BLASLONG n, FLOAT *x, BLASLONG inc_x)
nthreads = 1;
else
nthreads = num_cpu_avail(1);
nthreads = apple_omp_level1_threads((size_t)n * COMPSIZE * sizeof(FLOAT), inc_x == 1, nthreads);

if (nthreads == 1) {
ssum = ssum_compute(n, x, inc_x);
Expand Down
1 change: 1 addition & 0 deletions kernel/arm64/zasum_thunderx2t99.c
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ FLOAT CNAME(BLASLONG n, FLOAT *x, BLASLONG inc_x)
nthreads = 1;
else
nthreads = num_cpu_avail(1);
nthreads = apple_omp_level1_threads((size_t)n * COMPSIZE * sizeof(FLOAT), inc_x == 1, nthreads);

if (nthreads == 1) {
asum = zasum_compute(n, x, inc_x);
Expand Down
1 change: 1 addition & 0 deletions kernel/arm64/zdot_thunderx2t99.c
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,7 @@ OPENBLAS_COMPLEX_FLOAT CNAME(BLASLONG n, FLOAT *x, BLASLONG inc_x, FLOAT *y, BLA
nthreads = 1;
else
nthreads = num_cpu_avail(1);
nthreads = apple_omp_level1_threads(2 * (size_t)n * COMPSIZE * sizeof(FLOAT), inc_x == 1 && inc_y == 1, nthreads);

if (nthreads == 1) {
zdot_compute(n, x, inc_x, y, inc_y, &zdot);
Expand Down
1 change: 1 addition & 0 deletions kernel/arm64/zsum_thunderx2t99.c
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ FLOAT CNAME(BLASLONG n, FLOAT *x, BLASLONG inc_x)
nthreads = 1;
else
nthreads = num_cpu_avail(1);
nthreads = apple_omp_level1_threads((size_t)n * COMPSIZE * sizeof(FLOAT), inc_x == 1, nthreads);

if (nthreads == 1) {
asum = zasum_compute(n, x, inc_x);
Expand Down
Loading