-
Notifications
You must be signed in to change notification settings - Fork 122
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
Kokkos-aware Clad #783
base: master
Are you sure you want to change the base?
Kokkos-aware Clad #783
Conversation
…ide the forward pass
…zation problem with a simple algorithm
This triggers a static assert in GNU libstdc++
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clang-tidy made some suggestions
There were too many comments to post at once. Showing the first 10 out of 136. Check the log or trigger a new build to see more.
@@ -174,6 +179,22 @@ namespace clad { | |||
/// otherwise returns false. | |||
bool HasAnyReferenceOrPointerArgument(const clang::FunctionDecl* FD); | |||
|
|||
/// Returns true if `constructedTypeName` is a string describing Kokkos::TeamPolicy type. | |||
bool IsKokkosTeamPolicy(const std::string constructedTypeName); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
warning: parameter 'constructedTypeName' is const-qualified in the function declaration; const-qualification of parameters only has an effect in function definitions [readability-avoid-const-params-in-decls]
bool IsKokkosTeamPolicy(const std::string constructedTypeName); | |
bool IsKokkosTeamPolicy(std::string constructedTypeName); |
|
||
/// Returns true if `constructedTypeName` is a string describing Kokkos::TeamThreadRange, | ||
/// Kokkos::ThreadVectorRange, or Kokkos::TeamVectorRange type. | ||
bool IsKokkosRange(const std::string constructedTypeName); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
warning: parameter 'constructedTypeName' is const-qualified in the function declaration; const-qualification of parameters only has an effect in function definitions [readability-avoid-const-params-in-decls]
bool IsKokkosRange(const std::string constructedTypeName); | |
bool IsKokkosRange(std::string constructedTypeName); |
bool IsKokkosRange(const std::string constructedTypeName); | ||
|
||
/// Returns true if `constructedTypeName` is a string describing Kokkos::Member type. | ||
bool IsKokkosMember(const std::string constructedTypeName); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
warning: parameter 'constructedTypeName' is const-qualified in the function declaration; const-qualification of parameters only has an effect in function definitions [readability-avoid-const-params-in-decls]
bool IsKokkosMember(const std::string constructedTypeName); | |
bool IsKokkosMember(std::string constructedTypeName); |
bool IsKokkosMember(const std::string constructedTypeName); | ||
|
||
/// Returns true if `constructedTypeName` is a string describing Kokkos::View type. | ||
bool IsKokkosView(const std::string constructedTypeName); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
warning: parameter 'constructedTypeName' is const-qualified in the function declaration; const-qualification of parameters only has an effect in function definitions [readability-avoid-const-params-in-decls]
bool IsKokkosView(const std::string constructedTypeName); | |
bool IsKokkosView(std::string constructedTypeName); |
#ifndef CLAD_KOKKOS_VIEW_ACCESS_VISITOR_H | ||
#define CLAD_KOKKOS_VIEW_ACCESS_VISITOR_H |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
warning: header guard does not follow preferred style [llvm-header-guard]
#ifndef CLAD_KOKKOS_VIEW_ACCESS_VISITOR_H | |
#define CLAD_KOKKOS_VIEW_ACCESS_VISITOR_H | |
#ifndef CLAD_DIFFERENTIATOR_KOKKOSVIEWACCESSVISITOR_H | |
#define CLAD_DIFFERENTIATOR_KOKKOSVIEWACCESSVISITOR_H |
include/clad/Differentiator/KokkosViewAccessVisitor.h:423:
- #endif // CLAD_KOKKOS_VIEW_ACCESS_VISITOR_H
+ #endif // CLAD_DIFFERENTIATOR_KOKKOSVIEWACCESSVISITOR_H
using namespace clang; | ||
|
||
if (!Stmt1 || !Stmt2) { | ||
return !Stmt1 && !Stmt2; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
warning: implicit conversion 'const clang::Stmt *' -> bool [readability-implicit-bool-conversion]
return !Stmt1 && !Stmt2; | |
return (Stmt1 == nullptr) && !Stmt2; |
using namespace clang; | ||
|
||
if (!Stmt1 || !Stmt2) { | ||
return !Stmt1 && !Stmt2; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
warning: implicit conversion 'const clang::Stmt *' -> bool [readability-implicit-bool-conversion]
return !Stmt1 && !Stmt2; | |
return !Stmt1 && (Stmt2 == nullptr); |
case Stmt::NullStmtClass: | ||
return true; | ||
case Stmt::CStyleCastExprClass: { | ||
const CStyleCastExpr* CastExpr1 = cast<CStyleCastExpr>(Stmt1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
warning: use auto when initializing with a template cast to avoid duplicating the type name [modernize-use-auto]
const CStyleCastExpr* CastExpr1 = cast<CStyleCastExpr>(Stmt1); | |
const auto* CastExpr1 = cast<CStyleCastExpr>(Stmt1); |
return true; | ||
case Stmt::CStyleCastExprClass: { | ||
const CStyleCastExpr* CastExpr1 = cast<CStyleCastExpr>(Stmt1); | ||
const CStyleCastExpr* CastExpr2 = cast<CStyleCastExpr>(Stmt2); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
warning: use auto when initializing with a template cast to avoid duplicating the type name [modernize-use-auto]
const CStyleCastExpr* CastExpr2 = cast<CStyleCastExpr>(Stmt2); | |
const auto* CastExpr2 = cast<CStyleCastExpr>(Stmt2); |
return CastExpr1->getTypeAsWritten() == CastExpr2->getTypeAsWritten(); | ||
} | ||
case Stmt::ReturnStmtClass: { | ||
const ReturnStmt *ReturnStmt1 = cast<ReturnStmt>(Stmt1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
warning: use auto when initializing with a template cast to avoid duplicating the type name [modernize-use-auto]
const ReturnStmt *ReturnStmt1 = cast<ReturnStmt>(Stmt1); | |
const auto *ReturnStmt1 = cast<ReturnStmt>(Stmt1); |
@@ -153,6 +153,11 @@ namespace clad { | |||
clang::DeclContext* GetOutermostDC(clang::Sema& semaRef, | |||
clang::DeclContext* DC); | |||
|
|||
clang::Expr* GetUnresolvedLookup(clang::Sema& semaRef, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ASTContext
can be obtained through Sema
. We don't need to pass both of them to a function.
@@ -174,6 +179,22 @@ namespace clad { | |||
/// otherwise returns false. | |||
bool HasAnyReferenceOrPointerArgument(const clang::FunctionDecl* FD); | |||
|
|||
/// Returns true if `constructedTypeName` is a string describing Kokkos::TeamPolicy type. | |||
bool IsKokkosTeamPolicy(const std::string constructedTypeName); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps kokkos
specific functions should be in a separate namespace altogether?
|
||
/// Returns true if `constructedTypeName` is a string describing Kokkos::TeamThreadRange, | ||
/// Kokkos::ThreadVectorRange, or Kokkos::TeamVectorRange type. | ||
bool IsKokkosRange(const std::string constructedTypeName); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should pass std::string
as const std::string&
instead of const std::string
. const
in parameters not being passed as reference is meaningless for the caller.
auto MCE = dyn_cast<clang::CXXMemberCallExpr>(CE); | ||
|
||
if (utils::IsKokkosView(MCE->getObjectType().getAsString())) { | ||
//Member function called from a Kokkos::View; nothing to do here |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For supporting things such as this, we should use custom derivatives instead of modifying the core Clad code. Modifying core clad is not a scalable solution.
return StmtDiff(Clone(CE)); | ||
} | ||
} | ||
if (isa<CXXOperatorCallExpr>(CE)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be implemented as custom derivative as well.
} | ||
|
||
// Returning the function call and zero derivative | ||
if (isKokkosViewAccess) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All these changes can be implemented with more consistency and much less efforts using the custom derivative functionality.
@@ -99,7 +100,9 @@ Expr* getArraySizeExpr(const ArrayType* AT, ASTContext& context, | |||
} | |||
|
|||
ReverseModeVisitor::ReverseModeVisitor(DerivativeBuilder& builder) | |||
: VisitorBase(builder), m_Result(nullptr) {} | |||
: VisitorBase(builder), m_Result(nullptr) { | |||
m_KVAV = new KokkosViewAccessVisitor(m_Sema, m_Context); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems that we are unconditionally creating and deleting m_KVAV
and we exactly know when to create and delete it. Why does m_KVAV
needs to be a pointer? Why cannot we have m_KVAV
as non-pointer instance member?
This commit adds a test from the original Kokkos PR vgvassilev#783 and provides the implementation of the simplest Kokkos features in the form of custom pushforwards. This commit only addresses the forward mode.
This commit adds a test from the original Kokkos PR vgvassilev#783 and provides the implementation of the simplest Kokkos features in the form of custom pushforwards. This commit only addresses the forward mode.
This commit adds a test from the original Kokkos PR vgvassilev#783 and provides the implementation of the simplest Kokkos features in the form of custom pushforwards. This commit only addresses the forward mode.
This commit adds a test from the original Kokkos PR vgvassilev#783 and provides the implementation of the simplest Kokkos features in the form of custom pushforwards. This commit only addresses the forward mode.
This commit adds a test from the original Kokkos PR vgvassilev#783 and provides the implementation of the simplest Kokkos features in the form of custom pushforwards. This commit only addresses the forward mode.
This commit adds a test from the original Kokkos PR vgvassilev#783 and provides the implementation of the simplest Kokkos features in the form of custom pushforwards. This commit only addresses the forward mode.
This commit adds a test from the original Kokkos PR vgvassilev#783 and provides the implementation of the simplest Kokkos features in the form of custom pushforwards. This commit only addresses the forward mode.
This commit adds a test from the original Kokkos PR vgvassilev#783 and provides the implementation of the simplest Kokkos features in the form of custom pushforwards. This commit only addresses the forward mode.
This commit adds a test from the original Kokkos PR vgvassilev#783 and provides the implementation of the simplest Kokkos features in the form of custom pushforwards. This commit only addresses the forward mode.
This commit adds a test from the original Kokkos PR vgvassilev#783 and provides the implementation of the simplest Kokkos features in the form of custom pushforwards. This commit only addresses the forward mode.
This commit adds a test from the original Kokkos PR vgvassilev#783 and provides the implementation of the simplest Kokkos features in the form of custom pushforwards. This commit only addresses the forward mode.
This commit adds a test from the original Kokkos PR vgvassilev#783 and provides the implementation of the simplest Kokkos features in the form of custom pushforwards. This commit only addresses the forward mode.
This commit adds a test from the original Kokkos PR vgvassilev#783 and provides the implementation of the simplest Kokkos features in the form of custom pushforwards. This commit only addresses the forward mode.
This commit adds a test from the original Kokkos PR vgvassilev#783 and provides the implementation of the simplest Kokkos features in the form of custom pushforwards. This commit only addresses the forward mode.
This commit adds a test from the original Kokkos PR #783 and provides the implementation of the simplest Kokkos features in the form of custom pushforwards. This commit only addresses the forward mode.
@kliegeois, @brian-kelley, is there a point to try to rebase this PR or @gojakuch should continue picking random things from it as it is now? |
@vgvassilev I am not sure what is best. |
This PR provides the implementation of a first set of features for the automatic generation of gradients of Kokkos-based code.
The content of this PR supports reverse mode of Kokkos
parallel_for
,deep_copy
, and view accesses.@vgvassilev @brian-kelley