Skip to content

Commit 4399f1b

Browse files
Merge pull request intel#259 from wenjuan1-intel/shliclel180-testroot-topic
Enable llvm_test_suite_sycl ESIMD performance testing
2 parents d4c2874 + 69a65a8 commit 4399f1b

6 files changed

+113
-20
lines changed

SYCL/ESIMD/esimd_test_utils.hpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,4 +190,13 @@ inline double report_time(const std::string &msg, event e0, event en) {
190190
return elapsed;
191191
}
192192

193+
void display_timing_stats(double const kernelTime,
194+
unsigned int const uiNumberOfIterations,
195+
double const overallTime)
196+
{
197+
std::cout << "Number of iterations: " << uiNumberOfIterations << "\n";
198+
std::cout << "[KernelTime]:" << kernelTime << "\n";
199+
std::cout << "[OverallTime][Primary]:" << overallTime << "\n";
200+
}
201+
193202
} // namespace esimd_test

SYCL/ESIMD/histogram.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,11 +132,16 @@ int main(int argc, char *argv[]) {
132132
image_channel_type::unsigned_int32,
133133
range<2>{width / sizeof(uint4), height});
134134

135+
// Start Timer
136+
esimd_test::Timer timer;
137+
double start;
138+
135139
// Launches the task on the GPU.
136140
double kernel_times = 0;
137141
unsigned num_iters = 10;
138142

