Skip to content

Commit ba1632f

Browse files
authored
Merge pull request #47 from joaoleal/develop
Develop
2 parents c97c024 + 9650a00 commit ba1632f

20 files changed

+585
-357
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ ENDIF()
153153
# ----------------------------------------------------------------------------
154154
# Check if it is possible to use LLVM/Clang for JIT
155155
# ----------------------------------------------------------------------------
156-
SET(CPPADCG_LLVM_LINK_LIB "3.2|3.6|3.8|4.0|5.0|6.0|7.0|8.0")
156+
SET(CPPADCG_LLVM_LINK_LIB "3.2|3.6|3.8|4.0|5.0|6.0|7.0|8.0|9.0")
157157

158158
IF((("${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}" MATCHES "^(${CPPADCG_LLVM_LINK_LIB})$") AND CLANG_FOUND)
159159
OR

cmake/FindLLVM.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ UNSET(LLVM_MODULE_LIBS CACHE)
4141

4242
MACRO(find_llvm_iteratively)
4343
IF(NOT LLVM_CONFIG AND NOT LLVM_FIND_VERSION_EXACT)
44-
SET(_LLVM_KNOWN_VERSIONS ${LLVM_ADDITIONAL_VERSIONS} "8" "7" "6.0" "5.0" "4.0" "3.8" "3.7" "3.6" "3.5" "3.4" "3.3" "3.2")
44+
SET(_LLVM_KNOWN_VERSIONS ${LLVM_ADDITIONAL_VERSIONS} "9" "8" "7" "6.0" "5.0" "4.0" "3.8" "3.7" "3.6" "3.5" "3.4" "3.3" "3.2")
4545

4646
# Select acceptable versions.
4747
FOREACH(version ${_LLVM_KNOWN_VERSIONS})

include/cppad/cg/lang/mathml/language_mathml.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -601,7 +601,7 @@ class LanguageMathML : public Language<Base> {
601601
const std::vector<FuncArgument>& indArg = _nameGen->getIndependent();
602602
const std::vector<FuncArgument>& depArg = _nameGen->getDependent();
603603
const std::vector<FuncArgument>& tmpArg = _nameGen->getTemporary();
604-
CPPADCG_ASSERT_KNOWN(!indArg.empty() && depArg.size() > 0,
604+
CPPADCG_ASSERT_KNOWN(!indArg.empty() && !depArg.empty(),
605605
"There must be at least one dependent and one independent argument")
606606
CPPADCG_ASSERT_KNOWN(tmpArg.size() == 3,
607607
"There must be three temporary variables")
@@ -1906,7 +1906,7 @@ class LanguageMathML : public Language<Base> {
19061906
CPPADCG_ASSERT_KNOWN(node.getOperationType() == CGOpCode::IndexAssign, "Invalid node type")
19071907
CPPADCG_ASSERT_KNOWN(node.getArguments().size() > 0, "Invalid number of arguments for an index assignment operation")
19081908

1909-
IndexAssignOperationNode<Base>& inode = static_cast<IndexAssignOperationNode<Base>&> (node);
1909+
auto& inode = static_cast<IndexAssignOperationNode<Base>&> (node);
19101910

19111911
const IndexPattern& ip = inode.getIndexPattern();
19121912
_code << _startEq

include/cppad/cg/model/llvm/llvm.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
#include <cppad/cg/model/llvm/v7_0/llvm7_0.hpp>
3737
#elif LLVM_VERSION_MAJOR==8 && LLVM_VERSION_MINOR==0
3838
#include <cppad/cg/model/llvm/v8_0/llvm8_0.hpp>
39+
#elif LLVM_VERSION_MAJOR==9 && LLVM_VERSION_MINOR==0
40+
#include <cppad/cg/model/llvm/v9_0/llvm9_0.hpp>
3941
#endif
4042

4143
#endif
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
#ifndef CPPAD_CG_LLVM9_0_INCLUDED
2+
#define CPPAD_CG_LLVM9_0_INCLUDED
3+
/* --------------------------------------------------------------------------
4+
* CppADCodeGen: C++ Algorithmic Differentiation with Source Code Generation:
5+
* Copyright (C) 2019 Joao Leal
6+
*
7+
* CppADCodeGen is distributed under multiple licenses:
8+
*
9+
* - Eclipse Public License Version 1.0 (EPL1), and
10+
* - GNU General Public License Version 3 (GPL3).
11+
*
12+
* EPL1 terms and conditions can be found in the file "epl-v10.txt", while
13+
* terms and conditions for the GPL3 can be found in the file "gpl3.txt".
14+
* ----------------------------------------------------------------------------
15+
* Author: Joao Leal
16+
*/
17+
18+
/**
19+
* LLVM requires the use of it own flags which can make it difficult to compile
20+
* libraries not using NDEBUG often required by LLVM.
21+
* The define LLVM_CPPFLAG_NDEBUG can be used to apply NDEBUG only to LLVM
22+
* headers.
23+
*/
24+
#ifdef LLVM_WITH_NDEBUG
25+
26+
// save the original NDEBUG definition
27+
#ifdef NDEBUG
28+
#define _OUTER_NDEBUG_DEFINED
29+
#endif
30+
31+
#if LLVM_WITH_NDEBUG == 1
32+
#define NDEBUG
33+
#else
34+
#undef NDEBUG
35+
#endif
36+
37+
#endif
38+
39+
#include <clang/CodeGen/CodeGenAction.h>
40+
#include <clang/Basic/DiagnosticOptions.h>
41+
#include <clang/Basic/TargetInfo.h>
42+
#include <clang/Basic/SourceManager.h>
43+
#include <clang/Frontend/CompilerInstance.h>
44+
#include <clang/Frontend/CompilerInvocation.h>
45+
#include <clang/Frontend/FrontendDiagnostic.h>
46+
#include <clang/Frontend/TextDiagnosticPrinter.h>
47+
#include <clang/Frontend/Utils.h>
48+
#include <clang/Parse/ParseAST.h>
49+
#include <clang/Lex/Preprocessor.h>
50+
#include <clang/Lex/PreprocessorOptions.h>
51+
52+
#include <llvm/Analysis/Passes.h>
53+
#include <llvm/IR/Verifier.h>
54+
#include <llvm/ExecutionEngine/ExecutionEngine.h>
55+
#include <llvm/ExecutionEngine/SectionMemoryManager.h>
56+
//#include <llvm/ExecutionEngine/JIT.h>
57+
#include <llvm/IR/LegacyPassManager.h>
58+
#include <llvm/IR/Module.h>
59+
#include <llvm/IR/LLVMContext.h>
60+
#include <llvm/Pass.h>
61+
#include <llvm/Transforms/IPO/PassManagerBuilder.h>
62+
#include <llvm/Bitcode/BitcodeReader.h>
63+
#include <llvm/Bitcode/BitcodeWriter.h>
64+
#include <llvm/Support/ManagedStatic.h>
65+
#include <llvm/Support/MemoryBuffer.h>
66+
#include <llvm/Support/TargetSelect.h>
67+
#include <llvm/Support/raw_os_ostream.h>
68+
//#include <llvm/Support/system_error.h>
69+
#include <llvm/Linker/Linker.h>
70+
#include <llvm/Support/Program.h>
71+
72+
#ifdef LLVM_WITH_NDEBUG
73+
74+
// recover the original NDEBUG
75+
#ifdef _OUTER_NDEBUG_DEFINED
76+
#define NDEBUG
77+
#else
78+
#undef NDEBUG
79+
#endif
80+
81+
// no need for this anymore
82+
#undef _OUTER_NDEBUG_DEFINED
83+
84+
#endif
85+
86+
#include <cppad/cg/model/compiler/clang_compiler.hpp>
87+
#include <cppad/cg/model/llvm/llvm_model_library.hpp>
88+
#include <cppad/cg/model/llvm/llvm_model.hpp>
89+
#include <cppad/cg/model/llvm/v5_0/llvm_model_library_impl.hpp> // yes, this is from version 5.0
90+
#include <cppad/cg/model/llvm/v9_0/llvm_model_library_processor.hpp>
91+
92+
#endif
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#ifndef CPPAD_CG_LLVM_MODEL_LIBRARY_PROCESSOR_INCLUDED
2+
#define CPPAD_CG_LLVM_MODEL_LIBRARY_PROCESSOR_INCLUDED
3+
/* --------------------------------------------------------------------------
4+
* CppADCodeGen: C++ Algorithmic Differentiation with Source Code Generation:
5+
* Copyright (C) 2020 Joao Leal
6+
*
7+
* CppADCodeGen is distributed under multiple licenses:
8+
*
9+
* - Eclipse Public License Version 1.0 (EPL1), and
10+
* - GNU General Public License Version 3 (GPL3).
11+
*
12+
* EPL1 terms and conditions can be found in the file "epl-v10.txt", while
13+
* terms and conditions for the GPL3 can be found in the file "gpl3.txt".
14+
* ----------------------------------------------------------------------------
15+
* Author: Joao Leal
16+
*/
17+
18+
#include <cppad/cg/model/llvm/v5_0/llvm_base_model_library_processor_impl.hpp>
19+
20+
namespace CppAD {
21+
namespace cg {
22+
23+
/**
24+
* Useful class for generating a JIT evaluated model library (LLVM 9.0).
25+
*
26+
* @author Joao Leal
27+
*/
28+
template<class Base>
29+
class LlvmModelLibraryProcessor : public LlvmBaseModelLibraryProcessorImpl<Base> {
30+
public:
31+
32+
/**
33+
* Creates a LLVM model library processor.
34+
*
35+
* @param librarySourceGen
36+
*/
37+
LlvmModelLibraryProcessor(ModelLibraryCSourceGen<Base>& librarySourceGen) :
38+
LlvmBaseModelLibraryProcessorImpl<Base>(librarySourceGen, "9") {
39+
}
40+
41+
virtual ~LlvmModelLibraryProcessor() = default;
42+
43+
using LlvmBaseModelLibraryProcessorImpl<Base>::create;
44+
45+
static inline std::unique_ptr<LlvmModelLibrary<Base>> create(ModelLibraryCSourceGen<Base>& modelLibraryHelper) {
46+
LlvmModelLibraryProcessor<Base> p(modelLibraryHelper);
47+
return p.create();
48+
}
49+
};
50+
51+
} // END cg namespace
52+
} // END CppAD namespace
53+
54+
#endif

include/cppad/cg/util.hpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ inline void addMatrixSparsity(const VectorSet& a,
139139
template<class VectorSet, class VectorSet2>
140140
inline void addMatrixSparsity(const VectorSet& a,
141141
VectorSet2& result) {
142-
CPPADCG_ASSERT_UNKNOWN(result.size() == a.size());
142+
CPPADCG_ASSERT_UNKNOWN(result.size() == a.size())
143143

144144
addMatrixSparsity<VectorSet, VectorSet2>(a, a.size(), result);
145145
}
@@ -197,7 +197,7 @@ inline void multMatrixMatrixSparsity(const VectorSet& a,
197197

198198
for (size_t jj = 0; jj < q; jj++) { //loop columns of b
199199
const std::set<size_t>& colB = bt[jj];
200-
if (colB.size() > 0) {
200+
if (!colB.empty()) {
201201
for (size_t i = 0; i < m; i++) {
202202
const std::set<size_t>& rowA = a[i];
203203
for (size_t rowb : colB) {
@@ -264,7 +264,7 @@ inline void multMatrixTransMatrixSparsity(const VectorSet& a,
264264

265265
for (size_t jj = 0; jj < q; jj++) { //loop columns of b
266266
const std::set<size_t>& colB = bt[jj];
267-
if (colB.size() > 0) {
267+
if (!colB.empty()) {
268268
for (size_t i = 0; i < n; i++) {
269269
const std::set<size_t>& rowAt = at[i];
270270
if (!rowAt.empty()) {
@@ -805,6 +805,16 @@ inline std::string implode(const std::vector<std::string>& text,
805805
}
806806
}
807807

808+
std::string readStringFromFile(const std::string& path) {
809+
std::ifstream iStream;
810+
iStream.open(path);
811+
812+
std::stringstream strStream;
813+
strStream << iStream.rdbuf();
814+
815+
return strStream.str();
816+
}
817+
808818
} // END cg namespace
809819
} // END CppAD namespace
810820

test/CppADCGTest.hpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,19 @@ class CppADCGTest : public ::testing::Test {
5353

5454
protected:
5555

56+
static inline ::testing::AssertionResult compareValues(const std::vector<Base>& depCGen,
57+
const std::vector<CppAD::cg::CG<Base> >& dep,
58+
double epsilonR = 1e-14, double epsilonA = 1e-14) {
59+
60+
std::vector<double> depd(dep.size());
61+
62+
for (size_t i = 0; i < depd.size(); i++) {
63+
depd[i] = dep[i].getValue();
64+
}
65+
66+
return compareValues<Base>(depCGen, depd, epsilonR, epsilonA);
67+
}
68+
5669
template<class T>
5770
static inline ::testing::AssertionResult compareValues(const std::vector<std::vector<T> >& depCGen,
5871
const std::vector<std::vector<T> >& dep,

0 commit comments

Comments
 (0)