Skip to content

Commit 6771f4d

Browse files
authored
Add reporting to xrt::runner (#8922)
The runner infrastructure reports metrics upon request. The metrics are currently loosely defined and most metrics are collected upon request. Below is a sample of what is reported by the runner and returned as a json std::string. The schema will change before it is finalized and versioned. ``` { "cpu": { "elapsed": 491726, # execution elapsed time (us) "latency": 21, # execution computed latency (us) "throughput": 45793 # execution average throughput (op/s) }, "hwctx": { "columns": 0 # Number of columns (not implemented) }, "resources": { "buffers": 5, # Number of xrt::bo objects created "kernels": 1, # Number of xrt::kernel objects created "runs": 9, # Number of xrt::run objects created "total_buffer_size": 100 # Total buffer size in bytes }, "xclbin": { "uuid": "44968c89-7cfa-a9d6-38e0-17cfa13445f2" } } ``` Signed-off-by: Soren Soe <[email protected]>
1 parent c4a61a7 commit 6771f4d

File tree

8 files changed

+415
-91
lines changed

8 files changed

+415
-91
lines changed

src/runtime_src/core/common/api/hw_context_int.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ create_hw_context_from_implementation(void* hwctx_impl);
5151
xrt::module
5252
get_module(const xrt::hw_context& hwctx, const std::string& kname);
5353

54+
// Get the partition size (number of columns). May not be available
55+
// in xclbin mode.
56+
size_t
57+
get_partition_size(const xrt::hw_context&);
58+
5459
}} // hw_context_int, xrt_core
5560

5661
#endif

src/runtime_src/core/common/api/xrt_hw_context.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,12 @@ class hw_context_impl : public std::enable_shared_from_this<hw_context_impl>
176176
return m_mode;
177177
}
178178

179+
size_t
180+
get_partition_size() const
181+
{
182+
return m_partition_size;
183+
}
184+
179185
xrt_core::hwctx_handle*
180186
get_hwctx_handle()
181187
{
@@ -239,6 +245,12 @@ get_module(const xrt::hw_context& ctx, const std::string& kname)
239245
return ctx.get_handle()->get_module(kname);
240246
}
241247

248+
size_t
249+
get_partition_size(const xrt::hw_context& ctx)
250+
{
251+
return ctx.get_handle()->get_partition_size();
252+
}
253+
242254
} // xrt_core::hw_context_int
243255

244256
////////////////////////////////////////////////////////////////

src/runtime_src/core/common/runner/README.md

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<!-- SPDX-License-Identifier: Apache-2.0 -->
22
<!-- Copyright (C) 2024-2025 Advanced Micro Devices, Inc. All rights reserved. -->
3-
# Runner instrastructure
3+
# Runner infrastructure
44

55
This directory contains xrt::runner infrastructure. The runner is
66
broken into two json components. First is the recipe that defines a
@@ -10,3 +10,49 @@ under what constraints how the model is executed.
1010
- [recipe](recipe.md)
1111
- [profile](profile.md)
1212

13+
## Instantiating an xrt::runner
14+
15+
An execution profile is useless without a run recipe. But a run
16+
recipe can have several execution profiles, and less likely a
17+
profile could be used with multiple recipes.
18+
19+
The profile (and the recipe) may reference file artifacts. These
20+
artifacts can be passed to the runner in two different ways. (1) the
21+
runner can be instantiated with a path to a directory containing the
22+
referenced artifacts (files), or (2) it can be instantiated with an
23+
artifacts repository that have all the artifacts in memory pre-loaded.
24+
25+
See [runner.h](runner.h) or details.
26+
27+
## Reporting
28+
29+
The runner infrastructure reports metrics upon request. The metrics
30+
are currently loosely defined and most metrics are collected upon
31+
request.
32+
33+
Below is a sample of what is reported by the runner and returned
34+
as a json std::string.
35+
36+
The schema will change before it is finalized and versioned.
37+
38+
```
39+
{
40+
"cpu": {
41+
"elapsed": 491726, # execution elapsed time (us)
42+
"latency": 21, # execution computed latency (us)
43+
"throughput": 45793 # execution average throughput (op/s)
44+
},
45+
"hwctx": {
46+
"columns": 0 # Number of columns (not implemented)
47+
},
48+
"resources": {
49+
"buffers": 5, # Number of xrt::bo objects created
50+
"kernels": 1, # Number of xrt::kernel objects created
51+
"runs": 9, # Number of xrt::run objects created
52+
"total_buffer_size": 100 # Total buffer size in bytes
53+
},
54+
"xclbin": {
55+
"uuid": "44968c89-7cfa-a9d6-38e0-17cfa13445f2"
56+
}
57+
}
58+
```

