1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319
|
/*! \file */
/* ************************************************************************
* Copyright (C) 2019-2024 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 "rocsparse_parse_data.hpp"
#include "rocsparse_reproducibility.hpp"
#include "utility.hpp"
#include <gtest/gtest.h>
#include "test_check.hpp"
bool test_check::s_auto_testing_bad_arg;
bool display_timing_info_is_stdout_disabled()
{
return false;
}
rocsparse_status rocsparse_record_output(const std::string& s)
{
return rocsparse_status_success;
}
rocsparse_status rocsparse_record_output_legend(const std::string& s)
{
return rocsparse_status_success;
}
rocsparse_status rocsparse_record_timing(double msec, double gflops, double gbs)
{
return rocsparse_status_success;
}
class ConfigurableEventListener : public testing::TestEventListener
{
testing::TestEventListener* eventListener;
public:
bool showTestCases; // Show the names of each test case.
bool showTestNames; // Show the names of each test.
bool showSuccesses; // Show each success.
bool showInlineFailures; // Show each failure as it occurs.
bool showEnvironment; // Show the setup of the global environment.
explicit ConfigurableEventListener(testing::TestEventListener* theEventListener)
: eventListener(theEventListener)
, showTestCases(true)
, showTestNames(true)
, showSuccesses(true)
, showInlineFailures(true)
, showEnvironment(true)
{
}
~ConfigurableEventListener() override
{
delete eventListener;
}
void OnTestProgramStart(const testing::UnitTest& unit_test) override
{
eventListener->OnTestProgramStart(unit_test);
}
void OnTestIterationStart(const testing::UnitTest& unit_test, int iteration) override
{
eventListener->OnTestIterationStart(unit_test, iteration);
}
void OnEnvironmentsSetUpStart(const testing::UnitTest& unit_test) override
{
if(showEnvironment)
{
eventListener->OnEnvironmentsSetUpStart(unit_test);
}
}
void OnEnvironmentsSetUpEnd(const testing::UnitTest& unit_test) override
{
if(showEnvironment)
{
eventListener->OnEnvironmentsSetUpEnd(unit_test);
}
}
void OnTestCaseStart(const testing::TestCase& test_case) override
{
if(showTestCases)
{
eventListener->OnTestCaseStart(test_case);
}
}
void OnTestStart(const testing::TestInfo& test_info) override
{
if(showTestNames)
{
eventListener->OnTestStart(test_info);
}
}
void OnTestPartResult(const testing::TestPartResult& result) override
{
eventListener->OnTestPartResult(result);
}
void OnTestEnd(const testing::TestInfo& test_info) override
{
if(test_info.result()->Failed() ? showInlineFailures : showSuccesses)
{
eventListener->OnTestEnd(test_info);
}
}
void OnTestCaseEnd(const testing::TestCase& test_case) override
{
if(showTestCases)
{
eventListener->OnTestCaseEnd(test_case);
}
}
void OnEnvironmentsTearDownStart(const testing::UnitTest& unit_test) override
{
if(showEnvironment)
{
eventListener->OnEnvironmentsTearDownStart(unit_test);
}
}
void OnEnvironmentsTearDownEnd(const testing::UnitTest& unit_test) override
{
if(showEnvironment)
{
eventListener->OnEnvironmentsTearDownEnd(unit_test);
}
}
void OnTestIterationEnd(const testing::UnitTest& unit_test, int iteration) override
{
eventListener->OnTestIterationEnd(unit_test, iteration);
}
void OnTestProgramEnd(const testing::UnitTest& unit_test) override
{
eventListener->OnTestProgramEnd(unit_test);
}
};
/* =====================================================================
Main function:
=================================================================== */
int main(int argc, char** argv)
{
// Get version
rocsparse_handle handle;
rocsparse_create_handle(&handle);
int ver;
char rev[64];
rocsparse_get_version(handle, &ver);
rocsparse_get_git_rev(handle, rev);
rocsparse_destroy_handle(handle);
// Get user device id from command line
int dev = 0;
for(int i = 1; i < argc; ++i)
{
if(strcmp(argv[i], "--device") == 0 && argc > i + 1)
{
dev = atoi(argv[i + 1]);
}
else if(strcmp(argv[i], "--version") == 0)
{
// Print version and exit, if requested
std::cout << "rocSPARSE version: " << ver / 100000 << "." << ver / 100 % 1000 << "."
<< ver % 100 << "-" << rev << std::endl;
return 0;
}
}
// Device query
int devs;
if(hipGetDeviceCount(&devs) != hipSuccess)
{
std::cerr << "Error: cannot get device count" << std::endl;
return -1;
}
std::cout << "Query device success: there are " << devs << " devices" << std::endl;
for(int i = 0; i < devs; ++i)
{
hipDeviceProp_t prop;
if(hipGetDeviceProperties(&prop, i) != hipSuccess)
{
std::cerr << "Error: cannot get device properties" << std::endl;
return -1;
}
std::cout << "Device ID " << i << ": " << prop.name << std::endl;
std::cout << "-------------------------------------------------------------------------"
<< std::endl;
std::cout << "with " << (prop.totalGlobalMem >> 20) << "MB memory, clock rate "
<< prop.clockRate / 1000 << "MHz @ computing capability " << prop.major << "."
<< prop.minor << std::endl;
std::cout << "maxGridDimX " << prop.maxGridSize[0] << ", sharedMemPerBlock "
<< (prop.sharedMemPerBlock >> 10) << "KB, maxThreadsPerBlock "
<< prop.maxThreadsPerBlock << std::endl;
std::cout << "wavefrontSize " << prop.warpSize << std::endl;
std::cout << "-------------------------------------------------------------------------"
<< std::endl;
}
// Set device
if(hipSetDevice(dev) != hipSuccess || dev >= devs)
{
std::cerr << "Error: cannot set device ID " << dev << std::endl;
return -1;
}
hipDeviceProp_t prop;
hipGetDeviceProperties(&prop, dev);
std::cout << "Using device ID " << dev << " (" << prop.name << ") for rocSPARSE" << std::endl;
std::cout << "-------------------------------------------------------------------------"
<< std::endl;
// Print version
std::cout << "rocSPARSE version: " << ver / 100000 << "." << ver / 100 % 1000 << "."
<< ver % 100 << "-" << rev << std::endl;
std::string datapath = rocsparse_datapath();
// Print test data path being used
std::cout << "rocSPARSE data path: " << datapath << std::endl;
// Set data file path
rocsparse_parse_data(argc, argv, datapath + "rocsparse_test.data");
// Initialize google test
testing::InitGoogleTest(&argc, argv);
// Free up all temporary data generated during test creation
test_cleanup::cleanup();
// Remove the default listener
auto& listeners = testing::UnitTest::GetInstance()->listeners();
auto default_printer = listeners.Release(listeners.default_result_printer());
// Add our listener, by default everything is on (the same as using the default listener)
// Here turning everything off so only the 3 lines for the result are visible
// (plus any failures at the end), like:
// [==========] Running 149 tests from 53 test cases.
// [==========] 149 tests from 53 test cases ran. (1 ms total)
// [ PASSED ] 149 tests.
//
auto listener = new ConfigurableEventListener(default_printer);
auto gtest_listener = getenv("GTEST_LISTENER");
if(gtest_listener && !strcmp(gtest_listener, "NO_PASS_LINE_IN_LOG"))
{
listener->showTestNames = listener->showSuccesses = listener->showInlineFailures = false;
}
listeners.Append(listener);
// Run all tests
int ret = RUN_ALL_TESTS();
auto& reproducibility = rocsparse_reproducibility_t::instance();
if(reproducibility.config().is_enabled())
{
static hipDeviceProp_t prop;
static int dev;
if(hipGetDevice(&dev) != hipSuccess)
{
return -1;
}
if(hipGetDeviceProperties(&prop, dev) != hipSuccess)
{
return -1;
}
reproducibility.config().set_gpu_name(prop.gcnArchName);
rocsparse_reproducibility_write_report(reproducibility);
}
// Reset HIP device
hipDeviceReset();
return ret;
}
|