LBANN  0.103.0
LivermoreBigArtificialNeuralNetworkToolkit
cutensor_support.hpp
Go to the documentation of this file.
1 // Copyright (c) 2014-2023, Lawrence Livermore National Security, LLC.
3 // Produced at the Lawrence Livermore National Laboratory.
4 // Written by the LBANN Research Team (B. Van Essen, et al.) listed in
5 // the CONTRIBUTORS file. <lbann-dev@llnl.gov>
6 //
7 // LLNL-CODE-697807.
8 // All rights reserved.
9 //
10 // This file is part of LBANN: Livermore Big Artificial Neural Network
11 // Toolkit. For details, see http://software.llnl.gov/LBANN or
12 // https://github.com/LLNL/LBANN.
13 //
14 // Licensed under the Apache License, Version 2.0 (the "Licensee"); you
15 // may not use this file except in compliance with the License. You may
16 // obtain a copy of the License at:
17 //
18 // http://www.apache.org/licenses/LICENSE-2.0
19 //
20 // Unless required by applicable law or agreed to in writing, software
21 // distributed under the License is distributed on an "AS IS" BASIS,
22 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
23 // implied. See the License for the specific language governing
24 // permissions and limitations under the license.
26 #ifndef LBANN_SRC_LAYERS_TRANSFORM_CUTENSOR_SUPPORT_HPP_INCLUDED
27 #define LBANN_SRC_LAYERS_TRANSFORM_CUTENSOR_SUPPORT_HPP_INCLUDED
28 
29 #include "lbann/base.hpp"
31 
32 #include <cuda_runtime.h>
33 #include <cutensor.h>
34 
35 #define CHECK_CUTENSOR(cmd) \
36  do { \
37  auto const lbann_chk_cutensor_status__ = (cmd); \
38  if (CUTENSOR_STATUS_SUCCESS != lbann_chk_cutensor_status__) { \
39  LBANN_ERROR("cuTENSOR error (status=", \
40  lbann_chk_cutensor_status__, \
41  "): ", \
42  cutensorGetErrorString(lbann_chk_cutensor_status__)); \
43  } \
44  } while (false)
45 
46 namespace lbann {
47 
48 template <typename CppType>
49 struct CUDATypeT;
50 
51 template <>
52 struct CUDATypeT<__half>
53 {
54  typedef float scalar_type;
55  static constexpr auto value = CUDA_R_16F;
56 };
57 
58 template <>
59 struct CUDATypeT<float>
60 {
61  typedef float scalar_type;
62  static constexpr auto value = CUDA_R_32F;
63 };
64 template <>
65 struct CUDATypeT<double>
66 {
67  typedef double scalar_type;
68  static constexpr auto value = CUDA_R_64F;
69 };
70 template <>
71 struct CUDATypeT<El::Complex<float>>
72 {
73  typedef El::Complex<float> scalar_type;
74  static constexpr auto value = CUDA_C_32F;
75 };
76 template <>
77 struct CUDATypeT<El::Complex<double>>
78 {
79  typedef El::Complex<double> scalar_type;
80  static constexpr auto value = CUDA_C_64F;
81 };
82 
83 template <typename CppType>
85 
86 template <typename CppType>
88 
89 template <typename CppType>
91 
92 static cutensorHandle_t make_handle()
93 {
94  cutensorHandle_t handle;
95  CHECK_CUTENSOR(cutensorInit(&handle));
96  return handle;
97 }
98 static cutensorHandle_t* get_handle_ptr()
99 {
100  static cutensorHandle_t handle = make_handle();
101  return &handle;
102 }
103 
104 } // namespace lbann
105 
106 #endif // LBANN_SRC_LAYERS_TRANSFORM_CUTENSOR_SUPPORT_HPP_INCLUDED
static cutensorHandle_t * get_handle_ptr()
#define CHECK_CUTENSOR(cmd)
constexpr auto CUDAType
static cutensorHandle_t make_handle()
constexpr auto CUDAScalarType
typename CUDATypeT< CppType >::scalar_type CUDAScalar