mirror of
https://github.com/saymrwulf/pytorch.git
synced 2026-05-15 21:00:47 +00:00
Summary: This PR is a large codemod to rewrite all C++ API tests with GoogleTest (gtest) instead of Catch. You can largely trust me to have correctly code-modded the tests, so it's not required to review every of the 2000+ changed lines. However, additional things I changed were: 1. Moved the cmake parts for these tests into their own `CMakeLists.txt` under `test/cpp/api` and calling `add_subdirectory` from `torch/CMakeLists.txt` 2. Fixing DataParallel tests which weren't being compiled because `USE_CUDA` wasn't correctly being set at all. 3. Updated README ezyang ebetica Pull Request resolved: https://github.com/pytorch/pytorch/pull/11953 Differential Revision: D9998883 Pulled By: goldsborough fbshipit-source-id: affe3f320b0ca63e7e0019926a59076bb943db80
32 lines
904 B
C++
32 lines
904 B
C++
#include <gtest/gtest.h>
|
|
|
|
#include <torch/cuda.h>
|
|
|
|
#include <iostream>
|
|
#include <string>
|
|
|
|
std::string add_negative_flag(const std::string& flag) {
|
|
std::string filter = ::testing::GTEST_FLAG(filter);
|
|
if (filter.find('-') == std::string::npos) {
|
|
filter.push_back('-');
|
|
} else {
|
|
filter.push_back(':');
|
|
}
|
|
filter += flag;
|
|
return filter;
|
|
}
|
|
|
|
int main(int argc, char* argv[]) {
|
|
::testing::InitGoogleTest(&argc, argv);
|
|
if (!torch::cuda::is_available()) {
|
|
std::cout << "CUDA not available. Disabling CUDA and MultiCUDA tests"
|
|
<< std::endl;
|
|
::testing::GTEST_FLAG(filter) = add_negative_flag("*_CUDA:*_MultiCUDA");
|
|
} else if (torch::cuda::device_count() < 2) {
|
|
std::cout << "Only one CUDA device detected. Disabling MultiCUDA tests"
|
|
<< std::endl;
|
|
::testing::GTEST_FLAG(filter) = add_negative_flag("*_MultiCUDA");
|
|
}
|
|
|
|
return RUN_ALL_TESTS();
|
|
}
|