CUTLASS 3.2.1 (#1113)

* Updates for 3.2.1 release.

* Minor fix in gemm op profiler for raster order.

* Add scheduler mapping for raster order in the kernels.
This commit is contained in:
ANIKET SHIVAM
2023-09-26 14:24:26 -07:00
committed by GitHub
parent e0aaa3c3b3
commit 90d3b0fb18
428 changed files with 22253 additions and 21762 deletions

View File

@ -0,0 +1,75 @@
#################################################################################################
#
# Copyright (c) 2023 - 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: BSD-3-Clause
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# 3. Neither the name of the copyright holder nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
#################################################################################################
"""
Utility script for discovering and running all PyCuTe tests
"""
import argparse
import logging
import pathlib
import unittest
def numeric_log_level(log_level: str) -> int:
"""
Converts the string identifier of the log level into the numeric identifier used
in setting the log level
:param x: string representation of log level (e.g., 'INFO', 'DEBUG')
:type x: str
:return: numeric representation of log level
:rtype: int
"""
numeric_level = getattr(logging, log_level.upper(), None)
if not isinstance(numeric_level, int):
raise ValueError(f"Invalid log level: {log_level}")
return numeric_level
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("--log-level", default='info', type=numeric_log_level, required=False,
help='Logging level to be used by the generator script')
args = parser.parse_args()
# Set the logging level based on the user-provided `--log-level` command-line option
logging.basicConfig(level=args.log_level)
loader = unittest.TestLoader()
script_dir = str(pathlib.Path(__file__).parent.resolve()) + '/'
tests = loader.discover(script_dir, "test_*.py")
test_runner = unittest.runner.TextTestRunner()
results = test_runner.run(tests)
if not results.wasSuccessful():
raise Exception("Test cases failed")

View File

@ -0,0 +1,95 @@
#################################################################################################
#
# Copyright (c) 2023 - 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: BSD-3-Clause
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# 3. Neither the name of the copyright holder nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
#################################################################################################
"""
Unit tests for pycute.coalesce
"""
import logging
import unittest
from pycute import *
_LOGGER = logging.getLogger(__name__)
class TestCoalesce(unittest.TestCase):
def helper_test_coalesce(self, layout):
layoutR = coalesce(layout)
_LOGGER.debug(f"{layout} => {layoutR}")
self.assertEqual(size(layoutR), size(layout))
for i in range(size(layout)):
self.assertEqual(layoutR(i), layout(i))
def test_coalesce(self):
layout = Layout(1,0)
self.helper_test_coalesce(layout)
layout = Layout(1,1)
self.helper_test_coalesce(layout)
layout = Layout((2,4))
self.helper_test_coalesce(layout)
layout = Layout((2,4,6))
self.helper_test_coalesce(layout)
layout = Layout((2,4,6), (1,6,2))
self.helper_test_coalesce(layout)
layout = Layout((2,1,6), (1,7,2))
self.helper_test_coalesce(layout)
layout = Layout((2,1,6), (4,7,8))
self.helper_test_coalesce(layout)
layout = Layout((2,(4,6)))
self.helper_test_coalesce(layout)
layout = Layout((2,4), (4,1))
self.helper_test_coalesce(layout)
layout = Layout((2,4,6), (24,6,1))
self.helper_test_coalesce(layout)
layout = Layout((2,1,3), (2,4,4))
self.helper_test_coalesce(layout)
layout = Layout(((2,2),(2,2)), ((1,4),(8,32)))
self.helper_test_coalesce(layout)
if __name__ == "__main__":
unittest.main()

View File

@ -0,0 +1,92 @@
#################################################################################################
#
# Copyright (c) 2023 - 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: BSD-3-Clause
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# 3. Neither the name of the copyright holder nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
#################################################################################################
"""
Unit tests for pycute.complement
"""
import logging
import unittest
from pycute import *
_LOGGER = logging.getLogger(__name__)
class TestComplement(unittest.TestCase):
def helper_test_complement(self, layout):
layoutR = complement(layout)
_LOGGER.debug(f"{layout} => {layoutR}")
# Post-condition: test disjointness of the codomains
for a in range(size(layout)):
for b in range(size(layoutR)):
assert (layout(a) != layoutR(b)) or (layout(a) == 0 and layoutR(b) == 0)
def test_complement(self):
test = Layout(1,0)
self.helper_test_complement(test)
test = Layout(1,1)
self.helper_test_complement(test)
test = Layout(4,0)
self.helper_test_complement(test)
test = Layout((2,4),(1,2))
self.helper_test_complement(test)
test = Layout((2,3),(1,2))
self.helper_test_complement(test)
test = Layout((2,4),(1,4))
self.helper_test_complement(test)
test = Layout((2,4,8),(8,1,64))
self.helper_test_complement(test)
test = Layout(((2,2),(2,2)),((1,4),(8,32)))
self.helper_test_complement(test)
test = Layout((2,(3,4)),(3,(1,6)))
self.helper_test_complement(test)
test = Layout((4,6),(1,6))
self.helper_test_complement(test)
test = Layout((4,10),(1,10))
self.helper_test_complement(test)
if __name__ == "__main__":
unittest.main()

View File

@ -0,0 +1,204 @@
#################################################################################################
#
# Copyright (c) 2023 - 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: BSD-3-Clause
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# 3. Neither the name of the copyright holder nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
#################################################################################################
"""
Unit tests for pycute.composition
"""
import logging
import unittest
from pycute import *
_LOGGER = logging.getLogger(__name__)
class TestComposition(unittest.TestCase):
def helper_test_composition(self, layoutA, layoutB):
layoutR = composition(layoutA, layoutB)
_LOGGER.debug(f"{layoutA} o {layoutB} => {layoutR}")
# True post-condition: Every coordinate c of layoutB with L1D(c) < size(layoutR) is a coordinate of layoutR.
# Test that R(c) = A(B(c)) for all coordinates c in layoutR
for i in range(size(layoutR)):
self.assertEqual(layoutR(i), layoutA(layoutB(i)))
def test_composition(self):
layoutA = Layout(1,0)
layoutB = Layout(1,0)
self.helper_test_composition(layoutA, layoutB)
layoutA = Layout(1,0)
layoutB = Layout(1,1)
self.helper_test_composition(layoutA, layoutB)
layoutA = Layout(1,1)
layoutB = Layout(1,0)
self.helper_test_composition(layoutA, layoutB)
layoutA = Layout(1,1)
layoutB = Layout(1,1)
self.helper_test_composition(layoutA, layoutB)
layoutA = Layout((4))
layoutB = Layout((4))
self.helper_test_composition(layoutA, layoutB)
layoutA = Layout((4), (2))
layoutB = Layout((4))
self.helper_test_composition(layoutA, layoutB)
layoutA = Layout((4))
layoutB = Layout((4), (2))
self.helper_test_composition(layoutA, layoutB)
layoutA = Layout((4), (0))
layoutB = Layout((4))
self.helper_test_composition(layoutA, layoutB)
layoutA = Layout((4))
layoutB = Layout((4), (0))
self.helper_test_composition(layoutA, layoutB)
layoutA = Layout((1), (0))
layoutB = Layout((4))
self.helper_test_composition(layoutA, layoutB)
layoutA = Layout((4))
layoutB = Layout((1), (0))
self.helper_test_composition(layoutA, layoutB)
layoutA = Layout((4))
layoutB = Layout((2))
self.helper_test_composition(layoutA, layoutB)
layoutA = Layout((4), (2))
layoutB = Layout((2))
self.helper_test_composition(layoutA, layoutB)
layoutA = Layout((4))
layoutB = Layout((2), (2))
self.helper_test_composition(layoutA, layoutB)
layoutA = Layout((4), (2))
layoutB = Layout((2), (2))
self.helper_test_composition(layoutA, layoutB)
layoutA = Layout((12))
layoutB = Layout((4,3))
self.helper_test_composition(layoutA, layoutB)
layoutA = Layout((12), (2))
layoutB = Layout((4,3))
self.helper_test_composition(layoutA, layoutB)
layoutA = Layout((12))
layoutB = Layout((4,3), (3,1))
self.helper_test_composition(layoutA, layoutB)
layoutA = Layout((12), (2))
layoutB = Layout((4,3), (3,1))
self.helper_test_composition(layoutA, layoutB)
layoutA = Layout((12))
layoutB = Layout((2,3), (2,4))
self.helper_test_composition(layoutA, layoutB)
layoutA = Layout((4,3))
layoutB = Layout((4,3))
self.helper_test_composition(layoutA, layoutB)
layoutA = Layout((4,3))
layoutB = Layout((12))
self.helper_test_composition(layoutA, layoutB)
layoutA = Layout((4,3))
layoutB = Layout((6), (2))
self.helper_test_composition(layoutA, layoutB)
layoutA = Layout((4,3))
layoutB = Layout((6,2), (2,1))
self.helper_test_composition(layoutA, layoutB)
layoutA = Layout((4,3), (3,1))
layoutB = Layout((4,3))
self.helper_test_composition(layoutA, layoutB)
layoutA = Layout((4,3), (3,1))
layoutB = Layout((12))
self.helper_test_composition(layoutA, layoutB)
layoutA = Layout((4,3), (3,1))
layoutB = Layout((6), (2))
self.helper_test_composition(layoutA, layoutB)
layoutA = Layout((4,3), (3,1))
layoutB = Layout((6,2), (2,1))
self.helper_test_composition(layoutA, layoutB)
layoutA = Layout((8,8))
layoutB = Layout(((2,2,2), (2,2,2)),((1,16,4), (8,2,32)))
self.helper_test_composition(layoutA, layoutB)
layoutA = Layout((8,8), (8,1))
layoutB = Layout(((2,2,2), (2,2,2)),((1,16,4), (8,2,32)))
self.helper_test_composition(layoutA, layoutB)
layoutA = Layout(((2,2,2), (2,2,2)),((1,16,4), (8,2,32)))
layoutB = Layout(8, 4)
self.helper_test_composition(layoutA, layoutB)
layoutA = Layout(((4,2)), ((1,16)))
layoutB = Layout((4,2), (2,1))
self.helper_test_composition(layoutA, layoutB)
layoutA = Layout((2,2), (2,1))
layoutB = Layout((2,2), (2,1))
self.helper_test_composition(layoutA, layoutB)
layoutA = Layout((4,8,2))
layoutB = Layout((2,2,2), (2,8,1))
self.helper_test_composition(layoutA, layoutB)
layoutA = Layout((4,8,2), (2,8,1))
layoutB = Layout((2,2,2), (1,8,2))
self.helper_test_composition(layoutA, layoutB)
layoutA = Layout((4,8,2), (2,8,1))
layoutB = Layout((4,2,2), (2,8,1))
self.helper_test_composition(layoutA, layoutB)
if __name__ == "__main__":
unittest.main()

View File

@ -0,0 +1,80 @@
#################################################################################################
#
# Copyright (c) 2023 - 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: BSD-3-Clause
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# 3. Neither the name of the copyright holder nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
#################################################################################################
"""
Unit tests for pycute.int_tuple
"""
import unittest
from pycute import *
class TestIntTuple(unittest.TestCase):
def test_product(self):
self.assertEqual(product(2), 2)
self.assertEqual(product((3,2)), 6)
self.assertEqual(product(product(((2,3),4))), 24)
def test_inner_product(self):
self.assertEqual(inner_product(2, 3), 6)
self.assertEqual(inner_product((1,2), (3,2)), 7)
self.assertEqual(inner_product(((2,3),4), ((2,1),2)), 15)
def test_shape_div(self):
self.assertEqual(shape_div((3,4), 6), (1,2))
self.assertEqual(shape_div((3,4), 12), (1,1))
self.assertEqual(shape_div((3,4), 36), (1,1))
self.assertEqual(shape_div(((3,4),6), 36), ((1,1),2))
self.assertEqual(shape_div((6,(3,4)), 36), (1,(1,2)))
def test_prefix_product(self):
self.assertEqual(prefix_product(2), 1)
self.assertEqual(prefix_product((3,2)), (1,3))
self.assertEqual(prefix_product((3,2,4)), (1,3,6))
self.assertEqual(prefix_product(((2,3),4)), ((1,2),6))
self.assertEqual(prefix_product(((2,3),(2, 1, 2),( 5, 2, 1))),
((1,2),(6,12,12),(24,120,240)))

View File

@ -0,0 +1,87 @@
#################################################################################################
#
# Copyright (c) 2023 - 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: BSD-3-Clause
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# 3. Neither the name of the copyright holder nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
#################################################################################################
"""
Unit tests for pycute.left_inverse
"""
import logging
import unittest
from pycute import *
_LOGGER = logging.getLogger(__name__)
class TestLeftInverse(unittest.TestCase):
def helper_test_left_inverse(self, layout):
inv_layout = left_inverse(layout)
_LOGGER.debug(f"{layout} => {inv_layout}")
for i in range(size(layout)):
self.assertEqual(inv_layout(layout(i)), i)
def test_left_inverse(self):
test = Layout(1,0)
self.helper_test_left_inverse(test)
test = Layout((1,1),(0,0))
self.helper_test_left_inverse(test)
test = Layout(1,1)
self.helper_test_left_inverse(test)
test = Layout(4,1)
self.helper_test_left_inverse(test)
test = Layout(4,2)
self.helper_test_left_inverse(test)
test = Layout((8,4),(1,8))
self.helper_test_left_inverse(test)
test = Layout((8,4),(4,1))
self.helper_test_left_inverse(test)
test = Layout((2,4,6),(1,2,8))
self.helper_test_left_inverse(test)
test = Layout((2,4,6),(4,1,8))
self.helper_test_left_inverse(test)
test = Layout((4,2),(1,16))
self.helper_test_left_inverse(test)
if __name__ == "__main__":
unittest.main()

View File

@ -0,0 +1,96 @@
#################################################################################################
#
# Copyright (c) 2023 - 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: BSD-3-Clause
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# 3. Neither the name of the copyright holder nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
#################################################################################################
"""
Unit tests for pycute.left_inverse
"""
import logging
import unittest
from pycute import *
_LOGGER = logging.getLogger(__name__)
class TestRightInverse(unittest.TestCase):
def helper_test_right_inverse(self, layout):
inv_layout = right_inverse(layout)
_LOGGER.debug(f"{layout} => {inv_layout}")
for i in range(size(inv_layout)):
self.assertEqual(layout(inv_layout(i)), i)
def test_right_inverse(self):
test = Layout(1,0)
self.helper_test_right_inverse(test)
test = Layout((1,1),(0,0))
self.helper_test_right_inverse(test)
test = Layout((3,7),(0,0))
self.helper_test_right_inverse(test)
test = Layout(1,1)
self.helper_test_right_inverse(test)
test = Layout(4,0)
self.helper_test_right_inverse(test)
test = Layout(4,1)
self.helper_test_right_inverse(test)
test = Layout(4,2)
self.helper_test_right_inverse(test)
test = Layout((2,4),(0,2))
self.helper_test_right_inverse(test)
test = Layout((8,4),(1,8))
self.helper_test_right_inverse(test)
test = Layout((8,4),(4,1))
self.helper_test_right_inverse(test)
test = Layout((2,4,6),(1,2,8))
self.helper_test_right_inverse(test)
test = Layout((2,4,6),(4,1,8))
self.helper_test_right_inverse(test)
test = Layout((4,2),(1,16))
self.helper_test_right_inverse(test)
if __name__ == "__main__":
unittest.main()

View File

@ -0,0 +1,59 @@
#################################################################################################
#
# Copyright (c) 2023 - 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: BSD-3-Clause
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# 3. Neither the name of the copyright holder nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
#################################################################################################
"""
Unit tests for pycute.typing
"""
import logging
import unittest
from pycute import *
_LOGGER = logging.getLogger(__name__)
class TestTyping(unittest.TestCase):
def helper_test_typing(self, _cls, _obj, cls, expected: bool):
_LOGGER.debug(f"issubclass({_cls}, {cls})")
_LOGGER.debug(f"isinstance({_obj}, {cls})")
self.assertEqual(expected, issubclass(_cls, cls))
self.assertEqual(expected, isinstance(_obj, cls))
def test_typing(self):
self.helper_test_typing(int, 1, Integer, True)
self.helper_test_typing(float, 1., Integer, False)
self.helper_test_typing(str, 'hi', Integer, False)
self.helper_test_typing(bool, False, Integer, False)
if __name__ == '__main__':
unittest.main()