Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion python/tvm/relay/frontend/tflite.py
Original file line number Diff line number Diff line change
Expand Up @@ -1549,7 +1549,7 @@ def convert_gather(self, op):
assert axis < data_dim, "Axis out of bounds"

if self.has_expr(indices.tensor_idx):
indices_expr = self.get_expr(indices.tensor_idx)
indices_expr = _op.cast(self.get_expr(indices.tensor_idx), "int32")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you need this _op.cast?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was a bug I encountered while importing other tflite models.

Those models not added here as they are time consuming, but planning to add them to benchmarking scripts.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@leandron, @AndrewZhaoLuo, @masahi I have doubts, should the test be added for this change or not?
Other changes LGTM.

else:
indices_val = self.get_tensor_value(indices)
indices_expr = self.exp_tab.new_const(
Expand Down
39 changes: 39 additions & 0 deletions tests/python/relay/opencl_texture/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# 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 os
import tvm
from tvm import rpc
import pytest


@pytest.fixture(scope="session")
def remote():
if (
"TVM_TRACKER_HOST" in os.environ
and "TVM_TRACKER_PORT" in os.environ
and "RPC_DEVICE_KEY" in os.environ
):

rpc_tracker_host = os.environ["TVM_TRACKER_HOST"]
rpc_tracker_port = int(os.environ["TVM_TRACKER_PORT"])
rpc_device_key = os.environ["RPC_DEVICE_KEY"]
tracker = rpc.connect_tracker(rpc_tracker_host, rpc_tracker_port)
remote = tracker.request(rpc_device_key, priority=0, session_timeout=600)
return remote
else:
return None
100 changes: 62 additions & 38 deletions tests/python/relay/opencl_texture/test_conv2d_nchw_texture.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

@tvm.testing.requires_opencl
@tvm.testing.parametrize_targets("opencl -device=adreno")
def test_conv2d_inceptionv3_64x35x35_96x64x3x3_nopad(target, dtype):
def test_conv2d_inceptionv3_64x35x35_96x64x3x3_nopad(remote, target, dtype):
input_shape = (1, 32, 42, 42)
filter_shape = (96, 32, 3, 3)
bias_shape = (1, 96, 1, 1)
Expand Down Expand Up @@ -65,12 +65,14 @@ def test_conv2d_inceptionv3_64x35x35_96x64x3x3_nopad(target, dtype):
"bias": tvm.nd.array(bias_data),
}

build_run_compare(mod, params1, {"data": input_shape}, dtype, target, [], gpu_preprocess)
build_run_compare(
remote, mod, params1, {"data": input_shape}, {"data": dtype}, target, [], gpu_preprocess
)


@tvm.testing.requires_opencl
@tvm.testing.parametrize_targets("opencl -device=adreno")
def test_conv2d_inceptionv3_64x35x35_96x64x3x3_nopad_pass(target, dtype):
def test_conv2d_inceptionv3_64x35x35_96x64x3x3_nopad_pass(remote, target, dtype):
input_shape = (1, 32, 40, 40)
filter_shape = (96, 32, 2, 2)
bias_shape = (1, 96, 1, 1)
Expand Down Expand Up @@ -105,12 +107,14 @@ def test_conv2d_inceptionv3_64x35x35_96x64x3x3_nopad_pass(target, dtype):
"bias": tvm.nd.array(bias_data),
}

build_run_compare(mod, params1, {"data": input_shape}, dtype, target, [], gpu_preprocess)
build_run_compare(
remote, mod, params1, {"data": input_shape}, {"data": dtype}, target, [], gpu_preprocess
)


@tvm.testing.requires_opencl
@tvm.testing.parametrize_targets("opencl -device=adreno")
def test_conv2d_inceptionv3_35_35_strides(target, dtype):
def test_conv2d_inceptionv3_35_35_strides(remote, target, dtype):
input_shape = (1, 48, 35, 35)
filter_shape = (64, 48, 5, 5)
bias_shape = (1, 64, 1, 1)
Expand Down Expand Up @@ -145,12 +149,14 @@ def test_conv2d_inceptionv3_35_35_strides(target, dtype):
"bias": tvm.nd.array(bias_data),
}

build_run_compare(mod, params1, {"data": input_shape}, dtype, target, [], gpu_preprocess)
build_run_compare(
remote, mod, params1, {"data": input_shape}, {"data": dtype}, target, [], gpu_preprocess
)


