CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
107 lines
4.4 KiB
C++
107 lines
4.4 KiB
C++
/*
|
|
* Copyright (c) Advanced Micro Devices, Inc., or its affiliates.
|
|
*
|
|
* SPDX-License-Identifier: MIT
|
|
*/
|
|
|
|
#include <hip_test_common.hh>
|
|
#include <hip/hip_runtime_api.h>
|
|
#include <memcpy1d_tests_common.hh>
|
|
#include <resource_guards.hh>
|
|
#include <utils.hh>
|
|
|
|
HIP_TEST_CASE(Unit_hipMemcpy_Positive_Basic) { MemcpyWithDirectionCommonTests<false>(hipMemcpy); }
|
|
|
|
HIP_TEST_CASE(Unit_hipMemcpy_Positive_Synchronization_Behavior) {
|
|
using namespace std::placeholders;
|
|
HIP_CHECK(hipDeviceSynchronize());
|
|
|
|
// For transfers from pageable host memory to device memory, a stream sync is performed before
|
|
// the copy is initiated. The function will return once the pageable buffer has been copied to
|
|
// the staging memory for DMA transfer to device memory, but the DMA to final destination may
|
|
// not have completed.
|
|
// For transfers from pinned host memory to device memory, the function is synchronous with
|
|
// respect to the host
|
|
SECTION("Host memory to device memory") {
|
|
MemcpyHPageabletoDSyncBehavior(std::bind(hipMemcpy, _1, _2, _3, hipMemcpyHostToDevice), true);
|
|
}
|
|
|
|
// For transfers from device to either pageable or pinned host memory, the function returns only
|
|
// once the copy has completed
|
|
SECTION("Device memory to host memory") {
|
|
const auto f = std::bind(hipMemcpy, _1, _2, _3, hipMemcpyDeviceToHost);
|
|
MemcpyDtoHPageableSyncBehavior(f, true);
|
|
MemcpyDtoHPinnedSyncBehavior(f, true);
|
|
}
|
|
|
|
// For transfers from device memory to device memory, no host-side synchronization is performed.
|
|
SECTION("Device memory to device memory") {
|
|
// This behavior differs on NVIDIA and AMD, on AMD the hipMemcpy calls is synchronous with
|
|
// respect to the host
|
|
#if HT_AMD
|
|
WARN(
|
|
"EXSWCPHIPT-127 - Memcpy from device to device memory behavior differs on AMD and Nvidia");
|
|
return;
|
|
#endif
|
|
MemcpyDtoDSyncBehavior(std::bind(hipMemcpy, _1, _2, _3, hipMemcpyDeviceToDevice), false);
|
|
}
|
|
|
|
// For transfers from any host memory to any host memory, the function is fully synchronous with
|
|
// respect to the host
|
|
SECTION("Host memory to host memory") {
|
|
MemcpyHtoHSyncBehavior(std::bind(hipMemcpy, _1, _2, _3, hipMemcpyHostToHost), true);
|
|
}
|
|
}
|
|
|
|
HIP_TEST_CASE(Unit_hipMemcpy_Negative_Parameters) {
|
|
using namespace std::placeholders;
|
|
|
|
SECTION("Host to device") {
|
|
LinearAllocGuard<int> device_alloc(LinearAllocs::hipMalloc, kPageSize);
|
|
LinearAllocGuard<int> host_alloc(LinearAllocs::hipHostMalloc, kPageSize);
|
|
MemcpyWithDirectionCommonNegativeTests(hipMemcpy, device_alloc.ptr(), host_alloc.ptr(),
|
|
kPageSize, hipMemcpyHostToDevice);
|
|
}
|
|
|
|
SECTION("Device to host") {
|
|
LinearAllocGuard<int> device_alloc(LinearAllocs::hipMalloc, kPageSize);
|
|
LinearAllocGuard<int> host_alloc(LinearAllocs::hipHostMalloc, kPageSize);
|
|
MemcpyWithDirectionCommonNegativeTests(hipMemcpy, host_alloc.ptr(), device_alloc.ptr(),
|
|
kPageSize, hipMemcpyDeviceToHost);
|
|
}
|
|
|
|
SECTION("Host to host") {
|
|
LinearAllocGuard<int> src_alloc(LinearAllocs::hipHostMalloc, kPageSize);
|
|
LinearAllocGuard<int> dst_alloc(LinearAllocs::hipHostMalloc, kPageSize);
|
|
MemcpyWithDirectionCommonNegativeTests(hipMemcpy, dst_alloc.ptr(), src_alloc.ptr(), kPageSize,
|
|
hipMemcpyHostToHost);
|
|
}
|
|
|
|
SECTION("Device to device") {
|
|
LinearAllocGuard<int> src_alloc(LinearAllocs::hipMalloc, kPageSize);
|
|
LinearAllocGuard<int> dst_alloc(LinearAllocs::hipMalloc, kPageSize);
|
|
MemcpyWithDirectionCommonNegativeTests(hipMemcpy, dst_alloc.ptr(), src_alloc.ptr(), kPageSize,
|
|
hipMemcpyDeviceToDevice);
|
|
}
|
|
}
|
|
|
|
HIP_TEST_CASE(Unit_hipMemcpyWithStream_Capture) {
|
|
constexpr size_t kNumElements = 1024;
|
|
|
|
LinearAllocGuard<int> host_data(LinearAllocs::malloc, kNumElements * sizeof(int));
|
|
LinearAllocGuard<int> device_data(LinearAllocs::hipMalloc, kNumElements * sizeof(int));
|
|
|
|
hipStream_t stream;
|
|
HIP_CHECK(hipStreamCreate(&stream));
|
|
|
|
HIP_CHECK(hipStreamBeginCapture(stream, hipStreamCaptureModeGlobal));
|
|
|
|
HIP_CHECK_ERROR(hipMemcpyWithStream(device_data.ptr(), host_data.ptr(),
|
|
kNumElements * sizeof(int), hipMemcpyHostToDevice, stream),
|
|
hipErrorStreamCaptureUnsupported);
|
|
|
|
HIP_CHECK_ERROR(hipStreamEndCapture(stream, nullptr), hipErrorStreamCaptureInvalidated);
|
|
|
|
HIP_CHECK(hipStreamDestroy(stream));
|
|
}
|