Skip to content

Commit

Permalink
Rename Kokkos_ThreadsExec to align with the other backends
Browse files Browse the repository at this point in the history
  • Loading branch information
Rombur committed Oct 12, 2023
1 parent bc83a89 commit 6ff5721
Show file tree
Hide file tree
Showing 14 changed files with 317 additions and 292 deletions.
4 changes: 2 additions & 2 deletions Makefile.targets
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ Lock_Array_HIP.o: $(KOKKOS_CPP_DEPENDS) $(KOKKOS_PATH)/tpls/desul/src/Lock_Array
endif

ifeq ($(KOKKOS_INTERNAL_USE_THREADS), 1)
Kokkos_ThreadsExec.o: $(KOKKOS_CPP_DEPENDS) $(KOKKOS_PATH)/core/src/Threads/Kokkos_ThreadsExec.cpp
$(CXX) $(KOKKOS_CPPFLAGS) $(KOKKOS_CXXFLAGS) $(CXXFLAGS) -c $(KOKKOS_PATH)/core/src/Threads/Kokkos_ThreadsExec.cpp
Kokkos_Threads_Instance.o: $(KOKKOS_CPP_DEPENDS) $(KOKKOS_PATH)/core/src/Threads/Kokkos_Threads_Instance.cpp
$(CXX) $(KOKKOS_CPPFLAGS) $(KOKKOS_CXXFLAGS) $(CXXFLAGS) -c $(KOKKOS_PATH)/core/src/Threads/Kokkos_Threads_Instance.cpp
endif

