CUDNN Frontend API 8.3.0

cudnn_frontend_EngineFallbackList.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 #include <numeric>
27
28 namespace cudnn_frontend {
29
30 auto static get_fallback_engine_list(cudnnBackendDescriptorType_t mode, const std::string &opGraphTag) -> std::vector<int> {
31 auto major_version = cudnnGetVersion() / 1000;
32
33 auto minor_version = (cudnnGetVersion() / 100) % 10;
34 if (major_version >= 8) {
35 if (minor_version <= 2) {
40 if (mode == CUDNN_BACKEND_OPERATION_CONVOLUTION_FORWARD_DESCRIPTOR) {
41 if (opGraphTag.find("bias") == std::string::npos) {
42 std::vector<int> engine_list(50);
43 std::iota(engine_list.begin(), engine_list.end(), 0);
44 return engine_list;
45 } else {
46 return {11,0};
47 }
48 } else if (mode == CUDNN_BACKEND_OPERATION_CONVOLUTION_BACKWARD_DATA_DESCRIPTOR) {
49 std::vector<int> engine_list(61);
50 std::iota(engine_list.begin(), engine_list.end(), 0);
51 return engine_list;
52 } else if (mode == CUDNN_BACKEND_OPERATION_CONVOLUTION_BACKWARD_FILTER_DESCRIPTOR) {
53 return {0, 1, 20};
54 } else {
55 return {};
56 }
57 } else {
58 if (mode == CUDNN_BACKEND_OPERATION_CONVOLUTION_FORWARD_DESCRIPTOR) {
59 if (opGraphTag.find("bias") == std::string::npos) {
60 return {0, 1, 28};
61 } else {
62 return {};
63 }
64 } else if (mode == CUDNN_BACKEND_OPERATION_CONVOLUTION_BACKWARD_DATA_DESCRIPTOR) {
65 return {0, 1, 25};
66 } else if (mode == CUDNN_BACKEND_OPERATION_CONVOLUTION_BACKWARD_FILTER_DESCRIPTOR) {
67 return {0, 1, 20};
68 } else {
69 return {};
70 }
71 }
72 } else {
73 return {};
74 }
75 }
76
77 class EngineFallbackList_v8 : public BackendDescriptor {
78 public:
79 friend class EngineFallbackListBuilder_v8;
80
81 std::string
82 describe() const override {
83 std::stringstream ss;
84 ss << "CUDNN_BACKEND_FALLBACK ENGINES :";
85 return ss.str();
86 }
87
88 auto
89 getFallbackList() -> std::vector<ManagedOpaqueDescriptor> & {
90 return m_engine_configs;
91 }
92
93 ~EngineFallbackList_v8() = default;
94
95 EngineFallbackList_v8(EngineFallbackList_v8 &&from)
96 : BackendDescriptor(from.get_desc(), from.get_status(), from.get_error()),
97 opGraph(from.opGraph),
98 mode(from.mode),
99 num_ops(from.num_ops),
100 opGraphTag(from.opGraphTag) {
101 m_engine_configs.swap(from.m_engine_configs);
102 }
103
104 private:
105 EngineFallbackList_v8() = default;
106 EngineFallbackList_v8(EngineFallbackList_v8 const &) = delete;
107 EngineFallbackList_v8 &
108 operator=(EngineFallbackList_v8 const &) = delete;
109
110 ManagedOpaqueDescriptor opGraph = nullptr;
111 cudnnBackendDescriptorType_t mode;
112 uint64_t num_ops;
113 std::vector<ManagedOpaqueDescriptor> m_engine_configs;
114 std::string opGraphTag;
115 };
116
120 class EngineFallbackListBuilder_v8 {
121 public:
126 auto
128 setOperationGraph(OperationGraph_v8 &opGraph_) -> EngineFallbackListBuilder_v8 & {
129 m_fallback_list.opGraph = opGraph_.get_desc();
130 m_fallback_list.opGraphTag = opGraph_.getTag();
131 m_fallback_list.num_ops = opGraph_.getOpCount();
132 return *this;
133 }
134 auto
135 setOperation(cudnnBackendDescriptorType_t mode) -> EngineFallbackListBuilder_v8 & {
136 m_fallback_list.mode = mode;
137 return *this;
138 }
141 EngineFallbackList_v8 &&
144 build() {
145 if (m_fallback_list.opGraph == nullptr) {
146 set_error_and_throw_exception(&m_fallback_list,
147 CUDNN_STATUS_BAD_PARAM,
148 "CUDNN_BACKEND_ENGINEHEUR_DESCRIPTOR: Check and Set the "
149 "CUDNN_ATTR_ENGINEHEUR_OPERATION_GRAPH field for heuristic");
150 return std::move(m_fallback_list);
151 };
152 auto fallback_engine_list = get_fallback_engine_list(m_fallback_list.mode, m_fallback_list.opGraphTag);
153 for (std::uint32_t i = 0; i < fallback_engine_list.size(); i++) {
154 #ifndef NV_CUDNN_DISABLE_EXCEPTION
155 try {
156 #endif
157 auto engine = cudnn_frontend::EngineBuilder_v8()
158 .setGlobalEngineIdx(fallback_engine_list[i])
159 .setOperationGraph(m_fallback_list.opGraph)
160 .build();
161 auto engine_config = cudnn_frontend::EngineConfigBuilder_v8().setEngine(engine).build();
162 m_fallback_list.m_engine_configs.emplace_back(engine_config.get_desc());
163 #ifndef NV_CUDNN_DISABLE_EXCEPTION
164 } catch (cudnn_frontend::cudnnException &e) {
165 continue;
166 }
167 #endif
168 }
169 getLogger() << "[cudnn_frontend] " << m_fallback_list << std::endl;
170 return std::move(m_fallback_list);
171 }
172
173 explicit EngineFallbackListBuilder_v8() = default;
174 ~EngineFallbackListBuilder_v8() = default;
175 EngineFallbackListBuilder_v8(EngineFallbackListBuilder_v8 &&) = delete;
176 EngineFallbackListBuilder_v8(EngineFallbackListBuilder_v8 const &) = delete;
177 EngineFallbackListBuilder_v8 &
178 operator=(EngineFallbackListBuilder_v8 const &) = delete;
179
180 private:
181 EngineFallbackList_v8 m_fallback_list;
182 };
183 }
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