Skip to content

Commit

Permalink
Add the @nobarrier attribute to stop barriers from being automatica…
Browse files Browse the repository at this point in the history
…lly inserted between `@inner` loop blocks. (#544)
  • Loading branch information
kris-rowe committed Dec 7, 2021
1 parent 1a4c374 commit 2abc3e9
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/occa/internal/lang/builtins/attributes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <occa/internal/lang/builtins/attributes/inner.hpp>
#include <occa/internal/lang/builtins/attributes/kernel.hpp>
#include <occa/internal/lang/builtins/attributes/maxInnerDims.hpp>
#include <occa/internal/lang/builtins/attributes/noBarrier.hpp>
#include <occa/internal/lang/builtins/attributes/outer.hpp>
#include <occa/internal/lang/builtins/attributes/restrict.hpp>
#include <occa/internal/lang/builtins/attributes/shared.hpp>
Expand Down
34 changes: 34 additions & 0 deletions src/occa/internal/lang/builtins/attributes/noBarrier.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#include <occa/internal/lang/expr.hpp>
#include <occa/internal/lang/statement.hpp>
#include <occa/internal/lang/builtins/attributes/noBarrier.hpp>

namespace occa {
namespace lang {
namespace attributes {
//---[ @nobarrier ]-----------------------
noBarrier::noBarrier() {}

const std::string& noBarrier::name() const {
static std::string name_ = "nobarrier";
return name_;
}

bool noBarrier::forStatementType(const int sType) const {
return (sType & statementType::for_);
}

bool noBarrier::isValid(const attributeToken_t &attr) const {
if (attr.kwargs.size()) {
attr.printError("[@nobarrier] does not take kwargs");
return false;
}
if (attr.args.size()) {
attr.printError("[@nobarrier] does not take arguments");
return false;
}
return true;
}
//==================================
}
}
}
25 changes: 25 additions & 0 deletions src/occa/internal/lang/builtins/attributes/noBarrier.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#ifndef OCCA_INTERNAL_LANG_BUILTINS_ATTRIBUTES_NOBARRIER_HEADER
#define OCCA_INTERNAL_LANG_BUILTINS_ATTRIBUTES_NOBARRIER_HEADER

#include <occa/internal/lang/attribute.hpp>

namespace occa {
namespace lang {
namespace attributes {
//---[ @nobarrier ]---------------
class noBarrier : public attribute_t {
public:
noBarrier();

virtual const std::string& name() const;

virtual bool forStatementType(const int sType) const;

virtual bool isValid(const attributeToken_t &attr) const;
};
//================================
}
}
}

#endif
1 change: 1 addition & 0 deletions src/occa/internal/lang/modes/okl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,7 @@ namespace occa {
parser.addAttribute<attributes::outer>();
parser.addAttribute<attributes::shared>();
parser.addAttribute<attributes::maxInnerDims>();
parser.addAttribute<attributes::noBarrier>();
}

void setOklLoopIndices(functionDeclStatement &kernelSmnt) {
Expand Down
5 changes: 3 additions & 2 deletions src/occa/internal/lang/modes/withLauncher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -513,8 +513,9 @@ namespace occa {

//Only apply barriers when needed in the last inner-loop
if (isOuterMostInnerLoop(innerSmnt)
&& (!isLastInnerLoop(innerSmnt) || isInsideLoop(innerSmnt)))
addBarriersAfterInnerLoop(innerSmnt);
&& (!isLastInnerLoop(innerSmnt) || isInsideLoop(innerSmnt))
&& !(innerSmnt.hasAttribute("nobarrier"))
) addBarriersAfterInnerLoop(innerSmnt);
});
}

Expand Down

0 comments on commit 2abc3e9

Please sign in to comment.