diff --git a/catch/performance/CMakeLists.txt b/catch/performance/CMakeLists.txt index 5412636ebc..e1e159c6e5 100644 --- a/catch/performance/CMakeLists.txt +++ b/catch/performance/CMakeLists.txt @@ -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) diff --git a/catch/performance/event/CMakeLists.txt b/catch/performance/event/CMakeLists.txt new file mode 100644 index 0000000000..02a2c565dc --- /dev/null +++ b/catch/performance/event/CMakeLists.txt @@ -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) \ No newline at end of file diff --git a/catch/performance/event/hipEventCreate.cc b/catch/performance/event/hipEventCreate.cc new file mode 100644 index 0000000000..5af6214c6a --- /dev/null +++ b/catch/performance/event/hipEventCreate.cc @@ -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 +#include +#include + +/** + * @addtogroup event event + * @{ + * @ingroup PerformanceTest + * Contains performance tests for all hipEvent related HIP APIs. + */ + +class HipEventCreateBenchmark : public Benchmark { + 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(); +} \ No newline at end of file diff --git a/catch/performance/event/hipEventCreateWithFlags.cc b/catch/performance/event/hipEventCreateWithFlags.cc new file mode 100644 index 0000000000..f69c5bed76 --- /dev/null +++ b/catch/performance/event/hipEventCreateWithFlags.cc @@ -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 +#include +#include + +/** + * @addtogroup event event + * @{ + * @ingroup PerformanceTest + */ + +class HipEventCreateWithFlagsBenchmark : public Benchmark { + 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); +} \ No newline at end of file diff --git a/catch/performance/event/hipEventDestroy.cc b/catch/performance/event/hipEventDestroy.cc new file mode 100644 index 0000000000..0f3a8f63e0 --- /dev/null +++ b/catch/performance/event/hipEventDestroy.cc @@ -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 +#include +#include + +/** + * @addtogroup event event + * @{ + * @ingroup PerformanceTest + */ + +class HipEventDestroyBenchmark : public Benchmark { + 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(); +} \ No newline at end of file diff --git a/catch/performance/event/hipEventElapsedTime.cc b/catch/performance/event/hipEventElapsedTime.cc new file mode 100644 index 0000000000..9c6ac5696b --- /dev/null +++ b/catch/performance/event/hipEventElapsedTime.cc @@ -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 +#include + +#include +#include +#include + +/** + * @addtogroup event event + * @{ + * @ingroup PerformanceTest + */ + +class HipEventElapsedTimeBenchmark : public Benchmark { + 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(); +} diff --git a/catch/performance/event/hipEventQuery.cc b/catch/performance/event/hipEventQuery.cc new file mode 100644 index 0000000000..bc1e0656fe --- /dev/null +++ b/catch/performance/event/hipEventQuery.cc @@ -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 +#include +#include + +/** + * @addtogroup event event + * @{ + * @ingroup PerformanceTest + */ + +class HipEventQueryBenchmark : public Benchmark { + 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(); +} diff --git a/catch/performance/event/hipEventRecord.cc b/catch/performance/event/hipEventRecord.cc new file mode 100644 index 0000000000..df5f331b95 --- /dev/null +++ b/catch/performance/event/hipEventRecord.cc @@ -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 +#include +#include + +/** + * @addtogroup event event + * @{ + * @ingroup PerformanceTest + */ + +class HipEventRecordBenchmark : public Benchmark { + 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()); + } +} diff --git a/catch/performance/event/hipEventSynchronize.cc b/catch/performance/event/hipEventSynchronize.cc new file mode 100644 index 0000000000..422f852501 --- /dev/null +++ b/catch/performance/event/hipEventSynchronize.cc @@ -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 +#include +#include + +/** + * @addtogroup event event + * @{ + * @ingroup PerformanceTest + */ + +class HipEventSynchronizeBenchmark : public Benchmark { + 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); +}