CUDNN API  8
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 <cudnn.h>
26 
27 namespace cudnn_frontend {
28 
35  cudnnBackendDescriptor_t m_desc = nullptr;
36  cudnnStatus_t status = CUDNN_STATUS_SUCCESS;
37 
38  public:
41  operator=(const OpaqueBackendPointer&) = delete;
43 
48  OpaqueBackendPointer(cudnnBackendDescriptorType_t type) { status = cudnnBackendCreateDescriptor(type, &m_desc); }
53  ~OpaqueBackendPointer() { cudnnBackendDestroyDescriptor(m_desc); };
59  cudnnBackendDescriptor_t const&
61  return m_desc;
62  }
67  cudnnStatus_t
68  get_status() const {
69  return status;
70  }
75  bool
76  is_good() const {
77  return status == CUDNN_STATUS_SUCCESS;
78  }
79 };
80 
82 using ManagedOpaqueDescriptor = std::shared_ptr<OpaqueBackendPointer>;
83 
86 make_shared_backend_pointer(cudnnBackendDescriptorType_t type) {
87  return std::make_shared<OpaqueBackendPointer>(type);
88 }
89 
98  public:
100  virtual std::string
101  describe() const = 0;
102 
105  cudnnBackendDescriptor_t
106  get_raw_desc() const {
107  return pointer->get_backend_descriptor();
108  }
109 
111  cudnnStatus_t
112  get_status() const {
113  return status;
114  }
115 
117  void
118  set_status(cudnnStatus_t const status_) const {
119  status = status_;
120  }
121 
123  void
124  set_error(const char* message) const {
125  err_msg = message;
126  }
127 
129  const char*
130  get_error() const {
131  return err_msg.c_str();
132  }
133 
136  get_desc() const {
137  return pointer;
138  }
139 
141  cudnnStatus_t
142  initialize_managed_backend_pointer(cudnnBackendDescriptorType_t type) {
143  pointer = make_shared_backend_pointer(type);
144  return pointer->get_status();
145  }
146 
147  protected:
152  BackendDescriptor(ManagedOpaqueDescriptor pointer_, cudnnStatus_t status_, std::string err_msg_)
153  : pointer(pointer_), status(status_), err_msg(err_msg_) {}
154  BackendDescriptor() = default;
155 
157 
158  mutable cudnnStatus_t status = CUDNN_STATUS_SUCCESS;
159  mutable std::string err_msg;
160 };
161 }
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.