cudnn_frontend_EngineFallbackList.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 <cudnn.h>
#include <numeric>
namespace cudnn_frontend {
auto static get_fallback_engine_list(cudnnBackendDescriptorType_t mode, const std::string &opGraphTag) -> std::vector<int> {
auto major_version = cudnnGetVersion() / 1000;
auto minor_version = (cudnnGetVersion() / 100) % 10;
if (major_version >= 8) {
if (minor_version <= 2) {
if (mode == CUDNN_BACKEND_OPERATION_CONVOLUTION_FORWARD_DESCRIPTOR) {
if (opGraphTag.find("bias") == std::string::npos) {
std::vector<int> engine_list(50);
std::iota(engine_list.begin(), engine_list.end(), 0);
return engine_list;
} else {
return {11,0};
}
} else if (mode == CUDNN_BACKEND_OPERATION_CONVOLUTION_BACKWARD_DATA_DESCRIPTOR) {
std::vector<int> engine_list(61);
std::iota(engine_list.begin(), engine_list.end(), 0);
return engine_list;
} else if (mode == CUDNN_BACKEND_OPERATION_CONVOLUTION_BACKWARD_FILTER_DESCRIPTOR) {
return {0, 1, 20};
} else {
return {};
}
} else {
if (mode == CUDNN_BACKEND_OPERATION_CONVOLUTION_FORWARD_DESCRIPTOR) {
if (opGraphTag.find("bias") == std::string::npos) {
return {0, 1, 28};
} else {
return {};
}
} else if (mode == CUDNN_BACKEND_OPERATION_CONVOLUTION_BACKWARD_DATA_DESCRIPTOR) {
return {0, 1, 25};
} else if (mode == CUDNN_BACKEND_OPERATION_CONVOLUTION_BACKWARD_FILTER_DESCRIPTOR) {
return {0, 1, 20};
} else {
return {};
}
}
} else {
return {};
}
}
class EngineFallbackList_v8 : public BackendDescriptor {
public:
friend class EngineFallbackListBuilder_v8;
std::string
describe() const override {
std::stringstream ss;
ss << "CUDNN_BACKEND_FALLBACK ENGINES :";
return ss.str();
}
auto
getFallbackList() -> std::vector<ManagedOpaqueDescriptor> & {
return m_engine_configs;
}
~EngineFallbackList_v8() = default;
EngineFallbackList_v8(EngineFallbackList_v8 &&from)
: BackendDescriptor(from.get_desc(), from.get_status(), from.get_error()),
opGraph(from.opGraph),
mode(from.mode),
num_ops(from.num_ops),
opGraphTag(from.opGraphTag) {
m_engine_configs.swap(from.m_engine_configs);
}
private:
EngineFallbackList_v8() = default;
EngineFallbackList_v8(EngineFallbackList_v8 const &) = delete;
EngineFallbackList_v8 &
operator=(EngineFallbackList_v8 const &) = delete;
ManagedOpaqueDescriptor opGraph = nullptr;
cudnnBackendDescriptorType_t mode;
uint64_t num_ops;
std::vector<ManagedOpaqueDescriptor> m_engine_configs;
std::string opGraphTag;
};
class EngineFallbackListBuilder_v8 {
public:
auto
setOperationGraph(OperationGraph_v8 &opGraph_) -> EngineFallbackListBuilder_v8 & {
m_fallback_list.opGraph = opGraph_.get_desc();
m_fallback_list.opGraphTag = opGraph_.getTag();
m_fallback_list.num_ops = opGraph_.getOpCount();
return *this;
}
auto
setOperation(cudnnBackendDescriptorType_t mode) -> EngineFallbackListBuilder_v8 & {
m_fallback_list.mode = mode;
return *this;
}
EngineFallbackList_v8 &&
build() {
if (m_fallback_list.opGraph == nullptr) {
set_error_and_throw_exception(&m_fallback_list,
CUDNN_STATUS_BAD_PARAM,
"CUDNN_BACKEND_ENGINEHEUR_DESCRIPTOR: Check and Set the "
"CUDNN_ATTR_ENGINEHEUR_OPERATION_GRAPH field for heuristic");
return std::move(m_fallback_list);
};
auto fallback_engine_list = get_fallback_engine_list(m_fallback_list.mode, m_fallback_list.opGraphTag);
for (std::uint32_t i = 0; i < fallback_engine_list.size(); i++) {
#ifndef NV_CUDNN_DISABLE_EXCEPTION
try {
#endif
auto engine = cudnn_frontend::EngineBuilder_v8()
.setGlobalEngineIdx(fallback_engine_list[i])
.setOperationGraph(m_fallback_list.opGraph)
.build();
auto engine_config = cudnn_frontend::EngineConfigBuilder_v8().setEngine(engine).build();
m_fallback_list.m_engine_configs.emplace_back(engine_config.get_desc());
#ifndef NV_CUDNN_DISABLE_EXCEPTION
} catch (cudnn_frontend::cudnnException &e) {
continue;
}
#endif
}
getLogger() << "[cudnn_frontend] " << m_fallback_list << std::endl;
return std::move(m_fallback_list);
}
explicit EngineFallbackListBuilder_v8() = default;
~EngineFallbackListBuilder_v8() = default;
EngineFallbackListBuilder_v8(EngineFallbackListBuilder_v8 &&) = delete;
EngineFallbackListBuilder_v8(EngineFallbackListBuilder_v8 const &) = delete;
EngineFallbackListBuilder_v8 &
operator=(EngineFallbackListBuilder_v8 const &) = delete;
private:
EngineFallbackList_v8 m_fallback_list;
};
}
cudnn_frontend::get_fallback_engine_list
static auto get_fallback_engine_list(cudnnBackendDescriptorType_t mode, const std::string &opGraphTag) -> std::vector< int >
Definition: cudnn_frontend_EngineFallbackList.h:30
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::EngineBuilder_v8::setGlobalEngineIdx
auto setGlobalEngineIdx(int64_t idx_) -> EngineBuilder_v8 &
Set engine index for the engine.
Definition: cudnn_frontend_Engine.h:266
cudnn_frontend::BackendDescriptor
Definition: cudnn_backend_base.h:99
cudnn_frontend::EngineFallbackList_v8::describe
std::string describe() const override
Return a string describing the backend Descriptor.
Definition: cudnn_frontend_EngineFallbackList.h:82
cudnn_frontend::EngineConfigBuilder_v8
Definition: cudnn_frontend_EngineConfig.h:104
cudnn_frontend::EngineFallbackList_v8::EngineFallbackList_v8
EngineFallbackList_v8(EngineFallbackList_v8 &&from)
Definition: cudnn_frontend_EngineFallbackList.h:95
cudnn_frontend::EngineFallbackList_v8::mode
cudnnBackendDescriptorType_t mode
Definition: cudnn_frontend_EngineFallbackList.h:111
cudnn_frontend::BackendDescriptor::get_desc
ManagedOpaqueDescriptor get_desc() const
Returns a copy of underlying managed descriptor.
Definition: cudnn_backend_base.h:138
cudnn_frontend::EngineFallbackList_v8::opGraph
ManagedOpaqueDescriptor opGraph
Definition: cudnn_frontend_EngineFallbackList.h:110
cudnn_frontend::EngineConfigBuilder_v8::setEngine
auto setEngine(Engine_v8 const &engine_) -> EngineConfigBuilder_v8 &
Set engine for the EngineConfig_v8.
Definition: cudnn_frontend_EngineConfig.h:112
cudnn_frontend::EngineFallbackListBuilder_v8::setOperation
auto setOperation(cudnnBackendDescriptorType_t mode) -> EngineFallbackListBuilder_v8 &
Definition: cudnn_frontend_EngineFallbackList.h:135
cudnn_frontend::cudnnException
Definition: cudnn_frontend_utils.h:37
cudnn_frontend::BackendDescriptor::get_status
cudnnStatus_t get_status() const
Current status of the descriptor.
Definition: cudnn_backend_base.h:114
cudnn_frontend::EngineFallbackList_v8::~EngineFallbackList_v8
~EngineFallbackList_v8()=default
cudnn_frontend::EngineFallbackList_v8::EngineFallbackListBuilder_v8
friend class EngineFallbackListBuilder_v8
Definition: cudnn_frontend_EngineFallbackList.h:79
cudnn_frontend::EngineFallbackList_v8::num_ops
uint64_t num_ops
Definition: cudnn_frontend_EngineFallbackList.h:112
cudnn_frontend::EngineFallbackList_v8::EngineFallbackList_v8
EngineFallbackList_v8()=default
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
cudnn_frontend::EngineFallbackListBuilder_v8::setOperationGraph
auto setOperationGraph(OperationGraph_v8 &opGraph_) -> EngineFallbackListBuilder_v8 &
Set operationGraph for the engine (opGraph is not destroyed)
Definition: cudnn_frontend_EngineFallbackList.h:128
cudnn_frontend::EngineFallbackListBuilder_v8::build
EngineFallbackList_v8 && build()
Definition: cudnn_frontend_EngineFallbackList.h:144
cudnn_frontend::EngineFallbackList_v8
Definition: cudnn_frontend_EngineFallbackList.h:77
cudnn_frontend::EngineBuilder_v8
Definition: cudnn_frontend_Engine.h:244
cudnn_frontend::EngineFallbackListBuilder_v8::m_fallback_list
EngineFallbackList_v8 m_fallback_list
Definition: cudnn_frontend_EngineFallbackList.h:181
cudnn_frontend::EngineFallbackList_v8::opGraphTag
std::string opGraphTag
Definition: cudnn_frontend_EngineFallbackList.h:114
cudnn_frontend::EngineFallbackListBuilder_v8
Definition: cudnn_frontend_EngineFallbackList.h:120
cudnn_frontend::OperationGraph_v8
Definition: cudnn_frontend_OperationGraph.h:52
cudnn_frontend::EngineFallbackList_v8::operator=
EngineFallbackList_v8 & operator=(EngineFallbackList_v8 const &)=delete
cudnn_frontend::EngineFallbackList_v8::getFallbackList
auto getFallbackList() -> std::vector< ManagedOpaqueDescriptor > &
Definition: cudnn_frontend_EngineFallbackList.h:89
cudnn_frontend::EngineFallbackList_v8::m_engine_configs
std::vector< ManagedOpaqueDescriptor > m_engine_configs
Definition: cudnn_frontend_EngineFallbackList.h:113