From 95a954e63ab4520f5ca1ecce3d66d528ac6e356e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mirza=20Halil=C4=8Devi=C4=87?= <109971222+mirza-halilcevic@users.noreply.github.com> Date: Thu, 28 Dec 2023 18:26:22 +0100 Subject: [PATCH] EXSWHTEC-248 - Implement Performance Tests for Memset APIs #99 Change-Id: I6b4a0758299b0fd6d70c75508a4a0d67c62187ff --- catch/include/hip_test_defgroups.hh | 7 ++ catch/performance/memset/CMakeLists.txt | 39 +++++++++ catch/performance/memset/hipMemset.cc | 79 ++++++++++++++++++ catch/performance/memset/hipMemset2D.cc | 71 ++++++++++++++++ catch/performance/memset/hipMemset2DAsync.cc | 74 +++++++++++++++++ catch/performance/memset/hipMemset3D.cc | 72 ++++++++++++++++ catch/performance/memset/hipMemset3DAsync.cc | 74 +++++++++++++++++ catch/performance/memset/hipMemsetAsync.cc | 81 ++++++++++++++++++ catch/performance/memset/hipMemsetD16.cc | 80 ++++++++++++++++++ catch/performance/memset/hipMemsetD16Async.cc | 82 +++++++++++++++++++ catch/performance/memset/hipMemsetD32.cc | 80 ++++++++++++++++++ catch/performance/memset/hipMemsetD32Async.cc | 82 +++++++++++++++++++ catch/performance/memset/hipMemsetD8.cc | 80 ++++++++++++++++++ catch/performance/memset/hipMemsetD8Async.cc | 82 +++++++++++++++++++ 14 files changed, 983 insertions(+) create mode 100644 catch/performance/memset/CMakeLists.txt create mode 100644 catch/performance/memset/hipMemset.cc create mode 100644 catch/performance/memset/hipMemset2D.cc create mode 100644 catch/performance/memset/hipMemset2DAsync.cc create mode 100644 catch/performance/memset/hipMemset3D.cc create mode 100644 catch/performance/memset/hipMemset3DAsync.cc create mode 100644 catch/performance/memset/hipMemsetAsync.cc create mode 100644 catch/performance/memset/hipMemsetD16.cc create mode 100644 catch/performance/memset/hipMemsetD16Async.cc create mode 100644 catch/performance/memset/hipMemsetD32.cc create mode 100644 catch/performance/memset/hipMemsetD32Async.cc create mode 100644 catch/performance/memset/hipMemsetD8.cc create mode 100644 catch/performance/memset/hipMemsetD8Async.cc diff --git a/catch/include/hip_test_defgroups.hh b/catch/include/hip_test_defgroups.hh index fdf289e8c5..ff26989966 100644 --- a/catch/include/hip_test_defgroups.hh +++ b/catch/include/hip_test_defgroups.hh @@ -173,6 +173,13 @@ THE SOFTWARE. * @} */ +/** + * @defgroup PerformanceTest Performance tests + * @{ + * This section describes performance tests for the target API groups and use-cases. + * @} + */ + /** * @defgroup TextureTest Texture Management * @{ diff --git a/catch/performance/memset/CMakeLists.txt b/catch/performance/memset/CMakeLists.txt new file mode 100644 index 0000000000..f55683298b --- /dev/null +++ b/catch/performance/memset/CMakeLists.txt @@ -0,0 +1,39 @@ +# 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 + hipMemset.cc + hipMemsetAsync.cc + hipMemsetD8.cc + hipMemsetD8Async.cc + hipMemsetD16.cc + hipMemsetD16Async.cc + hipMemsetD32.cc + hipMemsetD32Async.cc + hipMemset2D.cc + hipMemset2DAsync.cc + hipMemset3D.cc + hipMemset3DAsync.cc +) + +hip_add_exe_to_target(NAME MemsetPerformance + 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/memset/hipMemset.cc b/catch/performance/memset/hipMemset.cc new file mode 100644 index 0000000000..0063eeca51 --- /dev/null +++ b/catch/performance/memset/hipMemset.cc @@ -0,0 +1,79 @@ +/* +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 memset memset + * @{ + * @ingroup PerformanceTest + * Contains performance tests for all memset HIP APIs. + */ + +class MemsetBenchmark : public Benchmark { + public: + MemsetBenchmark(LinearAllocs allocation_type, size_t size) + : dst_(allocation_type, size), size_(size) {} + + void operator()() { + TIMED_SECTION(kTimerTypeEvent) { HIP_CHECK(hipMemset(dst_.ptr(), 17, size_)); } + } + + private: + LinearAllocGuard dst_; + const size_t size_; +}; + +static void RunBenchmark(LinearAllocs allocation_type, size_t size) { + MemsetBenchmark benchmark(allocation_type, size); + benchmark.AddSectionName(std::to_string(size)); + benchmark.AddSectionName(GetAllocationSectionName(allocation_type)); + benchmark.Run(); +} + +/** + * Test Description + * ------------------------ + * - Executes `hipMemset`: + * -# Allocation size + * - Small: 4 KB + * - Medium: 4 MB + * - Large: 16 MB + * -# Allocation type + * - device + * - host + * - managed + * Test source + * ------------------------ + * - performance/memset/hipMemset.cc + * Test requirements + * ------------------------ + * - HIP_VERSION >= 5.2 + */ +TEST_CASE("Performance_hipMemset") { + const auto size = GENERATE(4_KB, 4_MB, 16_MB); + const auto allocation_type = GENERATE(LinearAllocs::hipMalloc, LinearAllocs::hipHostMalloc, + LinearAllocs::hipMallocManaged); + RunBenchmark(allocation_type, size); +} \ No newline at end of file diff --git a/catch/performance/memset/hipMemset2D.cc b/catch/performance/memset/hipMemset2D.cc new file mode 100644 index 0000000000..8384be095d --- /dev/null +++ b/catch/performance/memset/hipMemset2D.cc @@ -0,0 +1,71 @@ +/* +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 memset memset + * @{ + * @ingroup PerformanceTest + */ + +class Memset2DBenchmark : public Benchmark { + public: + Memset2DBenchmark(size_t width, size_t height) : dst_(width, height) {} + + void operator()() { + TIMED_SECTION(kTimerTypeEvent) { + HIP_CHECK(hipMemset2D(dst_.ptr(), dst_.pitch(), 17, dst_.width(), dst_.height())); + } + } + + private: + LinearAllocGuard2D dst_; +}; + +static void RunBenchmark(size_t width, size_t height) { + Memset2DBenchmark benchmark(width, height); + benchmark.AddSectionName("(" + std::to_string(width) + ", " + std::to_string(height) + ")"); + benchmark.Run(); +} + +/** + * Test Description + * ------------------------ + * - Executes `hipMemset2D`: + * -# Allocation size + * - Small: 4 KB x 32 B + * - Medium: 4 MB x 32 B + * - Large: 16 MB x 32 B + * Test source + * ------------------------ + * - performance/memset/hipMemset2D.cc + * Test requirements + * ------------------------ + * - HIP_VERSION >= 5.2 + */ +TEST_CASE("Performance_hipMemset2D") { + const auto width = GENERATE(4_KB, 4_MB, 16_MB); + RunBenchmark(width, 32); +} diff --git a/catch/performance/memset/hipMemset2DAsync.cc b/catch/performance/memset/hipMemset2DAsync.cc new file mode 100644 index 0000000000..4f6c68d418 --- /dev/null +++ b/catch/performance/memset/hipMemset2DAsync.cc @@ -0,0 +1,74 @@ +/* +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 memset memset + * @{ + * @ingroup PerformanceTest + */ + +class Memset2DAsyncBenchmark : public Benchmark { + public: + Memset2DAsyncBenchmark(size_t width, size_t height) + : dst_(width, height), stream_(Streams::created) {} + + void operator()(size_t width, size_t height) { + TIMED_SECTION_STREAM(kTimerTypeEvent, stream_.stream()) { + HIP_CHECK(hipMemset2DAsync(dst_.ptr(), dst_.pitch(), 17, dst_.width(), dst_.height(), + stream_.stream())); + } + } + + private: + LinearAllocGuard2D dst_; + StreamGuard stream_; +}; + +static void RunBenchmark(size_t width, size_t height) { + Memset2DAsyncBenchmark benchmark(width, height); + benchmark.AddSectionName("(" + std::to_string(width) + ", " + std::to_string(height) + ")"); + benchmark.Run(width, height); +} + +/** + * Test Description + * ------------------------ + * - Executes `hipMemset2DAsync`: + * -# Allocation size + * - Small: 4 KB x 32 B + * - Medium: 4 MB x 32 B + * - Large: 16 MB x 32 B + * Test source + * ------------------------ + * - performance/memset/hipMemset2DAsync.cc + * Test requirements + * ------------------------ + * - HIP_VERSION >= 5.2 + */ +TEST_CASE("Performance_hipMemset2DAsync") { + const auto width = GENERATE(4_KB, 4_MB, 16_MB); + RunBenchmark(width, 32); +} diff --git a/catch/performance/memset/hipMemset3D.cc b/catch/performance/memset/hipMemset3D.cc new file mode 100644 index 0000000000..69acea51c6 --- /dev/null +++ b/catch/performance/memset/hipMemset3D.cc @@ -0,0 +1,72 @@ +/* +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 memset memset + * @{ + * @ingroup PerformanceTest + */ + +class Memset3DBenchmark : public Benchmark { + public: + Memset3DBenchmark(size_t width, size_t height, size_t depth) : dst_(width, height, depth) {} + + void operator()() { + TIMED_SECTION(kTimerTypeEvent) { + HIP_CHECK(hipMemset3D(dst_.pitched_ptr(), 17, dst_.extent())); + } + } + + private: + LinearAllocGuard3D dst_; +}; + +static void RunBenchmark(size_t width, size_t height, size_t depth) { + Memset3DBenchmark benchmark(width, height, depth); + benchmark.AddSectionName("(" + std::to_string(width) + ", " + std::to_string(height) + ", " + + std::to_string(depth) + ")"); + benchmark.Run(); +} + +/** + * Test Description + * ------------------------ + * - Executes `hipMemset3D`: + * -# Allocation size + * - Small: 4 KB x 16 B x 4 B + * - Medium: 4 MB x 16 B x 4 B + * - Large: 16 MB x 16 B x 4 B + * Test source + * ------------------------ + * - performance/memset/hipMemset3D.cc + * Test requirements + * ------------------------ + * - HIP_VERSION >= 5.2 + */ +TEST_CASE("Performance_hipMemset3D") { + const auto width = GENERATE(4_KB, 4_MB, 16_MB); + RunBenchmark(width, 16, 4); +} diff --git a/catch/performance/memset/hipMemset3DAsync.cc b/catch/performance/memset/hipMemset3DAsync.cc new file mode 100644 index 0000000000..7efb344f9f --- /dev/null +++ b/catch/performance/memset/hipMemset3DAsync.cc @@ -0,0 +1,74 @@ +/* +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 memset memset + * @{ + * @ingroup PerformanceTest + */ + +class Memset3DAsyncBenchmark : public Benchmark { + public: + Memset3DAsyncBenchmark(size_t width, size_t height, size_t depth) + : dst_(width, height, depth), stream_(Streams::created) {} + + void operator()() { + TIMED_SECTION_STREAM(kTimerTypeEvent, stream_.stream()) { + HIP_CHECK(hipMemset3DAsync(dst_.pitched_ptr(), 17, dst_.extent(), stream_.stream())); + } + } + + private: + LinearAllocGuard3D dst_; + StreamGuard stream_; +}; + +static void RunBenchmark(size_t width, size_t height, size_t depth) { + Memset3DAsyncBenchmark benchmark(width, height, depth); + benchmark.AddSectionName("(" + std::to_string(width) + ", " + std::to_string(height) + ", " + + std::to_string(depth) + ")"); + benchmark.Run(); +} + +/** + * Test Description + * ------------------------ + * - Executes `hipMemset3DAsync`: + * -# Allocation size + * - Small: 4 KB x 16 B x 4 B + * - Medium: 4 MB x 16 B x 4 B + * - Large: 16 MB x 16 B x 4 B + * Test source + * ------------------------ + * - performance/memset/hipMemset3DAsync.cc + * Test requirements + * ------------------------ + * - HIP_VERSION >= 5.2 + */ +TEST_CASE("Performance_hipMemset3DAsync") { + const auto width = GENERATE(4_KB, 4_MB, 16_MB); + RunBenchmark(width, 16, 4); +} diff --git a/catch/performance/memset/hipMemsetAsync.cc b/catch/performance/memset/hipMemsetAsync.cc new file mode 100644 index 0000000000..ec82b27887 --- /dev/null +++ b/catch/performance/memset/hipMemsetAsync.cc @@ -0,0 +1,81 @@ +/* +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 memset memset + * @{ + * @ingroup PerformanceTest + */ + +class MemsetAsyncBenchmark : public Benchmark { + public: + MemsetAsyncBenchmark(LinearAllocs allocation_type, size_t size) + : dst_(allocation_type, size), size_(size), stream_(Streams::created) {} + + void operator()() { + TIMED_SECTION_STREAM(kTimerTypeEvent, stream_.stream()) { + HIP_CHECK(hipMemsetAsync(dst_.ptr(), 17, size_, stream_.stream())); + } + } + + private: + LinearAllocGuard dst_; + const size_t size_; + StreamGuard stream_; +}; + +static void RunBenchmark(LinearAllocs allocation_type, size_t size) { + MemsetAsyncBenchmark benchmark(allocation_type, size); + benchmark.AddSectionName(std::to_string(size)); + benchmark.AddSectionName(GetAllocationSectionName(allocation_type)); + benchmark.Run(); +} + +/** + * Test Description + * ------------------------ + * - Executes `hipMemsetAsync`: + * -# Allocation size + * - Small: 4 KB + * - Medium: 4 MB + * - Large: 16 MB + * -# Allocation type + * - device + * - host + * - managed + * Test source + * ------------------------ + * - performance/memset/hipMemsetAsync.cc + * Test requirements + * ------------------------ + * - HIP_VERSION >= 5.2 + */ +TEST_CASE("Performance_hipMemsetAsync") { + const auto size = GENERATE(4_KB, 4_MB, 16_MB); + const auto allocation_type = GENERATE(LinearAllocs::hipMalloc, LinearAllocs::hipHostMalloc, + LinearAllocs::hipMallocManaged); + RunBenchmark(allocation_type, size); +} diff --git a/catch/performance/memset/hipMemsetD16.cc b/catch/performance/memset/hipMemsetD16.cc new file mode 100644 index 0000000000..1f0e50cc6a --- /dev/null +++ b/catch/performance/memset/hipMemsetD16.cc @@ -0,0 +1,80 @@ +/* +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 memset memset + * @{ + * @ingroup PerformanceTest + */ + +class MemsetD16Benchmark : public Benchmark { + public: + MemsetD16Benchmark(LinearAllocs allocation_type, size_t size) + : dst_(allocation_type, size), size_(size) {} + + void operator()() { + TIMED_SECTION(kTimerTypeEvent) { + HIP_CHECK(hipMemsetD16(reinterpret_cast(dst_.ptr()), 311, size_)); + } + } + + private: + LinearAllocGuard dst_; + const size_t size_; +}; + +static void RunBenchmark(LinearAllocs allocation_type, size_t size) { + MemsetD16Benchmark benchmark(allocation_type, size); + benchmark.AddSectionName(std::to_string(size)); + benchmark.AddSectionName(GetAllocationSectionName(allocation_type)); + benchmark.Run(); +} + +/** + * Test Description + * ------------------------ + * - Executes `hipMemsetD16`: + * -# Allocation size + * - Small: 4 KB + * - Medium: 4 MB + * - Large: 16 MB + * -# Allocation type + * - device + * - host + * - managed + * Test source + * ------------------------ + * - performance/memset/hipMemsetD16.cc + * Test requirements + * ------------------------ + * - HIP_VERSION >= 5.2 + */ +TEST_CASE("Performance_hipMemsetD16") { + const auto size = GENERATE(4_KB, 4_MB, 16_MB); + const auto allocation_type = GENERATE(LinearAllocs::hipMalloc, LinearAllocs::hipHostMalloc, + LinearAllocs::hipMallocManaged); + RunBenchmark(allocation_type, size); +} diff --git a/catch/performance/memset/hipMemsetD16Async.cc b/catch/performance/memset/hipMemsetD16Async.cc new file mode 100644 index 0000000000..24aa103218 --- /dev/null +++ b/catch/performance/memset/hipMemsetD16Async.cc @@ -0,0 +1,82 @@ +/* +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 memset memset + * @{ + * @ingroup PerformanceTest + */ + +class MemsetD16AsyncBenchmark : public Benchmark { + public: + MemsetD16AsyncBenchmark(LinearAllocs allocation_type, size_t size) + : dst_(allocation_type, size), size_(size), stream_(Streams::created) {} + + void operator()() { + TIMED_SECTION_STREAM(kTimerTypeEvent, stream_.stream()) { + HIP_CHECK(hipMemsetD16Async(reinterpret_cast(dst_.ptr()), 311, size_, + stream_.stream())); + } + } + + private: + LinearAllocGuard dst_; + const size_t size_; + StreamGuard stream_; +}; + +static void RunBenchmark(LinearAllocs allocation_type, size_t size) { + MemsetD16AsyncBenchmark benchmark(allocation_type, size); + benchmark.AddSectionName(std::to_string(size)); + benchmark.AddSectionName(GetAllocationSectionName(allocation_type)); + benchmark.Run(); +} + +/** + * Test Description + * ------------------------ + * - Executes `hipMemsetD16Async`: + * -# Allocation size + * - Small: 4 KB + * - Medium: 4 MB + * - Large: 16 MB + * -# Allocation type + * - device + * - host + * - managed + * Test source + * ------------------------ + * - performance/memset/hipMemsetD16Async.cc + * Test requirements + * ------------------------ + * - HIP_VERSION >= 5.2 + */ +TEST_CASE("Performance_hipMemsetD16Async") { + const auto size = GENERATE(4_KB, 4_MB, 16_MB); + const auto allocation_type = GENERATE(LinearAllocs::hipMalloc, LinearAllocs::hipHostMalloc, + LinearAllocs::hipMallocManaged); + RunBenchmark(allocation_type, size); +} diff --git a/catch/performance/memset/hipMemsetD32.cc b/catch/performance/memset/hipMemsetD32.cc new file mode 100644 index 0000000000..c64573a54e --- /dev/null +++ b/catch/performance/memset/hipMemsetD32.cc @@ -0,0 +1,80 @@ +/* +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 memset memset + * @{ + * @ingroup PerformanceTest + */ + +class MemsetD32Benchmark : public Benchmark { + public: + MemsetD32Benchmark(LinearAllocs allocation_type, size_t size) + : dst_(allocation_type, size), size_(size) {} + + void operator()() { + TIMED_SECTION(kTimerTypeEvent) { + HIP_CHECK(hipMemsetD32(reinterpret_cast(dst_.ptr()), 123'456, size_)); + } + } + + private: + LinearAllocGuard dst_; + const size_t size_; +}; + +static void RunBenchmark(LinearAllocs allocation_type, size_t size) { + MemsetD32Benchmark benchmark(allocation_type, size); + benchmark.AddSectionName(std::to_string(size)); + benchmark.AddSectionName(GetAllocationSectionName(allocation_type)); + benchmark.Run(); +} + +/** + * Test Description + * ------------------------ + * - Executes `hipMemsetD32`: + * -# Allocation size + * - Small: 4 KB + * - Medium: 4 MB + * - Large: 16 MB + * -# Allocation type + * - device + * - host + * - managed + * Test source + * ------------------------ + * - performance/memset/hipMemsetD32.cc + * Test requirements + * ------------------------ + * - HIP_VERSION >= 5.2 + */ +TEST_CASE("Performance_hipMemsetD32") { + const auto size = GENERATE(4_KB, 4_MB, 16_MB); + const auto allocation_type = GENERATE(LinearAllocs::hipMalloc, LinearAllocs::hipHostMalloc, + LinearAllocs::hipMallocManaged); + RunBenchmark(allocation_type, size); +} diff --git a/catch/performance/memset/hipMemsetD32Async.cc b/catch/performance/memset/hipMemsetD32Async.cc new file mode 100644 index 0000000000..d755bee5b0 --- /dev/null +++ b/catch/performance/memset/hipMemsetD32Async.cc @@ -0,0 +1,82 @@ +/* +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 memset memset + * @{ + * @ingroup PerformanceTest + */ + +class MemsetD32AsyncBenchmark : public Benchmark { + public: + MemsetD32AsyncBenchmark(LinearAllocs allocation_type, size_t size) + : dst_(allocation_type, size), size_(size), stream_(Streams::created) {} + + void operator()() { + TIMED_SECTION_STREAM(kTimerTypeEvent, stream_.stream()) { + HIP_CHECK(hipMemsetD32Async(reinterpret_cast(dst_.ptr()), 123'456, size_, + stream_.stream())); + } + } + + private: + LinearAllocGuard dst_; + const size_t size_; + StreamGuard stream_; +}; + +static void RunBenchmark(LinearAllocs allocation_type, size_t size) { + MemsetD32AsyncBenchmark benchmark(allocation_type, size); + benchmark.AddSectionName(std::to_string(size)); + benchmark.AddSectionName(GetAllocationSectionName(allocation_type)); + benchmark.Run(); +} + +/** + * Test Description + * ------------------------ + * - Executes `hipMemsetD32Async`: + * -# Allocation size + * - Small: 4 KB + * - Medium: 4 MB + * - Large: 16 MB + * -# Allocation type + * - device + * - host + * - managed + * Test source + * ------------------------ + * - performance/memset/hipMemsetD32Async.cc + * Test requirements + * ------------------------ + * - HIP_VERSION >= 5.2 + */ +TEST_CASE("Performance_hipMemsetD32Async") { + const auto size = GENERATE(4_KB, 4_MB, 16_MB); + const auto allocation_type = GENERATE(LinearAllocs::hipMalloc, LinearAllocs::hipHostMalloc, + LinearAllocs::hipMallocManaged); + RunBenchmark(allocation_type, size); +} diff --git a/catch/performance/memset/hipMemsetD8.cc b/catch/performance/memset/hipMemsetD8.cc new file mode 100644 index 0000000000..b05a30d11a --- /dev/null +++ b/catch/performance/memset/hipMemsetD8.cc @@ -0,0 +1,80 @@ +/* +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 memset memset + * @{ + * @ingroup PerformanceTest + */ + +class MemsetD8Benchmark : public Benchmark { + public: + MemsetD8Benchmark(LinearAllocs allocation_type, size_t size) + : dst_(allocation_type, size), size_(size) {} + + void operator()() { + TIMED_SECTION(kTimerTypeEvent) { + HIP_CHECK(hipMemsetD8(reinterpret_cast(dst_.ptr()), 17, size_)); + } + } + + private: + LinearAllocGuard dst_; + const size_t size_; +}; + +static void RunBenchmark(LinearAllocs allocation_type, size_t size) { + MemsetD8Benchmark benchmark(allocation_type, size); + benchmark.AddSectionName(std::to_string(size)); + benchmark.AddSectionName(GetAllocationSectionName(allocation_type)); + benchmark.Run(); +} + +/** + * Test Description + * ------------------------ + * - Executes `hipMemsetD8`: + * -# Allocation size + * - Small: 4 KB + * - Medium: 4 MB + * - Large: 16 MB + * -# Allocation type + * - device + * - host + * - managed + * Test source + * ------------------------ + * - performance/memset/hipMemsetD8.cc + * Test requirements + * ------------------------ + * - HIP_VERSION >= 5.2 + */ +TEST_CASE("Performance_hipMemsetD8") { + const auto size = GENERATE(4_KB, 4_MB, 16_MB); + const auto allocation_type = GENERATE(LinearAllocs::hipMalloc, LinearAllocs::hipHostMalloc, + LinearAllocs::hipMallocManaged); + RunBenchmark(allocation_type, size); +} diff --git a/catch/performance/memset/hipMemsetD8Async.cc b/catch/performance/memset/hipMemsetD8Async.cc new file mode 100644 index 0000000000..73d734530b --- /dev/null +++ b/catch/performance/memset/hipMemsetD8Async.cc @@ -0,0 +1,82 @@ +/* +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 memset memset + * @{ + * @ingroup PerformanceTest + */ + +class MemsetD8AsyncBenchmark : public Benchmark { + public: + MemsetD8AsyncBenchmark(LinearAllocs allocation_type, size_t size) + : dst_(allocation_type, size), size_(size), stream_(Streams::created) {} + + void operator()() { + TIMED_SECTION_STREAM(kTimerTypeEvent, stream_.stream()) { + HIP_CHECK(hipMemsetD8Async(reinterpret_cast(dst_.ptr()), 17, size_, + stream_.stream())); + } + } + + private: + LinearAllocGuard dst_; + const size_t size_; + StreamGuard stream_; +}; + +static void RunBenchmark(LinearAllocs allocation_type, size_t size) { + MemsetD8AsyncBenchmark benchmark(allocation_type, size); + benchmark.AddSectionName(std::to_string(size)); + benchmark.AddSectionName(GetAllocationSectionName(allocation_type)); + benchmark.Run(); +} + +/** + * Test Description + * ------------------------ + * - Executes `hipMemsetD8Async`: + * -# Allocation size + * - Small: 4 KB + * - Medium: 4 MB + * - Large: 16 MB + * -# Allocation type + * - device + * - host + * - managed + * Test source + * ------------------------ + * - performance/memset/hipMemsetD8Async.cc + * Test requirements + * ------------------------ + * - HIP_VERSION >= 5.2 + */ +TEST_CASE("Performance_hipMemsetD8Async") { + const auto size = GENERATE(4_KB, 4_MB, 16_MB); + const auto allocation_type = GENERATE(LinearAllocs::hipMalloc, LinearAllocs::hipHostMalloc, + LinearAllocs::hipMallocManaged); + RunBenchmark(allocation_type, size); +}