139143
try {
144+
// num_iters + 1, iteration#0 is for warmup
140145
for (int iter = 0; iter <= num_iters; ++iter) {
141146
double etime = 0;
142147
for (int b = 0; b < NUM_BINS; b++)
@@ -215,6 +220,8 @@ int main(int argc, char *argv[]) {
215220
etime = esimd_test::report_time("kernel time", e, e);
216221
if (iter > 0)
217222
kernel_times += etime;
223+
else
224+
start = timer.Elapsed();
218225
}
219226
// SYCL will enqueue and run the kernel. Recall that the buffer's data is
220227
// given back to the host at the end of scope.
@@ -224,8 +231,12 @@ int main(int argc, char *argv[]) {
224231
return e.get_cl_code();
225232
}
226233

227-
float kernel_time = kernel_times / num_iters;
228-
std::cerr << "GPU kernel time = " << kernel_time << " msec\n";
234+
// End timer.
235+
double end = timer.Elapsed();
236+
237+
esimd_test::display_timing_stats(kernel_times,num_iters,(end-start)*1000);
238+
//float kernel_time = kernel_times / num_iters;
239+
//std::cerr << "GPU kernel time = " << kernel_time << " msec\n";
229240

230241
writeHist(bins);
231242
writeHist(cpuHistogram);

llvm_test_suite_sycl.pl

Lines changed: 82 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,15 @@
1010

1111
# @test_to_run_list stores only the test(s) that will be run
1212
# For example, for "tc -t llvm_test_suite_sycl/aot_cpu,aot_gpu" it will store 2 tests - aot_cpu and aot_gpu
13-
my @test_to_run_list = ();
13+
my @test_to_run_list = get_tests_to_run();
1414
# @suite_test_list stores all the tests in the whole suite(without splitting) or sub-suite(with splitting)
1515
# For example, for "tc -t llvm_test_suite_sycl~4-1/aot_cpu,aot_gpu" it will store all the tests in sub-suite 4-1
16-
my @suite_test_list = ();
16+
my @suite_test_list = get_test_list($current_optset);
1717
my $short_test_name;
1818
my $test_info;
19-
my $config_folder = "";
19+
my $config_folder = 'config_sycl';
2020
my $subdir = "SYCL";
2121
my $insert_command = "";
22-
my $is_suite = 0;
2322

2423
my $sycl_backend = "";
2524
my $device = "";
@@ -52,13 +51,27 @@ sub lscl {
5251
return $output;
5352
}
5453

54+
sub is_zperf_run {
55+
if ((defined $opt_perf && $opt_perf) ||
56+
(defined $opt_perf_run && $opt_perf_run)) {
57+
return 1;
58+
}
59+
return 0;
60+
}
61+
62+
sub is_suite {
63+
my @whole_suite_test = sort(@suite_test_list);
64+
my @current_test_list = sort(@test_to_run_list);
65+
66+
return is_same(\@current_test_list, \@whole_suite_test);
67+
}
68+
5569
sub init_test
5670
{
5771
my $suite_feature = $current_suite;
5872
$suite_feature =~ s/^llvm_test_suite_//;
5973
#Remove suffix of suite names if it has
6074
$suite_feature =~ s/~.*$//;
61-
$config_folder = 'config_sycl';
6275
if ($suite_feature !~ /^sycl/)
6376
{
6477
$config_folder = $config_folder . '_' . $suite_feature;
@@ -93,7 +106,7 @@ sub init_test
93106
}
94107

95108
#Remove untested source files from $subdir if it run with several subsuites
96-
if ($is_suite) {
109+
if (is_suite()) {
97110
my $info_dir = "$optset_work_dir/$config_folder";
98111
my @info_files = glob("$info_dir/*.info");
99112

@@ -124,21 +137,69 @@ sub init_test
124137
return PASS;
125138
}
126139

140+
sub extract_perf_results
141+
{
142+
my $timer = Timer->new($current_test, $current_suite, $current_optset);
143+
$timer->set("host", &alloy_utils::get_hostname());
144+
my $output_file = join($slash, $optset_work_dir, "$current_test.output");
145+
open(LOG, "+>", $output_file) or die "open $output_file fail";
146+
print LOG $execution_output;
147+
seek(LOG, 0, 0);
148+
my $perf_matched = 0;
149+
while (<LOG>) {
150+
my $pattern = ".*OverallTime(.*):(\\d+.?\\d*[Ee]?[+-]?\\d+).*";
151+
if ($_ =~ qr/$pattern/) {
152+
my $primary = $1;
153+
my $result = $2;
154+
my $metric = "time";
155+
my $better = "lt";
156+
$timer->set($metric, $result);
157+
$timer->set("BETTER_$metric", $better);
158+
if ($primary =~ m/Primary/) {
159+
$timer->set("primary_metric", $metric);
160+
$perf_matched = 1;
161+
}
162+
}
163+
$pattern = ".*KernelThroughput(.*):(\\d+.?\\d*[Ee]?[+-]?\\d+).*";
164+
if ($_ =~ qr/$pattern/) {
165+
my $primary = $1;
166+
my $result = $2;
167+
my $metric = "throughput";
168+
my $better = "gt";
169+
$timer->set($metric, $result);
170+
$timer->set("BETTER_$metric", $better);
171+
if ($primary =~ m/Primary/) {
172+
$timer->set("primary_metric", $metric);
173+
$perf_matched = 1;
174+
}
175+
}
176+
$pattern = ".*KernelTime(.*):(\\d+.?\\d*[Ee]?[+-]?\\d+).*";
177+
if ($_ =~ qr/$pattern/) {
178+
my $primary = $1;
179+
my $result = $2;
180+
my $metric = "kerneltime";
181+
my $better = "lt";
182+
$timer->set($metric, $result);
183+
$timer->set("BETTER_$metric", $better);
184+
if ($primary =~ m/Primary/) {
185+
$timer->set("primary_metric", $metric);
186+
$perf_matched = 1;
187+
}
188+
}
189+
}
190+
close(LOG);
191+
if (! $perf_matched) {
192+
print "Warning: Primary metric is not specified!!!\n";
193+
}
194+
}
195+
127196
sub BuildTest
128197
{
129198
$build_dir = $cwd . "/build";
130199
safe_Mkdir($build_dir);
131200

132-
# CMPLRTST-14094: API get_test_list() requires optset name as an argument
133-
@suite_test_list = get_test_list($current_optset);
134-
135-
@test_to_run_list = get_tests_to_run();
136201
if ($current_test eq $test_to_run_list[0])
137202
{
138-
my @whole_suite_test = sort(@suite_test_list);
139-
my @current_test_list = sort(@test_to_run_list);
140-
$is_suite = is_same(\@current_test_list, \@whole_suite_test);
141-
142203
init_test();
143204
chdir_log($build_dir);
144205

@@ -168,6 +229,9 @@ sub BuildTest
168229

169230
sub RunTest
170231
{
232+
$build_dir = $cwd . "/build";
233+
chdir_log($build_dir);
234+
171235
$test_info = get_info();
172236
my ( $status, $output) = do_run($test_info);
173237
my $res = "";
@@ -180,6 +244,9 @@ sub RunTest
180244
} else {
181245
$res = generate_run_result($output);
182246
}
247+
if ($res eq $PASS && is_zperf_run()) {
248+
extract_perf_results();
249+
}
183250
return $res;
184251
}
185252

@@ -215,7 +282,7 @@ sub do_run
215282
$timeset = "--timeout 0";
216283
}
217284

218-
if ($is_suite) {
285+
if (is_suite()) {
219286
set_tool_path();
220287
execute("$python $lit -a $matrix $jobset . $timeset > $run_all_lf 2>&1");
221288
} else {

llvm_test_suite_sycl.xml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<description>Port of llvm_test_suite_sycl.
44
Suite is autogenerated by suite_generator_sycl.pl that you can find in the root dir of suite
55
Sources repo https://github.com/intel-innersource/applications.compilers.tests.llvm-project-llvm-test-suite
6-
Last Changed Revision: 4be68f9c03290a6b48ef040f402ea754ae4d2998 Tue Sep 21 16:16:04 2021 -0700
6+
Last Changed Revision: 83d34b70c59796d3d3504c6e1d56771115c89ae4 Tue Sep 21 16:16:04 2021 -0700
77
</description>
88
<files>
99
<file path="cmake" />
@@ -17,6 +17,9 @@ Last Changed Revision: 4be68f9c03290a6b48ef040f402ea754ae4d2998 Tue Sep 21 16
1717
<file path="config_sycl" />
1818
<file path=".github/CODEOWNERS" />
1919
</files>
20+
<rules>
21+
<advancedRule perfSupport="accurate" />
22+
</rules>
2023
<tests>
2124
<test configFile="config_sycl/TEMPLATE_llvm_test_suite_sycl.xml" splitGroup="basic" testName="Basic_opencl_interop_0" />
2225
<test configFile="config_sycl/TEMPLATE_llvm_test_suite_sycl.xml" splitGroup="aot" testName="aot_accelerator" />

llvm_test_suite_sycl_matrix.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<description>Port of llvm_test_suite_sycl_matrix.
44
Suite is autogenerated by suite_generator_sycl.pl that you can find in the root dir of suite
55
Sources repo https://github.com/intel-innersource/applications.compilers.tests.llvm-project-llvm-test-suite
6-
Last Changed Revision: 4be68f9c03290a6b48ef040f402ea754ae4d2998 Tue Sep 21 16:16:04 2021 -0700
6+
Last Changed Revision: 83d34b70c59796d3d3504c6e1d56771115c89ae4 Tue Sep 21 16:16:04 2021 -0700
77
</description>
88
<files>
99
<file path="cmake" />

llvm_test_suite_sycl_valgrind.xml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<description>Port of llvm_test_suite_sycl.
44
Suite is autogenerated by suite_generator_sycl.pl that you can find in the root dir of suite
55
Sources repo https://github.com/intel-innersource/applications.compilers.tests.llvm-project-llvm-test-suite
6-
Last Changed Revision: 4be68f9c03290a6b48ef040f402ea754ae4d2998 Tue Sep 21 16:16:04 2021 -0700
6+
Last Changed Revision: 83d34b70c59796d3d3504c6e1d56771115c89ae4 Tue Sep 21 16:16:04 2021 -0700
77
</description>
88
<files>
99
<file path="cmake" />
@@ -17,6 +17,9 @@ Last Changed Revision: 4be68f9c03290a6b48ef040f402ea754ae4d2998 Tue Sep 21 16
1717
<file path="config_sycl" />
1818
<file path=".github/CODEOWNERS" />
1919
</files>
20+
<rules>
21+
<advancedRule perfSupport="accurate" />
22+
</rules>
2023
<tests>
2124
<test configFile="config_sycl/TEMPLATE_llvm_test_suite_sycl.xml" splitGroup="basic" testName="Basic_opencl_interop_0" />
2225
<test configFile="config_sycl/TEMPLATE_llvm_test_suite_sycl.xml" splitGroup="aot" testName="aot_accelerator" />

0 commit comments

Comments
 (0)