Skip to content

Commit f4ff423

Browse files
GitHub action benchmark (shader-slang#4804)
Adds a new Github CI action for benchmarking the slangc compiler on the MDL shaders. For now, the results are only dumped to the output of the CI, which can be later viewed through raw logs. The next step is to use github-action-benchmark to push these results into a page which will show the benchmark results over time as commits are pushed.
1 parent ee052a9 commit f4ff423

File tree

7 files changed

+319
-5
lines changed

7 files changed

+319
-5
lines changed

.github/workflows/benchmark.yml

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: Benchmark
2+
3+
on:
4+
push:
5+
branches: [master]
6+
paths-ignore:
7+
- 'docs/**'
8+
- 'LICENCE'
9+
- 'CONTRIBUTION.md'
10+
- 'README.md'
11+
pull_request:
12+
branches: [master]
13+
paths-ignore:
14+
- 'docs/**'
15+
- 'LICENCE'
16+
- 'CONTRIBUTION.md'
17+
- 'README.md'
18+
19+
jobs:
20+
build:
21+
runs-on: [Windows, benchmark, self-hosted]
22+
steps:
23+
- uses: actions/checkout@v3
24+
with:
25+
submodules: 'true'
26+
fetch-depth: '0'
27+
- name: Common setup
28+
uses: ./.github/actions/common-setup
29+
with:
30+
os: windows
31+
compiler: cl
32+
platform: x86_64
33+
config: release
34+
build-llvm: true
35+
- name: Build Slang
36+
run: |
37+
cmake --preset default --fresh -DSLANG_SLANG_LLVM_FLAVOR=USE_SYSTEM_LLVM -DCMAKE_COMPILE_WARNING_AS_ERROR=false
38+
cmake --workflow --preset release
39+
- name: Setup
40+
run: |
41+
cd tests/mdl
42+
pip install prettytable argparse
43+
- name: Run benchmark
44+
run: |
45+
cd tests/mdl
46+
Copy-Item -Path C:\slang-benchmarks -Destination . -Recurse
47+
python compile.py --samples 16 --target dxil --ci

source/core/slang-performance-profiler.cpp

+6-3
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,14 @@ namespace Slang
3131
}
3232
virtual void getResult(StringBuilder& out) override
3333
{
34-
for (auto func : data)
34+
char buffer[512];
35+
for (const auto& func : data)
3536
{
36-
out << func.key << ": \t";
37+
memset(buffer, 0, sizeof(buffer));
38+
snprintf(buffer, sizeof(buffer), "[*] %30s", func.key);
39+
out << buffer << " \t";
3740
auto milliseconds = std::chrono::duration_cast< std::chrono::milliseconds >(func.value.duration);
38-
out << func.value.invocationCount << "\t" << milliseconds.count() << "ms\n";
41+
out << func.value.invocationCount << " \t" << milliseconds.count() << "ms\n";
3942
}
4043
}
4144
virtual void clear() override

source/core/slang-performance-profiler.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,9 @@ struct SlangProfiler: public ISlangProfiler, public RefObject
6868
List<ProfileInfo> m_profilEntries;
6969
};
7070

71-
#define SLANG_PROFILE PerformanceProfilerFuncRAIIContext _profileContext(__func__)
71+
#define SLANG_PROFILE PerformanceProfilerFuncRAIIContext _profileContext(__func__)
72+
#define SLANG_PROFILE_SECTION(s) PerformanceProfilerFuncRAIIContext _profileContext##s(#s)
73+
7274
}
7375

7476
#endif

source/slang/slang-compiler.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include "../core/slang-basic.h"
44
#include "../core/slang-platform.h"
55
#include "../core/slang-io.h"
6+
#include "../core/slang-performance-profiler.h"
67
#include "../core/slang-string-util.h"
78
#include "../core/slang-hex-dump-util.h"
89
#include "../core/slang-riff.h"
@@ -2297,6 +2298,7 @@ namespace Slang
22972298

22982299
void EndToEndCompileRequest::generateOutput()
22992300
{
2301+
SLANG_PROFILE;
23002302
generateOutput(getSpecializedGlobalAndEntryPointsComponentType());
23012303

23022304
// If we are in command-line mode, we might be expected to actually

source/slang/slang.cpp

+11-1
Original file line numberDiff line numberDiff line change
@@ -2742,6 +2742,7 @@ static void _outputIncludes(const List<SourceFile*>& sourceFiles, SourceManager*
27422742
void FrontEndCompileRequest::parseTranslationUnit(
27432743
TranslationUnitRequest* translationUnit)
27442744
{
2745+
SLANG_PROFILE;
27452746
if (translationUnit->isChecked)
27462747
return;
27472748

@@ -2924,6 +2925,7 @@ void FrontEndCompileRequest::checkAllTranslationUnits()
29242925

29252926
void FrontEndCompileRequest::generateIR()
29262927
{
2928+
SLANG_PROFILE;
29272929
SLANG_AST_BUILDER_RAII(getLinkage()->getASTBuilder());
29282930

29292931
// Our task in this function is to generate IR code
@@ -3021,6 +3023,7 @@ static SourceLanguage inferSourceLanguage(FrontEndCompileRequest* request)
30213023

30223024
SlangResult FrontEndCompileRequest::executeActionsInner()
30233025
{
3026+
SLANG_PROFILE_SECTION(frontEndExecute);
30243027
SLANG_AST_BUILDER_RAII(getLinkage()->getASTBuilder());
30253028

30263029
for (TranslationUnitRequest* translationUnit : translationUnits)
@@ -3046,7 +3049,11 @@ SlangResult FrontEndCompileRequest::executeActionsInner()
30463049
return SLANG_FAIL;
30473050

30483051
// Perform semantic checking on the whole collection
3049-
checkAllTranslationUnits();
3052+
{
3053+
SLANG_PROFILE_SECTION(SemanticChecking);
3054+
checkAllTranslationUnits();
3055+
}
3056+
30503057
if (getSink()->getErrorCount() != 0)
30513058
return SLANG_FAIL;
30523059

@@ -3172,6 +3179,7 @@ void EndToEndCompileRequest::init()
31723179

31733180
SlangResult EndToEndCompileRequest::executeActionsInner()
31743181
{
3182+
SLANG_PROFILE_SECTION(endToEndActions);
31753183
// If no code-generation target was specified, then try to infer one from the source language,
31763184
// just to make sure we can do something reasonable when invoked from the command line.
31773185
//
@@ -6303,6 +6311,7 @@ SlangResult EndToEndCompileRequest::compile()
63036311
if (getOptionSet().getBoolOption(CompilerOptionName::ReportDownstreamTime))
63046312
{
63056313
getSession()->getCompilerElapsedTime(&totalStartTime, &downstreamStartTime);
6314+
PerformanceProfiler::getProfiler()->clear();
63066315
}
63076316
#if !defined(SLANG_DEBUG_INTERNAL_ERROR)
63086317
// By default we'd like to catch as many internal errors as possible,
@@ -6317,6 +6326,7 @@ SlangResult EndToEndCompileRequest::compile()
63176326

63186327
try
63196328
{
6329+
SLANG_PROFILE_SECTION(compileInner);
63206330
res = executeActions();
63216331
}
63226332
catch (const AbortCompilationException& e)

tests/mdl/.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
slang-benchmarks
2+
targets/
3+
modules/
4+
*.json

0 commit comments

Comments
 (0)