Skip to content

Commit 3cbf9aa

Browse files
committed
Add test driver for tapeless forward mode in the presence of OpDiLib.
1 parent d313bfe commit 3cbf9aa

64 files changed

Lines changed: 1176 additions & 2 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

tests/Makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,16 +79,20 @@ DRIVER_FILES = $(wildcard $(DRIVER_DIR)/Driver**.hpp)
7979
DRIVERS ?= $(patsubst $(DRIVER_DIR)/Driver%.hpp,%,$(DRIVER_FILES))
8080

8181
# exclude specific tests on a per-driver basis
82-
DRIVERS_USING_ALL_TESTS = FirstOrderReverse FirstOrderReverseNestedParallel FirstOrderReverseNoOpenMP FirstOrderReversePassive FirstOrderReverseSingleThread SecondOrderReverseForward
82+
DRIVERS_USING_ALL_TESTS = $(filter-out FirstOrderReverseNoParallel FirstOrderForward, $(DRIVERS))
8383
$(DRIVERS_USING_ALL_TESTS) $(patsubst %,run%,$(DRIVERS_USING_ALL_TESTS)): DRIVER_TESTS = $(TESTS)
8484

8585
# without surrounding parallel constructs, privatized variables are not recognized as shared and sections are considered orphaned; hence, they need to be filtered out
8686
FirstOrderReverseNoParallel runFirstOrderReverseNoParallel: DRIVER_TESTS = $(filter-out ParallelSections ForReduction ForReductionNowait ForReductionMultiple ForFirstprivate ForLastprivate OrderedReduction SectionsReduction SectionsReductionMultiple SectionsFirstprivate SectionsLastprivate ReductionNested SingleFirstprivate, $(TESTS))
8787

88+
FirstOrderForward runFirstOrderForward: DRIVER_TESTS = $(filter-out ExternalFunctionGlobal ExternalFunctionLocal ExternalFunctionLogicCalls ParallelFirstprivate2 StateExport TaskReset, $(TESTS))
89+
8890
# driver-specific compilation flags
8991
REVERSE_DRIVERS = FirstOrderReverse FirstOrderReverseNestedParallel FirstOrderReverseNoOpenMP FirstOrderReverseNoParallel FirstOrderReversePassive FirstOrderReverseSingleThread SecondOrderReverseForward
9092
$(REVERSE_DRIVERS): DRIVER_FLAGS = -DREVERSE_DRIVER
9193

