d-smirnov commented on a change in pull request #9704: URL: https://github.com/apache/tvm/pull/9704#discussion_r768640273
########## File path: tests/python/unittest/test_tir_usmp_algo_hill_climb.py ########## @@ -0,0 +1,409 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +import pytest +import random +import tvm +from tvm.tir.usmp.utils import BufferInfo, PoolInfo + + +def _check_max_workspace_size(buffer_pool_allocations, pool_info, size): + max_workspace_size = 0 + for buffer_info, pool_allocation in buffer_pool_allocations.items(): + if pool_allocation.pool_info == pool_info: + size_candidate = pool_allocation.byte_offset + buffer_info.size_bytes + if size_candidate > max_workspace_size: + max_workspace_size = size_candidate + _diff = max_workspace_size.value - size + assert ( + max_workspace_size.value == size + ), "'{}': expected {} got {}, diff {:0.2f}% ({} bytes)".format( + pool_info.pool_name, size, max_workspace_size, 100 * _diff / size, _diff + ) + + +def _verify_conflicts(buffer_info, pool_allocation, buffer_info_map): + """helper to check expected liveness conflicts""" + for conflict in buffer_info.conflicts: + conflict_pool_allocation = buffer_info_map[conflict] + + if conflict_pool_allocation.pool_info == pool_allocation.pool_info: + assert conflict_pool_allocation.byte_offset != pool_allocation.byte_offset + l2 = ( + max( + conflict_pool_allocation.byte_offset + conflict.size_bytes, + pool_allocation.byte_offset + buffer_info.size_bytes, + ) + - min(conflict_pool_allocation.byte_offset, pool_allocation.byte_offset) + ) + assert ( + conflict.size_bytes + buffer_info.size_bytes <= l2 + ), 'Conflicting: \n"{} @{}"\n"{} @{}"'.format( + conflict, conflict_pool_allocation, buffer_info, pool_allocation + ) + + +def _verify_all_conflicts(buffer_pool_allocations): + for buffer_info, pool_allocation in buffer_pool_allocations.items(): + # print( "Processing ", name ) Review comment: Removed -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@tvm.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org