tqchen commented on code in PR #16254:
URL: https://github.com/apache/tvm/pull/16254#discussion_r1430166620


##########
tests/python/relax/test_backend_dispatch_sort_scan.py:
##########
@@ -0,0 +1,415 @@
+# 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.
+
+import pytest
+
+import tvm
+import tvm.script
+import tvm.testing
+from tvm.script import relax as R, tir as T, ir as I
+
+from tvm.relax.backend import DispatchSortScan
+from tvm.ir.base import assert_structural_equal
+
+
+def test_dispatch_cumsum():
+    @I.ir_module
+    class Before:
+        I.module_global_infos({"vdevice": [I.vdevice("cuda", 0), 
I.vdevice("llvm", 0)]})
+
+        @R.function
+        def foo(x: R.Tensor((2, 3), "float32", "llvm")):
+            with R.dataflow():
+                gv = R.cumsum(x, axis=1, dtype="float64")
+                R.output(gv)
+            return gv
+
+    @I.ir_module
+    class Expected:
+        I.module_global_infos({"vdevice": [I.vdevice("cuda", 0), 
I.vdevice("llvm", 0)]})
+
+        @T.prim_func(private=True)
+        def cumsum(var_A: T.handle, out_buf: T.Buffer((T.int64(2), 
T.int64(3)), "float64")):
+            T.func_attr({"tir.noalias": T.bool(True)})
+            A = T.match_buffer(var_A, (T.int64(2), T.int64(3)), 
offset_factor=1)
+            with T.block("cumsum_generic"):
+                T.reads(A[T.int64(0) : T.int64(2), T.int64(0) : T.int64(3)])
+                T.writes(out_buf[T.int64(0) : T.int64(2), T.int64(0) : 
T.int64(3)])
+                for fused in T.parallel(T.int64(2)):
+                    out_buf[
+                        fused * T.int64(3) // T.int64(3), fused * T.int64(3) % 
T.int64(3)
+                    ] = T.Cast(
+                        "float64",
+                        A[fused * T.int64(3) // T.int64(3), fused * T.int64(3) 
% T.int64(3)],
+                    )
+                    for _k in range(T.int64(2)):
+                        out_buf[
+                            (fused * T.int64(3) + (_k + T.int64(1))) // 
T.int64(3),
+                            (fused * T.int64(3) + (_k + T.int64(1))) % 
T.int64(3),
+                        ] = out_buf[
+                            (fused * T.int64(3) + (_k + T.int64(1) - 
T.int64(1))) // T.int64(3),
+                            (fused * T.int64(3) + (_k + T.int64(1) - 
T.int64(1))) % T.int64(3),
+                        ] + T.Cast(
+                            "float64",
+                            A[
+                                (fused * T.int64(3) + (_k + T.int64(1))) // 
T.int64(3),
+                                (fused * T.int64(3) + (_k + T.int64(1))) % 
T.int64(3),
+                            ],
+                        )
+
+        @R.function
+        def foo(
+            x: R.Tensor((2, 3), dtype="float32", vdevice="llvm")
+        ) -> R.Tensor((2, 3), dtype="float64", vdevice="llvm"):
+            cls = Expected
+            with R.dataflow():
+                gv = R.call_tir(cls.cumsum, (x,), out_sinfo=R.Tensor((2, 3), 
dtype="float64"))
+                R.output(gv)
+            return gv
+
+    mod = DispatchSortScan()(Before)
+    assert_structural_equal(mod, Expected, map_free_vars=True)
+
+
[email protected]("The emitted primfunc is not roundtripable, failed in 
build.")
+def test_dispatch_cumsum_cuda():
+    @I.ir_module
+    class Before:

Review Comment:
   @jinhongyii is working on some fix, maybe he can chime in 



-- 
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: [email protected]

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

Reply via email to