Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[OpenCL] Enable OpenCL for GPU tests #12490

Merged
merged 32 commits into from
Sep 9, 2022
Merged
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
6d147c3
Add opencl target in test build script
valmat07 Aug 18, 2022
2730ecc
Fix fp16 test and compile test for opencl
valmat07 Aug 18, 2022
bb48962
fix lint
valmat07 Aug 18, 2022
3a01e41
Fix relay OpenCL texture tests
valmat07 Aug 19, 2022
2d30a73
Fix lint
valmat07 Aug 19, 2022
53d8042
Enable relay OpenCL tests
valmat07 Aug 19, 2022
4c981a1
Fix opencl relay texture tests
valmat07 Aug 22, 2022
61bf976
fix lint
valmat07 Aug 22, 2022
19a1153
Remove OpenCL gtest variable
valmat07 Aug 22, 2022
213620c
Fix unbound variable
valmat07 Aug 22, 2022
2ceddbc
Merge https://github.com/Deelvin/tvm into enable_cl_tests
valmat07 Aug 23, 2022
2107de0
Skip tests that are not supported in CI
valmat07 Aug 23, 2022
be5fb16
fix lint
valmat07 Aug 23, 2022
757f9d3
Add path for opencl gtest directory
valmat07 Aug 23, 2022
b17219d
Fix opencl gtests include directory
valmat07 Aug 24, 2022
ad16842
Enable OpenCL googletest. Fix bug in opencl timer test
valmat07 Aug 26, 2022
4b82982
testing fix for build cpp tests
valmat07 Aug 28, 2022
a5903ba
update googletest git version for opencl tests build
valmat07 Aug 29, 2022
650c20e
update cmakelist
valmat07 Aug 29, 2022
e9990e9
Update CMakeList
valmat07 Aug 29, 2022
afb2c98
Update CMakeList
valmat07 Aug 29, 2022
48b5606
Disable opencl googletests
valmat07 Aug 29, 2022
b238280
update Opecnl.cmake
valmat07 Aug 30, 2022
4f132bd
fix Opecnl.cmake
valmat07 Aug 30, 2022
ba350f0
Merge https://github.com/apache/tvm into enable_cl_tests
valmat07 Sep 5, 2022
f007b8e
Apply comments. Remove xfail decerator for opencl tests. Now specific…
valmat07 Sep 5, 2022
269e491
minor code changes
valmat07 Sep 5, 2022
560219c
apply comments
valmat07 Sep 6, 2022
17e49ec
apply comment
valmat07 Sep 6, 2022
42df63a
skip test in ci by decorator
valmat07 Sep 7, 2022
307ba3c
fix pytest skipif warnings
valmat07 Sep 7, 2022
dd6aa8b
Fix skipif for opencl gtests
valmat07 Sep 8, 2022
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 src/runtime/opencl/opencl_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -439,9 +439,9 @@ class OpenCLTimerNode : public TimerNode {
public:
// Timer start
virtual void Start() {
this->duration = 0;
if (count_timer_execs == 0) {
cl::OpenCLWorkspace::Global()->GetEventQueue(dev_).clear();
this->duration = 0;
// Very first call of Start() leads to the recreation of
// OpenCL command queue in profiling mode. This allows to run profile after inference.
recreateCommandQueue();
Expand Down
1 change: 1 addition & 0 deletions tests/cpp-runtime/opencl/opencl_timer_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ TEST(OpenCLTimerNode, nested_timers) {
cl_mem cl_buf = clCreateBuffer(workspace->context, CL_MEM_READ_ONLY, BUFF_SIZE * sizeof(cl_int),
NULL, &err);
OPENCL_CHECK_ERROR(err);
queue = workspace->GetQueue(thr->device);
OPENCL_CALL(clEnqueueWriteBuffer(queue, cl_buf, false, 0, BUFF_SIZE * sizeof(cl_int), tmp_buf,
0, NULL, &ev));
OPENCL_CALL(clReleaseMemObject(cl_buf));
Expand Down
2 changes: 1 addition & 1 deletion tests/cpp-runtime/opencl/run_gtests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ TVM_REGISTER_GLOBAL("opencl.run_gtests").set_body([](TVMArgs args, TVMRetValue*
argv.push_back(const_cast<char*>("opencl_run_gtests"));

// add parsed arguments
for (int i = 0; i < parsed_args.size(); ++i) {
for (size_t i = 0; i < parsed_args.size(); ++i) {
argv.push_back(const_cast<char*>(parsed_args[i].data()));
}

Expand Down
3 changes: 2 additions & 1 deletion tests/python/driver/tvmc/test_compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,8 +367,9 @@ def test_compile_opencl(tflite_mobilenet_v1_0_25_128):
tvmc_model = tvmc.load(tflite_mobilenet_v1_0_25_128)
tvmc_package = tvmc.compile(
tvmc_model,
target="opencl --host=llvm",
target="opencl -host=llvm",
desired_layout="NCHW",
dump_code="asm",
)
dumps_path = tvmc_package.package_path + ".asm"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@
from tvm.relay import testing
from tvm.contrib import utils
from utils.adreno_utils import gpu_preprocess, build_run_compare
import pytest


@tvm.testing.requires_opencl
def test_conv2d_inceptionv3_64x35x35_96x64x3x3_nopad():
target = "opencl --device=adreno"
dtype = "float16"
dtype = tvm.testing.parameter("float32")


@tvm.testing.requires_opencl
@tvm.testing.parametrize_targets("opencl -device=adreno")
def test_conv2d_inceptionv3_64x35x35_96x64x3x3_nopad(target, dtype):
input_shape = (1, 32, 42, 42)
filter_shape = (96, 32, 3, 3)
bias_shape = (1, 96, 1, 1)
Expand Down Expand Up @@ -67,10 +69,8 @@ def test_conv2d_inceptionv3_64x35x35_96x64x3x3_nopad():


@tvm.testing.requires_opencl
def test_conv2d_inceptionv3_64x35x35_96x64x3x3_nopad_pass():
target = "opencl --device=adreno"
dtype = "float16"

@tvm.testing.parametrize_targets("opencl -device=adreno")
def test_conv2d_inceptionv3_64x35x35_96x64x3x3_nopad_pass(target, dtype):
input_shape = (1, 32, 40, 40)
filter_shape = (96, 32, 2, 2)
bias_shape = (1, 96, 1, 1)
Expand Down Expand Up @@ -109,10 +109,8 @@ def test_conv2d_inceptionv3_64x35x35_96x64x3x3_nopad_pass():


@tvm.testing.requires_opencl
def test_conv2d_inceptionv3_35_35_strides():
target = "opencl --device=adreno"
dtype = "float16"

@tvm.testing.parametrize_targets("opencl -device=adreno")
def test_conv2d_inceptionv3_35_35_strides(target, dtype):
input_shape = (1, 48, 35, 35)
filter_shape = (64, 48, 5, 5)
bias_shape = (1, 64, 1, 1)
Expand Down Expand Up @@ -151,10 +149,8 @@ def test_conv2d_inceptionv3_35_35_strides():


@tvm.testing.requires_opencl
def test_conv2d_resnet50_v2_nchw_3c():
target = "opencl --device=adreno"
dtype = "float16"

@tvm.testing.parametrize_targets("opencl -device=adreno")
def test_conv2d_resnet50_v2_nchw_3c(target, dtype):
input_shape = (1, 3, 224, 224)
filter_shape = (64, 3, 7, 7)
bias_shape = (1, 64, 1, 1)
Expand Down Expand Up @@ -194,10 +190,8 @@ def test_conv2d_resnet50_v2_nchw_3c():


@tvm.testing.requires_opencl
def test_conv2d_inceptionv3_nchw_3c():
target = "opencl --device=adreno"
dtype = "float16"

@tvm.testing.parametrize_targets("opencl -device=adreno")
def test_conv2d_inceptionv3_nchw_3c(target, dtype):
input_shape = (1, 3, 299, 299)
filter_shape = (64, 3, 3, 3)
bias_shape = (1, 64, 1, 1)
Expand Down Expand Up @@ -236,10 +230,8 @@ def test_conv2d_inceptionv3_nchw_3c():


@tvm.testing.requires_opencl
def test_conv2d_1x1_16c16spatial():
target = "opencl --device=adreno"
dtype = "float16"

@tvm.testing.parametrize_targets("opencl -device=adreno")
def test_conv2d_1x1_16c16spatial(target, dtype):
input_shape = (1, 16, 256, 256)
filter_shape = (32, 16, 4, 4)
bias_shape = (1, 32, 1, 1)
Expand Down Expand Up @@ -278,10 +270,8 @@ def test_conv2d_1x1_16c16spatial():


@tvm.testing.requires_opencl
def test_conv2d_4x4_16c16pad():
target = "opencl --device=adreno"
dtype = "float16"

@tvm.testing.parametrize_targets("opencl -device=adreno")
def test_conv2d_4x4_16c16pad(target, dtype):
input_shape = (1, 32, 256, 256)
filter_shape = (32, 32, 4, 4)
bias_shape = (1, 32, 1, 1)
Expand Down Expand Up @@ -320,10 +310,8 @@ def test_conv2d_4x4_16c16pad():


@tvm.testing.requires_opencl
def test_conv2d_4x4x4_16c16pad():
target = "opencl --device=adreno"
dtype = "float16"

@tvm.testing.parametrize_targets("opencl -device=adreno")
def test_conv2d_4x4x4_16c16pad(target, dtype):
input_shape = (1, 32, 256, 256)
filter_shape = (4, 32, 4, 4)
bias_shape = (1, 4, 1, 1)
Expand Down Expand Up @@ -362,10 +350,8 @@ def test_conv2d_4x4x4_16c16pad():


@tvm.testing.requires_opencl
def test_conv2d_yolov3_v2_nchw_3c():
target = "opencl --device=adreno"
dtype = "float16"

@tvm.testing.parametrize_targets("opencl -device=adreno")
def test_conv2d_yolov3_v2_nchw_3c(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 @@ -397,10 +383,8 @@ def test_conv2d_yolov3_v2_nchw_3c():


@tvm.testing.requires_opencl
def test_conv2d_vgg16_winograd_4d():
target = "opencl --device=adreno"
dtype = "float16"

@tvm.testing.parametrize_targets("opencl -device=adreno")
def test_conv2d_vgg16_winograd_4d(target, dtype):
input_shape = (1, 512, 28, 28)
filter_shape = (512, 512, 3, 3)
bias_shape = (1, 512, 1, 1)
Expand Down Expand Up @@ -437,7 +421,7 @@ def test_conv2d_vgg16_winograd_4d():
stat_file = temp.relpath("stat.log")
with open(stat_file, "w") as f:
f.write(
'{"input": ["opencl -keys=adreno,opencl,gpu -device=adreno -max_num_threads=256", "conv2d_nchw_winograd.image2d", [["TENSOR", [1, 512, 28, 28], "float16"], ["TENSOR", [512, 512, 3, 3], "float16"], [1, 1], [1, 1, 1, 1], [1, 1], "float16"], {}], "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'
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
Expand All @@ -447,10 +431,8 @@ def test_conv2d_vgg16_winograd_4d():


@tvm.testing.requires_opencl
def test_conv2d_winograd_conv():
target = "opencl --device=adreno"
dtype = "float16"

@tvm.testing.parametrize_targets("opencl -device=adreno")
def test_conv2d_winograd_conv(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 @@ -486,7 +468,7 @@ def test_conv2d_winograd_conv():
stat_file = temp.relpath("stat.log")
with open(stat_file, "w") as f:
f.write(
'{"input": ["opencl -keys=adreno,opencl,gpu -device=adreno -max_num_threads=256", "conv2d_nchw_winograd.image2d", [["TENSOR", [1, 4, 3, 3], "float16"], ["TENSOR", [8, 4, 3, 3], "float16"], [1, 1], [1, 1, 1, 1], [1, 1], "float16"], {}], "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'
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
Expand All @@ -496,7 +478,8 @@ def test_conv2d_winograd_conv():


@tvm.testing.requires_opencl
def test_residual_block():
@tvm.testing.parametrize_targets("opencl -device=adreno")
def test_residual_block(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 All @@ -515,9 +498,6 @@ def test_residual_block():
| <- buffer
layout_transform (NCHW4c->NCHW)
"""
target = "opencl --device=adreno"
dtype = "float16"

input_shape = (1, 32, 40, 40)
filter_shape1 = (32, 32, 2, 2)
filter_shape2 = (32, 32, 1, 1)
Expand Down Expand Up @@ -555,7 +535,7 @@ def test_residual_block():
kernel_size=(1, 1),
)
D = relay.op.add(conv2, D)
D = D * relay.const(0.15, "float16")
D = D * relay.const(0.15, dtype)
D = relay.op.nn.relu(D)

conv3 = relay.nn.conv2d(
Expand Down Expand Up @@ -607,7 +587,8 @@ def test_residual_block():


@tvm.testing.requires_opencl
def test_concat():
@tvm.testing.parametrize_targets("opencl -device=adreno")
def test_concat(target, dtype):
"""
layout_transform (NCHW->NCHW4c)
| <- buffer
Expand All @@ -619,9 +600,6 @@ def test_concat():
| <- buffer
layout_transform (NCHW4c->NCHW)
"""
target = "opencl --device=adreno"
dtype = "float16"

input_shape = (1, 32, 40, 40)
filter_shape1 = (96, 32, 2, 2)
filter_shape2 = (32, 96, 2, 2)
Expand Down Expand Up @@ -721,7 +699,8 @@ def test_concat():


@tvm.testing.requires_opencl
def test_pooling_branching_texture_params():
@tvm.testing.parametrize_targets("opencl -device=adreno")
def test_pooling_branching_texture_params(target, dtype):
"""
Verification of the pooling and many branches having textures
layout_transform (NCHW->NCHW4c)
Expand All @@ -738,9 +717,6 @@ def test_pooling_branching_texture_params():
| <- buffer
layout_transform (NCHW4c->NCHW)
"""
target = "opencl --device=adreno"
dtype = "float16"

input_shape = (1, 32, 40, 40)
filter_shape0 = (32, 32, 1, 1)
filter_shape1 = (32, 32, 2, 2)
Expand Down Expand Up @@ -849,7 +825,8 @@ def test_pooling_branching_texture_params():


@tvm.testing.requires_opencl
def test_branching_texture_params():
@tvm.testing.parametrize_targets("opencl -device=adreno")
def test_branching_texture_params(target, dtype):
"""
Verification of passing texture to several consumers markup of relay variables in
primary functions + on_device
Expand All @@ -866,9 +843,6 @@ def test_branching_texture_params():
| <- buffer
layout_transform (NCHW4c->NCHW)
"""
target = "opencl --device=adreno"
dtype = "float16"

input_shape = (1, 32, 40, 40)
filter_shape0 = (32, 32, 1, 1)
filter_shape1 = (32, 32, 2, 2)
Expand Down Expand Up @@ -976,7 +950,8 @@ def test_branching_texture_params():

# function repeat, params scope are different in reused functions
@tvm.testing.requires_opencl
def test_conv2d_different_lowering_same_op():
@tvm.testing.parametrize_targets("opencl -device=adreno")
def test_conv2d_different_lowering_same_op(target, dtype):
"""
Use case for verification of caching compiled functions
Three convolutions following by each other in this case should be
Expand All @@ -993,9 +968,6 @@ def test_conv2d_different_lowering_same_op():
| <- buffer
layout_transform (NCHW4c->NCHW)
"""
target = "opencl --device=adreno"
dtype = "float16"

input_shape = (1, 32, 40, 40)
filter_shape1 = (32, 32, 1, 1)
A = relay.var("data", shape=input_shape, dtype=dtype)
Expand Down
Loading