Tpetra parallel linear algebra  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Tpetra_Details_checkLaunchBlocking.hpp
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 
10 #ifndef TPETRA_DETAILS_CHECKLAUNCHBLOCKING_HPP
11 #define TPETRA_DETAILS_CHECKLAUNCHBLOCKING_HPP
12 
13 #include "TpetraCore_config.h"
14 #include <cstdlib>
15 #include <stdexcept>
16 #include "Kokkos_Core.hpp"
17 
18 namespace Tpetra {
19 namespace Details {
20 #if defined(HAVE_TPETRACORE_CUDA) && defined(KOKKOS_ENABLE_DEPRECATED_CODE_4)
21 // Verify that for pre-Pascal CUDA architectures, $CUDA_LAUNCH_BLOCKING == 1
22 inline void checkOldCudaLaunchBlocking() {
23  if (!Kokkos::is_initialized())
24  throw std::logic_error("Kokkos must be initialized in order to check CUDA_LAUNCH_BLOCKING setting.");
25  size_t arch = Kokkos::Cuda::device_arch();
26  if (arch < 600) {
27  // Compiling for Kepler/Maxwell: require launch blocking.
28  const char* launchBlockingEnv = std::getenv("CUDA_LAUNCH_BLOCKING");
29  if (!launchBlockingEnv || strcmp(launchBlockingEnv, "1")) {
30  throw std::runtime_error(
31  "Tpetra::initialize(): Kokkos was compiled for an older CUDA architecture than Pascal, but\n"
32  "the environment variable CUDA_LAUNCH_BLOCKING is either unset or is not \"1\".\n"
33  "It must be set to \"1\" at runtime.\n");
34  }
35  }
36 }
37 #else
38 inline void checkOldCudaLaunchBlocking() {}
39 #endif
40 } // namespace Details
41 } // namespace Tpetra
42 
43 #endif