ccaa534b2c
This PR starts the step 0 to phase out relay from the current development main branch. This PR focuses on the python components of relay, autotvm, auto_scheduler. To make the change manageable, we will also do followup steps on te.Schedule and c++ components in followup PRs. To continue support community members who depends on legacy flows, the [v0.19.0](https://github.com/apache/tvm/tree/v0.19.0) branch will continue contain these components. As noted in [discussion on phasing out legacy components](https://discuss.tvm.apache.org/t/phasing-out-legacy-components/17703/30), this would help us to do two purposes: - By removing outdated or redundant elements, we can significantly reduce complexity and improve maintainability. - Unify our focus: Concentrating our efforts on the new unity flow will allow for more efficient development and innovation. It is also a good opportunity for us to revisit and reduce CI time. The past relay legacy flow contains a lot of end to end tests that requires hardware resources to run and causing long CI time. Moving onwards, we can focus more on unit-tests that focuses on structural equality and runs within seconds, while be mindful about tests that requires hardware resources (by restricting them to specific folders and CI nightly in some cases). --- Co-authored-by: Siyuan Feng <hzfengsy@sjtu.edu.cn>
71 lines
2.3 KiB
Python
71 lines
2.3 KiB
Python
# 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.
|
|
# pylint: disable=invalid-name
|
|
"""Common utility for topi test"""
|
|
|
|
import numpy as np
|
|
import scipy.signal
|
|
|
|
|
|
def _convolve2d(data, weights):
|
|
"""2d convolution operator in HW layout.
|
|
|
|
This is intended to be used as a replacement for
|
|
scipy.signals.convolve2d, with wider support for different dtypes.
|
|
scipy.signal.convolve2d does not support all TVM-supported
|
|
dtypes (e.g. float16). Where possible, this function uses
|
|
scipy.signal.convolve2d to take advantage of compiled scipy
|
|
routines, falling back to an explicit loop only where needed.
|
|
|
|
Parameters
|
|
----------
|
|
data : numpy.ndarray
|
|
2-D with shape [in_height, in_width]
|
|
|
|
weights : numpy.ndarray
|
|
2-D with shape [filter_height, filter_width].
|
|
|
|
Returns
|
|
-------
|
|
b_np : np.ndarray
|
|
2-D with shape [out_height, out_width]
|
|
|
|
Return value and layout conventions are matched to
|
|
``scipy.signal.convolve2d(data, weights, mode="valid")``
|
|
"""
|
|
|
|
try:
|
|
return scipy.signal.convolve2d(data, weights, mode="valid")
|
|
except ValueError:
|
|
pass
|
|
|
|
weights = np.rot90(weights, k=2)
|
|
|
|
assert len(data.shape) == len(weights.shape) == 2
|
|
|
|
dtype = data.dtype
|
|
kernel_h, kernel_w = weights.shape
|
|
|
|
output_shape = [a_dim - w_dim + 1 for a_dim, w_dim in zip(data.shape, weights.shape)]
|
|
output = np.zeros(output_shape, dtype=dtype)
|
|
|
|
for y in range(output_shape[0]):
|
|
for x in range(output_shape[1]):
|
|
output[y][x] = np.sum(data[y : y + kernel_h, x : x + kernel_w] * weights)
|
|
|
|
return output
|