@tvm.testing.requires_opencl
@tvm.testing.parametrize_targets("opencl -device=adreno")
def test_conv2d_resnet50_v2_nchw_3c(target, dtype):
def test_conv2d_resnet50_v2_nchw_3c(remote, target, dtype):
input_shape = (1, 3, 224, 224)
filter_shape = (64, 3, 7, 7)
bias_shape = (1, 64, 1, 1)
Expand Down Expand Up @@ -186,12 +192,12 @@ def test_conv2d_resnet50_v2_nchw_3c(target, dtype):
"bias": tvm.nd.array(bias_data),
}

build_run_compare(mod, params1, {"data": input_shape}, dtype, target)
build_run_compare(remote, mod, params1, {"data": input_shape}, {"data": dtype}, target)


@tvm.testing.requires_opencl
@tvm.testing.parametrize_targets("opencl -device=adreno")
def test_conv2d_inceptionv3_nchw_3c(target, dtype):
def test_conv2d_inceptionv3_nchw_3c(remote, target, dtype):
input_shape = (1, 3, 299, 299)
filter_shape = (64, 3, 3, 3)
bias_shape = (1, 64, 1, 1)
Expand Down Expand Up @@ -226,12 +232,12 @@ def test_conv2d_inceptionv3_nchw_3c(target, dtype):
"bias": tvm.nd.array(bias_data),
}

build_run_compare(mod, params1, {"data": input_shape}, dtype, target)
build_run_compare(remote, mod, params1, {"data": input_shape}, {"data": dtype}, target)


@tvm.testing.requires_opencl
@tvm.testing.parametrize_targets("opencl -device=adreno")
def test_conv2d_1x1_16c16spatial(target, dtype):
def test_conv2d_1x1_16c16spatial(remote, target, dtype):
input_shape = (1, 16, 256, 256)
filter_shape = (32, 16, 4, 4)
bias_shape = (1, 32, 1, 1)
Expand Down Expand Up @@ -266,12 +272,12 @@ def test_conv2d_1x1_16c16spatial(target, dtype):
"bias": tvm.nd.array(bias_data),
}

build_run_compare(mod, params1, {"data": input_shape}, dtype, target)
build_run_compare(remote, mod, params1, {"data": input_shape}, {"data": dtype}, target)


@tvm.testing.requires_opencl
@tvm.testing.parametrize_targets("opencl -device=adreno")
def test_conv2d_4x4_16c16pad(target, dtype):
def test_conv2d_4x4_16c16pad(remote, target, dtype):
input_shape = (1, 32, 256, 256)
filter_shape = (32, 32, 4, 4)
bias_shape = (1, 32, 1, 1)
Expand Down Expand Up @@ -306,12 +312,12 @@ def test_conv2d_4x4_16c16pad(target, dtype):
"bias": tvm.nd.array(bias_data),
}

build_run_compare(mod, params1, {"data": input_shape}, dtype, target)
build_run_compare(remote, mod, params1, {"data": input_shape}, {"data": dtype}, target)


@tvm.testing.requires_opencl
@tvm.testing.parametrize_targets("opencl -device=adreno")
def test_conv2d_4x4x4_16c16pad(target, dtype):
def test_conv2d_4x4x4_16c16pad(remote, target, dtype):
input_shape = (1, 32, 256, 256)
filter_shape = (4, 32, 4, 4)
bias_shape = (1, 4, 1, 1)
Expand Down Expand Up @@ -346,12 +352,12 @@ def test_conv2d_4x4x4_16c16pad(target, dtype):
"bias": tvm.nd.array(bias_data),
}

build_run_compare(mod, params1, {"data": input_shape}, dtype, target)
build_run_compare(remote, mod, params1, {"data": input_shape}, {"data": dtype}, target)


@tvm.testing.requires_opencl
@tvm.testing.parametrize_targets("opencl -device=adreno")
def test_conv2d_yolov3_v2_nchw_3c(target, dtype):
def test_conv2d_yolov3_v2_nchw_3c(remote, target, dtype):
input_shape = (1, 1024, 13, 13)
filter_shape = (255, 1024, 1, 1)
A = relay.var("data", shape=input_shape, dtype=dtype)
Expand Down Expand Up @@ -379,12 +385,12 @@ def test_conv2d_yolov3_v2_nchw_3c(target, dtype):
"weight": tvm.nd.array(filter_data),
}

build_run_compare(mod, params, {"data": input_shape}, dtype, target)
build_run_compare(remote, mod, params, {"data": input_shape}, {"data": dtype}, target)


