cudnn_backend_base.h
Go to the documentation of this file.
/*
* Copyright (c) 2021, NVIDIA CORPORATION. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
#pragma once
#include <ostream>
#include <cudnn.h>
namespace cudnn_frontend {
class OpaqueBackendPointer {
cudnnBackendDescriptor_t m_desc = nullptr;
cudnnStatus_t status = CUDNN_STATUS_SUCCESS;
public:
OpaqueBackendPointer(const OpaqueBackendPointer&) = delete;
OpaqueBackendPointer&
operator=(const OpaqueBackendPointer&) = delete;
OpaqueBackendPointer(OpaqueBackendPointer&&) = default;
OpaqueBackendPointer(cudnnBackendDescriptorType_t type) { status = cudnnBackendCreateDescriptor(type, &m_desc); }
~OpaqueBackendPointer() { cudnnBackendDestroyDescriptor(m_desc); };
cudnnBackendDescriptor_t const&
get_backend_descriptor() const {
return m_desc;
}
cudnnStatus_t
get_status() const {
return status;
}
bool
is_good() const {
return status == CUDNN_STATUS_SUCCESS;
}
};
using ManagedOpaqueDescriptor = std::shared_ptr<OpaqueBackendPointer>;
static ManagedOpaqueDescriptor
make_shared_backend_pointer(cudnnBackendDescriptorType_t type) {
return std::make_shared<OpaqueBackendPointer>(type);
}
class BackendDescriptor {
public:
virtual std::string
describe() const = 0;
cudnnBackendDescriptor_t
get_raw_desc() const {
return pointer->get_backend_descriptor();
}
cudnnStatus_t
get_status() const {
return status;
}
void
set_status(cudnnStatus_t const status_) const {
status = status_;
}
void
set_error(const char* message) const {
err_msg = message;
}
const char*
get_error() const {
return err_msg.c_str();
}
ManagedOpaqueDescriptor
get_desc() const {
return pointer;
}
cudnnStatus_t
initialize_managed_backend_pointer(cudnnBackendDescriptorType_t type) {
pointer = make_shared_backend_pointer(type);
return pointer->get_status();
}
protected:
BackendDescriptor(ManagedOpaqueDescriptor pointer_, cudnnStatus_t status_, std::string err_msg_)
: pointer(pointer_), status(status_), err_msg(err_msg_) {}
BackendDescriptor() = default;
ManagedOpaqueDescriptor pointer;
mutable cudnnStatus_t status = CUDNN_STATUS_SUCCESS;
mutable std::string err_msg;
};
}
cudnn_frontend::OpaqueBackendPointer::~OpaqueBackendPointer
~OpaqueBackendPointer()
Definition: cudnn_backend_base.h:55
cudnn_frontend::OpaqueBackendPointer::OpaqueBackendPointer
OpaqueBackendPointer(const OpaqueBackendPointer &)=delete
Delete the copy constructor to prevent bad copies.
cudnn_frontend::BackendDescriptor::set_status
void set_status(cudnnStatus_t const status_) const
Set status of the descriptor.
Definition: cudnn_backend_base.h:120
cudnn_frontend::BackendDescriptor::initialize_managed_backend_pointer
cudnnStatus_t initialize_managed_backend_pointer(cudnnBackendDescriptorType_t type)
Initializes the underlying managed descriptor.
Definition: cudnn_backend_base.h:144
cudnn_frontend::OpaqueBackendPointer
Definition: cudnn_backend_base.h:36
cudnn_frontend::OpaqueBackendPointer::m_desc
cudnnBackendDescriptor_t m_desc
Raw void pointer.
Definition: cudnn_backend_base.h:37
cudnn_frontend::BackendDescriptor
Definition: cudnn_backend_base.h:99
cudnn_frontend::OpaqueBackendPointer::is_good
bool is_good() const
Definition: cudnn_backend_base.h:78
cudnn_frontend::make_shared_backend_pointer
static ManagedOpaqueDescriptor make_shared_backend_pointer(cudnnBackendDescriptorType_t type)
Definition: cudnn_backend_base.h:88
cudnn_frontend::BackendDescriptor::get_raw_desc
cudnnBackendDescriptor_t get_raw_desc() const
Definition: cudnn_backend_base.h:108
cudnn_frontend::BackendDescriptor::get_desc
ManagedOpaqueDescriptor get_desc() const
Returns a copy of underlying managed descriptor.
Definition: cudnn_backend_base.h:138
cudnn_frontend::OpaqueBackendPointer::status
cudnnStatus_t status
status of creation of the Descriptor
Definition: cudnn_backend_base.h:38
cudnn_frontend::OpaqueBackendPointer::operator=
OpaqueBackendPointer & operator=(const OpaqueBackendPointer &)=delete
cudnn_frontend::OpaqueBackendPointer::get_backend_descriptor
cudnnBackendDescriptor_t const & get_backend_descriptor() const
Definition: cudnn_backend_base.h:62
cudnn_frontend::OpaqueBackendPointer::get_status
cudnnStatus_t get_status() const
Definition: cudnn_backend_base.h:70
cudnn_frontend::OpaqueBackendPointer::OpaqueBackendPointer
OpaqueBackendPointer(cudnnBackendDescriptorType_t type)
Definition: cudnn_backend_base.h:50
cudnn_frontend::BackendDescriptor::get_status
cudnnStatus_t get_status() const
Current status of the descriptor.
Definition: cudnn_backend_base.h:114
cudnn_frontend::ManagedOpaqueDescriptor
std::shared_ptr< OpaqueBackendPointer > ManagedOpaqueDescriptor
Definition: cudnn_backend_base.h:84
cudnn_frontend
Definition: cudnn_backend_base.h:29
cudnn_frontend::BackendDescriptor::get_error
const char * get_error() const
Diagonistic error message if any.
Definition: cudnn_backend_base.h:132
type
cudnn_frontend::BackendDescriptor::set_error
void set_error(const char *message) const
Set Diagonistic error message.
Definition: cudnn_backend_base.h:126
cudnn_frontend::BackendDescriptor::BackendDescriptor
BackendDescriptor(ManagedOpaqueDescriptor pointer_, cudnnStatus_t status_, std::string err_msg_)
Definition: cudnn_backend_base.h:154
cudnn_frontend::BackendDescriptor::err_msg
std::string err_msg
Error message if any being set.
Definition: cudnn_backend_base.h:161
cudnn_frontend::BackendDescriptor::pointer
ManagedOpaqueDescriptor pointer
Definition: cudnn_backend_base.h:158