CUDNN Frontend API  8.2.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 {
32  float time_ms;
33 };
34 
36 using executionOptions_t = std::vector<struct executionOption>;
37 using executionPlans_t = std::vector<cudnn_frontend::ExecutionPlan>;
38 using Predicate = std::function<bool(cudnn_frontend::ExecutionPlan const &plan)>;
39 using GeneratorSource = std::function<cudnn_frontend::EngineConfigList(cudnn_frontend::OperationGraph &)>;
40 
45 };
46 
51  private:
52  std::vector<GeneratorSource> engine_config_generators;
53 
54  public:
57  EngineConfigGenerator(int const sourceSize, GeneratorSource const *sources) {
58  for (int i = 0; i < sourceSize; i++) {
59  engine_config_generators.push_back(sources[i]);
60  }
61  };
62 
65  auto
67  cudnn_frontend::EngineConfigList engine_configs;
68  for (auto fn : engine_config_generators) {
69  cudnn_frontend::EngineConfigList new_engine_config = fn(opGraph);
70  std::copy(new_engine_config.begin(), new_engine_config.end(), std::back_inserter(engine_configs));
71  new_engine_config.clear();
72  }
73  return engine_configs;
74  }
75 
77  auto
78  cudnnGetPlan(cudnnHandle_t handle, cudnn_frontend::OperationGraph &&opGraph, Predicate pred) -> executionPlans_t;
79 
82  template <CudnnFindSamplingTechnique samplingTechnique>
83  auto
84  cudnnFindPlan(cudnnHandle_t handle,
86  cudnn_frontend::VariantPack &variantPack,
88 };
89 
93 auto
95  executionPlans_t filtered_plans;
96  for (auto &plan : plans) {
97  if (!pred(plan)) {
98  filtered_plans.emplace_back(std::move(plan));
99  }
100  }
101  return filtered_plans;
102 }
103 }
EngineConfigGenerator(int const sourceSize, GeneratorSource const *sources)
std::function< bool(cudnn_frontend::ExecutionPlan const &plan)> Predicate
auto generate_engine_config(cudnn_frontend::OperationGraph &opGraph) -> cudnn_frontend::EngineConfigList
float time_ms
One can get the underlying EngineConfig from the ExecutionPlan.
std::vector< cudnn_frontend::ExecutionPlan > executionPlans_t
std::function< cudnn_frontend::EngineConfigList(cudnn_frontend::OperationGraph &)> GeneratorSource
std::vector< struct executionOption > executionOptions_t
Variety of renames.
auto filter(Predicate pred, executionPlans_t &plans) -> executionPlans_t
Sample once quick but may have unstable values.
std::vector< ManagedOpaqueDescriptor > EngineConfigList