@tvm.testing.requires_opencl
@tvm.testing.parametrize_targets("opencl -device=adreno")
def test_conv2d_vgg16_winograd_4d(target, dtype):
def test_conv2d_vgg16_winograd_4d(remote, target, dtype):
input_shape = (1, 512, 28, 28)
filter_shape = (512, 512, 3, 3)
bias_shape = (1, 512, 1, 1)
Expand Down Expand Up @@ -424,15 +430,15 @@ def test_conv2d_vgg16_winograd_4d(target, dtype):
f'{{"input": ["opencl -keys=adreno,opencl,gpu -device=adreno -max_num_threads=256", "conv2d_nchw_winograd.image2d", [["TENSOR", [1, 512, 28, 28], "{dtype}"], ["TENSOR", [512, 512, 3, 3], "{dtype}"], [1, 1], [1, 1, 1, 1], [1, 1], "{dtype}"], {{}}], "config": {{"index": 1591, "code_hash": null, "entity": [["auto_unroll_max_step", "ot", 4], ["tile_y", "sp", [-1, 1, 32]], ["tile_x", "sp", [-1, 4, 2]], ["tile_rc", "sp", [-1, 8]]]}}, "result": [[0.0037244], 0, 7.06374192237854, 1653898629.7427933], "version": 0.2, "tvm_version": "0.8.dev0"}}\n'
)
graph = build_run_compare(
mod, params1, {"data": input_shape}, dtype, target, stat_file=stat_file
remote, mod, params1, {"data": input_shape}, {"data": dtype}, target, stat_file=stat_file
)
matches = re.findall("winograd", graph)
assert len(matches) > 0


@tvm.testing.requires_opencl
@tvm.testing.parametrize_targets("opencl -device=adreno")
def test_conv2d_winograd_conv(target, dtype):
def test_conv2d_winograd_conv(remote, target, dtype):
input_shape = (1, 4, 3, 3)
A = relay.var("data", shape=input_shape, dtype=dtype)
filter_shape3 = (8, 4, 3, 3)
Expand Down Expand Up @@ -471,15 +477,15 @@ def test_conv2d_winograd_conv(target, dtype):
f'{{"input": ["opencl -keys=adreno,opencl,gpu -device=adreno -max_num_threads=256", "conv2d_nchw_winograd.image2d", [["TENSOR", [1, 4, 3, 3], "{dtype}"], ["TENSOR", [8, 4, 3, 3], "{dtype}"], [1, 1], [1, 1, 1, 1], [1, 1], "{dtype}"], {{}}], "config": {{"index": 1591, "code_hash": null, "entity": [["auto_unroll_max_step", "ot", 4], ["tile_y", "sp", [-1, 1, 32]], ["tile_x", "sp", [-1, 4, 2]], ["tile_rc", "sp", [-1, 8]]]}}, "result": [[0.0037244], 0, 7.06374192237854, 1653898629.7427933], "version": 0.2, "tvm_version": "0.8.dev0"}}\n'
)
graph = build_run_compare(
mod, params1, {"data": input_shape}, dtype, target, stat_file=stat_file
remote, mod, params1, {"data": input_shape}, {"data": dtype}, target, stat_file=stat_file
)
matches = re.findall("winograd", graph)
assert len(matches) > 0


@tvm.testing.requires_opencl
@tvm.testing.parametrize_targets("opencl -device=adreno")
def test_residual_block(target, dtype):
def test_residual_block(remote, target, dtype):
"""
- some kind of residual block followed by convolution to have texture after residual block
- scalar data type verification which should be mapped to global memory scope
Expand Down Expand Up @@ -596,12 +602,14 @@ def test_residual_block(target, dtype):
"",
]

build_run_compare(mod, params1, {"data": input_shape}, dtype, target, static_memory_scope)
build_run_compare(
remote, mod, params1, {"data": input_shape}, {"data": dtype}, target, static_memory_scope
)


@tvm.testing.requires_opencl
@tvm.testing.parametrize_targets("opencl -device=adreno")
def test_concat(target, dtype):
def test_concat(remote, target, dtype):
"""
layout_transform (NCHW->NCHW4c)
| <- buffer
Expand Down Expand Up @@ -708,12 +716,14 @@ def test_concat(target, dtype):

static_memory_scope = []

build_run_compare(mod, params1, {"data": input_shape}, dtype, target, static_memory_scope)
build_run_compare(
remote, mod, params1, {"data": input_shape}, {"data": dtype}, target, static_memory_scope
)


@tvm.testing.requires_opencl
@tvm.testing.parametrize_targets("opencl -device=adreno")
def test_pooling_branching_texture_params(target, dtype):
def test_pooling_branching_texture_params(remote, target, dtype):
"""
Verification of the pooling and many branches having textures
layout_transform (NCHW->NCHW4c)
Expand Down Expand Up @@ -834,12 +844,14 @@ def test_pooling_branching_texture_params(target, dtype):
"",
]

build_run_compare(mod, params1, {"data": input_shape}, dtype, target, static_memory_scope)
build_run_compare(
remote, mod, params1, {"data": input_shape}, {"data": dtype}, target, static_memory_scope
)


@tvm.testing.requires_opencl
@tvm.testing.parametrize_targets("opencl -device=adreno")
def test_branching_texture_params(target, dtype):
def test_branching_texture_params(remote, target, dtype):
"""
Verification of passing texture to several consumers markup of relay variables in
primary functions + on_device
Expand Down Expand Up @@ -958,13 +970,15 @@ def test_branching_texture_params(target, dtype):
"",
]

