diff --git a/docs/build-profiling.md b/docs/build-profiling.md index 3ec8c7eee3..33251f21b6 100644 --- a/docs/build-profiling.md +++ b/docs/build-profiling.md @@ -13,7 +13,11 @@ brew install clang-build-analyzer Linux: ```console -TODO: +git clone https://github.com/aras-p/ClangBuildAnalyzer.git +cd ClangBuildAnalyzer +cmake -B build -DCMAKE_BUILD_TYPE=Release +cmake --build build -j$(nproc) +sudo cp build/ClangBuildAnalyzer /usr/local/bin/ ``` ### Usage @@ -21,7 +25,46 @@ TODO: $ ./scripts/build-profile-baseline.sh ``` +### Linux (Ubuntu 24.04) -### Baseline -The initial run of this produces the following report: -* [baseline-report.txt](./profiling-reports/baseline-report.txt) +Environment: +- Clang: 18.1.3 (Ubuntu clang version 18.1.3 (1ubuntu1)) +- libstdc++: GCC 13.3.0 (Ubuntu 13.3.0-6ubuntu2~24.04.1) +- Target: x86_64-pc-linux-gnu + +```console ++--------------------+-----+------------+------------+------------+ +| Build | TUs | Frontend | Backend | Total | ++--------------------+-----+------------+------------+------------+ +| Minimal, master | 249 | 468.2 s | 270.3 s | 738.5 s | +| Minimal, with PCH | 253 | 177.1 s | 265.8 s | 442.9 s | +| Full, master | 396 | 811.0 s | 692.2 s | 1,503.2 s | +| Full, with PCH | 404 | 418.3 s | 663.9 s | 1,082.2 s | ++--------------------+-----+------------+------------+------------+ + +PCH = precompiled header. +Full = includes building Server, Tools, and Tests. +``` +Note that the number of translation units (TUs) increases when using precompiled +headers — each PCH target adds one extra TU for the precompilation step itself. + +### Mac (Apple M3) + +Environment: +- Clang: Apple clang version 17.0.0 (clang-1700.3.19.1) +- libc++: ships with Apple clang 17.0.0 (Xcode toolchain) +- Target: arm64-apple-macosx15.6 + +```console ++--------------------+-----+------------+------------+------------+ +| Build | TUs | Frontend | Backend | Total | ++--------------------+-----+------------+------------+------------+ +| Minimal, master | 256 | 154.5 s | 94.8 s | 249.3 s | +| Minimal, with PCH | 261 | 65.9 s | 90.0 s | 155.9 s | +| Full, master | 407 | 265.7 s | 209.7 s | 475.4 s | +| Full, with PCH | 414 | 154.6 s | 197.5 s | 352.1 s | ++--------------------+-----+------------+------------+------------+ + +PCH = precompiled header. +Full = includes building Server, Tools, and Tests. +``` diff --git a/docs/profiling-reports/baseline-report.txt b/docs/profiling-reports/baseline-report.txt deleted file mode 100644 index 7025545da9..0000000000 --- a/docs/profiling-reports/baseline-report.txt +++ /dev/null @@ -1,239 +0,0 @@ -Analyzing build trace from '/Users/danbev/work/ai/llama.cpp/build-profile-baseline/clang_analysis.bin'... -**** Time summary: -Compilation (257 times): - Parsing (frontend): 152.3 s - Codegen & opts (backend): 94.8 s - -**** Files that took longest to parse (compiler frontend): - 2089 ms: /Users/danbev/work/ai/llama.cpp/build-profile-baseline/common/CMakeFiles/llama-common.dir/chat.cpp.o - 2054 ms: /Users/danbev/work/ai/llama.cpp/build-profile-baseline/vendor/cpp-httplib/CMakeFiles/cpp-httplib.dir/httplib.cpp.o - 1901 ms: /Users/danbev/work/ai/llama.cpp/build-profile-baseline/common/CMakeFiles/llama-common.dir/peg-parser.cpp.o - 1857 ms: /Users/danbev/work/ai/llama.cpp/build-profile-baseline/common/CMakeFiles/llama-common.dir/json.cpp.o - 1813 ms: /Users/danbev/work/ai/llama.cpp/build-profile-baseline/common/CMakeFiles/llama-common.dir/arg.cpp.o - 1662 ms: /Users/danbev/work/ai/llama.cpp/build-profile-baseline/common/CMakeFiles/llama-common.dir/chat-diff-analyzer.cpp.o - 1498 ms: /Users/danbev/work/ai/llama.cpp/build-profile-baseline/common/CMakeFiles/llama-common.dir/download.cpp.o - 1477 ms: /Users/danbev/work/ai/llama.cpp/build-profile-baseline/common/CMakeFiles/llama-common.dir/jinja/value.cpp.o - 1426 ms: /Users/danbev/work/ai/llama.cpp/build-profile-baseline/src/CMakeFiles/llama.dir/llama-model.cpp.o - 1356 ms: /Users/danbev/work/ai/llama.cpp/build-profile-baseline/common/CMakeFiles/llama-common.dir/json-schema-to-grammar.cpp.o - -**** Files that took longest to codegen (compiler backend): - 6436 ms: /Users/danbev/work/ai/llama.cpp/build-profile-baseline/common/CMakeFiles/llama-common.dir/chat.cpp.o - 6163 ms: /Users/danbev/work/ai/llama.cpp/build-profile-baseline/vendor/cpp-httplib/CMakeFiles/cpp-httplib.dir/httplib.cpp.o - 5876 ms: /Users/danbev/work/ai/llama.cpp/build-profile-baseline/common/CMakeFiles/llama-common.dir/arg.cpp.o - 3023 ms: /Users/danbev/work/ai/llama.cpp/build-profile-baseline/common/CMakeFiles/llama-common.dir/chat-diff-analyzer.cpp.o - 2807 ms: /Users/danbev/work/ai/llama.cpp/build-profile-baseline/common/CMakeFiles/llama-common.dir/peg-parser.cpp.o - 2798 ms: /Users/danbev/work/ai/llama.cpp/build-profile-baseline/common/CMakeFiles/llama-common.dir/json-schema-to-grammar.cpp.o - 2784 ms: /Users/danbev/work/ai/llama.cpp/build-profile-baseline/ggml/src/CMakeFiles/ggml-cpu.dir/ggml-cpu/ops.cpp.o - 2511 ms: /Users/danbev/work/ai/llama.cpp/build-profile-baseline/src/CMakeFiles/llama.dir/llama-model.cpp.o - 2475 ms: /Users/danbev/work/ai/llama.cpp/build-profile-baseline/src/CMakeFiles/llama.dir/unicode.cpp.o - 2439 ms: /Users/danbev/work/ai/llama.cpp/build-profile-baseline/src/CMakeFiles/llama.dir/llama-kv-cache.cpp.o - -**** Templates that took longest to instantiate: - 1085 ms: std::unordered_map, std::vector> (170 times, avg 6 ms) - 1084 ms: std::vector::vector (173 times, avg 6 ms) - 987 ms: std::unordered_map (165 times, avg 5 ms) - 930 ms: std::unordered_map (174 times, avg 5 ms) - 889 ms: std::__hash_table, std::vect... (170 times, avg 5 ms) - 830 ms: std::unordered_map (170 times, avg 4 ms) - 806 ms: std::vector::__construct_at_end (156 times, avg 5 ms) - 771 ms: std::basic_regex::basic_regex (11 times, avg 70 ms) - 769 ms: std::basic_regex::__init (11 times, avg 69 ms) - 766 ms: std::basic_regex::__parse (11 times, avg 69 ms) - 762 ms: std::__hash_table, std::__unordered... (165 times, avg 4 ms) - 743 ms: std::__hash_table, ... (174 times, avg 4 ms) - 741 ms: std::unordered_set (168 times, avg 4 ms) - 682 ms: std::basic_regex::basic_regex, std::all... (6 times, avg 113 ms) - 681 ms: std::basic_regex::__init> (6 times, avg 113 ms) - 677 ms: std::basic_regex::__parse> (6 times, avg 112 ms) - 667 ms: std::basic_regex::__parse_ecma_exp (11 times, avg 60 ms) - 663 ms: std::map (170 times, avg 3 ms) - 657 ms: std::basic_regex::__parse_alternative (11 times, avg 59 ms) - 657 ms: std::basic_regex::__parse_term (11 times, avg 59 ms) - 646 ms: std::basic_string (245 times, avg 2 ms) - 638 ms: std::__copy, true>, std::__bit... (170 times, avg 3 ms) - 637 ms: std::__hash_table (152 times, avg 3 ms) - 552 ms: std::basic_regex::__parse_ecma_exp (4706 times, avg 1 ms) - 5031 ms: std::unordered_map<$> (905 times, avg 5 ms) - 4783 ms: std::allocator_traits<$> (5799 times, avg 0 ms) - 4625 ms: std::__hash_table<$> (1084 times, avg 4 ms) - 3736 ms: std::map<$> (1105 times, avg 3 ms) - 2878 ms: std::__tree<$> (1369 times, avg 2 ms) - 2698 ms: std::unique_ptr<$> (2818 times, avg 0 ms) - 2259 ms: std::function<$>::function<$> (466 times, avg 4 ms) - 2234 ms: std::basic_string<$> (1010 times, avg 2 ms) - 2213 ms: std::__function::__value_func<$>::__value_func<$> (466 times, avg 4 ms) - 2159 ms: std::vector<$>::vector (487 times, avg 4 ms) - 1775 ms: std::basic_string<$>::basic_string (997 times, avg 1 ms) - 1724 ms: std::vector<$>::__construct_at_end<$> (492 times, avg 3 ms) - 1716 ms: std::vector<$>::emplace_back<$> (468 times, avg 3 ms) - 1613 ms: std::basic_string<$>::__init (979 times, avg 1 ms) - 1565 ms: std::basic_regex<$>::__init<$> (18 times, avg 86 ms) - 1558 ms: std::basic_regex<$>::__parse<$> (18 times, avg 86 ms) - 1531 ms: std::unordered_map<$>::unordered_map (554 times, avg 2 ms) - 1404 ms: std::vector<$>::~vector (670 times, avg 2 ms) - 1393 ms: std::vector<$>::__swap_out_circular_buffer (627 times, avg 2 ms) - 1315 ms: std::basic_regex<$>::__parse_ecma_exp<$> (18 times, avg 73 ms) - 1294 ms: std::basic_regex<$>::__parse_alternative<$> (18 times, avg 71 ms) - 1291 ms: std::basic_regex<$>::__parse_term<$> (18 times, avg 71 ms) - 1215 ms: std::vector<$>::__emplace_back_slow_path<$> (365 times, avg 3 ms) - 1199 ms: std::vector<$>::push_back (344 times, avg 3 ms) - 1159 ms: std::pair<$> (1184 times, avg 0 ms) - 1133 ms: std::__hash_table<$>::~__hash_table (546 times, avg 2 ms) - 1106 ms: std::__hash_table<$>::__deallocate_node (543 times, avg 2 ms) - 1090 ms: std::__copy<$> (377 times, avg 2 ms) - 962 ms: std::vector<$>::__init_with_size<$> (264 times, avg 3 ms) - -**** Functions that took longest to compile: - 1032 ms: common_params_parser_init(common_params&, llama_example, void (*)(in... (/Users/danbev/work/ai/llama.cpp/common/arg.cpp) - 156 ms: common_chat_try_specialized_template(common_chat_template const&, st... (/Users/danbev/work/ai/llama.cpp/common/chat.cpp) - 151 ms: llama_vocab::impl::load(llama_model_loader&, LLM_KV const&) (/Users/danbev/work/ai/llama.cpp/src/llama-vocab.cpp) - 132 ms: llm_chat_apply_template(llm_chat_template, std::__1::vector(args_set_input_kq_mask const&, fl... (/Users/danbev/work/ai/llama.cpp/src/llama-kv-cache.cpp) - 92 ms: llama_model_base::load_tensors(llama_model_loader&) (/Users/danbev/work/ai/llama.cpp/src/llama-model.cpp) - 92 ms: unicode_regex_split_custom(std::__1::basic_string(args_set_input_kq_mask c... (/Users/danbev/work/ai/llama.cpp/src/llama-kv-cache.cpp) - 88 ms: ggml_compute_forward_mul (/Users/danbev/work/ai/llama.cpp/ggml/src/ggml-cpu/binary-ops.cpp) - 87 ms: ggml_compute_forward_dup (/Users/danbev/work/ai/llama.cpp/ggml/src/ggml-cpu/ops.cpp) - 80 ms: ggml_compute_forward_out_prod (/Users/danbev/work/ai/llama.cpp/ggml/src/ggml-cpu/ops.cpp) - 80 ms: common_models_handler_apply(common_models_handler&, common_params&, ... (/Users/danbev/work/ai/llama.cpp/common/arg.cpp) - 79 ms: unicode_regex_split(std::__1::basic_string >::__m... (/Users/danbev/work/ai/llama.cpp/common/download.cpp) - 56 ms: common_chat_peg_builder::python_style_tool_calls(common_json const&,... (/Users/danbev/work/ai/llama.cpp/common/chat-peg-parser.cpp) - 52 ms: llama_meta_device_get_split_state(ggml_tensor const*, void*) (/Users/danbev/work/ai/llama.cpp/src/llama-model.cpp) - 51 ms: common_schema_converter::_pattern_to_rule(std::__1::basic_string::gemm<$>(long long, long lon... (36 times, avg 7 ms) - 156 ms: common_chat_try_specialized_template(common_chat_template const&, st... (1 times, avg 156 ms) - 153 ms: bool std::__1::basic_regex<$>::__match_at_start_posix_subs<$>(char c... (14 times, avg 10 ms) - 150 ms: std::__1::__bracket_expression<$>::__exec(std::__1::__state<$>&) const (15 times, avg 10 ms) - 146 ms: ggml::cpu::repack::tensor_traits<$>::forward_mul_mat(ggml_compute_pa... (16 times, avg 9 ms) - 142 ms: bool std::__1::basic_regex<$>::__match_at_start_posix_nosubs<$>(char... (14 times, avg 10 ms) - 132 ms: llm_chat_apply_template(llm_chat_template, std::__1::vector<$> const... (1 times, avg 132 ms) - 116 ms: std::__1::__wrap_iter<$> std::__1::vector<$>::__insert_with_size[abi... (16 times, avg 7 ms) - 113 ms: llama_model_quantize_impl(std::__1::basic_string<$> const&, std::__1... (1 times, avg 113 ms) - 104 ms: ggml::cpu::repack::tensor_traits<$>::forward_mul_mat_id(ggml_compute... (16 times, avg 6 ms) - 94 ms: void set_input_kq_mask_impl<$>(args_set_input_kq_mask const&, float*... (1 times, avg 94 ms) - 92 ms: unicode_regex_split_custom(std::__1::basic_string<$> const&, std::__... (1 times, avg 92 ms) - 89 ms: std::__1::vector<$>::__append(unsigned long) (69 times, avg 1 ms) - 89 ms: void set_input_kq_mask_impl<$>(args_set_input_kq_mask const&, unsign... (1 times, avg 89 ms) - 83 ms: void std::__1::__hash_table<$>::__do_rehash<$>(unsigned long) (56 times, avg 1 ms) - 79 ms: unicode_regex_split(std::__1::basic_string<$> const&, std::__1::vect... (1 times, avg 79 ms) - 75 ms: void std::__1::vector<$>::__assign_with_size[abi:ne200100]<$>(std::_... (18 times, avg 4 ms) - 75 ms: dsv4_build_comp_plans(std::__1::vector<$> const&, unsigned int, bool... (1 times, avg 75 ms) - 73 ms: common_schema_converter::visit(common_json const&, std::__1::basic_s... (1 times, avg 73 ms) - 70 ms: hf_cache::get_repo_files(std::__1::basic_string<$> const&, std::__1:... (1 times, avg 70 ms) - 70 ms: std::__1::__bracket_expression<$>::__add_range[abi:ne200100](std::__... (15 times, avg 4 ms) - 67 ms: bool std::__1::basic_regex<$>::__match_at_start_ecma<$>(char const*,... (14 times, avg 4 ms) - 64 ms: std::__1::deque<$>::__add_back_capacity() (16 times, avg 4 ms) - 60 ms: std::__1::__loop<$>::__exec(std::__1::__state<$>&) const (15 times, avg 4 ms) - 58 ms: void std::__1::__tree_balance_after_insert[abi:ne200100]<$>(std::__1... (44 times, avg 1 ms) - 57 ms: std::__1::deque<$>::__add_front_capacity() (15 times, avg 3 ms) - 51 ms: char const* std::__1::basic_regex<$>::__parse_expression_term<$>(cha... (11 times, avg 4 ms) - 51 ms: common_schema_converter::_pattern_to_rule(std::__1::basic_string - -63362 ms: /Users/danbev/work/ai/llama.cpp/src/llama-model.h (included 168 times, avg 377 ms), included via: - 151x: models.h - 17x: - -47408 ms: /Users/danbev/work/ai/llama.cpp/src/llama-arch.h (included 173 times, avg 274 ms), included via: - 151x: models.h llama-model.h - 3x: llama-model.h - 2x: llama-memory.h llama-graph.h - 2x: llama-model-loader.h - 2x: llama-context.h llama-graph.h - 1x: llama-graph.h - ... - -36275 ms: /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/string (included 245 times, avg 148 ms), included via: - 150x: models.h llama-model.h llama-arch.h - 13x: ggml-impl.h vector locale __locale - 3x: lexer.h utils.h - 3x: llama-impl.h - 3x: common.h list functional vector locale __locale - 3x: arg.h common.h list functional vector locale __locale - ... - -18679 ms: /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/vector (included 241 times, avg 77 ms), included via: - 151x: models.h llama-model.h llama-arch.h set functional - 13x: ggml-impl.h - 3x: common.h list functional - 3x: arg.h common.h list functional - 3x: llama-impl.h - 3x: lexer.h utils.h sstream istream ostream format queue deque functional - ... - -17411 ms: /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/set (included 207 times, avg 84 ms), included via: - 151x: models.h llama-model.h llama-arch.h - 7x: common.h - 4x: runtime.h value.h - 3x: llama-model.h llama-arch.h - 3x: arg.h common.h - 3x: - ... - -13431 ms: /Users/danbev/work/ai/llama.cpp/src/llama-graph.h (included 170 times, avg 79 ms), included via: - 151x: models.h llama-model.h - 4x: llama-model.h - 2x: llama-memory.h - 2x: llama-context.h - 1x: - 1x: llama-kv-cache-dsv4.h llama-kv-cache.h - ... - -9203 ms: /Users/danbev/work/ai/llama.cpp/common/common.h (included 22 times, avg 418 ms), included via: - 9x: - 3x: arg.h - 2x: sampling.h - 2x: chat-auto-parser-helpers.h chat-auto-parser.h chat.h - 1x: reasoning-budget.h - 1x: console.h - ... - -7501 ms: /Users/danbev/work/ai/llama.cpp/src/llama-batch.h (included 170 times, avg 44 ms), included via: - 151x: models.h llama-model.h llama-graph.h - 4x: llama-model.h llama-graph.h - 2x: llama-context.h llama-graph.h - 1x: llama-kv-cache-dsv4.h llama-kv-cache.h - 1x: llama-memory-hybrid.h - 1x: llama-kv-cache-iswa.h llama-kv-cache.h - ... - -7320 ms: /Users/danbev/work/ai/llama.cpp/ggml/src/ggml-impl.h (included 30 times, avg 244 ms), included via: - 21x: - 2x: amx.h ggml-cpu-impl.h - 2x: traits.h ggml-cpu-impl.h - 1x: vec.h - 1x: binary-ops.h common.h traits.h ggml-cpu-impl.h - 1x: unary-ops.h common.h traits.h ggml-cpu-impl.h - ... - - done in 0.0s. diff --git a/docs/profiling-reports/profile-report-baseline-mac.txt b/docs/profiling-reports/profile-report-baseline-mac.txt new file mode 100644 index 0000000000..313ce6a4ab --- /dev/null +++ b/docs/profiling-reports/profile-report-baseline-mac.txt @@ -0,0 +1,239 @@ +Analyzing build trace from '/Users/danbev/work/ai/llama.cpp/build-profile-baseline/clang_analysis.bin'... +**** Time summary: +Compilation (256 times): + Parsing (frontend): 154.5 s + Codegen & opts (backend): 94.8 s + +**** Files that took longest to parse (compiler frontend): + 2125 ms: /Users/danbev/work/ai/llama.cpp/build-profile-baseline/vendor/cpp-httplib/CMakeFiles/cpp-httplib.dir/httplib.cpp.o + 2032 ms: /Users/danbev/work/ai/llama.cpp/build-profile-baseline/common/CMakeFiles/llama-common.dir/chat.cpp.o + 1879 ms: /Users/danbev/work/ai/llama.cpp/build-profile-baseline/common/CMakeFiles/llama-common.dir/arg.cpp.o + 1579 ms: /Users/danbev/work/ai/llama.cpp/build-profile-baseline/src/CMakeFiles/llama.dir/llama-model.cpp.o + 1568 ms: /Users/danbev/work/ai/llama.cpp/build-profile-baseline/common/CMakeFiles/llama-common.dir/chat-diff-analyzer.cpp.o + 1523 ms: /Users/danbev/work/ai/llama.cpp/build-profile-baseline/common/CMakeFiles/llama-common.dir/json.cpp.o + 1493 ms: /Users/danbev/work/ai/llama.cpp/build-profile-baseline/common/CMakeFiles/llama-common.dir/peg-parser.cpp.o + 1474 ms: /Users/danbev/work/ai/llama.cpp/build-profile-baseline/common/CMakeFiles/llama-common.dir/download.cpp.o + 1404 ms: /Users/danbev/work/ai/llama.cpp/build-profile-baseline/common/CMakeFiles/llama-common.dir/jinja/value.cpp.o + 1214 ms: /Users/danbev/work/ai/llama.cpp/build-profile-baseline/common/CMakeFiles/llama-common.dir/preset.cpp.o + +**** Files that took longest to codegen (compiler backend): + 6256 ms: /Users/danbev/work/ai/llama.cpp/build-profile-baseline/vendor/cpp-httplib/CMakeFiles/cpp-httplib.dir/httplib.cpp.o + 5932 ms: /Users/danbev/work/ai/llama.cpp/build-profile-baseline/common/CMakeFiles/llama-common.dir/chat.cpp.o + 5454 ms: /Users/danbev/work/ai/llama.cpp/build-profile-baseline/common/CMakeFiles/llama-common.dir/arg.cpp.o + 3039 ms: /Users/danbev/work/ai/llama.cpp/build-profile-baseline/common/CMakeFiles/llama-common.dir/peg-parser.cpp.o + 2881 ms: /Users/danbev/work/ai/llama.cpp/build-profile-baseline/common/CMakeFiles/llama-common.dir/chat-diff-analyzer.cpp.o + 2860 ms: /Users/danbev/work/ai/llama.cpp/build-profile-baseline/ggml/src/CMakeFiles/ggml-cpu.dir/ggml-cpu/ops.cpp.o + 2720 ms: /Users/danbev/work/ai/llama.cpp/build-profile-baseline/src/CMakeFiles/llama.dir/llama-model.cpp.o + 2575 ms: /Users/danbev/work/ai/llama.cpp/build-profile-baseline/src/CMakeFiles/llama.dir/llama-kv-cache.cpp.o + 2530 ms: /Users/danbev/work/ai/llama.cpp/build-profile-baseline/src/CMakeFiles/llama.dir/unicode.cpp.o + 2208 ms: /Users/danbev/work/ai/llama.cpp/build-profile-baseline/common/CMakeFiles/llama-common.dir/json-schema-to-grammar.cpp.o + +**** Templates that took longest to instantiate: + 1192 ms: std::unordered_map, std::vector> (170 times, avg 7 ms) + 1064 ms: std::vector::vector (173 times, avg 6 ms) + 1032 ms: std::unordered_map (174 times, avg 5 ms) + 1001 ms: std::unordered_map (165 times, avg 6 ms) + 958 ms: std::__hash_table, std::vect... (170 times, avg 5 ms) + 881 ms: std::unordered_map (170 times, avg 5 ms) + 823 ms: std::unordered_map (156 times, avg 5 ms) + 815 ms: std::__hash_table, ... (174 times, avg 4 ms) + 789 ms: std::vector::__construct_at_end (168 times, avg 4 ms) + 784 ms: std::__hash_table, std::__unordered... (165 times, avg 4 ms) + 772 ms: std::basic_regex::basic_regex (11 times, avg 70 ms) + 771 ms: std::basic_regex::__init (11 times, avg 70 ms) + 769 ms: std::basic_regex::__parse (11 times, avg 69 ms) + 682 ms: std::basic_regex::__parse_ecma_exp (11 times, avg 62 ms) + 675 ms: std::basic_regex::__parse_alternative (11 times, avg 61 ms) + 675 ms: std::basic_regex::__parse_term (11 times, avg 61 ms) + 670 ms: std::map (170 times, avg 3 ms) + 664 ms: std::__hash_table (152 times, avg 4 ms) + 643 ms: std::__hash_table (245 times, avg 2 ms) + 622 ms: std::__copy, true>, std::__bit... (170 times, avg 3 ms) + 598 ms: std::basic_regex::basic_regex, std::all... (6 times, avg 99 ms) + 597 ms: std::basic_regex::__init> (6 times, avg 99 ms) + 593 ms: std::basic_regex::__parse> (6 times, avg 98 ms) + 541 ms: std::basic_string (245 times, avg 2 ms) + 532 ms: std::basic_string (245 times, avg 2 ms) + 529 ms: std::unordered_map::unordered_map (174 times, avg 3 ms) + +**** Template sets that took longest to instantiate: + 6796 ms: std::vector<$> (4713 times, avg 1 ms) + 5339 ms: std::unordered_map<$> (905 times, avg 5 ms) + 5133 ms: std::allocator_traits<$> (6086 times, avg 0 ms) + 4875 ms: std::__hash_table<$> (1084 times, avg 4 ms) + 3940 ms: std::map<$> (1105 times, avg 3 ms) + 3052 ms: std::__tree<$> (1369 times, avg 2 ms) + 2865 ms: std::unique_ptr<$> (3024 times, avg 0 ms) + 2326 ms: std::function<$>::function<$> (466 times, avg 4 ms) + 2279 ms: std::__function::__value_func<$>::__value_func<$> (466 times, avg 4 ms) + 2267 ms: std::basic_string<$> (1010 times, avg 2 ms) + 2126 ms: std::vector<$>::vector (496 times, avg 4 ms) + 1809 ms: std::basic_string<$>::basic_string (999 times, avg 1 ms) + 1757 ms: std::vector<$>::emplace_back<$> (462 times, avg 3 ms) + 1711 ms: std::vector<$>::__construct_at_end<$> (487 times, avg 3 ms) + 1638 ms: std::basic_string<$>::__init (979 times, avg 1 ms) + 1584 ms: std::unordered_map<$>::unordered_map (555 times, avg 2 ms) + 1503 ms: std::basic_regex<$>::__init<$> (18 times, avg 83 ms) + 1497 ms: std::basic_regex<$>::__parse<$> (18 times, avg 83 ms) + 1395 ms: std::vector<$>::~vector (671 times, avg 2 ms) + 1382 ms: std::vector<$>::__swap_out_circular_buffer (626 times, avg 2 ms) + 1255 ms: std::basic_regex<$>::__parse_ecma_exp<$> (18 times, avg 69 ms) + 1240 ms: std::basic_regex<$>::__parse_alternative<$> (18 times, avg 68 ms) + 1238 ms: std::basic_regex<$>::__parse_term<$> (18 times, avg 68 ms) + 1225 ms: std::vector<$>::__emplace_back_slow_path<$> (363 times, avg 3 ms) + 1189 ms: std::vector<$>::push_back (338 times, avg 3 ms) + 1152 ms: std::__hash_table<$>::~__hash_table (547 times, avg 2 ms) + 1141 ms: std::pair<$> (1191 times, avg 0 ms) + 1125 ms: std::__hash_table<$>::__deallocate_node (543 times, avg 2 ms) + 1061 ms: std::__copy<$> (381 times, avg 2 ms) + 970 ms: std::vector<$>::__init_with_size<$> (263 times, avg 3 ms) + +**** Functions that took longest to compile: + 937 ms: common_params_parser_init(common_params&, llama_example, void (*)(in... (/Users/danbev/work/ai/llama.cpp/common/arg.cpp) + 157 ms: common_chat_try_specialized_template(common_chat_template const&, st... (/Users/danbev/work/ai/llama.cpp/common/chat.cpp) + 138 ms: llm_chat_apply_template(llm_chat_template, std::__1::vector(args_set_input_kq_mask const&, fl... (/Users/danbev/work/ai/llama.cpp/src/llama-kv-cache.cpp) + 99 ms: llama_model_base::load_tensors(llama_model_loader&) (/Users/danbev/work/ai/llama.cpp/src/llama-model.cpp) + 99 ms: ggml_compute_forward_div (/Users/danbev/work/ai/llama.cpp/ggml/src/ggml-cpu/binary-ops.cpp) + 94 ms: ggml_compute_forward_add_non_quantized (/Users/danbev/work/ai/llama.cpp/ggml/src/ggml-cpu/binary-ops.cpp) + 90 ms: void set_input_kq_mask_impl(args_set_input_kq_mask c... (/Users/danbev/work/ai/llama.cpp/src/llama-kv-cache.cpp) + 88 ms: llama_model_saver::add_kv_from_model() (/Users/danbev/work/ai/llama.cpp/src/llama-model-saver.cpp) + 84 ms: unicode_regex_split(std::__1::basic_string::gemm<$>(long long, long lon... (36 times, avg 6 ms) + 168 ms: bool std::__1::basic_regex<$>::__match_at_start_posix_nosubs<$>(char... (14 times, avg 12 ms) + 164 ms: ggml::cpu::repack::tensor_traits<$>::forward_mul_mat(ggml_compute_pa... (16 times, avg 10 ms) + 157 ms: common_chat_try_specialized_template(common_chat_template const&, st... (1 times, avg 157 ms) + 157 ms: std::__1::__bracket_expression<$>::__exec(std::__1::__state<$>&) const (15 times, avg 10 ms) + 138 ms: llm_chat_apply_template(llm_chat_template, std::__1::vector<$> const... (1 times, avg 138 ms) + 123 ms: std::__1::__wrap_iter<$> std::__1::vector<$>::__insert_with_size[abi... (16 times, avg 7 ms) + 111 ms: ggml::cpu::repack::tensor_traits<$>::forward_mul_mat_id(ggml_compute... (16 times, avg 6 ms) + 104 ms: void set_input_kq_mask_impl<$>(args_set_input_kq_mask const&, float*... (1 times, avg 104 ms) + 99 ms: bool std::__1::basic_regex<$>::__match_at_start_posix_subs<$>(char c... (14 times, avg 7 ms) + 98 ms: bool std::__1::basic_regex<$>::__match_at_start_ecma<$>(char const*,... (14 times, avg 7 ms) + 90 ms: void set_input_kq_mask_impl<$>(args_set_input_kq_mask const&, unsign... (1 times, avg 90 ms) + 87 ms: std::__1::vector<$>::__append(unsigned long) (77 times, avg 1 ms) + 84 ms: unicode_regex_split(std::__1::basic_string<$> const&, std::__1::vect... (1 times, avg 84 ms) + 80 ms: unicode_regex_split_custom(std::__1::basic_string<$> const&, std::__... (1 times, avg 80 ms) + 80 ms: void std::__1::__hash_table<$>::__do_rehash<$>(unsigned long) (56 times, avg 1 ms) + 76 ms: llama_model_quantize_impl(std::__1::basic_string<$> const&, std::__1... (1 times, avg 76 ms) + 72 ms: llama_model_loader::llama_model_loader(gguf_context*, void (*)(ggml_... (1 times, avg 72 ms) + 71 ms: dsv4_build_comp_plans(std::__1::vector<$> const&, unsigned int, bool... (1 times, avg 71 ms) + 70 ms: common_schema_converter::visit(common_json const&, std::__1::basic_s... (1 times, avg 70 ms) + 67 ms: void std::__1::vector<$>::__assign_with_size[abi:ne200100]<$>(std::_... (18 times, avg 3 ms) + 64 ms: void std::__1::__tree_balance_after_insert[abi:ne200100]<$>(std::__1... (44 times, avg 1 ms) + 63 ms: std::__1::pair<$> std::__1::__hash_table<$>::__emplace_unique_key_ar... (15 times, avg 4 ms) + 61 ms: void std::__1::__introsort<$>(std::__1::pair<$>*, std::__1::pair<$>*... (1 times, avg 61 ms) + 60 ms: std::__1::deque<$>::__add_back_capacity() (16 times, avg 3 ms) + 60 ms: std::__1::__bracket_expression<$>::__add_range[abi:ne200100](std::__... (15 times, avg 4 ms) + 59 ms: char const* std::__1::basic_regex<$>::__parse_expression_term<$>(cha... (11 times, avg 5 ms) + 57 ms: void (anonymous namespace)::tinyBLAS_Q0_ARM<$>::gemm<$>(long long, l... (18 times, avg 3 ms) + 54 ms: hf_cache::get_repo_files(std::__1::basic_string<$> const&, std::__1:... (1 times, avg 54 ms) + 50 ms: std::__1::deque<$>::__add_front_capacity() (15 times, avg 3 ms) + +**** Expensive headers: +73736 ms: /Users/danbev/work/ai/llama.cpp/src/models/models.h (included 152 times, avg 485 ms), included via: + 152x: + +65981 ms: /Users/danbev/work/ai/llama.cpp/src/llama-model.h (included 168 times, avg 392 ms), included via: + 151x: models.h + 17x: + +49234 ms: /Users/danbev/work/ai/llama.cpp/src/llama-arch.h (included 173 times, avg 284 ms), included via: + 151x: models.h llama-model.h + 3x: llama-model.h + 2x: llama-memory.h llama-graph.h + 2x: llama-model-loader.h + 2x: llama-context.h llama-graph.h + 1x: llama-model-saver.h + ... + +37732 ms: /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/string (included 245 times, avg 154 ms), included via: + 150x: models.h llama-model.h llama-arch.h + 13x: ggml-impl.h vector locale __locale + 3x: lexer.h utils.h + 3x: llama-impl.h + 3x: common.h list functional vector locale __locale + 3x: arg.h common.h list functional vector locale __locale + ... + +19209 ms: /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/vector (included 241 times, avg 79 ms), included via: + 151x: models.h llama-model.h llama-arch.h set functional + 13x: ggml-impl.h + 3x: common.h list functional + 3x: arg.h common.h list functional + 3x: llama-impl.h + 3x: lexer.h utils.h sstream istream ostream format queue deque functional + ... + +17946 ms: /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/set (included 207 times, avg 86 ms), included via: + 151x: models.h llama-model.h llama-arch.h + 7x: common.h + 4x: runtime.h value.h + 3x: llama-model.h llama-arch.h + 3x: arg.h common.h + 3x: + ... + +14187 ms: /Users/danbev/work/ai/llama.cpp/src/llama-graph.h (included 170 times, avg 83 ms), included via: + 151x: models.h llama-model.h + 4x: llama-model.h + 2x: llama-memory.h + 2x: llama-context.h + 1x: + 1x: llama-kv-cache-dsv4.h llama-kv-cache.h + ... + +8229 ms: /Users/danbev/work/ai/llama.cpp/common/common.h (included 22 times, avg 374 ms), included via: + 9x: + 3x: arg.h + 2x: sampling.h + 2x: chat-auto-parser-helpers.h chat-auto-parser.h chat.h + 1x: speculative.h + 1x: chat.h + ... + +7954 ms: /Users/danbev/work/ai/llama.cpp/src/llama-batch.h (included 170 times, avg 46 ms), included via: + 151x: models.h llama-model.h llama-graph.h + 4x: llama-model.h llama-graph.h + 2x: llama-context.h llama-graph.h + 1x: llama-kv-cache-dsv4.h llama-kv-cache.h + 1x: llama-kv-cache-dsa.h llama-kv-cache.h + 1x: llama-memory-hybrid-iswa.h + ... + +7582 ms: /Users/danbev/work/ai/llama.cpp/ggml/src/ggml-impl.h (included 30 times, avg 252 ms), included via: + 21x: + 2x: amx.h ggml-cpu-impl.h + 2x: traits.h ggml-cpu-impl.h + 1x: vec.h + 1x: unary-ops.h common.h traits.h ggml-cpu-impl.h + 1x: binary-ops.h common.h traits.h ggml-cpu-impl.h + ... + + done in 0.0s. diff --git a/docs/profiling-reports/profile-report-baseline-ubuntu.txt b/docs/profiling-reports/profile-report-baseline-ubuntu.txt new file mode 100644 index 0000000000..c807d2aab1 --- /dev/null +++ b/docs/profiling-reports/profile-report-baseline-ubuntu.txt @@ -0,0 +1,245 @@ +Analyzing build trace from '/home/danbev/work/ai/llama.cpp/build-profile-baseline/clang_analysis.bin'... +**** Time summary: +Compilation (249 times): + Parsing (frontend): 468.2 s + Codegen & opts (backend): 270.3 s + +**** Files that took longest to parse (compiler frontend): + 6555 ms: /home/danbev/work/ai/llama.cpp/build-profile-baseline/common/CMakeFiles/llama-common.dir/chat.cpp.o + 6298 ms: /home/danbev/work/ai/llama.cpp/build-profile-baseline/common/CMakeFiles/llama-common.dir/json.cpp.o + 5897 ms: /home/danbev/work/ai/llama.cpp/build-profile-baseline/common/CMakeFiles/llama-common.dir/arg.cpp.o + 5076 ms: /home/danbev/work/ai/llama.cpp/build-profile-baseline/common/CMakeFiles/llama-common.dir/chat-diff-analyzer.cpp.o + 5037 ms: /home/danbev/work/ai/llama.cpp/build-profile-baseline/common/CMakeFiles/llama-common.dir/preset.cpp.o + 4819 ms: /home/danbev/work/ai/llama.cpp/build-profile-baseline/src/CMakeFiles/llama.dir/llama-model.cpp.o + 4723 ms: /home/danbev/work/ai/llama.cpp/build-profile-baseline/common/CMakeFiles/llama-common.dir/peg-parser.cpp.o + 4223 ms: /home/danbev/work/ai/llama.cpp/build-profile-baseline/common/CMakeFiles/llama-common.dir/download.cpp.o + 4204 ms: /home/danbev/work/ai/llama.cpp/build-profile-baseline/src/CMakeFiles/llama.dir/unicode-data.cpp.o + 4104 ms: /home/danbev/work/ai/llama.cpp/build-profile-baseline/common/CMakeFiles/llama-common.dir/json-schema-to-grammar.cpp.o + +**** Files that took longest to codegen (compiler backend): + 15027 ms: /home/danbev/work/ai/llama.cpp/build-profile-baseline/common/CMakeFiles/llama-common.dir/arg.cpp.o + 14526 ms: /home/danbev/work/ai/llama.cpp/build-profile-baseline/vendor/cpp-httplib/CMakeFiles/cpp-httplib.dir/httplib.cpp.o + 11187 ms: /home/danbev/work/ai/llama.cpp/build-profile-baseline/common/CMakeFiles/llama-common.dir/chat.cpp.o + 9741 ms: /home/danbev/work/ai/llama.cpp/build-profile-baseline/src/CMakeFiles/llama.dir/llama-kv-cache.cpp.o + 9428 ms: /home/danbev/work/ai/llama.cpp/build-profile-baseline/src/CMakeFiles/llama.dir/unicode.cpp.o + 9045 ms: /home/danbev/work/ai/llama.cpp/build-profile-baseline/src/CMakeFiles/llama.dir/llama-model.cpp.o + 8939 ms: /home/danbev/work/ai/llama.cpp/build-profile-baseline/common/CMakeFiles/llama-common.dir/json-schema-to-grammar.cpp.o + 8031 ms: /home/danbev/work/ai/llama.cpp/build-profile-baseline/src/CMakeFiles/llama.dir/llama-sampler.cpp.o + 7951 ms: /home/danbev/work/ai/llama.cpp/build-profile-baseline/common/CMakeFiles/llama-common.dir/peg-parser.cpp.o + 7631 ms: /home/danbev/work/ai/llama.cpp/build-profile-baseline/common/CMakeFiles/llama-common.dir/chat-diff-analyzer.cpp.o + +**** Templates that took longest to instantiate: + 7849 ms: std::basic_regex::_M_compile (15 times, avg 523 ms) + 7549 ms: std::__detail::_Compiler>::_Compiler (15 times, avg 503 ms) + 6484 ms: std::__detail::_Compiler>::_M_disjunction (15 times, avg 432 ms) + 6438 ms: std::__detail::_Compiler>::_M_alternative (15 times, avg 429 ms) + 6327 ms: std::__detail::_Compiler>::_M_term (15 times, avg 421 ms) + 5344 ms: std::__detail::_Compiler>::_M_atom (15 times, avg 356 ms) + 5173 ms: std::basic_regex::basic_regex (9 times, avg 574 ms) + 3240 ms: std::unordered_map (199 times, avg 16 ms) + 3214 ms: std::unique_ptr (170 times, avg 18 ms) + 2940 ms: std::unique_ptr (170 times, avg 17 ms) + 2830 ms: std::unique_ptr (172 times, avg 16 ms) + 2816 ms: std::unique_ptr (171 times, avg 16 ms) + 2795 ms: std::unique_ptr (168 times, avg 16 ms) + 2766 ms: std::__uniq_ptr_data (170 times, avg 16 ms) + 2725 ms: std::unique_ptr (170 times, avg 16 ms) + 2715 ms: std::unique_ptr (170 times, avg 15 ms) + 2696 ms: std::unique_ptr (170 times, avg 15 ms) + 2687 ms: std::unique_ptr (159 times, avg 16 ms) + 2681 ms: std::basic_regex::basic_regex, std::all... (6 times, avg 446 ms) + 2681 ms: std::unique_ptr (173 times, avg 15 ms) + 2675 ms: std::unique_ptr (159 times, avg 16 ms) + 2667 ms: std::unique_ptr (159 times, avg 16 ms) + 2550 ms: std::unique_ptr (147 times, avg 17 ms) + 2512 ms: std::unique_ptr (158 times, avg 15 ms) + 2436 ms: std::__uniq_ptr_data (171 times, avg 14 ms) + 2410 ms: std::__uniq_ptr_impl (171 times, avg 14 ms) + 2396 ms: std::__uniq_ptr_data (3044 times, avg 16 ms) + 42906 ms: std::__uniq_ptr_data<$> (3044 times, avg 14 ms) + 42431 ms: std::__uniq_ptr_impl<$> (3044 times, avg 13 ms) + 29501 ms: std::__and_<$> (24651 times, avg 1 ms) + 20580 ms: std::tuple<$> (3167 times, avg 6 ms) + 14925 ms: std::_Hashtable<$> (1666 times, avg 8 ms) + 13782 ms: std::vector<$> (4748 times, avg 2 ms) + 12460 ms: std::unordered_map<$> (938 times, avg 13 ms) + 10417 ms: std::_TupleConstraints<$>::__is_implicitly_constructible<$> (6459 times, avg 1 ms) + 8269 ms: std::basic_regex<$>::_M_compile (16 times, avg 516 ms) + 8014 ms: std::__or_<$> (10045 times, avg 0 ms) + 7945 ms: std::__detail::_Compiler<$>::_Compiler (16 times, avg 496 ms) + 7285 ms: std::_Vector_base<$> (4503 times, avg 1 ms) + 6821 ms: std::__detail::_Compiler<$>::_M_disjunction (16 times, avg 426 ms) + 6773 ms: std::__detail::_Compiler<$>::_M_alternative (16 times, avg 423 ms) + 6656 ms: std::__detail::_Compiler<$>::_M_term (16 times, avg 416 ms) + 6226 ms: std::_Tuple_impl<$> (3159 times, avg 1 ms) + 6042 ms: std::map<$> (1120 times, avg 5 ms) + 5669 ms: std::__detail::_Compiler<$>::_M_atom (16 times, avg 354 ms) + 5659 ms: std::_Destroy<$> (1574 times, avg 3 ms) + 5652 ms: std::vector<$>::~vector (1318 times, avg 4 ms) + 5516 ms: std::tuple<$>::__assignable<$> (5521 times, avg 0 ms) + 5470 ms: std::pair<$> (2005 times, avg 2 ms) + 5203 ms: std::_Hashtable<$>::~_Hashtable (574 times, avg 9 ms) + 5192 ms: std::unique_ptr<$>::~unique_ptr (1824 times, avg 2 ms) + 5173 ms: std::basic_regex<$>::basic_regex (9 times, avg 574 ms) + 4718 ms: std::allocator<$> (6850 times, avg 0 ms) + 4297 ms: std::function<$>::function<$> (729 times, avg 5 ms) + 4217 ms: std::vector<$>::emplace_back<$> (491 times, avg 8 ms) + 4172 ms: std::is_move_constructible<$> (3399 times, avg 1 ms) + +**** Functions that took longest to compile: + 2694 ms: common_params_parser_init(common_params&, llama_example, void (*)(in... (/home/danbev/work/ai/llama.cpp/common/arg.cpp) + 458 ms: llama_model_quantize_impl(std::__cxx11::basic_string(args_set_input_kq_... (/home/danbev/work/ai/llama.cpp/src/llama-kv-cache.cpp) + 365 ms: void set_input_kq_mask_impl(args_set_input_kq_mask con... (/home/danbev/work/ai/llama.cpp/src/llama-kv-cache.cpp) + 351 ms: void set_input_kq_mask_impl(args_set_input_kq_mask cons... (/home/danbev/work/ai/llama.cpp/src/llama-kv-cache.cpp) + 350 ms: unicode_regex_split_custom(std::__cxx11::basic_string(args_set_input_kq... (/home/danbev/work/ai/llama.cpp/src/llama-kv-cache.cpp) + 281 ms: common_params_fit_impl(char const*, llama_model_params*, llama_conte... (/home/danbev/work/ai/llama.cpp/common/fit.cpp) + 271 ms: unicode_regex_split(std::__cxx11::basic_string::_M_expression_term<$>(std::__detai... (60 times, avg 20 ms) + 933 ms: std::_Function_handler<$>::_M_manager(std::_Any_data&, std::_Any_dat... (645 times, avg 1 ms) + 751 ms: void set_input_kq_mask_impl<$>(args_set_input_kq_mask const&, unsign... (2 times, avg 375 ms) + 716 ms: void set_input_kq_mask_impl<$>(args_set_input_kq_mask const&, float*) (2 times, avg 358 ms) + 715 ms: std::__detail::_BracketMatcher<$>::_BracketMatcher(std::__detail::_B... (60 times, avg 11 ms) + 632 ms: void std::__detail::_Compiler<$>::_M_insert_bracket_matcher<$>(bool) (60 times, avg 10 ms) + 559 ms: std::__detail::_Compiler<$>::_M_quantifier() (15 times, avg 37 ms) + 487 ms: std::_Rb_tree<$>::_M_erase(std::_Rb_tree_node<$>*) (282 times, avg 1 ms) + 464 ms: void std::__detail::_Compiler<$>::_M_insert_character_class_matcher<... (60 times, avg 7 ms) + 458 ms: llama_model_quantize_impl(std::__cxx11::basic_string<$> const&, std:... (1 times, avg 458 ms) + 456 ms: std::vector<$>::~vector() (193 times, avg 2 ms) + 433 ms: std::__detail::_BracketMatcher<$>::_M_add_character_class(std::__cxx... (60 times, avg 7 ms) + 430 ms: std::__detail::_BracketMatcher<$>::_M_make_range(char, char) (56 times, avg 7 ms) + 428 ms: std::_Function_handler<$>::_M_invoke(std::_Any_data const&, jinja::f... (72 times, avg 5 ms) + 424 ms: std::__detail::_BracketMatcher<$>::_M_add_equivalence_class(std::__c... (60 times, avg 7 ms) + 423 ms: std::_Function_handler<$>::_M_invoke(std::_Any_data const&) (72 times, avg 5 ms) + 360 ms: std::__detail::_Executor<$>::_M_dfs(std::__detail::_Executor<$>::_Ma... (32 times, avg 11 ms) + 358 ms: void (anonymous namespace)::tinyBLAS<$>::gemm<$>(long, long, long) (27 times, avg 13 ms) + 350 ms: unicode_regex_split_custom(std::__cxx11::basic_string<$> const&, std... (1 times, avg 350 ms) + 350 ms: llm_chat_apply_template(llm_chat_template, std::vector<$> const&, st... (1 times, avg 350 ms) + 335 ms: std::__detail::_StateSeq<$>::_M_clone() (15 times, avg 22 ms) + 329 ms: std::__detail::_BracketMatcher<$>::_M_ready() (56 times, avg 5 ms) + 320 ms: std::vector<$>::_M_default_append(unsigned long) (58 times, avg 5 ms) + 313 ms: std::__detail::_BracketMatcher<$>::_M_add_collate_element(std::__cxx... (60 times, avg 5 ms) + 308 ms: std::__detail::_Executor<$>::_M_lookahead(long) (32 times, avg 9 ms) + 292 ms: std::__detail::_Compiler<$>::_M_atom() (15 times, avg 19 ms) + 290 ms: std::_Function_handler<$>::_M_invoke(std::_Any_data const&, common_c... (17 times, avg 17 ms) + 271 ms: unicode_regex_split(std::__cxx11::basic_string<$> const&, std::vecto... (1 times, avg 271 ms) + 251 ms: hf_cache::get_repo_files(std::__cxx11::basic_string<$> const&, std::... (1 times, avg 251 ms) + 245 ms: std::_Function_handler<$>::_M_invoke(std::_Any_data const&, char&&) (200 times, avg 1 ms) + +**** Expensive headers: +225979 ms: /home/danbev/work/ai/llama.cpp/src/models/models.h (included 152 times, avg 1486 ms), included via: + 151x: + 1x: llama-model.h + +213012 ms: /home/danbev/work/ai/llama.cpp/src/llama-model.h (included 168 times, avg 1267 ms), included via: + 151x: models.h + 2x: + 2x: llama-impl.h + 1x: llama-kv-cache-msa.h + 1x: llama-memory-recurrent.h + 1x: llama-context.h + ... + +185681 ms: /home/danbev/work/ai/llama.cpp/include/llama.h (included 201 times, avg 923 ms), included via: + 150x: models.h llama-model.h + 3x: arg.h common.h llama-cpp.h + 2x: sampling.h + 2x: llama-hparams.h + 2x: chat-auto-parser-helpers.h chat-auto-parser.h chat.h common.h llama-cpp.h + 2x: common.h llama-cpp.h + ... + +68432 ms: /home/danbev/work/ai/llama.cpp/src/llama-graph.h (included 170 times, avg 402 ms), included via: + 150x: models.h llama-model.h llama.h + 2x: llama-impl.h llama-model.h + 1x: + 1x: llama-memory.h llama.h + 1x: llama-model.h + 1x: llama-context.h llama.h + ... + +44735 ms: /home/danbev/work/ai/llama.cpp/src/llama-arch.h (included 162 times, avg 276 ms), included via: + 150x: models.h llama-model.h llama.h + 2x: llama-impl.h llama-model.h + 1x: models.h llama-model.h + 1x: llama-graph.h + 1x: + 1x: llama-model-saver.h gguf.h + ... + +25323 ms: /home/danbev/work/ai/llama.cpp/src/llama-hparams.h (included 173 times, avg 146 ms), included via: + 150x: models.h llama-model.h llama.h llama-graph.h + 2x: + 2x: llama-impl.h llama-model.h llama-graph.h + 1x: llama-memory-hybrid.h llama-batch.h llama-graph.h + 1x: llama-memory.h llama.h llama-graph.h + 1x: llama-memory-recurrent.h llama-batch.h llama-graph.h + ... + +18443 ms: /usr/include/c++/13/unordered_map (included 199 times, avg 92 ms), included via: + 150x: models.h llama-model.h llama.h llama-graph.h + 4x: runtime.h value.h cmath + 3x: arg.h common.h functional + 2x: chat-auto-parser-helpers.h chat-auto-parser.h chat.h common.h peg-parser.h + 2x: value.h cmath + 2x: + ... + +18100 ms: /home/danbev/work/ai/llama.cpp/common/common.h (included 22 times, avg 822 ms), included via: + 3x: arg.h + 2x: chat-auto-parser-helpers.h chat-auto-parser.h chat.h + 2x: + 2x: sampling.h llama.h + 1x: chat.h + 1x: chat-auto-parser.h chat.h + ... + +14291 ms: /usr/include/c++/13/cmath (included 352 times, avg 40 ms), included via: + 150x: models.h llama-model.h llama.h llama-graph.h llama-hparams.h + 133x: models.h llama-model.h + 6x: + 4x: runtime.h value.h + 2x: value.h + 2x: llama-hparams.h + ... + +13663 ms: /home/danbev/work/ai/llama.cpp/ggml/include/ggml.h (included 222 times, avg 61 ms), included via: + 150x: models.h llama-model.h llama.h + 4x: + 3x: arg.h common.h llama-cpp.h llama.h + 3x: ggml-backend.h + 2x: llama-impl.h + 2x: llama-hparams.h llama.h + ... + + done in 0.1s. diff --git a/docs/profiling-reports/profile-report-full-baseline-ubuntu.txt b/docs/profiling-reports/profile-report-full-baseline-ubuntu.txt new file mode 100644 index 0000000000..15ab2f544a --- /dev/null +++ b/docs/profiling-reports/profile-report-full-baseline-ubuntu.txt @@ -0,0 +1,238 @@ +Analyzing build trace from '/home/danbev/work/ai/llama.cpp/build-profile-full/clang_analysis.bin'... +**** Time summary: +Compilation (396 times): + Parsing (frontend): 811.0 s + Codegen & opts (backend): 692.2 s + +**** Files that took longest to parse (compiler frontend): + 9266 ms: /home/danbev/work/ai/llama.cpp/build-profile-full/tools/server/CMakeFiles/server-context.dir/server-context.cpp.o + 6956 ms: /home/danbev/work/ai/llama.cpp/build-profile-full/common/CMakeFiles/llama-common.dir/arg.cpp.o + 6881 ms: /home/danbev/work/ai/llama.cpp/build-profile-full/common/CMakeFiles/llama-common.dir/chat.cpp.o + 6738 ms: /home/danbev/work/ai/llama.cpp/build-profile-full/tools/server/CMakeFiles/llama-server-impl.dir/server-models.cpp.o + 6541 ms: /home/danbev/work/ai/llama.cpp/build-profile-full/common/CMakeFiles/llama-common.dir/json.cpp.o + 6446 ms: /home/danbev/work/ai/llama.cpp/build-profile-full/tools/server/CMakeFiles/server-context.dir/server-tools.cpp.o + 6289 ms: /home/danbev/work/ai/llama.cpp/build-profile-full/tests/CMakeFiles/gguf-model-data.dir/gguf-model-data.cpp.o + 6081 ms: /home/danbev/work/ai/llama.cpp/build-profile-full/tests/CMakeFiles/test-chat-peg-parser.dir/test-chat-peg-parser.cpp.o + 5900 ms: /home/danbev/work/ai/llama.cpp/build-profile-full/common/CMakeFiles/llama-common.dir/download.cpp.o + 5874 ms: /home/danbev/work/ai/llama.cpp/build-profile-full/src/CMakeFiles/llama.dir/unicode-data.cpp.o + +**** Files that took longest to codegen (compiler backend): + 42063 ms: /home/danbev/work/ai/llama.cpp/build-profile-full/tests/CMakeFiles/test-chat.dir/test-chat.cpp.o + 23793 ms: /home/danbev/work/ai/llama.cpp/build-profile-full/tests/CMakeFiles/test-jinja.dir/test-jinja.cpp.o + 23430 ms: /home/danbev/work/ai/llama.cpp/build-profile-full/tests/CMakeFiles/test-backend-ops.dir/test-backend-ops.cpp.o + 20616 ms: /home/danbev/work/ai/llama.cpp/build-profile-full/common/CMakeFiles/llama-common.dir/arg.cpp.o + 17714 ms: /home/danbev/work/ai/llama.cpp/build-profile-full/tests/CMakeFiles/test-chat-auto-parser.dir/test-chat-auto-parser.cpp.o + 17636 ms: /home/danbev/work/ai/llama.cpp/build-profile-full/common/CMakeFiles/llama-common.dir/chat.cpp.o + 16657 ms: /home/danbev/work/ai/llama.cpp/build-profile-full/vendor/cpp-httplib/CMakeFiles/cpp-httplib.dir/httplib.cpp.o + 16022 ms: /home/danbev/work/ai/llama.cpp/build-profile-full/tools/mtmd/CMakeFiles/mtmd.dir/mtmd-helper.cpp.o + 15606 ms: /home/danbev/work/ai/llama.cpp/build-profile-full/tests/CMakeFiles/test-chat-peg-parser.dir/test-chat-peg-parser.cpp.o + 14043 ms: /home/danbev/work/ai/llama.cpp/build-profile-full/tools/server/CMakeFiles/server-context.dir/server-context.cpp.o + +**** Templates that took longest to instantiate: + 21982 ms: std::basic_regex::_M_compile (42 times, avg 523 ms) + 21210 ms: std::__detail::_Compiler>::_Compiler (42 times, avg 505 ms) + 18203 ms: std::__detail::_Compiler>::_M_disjunction (42 times, avg 433 ms) + 18073 ms: std::__detail::_Compiler>::_M_alternative (42 times, avg 430 ms) + 17744 ms: std::__detail::_Compiler>::_M_term (42 times, avg 422 ms) + 15008 ms: std::__detail::_Compiler>::_M_atom (42 times, avg 357 ms) + 14516 ms: std::basic_regex::basic_regex, std::all... (29 times, avg 500 ms) + 7480 ms: std::basic_regex::basic_regex (14 times, avg 534 ms) + 6331 ms: std::__detail::__variant::_Copy_ctor_base>::_M_insert_charact... (42 times, avg 127 ms) + 4564 ms: std::unordered_map (306 times, avg 14 ms) + 3997 ms: std::__detail::__regex_algo_impl<__gnu_cxx::__normal_iterator, std::allocator (224 times, avg 15 ms) + 3414 ms: std::__detail::__variant::__gen_vtable_impl (172 times, avg 18 ms) + 3062 ms: std::unique_ptr (172 times, avg 17 ms) + 2979 ms: std::__uniq_ptr_data (224 times, avg 13 ms) + 2946 ms: std::__uniq_ptr_impl (224 times, avg 13 ms) + 2895 ms: std::unique_ptr (176 times, avg 16 ms) + 2894 ms: std::variant (174 times, avg 16 ms) + +**** Template sets that took longest to instantiate: + 61404 ms: std::unique_ptr<$> (3737 times, avg 16 ms) + 52144 ms: std::__uniq_ptr_data<$> (3737 times, avg 13 ms) + 51565 ms: std::__uniq_ptr_impl<$> (3737 times, avg 13 ms) + 41853 ms: std::__and_<$> (36597 times, avg 1 ms) + 25749 ms: std::tuple<$> (3998 times, avg 6 ms) + 23336 ms: std::vector<$> (8051 times, avg 2 ms) + 22439 ms: std::basic_regex<$>::_M_compile (43 times, avg 521 ms) + 21640 ms: std::__detail::_Compiler<$>::_Compiler (43 times, avg 503 ms) + 18807 ms: std::_Hashtable<$> (2122 times, avg 8 ms) + 18567 ms: std::__detail::_Compiler<$>::_M_disjunction (43 times, avg 431 ms) + 18434 ms: std::__detail::_Compiler<$>::_M_alternative (43 times, avg 428 ms) + 18098 ms: std::__detail::_Compiler<$>::_M_term (43 times, avg 420 ms) + 15357 ms: std::__detail::_Compiler<$>::_M_atom (43 times, avg 357 ms) + 15271 ms: std::unordered_map<$> (1141 times, avg 13 ms) + 14973 ms: std::basic_regex<$>::basic_regex<$> (30 times, avg 499 ms) + 14313 ms: std::__or_<$> (17720 times, avg 0 ms) + 12757 ms: std::_TupleConstraints<$>::__is_implicitly_constructible<$> (7998 times, avg 1 ms) + 12237 ms: std::_Vector_base<$> (7717 times, avg 1 ms) + 10406 ms: std::vector<$>::emplace_back<$> (1332 times, avg 7 ms) + 10329 ms: std::_Destroy<$> (3890 times, avg 2 ms) + 9801 ms: std::vector<$>::vector (1804 times, avg 5 ms) + 9786 ms: std::vector<$>::~vector (2906 times, avg 3 ms) + 9617 ms: std::function<$>::function<$> (1586 times, avg 6 ms) + 9275 ms: std::__do_visit<$> (91 times, avg 101 ms) + 9097 ms: std::pair<$> (3054 times, avg 2 ms) + 8804 ms: std::vector<$>::push_back (1151 times, avg 7 ms) + 8789 ms: std::__detail::__variant::__gen_vtable_impl<$>::_S_apply (91 times, avg 96 ms) + 8729 ms: std::__detail::__variant::__gen_vtable_impl<$>::_S_apply_all_alts<$> (91 times, avg 95 ms) + 8488 ms: std::__detail::__variant::__gen_vtable_impl<$>::_S_apply_single_alt<$> (1911 times, avg 4 ms) + 8206 ms: std::map<$> (1526 times, avg 5 ms) + +**** Functions that took longest to compile: + 4623 ms: common_params_parser_init(common_params&, llama_example, void (*)(in... (/home/danbev/work/ai/llama.cpp/common/arg.cpp) + 4332 ms: test_template_output_peg_parsers(bool) (/home/danbev/work/ai/llama.cpp/tests/test-chat.cpp) + 2044 ms: clip_model_loader::load_tensors(clip_ctx&) (/home/danbev/work/ai/llama.cpp/tools/mtmd/clip.cpp) + 1533 ms: make_test_cases_eval() (/home/danbev/work/ai/llama.cpp/tests/test-backend-ops.cpp) + 1502 ms: test_fuzzing(testing&) (/home/danbev/work/ai/llama.cpp/tests/test-jinja.cpp) + 1111 ms: clip_encode(clip_ctx*, clip_encode_params*) (/home/danbev/work/ai/llama.cpp/tools/mtmd/clip.cpp) + 1099 ms: test_array_methods(testing&) (/home/danbev/work/ai/llama.cpp/tests/test-jinja.cpp) + 1023 ms: test_gbnf_generation(testing&) (/home/danbev/work/ai/llama.cpp/tests/peg-parser/test-gbnf-generation.cpp) + 937 ms: make_test_cases_perf() (/home/danbev/work/ai/llama.cpp/tests/test-backend-ops.cpp) + 915 ms: test_basic(testing&)::$_2::operator()(testing&) const (/home/danbev/work/ai/llama.cpp/tests/peg-parser/test-basic.cpp) + 859 ms: test_filters(testing&) (/home/danbev/work/ai/llama.cpp/tests/test-jinja.cpp) + 687 ms: server_schema::make_llama_cmpl_schema(common_params const&, task_par... (/home/danbev/work/ai/llama.cpp/tools/server/server-schema.cpp) + 649 ms: server_task_result_cmpl_partial::to_json_oaicompat_resp() (/home/danbev/work/ai/llama.cpp/tools/server/server-task.cpp) + 635 ms: server_chat_convert_anthropic_to_oai(common_json const&) (/home/danbev/work/ai/llama.cpp/tools/server/server-chat.cpp) + 610 ms: test_python_dict_parser(testing&) (/home/danbev/work/ai/llama.cpp/tests/peg-parser/test-python-dict-parser.cpp) + 580 ms: common_chat_try_specialized_template(common_chat_template const&, st... (/home/danbev/work/ai/llama.cpp/common/chat.cpp) + 550 ms: server_task_result_cmpl_final::to_json_anthropic_stream() (/home/danbev/work/ai/llama.cpp/tools/server/server-task.cpp) + 541 ms: server_chat_convert_responses_to_chatcmpl(common_json const&) (/home/danbev/work/ai/llama.cpp/tools/server/server-chat.cpp) + 536 ms: analyze_template(std::__cxx11::basic_string, st... (/home/danbev/work/ai/llama.cpp/tests/test-json-schema-to-grammar.cpp) + 467 ms: ma_dr_flac__decode_samples_with_residual__rice__scalar(ma_dr_flac_bs... (/home/danbev/work/ai/llama.cpp/tools/mtmd/mtmd-helper.cpp) + 464 ms: create_tools() (/home/danbev/work/ai/llama.cpp/tests/test-chat-peg-parser.cpp) + 451 ms: llama_model_quantize_impl(std::__cxx11::basic_string::_M_expression_term<$>(std::__detai... (116 times, avg 20 ms) + 1778 ms: std::_Function_handler<$>::_M_manager(std::_Any_data&, std::_Any_dat... (1039 times, avg 1 ms) + 1371 ms: std::__detail::_BracketMatcher<$>::_BracketMatcher(std::__detail::_B... (116 times, avg 11 ms) + 1274 ms: std::vector<$>::~vector() (478 times, avg 2 ms) + 1242 ms: void std::__detail::_Compiler<$>::_M_insert_bracket_matcher<$>(bool) (116 times, avg 10 ms) + 1135 ms: std::__detail::_Compiler<$>::_M_quantifier() (29 times, avg 39 ms) + 920 ms: std::_Rb_tree<$>::_M_erase(std::_Rb_tree_node<$>*) (491 times, avg 1 ms) + 912 ms: void std::__detail::_Compiler<$>::_M_insert_character_class_matcher<... (116 times, avg 7 ms) + 878 ms: std::__detail::_Executor<$>::_M_dfs(std::__detail::_Executor<$>::_Ma... (70 times, avg 12 ms) + 874 ms: std::__detail::_BracketMatcher<$>::_M_make_range(char, char) (112 times, avg 7 ms) + 867 ms: std::_Function_handler<$>::_M_invoke(std::_Any_data const&, server_h... (48 times, avg 18 ms) + 854 ms: std::__detail::_BracketMatcher<$>::_M_add_character_class(std::__cxx... (116 times, avg 7 ms) + 827 ms: std::__detail::_BracketMatcher<$>::_M_add_equivalence_class(std::__c... (116 times, avg 7 ms) + 794 ms: void set_input_kq_mask_impl<$>(args_set_input_kq_mask const&, unsign... (2 times, avg 397 ms) + 776 ms: void set_input_kq_mask_impl<$>(args_set_input_kq_mask const&, float*) (2 times, avg 388 ms) + 755 ms: std::_Function_handler<$>::_M_invoke(std::_Any_data const&, common_c... (25 times, avg 30 ms) + 739 ms: std::__detail::_Executor<$>::_M_lookahead(long) (70 times, avg 10 ms) + 680 ms: std::_Function_handler<$>::_M_invoke(std::_Any_data const&) (110 times, avg 6 ms) + 675 ms: std::__detail::_BracketMatcher<$>::_M_ready() (112 times, avg 6 ms) + 645 ms: std::__detail::_StateSeq<$>::_M_clone() (29 times, avg 22 ms) + 637 ms: testing::print_result(std::__cxx11::basic_string<$> const&, int, int... (12 times, avg 53 ms) + 622 ms: std::__detail::_BracketMatcher<$>::_M_add_collate_element(std::__cxx... (116 times, avg 5 ms) + 591 ms: std::__detail::_Compiler<$>::_M_atom() (29 times, avg 20 ms) + 580 ms: common_chat_try_specialized_template(common_chat_template const&, st... (1 times, avg 580 ms) + 560 ms: std::vector<$>::_M_default_append(unsigned long) (93 times, avg 6 ms) + 546 ms: void (anonymous namespace)::tinyBLAS<$>::gemm<$>(long, long, long) (27 times, avg 20 ms) + 540 ms: void std::vector<$>::_M_range_insert<$>(__gnu_cxx::__normal_iterator... (48 times, avg 11 ms) + 536 ms: analyze_template(std::__cxx11::basic_string<$> const&) (1 times, avg 536 ms) + 533 ms: void std::vector<$>::_M_realloc_insert<$>(__gnu_cxx::__normal_iterat... (53 times, avg 10 ms) + 531 ms: bool std::__detail::__regex_algo_impl<$>(__gnu_cxx::__normal_iterato... (32 times, avg 16 ms) + +**** Expensive headers: +219629 ms: /home/danbev/work/ai/llama.cpp/src/models/models.h (included 152 times, avg 1444 ms), included via: + 151x: + 1x: llama-model.h + +208004 ms: /home/danbev/work/ai/llama.cpp/src/llama-model.h (included 169 times, avg 1230 ms), included via: + 151x: models.h + 2x: + 2x: llama-impl.h + 2x: llama.h + 1x: llama-memory-hybrid-idx.h + 1x: llama-kv-cache-dsa-iswa.h + ... + +205251 ms: /home/danbev/work/ai/llama.cpp/include/llama.h (included 320 times, avg 641 ms), included via: + 150x: models.h llama-model.h + 43x: models.h clip-graph.h clip.h mtmd.h + 18x: arg.h common.h llama-cpp.h + 15x: + 6x: tests.h testing.h common.h llama-cpp.h + 5x: common.h llama-cpp.h + ... + +68866 ms: /home/danbev/work/ai/llama.cpp/src/llama-graph.h (included 172 times, avg 400 ms), included via: + 150x: models.h llama-model.h llama.h + 2x: llama-impl.h llama-model.h + 1x: + 1x: llama-context.h llama.h + 1x: llama.h llama-context.h + 1x: llama-memory.h llama.h + ... + +66713 ms: /home/danbev/work/ai/llama.cpp/common/common.h (included 83 times, avg 803 ms), included via: + 18x: arg.h + 9x: llama.h + 6x: + 6x: tests.h testing.h + 3x: chat-auto-parser-helpers.h chat-auto-parser.h chat.h + 3x: testing.h + ... + +58734 ms: /home/danbev/work/ai/llama.cpp/tools/mtmd/models/models.h (included 44 times, avg 1334 ms), included via: + 43x: + 1x: clip.h + +48501 ms: /home/danbev/work/ai/llama.cpp/tools/mtmd/clip.h (included 48 times, avg 1010 ms), included via: + 43x: models.h clip-graph.h + 2x: + 1x: mtmd-image.h ggml.h clip-model.h + 1x: mtmd-audio.h ggml.h clip-model.h + 1x: testing.h mtmd-image.h clip-model.h + +43089 ms: /home/danbev/work/ai/llama.cpp/src/llama-arch.h (included 163 times, avg 264 ms), included via: + 150x: models.h llama-model.h llama.h + 2x: + 2x: llama-impl.h llama-model.h + 1x: models.h llama-model.h + 1x: llama-graph.h + 1x: llama-model.h llama.h + ... + +40560 ms: /home/danbev/work/ai/llama.cpp/common/chat.h (included 32 times, avg 1267 ms), included via: + 6x: tests.h testing.h chat-peg-parser.h + 4x: + 3x: chat-auto-parser-helpers.h chat-auto-parser.h + 2x: chat-peg-parser.h + 2x: chat-auto-parser.h + 2x: server-task.h server-common.h log.h + ... + +38337 ms: /home/danbev/work/ai/llama.cpp/ggml/include/ggml.h (included 344 times, avg 111 ms), included via: + 150x: models.h llama-model.h llama.h + 43x: models.h clip-graph.h + 18x: arg.h common.h llama-cpp.h llama.h + 16x: + 14x: llama.h + 6x: tests.h testing.h common.h llama-cpp.h llama.h + ... + + done in 0.2s. diff --git a/docs/profiling-reports/profile-report-full-mac.txt b/docs/profiling-reports/profile-report-full-mac.txt new file mode 100644 index 0000000000..267de50b39 --- /dev/null +++ b/docs/profiling-reports/profile-report-full-mac.txt @@ -0,0 +1,228 @@ +Analyzing build trace from '/Users/danbev/work/ai/llama.cpp/build-profile-full/clang_analysis.bin'... +**** Time summary: +Compilation (407 times): + Parsing (frontend): 265.7 s + Codegen & opts (backend): 209.7 s + +**** Files that took longest to parse (compiler frontend): + 2896 ms: /Users/danbev/work/ai/llama.cpp/build-profile-full/tools/ui/CMakeFiles/llama-ui.dir/ui.cpp.o + 2826 ms: /Users/danbev/work/ai/llama.cpp/build-profile-full/tools/server/CMakeFiles/llama-server-impl.dir/server-models.cpp.o + 2360 ms: /Users/danbev/work/ai/llama.cpp/build-profile-full/tools/server/CMakeFiles/server-context.dir/server-context.cpp.o + 2210 ms: /Users/danbev/work/ai/llama.cpp/build-profile-full/vendor/cpp-httplib/CMakeFiles/cpp-httplib.dir/httplib.cpp.o + 2094 ms: /Users/danbev/work/ai/llama.cpp/build-profile-full/tools/server/CMakeFiles/llama-server-impl.dir/server.cpp.o + 2049 ms: /Users/danbev/work/ai/llama.cpp/build-profile-full/common/CMakeFiles/llama-common.dir/chat.cpp.o + 1950 ms: /Users/danbev/work/ai/llama.cpp/build-profile-full/tools/server/CMakeFiles/llama-server-impl.dir/server-http.cpp.o + 1930 ms: /Users/danbev/work/ai/llama.cpp/build-profile-full/tools/server/CMakeFiles/server-context.dir/server-tools.cpp.o + 1925 ms: /Users/danbev/work/ai/llama.cpp/build-profile-full/common/CMakeFiles/llama-common.dir/arg.cpp.o + 1879 ms: /Users/danbev/work/ai/llama.cpp/build-profile-full/tests/CMakeFiles/test-peg-parser.dir/peg-parser/test-gbnf-generation.cpp.o + +**** Files that took longest to codegen (compiler backend): + 8830 ms: /Users/danbev/work/ai/llama.cpp/build-profile-full/tests/CMakeFiles/test-backend-ops.dir/test-backend-ops.cpp.o + 7873 ms: /Users/danbev/work/ai/llama.cpp/build-profile-full/tests/CMakeFiles/test-chat.dir/test-chat.cpp.o + 6536 ms: /Users/danbev/work/ai/llama.cpp/build-profile-full/vendor/cpp-httplib/CMakeFiles/cpp-httplib.dir/httplib.cpp.o + 5706 ms: /Users/danbev/work/ai/llama.cpp/build-profile-full/common/CMakeFiles/llama-common.dir/chat.cpp.o + 5336 ms: /Users/danbev/work/ai/llama.cpp/build-profile-full/common/CMakeFiles/llama-common.dir/arg.cpp.o + 4720 ms: /Users/danbev/work/ai/llama.cpp/build-profile-full/tests/CMakeFiles/test-jinja.dir/test-jinja.cpp.o + 4636 ms: /Users/danbev/work/ai/llama.cpp/build-profile-full/tools/mtmd/CMakeFiles/mtmd.dir/mtmd-helper.cpp.o + 4145 ms: /Users/danbev/work/ai/llama.cpp/build-profile-full/tools/server/CMakeFiles/server-context.dir/server-context.cpp.o + 4103 ms: /Users/danbev/work/ai/llama.cpp/build-profile-full/tests/CMakeFiles/test-chat-auto-parser.dir/test-chat-auto-parser.cpp.o + 4012 ms: /Users/danbev/work/ai/llama.cpp/build-profile-full/tests/CMakeFiles/test-chat-peg-parser.dir/test-chat-peg-parser.cpp.o + +**** Templates that took longest to instantiate: + 3123 ms: std::basic_regex::basic_regex, std::all... (29 times, avg 107 ms) + 3117 ms: std::basic_regex::__init> (29 times, avg 107 ms) + 3100 ms: std::basic_regex::__parse> (29 times, avg 106 ms) + 2589 ms: std::__variant_detail::__copy_constructor::__parse_ecma_exp::__parse_alternative::__parse_term> (29 times, avg 82 ms) + 1476 ms: std::basic_regex::__parse_atom> (29 times, avg 50 ms) + 1171 ms: std::unordered_map, std::vector> (172 times, avg 6 ms) + 1096 ms: std::basic_regex::basic_regex (17 times, avg 64 ms) + 1092 ms: std::basic_regex::__init (17 times, avg 64 ms) + 1089 ms: std::basic_regex::__parse (17 times, avg 64 ms) + 1042 ms: std::basic_regex::__push_lookahead (41 times, avg 25 ms) + 1039 ms: std::__lookahead>::__lookahead (41 times, avg 25 ms) + 1035 ms: std::__lookahead>::__exec (41 times, avg 25 ms) + 1012 ms: std::vector::vector (176 times, avg 5 ms) + 996 ms: std::unordered_map (185 times, avg 5 ms) + 971 ms: std::__hash_table, std::vect... (172 times, avg 5 ms) + 969 ms: std::unordered_map (166 times, avg 5 ms) + 956 ms: std::basic_regex::__parse_ecma_exp (17 times, avg 56 ms) + 950 ms: std::__variant_detail::__visitation::__base::__visit_alt_at<(lambda ... (34 times, avg 27 ms) + 947 ms: std::basic_regex::__parse_alternative (17 times, avg 55 ms) + 947 ms: std::basic_regex::__parse_term (17 times, avg 55 ms) + 940 ms: std::__variant_detail::__visitation::__base::__make_fdiagonal<(lambd... (34 times, avg 27 ms) + 933 ms: std::__variant_detail::__visitation::__base::__make_fdiagonal_impl<(... (34 times, avg 27 ms) + 926 ms: std::basic_regex::__match_at_start_ecma (386 times, avg 2 ms) + 855 ms: std::basic_string (386 times, avg 2 ms) + 845 ms: std::unordered_map (172 times, avg 4 ms) + +**** Template sets that took longest to instantiate: + 11404 ms: std::vector<$> (7951 times, avg 1 ms) + 7273 ms: std::allocator_traits<$> (8688 times, avg 0 ms) + 5682 ms: std::unordered_map<$> (1002 times, avg 5 ms) + 5545 ms: std::vector<$>::vector (1462 times, avg 3 ms) + 5461 ms: std::__hash_table<$> (1252 times, avg 4 ms) + 5198 ms: std::map<$> (1480 times, avg 3 ms) + 4950 ms: std::function<$>::function<$> (889 times, avg 5 ms) + 4846 ms: std::__function::__value_func<$>::__value_func<$> (889 times, avg 5 ms) + 4555 ms: std::vector<$>::__construct_at_end<$> (1413 times, avg 3 ms) + 4529 ms: std::vector<$>::emplace_back<$> (1243 times, avg 3 ms) + 4335 ms: std::basic_regex<$>::__init<$> (47 times, avg 92 ms) + 4314 ms: std::basic_regex<$>::__parse<$> (47 times, avg 91 ms) + 4132 ms: std::__tree<$> (1895 times, avg 2 ms) + 4028 ms: std::vector<$>::__init_with_size<$> (995 times, avg 4 ms) + 3934 ms: std::unique_ptr<$> (4148 times, avg 0 ms) + 3634 ms: std::__uninitialized_allocator_copy<$> (1226 times, avg 2 ms) + 3597 ms: std::basic_string<$> (1638 times, avg 2 ms) + 3537 ms: std::basic_regex<$>::__parse_ecma_exp<$> (47 times, avg 75 ms) + 3483 ms: std::vector<$>::__swap_out_circular_buffer (1565 times, avg 2 ms) + 3474 ms: std::basic_regex<$>::__parse_alternative<$> (47 times, avg 73 ms) + 3463 ms: std::basic_regex<$>::__parse_term<$> (47 times, avg 73 ms) + 3454 ms: std::vector<$>::__emplace_back_slow_path<$> (1009 times, avg 3 ms) + 3447 ms: std::vector<$>::push_back (903 times, avg 3 ms) + 3249 ms: std::basic_regex<$>::basic_regex<$> (30 times, avg 108 ms) + 2989 ms: std::basic_string<$>::basic_string (1615 times, avg 1 ms) + 2681 ms: std::basic_string<$>::__init (1545 times, avg 1 ms) + 2600 ms: std::__variant_detail::__ctor<$>::__generic_construct<$> (35 times, avg 74 ms) + 2589 ms: std::__variant_detail::__copy_constructor<$>::__copy_constructor (34 times, avg 76 ms) + 2291 ms: std::__exception_guard_exceptions<$>::~__exception_guard_exceptions (2134 times, avg 1 ms) + 2275 ms: std::__copy<$> (952 times, avg 2 ms) + +**** Functions that took longest to compile: + 2744 ms: test_template_output_peg_parsers(bool) (/Users/danbev/work/ai/llama.cpp/tests/test-chat.cpp) + 1008 ms: make_test_cases_eval() (/Users/danbev/work/ai/llama.cpp/tests/test-backend-ops.cpp) + 957 ms: common_params_parser_init(common_params&, llama_example, void (*)(in... (/Users/danbev/work/ai/llama.cpp/common/arg.cpp) + 567 ms: clip_model_loader::load_tensors(clip_ctx&) (/Users/danbev/work/ai/llama.cpp/tools/mtmd/clip.cpp) + 404 ms: test_gbnf_generation(testing&) (/Users/danbev/work/ai/llama.cpp/tests/peg-parser/test-gbnf-generation.cpp) + 354 ms: clip_encode(clip_ctx*, clip_encode_params*) (/Users/danbev/work/ai/llama.cpp/tools/mtmd/clip.cpp) + 336 ms: test_basic(testing&)::$_2::operator()(testing&) const (/Users/danbev/work/ai/llama.cpp/tests/peg-parser/test-basic.cpp) + 305 ms: test_fuzzing(testing&) (/Users/danbev/work/ai/llama.cpp/tests/test-jinja.cpp) + 289 ms: make_test_cases_perf() (/Users/danbev/work/ai/llama.cpp/tests/test-backend-ops.cpp) + 171 ms: test_python_dict_parser(testing&) (/Users/danbev/work/ai/llama.cpp/tests/peg-parser/test-python-dict-parser.cpp) + 169 ms: test_array_methods(testing&) (/Users/danbev/work/ai/llama.cpp/tests/test-jinja.cpp) + 157 ms: test_json_parser(testing&) (/Users/danbev/work/ai/llama.cpp/tests/peg-parser/test-json-parser.cpp) + 146 ms: parse_cmd_params(int, char**) (/Users/danbev/work/ai/llama.cpp/tools/llama-bench/llama-bench.cpp) + 144 ms: llama_server(common_params&, int, char**) (/Users/danbev/work/ai/llama.cpp/tools/server/server.cpp) + 141 ms: ma_flac_ds_read(void*, void*, unsigned long long, unsigned long long*) (/Users/danbev/work/ai/llama.cpp/tools/mtmd/mtmd-helper.cpp) + 139 ms: server_chat_convert_responses_to_chatcmpl(common_json const&) (/Users/danbev/work/ai/llama.cpp/tools/server/server-chat.cpp) + 137 ms: common_chat_try_specialized_template(common_chat_template const&, st... (/Users/danbev/work/ai/llama.cpp/common/chat.cpp) + 133 ms: test_handcrafted_file(unsigned int) (/Users/danbev/work/ai/llama.cpp/tests/test-gguf.cpp) + 132 ms: server_chat_convert_anthropic_to_oai(common_json const&) (/Users/danbev/work/ai/llama.cpp/tools/server/server-chat.cpp) + 130 ms: test_init(testing&) (/Users/danbev/work/ai/llama.cpp/tests/test-batch-alloc.cpp) + 130 ms: llama_vocab::impl::load(llama_model_loader&, LLM_KV const&) (/Users/danbev/work/ai/llama.cpp/src/llama-vocab.cpp) + 125 ms: void set_input_kq_mask_impl(args_set_input_kq_mask const&, fl... (/Users/danbev/work/ai/llama.cpp/src/llama-kv-cache.cpp) + 122 ms: llama_model_base::load_tensors(llama_model_loader&) (/Users/danbev/work/ai/llama.cpp/src/llama-model.cpp) + 121 ms: llm_chat_apply_template(llm_chat_template, std::__1::vector::__match_at_start_posix_nosubs<$>(char... (33 times, avg 15 ms) + 343 ms: std::__1::__wrap_iter<$> std::__1::vector<$>::__insert_with_size[abi... (45 times, avg 7 ms) + 285 ms: bool std::__1::basic_regex<$>::__match_at_start_posix_subs<$>(char c... (33 times, avg 8 ms) + 278 ms: std::__1::__bracket_expression<$>::__exec(std::__1::__state<$>&) const (29 times, avg 9 ms) + 246 ms: void (anonymous namespace)::tinyBLAS<$>::gemm<$>(long long, long lon... (36 times, avg 6 ms) + 189 ms: bool std::__1::basic_regex<$>::__match_at_start_ecma<$>(char const*,... (33 times, avg 5 ms) + 163 ms: std::__1::vector<$>::__append(unsigned long) (139 times, avg 1 ms) + 161 ms: ggml::cpu::repack::tensor_traits<$>::forward_mul_mat(ggml_compute_pa... (16 times, avg 10 ms) + 159 ms: void std::__1::__tree_balance_after_insert[abi:ne200100]<$>(std::__1... (119 times, avg 1 ms) + 144 ms: std::__1::deque<$>::__add_back_capacity() (39 times, avg 3 ms) + 138 ms: void std::__1::vector<$>::__assign_with_size[abi:ne200100]<$>(std::_... (38 times, avg 3 ms) + 137 ms: common_chat_try_specialized_template(common_chat_template const&, st... (1 times, avg 137 ms) + 129 ms: std::__1::vector<$>::~vector[abi:ne200100]() (145 times, avg 0 ms) + 128 ms: std::__1::deque<$>::__add_front_capacity() (35 times, avg 3 ms) + 127 ms: std::__1::__bracket_expression<$>::__add_range[abi:ne200100](std::__... (29 times, avg 4 ms) + 125 ms: void set_input_kq_mask_impl<$>(args_set_input_kq_mask const&, float*... (1 times, avg 125 ms) + 121 ms: llm_chat_apply_template(llm_chat_template, std::__1::vector<$> const... (1 times, avg 121 ms) + 111 ms: void std::__1::__hash_table<$>::__do_rehash<$>(unsigned long) (85 times, avg 1 ms) + 110 ms: ggml::cpu::repack::tensor_traits<$>::forward_mul_mat_id(ggml_compute... (16 times, avg 6 ms) + 106 ms: std::__1::__loop<$>::__exec(std::__1::__state<$>&) const (29 times, avg 3 ms) + 104 ms: test_all(std::__1::basic_string<$> const&, std::__1::function<$>) (1 times, avg 104 ms) + 103 ms: void set_input_kq_mask_impl<$>(args_set_input_kq_mask const&, unsign... (1 times, avg 103 ms) + 96 ms: std::__1::__exception_guard_exceptions<$>::~__exception_guard_except... (111 times, avg 0 ms) + 95 ms: unicode_regex_split(std::__1::basic_string<$> const&, std::__1::vect... (1 times, avg 95 ms) + 94 ms: char const* std::__1::basic_regex<$>::__parse_expression_term<$>(cha... (17 times, avg 5 ms) + 93 ms: std::__1::__function::__func<$>::target(std::type_info const&) const (125 times, avg 0 ms) + 92 ms: unicode_regex_split_custom(std::__1::basic_string<$> const&, std::__... (1 times, avg 92 ms) + 90 ms: dsv4_build_comp_plans(std::__1::vector<$> const&, unsigned int, bool... (1 times, avg 90 ms) + 88 ms: std::__1::vector<$>::assign(unsigned long, std::__1::sub_match<$> co... (34 times, avg 2 ms) + 85 ms: std::__1::__murmur2_or_cityhash::operator()[abi... (29 times, avg 2 ms) + +**** Expensive headers: +71656 ms: /Users/danbev/work/ai/llama.cpp/src/models/models.h (included 152 times, avg 471 ms), included via: + 152x: + +64040 ms: /Users/danbev/work/ai/llama.cpp/src/llama-model.h (included 169 times, avg 378 ms), included via: + 151x: models.h + 18x: + +47893 ms: /Users/danbev/work/ai/llama.cpp/src/llama-arch.h (included 176 times, avg 272 ms), included via: + 151x: models.h llama-model.h + 4x: llama-model.h + 3x: llama-memory.h llama-graph.h + 2x: + 2x: llama-model-loader.h + 2x: llama-context.h llama-graph.h + ... + +42695 ms: /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/string (included 386 times, avg 110 ms), included via: + 150x: models.h llama-model.h llama-arch.h + 43x: models.h clip-graph.h clip.h mtmd.h map functional vector locale __locale + 19x: arg.h common.h list functional vector locale __locale + 16x: common.h list functional vector locale __locale + 15x: ggml-impl.h vector locale __locale + 10x: + ... + +36571 ms: /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/functional (included 349 times, avg 104 ms), included via: + 151x: models.h llama-model.h llama-arch.h set + 43x: models.h clip-graph.h clip.h mtmd.h map + 20x: common.h list + 19x: arg.h common.h list + 6x: llama-grammar.h map + 5x: tests.h json.h map + ... + +30365 ms: /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/vector (included 377 times, avg 80 ms), included via: + 151x: models.h llama-model.h llama-arch.h set functional + 43x: models.h clip-graph.h clip.h mtmd.h map functional + 19x: arg.h common.h list functional + 16x: common.h list functional + 15x: ggml-impl.h + 6x: + ... + +29586 ms: /Users/danbev/work/ai/llama.cpp/common/common.h (included 84 times, avg 352 ms), included via: + 25x: + 23x: arg.h + 7x: tests.h testing.h + 3x: chat-auto-parser-helpers.h chat-auto-parser.h chat.h + 3x: testing.h + 2x: server-task.h + ... + +25740 ms: /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/algorithm (included 386 times, avg 66 ms), included via: + 150x: models.h llama-model.h llama-arch.h string string_view + 43x: models.h clip-graph.h clip.h mtmd.h map functional boyer_moore_searcher.h array + 19x: arg.h common.h list + 16x: common.h list + 15x: ggml-impl.h array + 9x: string string_view + ... + +20790 ms: /Users/danbev/work/ai/llama.cpp/tools/mtmd/models/models.h (included 44 times, avg 472 ms), included via: + 44x: + +20453 ms: /Users/danbev/work/ai/llama.cpp/tools/mtmd/clip-graph.h (included 44 times, avg 464 ms), included via: + 43x: models.h + 1x: + + done in 0.1s. diff --git a/scripts/build-profile-baseline.sh b/scripts/build-profile-baseline.sh index edf488d25c..4cbc992e23 100755 --- a/scripts/build-profile-baseline.sh +++ b/scripts/build-profile-baseline.sh @@ -3,7 +3,7 @@ # # Requires ClangBuildAnalyzer: # Install mac: brew install clang-build-analyzer -# Install linux: TODO +# Install linux: https://github.com/aras-p/ClangBuildAnalyzer.git set -euo pipefail @@ -89,8 +89,7 @@ find "${BUILD_DIR}" -name "*.json" ! -name "compile_commands.json" \ | xargs ls -l 2>/dev/null \ | awk 'NF>5 {print $5, $NF}' \ | sort -rn \ - | head -20 \ - | awk '{printf "%8.1f KB %s\n", $1/1024, $2}' + | awk 'NR<=20 {printf "%8.1f KB %s\n", $1/1024, $2}' echo echo "ClangBuildAnalyzer report was generated: ${BUILD_DIR}/profile-report.txt" diff --git a/scripts/build-profile-full.sh b/scripts/build-profile-full.sh index 62c99adb11..bed258cfcb 100755 --- a/scripts/build-profile-full.sh +++ b/scripts/build-profile-full.sh @@ -3,7 +3,7 @@ # # Requires ClangBuildAnalyzer: # Install mac: brew install clang-build-analyzer -# Install linux: TODO +# Install linux: https://github.com/aras-p/ClangBuildAnalyzer.git set -euo pipefail