From 5ee70b6d8276cb938337ddca9ee80fce912338b3 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, 3 Nov 2022 03:32:25 +0100 Subject: [PATCH] EXSWHTEC-26 - Implement tests for hipDeviceSetCacheConfig and hipDeviceGetCacheConfig (#2919) - Negative parameter tests - Default return value test - Multithreaded test - Reorder tests and generate test cases for all available devices in certain tests. - Add checks for hipDeviceSetCacheConfig not being supported on AMD. - Remove NVIDIA guards from tests and disable tests on AMD platform. [ROCm/hip commit: 60c0251ff10038bbb70b361b6e2040361b9812de] --- .../config/config_amd_linux_common.json | 4 +- .../config/config_amd_windows_common.json | 2 + .../unit/device/hipDeviceSetGetCacheConfig.cc | 125 +++++++++++++----- 3 files changed, 99 insertions(+), 32 deletions(-) diff --git a/projects/hip/tests/catch/hipTestMain/config/config_amd_linux_common.json b/projects/hip/tests/catch/hipTestMain/config/config_amd_linux_common.json index 60ef935548..8b8c42fcd4 100644 --- a/projects/hip/tests/catch/hipTestMain/config/config_amd_linux_common.json +++ b/projects/hip/tests/catch/hipTestMain/config/config_amd_linux_common.json @@ -2,6 +2,8 @@ "DisabledTests": [ "Unit_hipStreamPerThread_DeviceReset_1", - "Unit_hipMallocManaged_OverSubscription" + "Unit_hipMallocManaged_OverSubscription", + "Unit_hipDeviceGetCacheConfig_Positive_Basic", + "Unit_hipDeviceGetCacheConfig_Positive_Threaded" ] } diff --git a/projects/hip/tests/catch/hipTestMain/config/config_amd_windows_common.json b/projects/hip/tests/catch/hipTestMain/config/config_amd_windows_common.json index 07a4714117..2094761dc2 100644 --- a/projects/hip/tests/catch/hipTestMain/config/config_amd_windows_common.json +++ b/projects/hip/tests/catch/hipTestMain/config/config_amd_windows_common.json @@ -79,6 +79,8 @@ "Unit_hipStreamQuery_WithPendingWork", "Unit_hipStreamWaitEvent_DifferentStreams", "Unit_hipStreamQuery_WithFinishedWork", + "Unit_hipDeviceGetCacheConfig_Positive_Basic", + "Unit_hipDeviceGetCacheConfig_Positive_Threaded", "Unit_hipStreamValue_Wait32_Blocking_Mask_Gte", "Unit_hipStreamValue_Wait32_Blocking_Mask_Eq_1", "Unit_hipStreamValue_Wait32_Blocking_Mask_Eq_2", diff --git a/projects/hip/tests/catch/unit/device/hipDeviceSetGetCacheConfig.cc b/projects/hip/tests/catch/unit/device/hipDeviceSetGetCacheConfig.cc index 01dfdc3d63..b093336d6a 100644 --- a/projects/hip/tests/catch/unit/device/hipDeviceSetGetCacheConfig.cc +++ b/projects/hip/tests/catch/unit/device/hipDeviceSetGetCacheConfig.cc @@ -1,45 +1,108 @@ /* -Copyright (c) 2021 Advanced Micro Devices, Inc. All rights reserved. +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 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 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 -/** - * hipDeviceGetCacheConfig tests - * Scenario1: Validates if pConfig = nullptr returns hip error code. - * Scenario2: Validates if the value returned by hipDeviceGetCacheConfig is valid. - */ -TEST_CASE("Unit_hipDeviceGetCacheConfig_NegTst") { - // Scenario1 - REQUIRE_FALSE(hipSuccess == hipDeviceGetCacheConfig(nullptr)); -} -TEST_CASE("Unit_hipDeviceGetCacheConfig_FuncTst") { - hipFuncCache_t cacheConfig; - // Scenario2 - HIP_CHECK(hipDeviceGetCacheConfig(&cacheConfig)); - REQUIRE_FALSE(((cacheConfig != hipFuncCachePreferNone) && - (cacheConfig != hipFuncCachePreferShared) && - (cacheConfig != hipFuncCachePreferL1) && - (cacheConfig != hipFuncCachePreferEqual))); - // This code exists to test the dummy implementation of - // hipDeviceSetCacheConfig. -#if HT_NVIDIA - HIP_CHECK(hipDeviceSetCacheConfig(cacheConfig)); -#else - REQUIRE_FALSE(hipSuccess == hipDeviceSetCacheConfig(cacheConfig)); +#include + +#include +#include + +namespace { +constexpr std::array kCacheConfigs{ + hipFuncCachePreferNone, hipFuncCachePreferShared, hipFuncCachePreferL1, + hipFuncCachePreferEqual}; +} // anonymous namespace + + +TEST_CASE("Unit_hipDeviceSetCacheConfig_Positive_Basic") { + const auto device = GENERATE(range(0, HipTest::getDeviceCount())); + HIP_CHECK(hipSetDevice(device)); + INFO("Current device is: " << device); + + const auto cache_config = + GENERATE(from_range(std::begin(kCacheConfigs), std::end(kCacheConfigs))); +#if HT_AMD + HIP_CHECK_ERROR(hipDeviceSetCacheConfig(cache_config), hipErrorNotSupported); +#elif HT_NVIDIA + HIP_CHECK(hipDeviceSetCacheConfig(cache_config)); #endif } + +TEST_CASE("Unit_hipDeviceSetCacheConfig_Negative_Parameters") { +#if HT_AMD + HIP_CHECK_ERROR(hipDeviceSetCacheConfig(static_cast(-1)), hipErrorNotSupported); +#elif HT_NVIDIA + HIP_CHECK_ERROR(hipDeviceSetCacheConfig(static_cast(-1)), hipErrorInvalidValue); +#endif +} + +TEST_CASE("Unit_hipDeviceGetCacheConfig_Positive_Default") { + const auto device = GENERATE(range(0, HipTest::getDeviceCount())); + HIP_CHECK(hipSetDevice(device)); + INFO("Current device is: " << device); + + hipFuncCache_t cache_config; + HIP_CHECK(hipDeviceGetCacheConfig(&cache_config)); + REQUIRE(cache_config == hipFuncCachePreferNone); +} + +TEST_CASE("Unit_hipDeviceGetCacheConfig_Positive_Basic") { + const auto device = GENERATE(range(0, HipTest::getDeviceCount())); + HIP_CHECK(hipSetDevice(device)); + INFO("Current device is: " << device); + + const auto cache_config = + GENERATE(from_range(std::begin(kCacheConfigs), std::end(kCacheConfigs))); + + HIP_CHECK(hipDeviceSetCacheConfig(cache_config)); + hipFuncCache_t returned_cache_config; + HIP_CHECK(hipDeviceGetCacheConfig(&returned_cache_config)); + + REQUIRE(returned_cache_config == cache_config); +} + +TEST_CASE("Unit_hipDeviceGetCacheConfig_Positive_Threaded") { + class HipDeviceSetGetCacheConfigTest : public ThreadedZigZagTest { + public: + HipDeviceSetGetCacheConfigTest(const hipFuncCache_t cache_config) + : cache_config_{cache_config} {} + + void TestPart2() { HIP_CHECK_THREAD(hipDeviceSetCacheConfig(cache_config_)); } + + void TestPart3() { + hipFuncCache_t returned_cache_config; + HIP_CHECK(hipDeviceGetCacheConfig(&returned_cache_config)); + REQUIRE(returned_cache_config == cache_config_); + } + + private: + const hipFuncCache_t cache_config_; + }; + + const auto cache_config = + GENERATE(from_range(std::begin(kCacheConfigs), std::end(kCacheConfigs))); + + HipDeviceSetGetCacheConfigTest test(cache_config); + test.run(); +} + +TEST_CASE("Unit_HipDeviceGetCacheConfig_Negative_Parameters") { + HIP_CHECK_ERROR(hipDeviceGetCacheConfig(nullptr), hipErrorInvalidValue); +} \ No newline at end of file