Skip to content

Commit

Permalink
[gtest2/june24] in gg_tt.mad, temporarely revert the simplication of …
Browse files Browse the repository at this point in the history
…tests and add back the duplication of tests - the segfault madgraph5#907 disappears if gpuDeviceReset is removed!

git revert b6dcf4e
git cherry-pick 0cce7fb

INFO: The following Floating Point Exceptions will cause SIGFPE program aborts: FE_DIVBYZERO, FE_INVALID, FE_OVERFLOW
[==========] Running 4 tests from 4 test suites.
[----------] Global test environment set-up.
[----------] 1 test from SIGMA_SM_GG_TTX_GPU_XXX
[ RUN      ] SIGMA_SM_GG_TTX_GPU_XXX.testxxx
[       OK ] SIGMA_SM_GG_TTX_GPU_XXX.testxxx (1 ms)
[----------] 1 test from SIGMA_SM_GG_TTX_GPU_XXX (1 ms total)

[----------] 1 test from SIGMA_SM_GG_TTX_GPU_MISC
[ RUN      ] SIGMA_SM_GG_TTX_GPU_MISC.testmisc
[       OK ] SIGMA_SM_GG_TTX_GPU_MISC.testmisc (14 ms)
[----------] 1 test from SIGMA_SM_GG_TTX_GPU_MISC (14 ms total)

[----------] 1 test from SIGMA_SM_GG_TTX_GPU1/MadgraphTest
[ RUN      ] SIGMA_SM_GG_TTX_GPU1/MadgraphTest.CompareMomentaAndME/0
INFO: Opening reference file ../../test/ref/dump_CPUTest.Sigma_sm_gg_ttx.txt
INFO: No Floating Point Exceptions have been reported
[       OK ] SIGMA_SM_GG_TTX_GPU1/MadgraphTest.CompareMomentaAndME/0 (200 ms)
[----------] 1 test from SIGMA_SM_GG_TTX_GPU1/MadgraphTest (200 ms total)

[----------] 1 test from SIGMA_SM_GG_TTX_GPU2/MadgraphTest
[ RUN      ] SIGMA_SM_GG_TTX_GPU2/MadgraphTest.CompareMomentaAndME/0
INFO: Opening reference file ../../test/ref/dump_CPUTest.Sigma_sm_gg_ttx.txt
INFO: No Floating Point Exceptions have been reported
[       OK ] SIGMA_SM_GG_TTX_GPU2/MadgraphTest.CompareMomentaAndME/0 (181 ms)
[----------] 1 test from SIGMA_SM_GG_TTX_GPU2/MadgraphTest (181 ms total)

[----------] Global test environment tear-down
[==========] 4 tests from 4 test suites ran. (398 ms total)
[  PASSED  ] 4 tests.
  • Loading branch information
