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/12/07 01:40:20 UTC
[GitHub] [tvm] cconvey opened a new pull request, #13569: WIP [hexagon][tir][testing] same-module call tests
cconvey opened a new pull request, #13569:
URL: https://github.com/apache/tvm/pull/13569
Add unit tests for one PrimFunc calling into another PrimFunc in the same IRModule.
--
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
[GitHub] [tvm] cconvey commented on a diff in pull request #13569: [tir][testing] Enable intra-IRModule primfunc call
Posted by "cconvey (via GitHub)" <gi...@apache.org>.
cconvey commented on code in PR #13569:
URL: https://github.com/apache/tvm/pull/13569#discussion_r1083317912
##########
tests/python/contrib/test_hexagon/test_call_tir.py:
##########
@@ -0,0 +1,248 @@
+# 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.
+
+""" Various tests related to the (WIP) support for having
+one PrimFunc call another PrimFunc within the same IRModule.
+"""
+
+from typing import List
+import pytest
+import numpy as np
+
+import tvm
+import tvm.testing
+import tvm.script
+from tvm.script import tir as T
+
+from tvm.contrib.hexagon.session import Session
+from tvm.contrib.hexagon import allocate_hexagon_array
+from .infrastructure import get_hexagon_target
+
+# NOTE(cconvey): These pylint warnings should be re-enabled as TVM's pylint configuration matures.
+# pylint: disable=missing-function-docstring,no-self-argument,invalid-name
+# pylint: disable=redefined-outer-name,missing-class-docstring
+
+# --------------------------------------------------------------------------------------------------
+# Test parameters
+# --------------------------------------------------------------------------------------------------
+
+# The shape of the original (unsplit) tensors.
+# We assume that each shape describes a non-empty 2D tensor.
+original_shape = tvm.testing.parameter(
+ # degenerate cases...
+ [1, 1],
+ [1, 2],
+ [2, 1],
+ [2, 2],
+ # arbitrary, provided for variety
+ [5, 3],
+ [3, 5],
+)
+
+# This dtype is arbitrary, but it must match the dtype that's hardcoded into the
+# callee's function signature. E.g., 'a_data: T.Ptr[T.int8]'.
+#
+# Hopefully over time we'll find a way to soften this limitation, at least for
+# some approaches to PrimFunc-to-PrimFunc calls.
+dtype = tvm.testing.parameter("int8")
+
+# --------------------------------------------------------------------------------------------------
+# Helper functions / definitions...
+# --------------------------------------------------------------------------------------------------
+
+HEXAGON_TARGET_ = get_hexagon_target("v69")
+
+ENTRY_PRIMFUNC_NAME_ = "main"
+
+
+def get_reference_input_tensor_(shape: list, dtype: str) -> np.array:
+ assert len(shape) == 2
+
+ a = np.ndarray(shape, dtype=dtype)
+ np_dtype = a.dtype
+
+ if np_dtype.kind in ["i", "u"]:
+ # We allow overflow for integer types because it tends to be well-behaved
+ # and well-understood...
+ min_value = np.iinfo(np_dtype).min
+ max_value = np.iinfo(np_dtype).max
+
+ next_value = min_value
+
+ for i in range(shape[0]):
+ for j in range(shape[1]):
+ a[i, j] = next_value
+ next_value += 1
+
+ elif np_dtype.kind == "f":
+ # NOTE: For simplicity, we avoid test data that that require
+ # well-defined behavior on floating-point overflow.
+ # But it may be reasonable to test that in the future.
+ min_value = np.finfo(np_dtype).min
+ max_value = np.finfo(np_dtype).max
+
+ min_input_value = min_value / 2.0 + 1
Review Comment:
Thanks for the suggestion. AFAICT the code is using `min` correctly. Maybe you're thinking of `.tiny`?:
```
>>> np.finfo(float).min
-1.7976931348623157e+308
>>> np.finfo(float).min / 2
-8.988465674311579e+307
>>> np.finfo(float).tiny
2.2250738585072014e-308
```
Regarding `np.random.uniform`. I know this is common in TVM's tests, and `np.random.seed(...)` is definitely is an improvement for reproducibility.
Ideally we'd test with carefully chosen critical / boundary values, but that requires a level of analysis we usually don't have time to perform.
For situations like this, I prefer using test-values that are helpful to humans trying to debug failed tests. I suspect that regular intervals like these might help humans to spot trends regarding which particular input-tensor elements result in erroneous output-tensor elements.
--
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
[GitHub] [tvm] cconvey commented on a diff in pull request #13569: [tir][testing] Enable intra-IRModule primfunc call
Posted by "cconvey (via GitHub)" <gi...@apache.org>.
cconvey commented on code in PR #13569:
URL: https://github.com/apache/tvm/pull/13569#discussion_r1086976058
##########
include/tvm/ir/function.h:
##########
@@ -63,6 +63,43 @@ enum class CallingConv : int {
* - Implementation: defined by device runtime(e.g. runtime/cuda)
*/
kDeviceKernelLaunch = 2,
+ /*!
+ * \brief For functions only called by other functions within the same IR module.
+ *
+ * This calling convention exists to support one PrimFunc calling another PrimFunc
+ * within the same IRModule.
+ *
+ * Overview / Purpose:
+ *
+ * - This calling convention is intended only for PrimFuncs whose callers reside in
+ * the same IRModule. This is the only supported use case.
+ *
+ * - The details of the calling convention may change frequently as TVM evolves.
+ * Therefore users are discouraged from attempting to use this calling convention
+ * outside of the supported use case(s).
+ *
+ * Current mechanics / usage requirements:
+ *
+ * - A PrimFunc with this calling convention will NOT undergo any of the signature
+ * transformations provided by the MakePackedAPI pass.
+ *
+ * - Supported use cases, and their corresponding unit tests, are all expressed as
+ * TVMScript.
+ *
+ * - The callsite must use `T.call_extern`.
Review Comment:
Thanks for the feedback!
Could you clarify what you mean by "C calling convention" in this context?
I've only heard that term used to describe the mapping of C-language types to (e.g.) x86-64 ABI -compliant function calls.
But in this PR's context, the question (AFAICT) is how we map TVMScript callsite arguments to TVMScript formal parameters. So I'm not sure how this would relate to a C calling convention.
--
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
[GitHub] [tvm] cconvey commented on a diff in pull request #13569: [tir][testing] Enable intra-IRModule primfunc call
Posted by "cconvey (via GitHub)" <gi...@apache.org>.
cconvey commented on code in PR #13569:
URL: https://github.com/apache/tvm/pull/13569#discussion_r1083323804
##########
tests/python/contrib/test_hexagon/test_call_tir.py:
##########
@@ -0,0 +1,248 @@
+# 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.
+
+""" Various tests related to the (WIP) support for having
+one PrimFunc call another PrimFunc within the same IRModule.
+"""
+
+from typing import List
+import pytest
+import numpy as np
+
+import tvm
+import tvm.testing
+import tvm.script
+from tvm.script import tir as T
+
+from tvm.contrib.hexagon.session import Session
+from tvm.contrib.hexagon import allocate_hexagon_array
+from .infrastructure import get_hexagon_target
+
+# NOTE(cconvey): These pylint warnings should be re-enabled as TVM's pylint configuration matures.
+# pylint: disable=missing-function-docstring,no-self-argument,invalid-name
+# pylint: disable=redefined-outer-name,missing-class-docstring
+
+# --------------------------------------------------------------------------------------------------
+# Test parameters
+# --------------------------------------------------------------------------------------------------
+
+# The shape of the original (unsplit) tensors.
+# We assume that each shape describes a non-empty 2D tensor.
+original_shape = tvm.testing.parameter(
+ # degenerate cases...
+ [1, 1],
+ [1, 2],
+ [2, 1],
+ [2, 2],
+ # arbitrary, provided for variety
+ [5, 3],
+ [3, 5],
+)
+
+# This dtype is arbitrary, but it must match the dtype that's hardcoded into the
+# callee's function signature. E.g., 'a_data: T.Ptr[T.int8]'.
+#
+# Hopefully over time we'll find a way to soften this limitation, at least for
+# some approaches to PrimFunc-to-PrimFunc calls.
+dtype = tvm.testing.parameter("int8")
+
+# --------------------------------------------------------------------------------------------------
+# Helper functions / definitions...
+# --------------------------------------------------------------------------------------------------
+
+HEXAGON_TARGET_ = get_hexagon_target("v69")
+
+ENTRY_PRIMFUNC_NAME_ = "main"
+
+
+def get_reference_input_tensor_(shape: list, dtype: str) -> np.array:
+ assert len(shape) == 2
+
+ a = np.ndarray(shape, dtype=dtype)
+ np_dtype = a.dtype
+
+ if np_dtype.kind in ["i", "u"]:
+ # We allow overflow for integer types because it tends to be well-behaved
+ # and well-understood...
+ min_value = np.iinfo(np_dtype).min
+ max_value = np.iinfo(np_dtype).max
+
+ next_value = min_value
Review Comment:
Good idea. Turns out it's a bit moot, because I found an existing utility (tests/python/contrib/test_hexagon/pytest_util.py) that mostly does this already. I'm going to extended it a little and use it in an updated version of this PR.
##########
tests/python/contrib/test_hexagon/test_call_tir.py:
##########
@@ -0,0 +1,248 @@
+# 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.
+
+""" Various tests related to the (WIP) support for having
+one PrimFunc call another PrimFunc within the same IRModule.
+"""
+
+from typing import List
+import pytest
+import numpy as np
+
+import tvm
+import tvm.testing
+import tvm.script
+from tvm.script import tir as T
+
+from tvm.contrib.hexagon.session import Session
+from tvm.contrib.hexagon import allocate_hexagon_array
+from .infrastructure import get_hexagon_target
+
+# NOTE(cconvey): These pylint warnings should be re-enabled as TVM's pylint configuration matures.
+# pylint: disable=missing-function-docstring,no-self-argument,invalid-name
+# pylint: disable=redefined-outer-name,missing-class-docstring
+
+# --------------------------------------------------------------------------------------------------
+# Test parameters
+# --------------------------------------------------------------------------------------------------
+
+# The shape of the original (unsplit) tensors.
+# We assume that each shape describes a non-empty 2D tensor.
+original_shape = tvm.testing.parameter(
+ # degenerate cases...
+ [1, 1],
+ [1, 2],
+ [2, 1],
+ [2, 2],
+ # arbitrary, provided for variety
+ [5, 3],
+ [3, 5],
+)
+
+# This dtype is arbitrary, but it must match the dtype that's hardcoded into the
+# callee's function signature. E.g., 'a_data: T.Ptr[T.int8]'.
+#
+# Hopefully over time we'll find a way to soften this limitation, at least for
+# some approaches to PrimFunc-to-PrimFunc calls.
+dtype = tvm.testing.parameter("int8")
+
+# --------------------------------------------------------------------------------------------------
+# Helper functions / definitions...
+# --------------------------------------------------------------------------------------------------
+
+HEXAGON_TARGET_ = get_hexagon_target("v69")
+
+ENTRY_PRIMFUNC_NAME_ = "main"
+
+
+def get_reference_input_tensor_(shape: list, dtype: str) -> np.array:
+ assert len(shape) == 2
+
+ a = np.ndarray(shape, dtype=dtype)
+ np_dtype = a.dtype
+
+ if np_dtype.kind in ["i", "u"]:
+ # We allow overflow for integer types because it tends to be well-behaved
+ # and well-understood...
+ min_value = np.iinfo(np_dtype).min
+ max_value = np.iinfo(np_dtype).max
+
+ next_value = min_value
Review Comment:
Good idea. Turns out it's a bit moot, because I found an existing utility (`tests/python/contrib/test_hexagon/pytest_util.py`) that mostly does this already. I'm going to extended it a little and use it in an updated version of this PR.
--
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
[GitHub] [tvm] tqchen commented on a diff in pull request #13569: [tir][testing] Enable intra-IRModule primfunc call
Posted by "tqchen (via GitHub)" <gi...@apache.org>.
tqchen commented on code in PR #13569:
URL: https://github.com/apache/tvm/pull/13569#discussion_r1092462583
##########
include/tvm/ir/function.h:
##########
@@ -63,6 +63,43 @@ enum class CallingConv : int {
* - Implementation: defined by device runtime(e.g. runtime/cuda)
*/
kDeviceKernelLaunch = 2,
+ /*!
+ * \brief For functions only called by other functions within the same IR module.
+ *
+ * This calling convention exists to support one PrimFunc calling another PrimFunc
+ * within the same IRModule.
+ *
+ * Overview / Purpose:
+ *
+ * - This calling convention is intended only for PrimFuncs whose callers reside in
+ * the same IRModule. This is the only supported use case.
+ *
+ * - The details of the calling convention may change frequently as TVM evolves.
+ * Therefore users are discouraged from attempting to use this calling convention
+ * outside of the supported use case(s).
+ *
+ * Current mechanics / usage requirements:
+ *
+ * - A PrimFunc with this calling convention will NOT undergo any of the signature
+ * transformations provided by the MakePackedAPI pass.
+ *
+ * - Supported use cases, and their corresponding unit tests, are all expressed as
+ * TVMScript.
+ *
+ * - The callsite must use `T.call_extern`.
Review Comment:
Thanks for the discussion.
> The difference would be that a pass could modify the signature of a kIntraModule function (e.g. removing an unused argument from the signature, simultaneously updating all callsites), while a PackedFunc could not be modified without breaking the potential external callsites.
This have to do with linkage which is somewhat parallel to the calling convention. We should be able to modify a signature of a function if it is not being referred from outside (in our current case, no `global_symbol` attribute indicates a private linkage), and we can do such setups independent from the calling convention.
> it would enable assumptions of the final calling convention before it had been selected, mixing the different layers of abstraction
Indeed this is what we aim to avoid here. That is why normally we try to have pairs of(callsite intrinsic, and callee side calling convention annotations). For example,
- `InternalModuleCall` (callee side conv) and `call_internal`(caller side intrinsic) would make such pairing clear.
In the current proposal, we are trying to pair (`kIntraModule` and `call_extern`). Where previously in our convention `call_extern` was normally paired with C calling conv(mainly because we also can generate such calls).
BTW, I agree that it is OK to leave default lowering behavior unspecified, as long as the pairing is clear. But in this case, the possible confusion is that we already have lowering behavior for `call_extern` defined by our backend. So only leaving the callee site unspecified could leads to possible point of confusion.
So the main comment here is let us make sure our pairing is clear. Ideally we have a unique set of pairings, e.g. `call_extern` only maps to one callee-site calling conv. Introducing a extra intrinsic to pair with this one, or clarify that this is the only thing that call_extern pairs(in which case perhaps C calling conv is more proper) might be more clear.
The internal property have things to do with linkage and can be handled separately
--
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
[GitHub] [tvm] cconvey commented on a diff in pull request #13569: [tir][testing] Enable intra-IRModule primfunc call
Posted by "cconvey (via GitHub)" <gi...@apache.org>.
cconvey commented on code in PR #13569:
URL: https://github.com/apache/tvm/pull/13569#discussion_r1083323804
##########
tests/python/contrib/test_hexagon/test_call_tir.py:
##########
@@ -0,0 +1,248 @@
+# 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.
+
+""" Various tests related to the (WIP) support for having
+one PrimFunc call another PrimFunc within the same IRModule.
+"""
+
+from typing import List
+import pytest
+import numpy as np
+
+import tvm
+import tvm.testing
+import tvm.script
+from tvm.script import tir as T
+
+from tvm.contrib.hexagon.session import Session
+from tvm.contrib.hexagon import allocate_hexagon_array
+from .infrastructure import get_hexagon_target
+
+# NOTE(cconvey): These pylint warnings should be re-enabled as TVM's pylint configuration matures.
+# pylint: disable=missing-function-docstring,no-self-argument,invalid-name
+# pylint: disable=redefined-outer-name,missing-class-docstring
+
+# --------------------------------------------------------------------------------------------------
+# Test parameters
+# --------------------------------------------------------------------------------------------------
+
+# The shape of the original (unsplit) tensors.
+# We assume that each shape describes a non-empty 2D tensor.
+original_shape = tvm.testing.parameter(
+ # degenerate cases...
+ [1, 1],
+ [1, 2],
+ [2, 1],
+ [2, 2],
+ # arbitrary, provided for variety
+ [5, 3],
+ [3, 5],
+)
+
+# This dtype is arbitrary, but it must match the dtype that's hardcoded into the
+# callee's function signature. E.g., 'a_data: T.Ptr[T.int8]'.
+#
+# Hopefully over time we'll find a way to soften this limitation, at least for
+# some approaches to PrimFunc-to-PrimFunc calls.
+dtype = tvm.testing.parameter("int8")
+
+# --------------------------------------------------------------------------------------------------
+# Helper functions / definitions...
+# --------------------------------------------------------------------------------------------------
+
+HEXAGON_TARGET_ = get_hexagon_target("v69")
+
+ENTRY_PRIMFUNC_NAME_ = "main"
+
+
+def get_reference_input_tensor_(shape: list, dtype: str) -> np.array:
+ assert len(shape) == 2
+
+ a = np.ndarray(shape, dtype=dtype)
+ np_dtype = a.dtype
+
+ if np_dtype.kind in ["i", "u"]:
+ # We allow overflow for integer types because it tends to be well-behaved
+ # and well-understood...
+ min_value = np.iinfo(np_dtype).min
+ max_value = np.iinfo(np_dtype).max
+
+ next_value = min_value
Review Comment:
Good idea. Turns out it's a bit moot, because I found an existing utility (`tests/python/contrib/test_hexagon/pytest_util.py`) that mostly does this already. I'm going to extend it a little and use it in an updated version of this PR.
--
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
[GitHub] [tvm] cconvey commented on a diff in pull request #13569: [tir][testing] Enable intra-IRModule primfunc call
Posted by "cconvey (via GitHub)" <gi...@apache.org>.
cconvey commented on code in PR #13569:
URL: https://github.com/apache/tvm/pull/13569#discussion_r1092244842
##########
src/tir/transforms/plan_update_buffer_allocation_location.cc:
##########
@@ -111,6 +112,12 @@ class BufferAllocationLocator : public StmtExprMutator {
collector(func->body);
unmanaged_allocations_ = collector.unmanaged_allocations;
+ for (Var param : func->params) {
Review Comment:
I'd say that this PR's unit test already acts as a test case, because this change was needed to make that test pass.
--
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
[GitHub] [tvm] cconvey commented on a diff in pull request #13569: [tir][testing] Enable intra-IRModule primfunc call
Posted by "cconvey (via GitHub)" <gi...@apache.org>.
cconvey commented on code in PR #13569:
URL: https://github.com/apache/tvm/pull/13569#discussion_r1097637982
##########
src/tir/transforms/plan_update_buffer_allocation_location.cc:
##########
@@ -111,6 +112,12 @@ class BufferAllocationLocator : public StmtExprMutator {
collector(func->body);
unmanaged_allocations_ = collector.unmanaged_allocations;
+ for (Var param : func->params) {
Review Comment:
Update: This has now been merged via https://github.com/apache/tvm/pull/13906.
--
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
Re: [PR] [tir][testing] Enable intra-IRModule primfunc call [tvm]
Posted by "tqchen (via GitHub)" <gi...@apache.org>.
tqchen closed pull request #13569: [tir][testing] Enable intra-IRModule primfunc call
URL: https://github.com/apache/tvm/pull/13569
--
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
[GitHub] [tvm] tqchen commented on a diff in pull request #13569: [tir][testing] Enable intra-IRModule primfunc call
Posted by "tqchen (via GitHub)" <gi...@apache.org>.
tqchen commented on code in PR #13569:
URL: https://github.com/apache/tvm/pull/13569#discussion_r1087093102
##########
include/tvm/ir/function.h:
##########
@@ -63,6 +63,43 @@ enum class CallingConv : int {
* - Implementation: defined by device runtime(e.g. runtime/cuda)
*/
kDeviceKernelLaunch = 2,
+ /*!
+ * \brief For functions only called by other functions within the same IR module.
+ *
+ * This calling convention exists to support one PrimFunc calling another PrimFunc
+ * within the same IRModule.
+ *
+ * Overview / Purpose:
+ *
+ * - This calling convention is intended only for PrimFuncs whose callers reside in
+ * the same IRModule. This is the only supported use case.
+ *
+ * - The details of the calling convention may change frequently as TVM evolves.
+ * Therefore users are discouraged from attempting to use this calling convention
+ * outside of the supported use case(s).
+ *
+ * Current mechanics / usage requirements:
+ *
+ * - A PrimFunc with this calling convention will NOT undergo any of the signature
+ * transformations provided by the MakePackedAPI pass.
+ *
+ * - Supported use cases, and their corresponding unit tests, are all expressed as
+ * TVMScript.
+ *
+ * - The callsite must use `T.call_extern`.
Review Comment:
Just want to get some clarity here. That boils down how we map this cross function call in codegen phase.
- If the call maps into call_extern => caller side LLVM call, callee side just present the function as LLVM function. Then it is the common calling convention(either known as default per defined by platform)
- The reason why it is related to "C" calling convention is that if the callee side say was implemented as a C function with the same signature(and compile that say through hexagon-llvm, or platform-c), and we compile caller side as it is, it will still work
If the cross function call will be further lowered(and the behavior), then it might be useful to give it a different name. IntraModule might be slightly too generic(since we can also use Packed call intra module), also the caller side might need a different intrinsic(as call_extern implies call into a function with C calling convention). So if we want to state that this is a convention that will be further lowered, just a strawman: (e.g. InternalModuleCall, call_internal)
So the main comment to clarify this is to relate the calling convention as much as possible to existing known ones, or clarify it so it is differentiated from existing known ones(by different intrinsics and name).
After reading the context, seems we lean towards later. In that case, it might still be useful to specify what would be the default lowering of InternalModuleCall and call_internal. Since they have to be lowered together(if we map call_internal say to packed convention and function with internal InternalModuleCall without packed), then we will get an error. By reading the spec, the most likely outcome now seems to be lower to C calling convention.
--
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
[GitHub] [tvm] tqchen commented on a diff in pull request #13569: [tir][testing] Enable intra-IRModule primfunc call
Posted by "tqchen (via GitHub)" <gi...@apache.org>.
tqchen commented on code in PR #13569:
URL: https://github.com/apache/tvm/pull/13569#discussion_r1087093102
##########
include/tvm/ir/function.h:
##########
@@ -63,6 +63,43 @@ enum class CallingConv : int {
* - Implementation: defined by device runtime(e.g. runtime/cuda)
*/
kDeviceKernelLaunch = 2,
+ /*!
+ * \brief For functions only called by other functions within the same IR module.
+ *
+ * This calling convention exists to support one PrimFunc calling another PrimFunc
+ * within the same IRModule.
+ *
+ * Overview / Purpose:
+ *
+ * - This calling convention is intended only for PrimFuncs whose callers reside in
+ * the same IRModule. This is the only supported use case.
+ *
+ * - The details of the calling convention may change frequently as TVM evolves.
+ * Therefore users are discouraged from attempting to use this calling convention
+ * outside of the supported use case(s).
+ *
+ * Current mechanics / usage requirements:
+ *
+ * - A PrimFunc with this calling convention will NOT undergo any of the signature
+ * transformations provided by the MakePackedAPI pass.
+ *
+ * - Supported use cases, and their corresponding unit tests, are all expressed as
+ * TVMScript.
+ *
+ * - The callsite must use `T.call_extern`.
Review Comment:
Just want to get some clarity here. That boils down how we map this cross function call in codegen phase.
- If the call maps into call_extern => caller side LLVM call, callee side just present the function as LLVM function. Then it is the common calling convention(either known as default per defined by platform)
- The reason why it is related to "C" calling convention is that if the callee side say was implemented as a C function with the same signature(and compile that say through hexagon-llvm, or platform-c), and we compile caller side as it is, it will still work
If the cross function call will be further lowered(and the behavior), then it might be useful to give it a different name. IntraModule might be slightly too generic(since we can also use Packed call intra module), also the caller side might need a different intrinsic(as call_extern implies call into a function with C calling convention). So if we want to state that this is a convention that will be further lowered, just a strawman: (e.g. InternalModuleCall, call_internal)
After reading the context, seems we lean towards later. So the main comment to clarify this is to relate the calling convention as much as possible to existing known ones, or clarify it so it is differentiated from existing known ones(by different intrinsics and name).
--
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
[GitHub] [tvm] cconvey commented on a diff in pull request #13569: [tir][testing] Enable intra-IRModule primfunc call
Posted by "cconvey (via GitHub)" <gi...@apache.org>.
cconvey commented on code in PR #13569:
URL: https://github.com/apache/tvm/pull/13569#discussion_r1092323860
##########
src/tir/transforms/plan_update_buffer_allocation_location.cc:
##########
@@ -111,6 +112,12 @@ class BufferAllocationLocator : public StmtExprMutator {
collector(func->body);
unmanaged_allocations_ = collector.unmanaged_allocations;
+ for (Var param : func->params) {
Review Comment:
Update: After talking with @Lunderberg , I agree that adding a specific unit test makes sense. I'll add it to this PR.
--
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
[GitHub] [tvm] tqchen commented on pull request #13569: [tir][testing] Enable intra-IRModule primfunc call
Posted by "tqchen (via GitHub)" <gi...@apache.org>.
tqchen commented on PR #13569:
URL: https://github.com/apache/tvm/pull/13569#issuecomment-1402399451
would be great to get @vinx13 's input on this as well
--
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
[GitHub] [tvm] cconvey commented on a diff in pull request #13569: [tir][testing] Enable intra-IRModule primfunc call
Posted by "cconvey (via GitHub)" <gi...@apache.org>.
cconvey commented on code in PR #13569:
URL: https://github.com/apache/tvm/pull/13569#discussion_r1083317912
##########
tests/python/contrib/test_hexagon/test_call_tir.py:
##########
@@ -0,0 +1,248 @@
+# 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.
+
+""" Various tests related to the (WIP) support for having
+one PrimFunc call another PrimFunc within the same IRModule.
+"""
+
+from typing import List
+import pytest
+import numpy as np
+
+import tvm
+import tvm.testing
+import tvm.script
+from tvm.script import tir as T
+
+from tvm.contrib.hexagon.session import Session
+from tvm.contrib.hexagon import allocate_hexagon_array
+from .infrastructure import get_hexagon_target
+
+# NOTE(cconvey): These pylint warnings should be re-enabled as TVM's pylint configuration matures.
+# pylint: disable=missing-function-docstring,no-self-argument,invalid-name
+# pylint: disable=redefined-outer-name,missing-class-docstring
+
+# --------------------------------------------------------------------------------------------------
+# Test parameters
+# --------------------------------------------------------------------------------------------------
+
+# The shape of the original (unsplit) tensors.
+# We assume that each shape describes a non-empty 2D tensor.
+original_shape = tvm.testing.parameter(
+ # degenerate cases...
+ [1, 1],
+ [1, 2],
+ [2, 1],
+ [2, 2],
+ # arbitrary, provided for variety
+ [5, 3],
+ [3, 5],
+)
+
+# This dtype is arbitrary, but it must match the dtype that's hardcoded into the
+# callee's function signature. E.g., 'a_data: T.Ptr[T.int8]'.
+#
+# Hopefully over time we'll find a way to soften this limitation, at least for
+# some approaches to PrimFunc-to-PrimFunc calls.
+dtype = tvm.testing.parameter("int8")
+
+# --------------------------------------------------------------------------------------------------
+# Helper functions / definitions...
+# --------------------------------------------------------------------------------------------------
+
+HEXAGON_TARGET_ = get_hexagon_target("v69")
+
+ENTRY_PRIMFUNC_NAME_ = "main"
+
+
+def get_reference_input_tensor_(shape: list, dtype: str) -> np.array:
+ assert len(shape) == 2
+
+ a = np.ndarray(shape, dtype=dtype)
+ np_dtype = a.dtype
+
+ if np_dtype.kind in ["i", "u"]:
+ # We allow overflow for integer types because it tends to be well-behaved
+ # and well-understood...
+ min_value = np.iinfo(np_dtype).min
+ max_value = np.iinfo(np_dtype).max
+
+ next_value = min_value
+
+ for i in range(shape[0]):
+ for j in range(shape[1]):
+ a[i, j] = next_value
+ next_value += 1
+
+ elif np_dtype.kind == "f":
+ # NOTE: For simplicity, we avoid test data that that require
+ # well-defined behavior on floating-point overflow.
+ # But it may be reasonable to test that in the future.
+ min_value = np.finfo(np_dtype).min
+ max_value = np.finfo(np_dtype).max
+
+ min_input_value = min_value / 2.0 + 1
Review Comment:
Thanks for the suggestion. AFAICT the code is using `min` correctly. Maybe you're thinking of `.tiny`?:
```
>>> np.finfo(float).min
-1.7976931348623157e+308
>>> np.finfo(float).min / 2
-8.988465674311579e+307
>>> np.finfo(float).tiny
2.2250738585072014e-308
```
Regarding `np.random.uniform`. I know this is common in TVM's tests, and `np.random.seed(...)` is definitely is an improvement for reproducibility.
Ideally we'd test with carefully chosen critical / boundary values, but that requires a level of analysis we usually don't have time to perform.
For situations like this, I prefer using test-values that are help humans debug failed tests. I suspect that regular intervals like these might help humans to spot trends regarding which particular input-tensor elements result in erroneous output-tensor elements.
--
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
[GitHub] [tvm] cconvey commented on a diff in pull request #13569: [tir][testing] Enable intra-IRModule primfunc call
Posted by "cconvey (via GitHub)" <gi...@apache.org>.
cconvey commented on code in PR #13569:
URL: https://github.com/apache/tvm/pull/13569#discussion_r1106068776
##########
include/tvm/ir/function.h:
##########
@@ -63,6 +63,43 @@ enum class CallingConv : int {
* - Implementation: defined by device runtime(e.g. runtime/cuda)
*/
kDeviceKernelLaunch = 2,
+ /*!
+ * \brief For functions only called by other functions within the same IR module.
+ *
+ * This calling convention exists to support one PrimFunc calling another PrimFunc
+ * within the same IRModule.
+ *
+ * Overview / Purpose:
+ *
+ * - This calling convention is intended only for PrimFuncs whose callers reside in
+ * the same IRModule. This is the only supported use case.
+ *
+ * - The details of the calling convention may change frequently as TVM evolves.
+ * Therefore users are discouraged from attempting to use this calling convention
+ * outside of the supported use case(s).
+ *
+ * Current mechanics / usage requirements:
+ *
+ * - A PrimFunc with this calling convention will NOT undergo any of the signature
+ * transformations provided by the MakePackedAPI pass.
+ *
+ * - Supported use cases, and their corresponding unit tests, are all expressed as
+ * TVMScript.
+ *
+ * - The callsite must use `T.call_extern`.
Review Comment:
@wrongtest-intellif : Thanks very much for the thoughtful suggestion!
I don't have a ready answer to your suggestion, which means I have some more homework to do on my side before proceeding with the PR. Much appreciated!
--
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
[GitHub] [tvm] cconvey commented on pull request #13569: [tir][testing] Enable intra-IRModule primfunc call
Posted by GitBox <gi...@apache.org>.
cconvey commented on PR #13569:
URL: https://github.com/apache/tvm/pull/13569#issuecomment-1379456152
@Lunderberg @areusch : Mind giving this a look?
@JosephTheOctonaut : FYI
--
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
[GitHub] [tvm] Lunderberg commented on a diff in pull request #13569: [tir][testing] Enable intra-IRModule primfunc call
Posted by "Lunderberg (via GitHub)" <gi...@apache.org>.
Lunderberg commented on code in PR #13569:
URL: https://github.com/apache/tvm/pull/13569#discussion_r1084327226
##########
tests/python/contrib/test_hexagon/test_call_tir.py:
##########
@@ -0,0 +1,248 @@
+# 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.
+
+""" Various tests related to the (WIP) support for having
+one PrimFunc call another PrimFunc within the same IRModule.
+"""
+
+from typing import List
+import pytest
+import numpy as np
+
+import tvm
+import tvm.testing
+import tvm.script
+from tvm.script import tir as T
+
+from tvm.contrib.hexagon.session import Session
+from tvm.contrib.hexagon import allocate_hexagon_array
+from .infrastructure import get_hexagon_target
+
+# NOTE(cconvey): These pylint warnings should be re-enabled as TVM's pylint configuration matures.
+# pylint: disable=missing-function-docstring,no-self-argument,invalid-name
+# pylint: disable=redefined-outer-name,missing-class-docstring
+
+# --------------------------------------------------------------------------------------------------
+# Test parameters
+# --------------------------------------------------------------------------------------------------
+
+# The shape of the original (unsplit) tensors.
+# We assume that each shape describes a non-empty 2D tensor.
+original_shape = tvm.testing.parameter(
+ # degenerate cases...
+ [1, 1],
+ [1, 2],
+ [2, 1],
+ [2, 2],
+ # arbitrary, provided for variety
+ [5, 3],
+ [3, 5],
+)
+
+# This dtype is arbitrary, but it must match the dtype that's hardcoded into the
+# callee's function signature. E.g., 'a_data: T.Ptr[T.int8]'.
+#
+# Hopefully over time we'll find a way to soften this limitation, at least for
+# some approaches to PrimFunc-to-PrimFunc calls.
+dtype = tvm.testing.parameter("int8")
+
+# --------------------------------------------------------------------------------------------------
+# Helper functions / definitions...
+# --------------------------------------------------------------------------------------------------
+
+HEXAGON_TARGET_ = get_hexagon_target("v69")
+
+ENTRY_PRIMFUNC_NAME_ = "main"
+
+
+def get_reference_input_tensor_(shape: list, dtype: str) -> np.array:
+ assert len(shape) == 2
+
+ a = np.ndarray(shape, dtype=dtype)
+ np_dtype = a.dtype
+
+ if np_dtype.kind in ["i", "u"]:
+ # We allow overflow for integer types because it tends to be well-behaved
+ # and well-understood...
+ min_value = np.iinfo(np_dtype).min
+ max_value = np.iinfo(np_dtype).max
+
+ next_value = min_value
+
+ for i in range(shape[0]):
+ for j in range(shape[1]):
+ a[i, j] = next_value
+ next_value += 1
+
+ elif np_dtype.kind == "f":
+ # NOTE: For simplicity, we avoid test data that that require
+ # well-defined behavior on floating-point overflow.
+ # But it may be reasonable to test that in the future.
+ min_value = np.finfo(np_dtype).min
+ max_value = np.finfo(np_dtype).max
+
+ min_input_value = min_value / 2.0 + 1
Review Comment:
Looks like I was getting it mixed up with `std::numeric_limits<float>`, and was entirely incorrect in assuming that numpy followed the same conventions.
--
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
[GitHub] [tvm] areusch commented on pull request #13569: [tir][testing] Enable intra-IRModule primfunc call
Posted by "areusch (via GitHub)" <gi...@apache.org>.
areusch commented on PR #13569:
URL: https://github.com/apache/tvm/pull/13569#issuecomment-1400792549
@mbaret @tqchen should also have a look at this
--
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
[GitHub] [tvm] cconvey commented on a diff in pull request #13569: [tir][testing] Enable intra-IRModule primfunc call
Posted by "cconvey (via GitHub)" <gi...@apache.org>.
cconvey commented on code in PR #13569:
URL: https://github.com/apache/tvm/pull/13569#discussion_r1083317912
##########
tests/python/contrib/test_hexagon/test_call_tir.py:
##########
@@ -0,0 +1,248 @@
+# 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.
+
+""" Various tests related to the (WIP) support for having
+one PrimFunc call another PrimFunc within the same IRModule.
+"""
+
+from typing import List
+import pytest
+import numpy as np
+
+import tvm
+import tvm.testing
+import tvm.script
+from tvm.script import tir as T
+
+from tvm.contrib.hexagon.session import Session
+from tvm.contrib.hexagon import allocate_hexagon_array
+from .infrastructure import get_hexagon_target
+
+# NOTE(cconvey): These pylint warnings should be re-enabled as TVM's pylint configuration matures.
+# pylint: disable=missing-function-docstring,no-self-argument,invalid-name
+# pylint: disable=redefined-outer-name,missing-class-docstring
+
+# --------------------------------------------------------------------------------------------------
+# Test parameters
+# --------------------------------------------------------------------------------------------------
+
+# The shape of the original (unsplit) tensors.
+# We assume that each shape describes a non-empty 2D tensor.
+original_shape = tvm.testing.parameter(
+ # degenerate cases...
+ [1, 1],
+ [1, 2],
+ [2, 1],
+ [2, 2],
+ # arbitrary, provided for variety
+ [5, 3],
+ [3, 5],
+)
+
+# This dtype is arbitrary, but it must match the dtype that's hardcoded into the
+# callee's function signature. E.g., 'a_data: T.Ptr[T.int8]'.
+#
+# Hopefully over time we'll find a way to soften this limitation, at least for
+# some approaches to PrimFunc-to-PrimFunc calls.
+dtype = tvm.testing.parameter("int8")
+
+# --------------------------------------------------------------------------------------------------
+# Helper functions / definitions...
+# --------------------------------------------------------------------------------------------------
+
+HEXAGON_TARGET_ = get_hexagon_target("v69")
+
+ENTRY_PRIMFUNC_NAME_ = "main"
+
+
+def get_reference_input_tensor_(shape: list, dtype: str) -> np.array:
+ assert len(shape) == 2
+
+ a = np.ndarray(shape, dtype=dtype)
+ np_dtype = a.dtype
+
+ if np_dtype.kind in ["i", "u"]:
+ # We allow overflow for integer types because it tends to be well-behaved
+ # and well-understood...
+ min_value = np.iinfo(np_dtype).min
+ max_value = np.iinfo(np_dtype).max
+
+ next_value = min_value
+
+ for i in range(shape[0]):
+ for j in range(shape[1]):
+ a[i, j] = next_value
+ next_value += 1
+
+ elif np_dtype.kind == "f":
+ # NOTE: For simplicity, we avoid test data that that require
+ # well-defined behavior on floating-point overflow.
+ # But it may be reasonable to test that in the future.
+ min_value = np.finfo(np_dtype).min
+ max_value = np.finfo(np_dtype).max
+
+ min_input_value = min_value / 2.0 + 1
Review Comment:
Thanks for the suggestion. AFAICT the code is using `min` correctly. Maybe you're thinking of `.tiny`?:
```
>>> np.finfo(float).min
-1.7976931348623157e+308
>>> np.finfo(float).min / 2
-8.988465674311579e+307
>>> np.finfo(float).tiny
2.2250738585072014e-308
```
Regarding `np.random.uniform`. I know this is common in TVM's tests, and `np.random.seed(...)` is definitely is an improvement for reproducibility.
My ideal would be to use carefully chosen critical / boundary value for testing, but that requires a level of analysis we usually don't have time to perform.
For situations like this, I prefer using test-values that are helpful to humans trying to debug failed tests. I suspect that regular intervals like these might help humans to spot trends regarding which particular input-tensor elements result in erroneous output-tensor elements.
--
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
[GitHub] [tvm] Lunderberg commented on a diff in pull request #13569: [tir][testing] Enable intra-IRModule primfunc call
Posted by "Lunderberg (via GitHub)" <gi...@apache.org>.
Lunderberg commented on code in PR #13569:
URL: https://github.com/apache/tvm/pull/13569#discussion_r1084191551
##########
tests/python/contrib/test_hexagon/test_call_tir.py:
##########
@@ -0,0 +1,248 @@
+# 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.
+
+""" Various tests related to the (WIP) support for having
+one PrimFunc call another PrimFunc within the same IRModule.
+"""
+
+from typing import List
+import pytest
+import numpy as np
+
+import tvm
+import tvm.testing
+import tvm.script
+from tvm.script import tir as T
+
+from tvm.contrib.hexagon.session import Session
+from tvm.contrib.hexagon import allocate_hexagon_array
+from .infrastructure import get_hexagon_target
+
+# NOTE(cconvey): These pylint warnings should be re-enabled as TVM's pylint configuration matures.
+# pylint: disable=missing-function-docstring,no-self-argument,invalid-name
+# pylint: disable=redefined-outer-name,missing-class-docstring
+
+# --------------------------------------------------------------------------------------------------
+# Test parameters
+# --------------------------------------------------------------------------------------------------
+
+# The shape of the original (unsplit) tensors.
+# We assume that each shape describes a non-empty 2D tensor.
+original_shape = tvm.testing.parameter(
+ # degenerate cases...
+ [1, 1],
+ [1, 2],
+ [2, 1],
+ [2, 2],
+ # arbitrary, provided for variety
+ [5, 3],
+ [3, 5],
+)
+
+# This dtype is arbitrary, but it must match the dtype that's hardcoded into the
+# callee's function signature. E.g., 'a_data: T.Ptr[T.int8]'.
+#
+# Hopefully over time we'll find a way to soften this limitation, at least for
+# some approaches to PrimFunc-to-PrimFunc calls.
+dtype = tvm.testing.parameter("int8")
+
+# --------------------------------------------------------------------------------------------------
+# Helper functions / definitions...
+# --------------------------------------------------------------------------------------------------
+
+HEXAGON_TARGET_ = get_hexagon_target("v69")
+
+ENTRY_PRIMFUNC_NAME_ = "main"
+
+
+def get_reference_input_tensor_(shape: list, dtype: str) -> np.array:
Review Comment:
Makes sense, and I could go either way on it. The main advantage I see in making a fixture earlier rather than later is to prevent alterations that are incompatible with fixtures (e.g. Multiple calls per test method).
--
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
[GitHub] [tvm] cconvey commented on a diff in pull request #13569: [tir][testing] Enable intra-IRModule primfunc call
Posted by "cconvey (via GitHub)" <gi...@apache.org>.
cconvey commented on code in PR #13569:
URL: https://github.com/apache/tvm/pull/13569#discussion_r1086983972
##########
include/tvm/ir/function.h:
##########
@@ -63,6 +63,13 @@ enum class CallingConv : int {
* - Implementation: defined by device runtime(e.g. runtime/cuda)
*/
kDeviceKernelLaunch = 2,
+ /*!
+ * \brief For functions only called by other functions within the same IR module.
+ *
+ * Indicates that various signature transformations (e.g. those provided by the
+ * MakePackedAPI pass) are not desired.
+ */
+ kIntraModule = 3,
Review Comment:
> Would be great to specify that this is a convention that will be lowered (to another low-level convention), or if it is supposed to a final C convention (with restrictions)
Actually I was planning to leave that unstated, because I wanted the freedom to tweak the details without breaking any TCMScript that uses this.
Do you feel that there's a benefit in being explicit that outweighs that flexibility?
--
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
[GitHub] [tvm] vinx13 commented on a diff in pull request #13569: [tir][testing] Enable intra-IRModule primfunc call
Posted by "vinx13 (via GitHub)" <gi...@apache.org>.
vinx13 commented on code in PR #13569:
URL: https://github.com/apache/tvm/pull/13569#discussion_r1087050536
##########
src/tir/transforms/plan_update_buffer_allocation_location.cc:
##########
@@ -111,6 +112,12 @@ class BufferAllocationLocator : public StmtExprMutator {
collector(func->body);
unmanaged_allocations_ = collector.unmanaged_allocations;
+ for (Var param : func->params) {
Review Comment:
Need test case for this
##########
src/tir/transforms/plan_update_buffer_allocation_location.cc:
##########
@@ -27,6 +27,7 @@
#include <tvm/tir/transform.h>
#include "ir_utils.h"
+#include "tvm/tir/var.h"
Review Comment:
```suggestion
#include <tvm/tir/var.h>
```
--
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
[GitHub] [tvm] cconvey commented on a diff in pull request #13569: [tir][testing] Enable intra-IRModule primfunc call
Posted by "cconvey (via GitHub)" <gi...@apache.org>.
cconvey commented on code in PR #13569:
URL: https://github.com/apache/tvm/pull/13569#discussion_r1083317912
##########
tests/python/contrib/test_hexagon/test_call_tir.py:
##########
@@ -0,0 +1,248 @@
+# 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.
+
+""" Various tests related to the (WIP) support for having
+one PrimFunc call another PrimFunc within the same IRModule.
+"""
+
+from typing import List
+import pytest
+import numpy as np
+
+import tvm
+import tvm.testing
+import tvm.script
+from tvm.script import tir as T
+
+from tvm.contrib.hexagon.session import Session
+from tvm.contrib.hexagon import allocate_hexagon_array
+from .infrastructure import get_hexagon_target
+
+# NOTE(cconvey): These pylint warnings should be re-enabled as TVM's pylint configuration matures.
+# pylint: disable=missing-function-docstring,no-self-argument,invalid-name
+# pylint: disable=redefined-outer-name,missing-class-docstring
+
+# --------------------------------------------------------------------------------------------------
+# Test parameters
+# --------------------------------------------------------------------------------------------------
+
+# The shape of the original (unsplit) tensors.
+# We assume that each shape describes a non-empty 2D tensor.
+original_shape = tvm.testing.parameter(
+ # degenerate cases...
+ [1, 1],
+ [1, 2],
+ [2, 1],
+ [2, 2],
+ # arbitrary, provided for variety
+ [5, 3],
+ [3, 5],
+)
+
+# This dtype is arbitrary, but it must match the dtype that's hardcoded into the
+# callee's function signature. E.g., 'a_data: T.Ptr[T.int8]'.
+#
+# Hopefully over time we'll find a way to soften this limitation, at least for
+# some approaches to PrimFunc-to-PrimFunc calls.
+dtype = tvm.testing.parameter("int8")
+
+# --------------------------------------------------------------------------------------------------
+# Helper functions / definitions...
+# --------------------------------------------------------------------------------------------------
+
+HEXAGON_TARGET_ = get_hexagon_target("v69")
+
+ENTRY_PRIMFUNC_NAME_ = "main"
+
+
+def get_reference_input_tensor_(shape: list, dtype: str) -> np.array:
+ assert len(shape) == 2
+
+ a = np.ndarray(shape, dtype=dtype)
+ np_dtype = a.dtype
+
+ if np_dtype.kind in ["i", "u"]:
+ # We allow overflow for integer types because it tends to be well-behaved
+ # and well-understood...
+ min_value = np.iinfo(np_dtype).min
+ max_value = np.iinfo(np_dtype).max
+
+ next_value = min_value
+
+ for i in range(shape[0]):
+ for j in range(shape[1]):
+ a[i, j] = next_value
+ next_value += 1
+
+ elif np_dtype.kind == "f":
+ # NOTE: For simplicity, we avoid test data that that require
+ # well-defined behavior on floating-point overflow.
+ # But it may be reasonable to test that in the future.
+ min_value = np.finfo(np_dtype).min
+ max_value = np.finfo(np_dtype).max
+
+ min_input_value = min_value / 2.0 + 1
Review Comment:
Thanks for the suggestion. AFAICT the code is using `min` correctly. Maybe you're thinking of `.tiny`?:
```
>>> np.finfo(float).min
-1.7976931348623157e+308
>>> np.finfo(float).min / 2
-8.988465674311579e+307
>>> np.finfo(float).tiny
2.2250738585072014e-308
```
Regarding `np.random.uniform`. I know this is common in TVM's tests, and `np.random.seed(...)` is definitely is an improvement for reproducibility.
My ideal would be to use carefully chosen critical / boundary value for testing, but that requires a level of analysis we usually don't have time to perform.
For situations like this, I prefer using test-values that are helpful to humans trying to debug failed tests. I think regular-interval values like these could make it somewhat easier for humans to spot trends regarding which particular input-tensor elements result in erroneous output-tensor elements.
--
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
[GitHub] [tvm] cconvey commented on pull request #13569: [tir][testing] Enable intra-IRModule primfunc call
Posted by "cconvey (via GitHub)" <gi...@apache.org>.
cconvey commented on PR #13569:
URL: https://github.com/apache/tvm/pull/13569#issuecomment-1399314528
@Lunderberg : Ready for re-review.
--
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
[GitHub] [tvm] Lunderberg commented on a diff in pull request #13569: [tir][testing] Enable intra-IRModule primfunc call
Posted by GitBox <gi...@apache.org>.
Lunderberg commented on code in PR #13569:
URL: https://github.com/apache/tvm/pull/13569#discussion_r1082618777
##########
include/tvm/ir/function.h:
##########
@@ -63,6 +63,13 @@ enum class CallingConv : int {
* - Implementation: defined by device runtime(e.g. runtime/cuda)
*/
kDeviceKernelLaunch = 2,
+ /*!
+ * \brief For functions only called by other functions within the same IR module.
+ *
+ * Indicates that various signature transformations (e.g. those provided by the
+ * MakePackedAPI pass) are not desired.
+ */
+ kIntraModule = 3,
Review Comment:
I like the specification of the intent here, rather than just stating "disable packed API" or something equivalent. I think I'd expand on the statement that all callers of this function may be assumed to be within the current module, specifically that this function provides no guarantees as to function signature to end-users.
That way, it makes it clear that this isn't just a statement of the current behavior, but also what sort of changes may be made in the future. (e.g. If a parameter of an internal function is unused, it may be stripped from the internal function and removed from all callsites, but this wouldn't be legal for a user-facing function)
##########
tests/python/contrib/test_hexagon/test_call_tir.py:
##########
@@ -0,0 +1,248 @@
+# 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.
+
+""" Various tests related to the (WIP) support for having
+one PrimFunc call another PrimFunc within the same IRModule.
+"""
+
+from typing import List
+import pytest
+import numpy as np
+
+import tvm
+import tvm.testing
+import tvm.script
+from tvm.script import tir as T
+
+from tvm.contrib.hexagon.session import Session
+from tvm.contrib.hexagon import allocate_hexagon_array
+from .infrastructure import get_hexagon_target
+
+# NOTE(cconvey): These pylint warnings should be re-enabled as TVM's pylint configuration matures.
+# pylint: disable=missing-function-docstring,no-self-argument,invalid-name
+# pylint: disable=redefined-outer-name,missing-class-docstring
+
+# --------------------------------------------------------------------------------------------------
+# Test parameters
+# --------------------------------------------------------------------------------------------------
+
+# The shape of the original (unsplit) tensors.
+# We assume that each shape describes a non-empty 2D tensor.
+original_shape = tvm.testing.parameter(
+ # degenerate cases...
+ [1, 1],
+ [1, 2],
+ [2, 1],
+ [2, 2],
+ # arbitrary, provided for variety
+ [5, 3],
+ [3, 5],
+)
+
+# This dtype is arbitrary, but it must match the dtype that's hardcoded into the
+# callee's function signature. E.g., 'a_data: T.Ptr[T.int8]'.
+#
+# Hopefully over time we'll find a way to soften this limitation, at least for
+# some approaches to PrimFunc-to-PrimFunc calls.
+dtype = tvm.testing.parameter("int8")
+
+# --------------------------------------------------------------------------------------------------
+# Helper functions / definitions...
+# --------------------------------------------------------------------------------------------------
+
+HEXAGON_TARGET_ = get_hexagon_target("v69")
+
+ENTRY_PRIMFUNC_NAME_ = "main"
+
+
+def get_reference_input_tensor_(shape: list, dtype: str) -> np.array:
+ assert len(shape) == 2
+
+ a = np.ndarray(shape, dtype=dtype)
+ np_dtype = a.dtype
+
+ if np_dtype.kind in ["i", "u"]:
+ # We allow overflow for integer types because it tends to be well-behaved
+ # and well-understood...
+ min_value = np.iinfo(np_dtype).min
+ max_value = np.iinfo(np_dtype).max
+
+ next_value = min_value
+
+ for i in range(shape[0]):
+ for j in range(shape[1]):
+ a[i, j] = next_value
+ next_value += 1
+
+ elif np_dtype.kind == "f":
+ # NOTE: For simplicity, we avoid test data that that require
+ # well-defined behavior on floating-point overflow.
+ # But it may be reasonable to test that in the future.
+ min_value = np.finfo(np_dtype).min
+ max_value = np.finfo(np_dtype).max
+
+ min_input_value = min_value / 2.0 + 1
+ max_input_value = max_value / 2.0 - 2
+ delta = (max_input_value - min_input_value) / (shape[0] * shape[1])
+
+ next_value = min_input_value
+
+ for i in range(shape[0]):
+ for j in range(shape[1]):
+ a[i, j] = next_value
+ next_value += delta
+
+ else:
+ assert False, f"Unexpected data type: {np_dtype}"
+
+ return a
+
+
+def get_reference_output_tensor_(shape: list, dtype: str) -> np.array:
Review Comment:
Instead of a function, should this be a fixture instead?
##########
tests/python/contrib/test_hexagon/test_call_tir.py:
##########
@@ -0,0 +1,248 @@
+# 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.
+
+""" Various tests related to the (WIP) support for having
+one PrimFunc call another PrimFunc within the same IRModule.
+"""
+
+from typing import List
+import pytest
+import numpy as np
+
+import tvm
+import tvm.testing
+import tvm.script
+from tvm.script import tir as T
+
+from tvm.contrib.hexagon.session import Session
+from tvm.contrib.hexagon import allocate_hexagon_array
+from .infrastructure import get_hexagon_target
+
+# NOTE(cconvey): These pylint warnings should be re-enabled as TVM's pylint configuration matures.
+# pylint: disable=missing-function-docstring,no-self-argument,invalid-name
+# pylint: disable=redefined-outer-name,missing-class-docstring
+
+# --------------------------------------------------------------------------------------------------
+# Test parameters
+# --------------------------------------------------------------------------------------------------
+
+# The shape of the original (unsplit) tensors.
+# We assume that each shape describes a non-empty 2D tensor.
+original_shape = tvm.testing.parameter(
+ # degenerate cases...
+ [1, 1],
+ [1, 2],
+ [2, 1],
+ [2, 2],
+ # arbitrary, provided for variety
+ [5, 3],
+ [3, 5],
+)
+
+# This dtype is arbitrary, but it must match the dtype that's hardcoded into the
+# callee's function signature. E.g., 'a_data: T.Ptr[T.int8]'.
+#
+# Hopefully over time we'll find a way to soften this limitation, at least for
+# some approaches to PrimFunc-to-PrimFunc calls.
+dtype = tvm.testing.parameter("int8")
+
+# --------------------------------------------------------------------------------------------------
+# Helper functions / definitions...
+# --------------------------------------------------------------------------------------------------
+
+HEXAGON_TARGET_ = get_hexagon_target("v69")
+
+ENTRY_PRIMFUNC_NAME_ = "main"
+
+
+def get_reference_input_tensor_(shape: list, dtype: str) -> np.array:
+ assert len(shape) == 2
+
+ a = np.ndarray(shape, dtype=dtype)
+ np_dtype = a.dtype
+
+ if np_dtype.kind in ["i", "u"]:
+ # We allow overflow for integer types because it tends to be well-behaved
+ # and well-understood...
+ min_value = np.iinfo(np_dtype).min
+ max_value = np.iinfo(np_dtype).max
+
+ next_value = min_value
+
+ for i in range(shape[0]):
+ for j in range(shape[1]):
+ a[i, j] = next_value
+ next_value += 1
+
+ elif np_dtype.kind == "f":
+ # NOTE: For simplicity, we avoid test data that that require
+ # well-defined behavior on floating-point overflow.
+ # But it may be reasonable to test that in the future.
+ min_value = np.finfo(np_dtype).min
+ max_value = np.finfo(np_dtype).max
+
+ min_input_value = min_value / 2.0 + 1
Review Comment:
As an alternative, what about either of the following two methods?
```python
# Pseudo-random values on [-1,1], seeded to always get same values
np.random.seed(0)
np.random.uniform(-1,1, size=shape).astype(dtype)
# Sequential values on range [-1,1]
N = shape[0]*shape[1]
2*(np.arange(N).reshape(shape).astype(dtype) / N - 0.5)
```
##########
tests/python/contrib/test_hexagon/test_call_tir.py:
##########
@@ -0,0 +1,248 @@
+# 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.
+
+""" Various tests related to the (WIP) support for having
+one PrimFunc call another PrimFunc within the same IRModule.
+"""
+
+from typing import List
+import pytest
+import numpy as np
+
+import tvm
+import tvm.testing
+import tvm.script
+from tvm.script import tir as T
+
+from tvm.contrib.hexagon.session import Session
+from tvm.contrib.hexagon import allocate_hexagon_array
+from .infrastructure import get_hexagon_target
+
+# NOTE(cconvey): These pylint warnings should be re-enabled as TVM's pylint configuration matures.
+# pylint: disable=missing-function-docstring,no-self-argument,invalid-name
+# pylint: disable=redefined-outer-name,missing-class-docstring
+
+# --------------------------------------------------------------------------------------------------
+# Test parameters
+# --------------------------------------------------------------------------------------------------
+
+# The shape of the original (unsplit) tensors.
+# We assume that each shape describes a non-empty 2D tensor.
+original_shape = tvm.testing.parameter(
+ # degenerate cases...
+ [1, 1],
+ [1, 2],
+ [2, 1],
+ [2, 2],
+ # arbitrary, provided for variety
+ [5, 3],
+ [3, 5],
+)
+
+# This dtype is arbitrary, but it must match the dtype that's hardcoded into the
+# callee's function signature. E.g., 'a_data: T.Ptr[T.int8]'.
+#
+# Hopefully over time we'll find a way to soften this limitation, at least for
+# some approaches to PrimFunc-to-PrimFunc calls.
+dtype = tvm.testing.parameter("int8")
+
+# --------------------------------------------------------------------------------------------------
+# Helper functions / definitions...
+# --------------------------------------------------------------------------------------------------
+
+HEXAGON_TARGET_ = get_hexagon_target("v69")
+
+ENTRY_PRIMFUNC_NAME_ = "main"
+
+
+def get_reference_input_tensor_(shape: list, dtype: str) -> np.array:
+ assert len(shape) == 2
+
+ a = np.ndarray(shape, dtype=dtype)
+ np_dtype = a.dtype
+
+ if np_dtype.kind in ["i", "u"]:
+ # We allow overflow for integer types because it tends to be well-behaved
+ # and well-understood...
+ min_value = np.iinfo(np_dtype).min
+ max_value = np.iinfo(np_dtype).max
+
+ next_value = min_value
+
+ for i in range(shape[0]):
+ for j in range(shape[1]):
+ a[i, j] = next_value
+ next_value += 1
+
+ elif np_dtype.kind == "f":
+ # NOTE: For simplicity, we avoid test data that that require
+ # well-defined behavior on floating-point overflow.
+ # But it may be reasonable to test that in the future.
+ min_value = np.finfo(np_dtype).min
+ max_value = np.finfo(np_dtype).max
+
+ min_input_value = min_value / 2.0 + 1
Review Comment:
The `min_value` for floating point numbers is the smallest positive number that can be represented, so `min_value / 2.0` will always evaluate to zero. Similarly, numbers that are anywhere close to `max_value` will create a very large amount of rounding error, and probably won't be useful test inputs.
##########
tests/python/contrib/test_hexagon/test_call_tir.py:
##########
@@ -0,0 +1,248 @@
+# 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.
+
+""" Various tests related to the (WIP) support for having
+one PrimFunc call another PrimFunc within the same IRModule.
+"""
+
+from typing import List
+import pytest
+import numpy as np
+
+import tvm
+import tvm.testing
+import tvm.script
+from tvm.script import tir as T
+
+from tvm.contrib.hexagon.session import Session
+from tvm.contrib.hexagon import allocate_hexagon_array
+from .infrastructure import get_hexagon_target
+
+# NOTE(cconvey): These pylint warnings should be re-enabled as TVM's pylint configuration matures.
+# pylint: disable=missing-function-docstring,no-self-argument,invalid-name
+# pylint: disable=redefined-outer-name,missing-class-docstring
+
+# --------------------------------------------------------------------------------------------------
+# Test parameters
+# --------------------------------------------------------------------------------------------------
+
+# The shape of the original (unsplit) tensors.
+# We assume that each shape describes a non-empty 2D tensor.
+original_shape = tvm.testing.parameter(
+ # degenerate cases...
+ [1, 1],
+ [1, 2],
+ [2, 1],
+ [2, 2],
+ # arbitrary, provided for variety
+ [5, 3],
+ [3, 5],
+)
+
+# This dtype is arbitrary, but it must match the dtype that's hardcoded into the
+# callee's function signature. E.g., 'a_data: T.Ptr[T.int8]'.
+#
+# Hopefully over time we'll find a way to soften this limitation, at least for
+# some approaches to PrimFunc-to-PrimFunc calls.
+dtype = tvm.testing.parameter("int8")
+
+# --------------------------------------------------------------------------------------------------
+# Helper functions / definitions...
+# --------------------------------------------------------------------------------------------------
+
+HEXAGON_TARGET_ = get_hexagon_target("v69")
+
+ENTRY_PRIMFUNC_NAME_ = "main"
+
+
+def get_reference_input_tensor_(shape: list, dtype: str) -> np.array:
+ assert len(shape) == 2
+
+ a = np.ndarray(shape, dtype=dtype)
+ np_dtype = a.dtype
+
+ if np_dtype.kind in ["i", "u"]:
+ # We allow overflow for integer types because it tends to be well-behaved
+ # and well-understood...
+ min_value = np.iinfo(np_dtype).min
+ max_value = np.iinfo(np_dtype).max
+
+ next_value = min_value
Review Comment:
Numpy has a couple functions that may be useful here. The array could be generated as `np.arange(shape[0]*shape[1]).reshape(shape).astype(np_dtype)`. For integer types, this would start at zero and wrap at the maximum value of each int.
##########
tests/python/contrib/test_hexagon/test_call_tir.py:
##########
@@ -0,0 +1,248 @@
+# 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.
+
+""" Various tests related to the (WIP) support for having
+one PrimFunc call another PrimFunc within the same IRModule.
+"""
+
+from typing import List
+import pytest
+import numpy as np
+
+import tvm
+import tvm.testing
+import tvm.script
+from tvm.script import tir as T
+
+from tvm.contrib.hexagon.session import Session
+from tvm.contrib.hexagon import allocate_hexagon_array
+from .infrastructure import get_hexagon_target
+
+# NOTE(cconvey): These pylint warnings should be re-enabled as TVM's pylint configuration matures.
+# pylint: disable=missing-function-docstring,no-self-argument,invalid-name
+# pylint: disable=redefined-outer-name,missing-class-docstring
+
+# --------------------------------------------------------------------------------------------------
+# Test parameters
+# --------------------------------------------------------------------------------------------------
+
+# The shape of the original (unsplit) tensors.
+# We assume that each shape describes a non-empty 2D tensor.
+original_shape = tvm.testing.parameter(
+ # degenerate cases...
+ [1, 1],
+ [1, 2],
+ [2, 1],
+ [2, 2],
+ # arbitrary, provided for variety
+ [5, 3],
+ [3, 5],
+)
+
+# This dtype is arbitrary, but it must match the dtype that's hardcoded into the
+# callee's function signature. E.g., 'a_data: T.Ptr[T.int8]'.
+#
+# Hopefully over time we'll find a way to soften this limitation, at least for
+# some approaches to PrimFunc-to-PrimFunc calls.
+dtype = tvm.testing.parameter("int8")
+
+# --------------------------------------------------------------------------------------------------
+# Helper functions / definitions...
+# --------------------------------------------------------------------------------------------------
+
+HEXAGON_TARGET_ = get_hexagon_target("v69")
+
+ENTRY_PRIMFUNC_NAME_ = "main"
+
+
+def get_reference_input_tensor_(shape: list, dtype: str) -> np.array:
Review Comment:
Instead of a function, should this be a fixture instead? That way, it could be cached across multiple tests that use the same shape and dtype.
--
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
[GitHub] [tvm] tqchen commented on a diff in pull request #13569: [tir][testing] Enable intra-IRModule primfunc call
Posted by "tqchen (via GitHub)" <gi...@apache.org>.
tqchen commented on code in PR #13569:
URL: https://github.com/apache/tvm/pull/13569#discussion_r1085733259
##########
include/tvm/ir/function.h:
##########
@@ -63,6 +63,13 @@ enum class CallingConv : int {
* - Implementation: defined by device runtime(e.g. runtime/cuda)
*/
kDeviceKernelLaunch = 2,
+ /*!
+ * \brief For functions only called by other functions within the same IR module.
+ *
+ * Indicates that various signature transformations (e.g. those provided by the
+ * MakePackedAPI pass) are not desired.
+ */
+ kIntraModule = 3,
Review Comment:
Would be great to specify that this is a convention that will be lowered (to another low-level convention), or if it is supposed to a final C convention (with restrictions)
--
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
[GitHub] [tvm] cconvey commented on a diff in pull request #13569: [tir][testing] Enable intra-IRModule primfunc call
Posted by "cconvey (via GitHub)" <gi...@apache.org>.
cconvey commented on code in PR #13569:
URL: https://github.com/apache/tvm/pull/13569#discussion_r1083323911
##########
tests/python/contrib/test_hexagon/test_call_tir.py:
##########
@@ -0,0 +1,248 @@
+# 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.
+
+""" Various tests related to the (WIP) support for having
+one PrimFunc call another PrimFunc within the same IRModule.
+"""
+
+from typing import List
+import pytest
+import numpy as np
+
+import tvm
+import tvm.testing
+import tvm.script
+from tvm.script import tir as T
+
+from tvm.contrib.hexagon.session import Session
+from tvm.contrib.hexagon import allocate_hexagon_array
+from .infrastructure import get_hexagon_target
+
+# NOTE(cconvey): These pylint warnings should be re-enabled as TVM's pylint configuration matures.
+# pylint: disable=missing-function-docstring,no-self-argument,invalid-name
+# pylint: disable=redefined-outer-name,missing-class-docstring
+
+# --------------------------------------------------------------------------------------------------
+# Test parameters
+# --------------------------------------------------------------------------------------------------
+
+# The shape of the original (unsplit) tensors.
+# We assume that each shape describes a non-empty 2D tensor.
+original_shape = tvm.testing.parameter(
+ # degenerate cases...
+ [1, 1],
+ [1, 2],
+ [2, 1],
+ [2, 2],
+ # arbitrary, provided for variety
+ [5, 3],
+ [3, 5],
+)
+
+# This dtype is arbitrary, but it must match the dtype that's hardcoded into the
+# callee's function signature. E.g., 'a_data: T.Ptr[T.int8]'.
+#
+# Hopefully over time we'll find a way to soften this limitation, at least for
+# some approaches to PrimFunc-to-PrimFunc calls.
+dtype = tvm.testing.parameter("int8")
+
+# --------------------------------------------------------------------------------------------------
+# Helper functions / definitions...
+# --------------------------------------------------------------------------------------------------
+
+HEXAGON_TARGET_ = get_hexagon_target("v69")
+
+ENTRY_PRIMFUNC_NAME_ = "main"
+
+
+def get_reference_input_tensor_(shape: list, dtype: str) -> np.array:
+ assert len(shape) == 2
+
+ a = np.ndarray(shape, dtype=dtype)
+ np_dtype = a.dtype
+
+ if np_dtype.kind in ["i", "u"]:
+ # We allow overflow for integer types because it tends to be well-behaved
+ # and well-understood...
+ min_value = np.iinfo(np_dtype).min
+ max_value = np.iinfo(np_dtype).max
+
+ next_value = min_value
+
+ for i in range(shape[0]):
+ for j in range(shape[1]):
+ a[i, j] = next_value
+ next_value += 1
+
+ elif np_dtype.kind == "f":
+ # NOTE: For simplicity, we avoid test data that that require
+ # well-defined behavior on floating-point overflow.
+ # But it may be reasonable to test that in the future.
+ min_value = np.finfo(np_dtype).min
+ max_value = np.finfo(np_dtype).max
+
+ min_input_value = min_value / 2.0 + 1
Review Comment:
(See earlier comment about me switching to `pytest_util.py` for this logic.)
--
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
[GitHub] [tvm] cconvey commented on a diff in pull request #13569: [tir][testing] Enable intra-IRModule primfunc call
Posted by "cconvey (via GitHub)" <gi...@apache.org>.
cconvey commented on code in PR #13569:
URL: https://github.com/apache/tvm/pull/13569#discussion_r1083324067
##########
tests/python/contrib/test_hexagon/test_call_tir.py:
##########
@@ -0,0 +1,248 @@
+# 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.
+
+""" Various tests related to the (WIP) support for having
+one PrimFunc call another PrimFunc within the same IRModule.
+"""
+
+from typing import List
+import pytest
+import numpy as np
+
+import tvm
+import tvm.testing
+import tvm.script
+from tvm.script import tir as T
+
+from tvm.contrib.hexagon.session import Session
+from tvm.contrib.hexagon import allocate_hexagon_array
+from .infrastructure import get_hexagon_target
+
+# NOTE(cconvey): These pylint warnings should be re-enabled as TVM's pylint configuration matures.
+# pylint: disable=missing-function-docstring,no-self-argument,invalid-name
+# pylint: disable=redefined-outer-name,missing-class-docstring
+
+# --------------------------------------------------------------------------------------------------
+# Test parameters
+# --------------------------------------------------------------------------------------------------
+
+# The shape of the original (unsplit) tensors.
+# We assume that each shape describes a non-empty 2D tensor.
+original_shape = tvm.testing.parameter(
+ # degenerate cases...
+ [1, 1],
+ [1, 2],
+ [2, 1],
+ [2, 2],
+ # arbitrary, provided for variety
+ [5, 3],
+ [3, 5],
+)
+
+# This dtype is arbitrary, but it must match the dtype that's hardcoded into the
+# callee's function signature. E.g., 'a_data: T.Ptr[T.int8]'.
+#
+# Hopefully over time we'll find a way to soften this limitation, at least for
+# some approaches to PrimFunc-to-PrimFunc calls.
+dtype = tvm.testing.parameter("int8")
+
+# --------------------------------------------------------------------------------------------------
+# Helper functions / definitions...
+# --------------------------------------------------------------------------------------------------
+
+HEXAGON_TARGET_ = get_hexagon_target("v69")
+
+ENTRY_PRIMFUNC_NAME_ = "main"
+
+
+def get_reference_input_tensor_(shape: list, dtype: str) -> np.array:
Review Comment:
I'd suggest waiting until we're more sure it will get reused.
IMHO making something a fixture adds a little complexity, because the reader has to hunt down the fixture, rather than just seeing the logic right here.
--
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
[GitHub] [tvm] Lunderberg commented on a diff in pull request #13569: [tir][testing] Enable intra-IRModule primfunc call
Posted by "Lunderberg (via GitHub)" <gi...@apache.org>.
Lunderberg commented on code in PR #13569:
URL: https://github.com/apache/tvm/pull/13569#discussion_r1092259667
##########
include/tvm/ir/function.h:
##########
@@ -63,6 +63,43 @@ enum class CallingConv : int {
* - Implementation: defined by device runtime(e.g. runtime/cuda)
*/
kDeviceKernelLaunch = 2,
+ /*!
+ * \brief For functions only called by other functions within the same IR module.
+ *
+ * This calling convention exists to support one PrimFunc calling another PrimFunc
+ * within the same IRModule.
+ *
+ * Overview / Purpose:
+ *
+ * - This calling convention is intended only for PrimFuncs whose callers reside in
+ * the same IRModule. This is the only supported use case.
+ *
+ * - The details of the calling convention may change frequently as TVM evolves.
+ * Therefore users are discouraged from attempting to use this calling convention
+ * outside of the supported use case(s).
+ *
+ * Current mechanics / usage requirements:
+ *
+ * - A PrimFunc with this calling convention will NOT undergo any of the signature
+ * transformations provided by the MakePackedAPI pass.
+ *
+ * - Supported use cases, and their corresponding unit tests, are all expressed as
+ * TVMScript.
+ *
+ * - The callsite must use `T.call_extern`.
Review Comment:
> as call_extern implies call into a function with C calling convention
To double-check, is this the case for functions that exist within the same module? That is, because the name resolution in the LLVM codegen [preferentially resolves to names](https://github.com/apache/tvm/blob/main/src/target/llvm/codegen_llvm.cc#L973) within the existing module, my mental model was that the calling convention was only fixed for calls into external functions, or for callees that may be called externally. Therefore, the internal-only function would be sufficient to modify any matching `call_extern` instances.
> So if we want to state that this is a convention that will be further lowered, just a strawman: (e.g. InternalModuleCall, call_internal)
From the earlier design discussions, this was brought up as a potential later step, for when using `call_extern` becomes too unwieldy, or unable to express the degrees of freedom required by internal calls. Since it seemed that the changes to `call_extern` were legal with the current semantics, we hadn't moved to make a new builtin for it.
> IntraModule might be slightly too generic(since we can also use Packed call intra module),
I'm not quite seeing the issue with the name here. The semantics we were picturing was that while any calling convention may be used for internal calls, only the `kIntraModule` calling convention That is, `kIntraModule` implies an internal function, but not being `kIntraMoudule` does not imply the existence of external calls. The difference would be that a pass could modify the signature of a `kIntraModule` function (e.g. removing an unused argument from the signature, simultaneously updating all callsites), while a PackedFunc could not be modified without breaking the potential external callsites.
> After reading the context, seems we lean towards later. In that case, it might still be useful to specify what would be the default lowering of InternalModuleCall and call_internal.
The concern was that by specifying that behavior, it would enable assumptions of the final calling convention before it had been selected, mixing the different layers of abstraction. That is, somebody could erroneously generate a callsite that follows the PackedFunc API, on the assumption that the callee will also be lowered to the PackedFunc API. By leaving it unspecified, it makes that misunderstanding less likely.
--
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
[GitHub] [tvm] tvm-bot commented on pull request #13569: WIP [hexagon][tir][testing] same-module call tests
Posted by GitBox <gi...@apache.org>.
tvm-bot commented on PR #13569:
URL: https://github.com/apache/tvm/pull/13569#issuecomment-1340256685
<!---bot-comment-->
Thanks for contributing to TVM! Please refer to the contributing guidelines https://tvm.apache.org/docs/contribute/ for useful information and tips. Please request code reviews from [Reviewers](https://github.com/apache/incubator-tvm/blob/master/CONTRIBUTORS.md#reviewers) by @-ing them in a comment.
<sub>Generated by [tvm-bot](https://github.com/apache/tvm/blob/main/ci/README.md#github-actions)</sub>
--
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
[GitHub] [tvm] wrongtest-intellif commented on a diff in pull request #13569: [tir][testing] Enable intra-IRModule primfunc call
Posted by "wrongtest-intellif (via GitHub)" <gi...@apache.org>.
wrongtest-intellif commented on code in PR #13569:
URL: https://github.com/apache/tvm/pull/13569#discussion_r1098195564
##########
include/tvm/ir/function.h:
##########
@@ -63,6 +63,43 @@ enum class CallingConv : int {
* - Implementation: defined by device runtime(e.g. runtime/cuda)
*/
kDeviceKernelLaunch = 2,
+ /*!
+ * \brief For functions only called by other functions within the same IR module.
+ *
+ * This calling convention exists to support one PrimFunc calling another PrimFunc
+ * within the same IRModule.
+ *
+ * Overview / Purpose:
+ *
+ * - This calling convention is intended only for PrimFuncs whose callers reside in
+ * the same IRModule. This is the only supported use case.
+ *
+ * - The details of the calling convention may change frequently as TVM evolves.
+ * Therefore users are discouraged from attempting to use this calling convention
+ * outside of the supported use case(s).
+ *
+ * Current mechanics / usage requirements:
+ *
+ * - A PrimFunc with this calling convention will NOT undergo any of the signature
+ * transformations provided by the MakePackedAPI pass.
+ *
+ * - Supported use cases, and their corresponding unit tests, are all expressed as
+ * TVMScript.
+ *
+ * - The callsite must use `T.call_extern`.
Review Comment:
> Introducing a extra intrinsic
Could we leverage the fact that `call->op` can be `GlobalVar` to explicitly pair with `kIntraModule` function?
For `call_extern` , I believe `call_extern` an intra-module function by name should work in general settings. While except the calling convention issue, it seems also assume the presence of symbol lookup machanism in runtime (like dlsym in glibc), thus may not perfectly match so-called "intra-module" semantic? For example, one may want to compile both \_\_global__ function and \_\_device__ function (maybe kIntraModule) into single cuda module and invoke the \_\_device__ function directly from \_\_global__ function.
--
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
[GitHub] [tvm] wrongtest-intellif commented on a diff in pull request #13569: [tir][testing] Enable intra-IRModule primfunc call
Posted by "wrongtest-intellif (via GitHub)" <gi...@apache.org>.
wrongtest-intellif commented on code in PR #13569:
URL: https://github.com/apache/tvm/pull/13569#discussion_r1098195564
##########
include/tvm/ir/function.h:
##########
@@ -63,6 +63,43 @@ enum class CallingConv : int {
* - Implementation: defined by device runtime(e.g. runtime/cuda)
*/
kDeviceKernelLaunch = 2,
+ /*!
+ * \brief For functions only called by other functions within the same IR module.
+ *
+ * This calling convention exists to support one PrimFunc calling another PrimFunc
+ * within the same IRModule.
+ *
+ * Overview / Purpose:
+ *
+ * - This calling convention is intended only for PrimFuncs whose callers reside in
+ * the same IRModule. This is the only supported use case.
+ *
+ * - The details of the calling convention may change frequently as TVM evolves.
+ * Therefore users are discouraged from attempting to use this calling convention
+ * outside of the supported use case(s).
+ *
+ * Current mechanics / usage requirements:
+ *
+ * - A PrimFunc with this calling convention will NOT undergo any of the signature
+ * transformations provided by the MakePackedAPI pass.
+ *
+ * - Supported use cases, and their corresponding unit tests, are all expressed as
+ * TVMScript.
+ *
+ * - The callsite must use `T.call_extern`.
Review Comment:
> Introducing a extra intrinsic
Could we leverage the fact that `call->op` can be `GlobalVar` to explicitly pair with `kIntraModule` function?
For `call_extern` , I believe `call_extern` an intra-module function by name should work in general settings. While except the calling convention issue, it seems also assume the presence of runtime symbol lookup machanism in runtime (like dlsym in glibc), thus may not perfectly match so-called "intra-module" semantic? For example, one may want to compile both \_\_global__ function and \_\_device__ function (maybe kIntraModule) into single cuda module and invoke the \_\_device__ function directly from \_\_global__ function.
--
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
[GitHub] [tvm] cconvey commented on a diff in pull request #13569: [tir][testing] Enable intra-IRModule primfunc call
Posted by "cconvey (via GitHub)" <gi...@apache.org>.
cconvey commented on code in PR #13569:
URL: https://github.com/apache/tvm/pull/13569#discussion_r1083318682
##########
tests/python/contrib/test_hexagon/test_call_tir.py:
##########
@@ -0,0 +1,248 @@
+# 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.
+
+""" Various tests related to the (WIP) support for having
+one PrimFunc call another PrimFunc within the same IRModule.
+"""
+
+from typing import List
+import pytest
+import numpy as np
+
+import tvm
+import tvm.testing
+import tvm.script
+from tvm.script import tir as T
+
+from tvm.contrib.hexagon.session import Session
+from tvm.contrib.hexagon import allocate_hexagon_array
+from .infrastructure import get_hexagon_target
+
+# NOTE(cconvey): These pylint warnings should be re-enabled as TVM's pylint configuration matures.
+# pylint: disable=missing-function-docstring,no-self-argument,invalid-name
+# pylint: disable=redefined-outer-name,missing-class-docstring
+
+# --------------------------------------------------------------------------------------------------
+# Test parameters
+# --------------------------------------------------------------------------------------------------
+
+# The shape of the original (unsplit) tensors.
+# We assume that each shape describes a non-empty 2D tensor.
+original_shape = tvm.testing.parameter(
+ # degenerate cases...
+ [1, 1],
+ [1, 2],
+ [2, 1],
+ [2, 2],
+ # arbitrary, provided for variety
+ [5, 3],
+ [3, 5],
+)
+
+# This dtype is arbitrary, but it must match the dtype that's hardcoded into the
+# callee's function signature. E.g., 'a_data: T.Ptr[T.int8]'.
+#
+# Hopefully over time we'll find a way to soften this limitation, at least for
+# some approaches to PrimFunc-to-PrimFunc calls.
+dtype = tvm.testing.parameter("int8")
+
+# --------------------------------------------------------------------------------------------------
+# Helper functions / definitions...
+# --------------------------------------------------------------------------------------------------
+
+HEXAGON_TARGET_ = get_hexagon_target("v69")
+
+ENTRY_PRIMFUNC_NAME_ = "main"
+
+
+def get_reference_input_tensor_(shape: list, dtype: str) -> np.array:
+ assert len(shape) == 2
+
+ a = np.ndarray(shape, dtype=dtype)
+ np_dtype = a.dtype
+
+ if np_dtype.kind in ["i", "u"]:
+ # We allow overflow for integer types because it tends to be well-behaved
+ # and well-understood...
+ min_value = np.iinfo(np_dtype).min
+ max_value = np.iinfo(np_dtype).max
+
+ next_value = min_value
+
+ for i in range(shape[0]):
+ for j in range(shape[1]):
+ a[i, j] = next_value
+ next_value += 1
+
+ elif np_dtype.kind == "f":
+ # NOTE: For simplicity, we avoid test data that that require
+ # well-defined behavior on floating-point overflow.
+ # But it may be reasonable to test that in the future.
+ min_value = np.finfo(np_dtype).min
+ max_value = np.finfo(np_dtype).max
+
+ min_input_value = min_value / 2.0 + 1
+ max_input_value = max_value / 2.0 - 2
+ delta = (max_input_value - min_input_value) / (shape[0] * shape[1])
+
+ next_value = min_input_value
+
+ for i in range(shape[0]):
+ for j in range(shape[1]):
+ a[i, j] = next_value
+ next_value += delta
+
+ else:
+ assert False, f"Unexpected data type: {np_dtype}"
+
+ return a
+
+
+def get_reference_output_tensor_(shape: list, dtype: str) -> np.array:
Review Comment:
I think there's a good case for converting `get_reference_input_tensor_` into a fixture eventually, if other unit tests start using similar logic for populating their input tensors.
`get_reference_output_tensor_` is specific to this unit test, because it makes a specific assumption about the intended behavior of the code being tested.
I can see a case for converting `get_reference_input_tensor_` and `get_reference_output_tensor_` into fixtures for _performance_ reasons (caching), but I don't think we're anywhere near that inflection point.
--
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
[GitHub] [tvm] tqchen commented on a diff in pull request #13569: [tir][testing] Enable intra-IRModule primfunc call
Posted by "tqchen (via GitHub)" <gi...@apache.org>.
tqchen commented on code in PR #13569:
URL: https://github.com/apache/tvm/pull/13569#discussion_r1085730953
##########
include/tvm/ir/function.h:
##########
@@ -63,6 +63,43 @@ enum class CallingConv : int {
* - Implementation: defined by device runtime(e.g. runtime/cuda)
*/
kDeviceKernelLaunch = 2,
+ /*!
+ * \brief For functions only called by other functions within the same IR module.
+ *
+ * This calling convention exists to support one PrimFunc calling another PrimFunc
+ * within the same IRModule.
+ *
+ * Overview / Purpose:
+ *
+ * - This calling convention is intended only for PrimFuncs whose callers reside in
+ * the same IRModule. This is the only supported use case.
+ *
+ * - The details of the calling convention may change frequently as TVM evolves.
+ * Therefore users are discouraged from attempting to use this calling convention
+ * outside of the supported use case(s).
+ *
+ * Current mechanics / usage requirements:
+ *
+ * - A PrimFunc with this calling convention will NOT undergo any of the signature
+ * transformations provided by the MakePackedAPI pass.
+ *
+ * - Supported use cases, and their corresponding unit tests, are all expressed as
+ * TVMScript.
+ *
+ * - The callsite must use `T.call_extern`.
Review Comment:
One minor note, we might want to think a bit about possible intrinsics here, given call_extern already have semantics that normally assumes(C semantics). It might be preferrable to have a different intrinsic.
--
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
[GitHub] [tvm] tqchen commented on a diff in pull request #13569: [tir][testing] Enable intra-IRModule primfunc call
Posted by "tqchen (via GitHub)" <gi...@apache.org>.
tqchen commented on code in PR #13569:
URL: https://github.com/apache/tvm/pull/13569#discussion_r1085734468
##########
include/tvm/ir/function.h:
##########
@@ -63,6 +63,43 @@ enum class CallingConv : int {
* - Implementation: defined by device runtime(e.g. runtime/cuda)
*/
kDeviceKernelLaunch = 2,
+ /*!
+ * \brief For functions only called by other functions within the same IR module.
+ *
+ * This calling convention exists to support one PrimFunc calling another PrimFunc
+ * within the same IRModule.
+ *
+ * Overview / Purpose:
+ *
+ * - This calling convention is intended only for PrimFuncs whose callers reside in
+ * the same IRModule. This is the only supported use case.
+ *
+ * - The details of the calling convention may change frequently as TVM evolves.
+ * Therefore users are discouraged from attempting to use this calling convention
+ * outside of the supported use case(s).
+ *
+ * Current mechanics / usage requirements:
+ *
+ * - A PrimFunc with this calling convention will NOT undergo any of the signature
+ * transformations provided by the MakePackedAPI pass.
+ *
+ * - Supported use cases, and their corresponding unit tests, are all expressed as
+ * TVMScript.
+ *
+ * - The callsite must use `T.call_extern`.
Review Comment:
Alternatively, perhaps we can clarify it as C calling conv, effectively pass things as they are, which seems to match the behavior of call_extern and current behavior.
--
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
[GitHub] [tvm] tqchen commented on a diff in pull request #13569: [tir][testing] Enable intra-IRModule primfunc call
Posted by "tqchen (via GitHub)" <gi...@apache.org>.
tqchen commented on code in PR #13569:
URL: https://github.com/apache/tvm/pull/13569#discussion_r1085733259
##########
include/tvm/ir/function.h:
##########
@@ -63,6 +63,13 @@ enum class CallingConv : int {
* - Implementation: defined by device runtime(e.g. runtime/cuda)
*/
kDeviceKernelLaunch = 2,
+ /*!
+ * \brief For functions only called by other functions within the same IR module.
+ *
+ * Indicates that various signature transformations (e.g. those provided by the
+ * MakePackedAPI pass) are not desired.
+ */
+ kIntraModule = 3,
Review Comment:
Would be great to specify that this is a convention that will be lowered (to another low-level convention), or if it is supposed to a final C convention.
--
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