-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add drivers for each gtclang and dawn component and uses these in the executables. This does add code, but that is mostly in separating options, and more code will be eliminated once only these drivers are used (follow-up PR).
- Loading branch information
Showing
34 changed files
with
681 additions
and
270 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
//===--------------------------------------------------------------------------------*- C++ -*-===// | ||
// _ | ||
// | | | ||
// __| | __ ___ ___ ___ | ||
// / _` |/ _` \ \ /\ / / '_ | | ||
// | (_| | (_| |\ V V /| | | | | ||
// \__,_|\__,_| \_/\_/ |_| |_| - Compiler Toolchain | ||
// | ||
// | ||
// This file is distributed under the MIT License (MIT). | ||
// See LICENSE.txt for details. | ||
// | ||
//===------------------------------------------------------------------------------------------===// | ||
|
||
#include "dawn/CodeGen/Driver.h" | ||
#include "dawn/CodeGen/CXXNaive-ico/CXXNaiveCodeGen.h" | ||
#include "dawn/CodeGen/CXXNaive/CXXNaiveCodeGen.h" | ||
#include "dawn/CodeGen/Cuda/CudaCodeGen.h" | ||
#include "dawn/CodeGen/GridTools/GTCodeGen.h" | ||
#include <stdexcept> | ||
|
||
namespace dawn { | ||
namespace codegen { | ||
|
||
std::string generate(const std::unique_ptr<TranslationUnit>& translationUnit) { | ||
std::string code; | ||
for(const auto& p : translationUnit->getPPDefines()) | ||
code += p + "\n"; | ||
|
||
code += translationUnit->getGlobals() + "\n\n"; | ||
for(const auto& p : translationUnit->getStencils()) | ||
code += p.second; | ||
|
||
return code; | ||
} | ||
|
||
codegen::Backend parseBackendString(const std::string& backendStr) { | ||
if(backendStr == "gt" || backendStr == "gridtools") { | ||
return codegen::Backend::GridTools; | ||
} else if(backendStr == "naive" || backendStr == "cxxnaive" || backendStr == "c++-naive") { | ||
return codegen::Backend::CXXNaive; | ||
} else if(backendStr == "ico" || backendStr == "naive-ico" || backendStr == "c++-naive-ico") { | ||
return codegen::Backend::CXXNaiveIco; | ||
} else if(backendStr == "cuda" || backendStr == "CUDA") { | ||
return codegen::Backend::CUDA; | ||
} else { | ||
throw std::invalid_argument("Backend not supported"); | ||
} | ||
} | ||
|
||
std::unique_ptr<TranslationUnit> | ||
run(const std::map<std::string, std::shared_ptr<iir::StencilInstantiation>>& context, | ||
Backend backend, const Options& options) { | ||
switch(backend) { | ||
case Backend::CUDA: | ||
return cuda::run(context, options); | ||
case Backend::CXXNaive: | ||
return cxxnaive::run(context, options); | ||
case Backend::CXXNaiveIco: | ||
return cxxnaiveico::run(context, options); | ||
case Backend::GridTools: | ||
return gt::run(context, options); | ||
case Backend::CXXOpt: | ||
throw std::invalid_argument("Backend not supported"); | ||
} | ||
// This line should not be needed but the compiler seems to complain if it is not present. | ||
return nullptr; | ||
} | ||
|
||
} // namespace codegen | ||
} // namespace dawn |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
//===--------------------------------------------------------------------------------*- C++ -*-===// | ||
// _ | ||
// | | | ||
// __| | __ ___ ___ ___ | ||
// / _` |/ _` \ \ /\ / / '_ | | ||
// | (_| | (_| |\ V V /| | | | | ||
// \__,_|\__,_| \_/\_/ |_| |_| - Compiler Toolchain | ||
// | ||
// | ||
// This file is distributed under the MIT License (MIT). | ||
// See LICENSE.txt for details. | ||
// | ||
//===------------------------------------------------------------------------------------------===// | ||
|
||
#ifndef DAWN_CODEGEN_DRIVER_H | ||
#define DAWN_CODEGEN_DRIVER_H | ||
|
||
#include "dawn/CodeGen/Options.h" | ||
#include "dawn/CodeGen/TranslationUnit.h" | ||
#include "dawn/IIR/StencilInstantiation.h" | ||
#include <map> | ||
#include <memory> | ||
#include <string> | ||
|
||
namespace dawn { | ||
namespace codegen { | ||
|
||
/// @brief Parse the backend string to enumeration | ||
Backend parseBackendString(const std::string& backendStr); | ||
|
||
/// @brief Run the code generation | ||
std::unique_ptr<TranslationUnit> | ||
run(const std::map<std::string, std::shared_ptr<iir::StencilInstantiation>>& context, | ||
Backend backend, const Options& options = {}); | ||
|
||
/// @brief Shortcut to generate code from a translation unit | ||
std::string generate(const std::unique_ptr<TranslationUnit>& translationUnit); | ||
|
||
} // namespace codegen | ||
} // namespace dawn | ||
|
||
#endif |
Oops, something went wrong.