Skip to content

Commit

Permalink
[REFACTOR] Remainings of util => utils (apache#6778)
Browse files Browse the repository at this point in the history
  • Loading branch information
tqchen authored Oct 29, 2020
1 parent b305204 commit c8064b3
Show file tree
Hide file tree
Showing 332 changed files with 618 additions and 619 deletions.
2 changes: 1 addition & 1 deletion apps/android_camera/models/prepare_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

import tvm
import tvm.relay as relay
from tvm.contrib import util, ndk, graph_runtime as runtime
from tvm.contrib import utils, ndk, graph_runtime as runtime
from tvm.contrib.download import download_testdata, download

target = "llvm -mtriple=arm64-linux-android"
Expand Down
4 changes: 2 additions & 2 deletions apps/android_rpc/tests/android_rpc_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from tvm import te
import os
from tvm import rpc
from tvm.contrib import util, ndk
from tvm.contrib import utils, ndk
import numpy as np

# Set to be address of tvm proxy.
Expand All @@ -50,7 +50,7 @@ def test_rpc_module():
A = te.placeholder((n,), name="A")
B = te.compute(A.shape, lambda *i: A(*i) + 1.0, name="B")
a_np = np.random.uniform(size=1024).astype(A.dtype)
temp = util.tempdir()
temp = utils.tempdir()

# Establish remote connection with target hardware
tracker = rpc.connect_tracker(tracker_host, tracker_port)
Expand Down
2 changes: 1 addition & 1 deletion apps/benchmark/arm_cpu_imagenet_bench.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

import tvm
from tvm import te
from tvm.contrib.util import tempdir
from tvm.contrib.utils import tempdir
import tvm.contrib.graph_runtime as runtime
from tvm import relay

Expand Down
2 changes: 1 addition & 1 deletion apps/benchmark/mobile_gpu_imagenet_bench.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

import tvm
from tvm import te
from tvm.contrib.util import tempdir
from tvm.contrib.utils import tempdir
import tvm.contrib.graph_runtime as runtime
from tvm import relay

Expand Down
4 changes: 2 additions & 2 deletions apps/ios_rpc/tests/ios_rpc_mobilenet.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from tvm.relay import transform
from tvm.relay.op.annotation import compiler_begin, compiler_end
from tvm.relay.quantize.quantize import prerequisite_optimize
from tvm.contrib import util, xcode, graph_runtime, coreml_runtime
from tvm.contrib import utils, xcode, graph_runtime, coreml_runtime
from tvm.contrib.target import coreml as _coreml

import os
Expand Down Expand Up @@ -98,7 +98,7 @@ def get_model(model_name, data_shape):


def test_mobilenet():
temp = util.tempdir()
temp = utils.tempdir()
image, synset = prepare_input()
model, params = get_model("mobilenetv2_1.0", image.shape)

Expand Down
4 changes: 2 additions & 2 deletions apps/ios_rpc/tests/ios_rpc_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import re
import sys
from tvm import rpc
from tvm.contrib import util, xcode
from tvm.contrib import utils, xcode
import numpy as np

# Set to be address of tvm proxy.
Expand Down Expand Up @@ -59,7 +59,7 @@ def test_rpc_module():
n = tvm.runtime.convert(1024)
A = te.placeholder((n,), name="A")
B = te.compute(A.shape, lambda *i: A(*i) + 1.0, name="B")
temp = util.tempdir()
temp = utils.tempdir()
s = te.create_schedule(B.op)
xo, xi = s[B].split(B.op.axis[0], factor=64)
s[B].bind(xi, te.thread_axis("threadIdx.x"))
Expand Down
2 changes: 1 addition & 1 deletion apps/topi_recipe/conv/depthwise_conv2d_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from tvm.contrib import nvcc

from tvm import topi
from tvm.topi.util import get_const_tuple
from tvm.topi.utils import get_const_tuple
from tvm.topi.cuda.depthwise_conv2d import (
schedule_depthwise_conv2d_nchw,
schedule_depthwise_conv2d_nhwc,
Expand Down
2 changes: 1 addition & 1 deletion apps/topi_recipe/conv/test_conv2d_hwcn_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from tvm import te
from tvm.contrib import nvcc
from tvm import topi
from tvm.topi.util import get_const_tuple
from tvm.topi.utils import get_const_tuple

TASK = "conv2d_hwcn_map"
USE_MANUAL_CODE = False
Expand Down
4 changes: 2 additions & 2 deletions apps/topi_recipe/gemm/android_gemm_square.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from tvm import te
import os
from tvm import rpc
from tvm.contrib import util, ndk
from tvm.contrib import utils, ndk
import numpy as np

# Set to be address of tvm proxy.
Expand Down Expand Up @@ -121,7 +121,7 @@ def test_gemm_gpu(N, times, bn, num_block, num_thread):
print(tvm.lower(s, [A, B, C], simple_mode=True))

f = tvm.build(s, [A, B, C], "opencl", target_host=target, name="gemm_gpu")
temp = util.tempdir()
temp = utils.tempdir()
path_dso = temp.relpath("gemm_gpu.so")
f.export_library(path_dso, ndk.create_shared)

Expand Down
6 changes: 3 additions & 3 deletions docs/api/python/contrib.rst
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,9 @@ tvm.contrib.tar
:members:


tvm.contrib.util
~~~~~~~~~~~~~~~~
.. automodule:: tvm.contrib.util
tvm.contrib.utils
~~~~~~~~~~~~~~~~~
.. automodule:: tvm.contrib.utils
:members:


Expand Down
4 changes: 2 additions & 2 deletions docs/dev/introduction_to_module_serialization.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Let us build one ResNet-18 workload for GPU as an example first.
from tvm import relay
from tvm.relay import testing
from tvm.contrib import util
from tvm.contrib import utils
import tvm
# Resnet18 workload
Expand All @@ -43,7 +43,7 @@ Let us build one ResNet-18 workload for GPU as an example first.
_, resnet18_lib, _ = relay.build_module.build(resnet18_mod, "cuda", params=resnet18_params)
# create one tempory directory
temp = util.tempdir()
temp = utils.tempdir()
# path lib
file_name = "deploy.so"
Expand Down
2 changes: 1 addition & 1 deletion golang/sample/deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
# Save Compiled Module
# --------------------
from tvm.contrib import cc
from tvm.contrib import util
from tvm.contrib import utils

fadd.save("deploy.o")
cc.create_shared("deploy.so", ["deploy.o"])
2 changes: 1 addition & 1 deletion golang/src/util.go → golang/src/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

/*!
* \brief gotvm package source for common utilities
* \file util.go
* \file utils.go
*/

package gotvm
Expand Down
2 changes: 1 addition & 1 deletion jvm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ There's nothing special for this part. The following Python snippet generate add
import os
import tvm
from tvm import te
from tvm.contrib import cc, util
from tvm.contrib import cc, utils

def test_add(target_dir):
n = te.var("n")
Expand Down
2 changes: 1 addition & 1 deletion jvm/core/src/test/scripts/test_add_cpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import tvm
from tvm import te
from tvm.contrib import cc, util
from tvm.contrib import cc, utils


def test_add(target_dir):
Expand Down
2 changes: 1 addition & 1 deletion jvm/core/src/test/scripts/test_add_gpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import tvm
from tvm import te
from tvm.contrib import cc, util
from tvm.contrib import cc, utils


def test_add(target_dir):
Expand Down
1 change: 0 additions & 1 deletion python/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
# under the License.
# pylint: disable=invalid-name, exec-used
"""Setup TVM package."""
from __future__ import absolute_import
import os
import shutil
import sys
Expand Down
2 changes: 1 addition & 1 deletion python/tvm/auto_scheduler/auto_schedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class HardwareParams(Object):
"""The parameters of target hardware used to guide the search policy
TODO(jcf94): This is considered to be merged with the new Target specification:
https://discuss.tvm.ai/t/rfc-tvm-target-specification/6844
https://discuss.tvm.apache.org/t/rfc-tvm-target-specification/6844
Parameters
----------
Expand Down
2 changes: 1 addition & 1 deletion python/tvm/autotvm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
from . import record
from . import task
from . import tuner
from . import util
from . import utils
from . import env
from . import tophub

Expand Down
2 changes: 1 addition & 1 deletion python/tvm/autotvm/graph_tuner/base_graph_tuner.py
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ def _callback(_, inputs, results):
# Rule out invalid layout transformations
out = topi.layout_transform(data, in_layout, out_layout)
out_flops = 1
for i in topi.util.get_const_tuple(out.shape):
for i in topi.utils.get_const_tuple(out.shape):
out_flops *= i

if flops != out_flops:
Expand Down
2 changes: 1 addition & 1 deletion python/tvm/autotvm/measure/measure_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
from tvm.driver import build
from tvm.contrib import nvcc, ndk, tar

from ..util import get_const_tuple
from ..utils import get_const_tuple
from ..env import AutotvmGlobalScope
from ..task.space import InstantiationError

Expand Down
2 changes: 1 addition & 1 deletion python/tvm/autotvm/task/space.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

from tvm.te import schedule, thread_axis
from tvm.tir import expr
from tvm.autotvm.util import get_const_int
from tvm.autotvm.utils import get_const_int

Axis = namedtuple("Axis", ["space", "index"])

Expand Down
3 changes: 2 additions & 1 deletion python/tvm/autotvm/task/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
from tvm.te import placeholder, tensor
from tvm.tir import expr

from ..util import get_const_int, get_const_tuple

from ..utils import get_const_int, get_const_tuple
from .dispatcher import ApplyConfig, DispatchContext
from .space import ConfigSpace

Expand Down
2 changes: 1 addition & 1 deletion python/tvm/autotvm/tophub.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
from ..target import Target
from ..contrib.download import download
from .record import load_from_file
from .util import EmptyContext
from .utils import EmptyContext

# environment variable to read TopHub location
AUTOTVM_TOPHUB_LOC_VAR = "TOPHUB_LOCATION"
Expand Down
2 changes: 1 addition & 1 deletion python/tvm/autotvm/tuner/callback.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import numpy as np

from .. import record
from ..util import format_si_prefix
from ..utils import format_si_prefix

logger = logging.getLogger("autotvm")

Expand Down
2 changes: 1 addition & 1 deletion python/tvm/autotvm/tuner/metric.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import numpy as np

from ..util import get_rank
from ..utils import get_rank


def max_curve(trial_scores):
Expand Down
2 changes: 1 addition & 1 deletion python/tvm/autotvm/tuner/sa_model_optimizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

import numpy as np

from ..util import sample_ints
from ..utils import sample_ints
from .model_based_tuner import ModelOptimizer, knob2point, point2knob

logger = logging.getLogger("autotvm")
Expand Down
4 changes: 2 additions & 2 deletions python/tvm/autotvm/tuner/tuner.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import numpy as np

from ..measure import MeasureInput, create_measure_batch
from ..util import format_si_prefix
from ..utils import format_si_prefix

from ..env import GLOBAL_SCOPE

Expand Down Expand Up @@ -107,7 +107,7 @@ def tune(self, n_trial, measure_option, early_stopping=None, callbacks=(), si_pr
with no return value. These callback functions will be called on
every measurement pair. See autotvm/tuner/callback.py for some examples.
si_prefix: str
One of tvm.autotvm.util.SI_PREFIXES. The SI prefix to use when reporting FLOPS.
One of tvm.autotvm.utils.SI_PREFIXES. The SI prefix to use when reporting FLOPS.
"""
measure_batch = create_measure_batch(self.task, measure_option)
n_parallel = getattr(measure_batch, "n_parallel", 1)
Expand Down
2 changes: 1 addition & 1 deletion python/tvm/autotvm/tuner/xgboost_cost_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
xgb = None

from .. import feature
from ..util import get_rank
from ..utils import get_rank
from .metric import max_curve, recall_curve, cover_curve
from .model_based_tuner import CostModel, FeatureCache

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import os
import subprocess
import tvm._ffi
from . import util
from . import utils

# TODO does this file still belong in `contrib`. is it too µTVM-specific?

Expand Down Expand Up @@ -217,7 +217,7 @@ def tvm_callback_relocate_binary(
stack_pointer_init=stack_pointer_init,
)

tmp_dir = util.tempdir()
tmp_dir = utils.tempdir()
rel_obj_path = tmp_dir.relpath("relocated.obj")
rel_ld_script_path = tmp_dir.relpath("relocate.lds")
with open(rel_ld_script_path, "w") as f:
Expand Down Expand Up @@ -265,7 +265,7 @@ def tvm_callback_read_binary_section(binary, section, toolchain_prefix):
section_bin : bytearray
contents of the read section
"""
tmp_dir = util.tempdir()
tmp_dir = utils.tempdir()
tmp_bin = tmp_dir.relpath("temp.bin")
tmp_section = tmp_dir.relpath("tmp_section.bin")
with open(tmp_bin, "wb") as out_file:
Expand Down Expand Up @@ -306,7 +306,7 @@ def tvm_callback_get_symbol_map(binary, toolchain_prefix):
map of defined symbols to addresses, encoded as a series of
alternating newline-separated keys and values
"""
tmp_dir = util.tempdir()
tmp_dir = utils.tempdir()
tmp_obj = tmp_dir.relpath("tmp_obj.bin")
with open(tmp_obj, "wb") as out_file:
out_file.write(bytes(binary))
Expand Down
8 changes: 4 additions & 4 deletions python/tvm/contrib/clang.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

from tvm._ffi.base import py_str
import tvm.target
from . import util
from . import utils


def find_clang(required=True):
Expand Down Expand Up @@ -49,7 +49,7 @@ def find_clang(required=True):
cc_list += ["clang-%d" % major]
cc_list += ["clang"]
cc_list += ["clang.exe"]
valid_list = [util.which(x) for x in cc_list]
valid_list = [utils.which(x) for x in cc_list]
valid_list = [x for x in valid_list if x]
if not valid_list and required:
raise RuntimeError("cannot find clang, candidates are: " + str(cc_list))
Expand Down Expand Up @@ -83,12 +83,12 @@ def create_llvm(inputs, output=None, options=None, cc=None):
cc = cc if cc else find_clang()[0]
cmd = [cc]
cmd += ["-S", "-emit-llvm"]
temp = util.tempdir()
temp = utils.tempdir()
output = output if output else temp.relpath("output.ll")
inputs = [inputs] if isinstance(inputs, str) else inputs
input_files = []
for i, code in enumerate(inputs):
if util.is_source_path(code):
if utils.is_source_path(code):
input_files.append(code)
else:
temp_path = temp.relpath("input%d.cc" % i)
Expand Down
Loading

0 comments on commit c8064b3

Please sign in to comment.