-
Notifications
You must be signed in to change notification settings - Fork 579
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge Pull Request #10913 from rppawlo/Trilinos/phalanx-fix-cuda-warn…
…ings Automatically Merged using Trilinos Pull Request AutoTester PR Title: Phalanx: remove cuda compiler warnings and add test for new use case PR Author: rppawlo
- Loading branch information
Showing
3 changed files
with
122 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
#include "Kokkos_Core.hpp" | ||
#include "Kokkos_View.hpp" | ||
|
||
#include "Teuchos_Assert.hpp" | ||
#include "Teuchos_UnitTestHarness.hpp" | ||
#include "Phalanx_KokkosViewOfViews.hpp" | ||
|
||
template<typename T,int dim> | ||
class Vector { | ||
T values_[dim]; | ||
public: | ||
|
||
template<typename INDEX_I> | ||
KOKKOS_INLINE_FUNCTION | ||
T& operator[](const INDEX_I& index){return values_[index];} | ||
|
||
template<typename INDEX_I> | ||
KOKKOS_INLINE_FUNCTION | ||
const T& operator[](const INDEX_I& index)const{return values_[index];} | ||
|
||
template<typename INDEX_I> | ||
KOKKOS_INLINE_FUNCTION | ||
volatile T& operator[](const INDEX_I& index)volatile{return values_[index];} | ||
|
||
template<typename INDEX_I> | ||
KOKKOS_INLINE_FUNCTION | ||
const volatile T& operator[](const INDEX_I& index)const volatile{return values_[index];} | ||
}; | ||
|
||
class MyClass { | ||
Kokkos::View<double*> a_; | ||
double b_[3]; | ||
Kokkos::View<double*> c_; | ||
Vector<double,3> d_; | ||
// To test for cuda warnings when MyClass is lambda captured to | ||
// device | ||
PHX::ViewOfViews3<1,Kokkos::View<double*>> e_; | ||
|
||
public: | ||
MyClass() : | ||
a_("a",3), | ||
c_("c",3) | ||
{ | ||
Kokkos::deep_copy(a_,1.0); | ||
b_[0] = 1.0; | ||
b_[1] = 2.0; | ||
b_[2] = 3.0; | ||
Kokkos::deep_copy(c_,2.0); | ||
d_[0] = 1.0; | ||
d_[1] = 2.0; | ||
d_[2] = 3.0; | ||
} | ||
|
||
void KOKKOS_FUNCTION checkInternalMethod1() const | ||
{ this->callInternalMethod1(); } | ||
|
||
void KOKKOS_FUNCTION | ||
callInternalMethod1() const | ||
{ | ||
printf("b_[0]=%f\n",b_[0]); | ||
printf("b_[1]=%f\n",b_[1]); | ||
printf("b_[2]=%f\n",b_[2]); | ||
a_(0)=b_[0]; | ||
a_(1)=b_[1]; | ||
a_(2)=b_[2]; | ||
} | ||
|
||
void KOKKOS_FUNCTION checkInternalMethod2() const | ||
{ this->callInternalMethod2(); } | ||
|
||
void KOKKOS_FUNCTION | ||
callInternalMethod2() const | ||
{ | ||
a_(0)=c_(0); | ||
a_(1)=c_(1); | ||
a_(2)=c_(2); | ||
} | ||
|
||
void KOKKOS_FUNCTION checkInternalMethod3() const | ||
{ this->callInternalMethod3(); } | ||
|
||
void KOKKOS_FUNCTION | ||
callInternalMethod3() const | ||
{ | ||
a_(0)=d_[0]; | ||
a_(1)=d_[1]; | ||
a_(2)=d_[2]; | ||
} | ||
}; | ||
|
||
TEUCHOS_UNIT_TEST(KokkosClassOnDevice, One) | ||
{ | ||
MyClass my_class; | ||
|
||
Kokkos::parallel_for("test 1",1,KOKKOS_LAMBDA (const int ) { | ||
my_class.checkInternalMethod1(); | ||
}); | ||
|
||
Kokkos::parallel_for("test 2",1,KOKKOS_LAMBDA (const int ) { | ||
my_class.checkInternalMethod2(); | ||
}); | ||
|
||
Kokkos::parallel_for("test 3",1,KOKKOS_LAMBDA (const int ) { | ||
my_class.checkInternalMethod3(); | ||
}); | ||
|
||
Kokkos::fence(); | ||
} |