Skip to content

Commit

Permalink
fix lambda capture and constraints
Browse files Browse the repository at this point in the history
  • Loading branch information
fnrizzi committed Aug 8, 2023
1 parent 61839dc commit 5742e3f
Show file tree
Hide file tree
Showing 10 changed files with 70 additions and 149 deletions.
54 changes: 22 additions & 32 deletions algorithms/src/std_algorithms/Kokkos_Unique.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#ifndef KOKKOS_STD_ALGORITHMS_UNIQUE_HPP
#define KOKKOS_STD_ALGORITHMS_UNIQUE_HPP

#include "./impl/Kokkos_IsRandomAccessIterator.hpp"
#include "impl/Kokkos_Unique.hpp"
#include "Kokkos_BeginEnd.hpp"

Expand All @@ -28,7 +27,7 @@ namespace Experimental {
// overload set1: default predicate, accepting execution space
//
template <class ExecutionSpace, class IteratorType>
std::enable_if_t<Impl::is_random_access_iterator_v<IteratorType>&& ::Kokkos::
std::enable_if_t<Impl::is_iterator_v<IteratorType> &&
is_execution_space<ExecutionSpace>::value,
IteratorType>
unique(const ExecutionSpace& ex, IteratorType first, IteratorType last) {
Expand All @@ -37,7 +36,7 @@ unique(const ExecutionSpace& ex, IteratorType first, IteratorType last) {
}

template <class ExecutionSpace, class IteratorType>
std::enable_if_t<Impl::is_random_access_iterator_v<IteratorType>&& ::Kokkos::
std::enable_if_t<Impl::is_iterator_v<IteratorType> &&
is_execution_space<ExecutionSpace>::value,
IteratorType>
unique(const std::string& label, const ExecutionSpace& ex, IteratorType first,
Expand All @@ -46,8 +45,7 @@ unique(const std::string& label, const ExecutionSpace& ex, IteratorType first,
}

template <class ExecutionSpace, class DataType, class... Properties,
std::enable_if_t<::Kokkos::is_execution_space<ExecutionSpace>::value,
int> = 0>
std::enable_if_t<is_execution_space<ExecutionSpace>::value, int> = 0>
auto unique(const ExecutionSpace& ex,
const ::Kokkos::View<DataType, Properties...>& view) {
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(view);
Expand All @@ -56,8 +54,7 @@ auto unique(const ExecutionSpace& ex,
}

template <class ExecutionSpace, class DataType, class... Properties,
std::enable_if_t<::Kokkos::is_execution_space<ExecutionSpace>::value,
int> = 0>
std::enable_if_t<is_execution_space<ExecutionSpace>::value, int> = 0>
auto unique(const std::string& label, const ExecutionSpace& ex,
const ::Kokkos::View<DataType, Properties...>& view) {
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(view);
Expand All @@ -68,26 +65,23 @@ auto unique(const std::string& label, const ExecutionSpace& ex,
// overload set2: custom predicate, accepting execution space
//
template <class ExecutionSpace, class IteratorType, class BinaryPredicate>
std::enable_if_t<::Kokkos::is_execution_space<ExecutionSpace>::value,
IteratorType>
std::enable_if_t<is_execution_space<ExecutionSpace>::value, IteratorType>
unique(const ExecutionSpace& ex, IteratorType first, IteratorType last,
BinaryPredicate pred) {
return Impl::unique_exespace_impl("Kokkos::unique_iterator_api_default", ex,
first, last, pred);
}

template <class ExecutionSpace, class IteratorType, class BinaryPredicate>
std::enable_if_t<::Kokkos::is_execution_space<ExecutionSpace>::value,
IteratorType>
std::enable_if_t<is_execution_space<ExecutionSpace>::value, IteratorType>
unique(const std::string& label, const ExecutionSpace& ex, IteratorType first,
IteratorType last, BinaryPredicate pred) {
return Impl::unique_exespace_impl(label, ex, first, last, pred);
}

template <class ExecutionSpace, class DataType, class... Properties,
class BinaryPredicate,
std::enable_if_t<::Kokkos::is_execution_space<ExecutionSpace>::value,
int> = 0>
std::enable_if_t<is_execution_space<ExecutionSpace>::value, int> = 0>
auto unique(const ExecutionSpace& ex,
const ::Kokkos::View<DataType, Properties...>& view,
BinaryPredicate pred) {
Expand All @@ -98,8 +92,7 @@ auto unique(const ExecutionSpace& ex,

template <class ExecutionSpace, class DataType, class... Properties,
class BinaryPredicate,
std::enable_if_t<::Kokkos::is_execution_space<ExecutionSpace>::value,
int> = 0>
std::enable_if_t<is_execution_space<ExecutionSpace>::value, int> = 0>
auto unique(const std::string& label, const ExecutionSpace& ex,
const ::Kokkos::View<DataType, Properties...>& view,
BinaryPredicate pred) {
Expand All @@ -114,18 +107,16 @@ auto unique(const std::string& label, const ExecutionSpace& ex,
// since they cause issues on device because of the string allocation.
//
template <class TeamHandleType, class IteratorType>
KOKKOS_FUNCTION
std::enable_if_t<Impl::is_random_access_iterator_v<IteratorType>&& ::
Kokkos::is_team_handle<TeamHandleType>::value,
IteratorType>
unique(const TeamHandleType& teamHandle, IteratorType first,
IteratorType last) {
KOKKOS_FUNCTION std::enable_if_t<
Impl::is_iterator_v<IteratorType>&& ::is_team_handle<TeamHandleType>::value,
IteratorType>
unique(const TeamHandleType& teamHandle, IteratorType first,
IteratorType last) {
return Impl::unique_team_impl(teamHandle, first, last);
}

template <
class TeamHandleType, class DataType, class... Properties,
std::enable_if_t<::Kokkos::is_team_handle<TeamHandleType>::value, int> = 0>
template <class TeamHandleType, class DataType, class... Properties,
std::enable_if_t<is_team_handle<TeamHandleType>::value, int> = 0>
KOKKOS_FUNCTION auto unique(
const TeamHandleType& teamHandle,
const ::Kokkos::View<DataType, Properties...>& view) {
Expand All @@ -138,17 +129,16 @@ KOKKOS_FUNCTION auto unique(
// since they cause issues on device because of the string allocation.
//
template <class TeamHandleType, class IteratorType, class BinaryPredicate>
KOKKOS_FUNCTION std::enable_if_t<
::Kokkos::is_team_handle<TeamHandleType>::value, IteratorType>
unique(const TeamHandleType& teamHandle, IteratorType first, IteratorType last,
BinaryPredicate pred) {
KOKKOS_FUNCTION
std::enable_if_t<is_team_handle<TeamHandleType>::value, IteratorType>
unique(const TeamHandleType& teamHandle, IteratorType first,
IteratorType last, BinaryPredicate pred) {
return Impl::unique_team_impl(teamHandle, first, last, std::move(pred));
}

template <
class TeamHandleType, class DataType, class... Properties,
class BinaryPredicate,
std::enable_if_t<::Kokkos::is_team_handle<TeamHandleType>::value, int> = 0>
template <class TeamHandleType, class DataType, class... Properties,
class BinaryPredicate,
std::enable_if_t<is_team_handle<TeamHandleType>::value, int> = 0>
KOKKOS_FUNCTION auto unique(const TeamHandleType& teamHandle,
const ::Kokkos::View<DataType, Properties...>& view,
BinaryPredicate pred) {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ struct TestFunctorA {
auto it = KE::adjacent_difference(member, KE::cbegin(myRowViewFrom),
KE::cend(myRowViewFrom),
KE::begin(myRowViewDest));
Kokkos::single(Kokkos::PerTeam(member), [=]() {
Kokkos::single(Kokkos::PerTeam(member), [=, *this]() {
m_distancesView(myRowIndex) =
KE::distance(KE::begin(myRowViewDest), it);
});
Expand All @@ -72,7 +72,7 @@ struct TestFunctorA {
auto it = KE::adjacent_difference(member, KE::cbegin(myRowViewFrom),
KE::cend(myRowViewFrom),
KE::begin(myRowViewDest), m_binaryOp);
Kokkos::single(Kokkos::PerTeam(member), [=]() {
Kokkos::single(Kokkos::PerTeam(member), [=, *this]() {
m_distancesView(myRowIndex) =
KE::distance(KE::begin(myRowViewDest), it);
});
Expand All @@ -81,7 +81,7 @@ struct TestFunctorA {

case 2: {
auto it = KE::adjacent_difference(member, myRowViewFrom, myRowViewDest);
Kokkos::single(Kokkos::PerTeam(member), [=]() {
Kokkos::single(Kokkos::PerTeam(member), [=, *this]() {
m_distancesView(myRowIndex) =
KE::distance(KE::begin(myRowViewDest), it);
});
Expand All @@ -91,7 +91,7 @@ struct TestFunctorA {
case 3: {
auto it = KE::adjacent_difference(member, myRowViewFrom, myRowViewDest,
m_binaryOp);
Kokkos::single(Kokkos::PerTeam(member), [=]() {
Kokkos::single(Kokkos::PerTeam(member), [=, *this]() {
m_distancesView(myRowIndex) =
KE::distance(KE::begin(myRowViewDest), it);
});
Expand Down
8 changes: 4 additions & 4 deletions algorithms/unit_tests/TestStdAlgorithmsTeamExclusiveScan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ struct TestFunctorA {
auto it = KE::exclusive_scan(member, KE::cbegin(rowViewSrc),
KE::cend(rowViewSrc),
KE::begin(rowViewDest), initVal);
Kokkos::single(Kokkos::PerTeam(member), [=] {
Kokkos::single(Kokkos::PerTeam(member), [=, *this] {
m_distancesView(rowIndex) = KE::distance(KE::begin(rowViewDest), it);
});

Expand All @@ -74,7 +74,7 @@ struct TestFunctorA {

case 1: {
auto it = KE::exclusive_scan(member, rowViewSrc, rowViewDest, initVal);
Kokkos::single(Kokkos::PerTeam(member), [=] {
Kokkos::single(Kokkos::PerTeam(member), [=, *this] {
m_distancesView(rowIndex) = KE::distance(KE::begin(rowViewDest), it);
});

Expand All @@ -87,7 +87,7 @@ struct TestFunctorA {
auto it = KE::exclusive_scan(
member, KE::cbegin(rowViewSrc), KE::cend(rowViewSrc),
KE::begin(rowViewDest), initVal, m_binaryOp);
Kokkos::single(Kokkos::PerTeam(member), [=] {
Kokkos::single(Kokkos::PerTeam(member), [=, *this] {
m_distancesView(rowIndex) = KE::distance(KE::begin(rowViewDest), it);
});

Expand All @@ -97,7 +97,7 @@ struct TestFunctorA {
case 3: {
auto it = KE::exclusive_scan(member, rowViewSrc, rowViewDest, initVal,
m_binaryOp);
Kokkos::single(Kokkos::PerTeam(member), [=] {
Kokkos::single(Kokkos::PerTeam(member), [=, *this] {
m_distancesView(rowIndex) = KE::distance(KE::begin(rowViewDest), it);
});

Expand Down
12 changes: 6 additions & 6 deletions algorithms/unit_tests/TestStdAlgorithmsTeamInclusiveScan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ struct TestFunctorA {
switch (m_apiPick) {
case 0: {
auto it = KE::inclusive_scan(member, first, last, firstDest);
Kokkos::single(Kokkos::PerTeam(member), [=] {
Kokkos::single(Kokkos::PerTeam(member), [=, *this] {
m_distancesView(rowIndex) = KE::distance(firstDest, it);
});

Expand All @@ -77,7 +77,7 @@ struct TestFunctorA {

case 1: {
auto it = KE::inclusive_scan(member, srcRow, destRow);
Kokkos::single(Kokkos::PerTeam(member), [=] {
Kokkos::single(Kokkos::PerTeam(member), [=, *this] {
m_distancesView(rowIndex) = KE::distance(firstDest, it);
});

Expand All @@ -87,7 +87,7 @@ struct TestFunctorA {
case 2: {
auto it =
KE::inclusive_scan(member, first, last, firstDest, m_binaryOp);
Kokkos::single(Kokkos::PerTeam(member), [=] {
Kokkos::single(Kokkos::PerTeam(member), [=, *this] {
m_distancesView(rowIndex) = KE::distance(firstDest, it);
});

Expand All @@ -96,7 +96,7 @@ struct TestFunctorA {

case 3: {
auto it = KE::inclusive_scan(member, srcRow, destRow, m_binaryOp);
Kokkos::single(Kokkos::PerTeam(member), [=] {
Kokkos::single(Kokkos::PerTeam(member), [=, *this] {
m_distancesView(rowIndex) = KE::distance(firstDest, it);
});

Expand All @@ -106,7 +106,7 @@ struct TestFunctorA {
case 4: {
auto it = KE::inclusive_scan(member, first, last, firstDest, m_binaryOp,
initVal);
Kokkos::single(Kokkos::PerTeam(member), [=] {
Kokkos::single(Kokkos::PerTeam(member), [=, *this] {
m_distancesView(rowIndex) = KE::distance(firstDest, it);
});

Expand All @@ -116,7 +116,7 @@ struct TestFunctorA {
case 5: {
auto it =
KE::inclusive_scan(member, srcRow, destRow, m_binaryOp, initVal);
Kokkos::single(Kokkos::PerTeam(member), [=] {
Kokkos::single(Kokkos::PerTeam(member), [=, *this] {
m_distancesView(rowIndex) = KE::distance(firstDest, it);
});

Expand Down

0 comments on commit 5742e3f

Please sign in to comment.