CUDNN Frontend API  8.3.0
cudnn_backend_base.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2021, NVIDIA CORPORATION. All rights reserved.
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20  * DEALINGS IN THE SOFTWARE.
21  */
22 
23 #pragma once
24 
25 #include <ostream>
26 
27 #include <cudnn.h>
28 
29 namespace cudnn_frontend {
30 
37  cudnnBackendDescriptor_t m_desc = nullptr;
38  cudnnStatus_t status = CUDNN_STATUS_SUCCESS;
39 
40  public:
43  operator=(const OpaqueBackendPointer&) = delete;
45 
50  OpaqueBackendPointer(cudnnBackendDescriptorType_t type) { status = cudnnBackendCreateDescriptor(type, &m_desc); }
55  ~OpaqueBackendPointer() { cudnnBackendDestroyDescriptor(m_desc); };
61  cudnnBackendDescriptor_t const&
63  return m_desc;
64  }
69  cudnnStatus_t
70  get_status() const {
71  return status;
72  }
77  bool
78  is_good() const {
79  return status == CUDNN_STATUS_SUCCESS;
80  }
81 };
82 
84 using ManagedOpaqueDescriptor = std::shared_ptr<OpaqueBackendPointer>;
85 
88 make_shared_backend_pointer(cudnnBackendDescriptorType_t type) {
89  return std::make_shared<OpaqueBackendPointer>(type);
90 }
91 
100  public:
102  virtual std::string
103  describe() const = 0;
104 
107  cudnnBackendDescriptor_t
108  get_raw_desc() const {
109  return pointer->get_backend_descriptor();
110  }
111 
113  cudnnStatus_t
114  get_status() const {
115  return status;
116  }
117 
119  void
120  set_status(cudnnStatus_t const status_) const {
121  status = status_;
122  }
123 
125  void
126  set_error(const char* message) const {
127  err_msg = message;
128  }
129 
131  const char*
132  get_error() const {
133  return err_msg.c_str();
134  }
135 
138  get_desc() const {
139  return pointer;
140  }
141 
143  cudnnStatus_t
144  initialize_managed_backend_pointer(cudnnBackendDescriptorType_t type) {
145  pointer = make_shared_backend_pointer(type);
146  return pointer->get_status();
147  }
148 
149  protected:
154  BackendDescriptor(ManagedOpaqueDescriptor pointer_, cudnnStatus_t status_, std::string err_msg_)
155  : pointer(pointer_), status(status_), err_msg(err_msg_) {}
156  BackendDescriptor() = default;
157 
159 
160  mutable cudnnStatus_t status = CUDNN_STATUS_SUCCESS;
161  mutable std::string err_msg;
162 };
163 }
OpaqueBackendPointer(const OpaqueBackendPointer &)=delete
Delete the copy constructor to prevent bad copies.
void set_status(cudnnStatus_t const status_) const
Set status of the descriptor.
cudnnStatus_t initialize_managed_backend_pointer(cudnnBackendDescriptorType_t type)
Initializes the underlying managed descriptor.
cudnnBackendDescriptor_t m_desc
Raw void pointer.
static ManagedOpaqueDescriptor make_shared_backend_pointer(cudnnBackendDescriptorType_t type)
cudnnBackendDescriptor_t get_raw_desc() const
ManagedOpaqueDescriptor get_desc() const
Returns a copy of underlying managed descriptor.
cudnnStatus_t status
status of creation of the Descriptor
OpaqueBackendPointer & operator=(const OpaqueBackendPointer &)=delete
cudnnBackendDescriptor_t const & get_backend_descriptor() const
OpaqueBackendPointer(cudnnBackendDescriptorType_t type)
cudnnStatus_t get_status() const
Current status of the descriptor.
std::shared_ptr< OpaqueBackendPointer > ManagedOpaqueDescriptor
const char * get_error() const
Diagonistic error message if any.
void set_error(const char *message) const
Set Diagonistic error message.
BackendDescriptor(ManagedOpaqueDescriptor pointer_, cudnnStatus_t status_, std::string err_msg_)
std::string err_msg
Error message if any being set.