Skip to content

Commit df75d5c

Browse files
srkreddy1238GitHub Enterprise
authored andcommitted
Enable nvidia texture tests. (apache#168)
Co-authored-by: Siva <quic_sivb@quicinc.com>
1 parent 728a75a commit df75d5c

6 files changed

Lines changed: 100 additions & 52 deletions

File tree

python/tvm/testing/utils.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -935,6 +935,17 @@ def _check_opencl_vulkan():
935935
parent_features="cuda",
936936
)
937937

938+
# Mark a test as requiring the OpenCL runtime on remote RPC
939+
requires_adreno_opencl = Feature(
940+
"opencl",
941+
long_name="Remote Adreno OpenCL",
942+
cmake_flag="USE_OPENCL",
943+
target_kind_enabled="opencl",
944+
target_kind_hardware=None,
945+
parent_features="gpu",
946+
run_time_check=lambda: os.getenv("RPC_TARGET") is not None,
947+
)
948+
938949
# Mark a test as requiring the OpenCL runtime
939950
requires_opencl = Feature(
940951
"opencl",

tests/python/relax/texture/adreno_utils.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,18 +109,30 @@ def run_cpu(mod, inputs, save_lib=False):
109109

110110

111111
def build_run(mod, inputs, backend, is_adreno=False):
112-
112+
remote = get_rpc()
113113
target = get_target(backend, is_adreno)
114-
tgt = tvm.target.Target(target, host="llvm -mtriple=aarch64-linux-gnu")
114+
if remote is None:
115+
tgt = tvm.target.Target(target, host="llvm")
116+
else:
117+
tgt = tvm.target.Target(target, host="llvm -mtriple=aarch64-linux-gnu")
115118
relax_pipeline = relax.pipeline.get_default_pipeline(tgt)
116119
tir_pipeline = tvm.tir.get_default_tir_pipeline(tgt)
117120
mod = relax_pipeline(mod)
118121
ex = tvm.compile(mod, tgt, tir_pipeline=tir_pipeline)
119122

120-
remote = get_rpc()
121123
if remote is None:
122124
# local execution
123-
dev = tvm.device(target, 0)
125+
if "opencl" in backend:
126+
dev = tvm.opencl(0)
127+
elif "vulkan" in backend:
128+
dev = tvm.vulkan(0)
129+
else:
130+
raise RuntimeError("Unsupported backend")
131+
132+
if "vdevice" in mod.global_infos:
133+
device_arr = [dev for ii in range(len(mod.global_infos["vdevice"]))]
134+
else:
135+
device_arr = [dev]
124136
vm = relax.VirtualMachine(ex, device_arr)
125137
else:
126138
# remote execution
@@ -158,7 +170,8 @@ def build_run(mod, inputs, backend, is_adreno=False):
158170
else:
159171
tvm_output = tvm_output.numpy()
160172

161-
remote.get_function("CloseRPCConnection")()
173+
if remote:
174+
remote.get_function("CloseRPCConnection")()
162175
return tvm_output
163176

164177

tests/python/relax/texture/test_network.py

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -37,27 +37,6 @@
3737
import copy
3838

3939

40-
@pytest.mark.parametrize("dtype", ["float32"])
41-
@pytest.mark.parametrize(
42-
"url, shape_dict",
43-
[
44-
# ("mobilenetv2-12.onnx", {"input": [1, 3, 224, 224]}),
45-
# ("densenet-12.onnx", {"data_0": [1, 3, 224, 224]}),
46-
# ("inception-v2-9.onnx", {"data_0": [1, 3, 224, 224]}),
47-
("resnet18-v2-7.onnx", {"data": [1, 3, 224, 224]}),
48-
# ("resnet50-v2-7.onnx", {"data": [1, 3, 224, 224]}),
49-
],
50-
)
51-
@tvm.testing.requires_opencl_vulkan
52-
def _test_network(url, shape_dict, dtype):
53-
print("Network evaluating .. " + url + " " + dtype)
54-
model = onnx.load("./" + url)
55-
mod = from_onnx(model, shape_dict)
56-
mod1 = from_onnx(model, shape_dict)
57-
58-
verify(mod)
59-
60-
6140
@tvm.testing.requires_opencl_vulkan
6241
@tvm.testing.parametrize_targets("opencl", "vulkan")
6342
def test_network_resnet(target):

tests/python/relax/texture/test_texture_nd.py

Lines changed: 60 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -31,21 +31,27 @@
3131
from tvm.target import Target
3232
from tvm.contrib import ndk
3333
from tvm import tir, DataType
34+
from tvm.rpc import connect_tracker
3435

3536

36-
class RemoteConnection:
37-
def __init__(self):
38-
self.RPC_TRACKER_HOST = os.getenv("TVM_TRACKER_HOST", "localhost")
39-
self.RPC_TRACKER_PORT = int(os.getenv("TVM_TRACKER_PORT", 7979))
40-
self.RPC_KEY = os.getenv("RPC_DEVICE_KEY", "android")
41-
self.tracker = tvm.rpc.connect_tracker(self.RPC_TRACKER_HOST, self.RPC_TRACKER_PORT)
37+
def get_rpc():
38+
"""
39+
Establish an RPC connection to the remote device.
4240
43-
def __enter__(self):
44-
self.remote = self.tracker.request(self.RPC_KEY, priority=0, session_timeout=600)
45-
return self.remote
46-
47-
def __exit__(self, exc_type, exc_value, traceback):
48-
self.remote.get_function("CloseRPCConnection")()
41+
Returns
42+
-------
43+
tvm.rpc.RPCSession or None
44+
The RPC session object if RPC_TARGET is set; otherwise, None.
45+
"""
46+
rpc_target = os.getenv("RPC_TARGET", None)
47+
if rpc_target:
48+
host = os.getenv("TVM_TRACKER_HOST", "localhost")
49+
port = int(os.getenv("TVM_TRACKER_PORT", 9090))
50+
device_key = os.getenv("RPC_DEVICE_KEY", "android")
51+
tracker = connect_tracker(host, port)
52+
return tracker.request(device_key, priority=1, session_timeout=1000)
53+
else:
54+
return None
4955

5056

5157
def preprocess_pipeline(mod: IRModule) -> IRModule:
@@ -96,14 +102,13 @@ def postprocess_pipeline(mod: IRModule) -> IRModule:
96102

97103

98104
@tvm.testing.requires_rpc
99-
@tvm.testing.requires_opencl
100-
@pytest.mark.parametrize(
101-
"target", [Target("opencl -device=adreno", "llvm -mtriple=aarch64-linux-android")]
102-
)
105+
@tvm.testing.requires_adreno_opencl
106+
@pytest.mark.parametrize("backend", ["opencl"])
103107
@pytest.mark.parametrize("dtype", ["int8", "float16", "int16", "float32", "int32"])
104108
@pytest.mark.parametrize("channel_size", [64, 128])
105109
@pytest.mark.parametrize("read_width", [1, 2, 4, 8, 16])
106-
def test_texture_copy(target, dtype, channel_size, read_width):
110+
def test_texture_copy(backend, dtype, channel_size, read_width):
111+
remote = get_rpc()
107112
M, N, K = (256, 1024, 128)
108113
lanes = channel_size // DataType(dtype).bits
109114
if read_width > lanes:
@@ -139,6 +144,12 @@ def schedule_default(blk, lanes):
139144
schedule_default(B_blk, read_width)
140145

141146
mod = TextureCopy
147+
148+
if remote is None:
149+
target = Target(backend + " -device=adreno")
150+
else:
151+
target = Target(backend + " -device=adreno", "llvm -mtriple=aarch64-linux-android")
152+
142153
with target:
143154
mod = preprocess_pipeline(mod)
144155
sch = tir.Schedule(mod)
@@ -148,20 +159,43 @@ def schedule_default(blk, lanes):
148159
ex = relax.build(mod, target)
149160
load_path = "vm_library.so"
150161
inputs = [np.random.randint(0, 128, (M, N)).astype(dtype), np.zeros((M, N), dtype)]
151-
with RemoteConnection() as remote:
152-
with tempfile.TemporaryDirectory() as temp_dir:
162+
with tempfile.TemporaryDirectory() as temp_dir:
163+
if remote is not None:
153164
path = temp_dir + "/" + load_path
154165
ex.export_library(path, fcompile=ndk.create_shared, options=["-shared", "-fPIC", "-lm"])
155-
156166
remote.upload(path)
157167
rexec = remote.load_module(load_path)
158168
dev = remote.cl()
159-
160-
vm = relax.VirtualMachine(rexec, [dev, dev, dev])
161-
inps = [tvm.runtime.tensor(inp, dev) for inp in inputs]
162-
vm["main"](*inps)
163-
164-
np.testing.assert_equal(inps[-1].numpy(), inps[0].numpy())
169+
if "vdevice" in mod.global_infos:
170+
device_arr = [dev for ii in range(len(mod.global_infos["vdevice"]))]
171+
else:
172+
device_arr = [dev]
173+
vm = relax.VirtualMachine(rexec, device_arr)
174+
else:
175+
# local execution
176+
if "opencl" in backend:
177+
dev = tvm.opencl(0)
178+
elif "vulkan" in backend:
179+
dev = tvm.vulkan(0)
180+
else:
181+
raise RuntimeError("Unsupported backend")
182+
183+
if "vdevice" in mod.global_infos:
184+
device_arr = [dev for ii in range(len(mod.global_infos["vdevice"]))]
185+
else:
186+
device_arr = [dev]
187+
vm = relax.VirtualMachine(ex, device_arr)
188+
189+
inps = [tvm.runtime.tensor(inp, dev) for inp in inputs]
190+
vm["main"](*inps)
191+
192+
out1 = inps[-1].numpy()
193+
out2 = inps[0].numpy()
194+
195+
if remote:
196+
remote.get_function("CloseRPCConnection")()
197+
198+
np.testing.assert_equal(out1, out2)
165199

166200

167201
if __name__ == "__main__":

tests/scripts/ci.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -604,6 +604,7 @@ def add_subparser(
604604
[
605605
"./tests/scripts/task_opencl_cpp_unittest.sh {build_dir}",
606606
"./tests/scripts/task_python_unittest.sh",
607+
"./tests/scripts/task_python_unittest_gpuonly.sh",
607608
],
608609
),
609610
"frontend": ("run frontend tests", ["./tests/scripts/task_python_frontend.sh"]),

tests/scripts/task_python_unittest_gpuonly.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,13 @@ export TVM_UNITTEST_TESTSUITE_NAME=python-codegen-vulkan
3434
source tests/scripts/setup-pytest-env.sh
3535

3636
run_pytest ${TVM_UNITTEST_TESTSUITE_NAME}-1 tests/python/codegen/test_target_codegen_vulkan.py
37+
38+
# Adreno
39+
export PYTEST_ADDOPTS=""
40+
export TVM_TEST_TARGETS="opencl"
41+
export TVM_UNITTEST_TESTSUITE_NAME=python-codegen-clml-texture
42+
43+
source tests/scripts/setup-pytest-env.sh
44+
45+
run_pytest ${TVM_UNITTEST_TESTSUITE_NAME}-1 -s tests/python/relax/backend/clml/
46+
run_pytest ${TVM_UNITTEST_TESTSUITE_NAME}-1 tests/python/relax/texture/

0 commit comments

Comments
 (0)