Skip to content

Commit

Permalink
Add Kokkos::num_threads() and Kokkos::device_id()
Browse files Browse the repository at this point in the history
  • Loading branch information
dalg24 committed Feb 3, 2023
1 parent 2aa2576 commit a4af6f7
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
3 changes: 3 additions & 0 deletions core/src/Kokkos_Core.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ void declare_configuration_metadata(const std::string& category,
[[nodiscard]] bool is_initialized() noexcept;
[[nodiscard]] bool is_finalized() noexcept;

[[nodiscard]] int device_id() noexcept;
[[nodiscard]] int num_threads() noexcept;

bool show_warnings() noexcept;
bool tune_internals() noexcept;

Expand Down
20 changes: 20 additions & 0 deletions core/src/impl/Kokkos_Core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,26 @@ bool is_valid_map_device_id_by(std::string const& x) {

} // namespace

[[nodiscard]] int Kokkos::device_id() noexcept {
#if defined(KOKKOS_ENABLE_CUDA)
return Cuda().cuda_device();
#elif defined(KOKKOS_ENABLE_HIP)
return HIP().hip_device();
#elif defined(KOKKOS_ENABLE_OPENACC)
return Experimental::OpenACC().acc_device_number();
#elif defined(KOKKOS_ENABLE_OPENMPTARGET)
return omp_get_default_device(); // FIXME_OPENMPTARGET
#elif defined(KOKKOS_ENABLE_SYCL)
return Experimental::Impl::SYCLInternal::m_syclDev;
#else
return -1;
#endif
}

[[nodiscard]] int Kokkos::num_threads() noexcept {
return DefaultHostExecutionSpace().concurrency();
}

Kokkos::Impl::ExecSpaceManager& Kokkos::Impl::ExecSpaceManager::get_instance() {
static ExecSpaceManager space_initializer = {};
return space_initializer;
Expand Down

0 comments on commit a4af6f7

Please sign in to comment.