/* * Copyright (c) Advanced Micro Devices, Inc., or its affiliates. * * SPDX-License-Identifier: MIT */ #include "memcpy_performance_common.hh" /** * @addtogroup memcpy memcpy * @{ * @ingroup PerformanceTestMemory */ class MemcpyDtoHAsyncBenchmark : public Benchmark { public: void operator()(void* dst, const hipDeviceptr_t& src, size_t size, const hipStream_t& stream) { TIMED_SECTION_STREAM(kTimerTypeEvent, stream) { HIP_CHECK(hipMemcpyDtoHAsync(dst, src, size, stream)); } HIP_CHECK(hipStreamSynchronize(stream)); } }; static void RunBenchmark(LinearAllocs host_allocation_type, LinearAllocs device_allocation_type, size_t size) { MemcpyDtoHAsyncBenchmark benchmark; benchmark.AddSectionName(std::to_string(size)); benchmark.AddSectionName(GetAllocationSectionName(host_allocation_type)); const StreamGuard stream_guard(Streams::created); const hipStream_t stream = stream_guard.stream(); LinearAllocGuard device_allocation(device_allocation_type, size); LinearAllocGuard host_allocation(host_allocation_type, size); benchmark.Run(host_allocation.ptr(), reinterpret_cast(device_allocation.ptr()), size, stream); } /** * Test Description * ------------------------ * - Executes `hipMemcpyDtoHAsync` from Device to Host: * -# Allocation size * - Small: 4 KB * - Medium: 4 MB * - Large: 16 MB * -# Allocation type * - Source: device malloc * - Destination: host pinned and pageable * Test source * ------------------------ * - performance/api/memcpy/hipMemcpyDtoHAsync.cc * Test requirements * ------------------------ * - HIP_VERSION >= 5.2 */ HIP_TEST_CASE(Performance_hipMemcpyDtoHAsync) { const auto allocation_size = GENERATE(4_KB, 4_MB, 16_MB); const auto device_allocation_type = LinearAllocs::hipMalloc; const auto host_allocation_type = GENERATE(LinearAllocs::malloc, LinearAllocs::hipHostMalloc); RunBenchmark(host_allocation_type, device_allocation_type, allocation_size); } /** * End doxygen group memcpy. * @} */