src/runtime_src/core/common/runner/main.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,15 @@ usage()
3939
static void
4040
run(const std::string& recipe,
4141
const std::string& profile,
42-
const std::string& dir)
42+
const std::string& dir,
43+
bool report)
4344
{
4445
xrt::device device{0};
4546
xrt_core::runner runner {device, recipe, profile, dir};
4647
runner.execute();
4748
runner.wait();
49+
if (report)
50+
std::cout << runner.get_report() << "\n";
4851
}
4952

5053
static void
@@ -55,12 +58,18 @@ run(int argc, char* argv[])
5558
std::string recipe;
5659
std::string profile;
5760
std::string dir = ".";
61+
bool report = false;
5862
for (auto& arg : args) {
5963
if (arg == "-h") {
6064
usage();
6165
return;
6266
}
6367

68+
if (arg == "--report") {
69+
report = true;
70+
continue;
71+
}
72+
6473
if (arg[0] == '-') {
6574
cur = arg;
6675
continue;
@@ -76,7 +85,7 @@ run(int argc, char* argv[])
7685
throw std::runtime_error("Unknown option value " + cur + " " + arg);
7786
}
7887

79-
run(recipe, profile, dir);
88+
run(recipe, profile, dir, report);
8089
}
8190

8291
int

src/runtime_src/core/common/runner/profile.md

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ resources.
1313

1414
An execution profile is useful for testing of a run recipe. It allows
1515
for one external application controlling execution of a run recipe by
16-
defininng:
16+
defining:
1717

1818
- how data is bound to resources
1919
- how validation is performed
@@ -35,6 +35,8 @@ how many times along with what should be done in each iteration.
3535

3636
## QoS
3737

38+
This section is optional.
39+
3840
Simple key/value pairs designating configuration parameters for
3941
hardware context creation.
4042
```
@@ -44,11 +46,14 @@ hardware context creation.
4446
},
4547
```
4648
The json schema doesn't enforce key names or value ranges, XRT will
47-
warn but ignore unrecoqnized keys. Improper values are implementation
49+
warn but ignore unrecognized keys. Improper values are implementation
4850
defined.
4951

5052
## Bindings
5153

