kokkos-execution 0.0.1
Loading...
Searching...
No Matches
kokkos.hpp
Go to the documentation of this file.
1#ifndef KOKKOS_EXECUTION_TESTS_UTILS_KOKKOS_HPP
2#define KOKKOS_EXECUTION_TESTS_UTILS_KOKKOS_HPP
3
4#include <concepts>
5#include <iostream>
6#include <string_view>
7
8#include "Kokkos_Macros.hpp"
9#ifdef KOKKOS_ENABLE_EXPERIMENTAL_CXX20_MODULES
10import kokkos.core;
11#else
12# include "Kokkos_Core.hpp"
13#endif
14
15namespace Tests::Utils {
16
17template <Kokkos::ExecutionSpace Exec, Kokkos::ExecutionSpace OtherExec>
18bool are_same_instances(const Exec& exec, const OtherExec& other_exec) {
19 if constexpr (std::same_as<Exec, OtherExec>) {
20 return exec == other_exec;
21 } else {
22 return false;
23 }
24}
25
26template <Kokkos::ExecutionSpace Exec>
27constexpr bool on_device() {
28#if defined(KOKKOS_ENABLE_CUDA)
29 return std::same_as<Exec, Kokkos::Cuda>;
30#elif defined(KOKKOS_ENABLE_HIP)
31 return std::same_as<Exec, Kokkos::HIP>;
32#else
33 return false;
34#endif
35}
36
37template <Kokkos::ExecutionSpace Exec>
38void show_exec_space_id(const Exec& exec, std::string_view label = "", std::ostream& out = std::cout) {
39 out << "Execution space instance " << label << " has device ID " << Kokkos::Tools::Experimental::device_id(exec)
40 << '.' << std::endl;
41}
42
44template <typename ViewType>
45requires(ViewType::rank() == 1)
46auto span_from(const ViewType& view) noexcept {
47 return std::span{view.data(), view.size()};
48}
49
50} // namespace Tests::Utils
51
52#endif // KOKKOS_EXECUTION_TESTS_UTILS_KOKKOS_HPP
void show_exec_space_id(const Exec &exec, std::string_view label="", std::ostream &out=std::cout)
Definition kokkos.hpp:38
auto span_from(const ViewType &view) noexcept
Get a std::span from a rank-one Kokkos::View.
Definition kokkos.hpp:46
constexpr bool on_device()
Definition kokkos.hpp:27
bool are_same_instances(const Exec &exec, const OtherExec &other_exec)
Definition kokkos.hpp:18