1+ /*
2+ Copyright (c) 2022 Advanced Micro Devices, Inc. All rights reserved.
3+ Permission is hereby granted, free of charge, to any person obtaining a copy
4+ of this software and associated documentation files (the "Software"), to deal
5+ in the Software without restriction, including without limitation the rights
6+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+ copies of the Software, and to permit persons to whom the Software is
8+ furnished to do so, subject to the following conditions:
9+
10+ The above copyright notice and this permission notice shall be included in
11+ all copies or substantial portions of the Software.
12+
13+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19+ THE SOFTWARE.
20+ */
21+
22+ #include < array>
23+
24+ #include < hip_test_common.hh>
25+ #include < threaded_zig_zag_test.hh>
26+
27+ namespace {
28+ constexpr std::array<hipSharedMemConfig, 3 > kMemConfigs {
29+ hipSharedMemBankSizeDefault, hipSharedMemBankSizeFourByte, hipSharedMemBankSizeEightByte};
30+ } // anonymous namespace
31+
32+ TEST_CASE (" Unit_hipDeviceSetSharedMemConfig_Positive_Basic" ) {
33+ const auto device = GENERATE (range (0 , HipTest::getDeviceCount ()));
34+ const auto mem_config = GENERATE (from_range (std::begin (kMemConfigs ), std::end (kMemConfigs )));
35+ HIP_CHECK (hipSetDevice (device));
36+ INFO (" Current device is " << device);
37+
38+ #if HT_AMD
39+ HIP_CHECK_ERROR (hipDeviceSetSharedMemConfig (mem_config), hipErrorNotSupported);
40+ #elif HT_NVIDIA
41+ HIP_CHECK (hipDeviceSetSharedMemConfig (mem_config));
42+ #endif
43+ }
44+
45+ TEST_CASE (" Unit_hipDeviceSetSharedMemConfig_Negative_Parameters" ) {
46+ #if HT_AMD
47+ HIP_CHECK_ERROR (hipDeviceSetSharedMemConfig (static_cast <hipSharedMemConfig>(-1 )),
48+ hipErrorNotSupported);
49+ #elif HT_NVIDIA
50+ HIP_CHECK_ERROR (hipDeviceSetSharedMemConfig (static_cast <hipSharedMemConfig>(-1 )),
51+ hipErrorInvalidValue);
52+ #endif
53+ }
54+
55+ TEST_CASE (" Unit_hipDeviceGetSharedMemConfig_Positive_Default" ) {
56+ const auto device = GENERATE (range (0 , HipTest::getDeviceCount ()));
57+ HIP_CHECK (hipSetDevice (device));
58+ INFO (" Current device is " << device);
59+
60+ hipSharedMemConfig mem_config;
61+ HIP_CHECK (hipDeviceGetSharedMemConfig (&mem_config));
62+ REQUIRE (mem_config == hipSharedMemBankSizeFourByte);
63+ }
64+
65+ TEST_CASE (" Unit_hipDeviceGetSharedMemConfig_Positive_Basic" ) {
66+ const auto device = GENERATE (range (0 , HipTest::getDeviceCount ()));
67+ const auto mem_config = GENERATE (from_range (std::begin (kMemConfigs ), std::end (kMemConfigs )));
68+ HIP_CHECK (hipSetDevice (device));
69+ INFO (" Current device is " << device);
70+
71+ HIP_CHECK (hipDeviceSetSharedMemConfig (mem_config));
72+
73+ hipSharedMemConfig returned_mem_config;
74+ HIP_CHECK (hipDeviceGetSharedMemConfig (&returned_mem_config));
75+
76+ int major = -1 , minor = -1 ;
77+ HIP_CHECK (hipDeviceComputeCapability (&major, &minor, device));
78+ REQUIRE (major > 0 );
79+ if (major == 3 /* Kepler*/ ) {
80+ REQUIRE (returned_mem_config == mem_config);
81+ } else {
82+ REQUIRE (returned_mem_config == hipSharedMemBankSizeFourByte);
83+ }
84+ }
85+
86+ TEST_CASE (" Unit_hipDeviceGetSharedMemConfig_Positive_Threaded" ) {
87+ class HipDeviceGetSharedMemConfigTest
88+ : public ThreadedZigZagTest<HipDeviceGetSharedMemConfigTest> {
89+ public:
90+ HipDeviceGetSharedMemConfigTest (const hipSharedMemConfig mem_config)
91+ : mem_config_{mem_config} {}
92+
93+ void TestPart2 () { HIP_CHECK_THREAD (hipDeviceSetSharedMemConfig (mem_config_)); }
94+
95+ void TestPart3 () {
96+ hipSharedMemConfig returned_mem_config;
97+ HIP_CHECK (hipDeviceGetSharedMemConfig (&returned_mem_config));
98+
99+ int major = -1 , minor = -1 ;
100+ HIP_CHECK (hipDeviceComputeCapability (&major, &minor, 0 ));
101+ REQUIRE (major > 0 );
102+ if (major == 3 /* Kepler*/ ) {
103+ REQUIRE (returned_mem_config == mem_config_);
104+ } else {
105+ REQUIRE (returned_mem_config == hipSharedMemBankSizeFourByte);
106+ }
107+ }
108+
109+ private:
110+ const hipSharedMemConfig mem_config_;
111+ };
112+
113+ const auto mem_config = GENERATE (from_range (std::begin (kMemConfigs ), std::end (kMemConfigs )));
114+
115+ HipDeviceGetSharedMemConfigTest test (mem_config);
116+ test.run ();
117+ }
118+
119+ TEST_CASE (" Unit_hipDeviceGetSharedMemConfig_Negative_Parameters" ) {
120+ HIP_CHECK_ERROR (hipDeviceGetSharedMemConfig (nullptr ), hipErrorInvalidValue);
121+ }
0 commit comments