CUDNN Frontend API 8.3.0

cudnn_frontend_Errata.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 #include "contrib/nlohmann/json/json.hpp"
24
25 #include "../include/cudnn_frontend_Logging.h"
26
27 #include <cstdlib>
28 #include <fstream>
29 #pragma once
30
31 using json = nlohmann::json;
32
33 namespace cudnn_frontend {
34
35 // Loads the json handle from the json file
36 // json file is defined by environment variable
37 // CUDNN_ERRATA_JSON_FILE. If the environment variable
38 // is not set the value set in the API is considered.
39 static bool
40 load_from_config(json &json_handle, const std::string & errata_json) {
41 const char * err_json = std::getenv("CUDNN_ERRATA_JSON_FILE");
42 if (err_json == NULL && errata_json == "") {return false;}
43 if (err_json == NULL) { err_json = errata_json.c_str();}
44 std::ifstream ifs(err_json, std::ifstream::in);
45 if (!ifs.is_open() || !ifs.good()) {return false;}
46 ifs >> json_handle;
47 return true;
48 }
49
50 template <typename T>
51 static bool
52 check_rule(const json &json_handle, const std::string & executionPlanTag,
53 cudnnHandle_t handle, T fn) {
54 std::string operation = json_handle["operation"];
55 int64_t engine = json_handle["engine"];
56 uint64_t cudnn_start = 0;
57 uint64_t cudnn_end = -1;
58 if (json_handle.contains("cudnn_version_start")) {
59 cudnn_start = json_handle["cudnn_version_start"];
60 }
61 if (json_handle.contains("cudnn_version_end")) {
62 cudnn_end = json_handle["cudnn_version_end"];
63 }
64 std::string tag_prefix = operation + "_eng" + std::to_string(engine) + "_";
65 std::string mod_tag = executionPlanTag + "_";
66 bool blocked =
67 tag_prefix.size() <= mod_tag.size() &&
68 std::equal(tag_prefix.begin(), tag_prefix.end(), mod_tag.begin()) &&
69 CUDNN_VERSION >= cudnn_start &&
70 CUDNN_VERSION < cudnn_end;
71
72 if (blocked && json_handle.contains("knob")) { // Short circuit if operation and engine do not match
73 for (auto& kv : json_handle["knob"]) {
74 blocked = blocked &&
75 (executionPlanTag.find(kv) != std::string::npos);
76 }
77 }
78
79 blocked = blocked && fn();
80 return blocked;
81
82 (void) handle;
83 }
84
85 // Takes in an initialzed json handle and checks if it satisfies the
86 // condition for running it. Returns true if the given executionPlanTag
87 // is faulty.
88 template <typename T>
89 static bool
90 check_errata(const json &json_handle, const std::string & executionPlanTag,
91 cudnnHandle_t handle, T fn) {
92
93 cudnn_frontend::getLogger() << "[cudnn_frontend] " << "Verifying " << executionPlanTag;
94 for (auto const &rule : json_handle["rules"]) {
95 if (check_rule<T>(rule, executionPlanTag, handle, fn)) {
96 cudnn_frontend::getLogger() << ". Blocking." << std::endl;
97 return true;
98 }
99 }
100
101 cudnn_frontend::getLogger() << ". Passed." << std::endl;
102 return false;
103 }
104
105 }
cudnn_frontend::getLogger
ConditionalStreamer & getLogger()
Definition: cudnn_frontend_Logging.h:72
nlohmann::to_string
NLOHMANN_BASIC_JSON_TPL_DECLARATION std::string to_string(const NLOHMANN_BASIC_JSON_TPL &j)
user-defined to_string function for JSON values
Definition: json.hpp:25855
nlohmann::basic_json::contains
bool contains(KeyT &&key) const
check the existence of an element in a JSON object
Definition: json.hpp:21558
nlohmann::basic_json
a class to store JSON values
Definition: json.hpp:3366
json.hpp
cudnn_frontend::check_errata
static bool check_errata(const json &json_handle, const std::string &executionPlanTag, cudnnHandle_t handle, T fn)
Definition: cudnn_frontend_Errata.h:90
cudnn_frontend::check_rule
static bool check_rule(const json &json_handle, const std::string &executionPlanTag, cudnnHandle_t handle, T fn)
Definition: cudnn_frontend_Errata.h:52
nlohmann::detail::void
j template void())
Definition: json.hpp:4061
cudnn_frontend
Definition: cudnn_backend_base.h:29
nlohmann::json
basic_json<> json
default JSON class
Definition: json.hpp:3390
cudnn_frontend::load_from_config
static bool load_from_config(json &json_handle, const std::string &errata_json)
Definition: cudnn_frontend_Errata.h:40