From f6402bbc10ea6955e07c8e0a6aacf6da92171fa2 Mon Sep 17 00:00:00 2001 From: Mirza Halilcevic Date: Fri, 15 Dec 2023 16:05:13 +0530 Subject: [PATCH] EXSWHTEC-341 - Refactor tests for hipDeviceSetLimit and hipDeviceGetLimit (#425) Change-Id: Ib1e6937d0e391ec31fac47b89bb59489cff6a284 [ROCm/hip-tests commit: c6ba00b9dee18bcb8d4898c7751e4064aeeb87e7] --- .../config/config_nvidia_linux.json | 5 +- .../config/config_nvidia_windows.json | 5 +- .../catch/unit/device/CMakeLists.txt | 5 +- ...ceGetLimit.cc => hipDeviceGetLimit_old.cc} | 0 .../catch/unit/device/hipDeviceSetGetLimit.cc | 190 ++++++++++++++++++ ...ceSetLimit.cc => hipDeviceSetLimit_old.cc} | 0 6 files changed, 201 insertions(+), 4 deletions(-) rename projects/hip-tests/catch/unit/device/{hipDeviceGetLimit.cc => hipDeviceGetLimit_old.cc} (100%) create mode 100644 projects/hip-tests/catch/unit/device/hipDeviceSetGetLimit.cc rename projects/hip-tests/catch/unit/device/{hipDeviceSetLimit.cc => hipDeviceSetLimit_old.cc} (100%) diff --git a/projects/hip-tests/catch/hipTestMain/config/config_nvidia_linux.json b/projects/hip-tests/catch/hipTestMain/config/config_nvidia_linux.json index cdf3eccc68..d2467d0fca 100644 --- a/projects/hip-tests/catch/hipTestMain/config/config_nvidia_linux.json +++ b/projects/hip-tests/catch/hipTestMain/config/config_nvidia_linux.json @@ -70,6 +70,9 @@ "Unit_Device_Complex_Unary_double_Negative", "Unit_Device_Complex_Binary_float_Negative", "Unit_Device_Complex_Binary_double_Negative", - "Unit_Device_Complex_hipCfma_Negative" + "Unit_Device_Complex_hipCfma_Negative", + "=== Below 2 tests are disabled due to defect EXSWHTEC-342 ===", + "Unit_hipDeviceSetLimit_Negative_Parameters", + "Unit_hipDeviceGetLimit_Negative_Parameters" ] } diff --git a/projects/hip-tests/catch/hipTestMain/config/config_nvidia_windows.json b/projects/hip-tests/catch/hipTestMain/config/config_nvidia_windows.json index 94aaeb1201..3c9c53c490 100644 --- a/projects/hip-tests/catch/hipTestMain/config/config_nvidia_windows.json +++ b/projects/hip-tests/catch/hipTestMain/config/config_nvidia_windows.json @@ -28,6 +28,9 @@ "Unit_Device_Complex_Unary_double_Negative", "Unit_Device_Complex_Binary_float_Negative", "Unit_Device_Complex_Binary_double_Negative", - "Unit_Device_Complex_hipCfma_Negative" + "Unit_Device_Complex_hipCfma_Negative", + "=== Below 2 tests are disabled due to defect EXSWHTEC-342 ===", + "Unit_hipDeviceSetLimit_Negative_Parameters", + "Unit_hipDeviceGetLimit_Negative_Parameters" ] } diff --git a/projects/hip-tests/catch/unit/device/CMakeLists.txt b/projects/hip-tests/catch/unit/device/CMakeLists.txt index 8a14c06860..d7de547fe6 100644 --- a/projects/hip-tests/catch/unit/device/CMakeLists.txt +++ b/projects/hip-tests/catch/unit/device/CMakeLists.txt @@ -3,7 +3,7 @@ set(TEST_SRC hipChooseDevice.cc hipDeviceComputeCapability.cc hipDeviceGetByPCIBusId.cc - hipDeviceGetLimit.cc + hipDeviceGetLimit_old.cc hipDeviceGetName.cc hipDeviceGetPCIBusId.cc hipDeviceSetGetCacheConfig.cc @@ -20,7 +20,8 @@ set(TEST_SRC hipDeviceCanAccessPeer.cc hipDeviceEnableDisablePeerAccess.cc hipExtGetLinkTypeAndHopCount.cc - hipDeviceSetLimit.cc + hipDeviceSetLimit_old.cc + hipDeviceSetGetLimit.cc hipDeviceSetGetSharedMemConfig.cc hipDeviceReset.cc hipDeviceSetGetMemPool.cc diff --git a/projects/hip-tests/catch/unit/device/hipDeviceGetLimit.cc b/projects/hip-tests/catch/unit/device/hipDeviceGetLimit_old.cc similarity index 100% rename from projects/hip-tests/catch/unit/device/hipDeviceGetLimit.cc rename to projects/hip-tests/catch/unit/device/hipDeviceGetLimit_old.cc diff --git a/projects/hip-tests/catch/unit/device/hipDeviceSetGetLimit.cc b/projects/hip-tests/catch/unit/device/hipDeviceSetGetLimit.cc new file mode 100644 index 0000000000..87b417d942 --- /dev/null +++ b/projects/hip-tests/catch/unit/device/hipDeviceSetGetLimit.cc @@ -0,0 +1,190 @@ +/* +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 WARRANNTY OF ANY KIND, EXPRESS OR +IMPLIED, INNCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANNY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER INN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR INN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + +#include + +/** + * @addtogroup hipDeviceSetLimit hipDeviceSetLimit + * @{ + * @ingroup DeviceTest + * `hipDeviceSetLimit(enum hipLimit_t limit, size_t value)` - + * Set Resource limits of current device. + */ + +void DeviceSetLimitTest(hipLimit_t limit) { + size_t old_val; + HIP_CHECK(hipDeviceGetLimit(&old_val, limit)); + REQUIRE(old_val != 0); + + HIP_CHECK(hipDeviceSetLimit(limit, old_val + 8)); + + size_t new_val; + HIP_CHECK(hipDeviceGetLimit(&new_val, limit)); + REQUIRE(new_val >= old_val + 8); +} + +/** + * Test Description + * ------------------------ + * - Basic set-get test for `hipLimitStackSize`. + * Test source + * ------------------------ + * - unit/device/hipDeviceSetGetLimit.cc + * Test requirements + * ------------------------ + * - HIP_VERSION >= 5.3 + */ +TEST_CASE("Unit_hipDeviceSetLimit_Positive_StackSize") { DeviceSetLimitTest(hipLimitStackSize); } + +#if HT_NVIDIA + +__device__ __managed__ bool stop = false; + +/** + * Test Description + * ------------------------ + * - Basic set-get test for `hipLimitPrintfFifoSize`. + * Test source + * ------------------------ + * - unit/device/hipDeviceSetGetLimit.cc + * Test requirements + * ------------------------ + * - HIP_VERSION >= 5.3 + */ +TEST_CASE("Unit_hipDeviceSetLimit_Positive_PrintfFifoSize") { + DeviceSetLimitTest(hipLimitPrintfFifoSize); +} + +__global__ void PrintfKernel() { + while (!stop) printf(""); +} + +/** + * Test Description + * ------------------------ + * - Tests scenario where we try to set `hipLimitPrintfFifoSize` while a kernel that calls + * `printf()` is running. + * Test source + * ------------------------ + * - unit/device/hipDeviceSetGetLimit.cc + * Test requirements + * ------------------------ + * - HIP_VERSION >= 5.3 + */ +TEST_CASE("Unit_hipDeviceSetLimit_Negative_PrintfFifoSize") { + PrintfKernel<<<1, 1>>>(); + HIP_CHECK_ERROR(hipDeviceSetLimit(hipLimitPrintfFifoSize, 1024), hipErrorInvalidValue); + stop = true; + HIP_CHECK(hipDeviceSynchronize()); + stop = false; +} + +/** + * Test Description + * ------------------------ + * - Basic set-get test for `hipLimitMallocHeapSize`. + * Test source + * ------------------------ + * - unit/device/hipDeviceSetGetLimit.cc + * Test requirements + * ------------------------ + * - HIP_VERSION >= 5.3 + */ +TEST_CASE("Unit_hipDeviceSetLimit_Positive_MallocHeapSize") { + DeviceSetLimitTest(hipLimitMallocHeapSize); +} + +__global__ void MallocKernel() { + while (!stop) free(malloc(1)); +} + +/** + * Test Description + * ------------------------ + * - Tests scenario where we try to set `hipLimitMallocHeapSize` while a kernel that calls + * `malloc()` and `free()` is running. + * Test source + * ------------------------ + * - unit/device/hipDeviceSetGetLimit.cc + * Test requirements + * ------------------------ + * - HIP_VERSION >= 5.3 + */ +TEST_CASE("Unit_hipDeviceSetLimit_Negative_MallocHeapSize") { + MallocKernel<<<1, 1>>>(); + HIP_CHECK_ERROR(hipDeviceSetLimit(hipLimitMallocHeapSize, 1024), hipErrorInvalidValue); + stop = true; + HIP_CHECK(hipDeviceSynchronize()); + stop = false; +} + +#endif + +/** + * Test Description + * ------------------------ + * - Negative parameters test for `hipDeviceSetLimit`. + * Test source + * ------------------------ + * - unit/device/hipDeviceSetGetLimit.cc + * Test requirements + * ------------------------ + * - HIP_VERSION >= 5.3 + */ +TEST_CASE("Unit_hipDeviceSetLimit_Negative_Parameters") { + HIP_CHECK_ERROR(hipDeviceSetLimit(static_cast(-1), 1024), hipErrorUnsupportedLimit); +} + +/** + * End doxygen group hipDeviceSetLimit. + * @} + */ + +/** + * @addtogroup hipDeviceGetLimit hipDeviceGetLimit + * @{ + * @ingroup DeviceTest + * `hipDeviceGetLimit(size_t* pValue, enum hipLimit_t limit)` - + * Get Resource limits of current device. + */ + +/** + * Test Description + * ------------------------ + * - Negative parameters test for `hipDeviceGetLimit`. + * Test source + * ------------------------ + * - unit/device/hipDeviceSetGetLimit.cc + * Test requirements + * ------------------------ + * - HIP_VERSION >= 5.2 + */ +TEST_CASE("Unit_hipDeviceGetLimit_Negative_Parameters") { + SECTION("nullptr") { + HIP_CHECK_ERROR(hipDeviceGetLimit(nullptr, hipLimitStackSize), hipErrorInvalidValue); + } + + SECTION("unsupported limit") { + size_t val; + HIP_CHECK_ERROR(hipDeviceGetLimit(&val, static_cast(-1)), hipErrorUnsupportedLimit); + } +} \ No newline at end of file diff --git a/projects/hip-tests/catch/unit/device/hipDeviceSetLimit.cc b/projects/hip-tests/catch/unit/device/hipDeviceSetLimit_old.cc similarity index 100% rename from projects/hip-tests/catch/unit/device/hipDeviceSetLimit.cc rename to projects/hip-tests/catch/unit/device/hipDeviceSetLimit_old.cc