char-fork/llama.cpp
git clone https://git.t4t.associates/char-fork/llama.cpp
3bcfeb700
char/aliceai-t5-moe
1# Compile-time profiling using clang -ftime-trace + ClangBuildAnalyzer. 2# 3# Usage: 4# .\scripts\build-profile.ps1 [-Full] [-Jobs N] 5# 6# -Full : include Server, Tools, and Tests (default: minimal build) 7# -Jobs : number of parallel jobs (default: all cores) 8# 9# Requires ClangBuildAnalyzer: 10# https://github.com/aras-p/ClangBuildAnalyzer 11 12param ( 13 [switch ]$Full , 14 [int ]$Jobs = [Environment ]::ProcessorCount 15) 16 17$ErrorActionPreference ="Stop" 18 19$ScriptDir =Split-Path -Parent$MyInvocation .MyCommand .Path 20$RootDir =Split-Path -Parent$ScriptDir 21 22if ($Full ) { 23$BuildDir =Join-Path $RootDir "build-profile-full" 24$Report =Join-Path $BuildDir "profile-report-full.txt" 25}else { 26$BuildDir =Join-Path $RootDir "build-profile-baseline" 27$Report =Join-Path $BuildDir "profile-report.txt" 28} 29 30$OutputBin =Join-Path $BuildDir "clang_analysis.bin" 31 32if (-not (Get-Command clang++ -ErrorAction SilentlyContinue)) { 33Write-Error "clang++ not found" 34exit 1 35} 36 37if (-not (Get-Command ninja -ErrorAction SilentlyContinue)) { 38Write-Error "ninja not found (required so cmake does not fall back to the Visual Studio/MSVC generator)" 39exit 1 40} 41 42if (-not (Get-Command ClangBuildAnalyzer -ErrorAction SilentlyContinue)) { 43Write-Error "ClangBuildAnalyzer not found`n https://github.com/aras-p/ClangBuildAnalyzer/releases" 44exit 1 45} 46 47$ClangVer = (clang++ --version |Select-Object -First1 ) 48Write-Host "compiler : $ClangVer " 49Write-Host "build dir: $BuildDir " 50Write-Host "output : $OutputBin " 51Write-Host "jobs : $Jobs " 52Write-Host "" 53 54if (Get-Command ccache -ErrorAction SilentlyContinue) { 55Write-Host "clearing ccache..." 56ccache -C -z 57} 58 59$env:CCACHE_DISABLE ="1" 60 61$TestsFlag =if ($Full ) {"ON" }else {"OFF" } 62$ToolsFlag =if ($Full ) {"ON" }else {"OFF" } 63$ServerFlag =if ($Full ) {"ON" }else {"OFF" } 64 65cmake --fresh ` 66 -S$RootDir ` 67 -B$BuildDir ` 68 -G"Ninja" ` 69 -DCMAKE_BUILD_TYPE=Release ` 70- DCMAKE_C_COMPILER=clang ` 71- DCMAKE_CXX_COMPILER=clang++ ` 72- DCMAKE_C_FLAGS="-ftime- trace" ` 73- DCMAKE_CXX_FLAGS="-ftime- trace" ` 74- DGGML_CCACHE=OFF ` 75- DGGML_OPENMP=ON ` 76- DGGML_NATIVE=OFF ` 77 "- DLLAMA_BUILD_TESTS=$TestsFlag" ` 78- DLLAMA_BUILD_EXAMPLES=OFF ` 79 "- DLLAMA_BUILD_TOOLS=$ToolsFlag" ` 80 "- DLLAMA_BUILD_SERVER=$ServerFlag" ` 81- DLLAMA_BUILD_APP=OFF 82 83if ($LASTEXITCODE -ne 0 ) {exit $LASTEXITCODE } 84 85$StrayTrace =Join-Path $RootDir "-.json" 86if (Test-Path $StrayTrace ) { 87Remove-Item $StrayTrace -Force 88} 89 90Write-Host "" 91Write-Host "Initializing ClangBuildAnalyzer..." 92ClangBuildAnalyzer --start$BuildDir 93Write-Host "" 94 95Write-Host "building..." 96Write-Host "" 97 98$StartTime =Get-Date 99 100cmake --build$BuildDir --clean-first -j$Jobs 101 102if ($LASTEXITCODE -ne 0 ) {exit $LASTEXITCODE } 103 104$Elapsed = (Get-Date )- $StartTime 105 106Write-Host "" 107Write-Host ("build time: {0}s ({1}m {2}s)" -f [int ]$Elapsed .TotalSeconds , [int ]$Elapsed .TotalMinutes ,$Elapsed .Seconds ) 108Write-Host "" 109 110Write-Host "Aggregating profile metrics..." 111ClangBuildAnalyzer --stop$BuildDir $OutputBin |Out-Null 112 113Write-Host "" 114Write-Host ("=" * 80 ) 115 116$TUs ="?" 117if (Test-Path $Report ) { 118$Match =Select-String -Path$Report -Pattern"Compilation \((\d+)" |Select-Object -First1 119if ($Match ) {$TUs =$Match .Matches [0 ].Groups [1 ].Value } 120} 121 122ClangBuildAnalyzer --analyze$OutputBin |Tee-Object -FilePath$Report 123 124Write-Host "" 125Write-Host "translation units: $TUs " 126Write-Host "" 127Write-Host "largest trace files (top 20 by size):" 128 129Get-ChildItem -Path$BuildDir -Recurse -Filter"*.json" | 130Where-Object {$_ .Name -ne "compile_commands.json" } | 131Sort-Object Length -Descending | 132Select-Object -First20 | 133 ForEach-Object {"{0,8:F1} KB {1}" -f ($_ .Length / 1024 ),$_ .FullName } 134 135Write-Host "" 136Write-Host "ClangBuildAnalyzer report was generated: $Report "