You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tvm.apache.org by GitBox <gi...@apache.org> on 2022/08/22 20:35:49 UTC

[GitHub] [tvm] AndrewZhaoLuo commented on a diff in pull request #12352: [TIR] Add pass to check for out of bounds memory access

AndrewZhaoLuo commented on code in PR #12352:
URL: https://github.com/apache/tvm/pull/12352#discussion_r951067578


##########
src/tir/analysis/oob_checker.cc:
##########
@@ -0,0 +1,130 @@
+/*
+ * 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.
+ */
+
+/*!
+ *  Out of bounds array access static analyzer.
+ */
+
+#include <tvm/tir/transform.h>
+
+#include "../../arith/ir_visitor_with_analyzer.h"
+#include "../../printer/text_printer.h"
+#include "../schedule/error.h"
+
+namespace tvm {
+namespace tir {
+namespace transform {
+struct OOBLocation {
+  Buffer buf;
+  size_t dimension;
+  ObjectRef index;
+  arith::IntSet index_bounds;
+  arith::IntSet shape_bounds;
+};
+
+class OOBError : public ScheduleError {
+ public:
+  OOBError(IRModule mod, std::vector<OOBLocation> locations) : mod_(mod), locations_(locations) {}
+  String FastErrorString() const final { return "Out of bound memory access"; }
+
+  String DetailRenderTemplate() const final {
+    std::stringstream s;
+    for (const auto& oob : locations_) {
+      s << "Out of bounds memory access on buffer " << oob.buf->name << " dimension "

Review Comment:
   nit: It might be nice to have a test where you show the full rendered strings.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org