tqchen commented on a change in pull request #7686:
URL: https://github.com/apache/tvm/pull/7686#discussion_r596475663



##########
File path: include/tvm/ir/type.h
##########
@@ -181,6 +181,55 @@ class PointerType : public Type {
   TVM_DEFINE_OBJECT_REF_METHODS(PointerType, Type, PointerTypeNode);
 };
 
+/*!
+ * \brief Low-level texture type.
+ *
+ *  TextureType represents type hints in the TIR to be
+ *  passed to the final code generator.
+ *
+ *  TextureType should not occur in the high-level analysis.
+ *
+ * \sa TextureType
+ */
+class TextureTypeNode : public TypeNode {
+ public:
+  /*!
+   * \brief The base type of the texture.
+   */

Review comment:
       Given this is quite close to PointerType, perhaps we should think about 
instead introducing a scope flag (str for now) to the PointerType, instead of 
introducing a new type

##########
File path: src/runtime/thread_storage_scope.h
##########
@@ -57,6 +57,8 @@ enum class StorageRank {
   kWMMAMatrixB = 5,
   /*! \brief wmma scope memory of accumulator */
   kWMMAAccumulator = 6,
+  /*! \brief global scope texture memory */
+  kTexture = 7,

Review comment:
       I believe we do not need to introduce a special scope. Instead we can 
directly make texture a tag, for example: ```global.texture-weight```
   
   This would reduce special casing in thread hierachy calculations. We should 
actually also remove WMMA later

##########
File path: src/tir/transforms/texture_flatten.cc
##########
@@ -0,0 +1,330 @@
+/*
+ * 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.
+ */
+
+/*!
+ * \file texture_flatten.cc
+ * \brief Flattens texture from multi-dimensional array to 2D buffer access
+ */
+
+#include <tvm/arith/analyzer.h>
+#include <tvm/runtime/device_api.h>
+#include <tvm/runtime/registry.h>
+#include <tvm/target/target_info.h>
+#include <tvm/te/operation.h>
+#include <tvm/tir/analysis.h>
+#include <tvm/tir/buffer.h>
+#include <tvm/tir/builtin.h>
+#include <tvm/tir/expr.h>
+#include <tvm/tir/op.h>
+#include <tvm/tir/stmt.h>
+#include <tvm/tir/stmt_functor.h>
+#include <tvm/tir/transform.h>
+
+#include <unordered_map>
+#include <stack>
+
+#include "../../arith/ir_visitor_with_analyzer.h"
+#include "../../runtime/thread_storage_scope.h"
+#include "../../runtime/texture.h"
+#include "../ir/buffer_common.h"
+#include "arg_binder.h"
+#include "ir_utils.h"
+
+namespace tvm {
+namespace tir {
+namespace {
+
+using runtime::IsTextureStorage;
+using runtime::DefaultTextureLayoutSeparator;
+using runtime::ApplyTexture2DFlattening;
+
+inline PrimExpr SimplifyOffset(const Array<PrimExpr>& shape, const 
Array<PrimExpr>& index) {
+  PrimExpr base = make_const(DataType::Int(32), 0);
+  ICHECK_EQ(shape.size(), index.size());
+  arith::Analyzer ana;
+  if (index.size() > 0) {
+    PrimExpr offset = index[0];
+    for (size_t i = 1; i < index.size(); ++i) {
+      offset = MergeMulMod(&ana, offset * shape[i] + index[i]);

Review comment:
       I am not sure we would need this(through buffer common). MergeMulMod is 
a quite legacy function that needs to be simplified later, and ideally we 
should simply rely on analzyer simplify and leave the Buffer impl as it is




----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to