Tpetra parallel linear algebra  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Tpetra_Details_ExecutionSpaces.cpp
1 // @HEADER
2 // *****************************************************************************
3 // Tpetra: Templated Linear Algebra Services Package
4 //
5 // Copyright 2008 NTESS and the Tpetra contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
11 
12 #include <sstream>
13 #include <vector>
14 
15 namespace Tpetra {
16 namespace Details {
17 namespace Spaces {
18 
19 #if defined(KOKKOS_ENABLE_CUDA)
20 // cuda has default stream priority 0
21 CudaInfo::CudaInfo()
22  : initialized_(false)
23  , mediumPrio_(0) {}
24 #endif
25 
26 void lazy_init() {
27 #if defined(KOKKOS_ENABLE_CUDA)
28  if (!cudaInfo.initialized_) {
29  cudaInfo.initialized_ = true;
30  TPETRA_DETAILS_SPACES_CUDA_RUNTIME(cudaEventCreateWithFlags(
31  &cudaInfo.execSpaceWaitEvent_, cudaEventDisableTiming));
32  TPETRA_DETAILS_SPACES_CUDA_RUNTIME(cudaDeviceGetStreamPriorityRange(
33  &cudaInfo.lowPrio_, &cudaInfo.highPrio_));
34 
35  // We expect
36  // medium priority should be 0
37  // lower numbers to be higher priorities
38  // low is at least as good as medium
39  // medium is at least as good as high
40  if (!(cudaInfo.lowPrio_ >= cudaInfo.mediumPrio_ &&
41  cudaInfo.mediumPrio_ >= cudaInfo.highPrio_)) {
42  std::stringstream ss;
43  ss << "CUDA stream priority does not follow assumptions."
44  << " low=" << cudaInfo.lowPrio_ << " medium=" << cudaInfo.mediumPrio_
45  << " high=" << cudaInfo.highPrio_
46  << " Please report this to the Tpetra developers.";
47  throw std::runtime_error(ss.str());
48  }
49  }
50 #endif
51 }
52 
53 /* -----------------------------
54  Space Management Singletons
55  -----------------------------*/
56 
57 #if defined(KOKKOS_ENABLE_CUDA)
58 /*extern*/ InstanceLifetimeManager<Kokkos::Cuda> cudaSpaces;
59 /*extern*/ CudaInfo cudaInfo;
60 #endif
61 #ifdef KOKKOS_ENABLE_SERIAL
62 /*extern*/ InstanceLifetimeManager<Kokkos::Serial> serialSpaces;
63 #endif
64 #ifdef KOKKOS_ENABLE_OPENMP
65 /*extern*/ InstanceLifetimeManager<Kokkos::OpenMP> openMPSpaces;
66 #endif
67 #ifdef KOKKOS_ENABLE_HIP
68 /*extern*/ InstanceLifetimeManager<Kokkos::HIP> HIPSpaces;
69 #endif
70 #ifdef KOKKOS_ENABLE_SYCL
71 /*extern*/ InstanceLifetimeManager<Kokkos::Experimental::SYCL> SYCLSpaces;
72 #endif
73 
74 } // namespace Spaces
75 } // namespace Details
76 } // namespace Tpetra