|
| 1 | +#ifndef KOKKOSTOOLS_COMMON_SPACEHANDLE_HPP |
| 2 | +#define KOKKOSTOOLS_COMMON_SPACEHANDLE_HPP |
| 3 | + |
| 4 | +#include "impl/Kokkos_Profiling_C_Interface.h" |
| 5 | + |
| 6 | +#include <ostream> |
| 7 | +#include <string> |
| 8 | + |
| 9 | +namespace KokkosTools |
| 10 | +{ |
| 11 | +//! A @c Kokkos space type has a unique name. |
| 12 | +using SpaceHandle = Kokkos_Profiling_SpaceHandle; |
| 13 | + |
| 14 | +//! Supported @c Kokkos spaces. |
| 15 | +enum Space { |
| 16 | + HOST = 0, |
| 17 | + CUDA = 1, |
| 18 | + HIP = 2, |
| 19 | + SYCL = 3, |
| 20 | + OMPT = 4 |
| 21 | +}; |
| 22 | + |
| 23 | +//! Number of supported spaces (size of @ref Space). |
| 24 | +constexpr size_t NSPACES = 5; |
| 25 | + |
| 26 | +//! Get @ref Space from @ref SpaceHandle. |
| 27 | +Space get_space(SpaceHandle const& handle) |
| 28 | +{ |
| 29 | + switch(handle.name[0]) |
| 30 | + { |
| 31 | + // Only 'CUDA' space starts with 'C'. |
| 32 | + case 'C': |
| 33 | + return Space::CUDA; |
| 34 | + // Only 'SYCL' space starts with 'S'. |
| 35 | + case 'S': |
| 36 | + return Space::SYCL; |
| 37 | + // Only 'OpenMPTarget' starts with 'O'. |
| 38 | + case 'O': |
| 39 | + return Space::OMPT; |
| 40 | + // Otherwise, it's either 'HIP' or 'HOST'. |
| 41 | + case 'H': |
| 42 | + if(handle.name[1] == 'I') return Space::HIP; |
| 43 | + else return Space::HOST; |
| 44 | + default: |
| 45 | + std::abort(); |
| 46 | + } |
| 47 | +} |
| 48 | + |
| 49 | +//! Get the name of a @ref Space. |
| 50 | +const char* get_space_name(const Space space) { |
| 51 | + switch (space) { |
| 52 | + case Space::HOST: return "HOST"; |
| 53 | + case Space::CUDA: return "CUDA"; |
| 54 | + case Space::SYCL: return "SYCL"; |
| 55 | + case Space::OMPT: return "OpenMPTarget"; |
| 56 | + case Space::HIP : return "HIP"; |
| 57 | + } |
| 58 | + std::abort(); |
| 59 | +} |
| 60 | + |
| 61 | +std::ostream& operator<<(std::ostream& out, const Space space) { |
| 62 | + return out << get_space_name(space); |
| 63 | +} |
| 64 | + |
| 65 | +} // namespace KokkosTools |
| 66 | + |
| 67 | +#endif // KOKKOSTOOLS_COMMON_SPACEHANDLE_HPP |
0 commit comments