mirror of
https://github.com/pytorch/pytorch.git
synced 2025-10-20 21:14:14 +08:00
This reverts commit 515c19a3856e953c0fe23a0ed4fa844f8eea34d8. Reverted https://github.com/pytorch/pytorch/pull/154165 on behalf of https://github.com/seemethere due to This is failing when attempting to test against executorch main internally, author has acknowledged that this should be reverted ([comment](https://github.com/pytorch/pytorch/pull/154165#issuecomment-2931489616))
60 lines
2.3 KiB
Python
60 lines
2.3 KiB
Python
import unittest
|
|
|
|
from torchgen.executorch.api.types import ExecutorchCppSignature
|
|
from torchgen.local import parametrize
|
|
from torchgen.model import Location, NativeFunction
|
|
|
|
|
|
DEFAULT_NATIVE_FUNCTION, _ = NativeFunction.from_yaml(
|
|
{"func": "foo.out(Tensor input, *, Tensor(a!) out) -> Tensor(a!)"},
|
|
loc=Location(__file__, 1),
|
|
valid_tags=set(),
|
|
)
|
|
|
|
|
|
class ExecutorchCppSignatureTest(unittest.TestCase):
|
|
def setUp(self) -> None:
|
|
self.sig = ExecutorchCppSignature.from_native_function(DEFAULT_NATIVE_FUNCTION)
|
|
|
|
def test_runtime_signature_contains_runtime_context(self) -> None:
|
|
# test if `KernelRuntimeContext` argument exists in `RuntimeSignature`
|
|
with parametrize(
|
|
use_const_ref_for_mutable_tensors=False, use_ilistref_for_tensor_lists=False
|
|
):
|
|
args = self.sig.arguments(include_context=True)
|
|
self.assertEqual(len(args), 3)
|
|
self.assertTrue(any(a.name == "context" for a in args))
|
|
|
|
def test_runtime_signature_does_not_contain_runtime_context(self) -> None:
|
|
# test if `KernelRuntimeContext` argument is missing in `RuntimeSignature`
|
|
with parametrize(
|
|
use_const_ref_for_mutable_tensors=False, use_ilistref_for_tensor_lists=False
|
|
):
|
|
args = self.sig.arguments(include_context=False)
|
|
self.assertEqual(len(args), 2)
|
|
self.assertFalse(any(a.name == "context" for a in args))
|
|
|
|
def test_runtime_signature_declaration_correct(self) -> None:
|
|
with parametrize(
|
|
use_const_ref_for_mutable_tensors=False, use_ilistref_for_tensor_lists=False
|
|
):
|
|
decl = self.sig.decl(include_context=True)
|
|
self.assertEqual(
|
|
decl,
|
|
(
|
|
"torch::executor::Tensor & foo_outf("
|
|
"torch::executor::KernelRuntimeContext & context, "
|
|
"const torch::executor::Tensor & input, "
|
|
"torch::executor::Tensor & out)"
|
|
),
|
|
)
|
|
no_context_decl = self.sig.decl(include_context=False)
|
|
self.assertEqual(
|
|
no_context_decl,
|
|
(
|
|
"torch::executor::Tensor & foo_outf("
|
|
"const torch::executor::Tensor & input, "
|
|
"torch::executor::Tensor & out)"
|
|
),
|
|
)
|