ifeq ($(KOKKOS_INTERNAL_USE_OPENMP), 1)
Expand Down
2 changes: 1 addition & 1 deletion core/src/Threads/Kokkos_Threads.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ static_assert(false,

namespace Kokkos {
namespace Impl {
class ThreadsExec;
class ThreadsInternal;
enum class fence_is_static { yes, no };
} // namespace Impl
} // namespace Kokkos
Expand Down
55 changes: 29 additions & 26 deletions core/src/Threads/Kokkos_ThreadsTeam.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ class ThreadsExecTeamMember {

private:
using space = execution_space::scratch_memory_space;
ThreadsExec* const m_exec;
ThreadsExec* const* m_team_base; ///< Base for team fan-in
ThreadsInternal* const m_instance;
ThreadsInternal* const* m_team_base; ///< Base for team fan-in
space m_team_shared;
size_t m_team_shared_size;
int m_team_size;
Expand Down Expand Up @@ -85,13 +85,14 @@ class ThreadsExecTeamMember {
(!(m_team_rank_rev & n)) && ((j = m_team_rank_rev + n) < m_team_size);
n <<= 1) {
Impl::spinwait_while_equal<int>(m_team_base[j]->state(),
ThreadsExec::Active);
ThreadsInternal::Active);
}

// If not root then wait for release
if (m_team_rank_rev) {
m_exec->state() = ThreadsExec::Rendezvous;
Impl::spinwait_while_equal<int>(m_exec->state(), ThreadsExec::Rendezvous);
m_instance->state() = ThreadsInternal::Rendezvous;
Impl::spinwait_while_equal<int>(m_instance->state(),
ThreadsInternal::Rendezvous);
}

return !m_team_rank_rev;
Expand All @@ -102,7 +103,7 @@ class ThreadsExecTeamMember {
for (n = 1;
(!(m_team_rank_rev & n)) && ((j = m_team_rank_rev + n) < m_team_size);
n <<= 1) {
m_team_base[j]->state() = ThreadsExec::Active;
m_team_base[j]->state() = ThreadsInternal::Active;
}
}

Expand Down Expand Up @@ -188,10 +189,10 @@ class ThreadsExecTeamMember {
using type =
typename if_c<sizeof(Type) < TEAM_REDUCE_SIZE, Type, void>::type;

if (nullptr == m_exec) return value;
if (m_instance == nullptr) return value;

if (team_rank() != team_size() - 1) *
((volatile type*)m_exec->scratch_memory()) = value;
((volatile type*)m_instance->scratch_memory()) = value;

memory_fence();

Expand Down Expand Up @@ -229,9 +230,9 @@ class ThreadsExecTeamMember {
using type = typename if_c<sizeof(value_type) < TEAM_REDUCE_SIZE,
value_type, void>::type;

if (nullptr == m_exec) return;
if (m_instance == nullptr) return;

type* const local_value = ((type*)m_exec->scratch_memory());
type* const local_value = ((type*)m_instance->scratch_memory());

// Set this thread's contribution
if (team_rank() != team_size() - 1) { *local_value = contribution; }
Expand Down Expand Up @@ -285,9 +286,9 @@ class ThreadsExecTeamMember {
using type = typename if_c<sizeof(ArgType) < TEAM_REDUCE_SIZE, ArgType,
void>::type;

if (nullptr == m_exec) return type(0);
if (m_instance == nullptr) return type(0);

volatile type* const work_value = ((type*)m_exec->scratch_memory());
volatile type* const work_value = ((type*)m_instance->scratch_memory());

*work_value = value;

Expand Down Expand Up @@ -342,10 +343,10 @@ class ThreadsExecTeamMember {

template <class... Properties>
ThreadsExecTeamMember(
Impl::ThreadsExec* exec,
Impl::ThreadsInternal* instance,
const TeamPolicyInternal<Kokkos::Threads, Properties...>& team,
const size_t shared_size)
: m_exec(exec),
: m_instance(instance),
m_team_base(nullptr),
m_team_shared(nullptr, 0),
m_team_shared_size(shared_size),
Expand All @@ -361,9 +362,11 @@ class ThreadsExecTeamMember {
if (team.league_size()) {
// Execution is using device-team interface:

const int pool_rank_rev = m_exec->pool_size() - (m_exec->pool_rank() + 1);
const int pool_rank_rev =
m_instance->pool_size() - (m_instance->pool_rank() + 1);
const int team_rank_rev = pool_rank_rev % team.team_alloc();
const size_t pool_league_size = m_exec->pool_size() / team.team_alloc();
const size_t pool_league_size =
m_instance->pool_size() / team.team_alloc();
const size_t pool_league_rank_rev = pool_rank_rev / team.team_alloc();
if (pool_league_rank_rev >= pool_league_size) {
m_invalid_thread = 1;
Expand All @@ -372,7 +375,7 @@ class ThreadsExecTeamMember {
const size_t pool_league_rank =
pool_league_size - (pool_league_rank_rev + 1);

const int pool_num_teams = m_exec->pool_size() / team.team_alloc();
const int pool_num_teams = m_instance->pool_size() / team.team_alloc();
const int chunk_size =
team.chunk_size() > 0 ? team.chunk_size() : team.team_iter();
const int chunks_per_team =
Expand All @@ -387,8 +390,8 @@ class ThreadsExecTeamMember {

if ((team.team_alloc() > size_t(m_team_size))
? (team_rank_rev >= m_team_size)
: (m_exec->pool_size() - pool_num_teams * m_team_size >
m_exec->pool_rank()))
: (m_instance->pool_size() - pool_num_teams * m_team_size >
m_instance->pool_rank()))
m_invalid_thread = 1;
else
m_invalid_thread = 0;
Expand All @@ -398,7 +401,7 @@ class ThreadsExecTeamMember {

if (team_rank_rev < team.team_size() && !m_invalid_thread) {
m_team_base =
m_exec->pool_base() + team.team_alloc() * pool_league_rank_rev;
m_instance->pool_base() + team.team_alloc() * pool_league_rank_rev;
m_team_size = team.team_size();
m_team_rank = team.team_size() - (team_rank_rev + 1);
m_team_rank_rev = team_rank_rev;
Expand All @@ -413,21 +416,21 @@ class ThreadsExecTeamMember {
}

if ((m_team_rank_rev == 0) && (m_invalid_thread == 0)) {
m_exec->set_work_range(m_league_rank, m_league_end, m_chunk_size);
m_exec->reset_steal_target(m_team_size);
m_instance->set_work_range(m_league_rank, m_league_end, m_chunk_size);
m_instance->reset_steal_target(m_team_size);
}
if (std::is_same<typename TeamPolicyInternal<
Kokkos::Threads, Properties...>::schedule_type::type,
Kokkos::Dynamic>::value) {
m_exec->barrier();
m_instance->barrier();
}
} else {
m_invalid_thread = 1;
}
}

ThreadsExecTeamMember()
: m_exec(nullptr),
: m_instance(nullptr),
m_team_base(nullptr),
m_team_shared(nullptr, 0),
m_team_shared_size(0),
Expand All @@ -442,8 +445,8 @@ class ThreadsExecTeamMember {
m_invalid_thread(0),
m_team_alloc(0) {}

inline ThreadsExec& threads_exec_team_base() const {
return m_team_base ? **m_team_base : *m_exec;
inline ThreadsInternal& threads_exec_team_base() const {
return m_team_base ? **m_team_base : *m_instance;
}

bool valid_static() const { return m_league_rank < m_league_end; }
Expand Down

0 comments on commit 6ff5721

Please sign in to comment.