Safetensors
GGUF
File size: 3,823 Bytes
572ef52
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# Compile-time profiling using clang -ftime-trace + ClangBuildAnalyzer.
#
# Usage:
#   .\scripts\build-profile.ps1 [-Full] [-Jobs N]
#
# -Full : include Server, Tools, and Tests (default: minimal build)
# -Jobs :  number of parallel jobs (default: all cores)
#
# Requires ClangBuildAnalyzer:
#   https://github.com/aras-p/ClangBuildAnalyzer

param(
    [switch]$Full,
    [int]$Jobs = [Environment]::ProcessorCount
)

$ErrorActionPreference = "Stop"

$ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
$RootDir = Split-Path -Parent $ScriptDir

if ($Full) {
    $BuildDir = Join-Path $RootDir "build-profile-full"
    $Report = Join-Path $BuildDir "profile-report-full.txt"
} else {
    $BuildDir = Join-Path $RootDir "build-profile-baseline"
    $Report = Join-Path $BuildDir "profile-report.txt"
}

$OutputBin = Join-Path $BuildDir "clang_analysis.bin"

if (-not (Get-Command clang++ -ErrorAction SilentlyContinue)) {
    Write-Error "clang++ not found"
    exit 1
}

if (-not (Get-Command ninja -ErrorAction SilentlyContinue)) {
    Write-Error "ninja not found (required so cmake does not fall back to the Visual Studio/MSVC generator)"
    exit 1
}

if (-not (Get-Command ClangBuildAnalyzer -ErrorAction SilentlyContinue)) {
    Write-Error "ClangBuildAnalyzer not found`n  https://github.com/aras-p/ClangBuildAnalyzer/releases"
    exit 1
}

$ClangVer = (clang++ --version | Select-Object -First 1)
Write-Host "compiler : $ClangVer"
Write-Host "build dir: $BuildDir"
Write-Host "output   : $OutputBin"
Write-Host "jobs     : $Jobs"
Write-Host ""

if (Get-Command ccache -ErrorAction SilentlyContinue) {
    Write-Host "clearing ccache..."
    ccache -C -z
}

$env:CCACHE_DISABLE = "1"

$TestsFlag = if ($Full) { "ON" } else { "OFF" }
$ToolsFlag = if ($Full) { "ON" } else { "OFF" }
$ServerFlag = if ($Full) { "ON" } else { "OFF" }

cmake --fresh `
    -S $RootDir `
    -B $BuildDir `
    -G "Ninja" `
    -DCMAKE_BUILD_TYPE=Release `
    -DCMAKE_C_COMPILER=clang `
    -DCMAKE_CXX_COMPILER=clang++ `
    -DCMAKE_C_FLAGS="-ftime-trace" `
    -DCMAKE_CXX_FLAGS="-ftime-trace" `
    -DGGML_CCACHE=OFF `
    -DGGML_OPENMP=ON `
    -DGGML_NATIVE=OFF `
    "-DLLAMA_BUILD_TESTS=$TestsFlag" `
    -DLLAMA_BUILD_EXAMPLES=OFF `
    "-DLLAMA_BUILD_TOOLS=$ToolsFlag" `
    "-DLLAMA_BUILD_SERVER=$ServerFlag" `
    -DLLAMA_BUILD_APP=OFF

if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }

$StrayTrace = Join-Path $RootDir "-.json"
if (Test-Path $StrayTrace) {
    Remove-Item $StrayTrace -Force
}

Write-Host ""
Write-Host "Initializing ClangBuildAnalyzer..."
ClangBuildAnalyzer --start $BuildDir
Write-Host ""

Write-Host "building..."
Write-Host ""

$StartTime = Get-Date

cmake --build $BuildDir --clean-first -j $Jobs

if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }

$Elapsed = (Get-Date) - $StartTime

Write-Host ""
Write-Host ("build time: {0}s ({1}m {2}s)" -f [int]$Elapsed.TotalSeconds, [int]$Elapsed.TotalMinutes, $Elapsed.Seconds)
Write-Host ""

Write-Host "Aggregating profile metrics..."
ClangBuildAnalyzer --stop $BuildDir $OutputBin | Out-Null

Write-Host ""
Write-Host ("=" * 80)

$TUs = "?"
if (Test-Path $Report) {
    $Match = Select-String -Path $Report -Pattern "Compilation \((\d+)" | Select-Object -First 1
    if ($Match) { $TUs = $Match.Matches[0].Groups[1].Value }
}

ClangBuildAnalyzer --analyze $OutputBin | Tee-Object -FilePath $Report

Write-Host ""
Write-Host "translation units: $TUs"
Write-Host ""
Write-Host "largest trace files (top 20 by size):"

Get-ChildItem -Path $BuildDir -Recurse -Filter "*.json" |
    Where-Object { $_.Name -ne "compile_commands.json" } |
    Sort-Object Length -Descending |
    Select-Object -First 20 |
    ForEach-Object { "{0,8:F1} KB  {1}" -f ($_.Length / 1024), $_.FullName }

Write-Host ""
Write-Host "ClangBuildAnalyzer report was generated: $Report"