-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#9: rename inverse to reciprocal; add kokkos ops
- Loading branch information
Showing
10 changed files
with
247 additions
and
13 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,88 @@ | ||
/* | ||
//@HEADER | ||
// ************************************************************************ | ||
// | ||
// ops_elementwise_multiply.hpp | ||
// Pressio | ||
// Copyright 2019 | ||
// National Technology & Engineering Solutions of Sandia, LLC (NTESS) | ||
// | ||
// Under the terms of Contract DE-NA0003525 with NTESS, the | ||
// U.S. Government retains certain rights in this software. | ||
// | ||
// Pressio is licensed under BSD-3-Clause terms of use: | ||
// | ||
// Redistribution and use in source and binary forms, with or without | ||
// modification, are permitted provided that the following conditions | ||
// are met: | ||
// | ||
// 1. Redistributions of source code must retain the above copyright | ||
// notice, this list of conditions and the following disclaimer. | ||
// | ||
// 2. Redistributions in binary form must reproduce the above copyright | ||
// notice, this list of conditions and the following disclaimer in the | ||
// documentation and/or other materials provided with the distribution. | ||
// | ||
// 3. Neither the name of the copyright holder nor the names of its | ||
// contributors may be used to endorse or promote products derived | ||
// from this software without specific prior written permission. | ||
// | ||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | ||
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | ||
// COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | ||
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING | ||
// IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
// POSSIBILITY OF SUCH DAMAGE. | ||
// | ||
// Questions? Contact Francesco Rizzi ([email protected]) | ||
// | ||
// ************************************************************************ | ||
//@HEADER | ||
*/ | ||
|
||
#ifndef PRESSIOOPS_OPS_KOKKOS_OPS_ELEMENTWISE_RECIPROCAL_HPP_ | ||
#define PRESSIOOPS_OPS_KOKKOS_OPS_ELEMENTWISE_RECIPROCAL_HPP_ | ||
|
||
#include "ops_vector_reciprocal_kokkos_functor.hpp" | ||
|
||
namespace pressio{ namespace ops{ | ||
|
||
//---------------------------------------------------------------------- | ||
// computing elementwise: y = 1/z | ||
//---------------------------------------------------------------------- | ||
template <typename T1, typename T2> | ||
std::enable_if_t< | ||
// common elementwise_multiply constraints | ||
::pressio::Traits<T1>::rank == 1 | ||
&& ::pressio::Traits<T2>::rank == 1 | ||
// TPL/container specific | ||
&& (::pressio::is_native_container_kokkos<T1>::value | ||
|| ::pressio::is_expression_acting_on_kokkos<T1>::value) | ||
&& (::pressio::is_native_container_kokkos<T2>::value | ||
|| ::pressio::is_expression_acting_on_kokkos<T2>::value) | ||
// scalar compatibility | ||
&& ::pressio::all_have_traits_and_same_scalar<T1, T2>::value | ||
&& (std::is_floating_point<typename ::pressio::Traits<T1>::scalar_type>::value | ||
|| std::is_integral<typename ::pressio::Traits<T1>::scalar_type>::value) | ||
> | ||
elementwise_reciprocal(const T1 & z, T2 & y) | ||
{ | ||
assert(z.extent(0) == y.extent(0)); | ||
|
||
using t1_t = typename impl::NativeType<T1>::type; | ||
using t2_t = typename impl::NativeType<T2>::type; | ||
using scalar_t = typename ::pressio::Traits<T1>::scalar_type; | ||
|
||
using fnctr_t = ::pressio::ops::impl::VectorReciprocalFunctor<t1_t,t2_t,scalar_t>; | ||
fnctr_t F(impl::get_native(z), impl::get_native(y)); | ||
Kokkos::parallel_for(z.extent(0), F); | ||
} | ||
|
||
}}//end namespace pressio::ops | ||
#endif // PRESSIOOPS_OPS_KOKKOS_OPS_ELEMENTWISE_RECIPROCAL_HPP_ |
69 changes: 69 additions & 0 deletions
69
include/pressio/ops/kokkos/ops_vector_reciprocal_kokkos_functor.hpp
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,69 @@ | ||
/* | ||
//@HEADER | ||
// ************************************************************************ | ||
// | ||
// ops_vector_update_kokkos_functors.hpp | ||
// Pressio | ||
// Copyright 2019 | ||
// National Technology & Engineering Solutions of Sandia, LLC (NTESS) | ||
// | ||
// Under the terms of Contract DE-NA0003525 with NTESS, the | ||
// U.S. Government retains certain rights in this software. | ||
// | ||
// Pressio is licensed under BSD-3-Clause terms of use: | ||
// | ||
// Redistribution and use in source and binary forms, with or without | ||
// modification, are permitted provided that the following conditions | ||
// are met: | ||
// | ||
// 1. Redistributions of source code must retain the above copyright | ||
// notice, this list of conditions and the following disclaimer. | ||
// | ||
// 2. Redistributions in binary form must reproduce the above copyright | ||
// notice, this list of conditions and the following disclaimer in the | ||
// documentation and/or other materials provided with the distribution. | ||
// | ||
// 3. Neither the name of the copyright holder nor the names of its | ||
// contributors may be used to endorse or promote products derived | ||
// from this software without specific prior written permission. | ||
// | ||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | ||
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | ||
// COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | ||
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING | ||
// IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
// POSSIBILITY OF SUCH DAMAGE. | ||
// | ||
// Questions? Contact Francesco Rizzi ([email protected]) | ||
// | ||
// ************************************************************************ | ||
//@HEADER | ||
*/ | ||
|
||
#ifndef PRESSIOOPS_OPS_KOKKOS_OPS_VECTOR_RECIPROCAL_KOKKOS_FUNCTOR_HPP_ | ||
#define PRESSIOOPS_OPS_KOKKOS_OPS_VECTOR_RECIPROCAL_KOKKOS_FUNCTOR_HPP_ | ||
|
||
namespace pressio{ namespace ops{ namespace impl{ | ||
|
||
template <class T1, class T2, class sc_t> | ||
struct VectorReciprocalFunctor { | ||
T1 z_; | ||
T2 y_; | ||
|
||
VectorReciprocalFunctor(T1 z, T2 y) : z_(z), y_(y) {} | ||
|
||
KOKKOS_INLINE_FUNCTION | ||
void operator()(const int i) const { | ||
y_(i) = static_cast<sc_t>(1) / z_(i); | ||
} | ||
}; | ||
|
||
|
||
}}}//end namespace pressio::ops::impl | ||
#endif // PRESSIOOPS_OPS_KOKKOS_OPS_VECTOR_RECIPROCAL_KOKKOS_FUNCTOR_HPP_ |
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
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