54+
This section is optional if all buffer resources specified in the
55+
recipe are specified with `size` (see [recipe](recipe.md#buffer)).
56+
5257
The bindings section specifies how external buffers should be created,
5358
initialized, and validated. The section is an array of binding elements,
5459
where each binding element must reference a resource in the run-recipe.
@@ -68,7 +73,7 @@ file, but is otherwise required.
6873
{ ... }
6974
],
7075
```
71-
A binding elememnt has some simple attributes and more complex
76+
A binding element has some simple attributes and more complex
7277
nested attributes
7378

7479
### Simple attributes of a binding element
@@ -111,7 +116,7 @@ should be initialized. There are multiple ways to initialize a buffer.
111116
### Initialization of a resource buffer
112117

113118
A bindings element results in the creation of the `xrt::bo` buffer
114-
object. Upon creation, the buffer object is initialzied per the init
119+
object. Upon creation, the buffer object is initialized per the init
115120
sub-element. There are several ways to initialize a buffer only one
116121
of which can be specified.
117122

@@ -137,10 +142,10 @@ have been specified.
137142
}
138143
```
139144
File initialization implies that the resource buffer should be
140-
intialized with content from `file`. The `file` must reference
145+
initialized with content from `file`. The `file` must reference
141146
a key that locates a file on disk or in an artifacts repository used
142147
during construction of the `xrt::runner`. If the binding element
143-
specifies a `size` value, then this size takes precendence over the
148+
specifies a `size` value, then this size takes precedence over the
144149
size of the file, otherwise the size of the file will be the size of
145150
the buffer. The optional `skip` element
146151
allows skipping first bytes of the file during initialization of the
@@ -157,7 +162,7 @@ of the file are used.
157162

158163
If a bindings element specifies `reinit`, then the buffer is
159164
reinitialized with bytes from the file in each iteration of the
160-
recipe. The initalization in an iteration picks up from an offset
165+
recipe. The initialization in an iteration picks up from an offset
161166
into the file at the point where the previous iteration stopped
162167
copying. Again, the file wraps around when end-of-file is reached
163168
without filling all the bytes of the buffer.
@@ -166,9 +171,9 @@ without filling all the bytes of the buffer.
166171

167172
```
168173
"init": {
169-
"stride": 1, // stide bytes
174+
"stride": 1, // stride bytes
170175
"value": 239, // value to write at each stride
171-
"begin": 0, // begining of range to write at
176+
"begin": 0, // beginning of range to write at
172177
"end": 524288 // end of range
173178
}
174179
```
@@ -179,7 +184,7 @@ is referred to as strided buffer initialization.
179184
In the above example, the buffer range specified by `begin` and `end`
180185
is written with the byte value `239` at every byte (`stride` is
181186
1). The value can be any uint64_t value, but must be a decimal value
182-
in order to be valid json. To initalize a buffer with with
187+
in order to be valid json. To initialize a buffer with with
183188
0xdeadbeef, convert to decimal and write:
184189

185190
```
@@ -191,8 +196,8 @@ in order to be valid json. To initalize a buffer with with
191196

192197
#### Validation
193198

194-
After executon, a buffer can be validated against golden data. This is
195-
specifed using a `validate` element for the binding.
199+
After execution, a buffer can be validated against golden data. This is
200+
specified using a `validate` element for the binding.
196201

197202
```
198203
{
@@ -218,13 +223,23 @@ specifics as needed.
218223

219224
## Execution
220225

226+
This section is optional. If not present, the recipe will execute
227+
one iteration.
228+
221229
The execution section of a profile specifies how many times the recipe
222230
should be executed and how. It controls what should happen after each
223-
iteration and before next iteration.
231+
iteration and before next iteration. if `iterations` is not specified,
232+
then the recipe will execute one iteration.
233+
234+
By default the profile execution will display to stdout elapsed,
235+
throughput, and latency computed from running the recipe specified
236+
number of iterations.
237+
This can be disabled by setting `verbose: false`.
224238

225239
```
226240
"execution" : {
227241
"iterations": 500,
242+
"verbose": false, // disable reporting of cpu time
228243
"iteration" : {
229244
"bind": false, // re-bind binding buffers
230245
"init": true, // re-initialize binding buffers
@@ -235,15 +250,15 @@ iteration and before next iteration.
235250
}
236251
```
237252

238-
The iteration element specifies what should happen before after each
239-
iteration of the run recipe.
253+
The iteration element is optional, but if present specifies what
254+
should happen before after each iteration of the run recipe.
240255

241256
- `bind` indicates if buffers should be re-bound to the
242-
recipe before an iteration. Only buffers whos binding element
257+
recipe before an iteration. Only buffers whose binding element
243258
specifies `rebind` are re-bound. All buffers are by default
244259
bound to the recipe upon creation.
245260
- `init` indicates if buffer should be re-initialized before an
246-
iteration. Only buffers whos binding element specifies has an `init`
261+
iteration. Only buffers whose binding element specifies has an `init`
247262
element and specifies `reinit` are re-initialized. All buffers are by
248263
default initialized upon creation if their binding element has an
249264
`init` element.
@@ -256,18 +271,3 @@ iterations and after last iteration.
256271
- `validate` means buffer validation per what is specified in
257272
the binding element.
258273

259-
# Instatiating an xrt::runner with a profile
260-
261-
An execution profile is useless without a run recipe. But a run
262-
recipe can have several execution profiles, and less likely a
263-
profile could be used with multiple recipes.
264-
265-
The profile (and the recipe) may reference file artifacts. These
266-
artifacts can be passed to the runner in two different ways. (1) the
267-
runner can be instantied with a path to a directory containing the
268-
referenced artifacts (files), or (2) it can be instantiated with an
269-
artifacts repository that have all the artifacts in memory pre-loaded.
270-
271-
See [runner.h](runner.h) or details.
272-
273-

src/runtime_src/core/common/runner/recipe.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ A run recipe defines a graph model that can be executed by XRT.
66

77
This directory contains a stand-alone `xrt::runner` class that reads and
88
executes a run recipe json file. The idea is to have tools, e.g. VAIML
9-
geneate the run recipe along with xclbin and control code for kernels.
9+
generate the run recipe along with xclbin and control code for kernels.
1010

1111
The schema of the recipe json is defined in `schema/recipe.schema.json`. The
12-
implementation of the runner drove some of the defintion of the json
12+
implementation of the runner drove some of the definition of the json
1313
format.
1414

1515
A run recipe is associated with exactly one configuration (xclbin or
@@ -75,7 +75,7 @@ be listed in the resources section.
7575

7676
### Kernel functions
7777

78-
Kernels listed in the resoruces section result in runner creating
78+
Kernels listed in the resources section result in runner creating
7979
`xrt::kernel` objects. In XRT, the kernel objects are identified by
8080
name, which must match a kernel instance name in the xclbin.
8181

@@ -426,7 +426,7 @@ input and output are consumed during one kernel execution. See the
426426

427427
# Runner API
428428

429-
The runner is contructed from a recipe json file and a device object.
429+
The runner is constructed from a recipe json file and a device object.
430430
The runner is a standard XRT C++ first class object with the following
431431
API. Include documentation will be beefed up when the runner code is
432432
moved to public XRT.

0 commit comments

Comments
 (0)