From b186f5c6e18a9fa2abe81a7ec34a8981920d9f0b 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 15:04:34 +0100 Subject: [PATCH] EXSWHTEC-345 - Implement tests for hipPointerSetAttribute #427 Change-Id: I71e4eb3aab07eff8e24f54fa266a3971839501d1 [ROCm/hip-tests commit: 20a38116967ed6665262c6ccb9ce766e1b894e72] --- .../catch/hipTestMain/config/config_amd_linux | 2 + .../hipTestMain/config/config_amd_windows | 2 + .../catch/unit/memory/CMakeLists.txt | 13 ++- .../unit/memory/hipPointerSetAttribute.cc | 108 ++++++++++++++++++ 4 files changed, 124 insertions(+), 1 deletion(-) create mode 100644 projects/hip-tests/catch/unit/memory/hipPointerSetAttribute.cc diff --git a/projects/hip-tests/catch/hipTestMain/config/config_amd_linux b/projects/hip-tests/catch/hipTestMain/config/config_amd_linux index cf72d409d4..66107df9e1 100644 --- a/projects/hip-tests/catch/hipTestMain/config/config_amd_linux +++ b/projects/hip-tests/catch/hipTestMain/config/config_amd_linux @@ -128,6 +128,8 @@ "Unit_hipEventIpc", "=== SWDEV-427101:Below test fails randomly in PSDB ===", "Unit_deviceAllocation_InOneThread_AccessInAllThreads", + "=== Below test is disabled due to defect EXSWHTEC-347 ===", + "Unit_hipPointerSetAttribute_Positive_SyncMemops", "=== Patch which removes the typetraits implementation from std namespace in hiprtc is reverted ===", "Unit_hiprtc_stdheaders", "Unit_hipGraphAddMemcpyNode_Negative_Parameters", diff --git a/projects/hip-tests/catch/hipTestMain/config/config_amd_windows b/projects/hip-tests/catch/hipTestMain/config/config_amd_windows index 724aef781e..5631444f2b 100644 --- a/projects/hip-tests/catch/hipTestMain/config/config_amd_windows +++ b/projects/hip-tests/catch/hipTestMain/config/config_amd_windows @@ -213,6 +213,8 @@ "Unit_hipVectorTypes_test_on_device", "Unit_Layered1DTexture_Check_DeviceBufferToFromLayered1DArray - ushort4", "Unit_Layered2DTexture_Check_DeviceBufferToFromLayered2DArray - float4", + "=== Below test is disabled due to defect EXSWHTEC-347 ===", + "Unit_hipPointerSetAttribute_Positive_SyncMemops", "=== Patch which removes the typetraits implementation from std namespace in hiprtc is reverted ===", "Unit_hiprtc_stdheaders", "NOTE: The following test is disabled due to defect - EXSWHTEC-241", diff --git a/projects/hip-tests/catch/unit/memory/CMakeLists.txt b/projects/hip-tests/catch/unit/memory/CMakeLists.txt index d99cf33b32..431a9f72e1 100644 --- a/projects/hip-tests/catch/unit/memory/CMakeLists.txt +++ b/projects/hip-tests/catch/unit/memory/CMakeLists.txt @@ -83,7 +83,18 @@ if(HIP_PLATFORM MATCHES "amd") hipExtMallocWithFlags.cc hipMallocMngdMultiThread.cc hipArray.cc - hipMemVmm.cc) + hipMemVmm.cc + hipPointerSetAttribute.cc # Should be compiled for NVIDIA as well after EXSWHTEC-346 is addressed + hipMemCreate.cc + hipMemMap.cc + hipMemGetAllocationGranularity.cc + hipMemSetGetAccess.cc + hipMemRetainAllocationHandle.cc + hipMemUnmap.cc + hipMemAddressFree.cc + hipMemAddressReserve.cc + hipMemRelease.cc + hipMemGetAllocationPropertiesFromHandle.cc) else() set(TEST_SRC ${TEST_SRC} hipGetSymbolSizeAddress.cc) endif() diff --git a/projects/hip-tests/catch/unit/memory/hipPointerSetAttribute.cc b/projects/hip-tests/catch/unit/memory/hipPointerSetAttribute.cc new file mode 100644 index 0000000000..ebce0855b2 --- /dev/null +++ b/projects/hip-tests/catch/unit/memory/hipPointerSetAttribute.cc @@ -0,0 +1,108 @@ +/* +Copyright (c) 2023 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. +*/ + +/** + * @addtogroup hipPointerSetAttribute hipPointerSetAttribute + * @{ + * @ingroup MemoryTest + * `hipPointerSetAttribute(const void* value, hipPointer_attribute attribute, hipDeviceptr_t ptr)` - + * Set attributes on a previously allocated memory region. + */ + +#include +#include +#include + +/** + * Test Description + * ------------------------ + * - Sets pointer attribute `HIP_POINTER_ATTRIBUTE_SYNC_MEMOPS` and verifies behavior. + * Test source + * ------------------------ + * - unit/memory/hipPointerSetAttribute.cc + * Test requirements + * ------------------------ + * - HIP_VERSION >= 5.5 + */ +TEST_CASE("Unit_hipPointerSetAttribute_Positive_SyncMemops") { + LinearAllocGuard src(LinearAllocs::hipMalloc, 1024); + LinearAllocGuard dst(LinearAllocs::hipMalloc, 1024); + + StreamGuard stream(Streams::created); + LaunchDelayKernel(std::chrono::milliseconds{100}, stream.stream()); + HIP_CHECK(hipMemcpy(dst.ptr(), src.ptr(), 1024, hipMemcpyDeviceToDevice)); + HIP_CHECK_ERROR(hipStreamQuery(stream.stream()), hipErrorNotReady); + + bool value = true; + HIP_CHECK(hipPointerSetAttribute(&value, HIP_POINTER_ATTRIBUTE_SYNC_MEMOPS, + reinterpret_cast(src.ptr()))); + HIP_CHECK(hipPointerSetAttribute(&value, HIP_POINTER_ATTRIBUTE_SYNC_MEMOPS, + reinterpret_cast(dst.ptr()))); + + LaunchDelayKernel(std::chrono::milliseconds{100}, stream.stream()); + HIP_CHECK(hipMemcpy(dst.ptr(), src.ptr(), 1024, hipMemcpyDeviceToDevice)); + HIP_CHECK(hipStreamQuery(stream.stream())); +} + +/** + * Test Description + * ------------------------ + * - Negative parameters test for `hipPointerSetAttribute`. + * Test source + * ------------------------ + * - unit/memory/hipPointerSetAttribute.cc + * Test requirements + * ------------------------ + * - HIP_VERSION >= 5.5 + */ +TEST_CASE("Unit_hipPointerSetAttribute_Negative_Parameters") { + LinearAllocGuard mem(LinearAllocs::hipMalloc, 4); + bool value = false; + + SECTION("value is nullptr") { + HIP_CHECK_ERROR(hipPointerSetAttribute(nullptr, HIP_POINTER_ATTRIBUTE_SYNC_MEMOPS, mem.ptr()), + hipErrorInvalidValue); + } + + SECTION("invalid attribute") { + HIP_CHECK_ERROR( + hipPointerSetAttribute(&value, static_cast(-1), mem.ptr()), + hipErrorInvalidValue); + } + + SECTION("ptr is nullptr") { + HIP_CHECK_ERROR(hipPointerSetAttribute(&value, HIP_POINTER_ATTRIBUTE_SYNC_MEMOPS, nullptr), + hipErrorInvalidValue); + } + + SECTION("host pointer") { + int mem_host; + HIP_CHECK_ERROR(hipPointerSetAttribute(&value, HIP_POINTER_ATTRIBUTE_SYNC_MEMOPS, &mem_host), + hipErrorInvalidDevicePointer); + } + + SECTION("freed pointer") { + HIP_CHECK(hipFree(mem.ptr())); + HIP_CHECK_ERROR(hipPointerSetAttribute(&value, HIP_POINTER_ATTRIBUTE_SYNC_MEMOPS, mem.ptr()), + hipErrorInvalidDevicePointer); + } +} \ No newline at end of file