Skip to content

Instantly share code, notes, and snippets.

@twobob
Created August 11, 2023 13:22
Show Gist options
  • Save twobob/5cc797a0e07ba2803b3c8c7de0140d9f to your computer and use it in GitHub Desktop.
Save twobob/5cc797a0e07ba2803b3c8c7de0140d9f to your computer and use it in GitHub Desktop.
wraps the sample template
#Usage:
# powershell '.\sample.ps1' 1
#
# powershell '.\sample_15_110.ps1' -loops 3 -compilers 'runmingw', 'runmsvc'
#
# powershell '.\sample_15_110.ps1' 3 'runmingw', 'runmsvc'
#
# any combination of model is okay in the naming After
# you run create_sampling_hardlinks
#
param(
[int]$loops = 3,
[string[]]$compilers = @('runmingw', 'rungcc', 'runmsvc', 'run')
)
# Extract the model numbers from the script name
$scriptName = $MyInvocation.MyCommand.Name
$modelNumbers = $scriptName -replace 'sample_', '' -replace '.ps1', '' -split '_'
# Check if the array contains valid numbers and add them to models
$models = @()
foreach ($number in $modelNumbers) {
if ($number -match "^\d+$") {
$models += "model${number}M.bin"
}
}
# If no valid numbers were found, use the default models
if ($models.Count -eq 0) {
$models = 'model15M.bin', 'model42M.bin', 'model110M.bin'
}
$validCompilers = @('runmingw.exe', 'rungcc.exe', 'runmsvc.exe', 'run.exe', 'run_instrumented.exe')
$compilerOptions = $compilers | ForEach-Object { if ($_ -notmatch '\.exe$') { "$_.exe" } else { $_ } } | Where-Object { $_ -in $validCompilers }
if ($compilerOptions.Count -eq 0) {
# Exclude 'run_instrumented.exe' from the default options
$compilerOptions = $validCompilers | Where-Object { $_ -ne 'run_instrumented.exe' }
}
# Report the selected models and compilers
Write-Host "Selected Models:" -ForegroundColor Green
$models | ForEach-Object { Write-Host $_ }
Write-Host "Selected Compilers:" -ForegroundColor Green
$compilerOptions | ForEach-Object { Write-Host $_ }
# Call sample_template.ps1 with the selected loops, models, and compilers
& '.\sample_template.ps1' -loops $loops -models $models -compilers $compilerOptions
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment