diff --git a/python/tvm/__init__.py b/python/tvm/__init__.py index f3f908f2ef53..4bc20aac7dd6 100644 --- a/python/tvm/__init__.py +++ b/python/tvm/__init__.py @@ -14,6 +14,7 @@ from . import module from . import node from . import ir_builder +from . import target from . import ndarray as nd from .ndarray import context, cpu, gpu, opencl, cl, metal, mtl, vpi, rocm diff --git a/topi/python/topi/target.py b/python/tvm/target.py similarity index 97% rename from topi/python/topi/target.py rename to python/tvm/target.py index a4724a960972..8fcc44519703 100644 --- a/topi/python/topi/target.py +++ b/python/tvm/target.py @@ -1,4 +1,4 @@ -"""Target management API of topi""" +"""Target management API of tvm""" from __future__ import absolute_import diff --git a/topi/python/topi/__init__.py b/topi/python/topi/__init__.py index 0322f65bc8cc..1306f9d9cac8 100644 --- a/topi/python/topi/__init__.py +++ b/topi/python/topi/__init__.py @@ -16,6 +16,5 @@ from . import nn from . import cuda from . import rasp -from . import target from . import testing from . import util diff --git a/topi/python/topi/nn/__init__.py b/topi/python/topi/nn/__init__.py index 46edac975183..514149b00aa0 100644 --- a/topi/python/topi/nn/__init__.py +++ b/topi/python/topi/nn/__init__.py @@ -3,7 +3,7 @@ from __future__ import absolute_import as _abs from .batch_norm import * -from .convolution import * +from .conv2d import * from .depthwise_convolution import * from .elemwise import * from .dilate import * diff --git a/topi/python/topi/nn/convolution.py b/topi/python/topi/nn/conv2d.py similarity index 97% rename from topi/python/topi/nn/convolution.py rename to topi/python/topi/nn/conv2d.py index 6fe59781729d..fc20d9a9bd15 100644 --- a/topi/python/topi/nn/convolution.py +++ b/topi/python/topi/nn/conv2d.py @@ -1,14 +1,14 @@ # pylint: disable=invalid-name, unused-variable, too-many-locals -"""Convolution operators""" +"""Conv2D operators""" from __future__ import absolute_import as _abs from collections import namedtuple import tvm +from tvm import target as _target from .pad import pad from .util import get_pad_tuple from ..util import simplify -from .. import target as _target -# workload description of convolution +# workload description of conv2d Workload = namedtuple('Workload', ['height', 'width', 'in_filter', 'out_filter', 'hkernel', 'wkernel', 'hpad', 'wpad', 'hstride', 'wstride']) @@ -43,8 +43,8 @@ # platform specific declaration _CONV_DECLARATION = {} -def convolution(data, kernel, stride, padding, layout='NCHW'): - """Convolution operator. +def conv2d(data, kernel, stride, padding, layout='NCHW'): + """Conv2D operator. Parameters ---------- @@ -75,9 +75,9 @@ def convolution(data, kernel, stride, padding, layout='NCHW'): # default declaration if layout == 'NCHW': - conv2d_nchw(data, kernel, stride, padding) + return conv2d_nchw(data, kernel, stride, padding) elif layout == 'HWCN': - conv2d_hwcn(data, kernel, stride, padding) + return conv2d_hwcn(data, kernel, stride, padding) else: raise ValueError("not support this layout {} yet".format(layout)) diff --git a/topi/python/topi/rasp/__init__.py b/topi/python/topi/rasp/__init__.py index 21f68e0c23a6..f0f605eeba9d 100644 --- a/topi/python/topi/rasp/__init__.py +++ b/topi/python/topi/rasp/__init__.py @@ -2,4 +2,4 @@ """Raspberry pi specific declaration and schedules.""" from __future__ import absolute_import as _abs -from .convolution import * +from .conv2d import * diff --git a/topi/python/topi/rasp/convolution.py b/topi/python/topi/rasp/conv2d.py similarity index 96% rename from topi/python/topi/rasp/convolution.py rename to topi/python/topi/rasp/conv2d.py index cb607f4075fb..f48bd4a16ee1 100644 --- a/topi/python/topi/rasp/convolution.py +++ b/topi/python/topi/rasp/conv2d.py @@ -1,13 +1,13 @@ # pylint: disable=invalid-name,unused-variable,invalid-name -"""Convolution schedule on raspberry pi""" +"""Conv2D schedule on raspberry pi""" from __future__ import absolute_import as _abs import tvm -from .. import target as _target +from tvm import target as _target from .. import tag -from ..nn.convolution import SpatialPack, Im2ColPack -from ..nn.convolution import _CONV_DECLARATION, _CONV_SCHEDULE -from ..nn.convolution import _WORKLOADS, _SCH_TO_DECL_FUNC -from ..nn.convolution import _get_workload, _get_schedule +from ..nn.conv2d import SpatialPack, Im2ColPack +from ..nn.conv2d import _CONV_DECLARATION, _CONV_SCHEDULE +from ..nn.conv2d import _WORKLOADS, _SCH_TO_DECL_FUNC +from ..nn.conv2d import _get_workload, _get_schedule from ..nn.util import infer_pad, infer_stride _SCHEDULES = [ @@ -264,7 +264,7 @@ def _schedule_im2col_conv2d(s, data, data_pad, data_col, data_vec, return s -def schedule_convolution(outs): +def schedule_conv2d(outs): """Create schedule for tensors""" s = tvm.create_schedule([x.op for x in outs]) diff --git a/topi/tests/python/test_topi_convolution.py b/topi/tests/python/test_topi_conv2d.py similarity index 71% rename from topi/tests/python/test_topi_convolution.py rename to topi/tests/python/test_topi_conv2d.py index 5dcedf4a4891..b731bfee997a 100644 --- a/topi/tests/python/test_topi_convolution.py +++ b/topi/tests/python/test_topi_conv2d.py @@ -1,4 +1,4 @@ -"""Example code to do convolution.""" +"""Example code to do conv2d.""" import os import numpy as np import tvm @@ -7,20 +7,20 @@ from topi.util import get_const_tuple -def verify_convolution(batch, in_size, in_channel, num_filter, kernel, stride, padding): +def verify_conv2d(batch, in_size, in_channel, num_filter, kernel, stride, padding): in_height = in_width = in_size - with topi.target.rasp(): + with tvm.target.rasp(): A = tvm.placeholder((batch, in_channel, in_height, in_width), name='A') W = tvm.placeholder((num_filter, in_channel, kernel, kernel), name='W') - B = topi.nn.convolution(A, W, stride, padding) + B = topi.nn.conv2d(A, W, stride, padding) - s = topi.rasp.schedule_convolution([B]) + s = topi.rasp.schedule_conv2d([B]) a_shape = get_const_tuple(A.shape) w_shape = get_const_tuple(W.shape) dtype = A.dtype - @memoize("topi.tests.test_topi_convolution.verify_convolution") + @memoize("topi.tests.test_topi_conv2d.verify_conv2d") def get_ref_data(): a_np = np.random.uniform(size=a_shape).astype(dtype) w_np = np.random.uniform(size=w_shape).astype(dtype) @@ -37,8 +37,8 @@ def get_ref_data(): func(a, w, b) np.testing.assert_allclose(b.asnumpy(), b_np, rtol=1e-5) -def test_convolution(): - verify_convolution(1, 56, 64, 64, 3, 1, 1) +def test_conv2d(): + verify_conv2d(1, 56, 64, 64, 3, 1, 1) if __name__ == "__main__": - test_convolution() + test_conv2d()