cudnn_frontend_VariantPack.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 <algorithm>
#include <array>
#include <functional>
#include <memory>
#include <set>
#include <sstream>
#include <utility>
#include <cudnn.h>
#include <cudnn_backend.h>
#include "cudnn_frontend_utils.h"
namespace cudnn_frontend {
class VariantPack_v8 : public BackendDescriptor {
public:
friend class VariantPackBuilder_v8;
std::string
describe() const override {
std::stringstream ss;
ss << "CUDNN_BACKEND_VARIANT_PACK_DESCRIPTOR :"
<< " has " << num_ptrs << " data pointers";
return ss.str();
}
VariantPack_v8(VariantPack_v8 &&from) = default;
VariantPack_v8 &
operator=(VariantPack_v8 &&from) = default;
~VariantPack_v8() = default;
private:
VariantPack_v8() = default;
VariantPack_v8(VariantPack_v8 const &) = delete;
VariantPack_v8 &
operator=(VariantPack_v8 const &) = delete;
void *workspace = nullptr;
void *data_pointers[10] = {nullptr};
int64_t uid[10] = {-1};
int64_t num_ptrs = -1;
};
class VariantPackBuilder_v8 {
public:
auto
setDataPointers(int64_t num_ptr, void **ptrs) -> VariantPackBuilder_v8 & {
std::copy(ptrs, ptrs + num_ptr, m_variant_pack.data_pointers);
m_variant_pack.num_ptrs = num_ptr;
return *this;
}
auto
setUids(int64_t num_uids, int64_t *uid) -> VariantPackBuilder_v8 & {
std::copy(uid, uid + num_uids, m_variant_pack.uid);
return *this;
}
auto
setDataPointers(std::set<std::pair<uint64_t, void *>> const &data_pointers) -> VariantPackBuilder_v8 & {
auto i = 0;
for (auto &data_pointer : data_pointers) {
m_variant_pack.uid[i] = data_pointer.first;
m_variant_pack.data_pointers[i] = data_pointer.second;
i++;
}
m_variant_pack.num_ptrs = data_pointers.size();
return *this;
}
auto
setWorkspacePointer(void *ws) -> VariantPackBuilder_v8 & {
m_variant_pack.workspace = ws;
return *this;
}
VariantPack_v8 &&
build() {
// Create a descriptor. Memory allocation happens here.
auto status = m_variant_pack.initialize_managed_backend_pointer(CUDNN_BACKEND_VARIANT_PACK_DESCRIPTOR);
if (status != CUDNN_STATUS_SUCCESS) {
set_error_and_throw_exception(
&m_variant_pack, status, "CUDNN_BACKEND_VARIANT_PACK_DESCRIPTOR: cudnnCreate Failed");
return std::move(m_variant_pack);
}
status = cudnnBackendSetAttribute(m_variant_pack.pointer->get_backend_descriptor(),
CUDNN_ATTR_VARIANT_PACK_DATA_POINTERS,
CUDNN_TYPE_VOID_PTR,
m_variant_pack.num_ptrs,
m_variant_pack.data_pointers);
if (status != CUDNN_STATUS_SUCCESS) {
set_error_and_throw_exception(
&m_variant_pack,
status,
"CUDNN_BACKEND_VARIANT_PACK_DESCRIPTOR: SetAttribute CUDNN_ATTR_VARIANT_PACK_DATA_POINTERS Failed");
return std::move(m_variant_pack);
}
status = cudnnBackendSetAttribute(m_variant_pack.pointer->get_backend_descriptor(),
CUDNN_ATTR_VARIANT_PACK_UNIQUE_IDS,
CUDNN_TYPE_INT64,
m_variant_pack.num_ptrs,
m_variant_pack.uid);
if (status != CUDNN_STATUS_SUCCESS) {
set_error_and_throw_exception(
&m_variant_pack,
status,
"CUDNN_BACKEND_VARIANT_PACK_DESCRIPTOR: SetAttribute CUDNN_ATTR_VARIANT_PACK_UNIQUE_IDS Failed");
return std::move(m_variant_pack);
}
status = cudnnBackendSetAttribute(m_variant_pack.pointer->get_backend_descriptor(),
CUDNN_ATTR_VARIANT_PACK_WORKSPACE,
CUDNN_TYPE_VOID_PTR,
1,
&m_variant_pack.workspace);
if (status != CUDNN_STATUS_SUCCESS) {
set_error_and_throw_exception(
&m_variant_pack,
status,
"CUDNN_BACKEND_VARIANT_PACK_DESCRIPTOR: SetAttribute CUDNN_ATTR_VARIANT_PACK_WORKSPACE Failed");
return std::move(m_variant_pack);
}
// Finalizing the descriptor
status = cudnnBackendFinalize(m_variant_pack.pointer->get_backend_descriptor());
if (status != CUDNN_STATUS_SUCCESS) {
set_error_and_throw_exception(
&m_variant_pack, status, "CUDNN_BACKEND_VARIANT_PACK_DESCRIPTOR: cudnnFinalize Failed");
return std::move(m_variant_pack);
}
getLogger() << "[cudnn_frontend] "<< m_variant_pack << std::endl;
return std::move(m_variant_pack);
}
explicit VariantPackBuilder_v8() = default;
~VariantPackBuilder_v8() = default;
VariantPackBuilder_v8(VariantPackBuilder_v8 &&) = delete;
VariantPackBuilder_v8(VariantPackBuilder_v8 const &) = delete;
VariantPackBuilder_v8 &
operator=(VariantPackBuilder_v8 const &) = delete;
private:
VariantPack_v8 m_variant_pack;
};
}
cudnn_frontend::VariantPackBuilder_v8::m_variant_pack
VariantPack_v8 m_variant_pack
Definition: cudnn_frontend_VariantPack.h:193
cudnn_frontend::getLogger
ConditionalStreamer & getLogger()
Definition: cudnn_frontend_Logging.h:72
cudnn_frontend::set_error_and_throw_exception
static void set_error_and_throw_exception(BackendDescriptor const *desc, cudnnStatus_t status, const char *message)
Definition: cudnn_frontend_utils.h:138
cudnn_frontend::VariantPackBuilder_v8
Definition: cudnn_frontend_VariantPack.h:84
cudnn_frontend::VariantPackBuilder_v8::setWorkspacePointer
auto setWorkspacePointer(void *ws) -> VariantPackBuilder_v8 &
Set Workspace.
Definition: cudnn_frontend_VariantPack.h:117
cudnn_frontend::VariantPackBuilder_v8::setDataPointers
auto setDataPointers(int64_t num_ptr, void **ptrs) -> VariantPackBuilder_v8 &
Set dataPointers for the VariantPack_v8.
Definition: cudnn_frontend_VariantPack.h:92
cudnn_frontend::BackendDescriptor
Definition: cudnn_backend_base.h:99
cudnn_frontend::VariantPack_v8::VariantPack_v8
VariantPack_v8()=default
cudnn_frontend::VariantPack_v8::workspace
void * workspace
Definition: cudnn_frontend_VariantPack.h:75
cudnn_frontend::VariantPackBuilder_v8::setUids
auto setUids(int64_t num_uids, int64_t *uid) -> VariantPackBuilder_v8 &
Set Uids for the VariantPack_v8.
Definition: cudnn_frontend_VariantPack.h:99
cudnn_frontend_utils.h
cudnn_frontend::VariantPack_v8::~VariantPack_v8
~VariantPack_v8()=default
cudnn_frontend::VariantPack_v8::VariantPackBuilder_v8
friend class VariantPackBuilder_v8
Definition: cudnn_frontend_VariantPack.h:54
cudnn_frontend::VariantPack_v8
Definition: cudnn_frontend_VariantPack.h:52
cudnn_frontend::VariantPack_v8::num_ptrs
int64_t num_ptrs
Definition: cudnn_frontend_VariantPack.h:78
cudnn_frontend::VariantPack_v8::uid
int64_t uid[10]
Definition: cudnn_frontend_VariantPack.h:77
cudnn_frontend
Definition: cudnn_backend_base.h:29
cudnn_frontend::VariantPackBuilder_v8::build
VariantPack_v8 && build()
Definition: cudnn_frontend_VariantPack.h:126
cudnn_frontend::VariantPack_v8::data_pointers
void * data_pointers[10]
Definition: cudnn_frontend_VariantPack.h:76
cudnn_frontend::VariantPackBuilder_v8::setDataPointers
auto setDataPointers(std::set< std::pair< uint64_t, void *>> const &data_pointers) -> VariantPackBuilder_v8 &
Initialize a set of pairs containing uid and data pointer.
Definition: cudnn_frontend_VariantPack.h:105
cudnn_frontend::VariantPack_v8::describe
std::string describe() const override
Return a string describing the backend Descriptor.
Definition: cudnn_frontend_VariantPack.h:56
cudnn_frontend::VariantPack_v8::operator=
VariantPack_v8 & operator=(VariantPack_v8 &&from)=default
cudnn_frontend::BackendDescriptor::status
cudnnStatus_t status
Shared pointer of the OpaqueBackendPointer.
Definition: cudnn_backend_base.h:160