build_run_compare(mod, params1, {"data": input_shape}, dtype, target, static_memory_scope)
build_run_compare(
remote, mod, params1, {"data": input_shape}, {"data": dtype}, target, static_memory_scope
)


# function repeat, params scope are different in reused functions
@tvm.testing.requires_opencl
@tvm.testing.parametrize_targets("opencl -device=adreno")
def test_conv2d_different_lowering_same_op(target, dtype):
def test_conv2d_different_lowering_same_op(remote, target, dtype):
"""
Use case for verification of caching compiled functions
Three convolutions following by each other in this case should be
Expand Down Expand Up @@ -1040,12 +1054,14 @@ def test_conv2d_different_lowering_same_op(target, dtype):
"",
]

build_run_compare(mod, params1, {"data": input_shape}, dtype, target, static_memory_scope)
build_run_compare(
remote, mod, params1, {"data": input_shape}, {"data": dtype}, target, static_memory_scope
)


@tvm.testing.requires_opencl
@tvm.testing.parametrize_targets("opencl -device=adreno")
def test_conv2d_winograd_non_rect(target, dtype):
def test_conv2d_winograd_non_rect(remote, target, dtype):
input_shape = (1, 771, 36, 64)
A = relay.var("data", shape=input_shape, dtype=dtype)
filter_shape = (128, 771, 3, 3)
Expand All @@ -1070,7 +1086,7 @@ def test_conv2d_winograd_non_rect(target, dtype):
f'{{"input": ["opencl -keys=adreno,opencl,gpu -device=adreno -max_num_threads=256 -texture_spatial_limit=16384 -thread_warp_size=1", "conv2d_nchw_winograd.image2d", [["TENSOR", [1, 771, 36, 64], "{dtype}"], ["TENSOR", [128, 771, 3, 3], "{dtype}"], [1, 1], [1, 1, 1, 1], [1, 1], "{dtype}"], {{}}], "config": {{"index": 5399, "code_hash": null, "entity": [["auto_unroll_max_step", "ot", 16], ["tile_y", "sp", [-1, 1, 32]], ["tile_x", "sp", [-1, 4, 8]], ["tile_rc", "sp", [-1, 193]]]}}, "result": [[0.0037244], 0, 7.06374192237854, 1653898629.7427933], "version": 0.2, "tvm_version": "0.8.dev0"}}\n'
)
graph = build_run_compare(
mod, params1, {"data": input_shape}, dtype, target, stat_file=stat_file
remote, mod, params1, {"data": input_shape}, {"data": dtype}, target, stat_file=stat_file
)
matches = re.findall("winograd", graph)
assert len(matches) > 0
Expand All @@ -1079,7 +1095,7 @@ def test_conv2d_winograd_non_rect(target, dtype):
# function repeat, params scope are different in reused functions
@tvm.testing.requires_opencl
@tvm.testing.parametrize_targets("opencl -device=adreno")
def test_injective_nwo_inputs1(target, dtype):
def test_injective_nwo_inputs1(remote, target, dtype):
"""
Use case for verification of stability of annotation primary functions
having several ops accepting data outside of Primary function
Expand Down Expand Up @@ -1170,13 +1186,15 @@ def test_injective_nwo_inputs1(target, dtype):
"global",
"global",
]
build_run_compare(mod, params1, {"data": input_shape}, dtype, target, static_memory_scope)
build_run_compare(
remote, mod, params1, {"data": input_shape}, {"data": dtype}, target, static_memory_scope
)


# function repeat, params scope are different in reused functions
@tvm.testing.requires_opencl
@tvm.testing.parametrize_targets("opencl -device=adreno")
def test_injective_nwo_inputs2(target, dtype):
def test_injective_nwo_inputs2(remote, target, dtype):
"""
Use case for verification of stability of annotation primary functions
having several ops accepting data outside of Primary function
Expand Down Expand Up @@ -1266,4 +1284,10 @@ def test_injective_nwo_inputs2(target, dtype):
"global.texture",
"global",
]
build_run_compare(mod, params1, {"data": input_shape}, dtype, target, static_memory_scope)
build_run_compare(
remote, mod, params1, {"data": input_shape}, {"data": dtype}, target, static_memory_scope
)


if __name__ == "__main__":
tvm.testing.main()
Loading