Skip to content

Commit

Permalink
ggml : add system info functions
Browse files Browse the repository at this point in the history
  • Loading branch information
ggerganov committed Oct 25, 2022
1 parent c6710ef commit 34bb3ab
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 0 deletions.
15 changes: 15 additions & 0 deletions examples/bench/bench.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,5 +74,20 @@ int main(int argc, char ** argv) {
whisper_print_timings(ctx);
whisper_free(ctx);

fprintf(stderr, "\n");
fprintf(stderr, "system_info: n_threads = %d | %s\n", params.n_threads, whisper_print_system_info());

fprintf(stderr, "\n");
fprintf(stderr, "If you wish, you can submit these results here:\n");
fprintf(stderr, "\n");
fprintf(stderr, " https://github.com/ggerganov/whisper.cpp/issues/89\n");
fprintf(stderr, "\n");
fprintf(stderr, "Please include the following information:\n");
fprintf(stderr, "\n");
fprintf(stderr, " - CPU model\n");
fprintf(stderr, " - Operating system\n");
fprintf(stderr, " - Compiler\n");
fprintf(stderr, "\n");

return 0;
}
50 changes: 50 additions & 0 deletions ggml.c
Original file line number Diff line number Diff line change
Expand Up @@ -8032,3 +8032,53 @@ enum ggml_opt_result ggml_opt(
}

////////////////////////////////////////////////////////////////////////////////

int ggml_cpu_has_avx2(void) {
#if defined(__AVX2__)
return 1;
#else
return 0;
#endif
}

int ggml_cpu_has_avx512(void) {
#if defined(__AVX512F__)
return 1;
#else
return 0;
#endif
}

int ggml_cpu_has_neon(void) {
#if defined(__ARM_NEON__)
return 1;
#else
return 0;
#endif
}

int ggml_cpu_has_fp16_va(void) {
#if defined(__ARM_FEATURE_FP16_VECTOR_ARITHMETIC)
return 1;
#else
return 0;
#endif
}

int ggml_cpu_has_wasm_simd(void) {
#if defined(__wasm_simd128__)
return 1;
#else
return 0;
#endif
}

int ggml_cpu_has_blas(void) {
#if defined(GGML_USE_BLAS) || defined(GGML_USE_ACCELERATE)
return 1;
#else
return 0;
#endif
}

////////////////////////////////////////////////////////////////////////////////
11 changes: 11 additions & 0 deletions ggml.h
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,17 @@ enum ggml_opt_result ggml_opt(
struct ggml_opt_params params,
struct ggml_tensor * f);

//
// system info
//

int ggml_cpu_has_avx2(void);
int ggml_cpu_has_avx512(void);
int ggml_cpu_has_neon(void);
int ggml_cpu_has_fp16_va(void);
int ggml_cpu_has_wasm_simd(void);
int ggml_cpu_has_blas(void);

#ifdef __cplusplus
}
#endif
14 changes: 14 additions & 0 deletions whisper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2628,3 +2628,17 @@ whisper_token whisper_full_get_token_id(struct whisper_context * ctx, int i_segm
float whisper_full_get_token_p(struct whisper_context * ctx, int i_segment, int i_token) {
return ctx->result_all[i_segment].tokens[i_token].p;
}

const char * whisper_print_system_info() {
static std::string s;

s = "";
s += "AVX2 = " + std::to_string(ggml_cpu_has_avx2()) + " | ";
s += "AVX512 = " + std::to_string(ggml_cpu_has_avx512()) + " | ";
s += "NEON = " + std::to_string(ggml_cpu_has_neon()) + " | ";
s += "FP16_VA = " + std::to_string(ggml_cpu_has_fp16_va()) + " | ";
s += "WASM_SIMD = " + std::to_string(ggml_cpu_has_wasm_simd()) + " | ";
s += "BLAS = " + std::to_string(ggml_cpu_has_blas()) + " | ";

return s.c_str();
}
3 changes: 3 additions & 0 deletions whisper.h
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,9 @@ extern "C" {
// Get the probability of the specified token in the specified segment.
WHISPER_API float whisper_full_get_token_p(struct whisper_context * ctx, int i_segment, int i_token);

// Print system information
WHISPER_API const char * whisper_print_system_info();

#ifdef __cplusplus
}
#endif
Expand Down

0 comments on commit 34bb3ab

Please sign in to comment.