CUDNN Frontend API 8.3.0

cudnn_frontend_EngineConfigGenerator.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_frontend.h>
26
27 namespace cudnn_frontend {
28
30 using executionPlans_t = std::vector<cudnn_frontend::ExecutionPlan>;
31 using Predicate = std::function<bool(cudnn_frontend::ExecutionPlan const &plan)>;
32 using GeneratorSource = std::function<cudnn_frontend::EngineConfigList(cudnn_frontend::OperationGraph &)>;
33
34 enum class CudnnFindSamplingTechnique {
35 CUDNN_FIND_SAMPLE_ONCE,
36 CUDNN_FIND_SAMPLE_MEDIAN_OF_THREE,
37 CUDNN_FIND_SAMPLE_TILL_STABLE
38 };
39
43 class EngineConfigGenerator {
44 private:
45 std::vector<GeneratorSource> engine_config_generators;
46
47 public:
50 EngineConfigGenerator(int const sourceSize, GeneratorSource const *sources) {
51 for (int i = 0; i < sourceSize; i++) {
52 engine_config_generators.push_back(sources[i]);
53 }
54 };
55
58 auto
59 generate_engine_config(cudnn_frontend::OperationGraph &opGraph) -> cudnn_frontend::EngineConfigList {
60 cudnn_frontend::EngineConfigList engine_configs;
61 for (auto fn : engine_config_generators) {
62 cudnn_frontend::EngineConfigList new_engine_config = fn(opGraph);
63 getLogger() << "[cudnn_frontend] Called engine config generator and produced "
64 << new_engine_config.size() << " configs." << std::endl;
65 std::copy(new_engine_config.begin(), new_engine_config.end(), std::back_inserter(engine_configs));
66 new_engine_config.clear();
67 }
68 return engine_configs;
69 }
70
72 auto
73 cudnnGetPlan(cudnnHandle_t handle, cudnn_frontend::OperationGraph &opGraph, Predicate pred) -> executionPlans_t;
74 auto
75 cudnnGetPlan(cudnnHandle_t handle, cudnn_frontend::OperationGraph &opGraph) -> executionPlans_t;
76
77
80 template <CudnnFindSamplingTechnique samplingTechnique>
81 auto
82 cudnnFindPlan(cudnnHandle_t handle,
83 cudnn_frontend::OperationGraph &opGraph,
84 cudnn_frontend::VariantPack const &variantPack,
85 Predicate pred) -> executionPlans_t;
86
87 template <CudnnFindSamplingTechnique samplingTechnique>
88 auto
89 cudnnFindPlan(cudnnHandle_t handle,
90 cudnn_frontend::OperationGraph &opGraph,
91 cudnn_frontend::VariantPack const &variantPack) -> executionPlans_t;
92
93 template <CudnnFindSamplingTechnique samplingTechnique>
94 auto
95 cudnnFindPlanAndCache(cudnnHandle_t handle,
96 cudnn_frontend::OperationGraph &opGraph,
97 cudnn_frontend::VariantPack const &variantPack,
98 cudnn_frontend::ExecutionPlanCache &cache,
99 Predicate pred = [](const cudnn_frontend::ExecutionPlan &) {return false;}) -> cudnn_frontend::ExecutionPlan;
100 };
101
105 static auto
106 filter(Predicate pred, executionPlans_t &plans) -> executionPlans_t {
107 executionPlans_t filtered_plans;
108 for (auto &plan : plans) {
109 getLogger() << "[cudnn_frontend] "<< "Filtered ";
110 if (!pred(plan)) {
111 getLogger() << "and Added ";
112 filtered_plans.emplace_back(std::move(plan));
113 }
114 getLogger() << filtered_plans.back().getTag() << std::endl;
115 }
116 getLogger() << "[cudnn_frontend] Filtered plans count " << filtered_plans.size() << std::endl;
117 return filtered_plans;
118 }
119 }
cudnn_frontend::CudnnFindSamplingTechnique::CUDNN_FIND_SAMPLE_MEDIAN_OF_THREE
Sample 3 times and take median.
cudnn_frontend::getLogger
ConditionalStreamer & getLogger()
Definition: cudnn_frontend_Logging.h:72
cudnn_frontend::CudnnFindSamplingTechnique::CUDNN_FIND_SAMPLE_TILL_STABLE
Sample multiple times till stable.
cudnn_frontend::ExecutionPlan_v8
Definition: cudnn_frontend_ExecutionPlan.h:51
cudnn_frontend::EngineConfigGenerator::EngineConfigGenerator
EngineConfigGenerator(int const sourceSize, GeneratorSource const *sources)
Definition: cudnn_frontend_EngineConfigGenerator.h:50
cudnn_frontend::Predicate
std::function< bool(cudnn_frontend::ExecutionPlan const &plan)> Predicate
Definition: cudnn_frontend_EngineConfigGenerator.h:31
cudnn_frontend::filter
static auto filter(Predicate pred, executionPlans_t &plans) -> executionPlans_t
Definition: cudnn_frontend_EngineConfigGenerator.h:106
cudnn_frontend::EngineConfigGenerator::generate_engine_config
auto generate_engine_config(cudnn_frontend::OperationGraph &opGraph) -> cudnn_frontend::EngineConfigList
Definition: cudnn_frontend_EngineConfigGenerator.h:59
cudnn_frontend::CudnnFindSamplingTechnique
CudnnFindSamplingTechnique
Definition: cudnn_frontend_EngineConfigGenerator.h:34
cudnn_frontend::EngineConfigGenerator::engine_config_generators
std::vector< GeneratorSource > engine_config_generators
Definition: cudnn_frontend_EngineConfigGenerator.h:45
cudnn_frontend::EngineConfigGenerator
Definition: cudnn_frontend_EngineConfigGenerator.h:43
cudnn_frontend::executionPlans_t
std::vector< cudnn_frontend::ExecutionPlan > executionPlans_t
Variety of renames.
Definition: cudnn_frontend_EngineConfigGenerator.h:30
cudnn_frontend.h
cudnn_frontend::VariantPack_v8
Definition: cudnn_frontend_VariantPack.h:52
cudnn_frontend::GeneratorSource
std::function< cudnn_frontend::EngineConfigList(cudnn_frontend::OperationGraph &)> GeneratorSource
Definition: cudnn_frontend_EngineConfigGenerator.h:32
cudnn_frontend
Definition: cudnn_backend_base.h:29
cudnn_frontend::CudnnFindSamplingTechnique::CUDNN_FIND_SAMPLE_ONCE
Sample once quick but may have unstable values.
cudnn_frontend::EngineConfigList
std::vector< ManagedOpaqueDescriptor > EngineConfigList
Definition: cudnn_frontend_EngineConfig.h:248
cudnn_frontend::OperationGraph_v8
Definition: cudnn_frontend_OperationGraph.h:52
cudnn_frontend::ExecutionPlanCache_v2
Definition: cudnn_frontend_ExecutionPlanCache.h:141