94+
FirstOrderForward: DRIVER_FLAGS = -DFORWARD_DRIVER
95+
9296
# export directories for usage in shell scripts
9397
export DRIVER_DIR
9498
export TEST_DIR
Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
/*
2+
* OpDiLib, an Open Multiprocessing Differentiation Library
3+
*
4+
* Copyright (C) 2020-2022 Chair for Scientific Computing (SciComp), TU Kaiserslautern
5+
* Copyright (C) 2023-2025 Chair for Scientific Computing (SciComp), University of Kaiserslautern-Landau
6+
* Homepage: https://scicomp.rptu.de
7+
* Contact: Prof. Nicolas R. Gauger (opdi@scicomp.uni-kl.de)
8+
*
9+
* Lead developer: Johannes Blühdorn (SciComp, University of Kaiserslautern-Landau)
10+
*
11+
* This file is part of OpDiLib (https://scicomp.rptu.de/software/opdi).
12+
*
13+
* OpDiLib is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public
14+
* License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later
15+
* version.
16+
*
17+
* OpDiLib is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
18+
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
19+
* details.
20+
*
21+
* You should have received a copy of the GNU Lesser General Public License along with OpDiLib. If not, see
22+
* <http://www.gnu.org/licenses/>.
23+
*
24+
*/
25+
26+
#pragma once
27+
28+
#include <array>
29+
#include <cstdlib>
30+
#include <iostream>
31+
32+
#include "codi.hpp"
33+
34+
#ifndef BUILD_REFERENCE
35+
#ifdef OPDI_USE_MACRO_BACKEND
36+
#include "opdi/backend/macro/macroBackend.hpp"
37+
#elif OPDI_USE_OMPT_BACKEND
38+
#include "opdi/backend/ompt/omptBackend.hpp"
39+
#endif
40+
#include "opdi.hpp"
41+
#include "opdi/tool/emptyTool.hpp"
42+
#ifdef OUTPUT_INSTRUMENT
43+
#include "opdi/logic/omp/instrument/ompLogicOutputInstrument.hpp"
44+
#endif
45+
#else
46+
#include "opdi/helpers/emptyMacros.hpp"
47+
#endif
48+
49+
#include "driverBase.hpp"
50+
51+
using TestReal = codi::RealForward;
52+
53+
#ifndef BUILD_REFERENCE
54+
OPDI_DECLARE_REDUCTION(+, TestReal, +, 0.0);
55+
OPDI_DECLARE_REDUCTION(*, TestReal, *, 1.0);
56+
#endif
57+
58+
template<typename _Case>
59+
struct DriverFirstOrderForward : public DriverBase<DriverFirstOrderForward<_Case> > {
60+
public:
61+
62+
using Case = _Case;
63+
64+
static void run() {
65+
66+
#ifndef BUILD_REFERENCE
67+
#ifdef OPDI_USE_MACRO_BACKEND
68+
opdi::backend = new opdi::MacroBackend();
69+
opdi::backend->init();
70+
#else
71+
if (omp_get_num_threads() /* trigger OMPT initialization */ && opdi::backend == nullptr) {
72+
std::cout << "Could not initialize OMPT backend. Please check OMPT support." << std::endl;
73+
exit(1);
74+
}
75+
#endif
76+
#ifdef OUTPUT_INSTRUMENT
77+
opdi::ompLogicInstruments.push_back(new opdi::OmpLogicOutputInstrument);
78+
#endif
79+
opdi::logic = new opdi::OmpLogic;
80+
opdi::logic->init();
81+
opdi::tool = new opdi::EmptyTool;
82+
opdi::tool->init();
83+
#endif
84+
85+
std::array<std::array<TestReal, Case::nIn>, Case::nPoints> inputs = Case::template genPoints<TestReal>();
86+
87+
for (int p = 0; p < Case::nPoints; ++p) {
88+
double jacobian[Case::nOut][Case::nIn];
89+
double primal[Case::nOut];
90+
91+
for (int i = 0; i < Case::nIn; ++i) {
92+
std::array<TestReal, Case::nOut> outputs = {0.0};
93+
94+
inputs[p][i].setGradient(1.0);
95+
96+
Case::template test<TestReal>(inputs[p], outputs);
97+
98+
for (int o = 0; o < Case::nOut; ++o) {
99+
jacobian[o][i] = outputs[o].getGradient();
100+
primal[o] = outputs[o].getValue();
101+
}
102+
103+
inputs[p][i].setGradient(0.0);
104+
105+
#ifndef BUILD_REFERENCE
106+
opdi::logic->reset();
107+
#endif
108+
}
109+
110+
std::cout << "Point " << p << " :" << std::endl;
111+
for (int o = 0; o < Case::nOut; ++o)
112+
std::cout << primal[o] << std::endl;
113+
114+
for (int o = 0; o < Case::nOut; ++o) {
115+
for (int i = 0; i < Case::nIn; ++i) {
116+
std::cout << jacobian[o][i] << std::endl;
117+
}
118+
}
119+
}
120+
121+
#ifndef BUILD_REFERENCE
122+
opdi::tool->finalize();
123+
opdi::logic->finalize();
124+
#ifdef OUTPUT_INSTRUMENT
125+
delete opdi::ompLogicInstruments.front();
126+
opdi::ompLogicInstruments.clear();
127+
#endif
128+
opdi::backend->finalize();
129+
#ifdef OPDI_USE_MACRO_BACKEND
130+
delete opdi::backend;
131+
#endif
132+
delete opdi::tool;
133+
delete opdi::logic;
134+
#endif
135+
}
136+
};
137+
138+
#ifndef BUILD_REFERENCE
139+
#include "opdi.cpp"
140+
#endif
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
Point 0 :
2+
-524.484
3+
70443
4+
1905.62
5+
-159857
6+
-30387.6
7+
Point 1 :
8+
-362.937
9+
23881.9
10+
-37841.1
11+
-51032.7
12+
62404.1
13+
Point 2 :
14+
398.524
15+
62878.5
16+
-12291.6
17+
-42733.6
18+
104665
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
Point 0 :
2+
-524.484
3+
70443
4+
1905.62
5+
-159857
6+
-30387.6
7+
Point 1 :
8+
-362.937
9+
23881.9
10+
-37841.1
11+
-51032.7
12+
62404.1
13+
Point 2 :
14+
398.524
15+
62878.5
16+
-12291.6
17+
-42733.6
18+
104665
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
Point 0 :
2+
-519.699
3+
115228
4+
3477.57
5+
-118744
6+
-14333.2
7+
Point 1 :
8+
-364.32
9+
49251.7
10+
-68899.4
11+
-97499.6
12+
114015
13+
Point 2 :
14+
409.667
15+
56343.5
16+
11630.2
17+
-17082.3
18+
228925
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
Point 0 :
2+
358.725
3+
7.3232e+07
4+
-3.09295e+07
5+
8.1604e+07
6+
1.74782e+07
7+
Point 1 :
8+
298.759
9+
-9.18313e+07
10+
-6.69257e+07
11+
9.5149e+06
12+
4.98709e+07
13+
Point 2 :
14+
97.7815
15+
-8.88214e+07
16+
-8.42372e+07
17+
-1.5157e+07
18+
-1.5929e+08
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
Point 0 :
2+
595.487
3+
177.011
4+
392.217
5+
13697.3
6+
3466.68
7+
Point 1 :
8+
579.603
9+
12167.2
10+
5538.64
11+
-2783.46
12+
1269.94
13+
Point 2 :
14+
309.709
15+
4216.91
16+
13059.9
17+
11645.2
18+
135468
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
Point 0 :
2+
-348.826
3+
769.932
4+
1996.83
5+
-14980.6
6+
-2788.03
7+
Point 1 :
8+
-336.432
9+
-818.028
10+
3154.85
11+
4708.61
12+
1741.92
13+
Point 2 :
14+
-38.4341
15+
-3102.3
16+
-8004.34
17+
-5462.34
18+
-46717.7
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
Point 0 :
2+
-723.925
3+
-5515.29
4+
95.0474
5+
-6729
6+
-2140.22
7+
Point 1 :
8+
-325.634
9+
3921.84
10+
7865.3
11+
4847.89
12+
-3985.11
13+
Point 2 :
14+
237.233
15+
4779.5
16+
-3268.62
17+
-5359.29
18+
-10427.2
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
Point 0 :
2+
-723.925
3+
-5515.29
4+
95.0474
5+
-6729
6+
-2140.22
7+
Point 1 :
8+
-325.634
9+
3921.84
10+
7865.3
11+
4847.89
12+
-3985.11
13+
Point 2 :
14+
237.233
15+
4779.5
16+
-3268.62
17+
-5359.29
18+
-10427.2

0 commit comments

Comments
 (0)