forked from neo-ai/tvm
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[TensorIR][M2a] Structural Error Reporting (apache#8121)
This PR is part of the TensorIR upstreaming effort (apache#7527), stage M2a. In this PR, we implemented ScheduleError, an error reporting mechanism for schedule primitives to report user-face error messages, with the functionality of rendering the TIR out in the TVM script syntax. This set of APIs allows future improvement of error location rendering, e.g. more colorful rendering mechanisms like synr does. Co-authored-by: Siyuan Feng <Hzfengsy@sjtu.edu.cn> Co-authored-by: Bohan Hou <32121147+spectrometerHBH@users.noreply.github.com> Co-authored-by: Ruihang Lai <lairuihangdongdong@qq.com> Co-authored-by: Hongyi Jin <3231950289@qq.com> Co-authored-by: Wuwei Lin <wuwei@apache.org> Co-authored-by: Tristan Konolige <tristan.konolige@gmail.com> Co-authored-by: Siyuan Feng <Hzfengsy@sjtu.edu.cn> Co-authored-by: Bohan Hou <32121147+spectrometerHBH@users.noreply.github.com> Co-authored-by: Ruihang Lai <lairuihangdongdong@qq.com> Co-authored-by: Hongyi Jin <3231950289@qq.com> Co-authored-by: Wuwei Lin <wuwei@apache.org> Co-authored-by: Tristan Konolige <tristan.konolige@gmail.com>
- Loading branch information
1 parent
718f2e3
commit 39adf51
Showing
11 changed files
with
296 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
#include "./utils.h" | ||
|
||
namespace tvm { | ||
namespace tir { | ||
|
||
String ScheduleError::RenderReport() const { | ||
IRModule mod = this->mod(); | ||
std::ostringstream os; | ||
os << "ScheduleError: An error occurred in the schedule primitive '" << this->primitive() | ||
<< "'.\n\nThe IR is:\n" | ||
<< AsTVMScript(mod); | ||
Array<ObjectRef> locs = LocationsOfInterest(); | ||
int n_locs = locs.size(); | ||
std::vector<String> roi_names; | ||
roi_names.reserve(n_locs); | ||
if (n_locs > 0) { | ||
os << "Regions of interest:\n"; | ||
for (const ObjectRef& obj : locs) { | ||
String name = obj->GetTypeKey() + '#' + std::to_string(roi_names.size()); | ||
os << name << "\n" << obj; | ||
roi_names.emplace_back(std::move(name)); | ||
} | ||
os << "\n"; | ||
} | ||
std::string msg = DetailRenderTemplate(); | ||
for (int i = 0; i < n_locs; ++i) { | ||
std::string src = "{" + std::to_string(i) + "}"; | ||
for (size_t pos; (pos = msg.find(src)) != std::string::npos;) { | ||
msg.replace(pos, src.length(), roi_names[i]); | ||
} | ||
} | ||
os << "Error message: " << msg; | ||
return os.str(); | ||
} | ||
|
||
} // namespace tir | ||
} // namespace tvm |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
#ifndef TVM_TIR_SCHEDULE_ERROR_H_ | ||
#define TVM_TIR_SCHEDULE_ERROR_H_ | ||
|
||
#include <tvm/tir/schedule/state.h> | ||
|
||
namespace tvm { | ||
namespace tir { | ||
|
||
/*! \brief Error that happens during TensorIR scheduling */ | ||
class ScheduleError : public tvm::runtime::Error { | ||
public: | ||
/*! \brief Base constructor */ | ||
ScheduleError() : tvm::runtime::Error("") {} | ||
/*! \brief The error occurred in this scheduling primitive */ | ||
virtual String primitive() const = 0; | ||
/*! \brief The error occurred in this IRModule */ | ||
virtual IRModule mod() const = 0; | ||
/*! \brief The locations of interest that we want to point out */ | ||
virtual Array<ObjectRef> LocationsOfInterest() const = 0; | ||
/*! | ||
* \brief Returns an error string template for rendering, corresponds to the "detail" mode. | ||
* \sa ScheduleErrorRenderLevel | ||
* \note The template is a string, e.g. | ||
* "Some error occurred on block {0} and loop {1} blah blah" | ||
* And renderer will replace {0} and {1} according to the list provided LocationsOfInterest. Right | ||
* now it only printed out all the locations in plain text, but in the future, we may want to mark | ||
* the IR with underscores and attach names to each location of interest, like what synr does. | ||
*/ | ||
virtual String DetailRenderTemplate() const = 0; | ||
/*! | ||
* \brief Returns an error string without needing to render, corresponds to the "fast" mode | ||
* \sa ScheduleErrorRenderLevel | ||
*/ | ||
virtual String FastErrorString() const = 0; | ||
/*! \brief Render the ScheduleError with the template provided by `DetailRenderTemplate` */ | ||
String RenderReport() const; | ||
}; | ||
|
||
} // namespace tir | ||
} // namespace tvm | ||
|
||
#endif // TVM_TIR_SCHEDULE_ERROR_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.