Skip to content

Commit 2332df3

Browse files
committed
finished unit test cuda enablement
1 parent 214b5d4 commit 2332df3

File tree

13 files changed

+287
-283
lines changed

13 files changed

+287
-283
lines changed

src/common/DirectSystemSolve.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313

1414
#include "macros.hpp"
1515
#include "symmetricMatrix.hpp"
16-
#include <cmath>
16+
17+
#include <math.h>
1718

1819
namespace hpcReact
1920
{

src/common/nonlinearSolvers.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
#include "macros.hpp"
1515
#include "DirectSystemSolve.hpp"
16-
#include <cmath>
16+
#include <math.h>
1717

1818
namespace hpcReact
1919
{

src/common/unitTests/testDirectSystemSolve.cpp

Lines changed: 0 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -16,43 +16,6 @@
1616
#include <gtest/gtest.h>
1717

1818
using namespace hpcReact;
19-
// TEST( testDirectSystemSolve, test3x3 )
20-
// {
21-
// // **Define a Sample NxN Linear System**
22-
// double A_host[9] =
23-
// {
24-
// 1.0, 2.0, 3.0,
25-
// 2.0, -1.0, 1.0,
26-
// 3.0, 4.0, 5.0
27-
// };
28-
// double b_host[3] = { 14.0, 3.0, 24.0 }; // Right-hand side
29-
// double x_host[3]; // Solution
30-
31-
// // **Allocate Memory on the GPU**
32-
// double *d_A, *d_b, *d_x;
33-
// cudaMalloc(&d_A, sizeof(A_host));
34-
// cudaMalloc(&d_b, sizeof(b_host));
35-
// cudaMalloc(&d_x, sizeof(x_host));
36-
37-
// // **Copy Data to the GPU**
38-
// cudaMemcpy(d_A, A_host, sizeof(A_host), cudaMemcpyHostToDevice);
39-
// cudaMemcpy(d_b, b_host, sizeof(b_host), cudaMemcpyHostToDevice);
40-
41-
// // **Launch Kernel (1 block, 1 thread per system)**
42-
// kernel_solveNxN_pivoted<double,3><<<1, 1>>>(d_A, d_b, d_x, 1);
43-
44-
// // **Copy Result Back to Host**
45-
// cudaMemcpy(x_host, d_x, sizeof(x_host), cudaMemcpyDeviceToHost);
46-
47-
// // **Print the Solution**
48-
// std::cout << "Solution: x = [" << x_host[0] << ", " << x_host[1] << ", " << x_host[2] << "]" << std::endl;
49-
50-
// // **Free GPU Memory**
51-
// cudaFree(d_A);
52-
// cudaFree(d_b);
53-
// cudaFree(d_x);
54-
55-
// }
5619

5720
template< typename REAL_TYPE, int N >
5821
struct LinearSystem
@@ -94,47 +57,6 @@ TEST( testDirectSystemSolve, test3x3 )
9457
}
9558

9659

97-
#if 0
98-
TEST( testDirectSystemSolve, test3x3_CUDA )
99-
{
100-
// **Define a Sample NxN Linear System**
101-
double A_host[9] =
102-
{
103-
1.0, 2.0, 3.0,
104-
2.0, -1.0, 1.0,
105-
3.0, 4.0, 5.0
106-
};
107-
double b_host[3] = { 14.0, 3.0, 24.0 }; // Right-hand side
108-
double x_host[3]; // Solution
109-
110-
// **Allocate Memory on the GPU**
111-
double *d_A, *d_b, *d_x;
112-
cudaMalloc( &d_A, sizeof(A_host));
113-
cudaMalloc( &d_b, sizeof(b_host));
114-
cudaMalloc( &d_x, sizeof(x_host));
115-
116-
// **Copy Data to the GPU**
117-
cudaMemcpy( d_A, A_host, sizeof(A_host), cudaMemcpyHostToDevice );
118-
cudaMemcpy( d_b, b_host, sizeof(b_host), cudaMemcpyHostToDevice );
119-
120-
// **Launch Kernel (1 block, 1 thread per system)**
121-
kernel_solveNxN_pivoted< double, 3 ><<<1, 1>>>(d_A, d_b, d_x, 1);
122-
123-
// **Copy Result Back to Host**
124-
cudaMemcpy( x_host, d_x, sizeof(x_host), cudaMemcpyDeviceToHost );
125-
126-
// **Print the Solution**
127-
std::cout << "Solution: x = [" << x_host[0] << ", " << x_host[1] << ", " << x_host[2] << "]" << std::endl;
128-
129-
// **Free GPU Memory**
130-
cudaFree( d_A );
131-
cudaFree( d_b );
132-
cudaFree( d_x );
133-
134-
}
135-
#endif
136-
137-
13860
int main( int argc, char * * argv )
13961
{
14062
::testing::InitGoogleTest( &argc, argv );

src/reactions/exampleSystems/unitTests/testEquilibriumReactions.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "reactions/unitTestUtilities/equilibriumReactionsTestUtilities.hpp"
1414
#include "../BulkGeneric.hpp"
1515

16+
1617
#include <gtest/gtest.h>
1718

1819
using namespace hpcReact;
@@ -30,6 +31,7 @@ TEST( testEquilibriumReactions, computeResidualAndJacobianTest )
3031
double const expectedJacobian[2][2] =
3132
{ { 1.0e16, -2.0 },
3233
{ -2.0, 4.0e16 } };
34+
3335
computeResidualAndJacobianTest< double, 2 >( bulkGeneric::simpleTestRateParams,
3436
initialSpeciesConcentration,
3537
expectedResiduals,

src/reactions/exampleSystems/unitTests/testMomasEasyCase.cpp

Lines changed: 42 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -19,48 +19,53 @@ using namespace hpcReact::unitTest_utilities;
1919

2020
//******************************************************************************
2121

22-
TEST( testEquilibriumReactions, testMoMasAllEquilibrium )
23-
{
2422

23+
24+
void testMoMasAllEquilibriumHelper()
25+
{
2526
using EquilibriumReactionsType = reactionsSystems::EquilibriumReactions< double,
2627
int,
2728
int >;
2829

2930
constexpr int numPrimarySpecies = hpcReact::MoMasBenchmark::easyCaseParams.numPrimarySpecies();
3031

31-
double const targetAggregatePrimarySpeciesConcentration[numPrimarySpecies] =
32-
{
33-
1.0e-20, // X1
34-
-2.0, // X2
35-
1.0e-20, // X3
36-
2.0, // X4
37-
1.0 // S
38-
};
39-
40-
double const initialPrimarySpeciesConcentration[numPrimarySpecies] =
41-
{
42-
1.0e-20, // X1
43-
0.02, // X2
44-
1.0e-20, // X3
45-
1.0, // X4
46-
1.00 // S
47-
};
32+
double logPrimarySpeciesConcentration[numPrimarySpecies];
4833

49-
double const logInitialPrimarySpeciesConcentration[numPrimarySpecies] =
34+
pmpl::genericKernelWrapper( numPrimarySpecies, logPrimarySpeciesConcentration, [] HPCREACT_DEVICE ( auto * const logPrimarySpeciesConcentrationCopy )
5035
{
51-
log( initialPrimarySpeciesConcentration[0] ),
52-
log( initialPrimarySpeciesConcentration[1] ),
53-
log( initialPrimarySpeciesConcentration[2] ),
54-
log( initialPrimarySpeciesConcentration[3] ),
55-
log( initialPrimarySpeciesConcentration[4] )
56-
};
57-
58-
double logPrimarySpeciesConcentration[numPrimarySpecies];
59-
EquilibriumReactionsType::enforceEquilibrium_Aggregate( 0,
60-
hpcReact::MoMasBenchmark::easyCaseParams.equilibriumReactionsParameters(),
61-
targetAggregatePrimarySpeciesConcentration,
62-
logInitialPrimarySpeciesConcentration,
63-
logPrimarySpeciesConcentration );
36+
double const targetAggregatePrimarySpeciesConcentration[numPrimarySpecies] =
37+
{
38+
1.0e-20, // X1
39+
-2.0, // X2
40+
1.0e-20, // X3
41+
2.0, // X4
42+
1.0 // S
43+
};
44+
45+
double const initialPrimarySpeciesConcentration[numPrimarySpecies] =
46+
{
47+
1.0e-20, // X1
48+
0.02, // X2
49+
1.0e-20, // X3
50+
1.0, // X4
51+
1.00 // S
52+
};
53+
54+
double const logInitialPrimarySpeciesConcentration[numPrimarySpecies] =
55+
{
56+
log( initialPrimarySpeciesConcentration[0] ),
57+
log( initialPrimarySpeciesConcentration[1] ),
58+
log( initialPrimarySpeciesConcentration[2] ),
59+
log( initialPrimarySpeciesConcentration[3] ),
60+
log( initialPrimarySpeciesConcentration[4] )
61+
};
62+
63+
EquilibriumReactionsType::enforceEquilibrium_Aggregate( 0,
64+
hpcReact::MoMasBenchmark::easyCaseParams.equilibriumReactionsParameters(),
65+
targetAggregatePrimarySpeciesConcentration,
66+
logInitialPrimarySpeciesConcentration,
67+
logPrimarySpeciesConcentrationCopy );
68+
});
6469

6570
double const expectedPrimarySpeciesConcentrations[numPrimarySpecies] =
6671
{
@@ -76,7 +81,10 @@ TEST( testEquilibriumReactions, testMoMasAllEquilibrium )
7681
EXPECT_NEAR( exp( logPrimarySpeciesConcentration[r] ), expectedPrimarySpeciesConcentrations[r], 1.0e-8 * expectedPrimarySpeciesConcentrations[r] );
7782
}
7883

79-
84+
}
85+
TEST( testEquilibriumReactions, testMoMasAllEquilibrium )
86+
{
87+
testMoMasAllEquilibriumHelper();
8088
}
8189

8290
int main( int argc, char * * argv )

src/reactions/exampleSystems/unitTests/testMomasMediumCase.cpp

Lines changed: 42 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -19,47 +19,54 @@ using namespace hpcReact::unitTest_utilities;
1919

2020
//******************************************************************************
2121

22-
TEST( testEquilibriumReactions, testMoMasMediumEquilibrium )
22+
23+
void testMoMasMediumEquilibriumHelper()
2324
{
2425
using EquilibriumReactionsType = reactionsSystems::EquilibriumReactions< double,
2526
int,
2627
int >;
2728

2829
constexpr int numPrimarySpecies = hpcReact::MoMasBenchmark::mediumCaseParams.numPrimarySpecies();
2930

30-
double const targetAggregatePrimarySpeciesConcentration[numPrimarySpecies] =
31-
{
32-
1.0e-20, // X1
33-
-3.0, // X2
34-
1.0e-20, // X3
35-
1.0, // X4
36-
1.0 // S
37-
};
3831

39-
double const initialPrimarySpeciesConcentration[numPrimarySpecies] =
40-
{
41-
1.0e-20, // X1
42-
0.02, // X2
43-
1.0e-20, // X3
44-
1.0, // X4
45-
1.0 // S
46-
};
4732

48-
double const logInitialPrimarySpeciesConcentration[numPrimarySpecies] =
33+
double logPrimarySpeciesConcentration[numPrimarySpecies];
34+
35+
pmpl::genericKernelWrapper( numPrimarySpecies, logPrimarySpeciesConcentration, [] HPCREACT_DEVICE ( auto * const logPrimarySpeciesConcentrationCopy )
4936
{
50-
log( initialPrimarySpeciesConcentration[0] ),
51-
log( initialPrimarySpeciesConcentration[1] ),
52-
log( initialPrimarySpeciesConcentration[2] ),
53-
log( initialPrimarySpeciesConcentration[3] ),
54-
log( initialPrimarySpeciesConcentration[4] )
55-
};
37+
double const targetAggregatePrimarySpeciesConcentration[numPrimarySpecies] =
38+
{
39+
1.0e-20, // X1
40+
-3.0, // X2
41+
1.0e-20, // X3
42+
1.0, // X4
43+
1.0 // S
44+
};
5645

57-
double logPrimarySpeciesConcentration[numPrimarySpecies];
58-
EquilibriumReactionsType::enforceEquilibrium_Aggregate( 0,
59-
hpcReact::MoMasBenchmark::mediumCaseParams.equilibriumReactionsParameters(),
60-
targetAggregatePrimarySpeciesConcentration,
61-
logInitialPrimarySpeciesConcentration,
62-
logPrimarySpeciesConcentration );
46+
double const initialPrimarySpeciesConcentration[numPrimarySpecies] =
47+
{
48+
1.0e-20, // X1
49+
0.02, // X2
50+
1.0e-20, // X3
51+
1.0, // X4
52+
1.0 // S
53+
};
54+
55+
double const logInitialPrimarySpeciesConcentration[numPrimarySpecies] =
56+
{
57+
log( initialPrimarySpeciesConcentration[0] ),
58+
log( initialPrimarySpeciesConcentration[1] ),
59+
log( initialPrimarySpeciesConcentration[2] ),
60+
log( initialPrimarySpeciesConcentration[3] ),
61+
log( initialPrimarySpeciesConcentration[4] )
62+
};
63+
64+
EquilibriumReactionsType::enforceEquilibrium_Aggregate( 0,
65+
hpcReact::MoMasBenchmark::mediumCaseParams.equilibriumReactionsParameters(),
66+
targetAggregatePrimarySpeciesConcentration,
67+
logInitialPrimarySpeciesConcentration,
68+
logPrimarySpeciesConcentrationCopy );
69+
});
6370

6471
double const expectedPrimarySpeciesConcentrations[numPrimarySpecies] =
6572
{
@@ -78,6 +85,11 @@ TEST( testEquilibriumReactions, testMoMasMediumEquilibrium )
7885

7986
}
8087

88+
TEST( testEquilibriumReactions, testMoMasMediumEquilibrium )
89+
{
90+
testMoMasMediumEquilibriumHelper();
91+
}
92+
8193
int main( int argc, char * * argv )
8294
{
8395
::testing::InitGoogleTest( &argc, argv );

src/reactions/geochemistry/unitTests/testGeochemicalKineticReactions.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,8 @@ TEST( testKineticReactions, testTimeStep_carbonateSystemAllKinetic )
164164
};
165165

166166
timeStepTest< double, false >( carbonateSystemAllKinetic.kineticReactionsParameters(),
167-
2.0,
168-
100000,
167+
10.0,
168+
10000,
169169
initialSpeciesConcentration,
170170
expectedSpeciesConcentrations );
171171

0 commit comments

Comments
 (0)