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/06/24 15:34:03 UTC

[GitHub] [tvm] csullivan commented on a diff in pull request #11549: [HEXAGON] Initial clip operator for Hexagon

csullivan commented on code in PR #11549:
URL: https://github.com/apache/tvm/pull/11549#discussion_r906178546


##########
tests/python/contrib/test_hexagon/topi/test_clip.py:
##########
@@ -0,0 +1,127 @@
+# 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.
+
+# pylint: disable=invalid-name
+
+import pytest
+import numpy as np
+
+from tvm import te, topi
+
+import tvm.testing
+from tvm.topi import testing
+from tvm.contrib.hexagon.build import HexagonLauncher
+import tvm.topi.hexagon.slice_ops as sl
+from ..infrastructure import allocate_hexagon_array, transform_numpy
+
+input_layout = tvm.testing.parameter(
+    "nhwc-8h2w32c2w-2d",
+)
+
+
+@tvm.testing.fixture
+def input_np(input_shape, dtype):
+    return np.random.random(input_shape).astype(dtype)
+
+
+@tvm.testing.fixture
+def transformed_expected_output_np(expected_output_np, output_layout):
+    return transform_numpy(expected_output_np, "nhwc", output_layout)
+
+
+@tvm.testing.fixture
+def transformed_input_np(input_np, input_layout):
+    return transform_numpy(input_np, "nhwc", input_layout)
+
+
+class TestClipSlice:
+    input_shape, output_shape, A_min, A_max, output_layout, dtype = tvm.testing.parameters(
+        ([1, 8, 4, 32], [1, 8, 4, 32], 0.1, 0.5, "nhwc-8h2w32c2w-2d", "float16")
+    )
+
+    @tvm.testing.fixture
+    def expected_output_np(self, input_np, A_min, A_max):
+        ref_np = np.clip(input_np, A_min, A_max)
+        return ref_np
+
+    @tvm.testing.requires_hexagon
+    def test_clip_slice(
+        self,
+        input_shape,
+        output_shape,
+        input_np,
+        input_layout,
+        output_layout,
+        dtype,
+        A_min,
+        A_max,
+        transformed_input_np,
+        transformed_expected_output_np,
+        hexagon_session,
+    ):
+        # establish target and input placeholder
+        target_hexagon = tvm.target.hexagon("v68")
+        A = te.placeholder(input_shape, name="A", dtype=dtype)
+
+        # get the compute function and schedule
+        M = sl.clip_compute(A, A_min, A_max)
+
+        # Assume layout is nhwc-8h2w32c2w-2d
+        tir_schedule = sl.clip_schedule(M, A, output_layout, input_layout)
+        sch = tir_schedule.mod
+
+        # build the function
+        with tvm.transform.PassContext(opt_level=3):
+            func = tvm.build(
+                sch, [A, M], tvm.target.Target(target_hexagon, host=target_hexagon), name="clip"

Review Comment:
   Hi @jcoplin-quic, with TIR schedules you'll want to pass in the module, sch.mod, in which case you don't need the tensor list as @Lunderberg pointed out.



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