EXSWHTEC-250 - Implement Performance Tests for Event APIs (#133)

* Introduce performance tests to project.
* Improve benchmarking utilities.
* Delete copy constructors from Timer and Benchmark classes.
* Disable Catch2's benchmarking functionalities.
* Implement Performance Tests for Event APIs
* Implement microbenchmarks for the Event Management APIs.
* Add output modifier to Benchmark class.
* Seperate hipEventCreateWithFlags and hipEventDestroy into seperate files.
* Introduce command line options.
* Update performance_common.hh

[ROCm/hip-tests commit: bca87f46a6]
Tento commit je obsažen v:
Marko Veniger
2023-08-14 17:17:29 +02:00
odevzdal GitHub
rodič a2ae1bcb87
revize abe4a14f9e
9 změnil soubory, kde provedl 497 přidání a 0 odebrání
+1
Zobrazit soubor
@@ -18,4 +18,5 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
add_subdirectory(event)
add_subdirectory(example)
+34
Zobrazit soubor
@@ -0,0 +1,34 @@
# Copyright (c) 2022 Advanced Micro Devices, Inc. All Rights Reserved.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
set(TEST_SRC
hipEventCreate.cc
hipEventCreateWithFlags.cc
hipEventRecord.cc
hipEventDestroy.cc
hipEventSynchronize.cc
hipEventElapsedTime.cc
hipEventQuery.cc
)
hip_add_exe_to_target(NAME EventPerformance
TEST_SRC ${TEST_SRC}
TEST_TARGET_NAME build_tests
COMPILE_OPTIONS -std=c++17)
+56
Zobrazit soubor
@@ -0,0 +1,56 @@
/*
Copyright (c) 2022 Advanced Micro Devices, Inc. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#include <hip_test_common.hh>
#include <performance_common.hh>
#include <resource_guards.hh>
/**
* @addtogroup event event
* @{
* @ingroup PerformanceTest
* Contains performance tests for all hipEvent related HIP APIs.
*/
class HipEventCreateBenchmark : public Benchmark<HipEventCreateBenchmark> {
public:
void operator()() {
hipEvent_t event;
TIMED_SECTION(kTimerTypeCpu) { HIP_CHECK(hipEventCreate(&event)); }
HIP_CHECK(hipEventDestroy(event));
}
};
/**
* Test Description
* ------------------------
* - Executes `hipEventCreate`
* Test source
* ------------------------
* - performance/event/hipEventCreate.cc
* Test requirements
* ------------------------
* - HIP_VERSION >= 5.2
*/
TEST_CASE("Performance_hipEventCreate") {
HipEventCreateBenchmark benchmark;
benchmark.Run();
}
@@ -0,0 +1,83 @@
/*
Copyright (c) 2022 Advanced Micro Devices, Inc. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#include <hip_test_common.hh>
#include <performance_common.hh>
#include <resource_guards.hh>
/**
* @addtogroup event event
* @{
* @ingroup PerformanceTest
*/
class HipEventCreateWithFlagsBenchmark : public Benchmark<HipEventCreateWithFlagsBenchmark> {
public:
void operator()(unsigned flag) {
hipEvent_t event;
TIMED_SECTION(kTimerTypeCpu) { HIP_CHECK(hipEventCreateWithFlags(&event, flag)); }
HIP_CHECK(hipEventDestroy(event));
}
};
static std::string GetEventCreateFlagName(unsigned flag) {
switch (flag) {
case hipEventDefault:
return "hipEventDefault";
case hipEventBlockingSync:
return "hipEventBlockingSync";
case hipEventDisableTiming:
return "hipEventDisableTiming";
case hipEventInterprocess:
return "hipEventInterprocess";
default:
return "flag combination";
}
}
static void RunBenchmark(unsigned flag) {
HipEventCreateWithFlagsBenchmark benchmark;
benchmark.AddSectionName(GetEventCreateFlagName(flag));
benchmark.Run(flag);
}
/**
* Test Description
* ------------------------
* - Executes `hipEventCreateWithFlags` with all flags:
* -# Flags
* - hipEventDefault
* - hipEventBlockingSync
* - hipEventDisableTiming
* - hipEventInterprocess (currently disabled)
* Test source
* ------------------------
* - performance/event/hipEventCreate.cc
* Test requirements
* ------------------------
* - HIP_VERSION >= 5.2
*/
TEST_CASE("Performance_hipEventCreateWithFlags") {
const auto flag = GENERATE(
hipEventDefault, hipEventBlockingSync,
hipEventDisableTiming /*, hipEventInterprocess disabled until fixed (EXSWHTEC-25) */);
RunBenchmark(flag);
}
+54
Zobrazit soubor
@@ -0,0 +1,54 @@
/*
Copyright (c) 2022 Advanced Micro Devices, Inc. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#include <hip_test_common.hh>
#include <performance_common.hh>
#include <resource_guards.hh>
/**
* @addtogroup event event
* @{
* @ingroup PerformanceTest
*/
class HipEventDestroyBenchmark : public Benchmark<HipEventDestroyBenchmark> {
public:
void operator()() {
hipEvent_t event;
HIP_CHECK(hipEventCreate(&event));
TIMED_SECTION(kTimerTypeCpu) { HIP_CHECK(hipEventDestroy(event)); }
}
};
/**
* Test Description
* ------------------------
* - Executes `hipEventDestroy`
* Test source
* ------------------------
* - performance/event/hipEventCreate.cc
* Test requirements
* ------------------------
* - HIP_VERSION >= 5.2
*/
TEST_CASE("Performance_hipEventDestroy") {
HipEventDestroyBenchmark benchmark;
benchmark.Run();
}
+68
Zobrazit soubor
@@ -0,0 +1,68 @@
/*
Copyright (c) 2022 Advanced Micro Devices, Inc. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#include <chrono>
#include <thread>
#include <hip_test_common.hh>
#include <performance_common.hh>
#include <resource_guards.hh>
/**
* @addtogroup event event
* @{
* @ingroup PerformanceTest
*/
class HipEventElapsedTimeBenchmark : public Benchmark<HipEventElapsedTimeBenchmark> {
public:
void operator()() {
hipEvent_t start, end;
float time;
HIP_CHECK(hipEventCreate(&start));
HIP_CHECK(hipEventCreate(&end));
HIP_CHECK(hipEventRecord(start));
std::this_thread::sleep_for(std::chrono::milliseconds(5)); /* idle for 5 ms */
HIP_CHECK(hipEventRecord(end));
HIP_CHECK(hipEventSynchronize(end));
TIMED_SECTION(kTimerTypeCpu) { HIP_CHECK(hipEventElapsedTime(&time, start, end)); }
HIP_CHECK(hipEventDestroy(start));
HIP_CHECK(hipEventDestroy(end));
}
};
/**
* Test Description
* ------------------------
* - Executes `hipEventElapsedTime`
* Test source
* ------------------------
* - performance/event/hipEventElapsedTime.cc
* Test requirements
* ------------------------
* - HIP_VERSION >= 5.2
*/
TEST_CASE("Performance_hipEventElapsedTime") {
HipEventElapsedTimeBenchmark benchmark;
benchmark.Run();
}
+58
Zobrazit soubor
@@ -0,0 +1,58 @@
/*
Copyright (c) 2022 Advanced Micro Devices, Inc. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#include <hip_test_common.hh>
#include <performance_common.hh>
#include <resource_guards.hh>
/**
* @addtogroup event event
* @{
* @ingroup PerformanceTest
*/
class HipEventQueryBenchmark : public Benchmark<HipEventQueryBenchmark> {
public:
void operator()() {
hipEvent_t event;
HIP_CHECK(hipEventCreate(&event));
HIP_CHECK(hipEventRecord(event));
HIP_CHECK(hipEventSynchronize(event));
TIMED_SECTION(kTimerTypeCpu) { HIP_CHECK(hipEventQuery(event)); }
HIP_CHECK(hipEventDestroy(event));
}
};
/**
* Test Description
* ------------------------
* - Executes `hipEventQuery`
* Test source
* ------------------------
* - performance/event/hipEventQuery.cc
* Test requirements
* ------------------------
* - HIP_VERSION >= 5.2
*/
TEST_CASE("Performance_hipEventQuery") {
HipEventQueryBenchmark benchmark;
benchmark.Run();
}
+73
Zobrazit soubor
@@ -0,0 +1,73 @@
/*
Copyright (c) 2022 Advanced Micro Devices, Inc. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#include <hip_test_common.hh>
#include <performance_common.hh>
#include <resource_guards.hh>
/**
* @addtogroup event event
* @{
* @ingroup PerformanceTest
*/
class HipEventRecordBenchmark : public Benchmark<HipEventRecordBenchmark> {
public:
void operator()(hipStream_t stream) {
hipEvent_t event;
HIP_CHECK(hipEventCreate(&event));
TIMED_SECTION(kTimerTypeCpu) { HIP_CHECK(hipEventRecord(event, stream)); }
HIP_CHECK(hipEventDestroy(event));
}
};
static void RunBenchmark(hipStream_t stream) {
HipEventRecordBenchmark benchmark;
if (stream == NULL) {
benchmark.AddSectionName("Default stream");
} else {
benchmark.AddSectionName("Created stream");
}
benchmark.Run(stream);
}
/**
* Test Description
* ------------------------
* - Executes `hipEventRecord`
* -# Executed both on
* - default stream
* - created stream
* Test source
* ------------------------
* - performance/event/hipEventRecord.cc
* Test requirements
* ------------------------
* - HIP_VERSION >= 5.2
*/
TEST_CASE("Performance_hipEventRecord") {
SECTION("default stream") { RunBenchmark(nullptr); }
SECTION("created stream") {
StreamGuard stream(Streams::created);
RunBenchmark(stream.stream());
}
}
+70
Zobrazit soubor
@@ -0,0 +1,70 @@
/*
Copyright (c) 2022 Advanced Micro Devices, Inc. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#include <hip_test_common.hh>
#include <performance_common.hh>
#include <resource_guards.hh>
/**
* @addtogroup event event
* @{
* @ingroup PerformanceTest
*/
class HipEventSynchronizeBenchmark : public Benchmark<HipEventSynchronizeBenchmark> {
public:
void operator()(unsigned flag) {
hipEvent_t event;
HIP_CHECK(hipEventCreateWithFlags(&event, flag));
HIP_CHECK(hipEventRecord(event));
TIMED_SECTION(kTimerTypeCpu) { HIP_CHECK(hipEventSynchronize(event)); }
HIP_CHECK(hipEventDestroy(event));
}
};
static void RunBenchmark(unsigned flag) {
HipEventSynchronizeBenchmark benchmark;
if (flag == hipEventDefault) {
benchmark.AddSectionName("Default event");
} else {
benchmark.AddSectionName("Blocking sync event");
}
benchmark.Run(flag);
}
/**
* Test Description
* ------------------------
* - Executes `hipEventSynchronize`
* -# Checked on events created with flags:
* - hipEventDefault
* - hipEventBlockingSync
* Test source
* ------------------------
* - performance/event/hipEventSynchronize.cc
* Test requirements
* ------------------------
* - HIP_VERSION >= 5.2
*/
TEST_CASE("Performance_hipEventSynchronize") {
const auto flag = GENERATE(hipEventDefault, hipEventBlockingSync);
RunBenchmark(flag);
}