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 2a857c27d0..dd0f6fd6c4 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 @@ -3,6 +3,8 @@ [ "Unit_hipStreamPerThread_DeviceReset_1", "Unit_hipMallocManaged_OverSubscription", + "Unit_hipDeviceGetSharedMemConfig_Positive_Basic", + "Unit_hipDeviceGetSharedMemConfig_Positive_Threaded", "Unit_hipDeviceGetCacheConfig_Positive_Basic", "Unit_hipDeviceGetCacheConfig_Positive_Threaded", "Unit_hipGetDeviceFlags_Positive_Context", 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 3c8570f63d..9662edd8ed 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 @@ -100,6 +100,8 @@ "Unit_hipStreamValue_Wait64_Blocking_NoMask_Nor", "Unit_hipGetDeviceFlags_Positive_Context", "Unit_hipIpcCloseMemHandle_Negative_Close_In_Originating_Process", - "Unit_hipDeviceGetPCIBusId_Negative_PartialFill" + "Unit_hipDeviceGetPCIBusId_Negative_PartialFill", + "Unit_hipDeviceGetSharedMemConfig_Positive_Basic", + "Unit_hipDeviceGetSharedMemConfig_Positive_Threaded" ] } diff --git a/projects/hip/tests/catch/unit/device/CMakeLists.txt b/projects/hip/tests/catch/unit/device/CMakeLists.txt index 1ac6b88fbb..f027abbfa7 100644 --- a/projects/hip/tests/catch/unit/device/CMakeLists.txt +++ b/projects/hip/tests/catch/unit/device/CMakeLists.txt @@ -22,6 +22,7 @@ set(TEST_SRC hipDeviceEnableDisablePeerAccess.cc hipExtGetLinkTypeAndHopCount.cc hipDeviceSetLimit.cc + hipDeviceSetGetSharedMemConfig.cc hipDeviceSetGetMemPool.cc ) diff --git a/projects/hip/tests/catch/unit/device/hipDeviceSetGetSharedMemConfig.cc b/projects/hip/tests/catch/unit/device/hipDeviceSetGetSharedMemConfig.cc new file mode 100644 index 0000000000..045f40092a --- /dev/null +++ b/projects/hip/tests/catch/unit/device/hipDeviceSetGetSharedMemConfig.cc @@ -0,0 +1,121 @@ +/* +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 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 + +#include +#include + +namespace { +constexpr std::array kMemConfigs{ + hipSharedMemBankSizeDefault, hipSharedMemBankSizeFourByte, hipSharedMemBankSizeEightByte}; +} // anonymous namespace + +TEST_CASE("Unit_hipDeviceSetSharedMemConfig_Positive_Basic") { + const auto device = GENERATE(range(0, HipTest::getDeviceCount())); + const auto mem_config = GENERATE(from_range(std::begin(kMemConfigs), std::end(kMemConfigs))); + HIP_CHECK(hipSetDevice(device)); + INFO("Current device is " << device); + +#if HT_AMD + HIP_CHECK_ERROR(hipDeviceSetSharedMemConfig(mem_config), hipErrorNotSupported); +#elif HT_NVIDIA + HIP_CHECK(hipDeviceSetSharedMemConfig(mem_config)); +#endif +} + +TEST_CASE("Unit_hipDeviceSetSharedMemConfig_Negative_Parameters") { +#if HT_AMD + HIP_CHECK_ERROR(hipDeviceSetSharedMemConfig(static_cast(-1)), + hipErrorNotSupported); +#elif HT_NVIDIA + HIP_CHECK_ERROR(hipDeviceSetSharedMemConfig(static_cast(-1)), + hipErrorInvalidValue); +#endif +} + +TEST_CASE("Unit_hipDeviceGetSharedMemConfig_Positive_Default") { + const auto device = GENERATE(range(0, HipTest::getDeviceCount())); + HIP_CHECK(hipSetDevice(device)); + INFO("Current device is " << device); + + hipSharedMemConfig mem_config; + HIP_CHECK(hipDeviceGetSharedMemConfig(&mem_config)); + REQUIRE(mem_config == hipSharedMemBankSizeFourByte); +} + +TEST_CASE("Unit_hipDeviceGetSharedMemConfig_Positive_Basic") { + const auto device = GENERATE(range(0, HipTest::getDeviceCount())); + const auto mem_config = GENERATE(from_range(std::begin(kMemConfigs), std::end(kMemConfigs))); + HIP_CHECK(hipSetDevice(device)); + INFO("Current device is " << device); + + HIP_CHECK(hipDeviceSetSharedMemConfig(mem_config)); + + hipSharedMemConfig returned_mem_config; + HIP_CHECK(hipDeviceGetSharedMemConfig(&returned_mem_config)); + + int major = -1, minor = -1; + HIP_CHECK(hipDeviceComputeCapability(&major, &minor, device)); + REQUIRE(major > 0); + if (major == 3 /*Kepler*/) { + REQUIRE(returned_mem_config == mem_config); + } else { + REQUIRE(returned_mem_config == hipSharedMemBankSizeFourByte); + } +} + +TEST_CASE("Unit_hipDeviceGetSharedMemConfig_Positive_Threaded") { + class HipDeviceGetSharedMemConfigTest + : public ThreadedZigZagTest { + public: + HipDeviceGetSharedMemConfigTest(const hipSharedMemConfig mem_config) + : mem_config_{mem_config} {} + + void TestPart2() { HIP_CHECK_THREAD(hipDeviceSetSharedMemConfig(mem_config_)); } + + void TestPart3() { + hipSharedMemConfig returned_mem_config; + HIP_CHECK(hipDeviceGetSharedMemConfig(&returned_mem_config)); + + int major = -1, minor = -1; + HIP_CHECK(hipDeviceComputeCapability(&major, &minor, 0)); + REQUIRE(major > 0); + if (major == 3 /*Kepler*/) { + REQUIRE(returned_mem_config == mem_config_); + } else { + REQUIRE(returned_mem_config == hipSharedMemBankSizeFourByte); + } + } + + private: + const hipSharedMemConfig mem_config_; + }; + + const auto mem_config = GENERATE(from_range(std::begin(kMemConfigs), std::end(kMemConfigs))); + + HipDeviceGetSharedMemConfigTest test(mem_config); + test.run(); +} + +TEST_CASE("Unit_hipDeviceGetSharedMemConfig_Negative_Parameters") { + HIP_CHECK_ERROR(hipDeviceGetSharedMemConfig(nullptr), hipErrorInvalidValue); +} \ No newline at end of file