| 1 | ################################################################################ |
| 2 | # |
| 3 | # Copyright (C) 2025 Advanced Micro Devices, Inc. All rights reserved. |
| 4 | # |
| 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy |
| 6 | # of this software and associated documentation files (the "Software"), to deal |
| 7 | # in the Software without restriction, including without limitation the rights |
| 8 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 9 | # copies of the Software, and to permit persons to whom the Software is |
| 10 | # furnished to do so, subject to the following conditions: |
| 11 | # |
| 12 | # The above copyright notice and this permission notice shall be included in |
| 13 | # all copies or substantial portions of the Software. |
| 14 | # |
| 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 21 | # SOFTWARE. |
| 22 | # |
| 23 | ################################################################################ |
| 24 | |
| 25 | import sys |
| 26 | import math |
| 27 | |
| 28 | def reject(state: dict, printSolutionRejectionReason: bool = True, *args) -> bool: |
| 29 | """ |
| 30 | Reject a solution based on its internal state. |
| 31 | |
| 32 | Args: |
| 33 | state: The state of the solution. |
| 34 | printSolutionRejectionReason: If True, print the rejection reason. |
| 35 | *args: Additional arguments to print if rejection occurs. |
| 36 | |
| 37 | Returns: |
| 38 | True if the solution is rejected, False otherwise. |
| 39 | """ |
| 40 | if state and "NoReject" in state and state["NoReject"]: |
| 41 | return False |
| 42 | if printSolutionRejectionReason: |
| 43 | sys.stdout.write("\nreject: ") |
| 44 | for a in args: |
| 45 | print(a) |
| 46 | #traceback.print_stack(None, 2) |
| 47 | solutionIndex = state["SolutionIndex"] if (state != None and "SolutionIndex" in state) else -1 |
| 48 | if solutionIndex != -1: |
| 49 | # If we have valid solutionIndex, this means we are during TensileCreateLibrary stage |
| 50 | # In this stage, all solutions in the logic should be valid |
| 51 | # So if any rejection happens, print the warning for further check |
| 52 | # This will be done only when --global-parameters=PrintSolutionRejectionReason=True |
| 53 | solutionNameMin = state["SolutionNameMin"] if ("SolutionNameMin" in state) else None |
| 54 | # if we don't have SolutionNameMin, we simply use the problemTypeName |
| 55 | solutionNameMin = str(state["ProblemType"]) if (solutionNameMin == None) else solutionNameMin |
| 56 | raise Exception("!! Warning: Any rejection of a LibraryLogic is not expected, please check. \ |
| 57 | SolutionIndex: %d (or SolutionName/ProblemType: %s)"%(solutionIndex, solutionNameMin)) |
| 58 | if state != None: |
| 59 | state["Valid"] = False |
| 60 | return True |
| 61 | |
| 62 | # print a labled variable |
| 63 | def pvar(state, field): |
| 64 | return field + "=" + str(state[field]) |
| 65 | |
| 66 | def roundupRatio(dividend, divisor): |
| 67 | return int(math.ceil(float(dividend) / float(divisor))) |