Skip to content

Commit ba77a54

Browse files
committed
fix_prctl_macos
1 parent c990f3d commit ba77a54

File tree

8 files changed

+36
-35
lines changed

8 files changed

+36
-35
lines changed

ggml/src/ggml-cpu/arch/arm/quants.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ void ggml_vec_dot_q4_0_q8_0(int n, float * GGML_RESTRICT s, size_t bs, const voi
231231
int ib = 0;
232232
float sumf = 0;
233233

234-
#if defined(__ARM_FEATURE_SVE)
234+
#if defined(__ARM_FEATURE_SVE) && defined(__linux__)
235235
svfloat32_t sumv0 = svdup_n_f32(0.0f);
236236
svfloat32_t sumv1 = svdup_n_f32(0.0f);
237237

@@ -962,7 +962,7 @@ void ggml_vec_dot_q8_0_q8_0(int n, float * GGML_RESTRICT s, size_t bs, const voi
962962
int ib = 0;
963963
float sumf = 0;
964964

965-
#if defined(__ARM_FEATURE_SVE)
965+
#if defined(__ARM_FEATURE_SVE) && defined(__linux__)
966966
svfloat32_t sumv0 = svdup_n_f32(0.0f);
967967
svfloat32_t sumv1 = svdup_n_f32(0.0f);
968968

@@ -1427,7 +1427,7 @@ void ggml_vec_dot_q2_K_q8_K(int n, float * GGML_RESTRICT s, size_t bs, const voi
14271427

14281428
const int nb = n / QK_K;
14291429

1430-
#ifdef __ARM_FEATURE_SVE
1430+
#if defined(__ARM_FEATURE_SVE) && defined(__linux__)
14311431
const int vector_length = svcntb()*8;
14321432
const svuint8_t m3s = svdup_n_u8(0x3);
14331433
const svuint32_t m4s = svdup_n_u32(0xF);
@@ -1764,7 +1764,7 @@ void ggml_vec_dot_q3_K_q8_K(int n, float * GGML_RESTRICT s, size_t bs, const voi
17641764

17651765
const int nb = n / QK_K;
17661766

1767-
#if defined(__ARM_FEATURE_SVE)
1767+
#if defined(__ARM_FEATURE_SVE) && defined(__linux__)
17681768

17691769
uint32_t aux[3];
17701770
uint32_t utmp[4];
@@ -2207,7 +2207,7 @@ void ggml_vec_dot_q4_K_q8_K(int n, float * GGML_RESTRICT s, size_t bs, const voi
22072207
}
22082208
#endif
22092209

2210-
#ifdef __ARM_FEATURE_SVE
2210+
#if defined(__ARM_FEATURE_SVE) && defined(__linux__)
22112211
float sumf = 0;
22122212
for (int i = 0; i < nb; ++i) {
22132213

@@ -2594,7 +2594,7 @@ void ggml_vec_dot_q6_K_q8_K(int n, float * GGML_RESTRICT s, size_t bs, const voi
25942594
// adjust bias, apply superblock scale
25952595
{
25962596
int32_t bias[4];
2597-
#ifdef __ARM_FEATURE_SVE
2597+
#if defined(__ARM_FEATURE_SVE) && defined(__linux__)
25982598
const svbool_t pg16_8 = svptrue_pat_b16(SV_VL8);
25992599
const svbool_t pg8_8 = svptrue_pat_b8(SV_VL8);
26002600
const svint16_t y0_q8sums_0 = svld1_s16(pg16_8, y0->bsums);
@@ -2671,7 +2671,7 @@ void ggml_vec_dot_q6_K_q8_K(int n, float * GGML_RESTRICT s, size_t bs, const voi
26712671
}
26722672
#endif
26732673

2674-
#ifdef __ARM_FEATURE_SVE
2674+
#if defined(__ARM_FEATURE_SVE) && defined(__linux__)
26752675
const int vector_length = ggml_cpu_get_sve_cnt()*8;
26762676
float sum = 0;
26772677
svuint8_t m4b = svdup_n_u8(0xf);

ggml/src/ggml-cpu/arch/arm/repack.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ void ggml_gemv_q4_0_8x8_q8_0(int n, float * GGML_RESTRICT s, size_t bs, const vo
332332
UNUSED(blocklen);
333333

334334
#if ! ((defined(_MSC_VER)) && ! defined(__clang__)) && defined(__aarch64__)
335-
#if defined(__ARM_FEATURE_SVE)
335+
#if defined(__ARM_FEATURE_SVE) && defined(__linux__)
336336
if (ggml_cpu_get_sve_cnt() == QK8_0) {
337337
const void * b_ptr = vx;
338338
const void * a_ptr = vy;
@@ -398,7 +398,7 @@ void ggml_gemv_q4_0_8x8_q8_0(int n, float * GGML_RESTRICT s, size_t bs, const vo
398398
);
399399
return;
400400
}
401-
#endif // #if defined(__ARM_FEATURE_SVE)
401+
#endif // #if defined(__ARM_FEATURE_SVE) && defined(__linux__)
402402

403403
#endif // #if ! ((defined(_MSC_VER)) && ! defined(__clang__)) && defined(__aarch64__)
404404
ggml_gemv_q4_0_8x8_q8_0_generic(n, s, bs, vx, vy, nr, nc);
@@ -1397,7 +1397,7 @@ void ggml_gemm_q4_0_8x8_q8_0(int n, float * GGML_RESTRICT s, size_t bs, const vo
13971397
UNUSED(blocklen);
13981398

13991399
#if ! ((defined(_MSC_VER)) && ! defined(__clang__)) && defined(__aarch64__)
1400-
#if defined(__ARM_FEATURE_SVE) && defined(__ARM_FEATURE_MATMUL_INT8)
1400+
#if defined(__ARM_FEATURE_SVE) && defined(__ARM_FEATURE_MATMUL_INT8) && defined(__linux__)
14011401
if (ggml_cpu_get_sve_cnt() == QK8_0) {
14021402
const void * b_ptr = vx;
14031403
const void * a_ptr = vy;
@@ -1808,7 +1808,7 @@ void ggml_gemm_q4_0_8x8_q8_0(int n, float * GGML_RESTRICT s, size_t bs, const vo
18081808
);
18091809
return;
18101810
}
1811-
#endif // #if defined(__ARM_FEATURE_SVE) && defined(__ARM_FEATURE_MATMUL_INT8)
1811+
#endif // #if defined(__ARM_FEATURE_SVE) && defined(__linux__) && defined(__ARM_FEATURE_MATMUL_INT8)
18121812

18131813
#endif // #if ! ((defined(_MSC_VER)) && ! defined(__clang__)) && defined(__aarch64__)
18141814
ggml_gemm_q4_0_8x8_q8_0_generic(n, s, bs, vx, vy, nr, nc);

ggml/src/ggml-cpu/ggml-cpu-impl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ struct ggml_compute_params {
6868
#endif // __VXE2__
6969
#endif // __s390x__ && __VEC__
7070

71-
#if defined(__ARM_FEATURE_SVE)
71+
#if defined(__ARM_FEATURE_SVE) && defined(__linux__)
7272
#include <sys/prctl.h>
7373
#endif
7474

ggml/src/ggml-cpu/ggml-cpu.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
#include <omp.h>
4343
#endif
4444

45-
#if defined(__ARM_FEATURE_SVE) || defined(__ARM_FEATURE_MATMUL_INT8)
45+
#if (defined(__ARM_FEATURE_SVE) && defined(__linux__)) || defined(__ARM_FEATURE_MATMUL_INT8)
4646
#undef GGML_USE_LLAMAFILE
4747
#endif
4848

@@ -3477,7 +3477,7 @@ int ggml_cpu_has_dotprod(void) {
34773477
}
34783478

34793479
int ggml_cpu_has_sve(void) {
3480-
#if defined(__ARM_ARCH) && defined(__ARM_FEATURE_SVE)
3480+
#if defined(__ARM_ARCH) && defined(__ARM_FEATURE_SVE) && defined(__linux__)
34813481
return 1;
34823482
#else
34833483
return 0;
@@ -3493,7 +3493,7 @@ int ggml_cpu_has_matmul_int8(void) {
34933493
}
34943494

34953495
int ggml_cpu_get_sve_cnt(void) {
3496-
#if defined(__ARM_ARCH) && defined(__ARM_FEATURE_SVE)
3496+
#if defined(__ARM_ARCH) && defined(__ARM_FEATURE_SVE) && defined(__linux__)
34973497
return ggml_arm_arch_features.sve_cnt;
34983498
#else
34993499
return 0;

ggml/src/ggml-cpu/ops.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9417,7 +9417,8 @@ static void ggml_compute_forward_ssm_scan_f32(
94179417
const float x_dt = x[ii] * dt_soft_plus;
94189418
float sumf = 0.0f;
94199419
#if defined(GGML_SIMD)
9420-
#if defined(__ARM_FEATURE_SVE)
9420+
#if defined(__ARM_FEATURE_SVE) && defined(__linux__)
9421+
94219422
const int ggml_f32_epr = svcntw();
94229423
const int ggml_f32_step = 1 * ggml_f32_epr;
94239424

@@ -9511,7 +9512,7 @@ static void ggml_compute_forward_ssm_scan_f32(
95119512
for (int i1 = 0; i1 < nr; ++i1) {
95129513
const int ii = i1 + h*nr;
95139514
const float x_dt = x[ii] * dt_soft_plus;
9514-
#if defined(__ARM_FEATURE_SVE)
9515+
#if defined(__ARM_FEATURE_SVE) && defined(__linux__)
95159516
svfloat32_t vx_dt = GGML_F32_VEC_SET1(x_dt);
95169517
svfloat32_t vdt_soft_plus = GGML_F32_VEC_SET1(dt_soft_plus);
95179518
svfloat32_t r1_vector = GGML_F32_VEC_ZERO;
@@ -10001,7 +10002,7 @@ static void ggml_compute_forward_rwkv_wkv6_f32(
1000110002
#define GGML_F32X_MUL GGML_F32x16_MUL
1000210003
#define GGML_F32X_FMA GGML_F32x16_FMA
1000310004
#define WKV_VECTOR_SIZE 16
10004-
#elif defined(__ARM_FEATURE_SVE) && defined(__aarch64__)
10005+
#elif defined(__ARM_FEATURE_SVE) && defined(__aarch64__) && defined(__linux__)
1000510006
#define GGML_F32X GGML_F32xt
1000610007
#define GGML_F32X_SET1 GGML_F32xt_SET1
1000710008
#define GGML_F32X_LOAD GGML_F32xt_LOAD
@@ -10021,7 +10022,7 @@ static void ggml_compute_forward_rwkv_wkv6_f32(
1002110022

1002210023
#ifdef WKV_VECTOR_SIZE
1002310024
int wkv_vector_size;
10024-
#if defined(__ARM_FEATURE_SVE)
10025+
#if defined(__ARM_FEATURE_SVE) && defined(__linux__) && defined(__linux__)
1002510026
wkv_vector_size = svcntw();
1002610027
#else
1002710028
wkv_vector_size = WKV_VECTOR_SIZE;
@@ -10217,7 +10218,7 @@ static void ggml_compute_forward_gla_f32(
1021710218
#define GGML_F32X_MUL GGML_F32x16_MUL
1021810219
#define GGML_F32X_FMA GGML_F32x16_FMA
1021910220
#define GLA_VECTOR_SIZE 16
10220-
#elif defined(__ARM_FEATURE_SVE) && defined(__aarch64__)
10221+
#elif defined(__ARM_FEATURE_SVE) && defined(__aarch64__) && defined(__linux__)
1022110222
#define GGML_F32X GGML_F32xt
1022210223
#define GGML_F32X_SET1 GGML_F32xt_SET1
1022310224
#define GGML_F32X_LOAD GGML_F32xt_LOAD
@@ -10237,7 +10238,7 @@ static void ggml_compute_forward_gla_f32(
1023710238

1023810239
#ifdef GLA_VECTOR_SIZE
1023910240
int gla_vector_size;
10240-
#if defined(__ARM_FEATURE_SVE)
10241+
#if defined(__ARM_FEATURE_SVE) && defined(__linux__)
1024110242
gla_vector_size = svcntw();
1024210243
#else
1024310244
gla_vector_size = GLA_VECTOR_SIZE;
@@ -10402,7 +10403,7 @@ static void ggml_compute_forward_rwkv_wkv7_f32(
1040210403
int64_t h_stride_2d = head_size * head_size;
1040310404

1040410405
#if defined(GGML_SIMD)
10405-
#if defined(__ARM_FEATURE_SVE) || defined(__riscv_v_intrinsic)
10406+
#if defined(__ARM_FEATURE_SVE) && defined(__linux__) || defined(__riscv_v_intrinsic)
1040610407
// scalar Route to scalar implementation //TODO: Write SVE code and RVV code
1040710408
for (int64_t t = 0; t < T; t++) {
1040810409
int64_t t_offset = t * t_stride;

ggml/src/ggml-cpu/simd-mappings.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ inline static float ggml_lookup_fp16_to_fp32(ggml_fp16_t f) {
149149
// number of elements to fit in a single register
150150
//
151151

152-
#if defined(__ARM_FEATURE_SVE) && defined(__ARM_FEATURE_FMA)
152+
#if defined(__ARM_FEATURE_SVE) && defined(__ARM_FEATURE_FMA) && defined(__linux__)
153153

154154
#define GGML_SIMD
155155

ggml/src/ggml-cpu/vec.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ void ggml_vec_dot_f32(int n, float * GGML_RESTRICT s, size_t bs, const float * G
1818
#if defined(GGML_SIMD)
1919
float sumf = 0.0f;
2020

21-
#if defined(__ARM_FEATURE_SVE)
21+
#if defined(__ARM_FEATURE_SVE) && defined(__linux__)
2222
const int sve_register_length = ggml_cpu_get_sve_cnt() * 8;
2323
const int ggml_f32_epr = sve_register_length / 32;//8;//svcntw(); // SVE128:4, SVE256:8, SVE512:16
2424
const int ggml_f32_step = 8 * ggml_f32_epr; // choose 8 SVE registers
@@ -215,7 +215,7 @@ void ggml_vec_dot_f16(int n, float * GGML_RESTRICT s, size_t bs, ggml_fp16_t * G
215215

216216

217217
#if defined(GGML_SIMD)
218-
#if defined(__ARM_FEATURE_SVE)
218+
#if defined(__ARM_FEATURE_SVE) && defined(__linux__)
219219
const int sve_register_length = svcntb() * 8; //get vector length
220220
const int ggml_f16_epr = sve_register_length / 16; // running when 16
221221
const int ggml_f16_step = 8 * ggml_f16_epr; // choose 8 SVE registers
@@ -350,7 +350,7 @@ void ggml_vec_silu_f32(const int n, float * y, const float * x) {
350350
for (; i + 3 < n; i += 4) {
351351
_mm_storeu_ps(y + i, ggml_v_silu(_mm_loadu_ps(x + i)));
352352
}
353-
#elif defined(__ARM_FEATURE_SVE) && defined(__aarch64__)
353+
#elif defined(__ARM_FEATURE_SVE) && defined(__aarch64__) && defined(__linux__)
354354
const int vlen = svcntw();
355355
for (; i < n; i += vlen) {
356356
const svbool_t pg = svwhilelt_b32_s32(i, n);
@@ -380,7 +380,7 @@ void ggml_vec_swiglu_f32(const int n, float * y, const float * x, const float *
380380
for (; i + 3 < n; i += 4) {
381381
_mm_storeu_ps(y + i, _mm_mul_ps(ggml_v_silu(_mm_loadu_ps(x + i)), _mm_loadu_ps(g + i)));
382382
}
383-
#elif defined(__ARM_FEATURE_SVE) && defined(__aarch64__)
383+
#elif defined(__ARM_FEATURE_SVE) && defined(__aarch64__) && defined(__linux__)
384384
const int vlen = svcntw();
385385
for (; i < n; i += vlen) {
386386
const svbool_t pg = svwhilelt_b32_s32(i, n);
@@ -441,7 +441,7 @@ ggml_float ggml_vec_soft_max_f32(const int n, float * y, const float * x, float
441441
#endif
442442
sum += (ggml_float)_mm_cvtss_f32(val);
443443
}
444-
#elif defined(__ARM_FEATURE_SVE) && defined(__aarch64__)
444+
#elif defined(__ARM_FEATURE_SVE) && defined(__aarch64__) && defined(__linux__)
445445
const int vlen = svcntw();
446446
for (; i < n; i += vlen) {
447447
const svbool_t pg = svwhilelt_b32_s32(i, n);

ggml/src/ggml-cpu/vec.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ inline static void ggml_vec_dot_f16_unroll(const int n, const int xs, float * GG
119119
}
120120

121121
#if defined(GGML_SIMD)
122-
#if defined(__ARM_FEATURE_SVE)
122+
#if defined(__ARM_FEATURE_SVE) && defined(__linux__)
123123

124124
const int sve_register_length = svcntb() * 8;
125125
const int ggml_f16_epr = sve_register_length / 16; // running when 16
@@ -277,7 +277,7 @@ inline static void ggml_vec_dot_f16_unroll(const int n, const int xs, float * GG
277277

278278
inline static void ggml_vec_mad_f32(const int n, float * GGML_RESTRICT y, const float * GGML_RESTRICT x, const float v) {
279279
#if defined(GGML_SIMD)
280-
#if defined(__ARM_FEATURE_SVE)
280+
#if defined(__ARM_FEATURE_SVE) && defined(__linux__)
281281

282282
const int sve_register_length = ggml_cpu_get_sve_cnt() * 8;
283283
const int ggml_f32_epr = sve_register_length / 32;//8;//svcntw(); // SVE128:4, SVE256:8, SVE512:16
@@ -397,7 +397,7 @@ inline static void ggml_vec_mad_f32(const int n, float * GGML_RESTRICT y, const
397397

398398
inline static void ggml_vec_mad_f16(const int n, ggml_fp16_t * GGML_RESTRICT y, const ggml_fp16_t * GGML_RESTRICT x, const float v) {
399399
#if defined(GGML_SIMD)
400-
#if defined(__ARM_FEATURE_SVE)
400+
#if defined(__ARM_FEATURE_SVE) && defined(__linux__)
401401
const int sve_register_length = svcntb() * 8;
402402
const int ggml_f16_epr = sve_register_length / 16;
403403
const int ggml_f16_step = 8 * ggml_f16_epr;
@@ -523,7 +523,7 @@ inline static void ggml_vec_mad_f32_unroll(const int n, const int xs, const int
523523
}
524524

525525
#if defined(GGML_SIMD)
526-
#if defined(__ARM_FEATURE_SVE)
526+
#if defined(__ARM_FEATURE_SVE) && defined(__linux__)
527527
// scalar Route to scalar implementation //TODO: Write SVE code
528528
for (int k = 0; k < GGML_VEC_MAD_UNROLL; ++k) {
529529
for (int i = 0; i < n; ++i) {
@@ -698,7 +698,7 @@ inline static void ggml_vec_scale_f32(const int n, float * y, const float v) {
698698

699699
inline static void ggml_vec_scale_f16(const int n, ggml_fp16_t * y, const float v) {
700700
#if defined(GGML_SIMD)
701-
#if defined(__ARM_FEATURE_SVE)
701+
#if defined(__ARM_FEATURE_SVE) && defined(__linux__)
702702
const int sve_register_length = svcntb() * 8;
703703
const int ggml_f16_epr = sve_register_length / 16;
704704
const int ggml_f16_step = 2 * ggml_f16_epr;
@@ -968,7 +968,7 @@ inline static ggml_fp16_t ggml_silu_f16(ggml_fp16_t x) {
968968

969969
/* Below function was borrowed from the GitHub repository:
970970
https://github.com/openvinotoolkit/openvino/blob/master/src/plugins/intel_cpu/src/nodes/kernels/scaled_attn/common.hpp */
971-
#if defined(__ARM_FEATURE_SVE) && defined(__aarch64__)
971+
#if defined(__ARM_FEATURE_SVE) && defined(__aarch64__) && defined(__linux__)
972972
inline static svfloat32_t exp_ps_sve(svbool_t pg, svfloat32_t src) {
973973
// Constants
974974
const svfloat32_t log2_e = svdup_n_f32(1.4426950409f);
@@ -1002,7 +1002,7 @@ inline static ggml_fp16_t ggml_silu_f16(ggml_fp16_t x) {
10021002
}
10031003
#endif
10041004

1005-
#if defined(__ARM_FEATURE_SVE) && defined(__aarch64__)
1005+
#if defined(__ARM_FEATURE_SVE) && defined(__aarch64__) && defined(__linux__)
10061006

10071007
inline static svfloat32_t ggml_v_expf(svbool_t pg, svfloat32_t x) {
10081008
const svfloat32_t r = svdup_n_f32_x(pg, 0x1.8p23f);

0 commit comments

Comments
 (0)