junrushao commented on code in PR #15487:
URL: https://github.com/apache/tvm/pull/15487#discussion_r1296724715


##########
tests/python/relax/test_frontend_nn_extern_module.py:
##########
@@ -0,0 +1,122 @@
+# 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 numpy as np
+import pytest
+
+import tvm
+from tvm import relax
+from tvm.relax.backend.contrib.cutlass import partition_for_cutlass
+from tvm.script import ir as I
+from tvm.script import relax as R
+from tvm.script import tir as T
+from tvm.tir import Var
+from tvm.relax.frontend import nn
+from tvm.relax.frontend.nn import spec
+from tvm.relax.testing import get_relax_matmul_module
+
+
+has_cutlass = tvm.get_global_func("relax.ext.cutlass", True)
+
+cutlass_enabled = pytest.mark.skipif(
+    not has_cutlass,
+    reason="CUTLASS not enabled.",
+)
+
+pytestmark = [cutlass_enabled]
+
+
[email protected](autouse=True)
+def reset_seed():
+    np.random.seed(0)
+
+
[email protected](
+    "shape_a, shape_b, shape_out, dtype, value_table, var_table",
+    [
+        (("n", 4, 16), ("n", 16, 8), ("n", 4, 8), "float16", {"n": 16}, {"n": 
Var("n", "int64")}),
+    ],
+)
+def test_extern_module(shape_a, shape_b, shape_out, dtype, value_table, 
var_table):
+    def shape_converter(shape, table):
+        out_shape = []
+        for value in shape:
+            if isinstance(value, str):
+                out_shape.append(table[value])
+            else:
+                out_shape.append(value)
+        return tuple(out_shape)
+
+    Module = get_relax_matmul_module(
+        shape_converter(shape_a, var_table),
+        shape_converter(shape_b, var_table),
+        dtype,
+    )
+
+    mod = partition_for_cutlass(Module, True)
+    codegen_pass = relax.transform.RunCodegen({"cutlass": {"sm": 80, 
"find_first_valid": True}})
+    mod = codegen_pass(mod)

Review Comment:
   iiuc this part is only used for generating `./tmp/cutlass.o` - is that 
correct?
   
   if so, is it possible to:
   1) use a much simpler and more unit-testable source code? for example:
   
   ```C++
   void Add(NDArray a, NDArray b, NDArray c) {
     ICHECK(a->ndim == 0 && a->dtype == DataType::Float(32));
     ICHECK(b->ndim == 0 && b->dtype == DataType::Float(32));
     ICHECK(c->ndim == 0 && c->dtype == DataType::Float(32));
     *(reinterpret_cast<double*>(c->data)) = 
*(reinterpret_cast<double*>(a->data)) + *(reinterpret_cast<double*>(b->data));
   }
   ```
   
   2) isolate this logic to a separate method, say, "def 
generate_test_module(path: str)"



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