forked from llvm/torch-mlir
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[REFBACKEND] Add support for returning multiple different return types.
Added the dynamic registration of return function to the execution engine. This makes sure that different/multiple return types are supported. Also, updated the .style.yapf indentation to 4.
- Loading branch information
Prashant Kumar
committed
Apr 21, 2022
1 parent
b69db60
commit 33c9d25
Showing
5 changed files
with
140 additions
and
160 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
# See https://llvm.org/LICENSE.txt for license information. | ||
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
# Also available under a BSD-style license. See LICENSE. | ||
|
||
import torch | ||
|
||
from torch_mlir_e2e_test.torchscript.framework import TestUtils | ||
from torch_mlir_e2e_test.torchscript.registry import register_test_case | ||
from torch_mlir_e2e_test.torchscript.annotations import annotate_args, export | ||
|
||
# ============================================================================== | ||
|
||
|
||
class TestMultipleTensorReturn(torch.nn.Module): | ||
|
||
def __init__(self): | ||
super().__init__() | ||
|
||
@export | ||
@annotate_args([ | ||
None, | ||
([-1, -1], torch.float32, True), | ||
([-1, -1], torch.float64, True), | ||
([-1, -1], torch.int32, True), | ||
([-1, -1], torch.int64, True), | ||
([-1, -1], torch.bool, True), | ||
]) | ||
def forward(self, a, b, c, d, e): | ||
return a, b, c, d, e | ||
|
||
|
||
@register_test_case(module_factory=lambda: TestMultipleTensorReturn()) | ||
def TestMultipleTensorReturn_basic(module, tu: TestUtils): | ||
module.forward( | ||
tu.rand(3, 4).to(torch.float32), | ||
tu.rand(2, 3).to(torch.float64), | ||
tu.rand(2, 3).to(torch.int32), | ||
tu.rand(2, 3).to(torch.int64), | ||
tu.rand(2, 3).to(torch.bool)) | ||
|
||
|
||
class TestMultipleTensorAndPrimitiveTypesReturn(torch.nn.Module): | ||
|
||
def __init__(self): | ||
super().__init__() | ||
|
||
@export | ||
@annotate_args([ | ||
None, | ||
([-1, -1], torch.int32, True), | ||
([-1, -1], torch.float64, True), | ||
([-1, -1], torch.bool, True), | ||
]) | ||
def forward(self, a, b, c): | ||
d = 1 | ||
e = 2.3 | ||
return a, b, c, d, e | ||
|
||
|
||
@register_test_case( | ||
module_factory=lambda: TestMultipleTensorAndPrimitiveTypesReturn()) | ||
def TestMultipleTensorAndPrimitiveTypesReturn_basic(module, tu: TestUtils): | ||
module.forward( | ||
tu.rand(3, 4).to(torch.int32), | ||
tu.rand(2, 3).to(torch.float64), | ||
tu.rand(2, 3).to(torch.bool)) | ||
|
||
|
||
# ============================================================================== |