char-fork/llama.cpp
git clone https://git.t4t.associates/char-fork/llama.cpp
1f368f354
char/aliceai-t5-moe
1#pragma once 2 3#if defined(__aarch64__ )|| defined(_M_ARM64 ) 4 5#if defined(__linux__ ) 6#include <sys/auxv.h> 7#include <sys/prctl.h> 8 9#if !defined(HWCAP2_SVE2 ) 10#define HWCAP2_SVE2 (1ULL << 1) 11#endif 12 13#if !defined(HWCAP_FPHP ) 14#define HWCAP_FPHP (1 << 9) 15#endif 16 17#if !defined(HWCAP_ASIMDHP ) 18#define HWCAP_ASIMDHP (1 << 10) 19#endif 20 21#if !defined(HWCAP2_I8MM ) 22#define HWCAP2_I8MM (1ULL << 13) 23#endif 24 25#if !defined(HWCAP_ASIMDDP ) 26#define HWCAP_ASIMDDP (1 << 20) 27#endif 28 29#if !defined(HWCAP_SVE ) 30#define HWCAP_SVE (1 << 22) 31#endif 32 33#if !defined(HWCAP2_SME ) 34#define HWCAP2_SME (1ULL << 23) 35#endif 36 37#if !defined(HWCAP2_SME2 ) 38#define HWCAP2_SME2 (1ULL << 37) 39#endif 40 41#if !defined(PR_SVE_GET_VL ) 42#define PR_SVE_GET_VL 51 43#endif 44 45#if !defined(PR_SVE_VL_LEN_MASK ) 46#define PR_SVE_VL_LEN_MASK 0xffff 47#endif 48 49#elif defined(__APPLE__ ) 50#include <sys/sysctl.h> 51#elif defined(_WIN32 ) 52#include <windows.h> 53 54#if !defined(PF_ARM_V82_DP_INSTRUCTIONS_AVAILABLE ) 55#define PF_ARM_V82_DP_INSTRUCTIONS_AVAILABLE 43 56#endif 57 58#if !defined(PF_ARM_SVE_INSTRUCTIONS_AVAILABLE ) 59#define PF_ARM_SVE_INSTRUCTIONS_AVAILABLE 46 60#endif 61 62#if !defined(PF_ARM_SVE2_INSTRUCTIONS_AVAILABLE ) 63#define PF_ARM_SVE2_INSTRUCTIONS_AVAILABLE 47 64#endif 65 66#if !defined(PF_ARM_V82_I8MM_INSTRUCTIONS_AVAILABLE ) 67#define PF_ARM_V82_I8MM_INSTRUCTIONS_AVAILABLE 66 68#endif 69 70#if !defined(PF_ARM_V82_FP16_INSTRUCTIONS_AVAILABLE ) 71#define PF_ARM_V82_FP16_INSTRUCTIONS_AVAILABLE 67 72#endif 73 74#if !defined(PF_ARM_SME_INSTRUCTIONS_AVAILABLE ) 75#define PF_ARM_SME_INSTRUCTIONS_AVAILABLE 70 76#endif 77 78#if !defined(PF_ARM_SME2_INSTRUCTIONS_AVAILABLE ) 79#define PF_ARM_SME2_INSTRUCTIONS_AVAILABLE 71 80#endif 81 82#endif 83 84typedef struct ggml_feats_arch64_runtime { 85bool has_dotprod ; 86bool has_fp16 ; 87bool has_sve ; 88bool has_sve2 ; 89bool has_i8mm ; 90bool has_sme ; 91bool has_sme2 ; 92int sve_cnt ; 93}ggml_feats_arch64_runtime_t ; 94 95static inline ggml_feats_arch64_runtime_t ggml_feats_get_arch64_runtime (void ) { 96ggml_feats_arch64_runtime_t runtime_feat = {}; 97 98#if defined(__linux__ ) 99const unsigned long hwcap = getauxval (AT_HWCAP ); 100const unsigned long hwcap2 = getauxval (AT_HWCAP2 ); 101 102runtime_feat .has_dotprod = !!(hwcap & HWCAP_ASIMDDP ); 103runtime_feat .has_fp16 = !!(hwcap & HWCAP_FPHP )&& !!(hwcap & HWCAP_ASIMDHP );; 104runtime_feat .has_sve = !!(hwcap & HWCAP_SVE ); 105runtime_feat .has_sve2 = !!(hwcap2 & HWCAP2_SVE2 ); 106runtime_feat .has_i8mm = !!(hwcap2 & HWCAP2_I8MM ); 107runtime_feat .has_sme = !!(hwcap2 & HWCAP2_SME ); 108runtime_feat .has_sme2 = !!(hwcap2 & HWCAP2_SME2 ); 109 110if (runtime_feat .has_sve ) { 111const int vl = prctl (PR_SVE_GET_VL ); 112if (vl >=0 ) { 113runtime_feat .sve_cnt = vl & PR_SVE_VL_LEN_MASK ; 114 } 115 } 116#elif defined(__APPLE__ ) 117int oldp = 0 ; 118size_t size = sizeof (oldp ); 119 120if (sysctlbyname ("hw.optional.arm.FEAT_DotProd" ,& oldp ,& size ,nullptr ,0 )== 0 ) { 121runtime_feat .has_dotprod = static_cast < bool > (oldp ); 122 } 123 124if (sysctlbyname ("hw.optional.arm.FEAT_FP16" ,& oldp ,& size ,nullptr ,0 )== 0 ) { 125runtime_feat .has_fp16 = static_cast < bool > (oldp ); 126 } 127 128if (sysctlbyname ("hw.optional.arm.FEAT_SVE" ,& oldp ,& size ,nullptr ,0 )== 0 ) { 129runtime_feat .has_sve = static_cast < bool > (oldp ); 130 } 131 132if (sysctlbyname ("hw.optional.arm.FEAT_SVE2" ,& oldp ,& size ,nullptr ,0 )== 0 ) { 133runtime_feat .has_sve2 = static_cast < bool > (oldp ); 134 } 135 136if (sysctlbyname ("hw.optional.arm.FEAT_I8MM" ,& oldp ,& size ,nullptr ,0 )== 0 ) { 137runtime_feat .has_i8mm = static_cast < bool > (oldp ); 138 } 139 140if (sysctlbyname ("hw.optional.arm.FEAT_SME" ,& oldp ,& size ,nullptr ,0 )== 0 ) { 141runtime_feat .has_sme = static_cast < bool > (oldp ); 142 } 143 144if (sysctlbyname ("hw.optional.arm.FEAT_SME2" ,& oldp ,& size ,nullptr ,0 )== 0 ) { 145runtime_feat .has_sme2 = static_cast < bool > (oldp ); 146 } 147 148// Apple does not support userspace non-streaming SVE; keep SVE vector length unknown. 149runtime_feat .sve_cnt = 0 ; 150#elif defined (_WIN32 ) 151runtime_feat .has_dotprod = IsProcessorFeaturePresent (PF_ARM_V82_DP_INSTRUCTIONS_AVAILABLE )!= 0 ; 152runtime_feat .has_fp16 = IsProcessorFeaturePresent (PF_ARM_V82_FP16_INSTRUCTIONS_AVAILABLE )!= 0 ; 153runtime_feat .has_sve = IsProcessorFeaturePresent (PF_ARM_SVE_INSTRUCTIONS_AVAILABLE )!= 0 ; 154runtime_feat .has_sve2 = IsProcessorFeaturePresent (PF_ARM_SVE2_INSTRUCTIONS_AVAILABLE )!= 0 ; 155runtime_feat .has_i8mm = IsProcessorFeaturePresent (PF_ARM_V82_I8MM_INSTRUCTIONS_AVAILABLE )!= 0 ; 156runtime_feat .has_sme = IsProcessorFeaturePresent (PF_ARM_SME_INSTRUCTIONS_AVAILABLE )!= 0 ; 157runtime_feat .has_sme2 = IsProcessorFeaturePresent (PF_ARM_SME2_INSTRUCTIONS_AVAILABLE )!= 0 ; 158 159// Windows exposes SVE feature presence, but not the runtime SVE vector length here. 160runtime_feat .sve_cnt = 0 ; 161#endif 162 163return runtime_feat ; 164} 165 166#endif // defined(__aarch64__) || defined(_M_ARM64)