Skip to content

Commit

Permalink
Remove diagnostics (#957)
Browse files Browse the repository at this point in the history
Removes the diagnostics objects and generally cleans up printing log messages, e.g. all "raw" std::cout calls inside dawn are removed and replaced by general ostreams that are hooked up to use the dawn::log::{info,warn,error}.stream() std::ostreams.
  • Loading branch information
jdahm committed May 29, 2020
1 parent f656bc3 commit 019b82c
Show file tree
Hide file tree
Showing 100 changed files with 491 additions and 935 deletions.
1 change: 0 additions & 1 deletion dawn/src/dawn/AST/ASTStringifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#include "dawn/Support/StringUtil.h"
#include "dawn/Support/Type.h"
#include "dawn/Support/Unreachable.h"
#include <iostream>
#include <sstream>

namespace dawn {
Expand Down
2 changes: 1 addition & 1 deletion dawn/src/dawn/AST/GridType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
//===------------------------------------------------------------------------------------------===//

#include "dawn/AST/GridType.h"
#include <iostream>
#include <ostream>

namespace dawn {

Expand Down
2 changes: 0 additions & 2 deletions dawn/src/dawn/AST/Offsets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
#include "dawn/AST/Offsets.h"
#include "dawn/Support/Assert.h"

#include <iostream>

namespace dawn {
namespace ast {

Expand Down
35 changes: 14 additions & 21 deletions dawn/src/dawn/CodeGen/CXXNaive-ico/CXXNaiveCodeGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "dawn/IIR/StencilInstantiation.h"
#include "dawn/SIR/SIR.h"
#include "dawn/Support/Assert.h"
#include "dawn/Support/Exception.h"
#include "dawn/Support/Logger.h"
#include "dawn/Support/StringUtil.h"
#include <algorithm>
Expand Down Expand Up @@ -93,20 +94,13 @@ std::unique_ptr<TranslationUnit>
run(const std::map<std::string, std::shared_ptr<iir::StencilInstantiation>>&
stencilInstantiationMap,
const Options& options) {
DiagnosticsEngine diagnostics;
CXXNaiveIcoCodeGen CG(stencilInstantiationMap, diagnostics, options.MaxHaloSize);
if(diagnostics.hasDiags()) {
for(const auto& diag : diagnostics.getQueue())
DAWN_LOG(INFO) << diag->getMessage();
throw std::runtime_error("An error occured in code generation");
}
CXXNaiveIcoCodeGen CG(stencilInstantiationMap, options.MaxHaloSize);

return CG.generateCode();
}

CXXNaiveIcoCodeGen::CXXNaiveIcoCodeGen(const StencilInstantiationContext& ctx,
DiagnosticsEngine& engine, int maxHaloPoint)
: CodeGen(ctx, engine, maxHaloPoint) {}
CXXNaiveIcoCodeGen::CXXNaiveIcoCodeGen(const StencilInstantiationContext& ctx, int maxHaloPoint)
: CodeGen(ctx, maxHaloPoint) {}

CXXNaiveIcoCodeGen::~CXXNaiveIcoCodeGen() {}

Expand Down Expand Up @@ -527,23 +521,22 @@ void CXXNaiveIcoCodeGen::generateStencilFunctions(
const auto& fields = stencilFun->getCalleeFields();

if(fields.empty()) {
DiagnosticsBuilder diag(DiagnosticsKind::Error,
stencilInstantiation->getMetaData().getStencilLocation());
diag << "no storages referenced in stencil '" << stencilInstantiation->getName()
<< "', this would result in invalid gridtools code";
diagEngine.report(diag);
return;
throw SemanticError(std::string("No storages referenced in stencil '") +
stencilInstantiation->getName() +
"', this would result in invalid gridtools code",
stencilInstantiation->getMetaData().getFileName(),
stencilInstantiation->getMetaData().getStencilLocation());
}

MemberFunction stencilFunMethod = stencilWrapperClass.addMemberFunction(
std::string("static ") + (stencilFun->hasReturn() ? "double" : "void"), stencilFunName);

if(fields.empty() && !stencilFun->hasReturn()) {
DiagnosticsBuilder diag(DiagnosticsKind::Error, stencilFun->getStencilFunction()->Loc);
diag << "no storages referenced in stencil function '" << stencilFun->getName()
<< "', this would result in invalid gridtools code";
diagEngine.report(diag);
return;
throw SemanticError(std::string("No storages referenced in stencil function '") +
stencilInstantiation->getName() +
"', this would result in invalid gridtools code",
stencilInstantiation->getMetaData().getFileName(),
stencilFun->getStencilFunction()->Loc);
}

// Each stencil function call will pass the (i,j,k) position
Expand Down
3 changes: 1 addition & 2 deletions dawn/src/dawn/CodeGen/CXXNaive-ico/CXXNaiveCodeGen.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ run(const std::map<std::string, std::shared_ptr<iir::StencilInstantiation>>&
class CXXNaiveIcoCodeGen : public CodeGen {
public:
///@brief constructor
CXXNaiveIcoCodeGen(const StencilInstantiationContext& ctx, DiagnosticsEngine& engine,
int maxHaloPoint);
CXXNaiveIcoCodeGen(const StencilInstantiationContext& ctx, int maxHaloPoint);
virtual ~CXXNaiveIcoCodeGen();
virtual std::unique_ptr<TranslationUnit> generateCode() override;

Expand Down
35 changes: 14 additions & 21 deletions dawn/src/dawn/CodeGen/CXXNaive/CXXNaiveCodeGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "dawn/IIR/StencilInstantiation.h"
#include "dawn/SIR/SIR.h"
#include "dawn/Support/Assert.h"
#include "dawn/Support/Exception.h"
#include "dawn/Support/Logger.h"
#include "dawn/Support/StringUtil.h"
#include <algorithm>
Expand Down Expand Up @@ -88,20 +89,13 @@ std::unique_ptr<TranslationUnit>
run(const std::map<std::string, std::shared_ptr<iir::StencilInstantiation>>&
stencilInstantiationMap,
const Options& options) {
DiagnosticsEngine diagnostics;
CXXNaiveCodeGen CG(stencilInstantiationMap, diagnostics, options.MaxHaloSize);
if(diagnostics.hasDiags()) {
for(const auto& diag : diagnostics.getQueue())
DAWN_LOG(INFO) << diag->getMessage();
throw std::runtime_error("An error occured in code generation");
}
CXXNaiveCodeGen CG(stencilInstantiationMap, options.MaxHaloSize);

return CG.generateCode();
}

CXXNaiveCodeGen::CXXNaiveCodeGen(const StencilInstantiationContext& ctx, DiagnosticsEngine& engine,
int maxHaloPoint)
: CodeGen(ctx, engine, maxHaloPoint) {}
CXXNaiveCodeGen::CXXNaiveCodeGen(const StencilInstantiationContext& ctx, int maxHaloPoint)
: CodeGen(ctx, maxHaloPoint) {}

CXXNaiveCodeGen::~CXXNaiveCodeGen() {}

Expand Down Expand Up @@ -522,12 +516,11 @@ void CXXNaiveCodeGen::generateStencilFunctions(
const auto& fields = stencilFun->getCalleeFields();

if(fields.empty()) {
DiagnosticsBuilder diag(DiagnosticsKind::Error,
stencilInstantiation->getMetaData().getStencilLocation());
diag << "no storages referenced in stencil '" << stencilInstantiation->getName()
<< "', this would result in invalid gridtools code";
diagEngine.report(diag);
return;
throw SemanticError(std::string("No storages referenced in stencil '") +
stencilInstantiation->getName() +
"', this would result in invalid gridtools code",
stencilInstantiation->getMetaData().getFileName(),
stencilInstantiation->getMetaData().getStencilLocation());
}

// list of template names of the stencil function declaration
Expand All @@ -543,11 +536,11 @@ void CXXNaiveCodeGen::generateStencilFunctions(
[](const std::string& str) { return "class " + str; }));

if(fields.empty() && !stencilFun->hasReturn()) {
DiagnosticsBuilder diag(DiagnosticsKind::Error, stencilFun->getStencilFunction()->Loc);
diag << "no storages referenced in stencil function '" << stencilFun->getName()
<< "', this would result in invalid gridtools code";
diagEngine.report(diag);
return;
throw SemanticError(std::string("No storages referenced in stencil function '") +
stencilInstantiation->getName() +
"', this would result in invalid gridtools code",
stencilInstantiation->getMetaData().getFileName(),
stencilFun->getStencilFunction()->Loc);
}

// Each stencil function call will pass the (i,j,k) position
Expand Down
3 changes: 1 addition & 2 deletions dawn/src/dawn/CodeGen/CXXNaive/CXXNaiveCodeGen.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ run(const std::map<std::string, std::shared_ptr<iir::StencilInstantiation>>&
class CXXNaiveCodeGen : public CodeGen {
public:
///@brief constructor
CXXNaiveCodeGen(const StencilInstantiationContext& ctx, DiagnosticsEngine& engine,
int maxHaloPoint);
CXXNaiveCodeGen(const StencilInstantiationContext& ctx, int maxHaloPoint);
virtual ~CXXNaiveCodeGen();
virtual std::unique_ptr<TranslationUnit> generateCode() override;

Expand Down
5 changes: 2 additions & 3 deletions dawn/src/dawn/CodeGen/CodeGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@
namespace dawn {
namespace codegen {

CodeGen::CodeGen(const StencilInstantiationContext& ctx, DiagnosticsEngine& engine,
int maxHaloPoints)
: context_(ctx), diagEngine(engine), codeGenOptions{maxHaloPoints} {}
CodeGen::CodeGen(const StencilInstantiationContext& ctx, int maxHaloPoints)
: context_(ctx), codeGenOptions{maxHaloPoints} {}

size_t CodeGen::getVerticalTmpHaloSize(iir::Stencil const& stencil) {
std::optional<iir::Interval> tmpInterval = stencil.getEnclosingIntervalTemporaries();
Expand Down
4 changes: 1 addition & 3 deletions dawn/src/dawn/CodeGen/CodeGen.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#include "dawn/CodeGen/CodeGenProperties.h"
#include "dawn/CodeGen/TranslationUnit.h"
#include "dawn/IIR/StencilInstantiation.h"
#include "dawn/Support/DiagnosticsEngine.h"
#include "dawn/Support/IndexRange.h"
#include <memory>

Expand All @@ -34,7 +33,6 @@ using StencilInstantiationContext =
class CodeGen {
protected:
const StencilInstantiationContext& context_;
DiagnosticsEngine& diagEngine;
struct codeGenOption {
int MaxHaloPoints;
} codeGenOptions;
Expand Down Expand Up @@ -77,7 +75,7 @@ class CodeGen {
const std::string bigWrapperMetadata_ = "m_meta_data";

public:
CodeGen(const StencilInstantiationContext& ctx, DiagnosticsEngine& engine, int maxHaloPoints);
CodeGen(const StencilInstantiationContext& ctx, int maxHaloPoints);
virtual ~CodeGen() {}

/// @brief Generate code
Expand Down
16 changes: 5 additions & 11 deletions dawn/src/dawn/CodeGen/Cuda-ico/CudaIcoCodeGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,23 +39,17 @@ std::unique_ptr<TranslationUnit>
run(const std::map<std::string, std::shared_ptr<iir::StencilInstantiation>>&
stencilInstantiationMap,
const Options& options) {
DiagnosticsEngine diagnostics;
const Array3i domain_size{options.DomainSizeI, options.DomainSizeJ, options.DomainSizeK};
CudaIcoCodeGen CG(stencilInstantiationMap, diagnostics, options.MaxHaloSize, options.nsms,
CudaIcoCodeGen CG(stencilInstantiationMap, options.MaxHaloSize, options.nsms,
options.MaxBlocksPerSM, domain_size);
if(diagnostics.hasDiags()) {
for(const auto& diag : diagnostics.getQueue())
DAWN_LOG(INFO) << diag->getMessage();
throw std::runtime_error("An error occured in code generation");
}

return CG.generateCode();
}

CudaIcoCodeGen::CudaIcoCodeGen(const StencilInstantiationContext& ctx, DiagnosticsEngine& engine,
int maxHaloPoints, int nsms, int maxBlocksPerSM,
const Array3i& domainSize)
: CodeGen(ctx, engine, maxHaloPoints) {}
CudaIcoCodeGen::CudaIcoCodeGen(const StencilInstantiationContext& ctx, int maxHaloPoints, int nsms,
int maxBlocksPerSM, const Array3i& domainSize,
const bool runWithSync)
: CodeGen(ctx, maxHaloPoints) {}

CudaIcoCodeGen::~CudaIcoCodeGen() {}

Expand Down
5 changes: 3 additions & 2 deletions dawn/src/dawn/CodeGen/Cuda-ico/CudaIcoCodeGen.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,16 @@ class CudaIcoCodeGen : public CodeGen {

public:
///@brief constructor
CudaIcoCodeGen(const StencilInstantiationContext& ctx, DiagnosticsEngine& engine,
int maxHaloPoints, int nsms, int maxBlocksPerSM, const Array3i& domainSize);
CudaIcoCodeGen(const StencilInstantiationContext& ctx, int maxHaloPoints, int nsms,
int maxBlocksPerSM, const Array3i& domainSize, bool runWithSync = true);
virtual ~CudaIcoCodeGen();
virtual std::unique_ptr<TranslationUnit> generateCode() override;

struct CudaCodeGenOptions {
int nsms;
int maxBlocksPerSM;
Array3i domainSize;
bool runWithSync;
};

private:
Expand Down
18 changes: 5 additions & 13 deletions dawn/src/dawn/CodeGen/Cuda/CudaCodeGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,24 +56,16 @@ std::unique_ptr<TranslationUnit>
run(const std::map<std::string, std::shared_ptr<iir::StencilInstantiation>>&
stencilInstantiationMap,
const Options& options) {
DiagnosticsEngine diagnostics;
const Array3i domain_size{options.DomainSizeI, options.DomainSizeJ, options.DomainSizeK};
CudaCodeGen CG(stencilInstantiationMap, diagnostics, options.MaxHaloSize, options.nsms,
options.MaxBlocksPerSM, domain_size, options.RunWithSync);
if(diagnostics.hasDiags()) {
for(const auto& diag : diagnostics.getQueue())
DAWN_LOG(INFO) << diag->getMessage();
throw std::runtime_error("An error occured in code generation");
}
CudaCodeGen CG(stencilInstantiationMap, options.MaxHaloSize, options.nsms, options.MaxBlocksPerSM,
domain_size, options.RunWithSync);

return CG.generateCode();
}

CudaCodeGen::CudaCodeGen(const StencilInstantiationContext& ctx, DiagnosticsEngine& engine,
int maxHaloPoints, int nsms, int maxBlocksPerSM,
const Array3i& domainSize, bool runWithSync)
: CodeGen(ctx, engine, maxHaloPoints), codeGenOptions_{nsms, maxBlocksPerSM, domainSize,
runWithSync} {}
CudaCodeGen::CudaCodeGen(const StencilInstantiationContext& ctx, int maxHaloPoints, int nsms,
int maxBlocksPerSM, const Array3i& domainSize, bool runWithSync)
: CodeGen(ctx, maxHaloPoints), codeGenOptions_{nsms, maxBlocksPerSM, domainSize, runWithSync} {}

CudaCodeGen::~CudaCodeGen() {}

Expand Down
4 changes: 2 additions & 2 deletions dawn/src/dawn/CodeGen/Cuda/CudaCodeGen.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ class CudaCodeGen : public CodeGen {

public:
///@brief constructor
CudaCodeGen(const StencilInstantiationContext& ctx, DiagnosticsEngine& engine, int maxHaloPoints,
int nsms, int maxBlocksPerSM, const Array3i& domainSize, bool runWithSync = true);
CudaCodeGen(const StencilInstantiationContext& ctx, int maxHaloPoints, int nsms,
int maxBlocksPerSM, const Array3i& domainSize, bool runWithSync = true);
virtual ~CudaCodeGen();
virtual std::unique_ptr<TranslationUnit> generateCode() override;

Expand Down
46 changes: 19 additions & 27 deletions dawn/src/dawn/CodeGen/GridTools/GTCodeGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include "dawn/IIR/StencilInstantiation.h"
#include "dawn/SIR/SIR.h"
#include "dawn/Support/Assert.h"
#include "dawn/Support/DiagnosticsEngine.h"
#include "dawn/Support/Exception.h"
#include "dawn/Support/Logger.h"
#include "dawn/Support/StringUtil.h"
#include <map>
Expand All @@ -38,21 +38,15 @@ std::unique_ptr<TranslationUnit>
run(const std::map<std::string, std::shared_ptr<iir::StencilInstantiation>>&
stencilInstantiationMap,
const Options& options) {
DiagnosticsEngine diagnostics;
GTCodeGen CG(stencilInstantiationMap, diagnostics, options.UseParallelEP, options.MaxHaloSize,
GTCodeGen CG(stencilInstantiationMap, options.UseParallelEP, options.MaxHaloSize,
options.RunWithSync);
if(diagnostics.hasDiags()) {
for(const auto& diag : diagnostics.getQueue())
DAWN_LOG(INFO) << diag->getMessage();
throw std::runtime_error("An error occured in code generation");
}

return CG.generateCode();
}

GTCodeGen::GTCodeGen(const StencilInstantiationContext& ctx, DiagnosticsEngine& engine,
bool useParallelEP, int maxHaloPoints, bool runWithSync)
: CodeGen(ctx, engine, maxHaloPoints),
GTCodeGen::GTCodeGen(const StencilInstantiationContext& ctx, bool useParallelEP, int maxHaloPoints,
bool runWithSync)
: CodeGen(ctx, maxHaloPoints),
mplContainerMaxSize_(20), codeGenOptions_{useParallelEP, runWithSync} {}

GTCodeGen::~GTCodeGen() {}
Expand Down Expand Up @@ -491,12 +485,10 @@ void GTCodeGen::generateStencilClasses(
return !f.second.IsTemporary;
});
if(stencil.isEmpty()) {
DiagnosticsBuilder diag(DiagnosticsKind::Error,
stencilInstantiation->getMetaData().getStencilLocation());
diag << "empty stencil '" << stencilInstantiation->getName()
<< "', this would result in invalid gridtools code";
diagEngine.report(diag);
return;
throw SemanticError(std::string("Empty stencil '") + stencilInstantiation->getName() +
"', this would result in invalid gridtools code",
stencilInstantiation->getMetaData().getFileName(),
stencilInstantiation->getMetaData().getStencilLocation());
}

// Check for horizontal iteration spaces
Expand Down Expand Up @@ -585,11 +577,11 @@ void GTCodeGen::generateStencilClasses(
std::vector<std::string> arglist;

if(fields.empty() && !stencilFun->hasReturn()) {
DiagnosticsBuilder diag(DiagnosticsKind::Error, stencilFun->getStencilFunction()->Loc);
diag << "no storages referenced in stencil function '" << stencilFun->getName()
<< "', this would result in invalid gridtools code";
diagEngine.report(diag);
return;
throw SemanticError(std::string("No storages referenced in stencil '") +
stencilInstantiation->getName() +
"', this would result in invalid gridtools code",
stencilInstantiation->getMetaData().getFileName(),
stencilInstantiation->getMetaData().getStencilLocation());
}

// If we have a return argument, we generate a special `__out` field
Expand Down Expand Up @@ -755,11 +747,11 @@ void GTCodeGen::generateStencilClasses(
// Field declaration
std::vector<std::string> arglist;
if(fields.empty()) {
DiagnosticsBuilder diag(DiagnosticsKind::Error,
stencilInstantiation->getMetaData().getStencilLocation());
diag << "no storages referenced in stencil '" << stencilInstantiation->getName()
<< "', this would result in invalid gridtools code";
diagEngine.report(diag);
throw SemanticError(std::string("No storages referenced in stencil '") +
stencilInstantiation->getName() +
"', this would result in invalid gridtools code",
stencilInstantiation->getMetaData().getFileName(),
stencilInstantiation->getMetaData().getStencilLocation());
}

std::size_t accessorIdx = 0;
Expand Down
Loading

0 comments on commit 019b82c

Please sign in to comment.