Skip to content

Commit

Permalink
Explode globals (#1091)
Browse files Browse the repository at this point in the history
## Technical Description

In order to not be required to expose the `global` struct also in the external API the global variables need to be exploded in all API functions, not just the ones to FORTRAN
  • Loading branch information
mroethlin committed Jan 19, 2021
1 parent e72939c commit 6fdc460
Showing 1 changed file with 9 additions and 12 deletions.
21 changes: 9 additions & 12 deletions dawn/src/dawn/CodeGen/Cuda-ico/CudaIcoCodeGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@

#include "ASTStencilBody.h"
#include "dawn/AST/ASTExpr.h"
#include "dawn/AST/ASTVisitor.h"
#include "dawn/AST/IterationSpace.h"
#include "dawn/AST/LocationType.h"
#include "dawn/CodeGen/CXXUtil.h"
#include "dawn/CodeGen/Cuda-ico/LocToStringUtils.h"
#include "dawn/CodeGen/Cuda/CodeGeneratorHelper.h"
#include "dawn/CodeGen/F90Util.h"
#include "dawn/CodeGen/IcoChainSizes.h"
#include "dawn/AST/ASTVisitor.h"
#include "dawn/IIR/Field.h"
#include "dawn/IIR/Interval.h"
#include "dawn/IIR/MultiStage.h"
Expand Down Expand Up @@ -741,11 +741,8 @@ void CudaIcoCodeGen::generateAllAPIRunFunctions(
for(auto& apiRunFun : apiRunFuns) {
apiRunFun->addArg("dawn::GlobalGpuTriMesh *mesh");
apiRunFun->addArg("int k_size");
addExplodedGlobals(globalsMap, *apiRunFun);
}
if(!globalsMap.empty()) {
apiRunFuns[0]->addArg("globals globals");
}
addExplodedGlobals(globalsMap, *apiRunFuns[1]);
} else {
addExplodedGlobals(globalsMap, *apiRunFuns[0]);
}
Expand Down Expand Up @@ -809,12 +806,11 @@ void CudaIcoCodeGen::generateAllAPIRunFunctions(
const std::string fullStencilName =
"dawn_generated::cuda_ico::" + wrapperName + "::" + stencilName;

auto copyGlobals = [](const ast::GlobalVariableMap& globalsMap, MemberFunction& fun,
bool wrapped) {
auto copyGlobals = [](const dawn::ast::GlobalVariableMap& globalsMap, MemberFunction& fun) {
for(const auto& global : globalsMap) {
std::string Name = global.first;
std::string Type = ast::Value::typeToString(global.second.getType());
fun.addStatement("s.set_" + Name + "(" + (wrapped ? "globals." + Name : Name) + ")");
std::string Type = dawn::ast::Value::typeToString(global.second.getType());
fun.addStatement("s.set_" + Name + "(" + Name + ")");
}
};

Expand All @@ -829,11 +825,12 @@ void CudaIcoCodeGen::generateAllAPIRunFunctions(
// not
apiRunFuns[0]->addStatement("s.copy_memory(" + fieldsStr.str() + ", true)");
apiRunFuns[1]->addStatement("s.copy_memory(" + fieldsStr.str() + ", false)");
copyGlobals(globalsMap, *apiRunFuns[0], true);
copyGlobals(globalsMap, *apiRunFuns[1], false);
for(auto& apiRunFun : apiRunFuns) {
copyGlobals(globalsMap, *apiRunFun);
}
} else {
apiRunFuns[0]->addStatement("s.copy_pointers(" + fieldsStr.str() + ")");
copyGlobals(globalsMap, *apiRunFuns[0], false);
copyGlobals(globalsMap, *apiRunFuns[0]);
}
for(auto& apiRunFun : apiRunFuns) {
apiRunFun->addStatement("s.run()");
Expand Down

0 comments on commit 6fdc460

Please sign in to comment.