Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the @nobarrier attribute to stop barriers from being added automatically to @inner loop blocks. #544

Merged
merged 2 commits into from
Dec 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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