2021-11-24 08:16:32 +08:00
|
|
|
# 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
|
|
|
|
|
2022-02-17 00:34:03 +08:00
|
|
|
# ==============================================================================
|
2021-11-24 08:16:32 +08:00
|
|
|
|
|
|
|
class AddIntModule(torch.nn.Module):
|
|
|
|
def __init__(self):
|
|
|
|
super().__init__()
|
|
|
|
|
|
|
|
@export
|
|
|
|
@annotate_args([
|
|
|
|
None,
|
|
|
|
([], torch.int64, True),
|
|
|
|
([], torch.int64, True),
|
|
|
|
])
|
|
|
|
def forward(self, lhs, rhs):
|
|
|
|
return int(lhs)+int(rhs)
|
|
|
|
|
2022-02-17 00:34:03 +08:00
|
|
|
|
|
|
|
@register_test_case(module_factory=lambda: AddIntModule())
|
|
|
|
def AddIntModule_basic(module, tu: TestUtils):
|
|
|
|
module.forward(torch.randint(-100, 100,()), torch.randint(-100, 100,()))
|
|
|
|
|
|
|
|
# ==============================================================================
|
|
|
|
|
2021-12-17 23:24:56 +08:00
|
|
|
class SubIntModule(torch.nn.Module):
|
|
|
|
def __init__(self):
|
|
|
|
super().__init__()
|
|
|
|
|
|
|
|
@export
|
|
|
|
@annotate_args([
|
|
|
|
None,
|
|
|
|
([], torch.int64, True),
|
|
|
|
([], torch.int64, True),
|
|
|
|
])
|
|
|
|
def forward(self, lhs, rhs):
|
|
|
|
return int(lhs)-int(rhs)
|
|
|
|
|
2022-02-17 00:34:03 +08:00
|
|
|
|
|
|
|
@register_test_case(module_factory=lambda: SubIntModule())
|
|
|
|
def SubIntModule_basic(module, tu: TestUtils):
|
|
|
|
module.forward(torch.randint(-100, 100,()), torch.randint(-100, 100,()))
|
|
|
|
|
|
|
|
# ==============================================================================
|
|
|
|
|
|
|
|
class SubFloatModule(torch.nn.Module):
|
|
|
|
def __init__(self):
|
|
|
|
super().__init__()
|
|
|
|
|
|
|
|
@export
|
|
|
|
@annotate_args([
|
|
|
|
None,
|
|
|
|
([], torch.float64, True),
|
|
|
|
([], torch.float64, True),
|
|
|
|
])
|
|
|
|
def forward(self, lhs, rhs):
|
|
|
|
return float(lhs)-float(rhs)
|
|
|
|
|
|
|
|
|
|
|
|
@register_test_case(module_factory=lambda: SubFloatModule())
|
|
|
|
def SubFloatModule_basic(module, tu: TestUtils):
|
|
|
|
module.forward(torch.rand(()).double(), torch.rand(()).double())
|
|
|
|
|
|
|
|
# ==============================================================================
|
|
|
|
|
2021-12-17 23:24:56 +08:00
|
|
|
class MulIntModule(torch.nn.Module):
|
|
|
|
def __init__(self):
|
|
|
|
super().__init__()
|
|
|
|
|
|
|
|
@export
|
|
|
|
@annotate_args([
|
|
|
|
None,
|
|
|
|
([], torch.int64, True),
|
|
|
|
([], torch.int64, True),
|
|
|
|
])
|
|
|
|
def forward(self, lhs, rhs):
|
|
|
|
return int(lhs)*int(rhs)
|
|
|
|
|
2021-11-24 08:16:32 +08:00
|
|
|
|
2021-12-17 23:24:56 +08:00
|
|
|
@register_test_case(module_factory=lambda: MulIntModule())
|
|
|
|
def MulIntModule_basic(module, tu: TestUtils):
|
|
|
|
module.forward(torch.randint(-100, 100,()), torch.randint(-100, 100,()))
|
2022-02-17 00:34:03 +08:00
|
|
|
|
|
|
|
# ==============================================================================
|