valassi committed Jul 12, 2024
1 parent 503a69d commit d154507
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 43 deletions.
65 changes: 54 additions & 11 deletions epochX/cudacpp/gg_tt.mad/SubProcesses/MadgraphTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,29 @@ namespace
* Users need to implement:
* - Functions to retrieve matrix element and 4-momenta. These are used in the tests.
* - Driver functions that run the madgraph workflow.
*
* Usage:
* ```
* class TestImplementation : public TestDriverBase {
* <override all pure-virtual functions with Madgraph workflow>
* }
*
* class TestImplementation2 : public TestDriverBase {
* <override all pure-virtual functions with a different Madgraph workflow>
* }
*
* INSTANTIATE_TEST_SUITE_P( TestName,
* MadgraphTest,
* testing::Values( new TestImplementation, new TestImplementation2, ... ) );
*```
*
* For adapting the test workflow, see the .cc and adapt
* TEST_P(MadgraphTest, CompareMomentaAndME)
*
* To add a test that should be runnable with all test implementations that derive from TestDriverBase, add a new
* TEST_P(MadgraphTest, <TestName>) {
* <test code>
* }
*/
class TestDriverBase
{
Expand Down Expand Up @@ -161,18 +184,34 @@ class TestDriverBase

/**
* Test class that's defining all tests to run with a Madgraph workflow.
* The tests are defined below using TEST_P.
* Instantiate them using:
* ```
* INSTANTIATE_TEST_SUITE_P( TestName,
* MadgraphTest,
* testing::Values( new TestImplementation, new TestImplementation2, ... ) );
* ```
*/
class MadgraphTest
class MadgraphTest : public testing::TestWithParam<TestDriverBase*>
{
public:
MadgraphTest( TestDriverBase& testDriverRef ) : testDriver( &testDriverRef ) {}
~MadgraphTest() {}
void CompareMomentaAndME() const;
private:
TestDriverBase* testDriver; // non-owning pointer
protected:
std::unique_ptr<TestDriverBase> testDriver;

MadgraphTest()
: TestWithParam(), testDriver( GetParam() )
{
}
};

void MadgraphTest::CompareMomentaAndME() const
// WARNING: before the split of C++ and CUDA builds, both CPU and GPU tests were linked together into the same executable;
// it was therefore necessary to prevent multiply-defined symbols by only compiling this when "#ifndef MGONGPUCPP_GPUIMPL";
// now that runTest.exe only contains either CPU or GPU tests, this is no longer necessary!
//#ifndef MGONGPUCPP_GPUIMPL

/// Compare momenta and matrix elements.
/// This uses an implementation of TestDriverBase to run a madgraph workflow,
/// and compares momenta and matrix elements with a reference file.
TEST_P( MadgraphTest, CompareMomentaAndME )
{
const fptype toleranceMomenta = std::is_same<double, fptype>::value ? 1.E-10 : 4.E-2; // see #735
#ifdef __APPLE__
Expand Down Expand Up @@ -205,7 +244,7 @@ void MadgraphTest::CompareMomentaAndME() const
{
referenceData = readReferenceData( refFileName );
}
//ASSERT_FALSE( HasFailure() ); // It doesn't make any sense to continue if we couldn't read the reference file.
ASSERT_FALSE( HasFailure() ); // It doesn't make any sense to continue if we couldn't read the reference file.
// **************************************
// *** START MAIN LOOP ON #ITERATIONS ***
// **************************************
Expand All @@ -215,8 +254,7 @@ void MadgraphTest::CompareMomentaAndME() const
testDriver->prepareMomenta( energy );
testDriver->runSigmaKin( iiter );
// --- Run checks on all events produced in this iteration
//for( std::size_t ievt = 0; ievt < testDriver->nevt && !HasFailure(); ++ievt )
for( std::size_t ievt = 0; ievt < testDriver->nevt; ++ievt )
for( std::size_t ievt = 0; ievt < testDriver->nevt && !HasFailure(); ++ievt )
{
if( dumpEvents )
{
Expand Down Expand Up @@ -283,4 +321,9 @@ void MadgraphTest::CompareMomentaAndME() const
}
}

// WARNING: before the split of C++ and CUDA builds, both CPU and GPU tests were linked together into the same executable;
// it was therefore necessary to prevent multiply-defined symbols by only compiling this when "#ifndef MGONGPUCPP_GPUIMPL";
// now that runTest.exe only contains either CPU or GPU tests, this is no longer necessary!
//#endif // MGONGPUCPP_GPUIMPL

#endif /* MADGRAPHTEST_H_ */
65 changes: 33 additions & 32 deletions epochX/cudacpp/gg_tt.mad/SubProcesses/runTest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -242,37 +242,38 @@ struct CUDATest : public CUDA_CPU_TestBase
};
#endif /* clang-format off */

// AV July 2024 much simpler class structure without the presently-unnecessary googletest templates
// This is meant as a workaround to prevent not-understood segfault #907 when adding a second test
// Use two levels of macros to force stringification at the right level
// (see https://gcc.gnu.org/onlinedocs/gcc-3.0.1/cpp_3.html#SEC17 and https://stackoverflow.com/a/3419392)
// Google macro is in https://github.com/google/googletest/blob/master/googletest/include/gtest/gtest-param-test.h
#define TESTID_CPU1( s ) s##_CPU1
#define XTESTID_CPU1( s ) TESTID_CPU1( s )
#define MG_INSTANTIATE_TEST_SUITE_CPU1( prefix, test_suite_name ) \
INSTANTIATE_TEST_SUITE_P( prefix, \
test_suite_name, \
testing::Values( new CPUTest( MG_EPOCH_REFERENCE_FILE_NAME ) ) );
#define TESTID_CPU2( s ) s##_CPU2
#define XTESTID_CPU2( s ) TESTID_CPU2( s )
#define MG_INSTANTIATE_TEST_SUITE_CPU2( prefix, test_suite_name ) \
INSTANTIATE_TEST_SUITE_P( prefix, \
test_suite_name, \
testing::Values( new CPUTest( MG_EPOCH_REFERENCE_FILE_NAME ) ) );
#define TESTID_GPU1( s ) s##_GPU1
#define XTESTID_GPU1( s ) TESTID_GPU1( s )
#define MG_INSTANTIATE_TEST_SUITE_GPU1( prefix, test_suite_name ) \
INSTANTIATE_TEST_SUITE_P( prefix, \
test_suite_name, \
testing::Values( new CUDATest( MG_EPOCH_REFERENCE_FILE_NAME ) ) );
#define TESTID_GPU2( s ) s##_GPU2
#define XTESTID_GPU2( s ) TESTID_GPU2( s )
#define MG_INSTANTIATE_TEST_SUITE_GPU2( prefix, test_suite_name ) \
INSTANTIATE_TEST_SUITE_P( prefix, \
test_suite_name, \
testing::Values( new CUDATest( MG_EPOCH_REFERENCE_FILE_NAME ) ) );

#ifdef MGONGPUCPP_GPUIMPL
// CUDA tests
CUDATest cudaDriver1( MG_EPOCH_REFERENCE_FILE_NAME );
CUDATest cudaDriver2( MG_EPOCH_REFERENCE_FILE_NAME );
MadgraphTest mgTest1( cudaDriver1 );
MadgraphTest mgTest2( cudaDriver2 );
#define TESTID1( s ) s##_GPU_MADGRAPH1
#define XTESTID1( s ) TESTID1( s )
#define TESTID2( s ) s##_GPU_MADGRAPH2
#define XTESTID2( s ) TESTID2( s )
MG_INSTANTIATE_TEST_SUITE_GPU1( XTESTID_GPU1( MG_EPOCH_PROCESS_ID ), MadgraphTest );
MG_INSTANTIATE_TEST_SUITE_GPU2( XTESTID_GPU2( MG_EPOCH_PROCESS_ID ), MadgraphTest );
#else
// CPU tests
CPUTest cppDriver1( MG_EPOCH_REFERENCE_FILE_NAME );
CPUTest cppDriver2( MG_EPOCH_REFERENCE_FILE_NAME );
MadgraphTest mgTest1( cppDriver1 );
MadgraphTest mgTest2( cppDriver2 );
#define TESTID1( s ) s##_CPU_MADGRAPH1
#define XTESTID1( s ) TESTID1( s )
#define TESTID2( s ) s##_CPU_MADGRAPH2
#define XTESTID2( s ) TESTID2( s )
#endif

// Instantiate Google tests
TEST( XTESTID1( MG_EPOCH_PROCESS_ID ), compareMomAndME )
{
mgTest1.CompareMomentaAndME();
}
TEST( XTESTID2( MG_EPOCH_PROCESS_ID ), compareMomAndME )
{
mgTest2.CompareMomentaAndME();
}
/* clang-format on */
MG_INSTANTIATE_TEST_SUITE_CPU1( XTESTID_CPU1( MG_EPOCH_PROCESS_ID ), MadgraphTest );
MG_INSTANTIATE_TEST_SUITE_CPU2( XTESTID_CPU2( MG_EPOCH_PROCESS_ID ), MadgraphTest );
#endif /* clang-format on */

0 comments on commit d154507

Please sign in to comment.