79 lines
2.9 KiB
PowerShell
79 lines
2.9 KiB
PowerShell
param(
|
|
[string]$SourceHlsDir,
|
|
[string]$WorkRoot = "C:\hls_tiny_cnn_work",
|
|
[string]$HlsBat = "F:\ZYNQ_\Vitis_HLS\2020.2\bin\vitis_hls.bat",
|
|
[string]$VivadoBat = "F:\ZYNQ_\Vivado\2020.2\bin\vivado.bat"
|
|
)
|
|
|
|
$ErrorActionPreference = "Stop"
|
|
|
|
function Copy-TreeItem {
|
|
param(
|
|
[Parameter(Mandatory = $true)][string]$Source,
|
|
[Parameter(Mandatory = $true)][string]$Destination
|
|
)
|
|
if (Test-Path -LiteralPath $Source) {
|
|
Copy-Item -LiteralPath $Source -Destination $Destination -Recurse -Force
|
|
}
|
|
}
|
|
|
|
$sourcePath = [System.IO.Path]::GetFullPath($SourceHlsDir)
|
|
$workRootPath = [System.IO.Path]::GetFullPath($WorkRoot)
|
|
$workHlsDir = Join-Path $workRootPath "hls_cnn"
|
|
|
|
if (-not (Test-Path -LiteralPath $sourcePath -PathType Container)) {
|
|
throw "Source HLS directory not found: $sourcePath"
|
|
}
|
|
if (-not (Test-Path -LiteralPath $HlsBat -PathType Leaf)) {
|
|
throw "Vitis HLS not found: $HlsBat"
|
|
}
|
|
if (-not (Test-Path -LiteralPath $VivadoBat -PathType Leaf)) {
|
|
throw "Vivado not found: $VivadoBat"
|
|
}
|
|
if ($workRootPath -notmatch '^[A-Za-z]:\\hls_tiny_cnn_work$') {
|
|
throw "Refusing to use unexpected work root: $workRootPath"
|
|
}
|
|
|
|
New-Item -ItemType Directory -Force -Path $workRootPath | Out-Null
|
|
if (Test-Path -LiteralPath $workHlsDir) {
|
|
Remove-Item -LiteralPath $workHlsDir -Recurse -Force
|
|
}
|
|
New-Item -ItemType Directory -Force -Path $workHlsDir | Out-Null
|
|
|
|
foreach ($dir in @("include", "scripts", "src", "tb")) {
|
|
Copy-TreeItem -Source (Join-Path $sourcePath $dir) -Destination $workHlsDir
|
|
}
|
|
foreach ($file in @("README.md", "export_weights.py")) {
|
|
Copy-TreeItem -Source (Join-Path $sourcePath $file) -Destination $workHlsDir
|
|
}
|
|
|
|
Write-Host "Running Vitis HLS in ASCII work directory:"
|
|
Write-Host " $workHlsDir"
|
|
& $HlsBat -f (Join-Path $workHlsDir "scripts\run_hls.tcl")
|
|
if ($LASTEXITCODE -ne 0) {
|
|
throw "Vitis HLS failed with exit code $LASTEXITCODE"
|
|
}
|
|
|
|
$ipDir = Join-Path $workHlsDir "build\tiny_cnn_hls\solution1\impl\ip"
|
|
& powershell.exe -NoProfile -ExecutionPolicy Bypass -File (Join-Path $workHlsDir "scripts\patch_and_pack_ip.ps1") -IpDir $ipDir -VivadoBat $VivadoBat -Revision 1 -ArchiveName "xilinx_com_hls_tiny_cnn_accel_1_0.zip"
|
|
if ($LASTEXITCODE -ne 0) {
|
|
throw "IP patch/package step failed with exit code $LASTEXITCODE"
|
|
}
|
|
|
|
foreach ($dir in @("build", "ip_repo")) {
|
|
$from = Join-Path $workHlsDir $dir
|
|
if (Test-Path -LiteralPath $from) {
|
|
Copy-TreeItem -Source $from -Destination $sourcePath
|
|
}
|
|
}
|
|
|
|
$zip = Join-Path $ipDir "xilinx_com_hls_tiny_cnn_accel_1_0.zip"
|
|
if (Test-Path -LiteralPath $zip) {
|
|
$repoDir = Join-Path $sourcePath "ip_repo"
|
|
New-Item -ItemType Directory -Force -Path $repoDir | Out-Null
|
|
Copy-Item -LiteralPath $zip -Destination (Join-Path $repoDir "tiny_cnn_accel.zip") -Force
|
|
}
|
|
|
|
Write-Host "HLS build completed. Generated IP directory:"
|
|
Write-Host " $(Join-Path $sourcePath 'build\tiny_cnn_hls\solution1\impl\ip')"
|