Skip to content

Commit e0eac8b

Browse files
committed
examples: tachyon: Add relative error estimation
Extend Tachyon example with additional option to execute rendering several times and calculate relative error to estimate rendering performance reliability. Signed-off-by: Dmitrii Golovanov <[email protected]>
1 parent c8c8793 commit e0eac8b

File tree

3 files changed

+47
-9
lines changed

3 files changed

+47
-9
lines changed

examples/parallel_for/tachyon/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ tachyon [dataset=value] [boundthresh=value] [no-display-updating] [no-bounding]
3434
* `boundthresh` - bounding threshold value.
3535
* `no-display-updating` - disable run-time display updating.
3636
* `no-bounding` - disable bounding technique.
37+
* `n-of-iterations` - how many times to repeat rendering to collect its reliable performance statistics.
3738

3839
### Environment variables
3940
The `tbb` and `tbb1d` version of examples has the following settings that may be handled by environment variables:

examples/parallel_for/tachyon/src/main.cpp

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (c) 2005-2022 Intel Corporation
2+
Copyright (c) 2005-2025 Intel Corporation
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.
@@ -55,6 +55,7 @@
5555
#include "util.hpp"
5656
#include "tachyon_video.hpp"
5757
#include "common/utility/utility.hpp"
58+
#include "common/utility/measurements.hpp"
5859

5960
#if WIN8UI_EXAMPLE
6061
#include "oneapi/tbb.h"
@@ -74,9 +75,11 @@ bool global_usegraphics;
7475

7576
bool silent_mode = false; /* silent mode */
7677

78+
utility::measurements *global_measurements = nullptr;
7779
class tachyon_video *video = nullptr;
7880

7981
typedef struct {
82+
int iterations; /* how many times to repeat rendering for statistics */
8083
int foundfilename; /* was a model file name found in the args? */
8184
char filename[1024]; /* model file to render */
8285
int useoutfilename; /* command line override of output filename */
@@ -92,6 +95,7 @@ typedef struct {
9295

9396
void initoptions(argoptions *opt) {
9497
memset(opt, 0, sizeof(argoptions));
98+
opt->iterations = 1;
9599
opt->foundfilename = -1;
96100
opt->useoutfilename = -1;
97101
opt->verbosemode = -1;
@@ -289,6 +293,9 @@ argoptions ParseCommandLine(int argc, const char *argv[]) {
289293
.positional_arg(opt.boundthresh, "boundthresh", "bounding threshold value")
290294
.arg(nodisp, "no-display-updating", "disable run-time display updating")
291295
.arg(nobounding, "no-bounding", "disable bounding technique")
296+
.arg(opt.iterations,
297+
"n-of-iterations",
298+
"number of rendering iterations to collect its reliable performance statistics")
292299
.arg(silent_mode, "silent", "no output except elapsed time"));
293300

294301
strcpy(opt.filename, filename.c_str());
@@ -345,9 +352,21 @@ int main(int argc, char *argv[]) {
345352
global_window_title = window_title_string(argc, (const char **)argv);
346353

347354
argoptions opt = ParseCommandLine(argc, (const char **)argv);
355+
if (opt.iterations > 1) {
356+
fprintf(stdout, "Repeating ray tracing %d times ...\n", opt.iterations);
357+
}
358+
else if (opt.iterations < 1) {
359+
fprintf(stderr, "Incorrect n-of-iterations=%d, exit.\n", opt.iterations);
360+
return -1;
361+
}
362+
363+
utility::measurements measurements(opt.iterations);
364+
global_measurements = &measurements;
348365

349-
if (CreateScene(opt) != 0)
366+
if (CreateScene(opt) != 0) {
367+
fprintf(stderr, "Failed to create scene!, exit.\n");
350368
return -1;
369+
}
351370

352371
tachyon_video tachyon;
353372
tachyon.threaded = true;
@@ -356,12 +375,17 @@ int main(int argc, char *argv[]) {
356375
tachyon.title = global_window_title;
357376
// always using window even if(!global_usegraphics)
358377
global_usegraphics = tachyon.init_window(global_xwinsize, global_ywinsize);
359-
if (!tachyon.running)
378+
if (!tachyon.running) {
379+
fprintf(stderr, "Failed to start tracing!, exit.\n");
360380
return -1;
381+
}
361382

362383
video = &tachyon;
363384
tachyon.main_loop();
364385

386+
if (opt.iterations > 1) {
387+
utility::report_relative_error(measurements.computeRelError());
388+
}
365389
utility::report_elapsed_time(timertime(mainStartTime, gettimer()));
366390
return 0;
367391
}

examples/parallel_for/tachyon/src/tachyon_video.cpp

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (c) 2005-2021 Intel Corporation
2+
Copyright (c) 2005-2025 Intel Corporation
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.
@@ -43,6 +43,7 @@
4343
SUCH DAMAGE.
4444
*/
4545

46+
#include <chrono>
4647
#include <cstdio>
4748
#include <cstdlib>
4849
#include <cstring>
@@ -53,27 +54,39 @@
5354
#include "util.hpp"
5455
#include "tachyon_video.hpp"
5556

57+
#include "common/utility/measurements.hpp"
58+
5659
extern SceneHandle global_scene;
5760
extern char *global_window_title;
5861
extern bool global_usegraphics;
62+
extern utility::measurements *global_measurements;
5963

6064
void tachyon_video::on_process() {
6165
char buf[8192];
6266
flt runtime;
67+
unsigned iterations = global_measurements->iterations();
6368
scenedef *scene = (scenedef *)global_scene;
6469
updating_mode = scene->displaymode == RT_DISPLAY_ENABLED;
65-
recycling = false;
6670
pausing = false;
6771
do {
72+
recycling = false;
6873
updating = updating_mode;
69-
timer start_timer = gettimer();
74+
global_measurements->start();
7075
rt_renderscene(global_scene);
71-
timer end_timer = gettimer();
72-
runtime = timertime(start_timer, end_timer);
73-
sprintf(buf, "%s: %.3f seconds", global_window_title, runtime);
76+
auto duration_usec = global_measurements->stop().count();
77+
sprintf(buf,
78+
"%s: %.3f seconds",
79+
global_window_title,
80+
(double)duration_usec / std::chrono::microseconds(std::chrono::seconds(1)).count());
7481
rt_ui_message(MSG_0, buf);
7582
title = buf;
7683
show_title(); // show time spent for rendering
84+
85+
iterations--;
86+
if (iterations > 0) {
87+
updating = false;
88+
recycling = true;
89+
}
7790
if (!updating) {
7891
updating = true;
7992
drawing_memory dm = get_drawing_memory();

0 commit comments

Comments
 (0)