Permalink
Browse files

Merge branch 'code_generation_maxderiv' into 'master'

[code generation] Option to generate code for derivatives

Closes #52

See merge request !228
  • Loading branch information...
JSchoeberl committed Sep 7, 2017
2 parents 5de755b + d32f6b1 commit a095e4cc7e22fe44200d7e546827714ab88f7f17
Showing with 19 additions and 12 deletions.
  1. +15 −9 fem/coefficient.cpp
  2. +1 −1 fem/coefficient.hpp
  3. +3 −2 fem/python_fem.cpp
@@ -4613,7 +4613,7 @@ shared_ptr<CoefficientFunction> MakeCoordinateCoefficientFunction (int comp)
lib_function_dderiv compiled_function_dderiv = nullptr;
lib_function_simd_dderiv compiled_function_simd_dderiv = nullptr;
public:
CompiledCoefficientFunction (shared_ptr<CoefficientFunction> acf, bool realcompile)
CompiledCoefficientFunction (shared_ptr<CoefficientFunction> acf, bool realcompile, int maxderiv)
: CoefficientFunction(acf->Dimension(), acf->IsComplex()), cf(acf) // , compiled_function(nullptr), compiled_function_simd(nullptr)
{
SetDimensions (cf->Dimensions());
@@ -4664,7 +4664,7 @@ shared_ptr<CoefficientFunction> MakeCoordinateCoefficientFunction (int comp)
string parameters[3] = {"results", "deriv", "dderiv"};
for (int deriv : Range(3))
for (int deriv : Range(maxderiv+1))
for (auto simd : {false,true}) {
cout << IM(3) << "Compiled CF:" << endl;
Code code;
@@ -4746,15 +4746,21 @@ shared_ptr<CoefficientFunction> MakeCoordinateCoefficientFunction (int comp)
pointer_code += "}\n";
codes.push_back(pointer_code);
}
std::thread( [this, codes] () {
std::thread( [this, codes, maxderiv] () {
try {
library.Compile( codes );
compiled_function_simd = library.GetFunction<lib_function_simd>("CompiledEvaluateSIMD");
compiled_function = library.GetFunction<lib_function>("CompiledEvaluate");
compiled_function_simd_deriv = library.GetFunction<lib_function_simd_deriv>("CompiledEvaluateDerivSIMD");
compiled_function_deriv = library.GetFunction<lib_function_deriv>("CompiledEvaluateDeriv");
compiled_function_simd_dderiv = library.GetFunction<lib_function_simd_dderiv>("CompiledEvaluateDDerivSIMD");
compiled_function_dderiv = library.GetFunction<lib_function_dderiv>("CompiledEvaluateDDeriv");
if(maxderiv>0)
{
compiled_function_simd_deriv = library.GetFunction<lib_function_simd_deriv>("CompiledEvaluateDerivSIMD");
compiled_function_deriv = library.GetFunction<lib_function_deriv>("CompiledEvaluateDeriv");
}
if(maxderiv>1)
{
compiled_function_simd_dderiv = library.GetFunction<lib_function_simd_dderiv>("CompiledEvaluateDDerivSIMD");
compiled_function_dderiv = library.GetFunction<lib_function_dderiv>("CompiledEvaluateDDeriv");
}
cout << IM(7) << "Compilation done" << endl;
} catch (const std::exception &e) {
cerr << IM(3) << "Compilation of CoefficientFunction failed: " << e.what() << endl;
@@ -5097,9 +5103,9 @@ shared_ptr<CoefficientFunction> MakeCoordinateCoefficientFunction (int comp)
shared_ptr<CoefficientFunction> Compile (shared_ptr<CoefficientFunction> c, bool realcompile)
shared_ptr<CoefficientFunction> Compile (shared_ptr<CoefficientFunction> c, bool realcompile, int maxderiv)
{
return make_shared<CompiledCoefficientFunction> (c, realcompile);
return make_shared<CompiledCoefficientFunction> (c, realcompile, maxderiv);
}
@@ -1738,7 +1738,7 @@ void ExportBinaryFunction (class pybind11::module & m, string name)
shared_ptr<CoefficientFunction> cf_else);
NGS_DLL_HEADER
shared_ptr<CoefficientFunction> Compile (shared_ptr<CoefficientFunction> c, bool realcompile=false);
shared_ptr<CoefficientFunction> Compile (shared_ptr<CoefficientFunction> c, bool realcompile=false, int maxderiv=2);
}
@@ -656,9 +656,10 @@ val : can be one of the following:
},
"transpose of matrix-valued CF")
.def ("Compile", [] (shared_ptr<CF> coef, bool realcompile)
{ return Compile (coef, realcompile); },
.def ("Compile", [] (shared_ptr<CF> coef, bool realcompile, int maxderiv)
{ return Compile (coef, realcompile, maxderiv); },
py::arg("realcompile")=false,
py::arg("maxderiv")=2,
"compile list of individual steps, experimental improvement for deep trees")
;

0 comments on commit a095e4c

Please sign in to comment.