1/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19#include "./utils.h"
20
21namespace tvm {
22namespace tir {
23
24String ScheduleError::RenderReport(const String& primitive) const {
25 IRModule mod = this->mod();
26 std::ostringstream os;
27
28 // get locations of interest
29 Array<ObjectRef> locs = LocationsOfInterest();
30 std::unordered_map<ObjectRef, String, ObjectPtrHash, ObjectPtrEqual> loc_obj_to_name;
31 int n_locs = locs.size();
32 std::string msg = DetailRenderTemplate();
33 PrinterConfig cfg;
34 cfg->syntax_sugar = false;
35 if (n_locs > 0) {
36 for (int i = 0; i < n_locs; ++i) {
37 std::string name = locs[i]->GetTypeKey() + '#' + std::to_string(i);
38 std::string src = "{" + std::to_string(i) + "}";
39 for (size_t pos; (pos = msg.find(src)) != std::string::npos;) {
40 msg.replace(pos, src.length(), name);
41 }
42 cfg->obj_to_annotate.Set(locs[i], name);
43 cfg->obj_to_underline.push_back(locs[i]);
44 }
45 }
46 os << "ScheduleError: An error occurred in the schedule primitive '" << primitive
47 << "'.\n\nThe IR with diagnostic is:\n"
48 << TVMScriptPrinter::Script(mod, cfg) << std::endl;
49
50 // print error message
51 os << "Error message: " << msg;
52 return os.str();
53}
54
55} // namespace tir
56} // namespace tvm
57