chore: import upstream snapshot with attribution
cffconvert / validate (push) Has been skipped
License Check / license-check (push) Failing after 2s

This commit is contained in:
wehub-resource-sync
2026-07-13 12:14:16 +08:00
commit 8a852e4b4e
36502 changed files with 9277225 additions and 0 deletions
@@ -0,0 +1,803 @@
load("@rules_cc//cc:cc_library.bzl", "cc_library")
load("@rules_cc//cc:cc_test.bzl", "cc_test")
load(
"//tensorflow/core/platform:build_config_root.bzl",
"tf_gpu_tests_tags",
)
load("//tensorflow/lite/delegates/gpu:build_defs.bzl", "gtest_main_no_heapcheck_deps")
package(
# copybara:uncomment default_applicable_licenses = ["//tensorflow:LICENSE"],
default_visibility = ["//visibility:public"],
licenses = ["notice"],
)
cc_test(
name = "add_test",
srcs = ["add_test.cc"],
tags = [
"noasan",
"nomsan",
"notsan",
"requires-gpu-nvidia",
],
# TODO(b/279977471) Once b/279347631 is resolved, check for heap again
deps = [
":cl_test",
"//tensorflow/lite/delegates/gpu/common:operations",
"//tensorflow/lite/delegates/gpu/common:status",
"//tensorflow/lite/delegates/gpu/common/tasks:add_test_util",
] + gtest_main_no_heapcheck_deps(),
)
cc_test(
name = "cast_test",
srcs = ["cast_test.cc"],
tags = [
"noasan",
"nomsan",
"notsan",
"requires-gpu-nvidia",
],
deps = [
":cl_test",
"//tensorflow/lite/delegates/gpu/common:operations",
"//tensorflow/lite/delegates/gpu/common:status",
"//tensorflow/lite/delegates/gpu/common/tasks:cast_test_util",
] + gtest_main_no_heapcheck_deps(),
)
cc_library(
name = "cl_test",
testonly = 1,
srcs = ["cl_test.cc"],
hdrs = ["cl_test.h"],
deps = [
"//tensorflow/lite/delegates/gpu/cl:cl_operation",
"//tensorflow/lite/delegates/gpu/cl:environment",
"//tensorflow/lite/delegates/gpu/cl:opencl_wrapper",
"//tensorflow/lite/delegates/gpu/cl:tensor",
"//tensorflow/lite/delegates/gpu/common:status",
"//tensorflow/lite/delegates/gpu/common/task:testing_util",
"@com_google_googletest//:gtest",
],
)
cc_test(
name = "concat_test",
srcs = ["concat_test.cc"],
tags = [
"noasan",
"nomsan",
"notsan",
"requires-gpu-nvidia",
],
deps = [
":cl_test",
"//tensorflow/lite/delegates/gpu/common:operations",
"//tensorflow/lite/delegates/gpu/common:status",
"//tensorflow/lite/delegates/gpu/common/tasks:concat_test_util",
] + gtest_main_no_heapcheck_deps(),
)
cc_test(
name = "conv_constants_test",
srcs = ["conv_constants_test.cc"],
tags = [
"noasan",
"nomsan",
"notsan",
"requires-gpu-nvidia",
],
deps = [
":cl_test",
"//tensorflow/lite/delegates/gpu/common:operations",
"//tensorflow/lite/delegates/gpu/common:status",
"//tensorflow/lite/delegates/gpu/common/tasks:conv_constants_test_util",
] + gtest_main_no_heapcheck_deps(),
)
cc_test(
name = "conv_generic_test",
srcs = ["conv_generic_test.cc"],
tags = [
"noasan",
"nomsan",
"notsan",
"requires-gpu-nvidia",
],
deps = [
":cl_test",
"//tensorflow/lite/delegates/gpu/common:operations",
"//tensorflow/lite/delegates/gpu/common:status",
"//tensorflow/lite/delegates/gpu/common/tasks:conv_generic_test_util",
] + gtest_main_no_heapcheck_deps(),
)
cc_test(
name = "conv_weights_converter_test",
srcs = ["conv_weights_converter_test.cc"],
tags = [
"noasan",
"nomsan",
"notsan",
"requires-gpu-nvidia",
],
deps = [
":cl_test",
"//tensorflow/lite/delegates/gpu/common:operations",
"//tensorflow/lite/delegates/gpu/common:status",
"//tensorflow/lite/delegates/gpu/common/tasks:conv_weights_converter_test_util",
] + gtest_main_no_heapcheck_deps(),
)
cc_library(
name = "converter",
srcs = ["converter.cc"],
hdrs = ["converter.h"],
deps = [
"//tensorflow/lite/delegates/gpu:spi",
"//tensorflow/lite/delegates/gpu/cl:buffer",
"//tensorflow/lite/delegates/gpu/cl:cl_arguments",
"//tensorflow/lite/delegates/gpu/cl:cl_command_queue",
"//tensorflow/lite/delegates/gpu/cl:cl_errors",
"//tensorflow/lite/delegates/gpu/cl:environment",
"//tensorflow/lite/delegates/gpu/cl:opencl_wrapper",
"//tensorflow/lite/delegates/gpu/cl:tensor",
"//tensorflow/lite/delegates/gpu/cl:tensor_type_util",
"//tensorflow/lite/delegates/gpu/common:data_type",
"//tensorflow/lite/delegates/gpu/common:types",
"//tensorflow/lite/delegates/gpu/common:util",
"//tensorflow/lite/delegates/gpu/common/task:arguments",
"//tensorflow/lite/delegates/gpu/common/task:gpu_operation",
"//tensorflow/lite/delegates/gpu/common/task:tensor_desc",
"//tensorflow/lite/delegates/gpu/common/task:util",
"//tensorflow/lite/delegates/gpu/common/task:work_group_picking",
"//tensorflow/lite/delegates/gpu/common/tasks:conversion",
"@com_google_absl//absl/status",
"@com_google_absl//absl/strings",
],
)
cc_test(
name = "convolution_transposed_test",
srcs = ["convolution_transposed_test.cc"],
tags = [
"noasan",
"nomsan",
"notsan",
"requires-gpu-nvidia",
],
deps = [
":cl_test",
"//tensorflow/lite/delegates/gpu/common:operations",
"//tensorflow/lite/delegates/gpu/common:status",
"//tensorflow/lite/delegates/gpu/common/tasks:convolution_transposed_test_util",
] + gtest_main_no_heapcheck_deps(),
)
cc_test(
name = "convolution_transposed_3x3_test",
srcs = ["convolution_transposed_3x3_test.cc"],
tags = [
"noasan",
"nomsan",
"notsan",
"requires-gpu-nvidia",
],
deps = [
":cl_test",
"//tensorflow/lite/delegates/gpu/common:operations",
"//tensorflow/lite/delegates/gpu/common:status",
"//tensorflow/lite/delegates/gpu/common/tasks:convolution_transposed_3x3_test_util",
] + gtest_main_no_heapcheck_deps(),
)
cc_test(
name = "convolution_transposed_3x3_thin_test",
srcs = ["convolution_transposed_3x3_thin_test.cc"],
tags = [
"noasan",
"nomsan",
"notsan",
"requires-gpu-nvidia",
],
deps = [
":cl_test",
"//tensorflow/lite/delegates/gpu/common:operations",
"//tensorflow/lite/delegates/gpu/common:status",
"//tensorflow/lite/delegates/gpu/common/tasks:convolution_transposed_3x3_thin_test_util",
] + gtest_main_no_heapcheck_deps(),
)
cc_test(
name = "convolution_transposed_4x4_test",
srcs = ["convolution_transposed_4x4_test.cc"],
tags = [
"noasan",
"nomsan",
"notsan",
"requires-gpu-nvidia",
],
deps = [
":cl_test",
"//tensorflow/lite/delegates/gpu/common:operations",
"//tensorflow/lite/delegates/gpu/common:status",
"//tensorflow/lite/delegates/gpu/common/tasks:convolution_transposed_4x4_test_util",
] + gtest_main_no_heapcheck_deps(),
)
cc_test(
name = "convolution_transposed_thin_test",
srcs = ["convolution_transposed_thin_test.cc"],
tags = [
"noasan",
"nomsan",
"notsan",
"requires-gpu-nvidia",
],
deps = [
":cl_test",
"//tensorflow/lite/delegates/gpu/common:operations",
"//tensorflow/lite/delegates/gpu/common:status",
"//tensorflow/lite/delegates/gpu/common/tasks:convolution_transposed_thin_test_util",
] + gtest_main_no_heapcheck_deps(),
)
cc_test(
name = "cumsum_test",
srcs = ["cumsum_test.cc"],
tags = [
"noasan",
"nomsan",
"notsan",
"requires-gpu-nvidia",
],
deps = [
":cl_test",
"//tensorflow/lite/delegates/gpu/common:operations",
"//tensorflow/lite/delegates/gpu/common:status",
"//tensorflow/lite/delegates/gpu/common/tasks:cumsum_test_util",
] + gtest_main_no_heapcheck_deps(),
)
cc_test(
name = "depthwise_conv_test",
srcs = ["depthwise_conv_test.cc"],
tags = [
"noasan",
"nomsan",
"notsan",
"requires-gpu-nvidia",
],
deps = [
":cl_test",
"//tensorflow/lite/delegates/gpu/common:operations",
"//tensorflow/lite/delegates/gpu/common:status",
"//tensorflow/lite/delegates/gpu/common/tasks:depthwise_conv_test_util",
] + gtest_main_no_heapcheck_deps(),
)
cc_test(
name = "depthwise_conv_3x3_test",
srcs = ["depthwise_conv_3x3_test.cc"],
tags = [
"noasan",
"nomsan",
"notsan",
"requires-gpu-nvidia",
],
deps = [
":cl_test",
"//tensorflow/lite/delegates/gpu/common:operations",
"//tensorflow/lite/delegates/gpu/common:status",
"//tensorflow/lite/delegates/gpu/common/tasks:depthwise_conv_3x3_stride_h2_test_util",
"//tensorflow/lite/delegates/gpu/common/tasks:depthwise_conv_3x3_test_util",
] + gtest_main_no_heapcheck_deps(),
)
cc_test(
name = "elementwise_test",
srcs = ["elementwise_test.cc"],
tags = [
"noasan",
"nomsan",
"notsan",
"requires-gpu-nvidia",
],
deps = [
":cl_test",
"//tensorflow/lite/delegates/gpu/common:operations",
"//tensorflow/lite/delegates/gpu/common:status",
"//tensorflow/lite/delegates/gpu/common/tasks:elementwise_test_util",
] + gtest_main_no_heapcheck_deps(),
)
cc_test(
name = "fully_connected_test",
srcs = ["fully_connected_test.cc"],
tags = [
"noasan",
"nomsan",
"notsan",
"requires-gpu-nvidia",
],
deps = [
":cl_test",
"//tensorflow/lite/delegates/gpu/cl:environment",
"//tensorflow/lite/delegates/gpu/common:data_type",
"//tensorflow/lite/delegates/gpu/common:operations",
"//tensorflow/lite/delegates/gpu/common:shape",
"//tensorflow/lite/delegates/gpu/common:tensor",
"//tensorflow/lite/delegates/gpu/common/task:gpu_operation",
"//tensorflow/lite/delegates/gpu/common/tasks:fully_connected",
"//tensorflow/lite/delegates/gpu/common/tasks:fully_connected_test_util",
] + gtest_main_no_heapcheck_deps(),
)
cc_test(
name = "gather_test",
srcs = ["gather_test.cc"],
tags = [
"noasan",
"nomsan",
"notsan",
"requires-gpu-nvidia",
],
deps = [
":cl_test",
"//tensorflow/lite/delegates/gpu/common:operations",
"//tensorflow/lite/delegates/gpu/common:status",
"//tensorflow/lite/delegates/gpu/common/tasks:gather_test_util",
] + gtest_main_no_heapcheck_deps(),
)
cc_test(
name = "lstm_test",
srcs = ["lstm_test.cc"],
tags = [
"noasan",
"nomsan",
"notsan",
"requires-gpu-nvidia",
],
deps = [
":cl_test",
"//tensorflow/lite/delegates/gpu/common:operations",
"//tensorflow/lite/delegates/gpu/common:status",
"//tensorflow/lite/delegates/gpu/common/tasks:lstm_test_util",
] + gtest_main_no_heapcheck_deps(),
)
cc_test(
name = "lstm_full_test",
srcs = ["lstm_full_test.cc"],
linkstatic = True,
tags = tf_gpu_tests_tags() + [
"linux",
"local",
],
deps = [
"//tensorflow/lite:framework",
"//tensorflow/lite/delegates/gpu:delegate",
"//tensorflow/lite/kernels:test_main",
"//tensorflow/lite/kernels:test_util",
"//tensorflow/lite/schema:schema_fbs",
"@com_google_googletest//:gtest",
"@flatbuffers",
],
)
cc_test(
name = "max_unpooling_test",
srcs = ["max_unpooling_test.cc"],
tags = [
"noasan",
"nomsan",
"notsan",
"requires-gpu-nvidia",
],
deps = [
":cl_test",
"//tensorflow/lite/delegates/gpu/common:operations",
"//tensorflow/lite/delegates/gpu/common:status",
"//tensorflow/lite/delegates/gpu/common/tasks:max_unpooling_test_util",
] + gtest_main_no_heapcheck_deps(),
)
cc_test(
name = "mean_stddev_normalization_test",
srcs = ["mean_stddev_normalization_test.cc"],
tags = [
"noasan",
"nomsan",
"notsan",
"requires-gpu-nvidia",
],
deps = [
":cl_test",
"//tensorflow/lite/delegates/gpu/common:operations",
"//tensorflow/lite/delegates/gpu/common:status",
"//tensorflow/lite/delegates/gpu/common/tasks:mean_stddev_normalization_test_util",
] + gtest_main_no_heapcheck_deps(),
)
cc_test(
name = "one_hot_test",
srcs = ["one_hot_test.cc"],
tags = [
"noasan",
"nomsan",
"notsan",
"requires-gpu-nvidia",
],
deps = [
":cl_test",
"//tensorflow/lite/delegates/gpu/common:operations",
"//tensorflow/lite/delegates/gpu/common:status",
"//tensorflow/lite/delegates/gpu/common/tasks:one_hot_test_util",
] + gtest_main_no_heapcheck_deps(),
)
cc_test(
name = "padding_test",
srcs = ["padding_test.cc"],
tags = [
"noasan",
"nomsan",
"notsan",
"requires-gpu-nvidia",
],
deps = [
":cl_test",
"//tensorflow/lite/delegates/gpu/common:operations",
"//tensorflow/lite/delegates/gpu/common:status",
"//tensorflow/lite/delegates/gpu/common/tasks:padding_test_util",
] + gtest_main_no_heapcheck_deps(),
)
cc_test(
name = "pooling_test",
srcs = ["pooling_test.cc"],
tags = [
"noasan",
"nomsan",
"notsan",
"requires-gpu-nvidia",
],
deps = [
":cl_test",
"//tensorflow/lite/delegates/gpu/common:operations",
"//tensorflow/lite/delegates/gpu/common:status",
"//tensorflow/lite/delegates/gpu/common/tasks:pooling_test_util",
] + gtest_main_no_heapcheck_deps(),
)
cc_test(
name = "prelu_test",
srcs = ["prelu_test.cc"],
tags = [
"noasan",
"nomsan",
"notsan",
"requires-gpu-nvidia",
],
deps = [
":cl_test",
"//tensorflow/lite/delegates/gpu/common:operations",
"//tensorflow/lite/delegates/gpu/common:status",
"//tensorflow/lite/delegates/gpu/common/tasks:prelu_test_util",
] + gtest_main_no_heapcheck_deps(),
)
cc_test(
name = "quantize_and_dequantize_test",
srcs = ["quantize_and_dequantize_test.cc"],
tags = [
"noasan",
"nomsan",
"notsan",
"requires-gpu-nvidia",
],
deps = [
":cl_test",
"//tensorflow/lite/delegates/gpu/common:operations",
"//tensorflow/lite/delegates/gpu/common:status",
"//tensorflow/lite/delegates/gpu/common/tasks:quantize_and_dequantize_test_util",
] + gtest_main_no_heapcheck_deps(),
)
cc_test(
name = "reduce_test",
srcs = ["reduce_test.cc"],
tags = [
"noasan",
"nomsan",
"notsan",
"requires-gpu-nvidia",
],
deps = [
":cl_test",
"//tensorflow/lite/delegates/gpu/common:operations",
"//tensorflow/lite/delegates/gpu/common:status",
"//tensorflow/lite/delegates/gpu/common/tasks:reduce_test_util",
] + gtest_main_no_heapcheck_deps(),
)
cc_test(
name = "relu_test",
srcs = ["relu_test.cc"],
tags = [
"noasan",
"nomsan",
"notsan",
"requires-gpu-nvidia",
],
deps = [
":cl_test",
"//tensorflow/lite/delegates/gpu/common:operations",
"//tensorflow/lite/delegates/gpu/common:status",
"//tensorflow/lite/delegates/gpu/common/tasks:relu_test_util",
] + gtest_main_no_heapcheck_deps(),
)
cc_test(
name = "resampler_test",
srcs = ["resampler_test.cc"],
tags = [
"noasan",
"nomsan",
"notsan",
"requires-gpu-nvidia",
],
deps = [
"//tensorflow/lite/delegates/gpu/cl/kernels:cl_test",
"//tensorflow/lite/delegates/gpu/common:operations",
"//tensorflow/lite/delegates/gpu/common:status",
"//tensorflow/lite/delegates/gpu/common/tasks:resampler_test_util",
] + gtest_main_no_heapcheck_deps(),
)
cc_test(
name = "reshape_test",
srcs = ["reshape_test.cc"],
tags = [
"noasan",
"nomsan",
"notsan",
"requires-gpu-nvidia",
],
deps = [
":cl_test",
"//tensorflow/lite/delegates/gpu/common:operations",
"//tensorflow/lite/delegates/gpu/common:status",
"//tensorflow/lite/delegates/gpu/common/tasks:reshape_test_util",
] + gtest_main_no_heapcheck_deps(),
)
cc_test(
name = "reshapex4_test",
srcs = ["reshapex4_test.cc"],
tags = [
"noasan",
"nomsan",
"notsan",
"requires-gpu-nvidia",
],
deps = [
":cl_test",
"//tensorflow/lite/delegates/gpu/common:operations",
"//tensorflow/lite/delegates/gpu/common:status",
"//tensorflow/lite/delegates/gpu/common/tasks:reshape_test_util",
] + gtest_main_no_heapcheck_deps(),
)
cc_test(
name = "select_v2_test",
srcs = ["select_v2_test.cc"],
tags = [
"noasan",
"nomsan",
"notsan",
"requires-gpu-nvidia",
],
deps = [
":cl_test",
"//tensorflow/lite/delegates/gpu/common:operations",
"//tensorflow/lite/delegates/gpu/common:status",
"//tensorflow/lite/delegates/gpu/common/tasks:select_v2_test_util",
] + gtest_main_no_heapcheck_deps(),
)
cc_test(
name = "softmax_test",
srcs = ["softmax_test.cc"],
tags = [
"noasan",
"nomsan",
"notsan",
"requires-gpu-nvidia",
],
deps = [
":cl_test",
"//tensorflow/lite/delegates/gpu/common:operations",
"//tensorflow/lite/delegates/gpu/common:status",
"//tensorflow/lite/delegates/gpu/common/tasks:softmax_test_util",
] + gtest_main_no_heapcheck_deps(),
)
cc_test(
name = "softmax1x1_test",
srcs = ["softmax1x1_test.cc"],
tags = [
"noasan",
"nomsan",
"notsan",
"requires-gpu-nvidia",
],
deps = [
":cl_test",
"//tensorflow/lite/delegates/gpu/common:operations",
"//tensorflow/lite/delegates/gpu/common:status",
"//tensorflow/lite/delegates/gpu/common/tasks:softmax_test_util",
] + gtest_main_no_heapcheck_deps(),
)
cc_test(
name = "space_to_depth_test",
srcs = ["space_to_depth_test.cc"],
tags = [
"noasan",
"nomsan",
"notsan",
"requires-gpu-nvidia",
],
deps = [
":cl_test",
"//tensorflow/lite/delegates/gpu/common:operations",
"//tensorflow/lite/delegates/gpu/common:status",
"//tensorflow/lite/delegates/gpu/common/tasks:space_to_depth_test_util",
] + gtest_main_no_heapcheck_deps(),
)
cc_test(
name = "split_test",
srcs = ["split_test.cc"],
tags = [
"noasan",
"nomsan",
"notsan",
"requires-gpu-nvidia",
],
deps = [
":cl_test",
"//tensorflow/lite/delegates/gpu/common:operations",
"//tensorflow/lite/delegates/gpu/common:status",
"//tensorflow/lite/delegates/gpu/common/tasks:split_test_util",
] + gtest_main_no_heapcheck_deps(),
)
cc_test(
name = "strided_slice_test",
srcs = ["strided_slice_test.cc"],
tags = [
"noasan",
"nomsan",
"notsan",
"requires-gpu-nvidia",
],
deps = [
":cl_test",
"//tensorflow/lite/delegates/gpu/common:operations",
"//tensorflow/lite/delegates/gpu/common:status",
"//tensorflow/lite/delegates/gpu/common/tasks:strided_slice_test_util",
] + gtest_main_no_heapcheck_deps(),
)
cc_test(
name = "tile_test",
srcs = ["tile_test.cc"],
tags = [
"noasan",
"nomsan",
"notsan",
"requires-gpu-nvidia",
],
deps = [
":cl_test",
"//tensorflow/lite/delegates/gpu/common:operations",
"//tensorflow/lite/delegates/gpu/common:status",
"//tensorflow/lite/delegates/gpu/common/tasks:tile_test_util",
] + gtest_main_no_heapcheck_deps(),
)
cc_test(
name = "transpose_test",
srcs = ["transpose_test.cc"],
tags = [
"noasan",
"nomsan",
"notsan",
"requires-gpu-nvidia",
],
deps = [
":cl_test",
"//tensorflow/lite/delegates/gpu/common:operations",
"//tensorflow/lite/delegates/gpu/common:status",
"//tensorflow/lite/delegates/gpu/common/tasks:transpose_test_util",
] + gtest_main_no_heapcheck_deps(),
)
cc_test(
name = "resize_test",
srcs = ["resize_test.cc"],
tags = [
"noasan",
"nomsan",
"notsan",
"requires-gpu-nvidia",
],
deps = [
":cl_test",
"//tensorflow/lite/delegates/gpu/common:operations",
"//tensorflow/lite/delegates/gpu/common:status",
"//tensorflow/lite/delegates/gpu/common/tasks:resize_test_util",
] + gtest_main_no_heapcheck_deps(),
)
cc_test(
name = "winograd_test",
srcs = ["winograd_test.cc"],
tags = [
"noasan",
"nomsan",
"notsan",
"requires-gpu-nvidia",
],
deps = [
":cl_test",
"//tensorflow/lite/delegates/gpu/common:operations",
"//tensorflow/lite/delegates/gpu/common:status",
"//tensorflow/lite/delegates/gpu/common/tasks:winograd_test_util",
] + gtest_main_no_heapcheck_deps(),
)
test_suite(
name = "all_tests",
tests = [
"add_test",
"cast_test",
"concat_test",
"conv_constants_test",
"conv_generic_test",
"conv_weights_converter_test",
"convolution_transposed_3x3_test",
"convolution_transposed_3x3_thin_test",
"convolution_transposed_4x4_test",
"convolution_transposed_test",
"convolution_transposed_thin_test",
"depthwise_conv_3x3_test",
"depthwise_conv_test",
"elementwise_test",
"fully_connected_test",
"gather_test",
"lstm_test",
"max_unpooling_test",
"mean_stddev_normalization_test",
"padding_test",
"pooling_test",
"prelu_test",
"reduce_test",
"relu_test",
"reshape_test",
"reshapex4_test",
"resize_test",
"softmax1x1_test",
"softmax_test",
"split_test",
"strided_slice_test",
"tile_test",
"transpose_test",
"winograd_test",
],
)
@@ -0,0 +1,48 @@
/* Copyright 2019 The TensorFlow Authors. All Rights Reserved.
Licensed 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.
==============================================================================*/
#include <vector>
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include "tensorflow/lite/delegates/gpu/cl/kernels/cl_test.h"
#include "tensorflow/lite/delegates/gpu/common/operations.h"
#include "tensorflow/lite/delegates/gpu/common/status.h"
#include "tensorflow/lite/delegates/gpu/common/tasks/add_test_util.h"
namespace tflite {
namespace gpu {
namespace cl {
namespace {
TEST_F(OpenCLOperationTest, AddTwoEqualTensors) {
auto status = AddTwoEqualTensorsTest(&exec_env_);
ASSERT_TRUE(status.ok()) << status.message();
}
TEST_F(OpenCLOperationTest, AddFirstTensorHasMoreChannelsThanSecond) {
auto status = AddFirstTensorHasMoreChannelsThanSecondTest(&exec_env_);
ASSERT_TRUE(status.ok()) << status.message();
}
TEST_F(OpenCLOperationTest, AddFirstTensorHasLessChannelsThanSecond) {
auto status = AddFirstTensorHasLessChannelsThanSecond(&exec_env_);
ASSERT_TRUE(status.ok()) << status.message();
}
} // namespace
} // namespace cl
} // namespace gpu
} // namespace tflite
@@ -0,0 +1,46 @@
/* Copyright 2022 The TensorFlow Authors. All Rights Reserved.
Licensed 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.
==============================================================================*/
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include "tensorflow/lite/delegates/gpu/cl/kernels/cl_test.h"
#include "tensorflow/lite/delegates/gpu/common/operations.h"
#include "tensorflow/lite/delegates/gpu/common/status.h"
#include "tensorflow/lite/delegates/gpu/common/tasks/cast_test_util.h"
namespace tflite {
namespace gpu {
namespace cl {
namespace {
TEST_F(OpenCLOperationTest, Cast) {
auto status = CastTests(&exec_env_);
ASSERT_TRUE(status.ok()) << status.message();
}
TEST_F(OpenCLOperationTest, CastToBool) {
auto status = CastToBoolTests(&exec_env_);
ASSERT_TRUE(status.ok()) << status.message();
}
TEST_F(OpenCLOperationTest, CastFromBool) {
auto status = CastFromBoolTests(&exec_env_);
ASSERT_TRUE(status.ok()) << status.message();
}
} // namespace
} // namespace cl
} // namespace gpu
} // namespace tflite
@@ -0,0 +1,93 @@
/* Copyright 2019 The TensorFlow Authors. All Rights Reserved.
Licensed 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.
==============================================================================*/
#include "tensorflow/lite/delegates/gpu/cl/kernels/cl_test.h"
#include <memory>
#include <utility>
#include <vector>
#include "tensorflow/lite/delegates/gpu/cl/cl_operation.h"
#include "tensorflow/lite/delegates/gpu/cl/tensor.h"
#include "tensorflow/lite/delegates/gpu/common/status.h"
namespace tflite {
namespace gpu {
namespace cl {
absl::Status ClExecutionEnvironment::Init() { return CreateEnvironment(&env_); }
std::vector<CalculationsPrecision>
ClExecutionEnvironment::GetSupportedPrecisions() const {
return env_.GetSupportedPrecisions();
}
std::vector<TensorStorageType> ClExecutionEnvironment::GetSupportedStorages(
DataType data_type) const {
if (data_type == DataType::FLOAT16 &&
!env_.GetDevicePtr()->GetInfo().SupportsFP16()) {
return {};
}
return env_.GetSupportedStorages();
}
const GpuInfo& ClExecutionEnvironment::GetGpuInfo() const {
return env_.GetDevicePtr()->GetInfo();
}
absl::Status ClExecutionEnvironment::ExecuteGpuOperationInternal(
const std::vector<TensorDescriptor*>& src_cpu,
const std::vector<TensorDescriptor*>& dst_cpu,
std::unique_ptr<GPUOperation>&& operation) {
const OperationDef& op_def = operation->GetDefinition();
std::vector<Tensor> src(src_cpu.size());
for (int i = 0; i < src_cpu.size(); ++i) {
RETURN_IF_ERROR(src[i].CreateFromDescriptor(*src_cpu[i], &env_.context()));
operation->SetSrc(&src[i], i);
}
std::vector<Tensor> dst(dst_cpu.size());
for (int i = 0; i < dst_cpu.size(); ++i) {
TensorDescriptor descriptor_with_shape = op_def.dst_tensors[i];
descriptor_with_shape.SetBHWDCShape(dst_cpu[i]->GetBHWDCShape());
RETURN_IF_ERROR(
CreateTensor(env_.context(), descriptor_with_shape, &dst[i]));
operation->SetDst(&dst[i], i);
}
ClOperation cl_op;
cl_op.Init(std::move(operation));
{
CreationContext creation_context;
creation_context.device = env_.GetDevicePtr();
creation_context.context = &env_.context();
creation_context.queue = env_.queue();
creation_context.cache = env_.program_cache();
RETURN_IF_ERROR(cl_op.Compile(creation_context));
}
RETURN_IF_ERROR(cl_op.UpdateParams());
RETURN_IF_ERROR(cl_op.AddToQueue(env_.queue()));
RETURN_IF_ERROR(env_.queue()->WaitForCompletion());
for (int i = 0; i < dst_cpu.size(); ++i) {
RETURN_IF_ERROR(dst[i].ToDescriptor(dst_cpu[i], env_.queue()));
}
return absl::OkStatus();
}
} // namespace cl
} // namespace gpu
} // namespace tflite
@@ -0,0 +1,73 @@
/* Copyright 2019 The TensorFlow Authors. All Rights Reserved.
Licensed 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.
==============================================================================*/
#ifndef TENSORFLOW_LITE_DELEGATES_GPU_CL_KERNELS_CL_TEST_H_
#define TENSORFLOW_LITE_DELEGATES_GPU_CL_KERNELS_CL_TEST_H_
#include <memory>
#include <vector>
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include "tensorflow/lite/delegates/gpu/cl/environment.h"
#include "tensorflow/lite/delegates/gpu/cl/opencl_wrapper.h"
#include "tensorflow/lite/delegates/gpu/common/status.h"
#include "tensorflow/lite/delegates/gpu/common/task/testing_util.h"
namespace tflite {
namespace gpu {
namespace cl {
#ifndef ASSERT_OK
#define ASSERT_OK(x) ASSERT_TRUE(x.ok());
#endif
class ClExecutionEnvironment : public TestExecutionEnvironment {
public:
ClExecutionEnvironment() = default;
~ClExecutionEnvironment() override = default;
absl::Status Init();
std::vector<CalculationsPrecision> GetSupportedPrecisions() const override;
std::vector<TensorStorageType> GetSupportedStorages(
DataType data_type) const override;
const GpuInfo& GetGpuInfo() const override;
absl::Status ExecuteGpuOperationInternal(
const std::vector<TensorDescriptor*>& src_cpu,
const std::vector<TensorDescriptor*>& dst_cpu,
std::unique_ptr<GPUOperation>&& operation) override;
private:
Environment env_;
};
class OpenCLOperationTest : public ::testing::Test {
public:
void SetUp() override {
ASSERT_OK(LoadOpenCL());
ASSERT_OK(exec_env_.Init());
}
protected:
ClExecutionEnvironment exec_env_;
};
} // namespace cl
} // namespace gpu
} // namespace tflite
#endif // TENSORFLOW_LITE_DELEGATES_GPU_CL_KERNELS_CL_TEST_H_
@@ -0,0 +1,53 @@
/* Copyright 2019 The TensorFlow Authors. All Rights Reserved.
Licensed 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.
==============================================================================*/
#include <vector>
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include "tensorflow/lite/delegates/gpu/cl/kernels/cl_test.h"
#include "tensorflow/lite/delegates/gpu/common/operations.h"
#include "tensorflow/lite/delegates/gpu/common/status.h"
#include "tensorflow/lite/delegates/gpu/common/tasks/concat_test_util.h"
namespace tflite {
namespace gpu {
namespace cl {
namespace {
TEST_F(OpenCLOperationTest, ConcatWidth) {
auto status = ConcatWidthTest(&exec_env_);
ASSERT_TRUE(status.ok()) << status.message();
}
TEST_F(OpenCLOperationTest, ConcatHeight) {
auto status = ConcatHeightTest(&exec_env_);
ASSERT_TRUE(status.ok()) << status.message();
}
TEST_F(OpenCLOperationTest, ConcatChannels) {
auto status = ConcatChannelsTest(&exec_env_);
ASSERT_TRUE(status.ok()) << status.message();
}
TEST_F(OpenCLOperationTest, ConcatChannelsAlignedx4) {
auto status = ConcatChannelsAlignedx4Test(&exec_env_);
ASSERT_TRUE(status.ok()) << status.message();
}
} // namespace
} // namespace cl
} // namespace gpu
} // namespace tflite
@@ -0,0 +1,39 @@
/* Copyright 2019 The TensorFlow Authors. All Rights Reserved.
Licensed 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.
==============================================================================*/
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include "tensorflow/lite/delegates/gpu/cl/kernels/cl_test.h"
#include "tensorflow/lite/delegates/gpu/common/operations.h"
#include "tensorflow/lite/delegates/gpu/common/status.h"
#include "tensorflow/lite/delegates/gpu/common/tasks/conv_constants_test_util.h"
namespace tflite {
namespace gpu {
namespace cl {
TEST_F(OpenCLOperationTest, ConvConstantsSimpleWeights) {
const auto status = ConvConstantsSimpleWeightsTest(&exec_env_);
ASSERT_TRUE(status.ok()) << status.message();
}
TEST_F(OpenCLOperationTest, ConvConstants) {
const auto status = ConvConstantsTest(&exec_env_);
ASSERT_TRUE(status.ok()) << status.message();
}
} // namespace cl
} // namespace gpu
} // namespace tflite
@@ -0,0 +1,56 @@
/* Copyright 2019 The TensorFlow Authors. All Rights Reserved.
Licensed 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.
==============================================================================*/
#include <vector>
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include "tensorflow/lite/delegates/gpu/cl/kernels/cl_test.h"
#include "tensorflow/lite/delegates/gpu/common/operations.h"
#include "tensorflow/lite/delegates/gpu/common/status.h"
#include "tensorflow/lite/delegates/gpu/common/tasks/conv_generic_test_util.h"
namespace tflite {
namespace gpu {
namespace cl {
TEST_F(OpenCLOperationTest, ConvGeneric1x1SimpleWeights) {
const auto status = ConvGeneric1x1SimpleWeightsTest(&exec_env_);
ASSERT_TRUE(status.ok()) << status.message();
}
TEST_F(OpenCLOperationTest, ConvGeneric1x1) {
const auto status = ConvGeneric1x1Test(&exec_env_);
ASSERT_TRUE(status.ok()) << status.message();
}
TEST_F(OpenCLOperationTest, ConvGenericSimpleWeights) {
const auto status = ConvGenericSimpleWeightsTest(&exec_env_);
ASSERT_TRUE(status.ok()) << status.message();
}
TEST_F(OpenCLOperationTest, ConvGeneric) {
const auto status = ConvGenericTest(&exec_env_);
ASSERT_TRUE(status.ok()) << status.message();
}
TEST_F(OpenCLOperationTest, ConvGenericGrouped) {
const auto status = ConvGenericGroupedTest(&exec_env_);
ASSERT_TRUE(status.ok()) << status.message();
}
} // namespace cl
} // namespace gpu
} // namespace tflite
@@ -0,0 +1,61 @@
/* Copyright 2021 The TensorFlow Authors. All Rights Reserved.
Licensed 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.
==============================================================================*/
#include <vector>
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include "tensorflow/lite/delegates/gpu/cl/kernels/cl_test.h"
#include "tensorflow/lite/delegates/gpu/common/operations.h"
#include "tensorflow/lite/delegates/gpu/common/status.h"
#include "tensorflow/lite/delegates/gpu/common/tasks/conv_weights_converter_test_util.h"
namespace tflite {
namespace gpu {
namespace cl {
TEST_F(OpenCLOperationTest, ConverterToConvWeights1x1OutX4) {
const auto status = ConverterToConvWeights1x1OutX4Test(&exec_env_);
ASSERT_TRUE(status.ok()) << status.message();
}
TEST_F(OpenCLOperationTest, ConverterToConvWeights1x1OutX4Unaligned) {
const auto status = ConverterToConvWeights1x1OutX4UnalignedTest(&exec_env_);
ASSERT_TRUE(status.ok()) << status.message();
}
TEST_F(OpenCLOperationTest, ConverterToConvWeights1x1OutX2) {
const auto status = ConverterToConvWeights1x1OutX2Test(&exec_env_);
ASSERT_TRUE(status.ok()) << status.message();
}
TEST_F(OpenCLOperationTest, ConverterToConvWeightsOutX2) {
const auto status = ConverterToConvWeightsOutX2Test(&exec_env_);
ASSERT_TRUE(status.ok()) << status.message();
}
TEST_F(OpenCLOperationTest, ConverterToConvTransposedWeights4x4) {
const auto status = ConverterToConvTransposedWeights4x4Test(&exec_env_);
ASSERT_TRUE(status.ok()) << status.message();
}
TEST_F(OpenCLOperationTest, ConverterToConvWeights4xTextures) {
const auto status = ConverterToConvWeights4xTexturesTest(&exec_env_);
ASSERT_TRUE(status.ok()) << status.message();
}
} // namespace cl
} // namespace gpu
} // namespace tflite
@@ -0,0 +1,644 @@
/* Copyright 2019 The TensorFlow Authors. All Rights Reserved.
Licensed 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.
==============================================================================*/
#include "tensorflow/lite/delegates/gpu/cl/kernels/converter.h"
#include <array>
#include <memory>
#include <string>
#include <utility>
#include <variant>
#include <vector>
#include "absl/status/status.h"
#include "absl/strings/str_cat.h"
#include "absl/strings/substitute.h"
#include "tensorflow/lite/delegates/gpu/cl/buffer.h"
#include "tensorflow/lite/delegates/gpu/cl/cl_arguments.h"
#include "tensorflow/lite/delegates/gpu/cl/cl_command_queue.h"
#include "tensorflow/lite/delegates/gpu/cl/cl_errors.h"
#include "tensorflow/lite/delegates/gpu/cl/opencl_wrapper.h"
#include "tensorflow/lite/delegates/gpu/cl/tensor.h"
#include "tensorflow/lite/delegates/gpu/cl/tensor_type_util.h"
#include "tensorflow/lite/delegates/gpu/common/data_type.h"
#include "tensorflow/lite/delegates/gpu/common/task/arguments.h"
#include "tensorflow/lite/delegates/gpu/common/task/gpu_operation.h"
#include "tensorflow/lite/delegates/gpu/common/task/tensor_desc.h"
#include "tensorflow/lite/delegates/gpu/common/task/util.h"
#include "tensorflow/lite/delegates/gpu/common/task/work_group_picking.h"
#include "tensorflow/lite/delegates/gpu/common/tasks/conversion.h"
#include "tensorflow/lite/delegates/gpu/common/types.h"
#include "tensorflow/lite/delegates/gpu/common/util.h"
namespace tflite {
namespace gpu {
namespace cl {
namespace {
class OpenClConverterImpl : public TensorObjectConverter {
public:
virtual absl::Status Init(const TensorObjectDef& input_def,
const TensorObjectDef& output_def,
Environment* environment) = 0;
void SetGpuInfo(const GpuInfo& info) { gpu_info_ = info; }
protected:
absl::Status DispatchKernel(Buffer* buffer, Tensor* tensor) {
RETURN_IF_ERROR(cl_args_.SetObjectRef("buffer", buffer));
RETURN_IF_ERROR(cl_args_.SetObjectRef("tensor", tensor));
RETURN_IF_ERROR(cl_args_.Bind(kernel_.kernel()));
const int64_t grid_x =
static_cast<int64_t>(tensor->Width()) * tensor->Batch();
if (grid_x > std::numeric_limits<int>::max()) {
return absl::InvalidArgumentError(
"Grid x-dimension exceeds 32-bit integer maximum.");
}
const int3 grid =
int3(static_cast<int>(grid_x), tensor->Height(), tensor->Slices());
std::vector<int3> work_groups;
GetPossibleWorkGroupsConv(TuningType::kFast, gpu_info_, kernel_.info_, grid,
&work_groups);
const int3 work_group_size = work_groups[0];
const int3 work_groups_count = GetWorkGroupsCount(grid, work_group_size);
return queue_->Dispatch(kernel_, work_groups_count, work_group_size);
}
CLArguments cl_args_;
BHWC shape_;
CLKernel kernel_;
TensorDescriptor tensor_descriptor_;
GpuInfo gpu_info_;
CLCommandQueue* queue_ = nullptr;
const CLContext* context_ = nullptr;
};
bool IsSupportedDataType(DataType type) {
return type == DataType::FLOAT16 || type == DataType::FLOAT32 ||
type == DataType::INT32 || type == DataType::BOOL;
}
bool IsBHWCOpenCLBuffer(const ObjectDef& def) {
return IsSupportedDataType(def.data_type) &&
def.object_type == ObjectType::OPENCL_BUFFER &&
def.data_layout == DataLayout::BHWC;
}
bool IsOpenCLTensor(const ObjectDef& def) {
const bool is_buffer_tensor = def.object_type == ObjectType::OPENCL_BUFFER &&
def.data_layout == DataLayout::DHWC4;
const bool is_image2d_tensor =
def.object_type == ObjectType::OPENCL_TEXTURE &&
def.data_layout == DataLayout::HDWC4;
const bool is_image2d_array_tensor =
def.object_type == ObjectType::OPENCL_TEXTURE &&
def.data_layout == DataLayout::DHWC4;
const bool is_single_image_tensor =
def.object_type == ObjectType::OPENCL_TEXTURE &&
def.data_layout == DataLayout::BHWC;
return IsSupportedDataType(def.data_type) &&
(is_buffer_tensor || is_image2d_tensor || is_image2d_array_tensor ||
is_single_image_tensor);
}
absl::Status GetOpenCLMemory(const TensorObject& obj, cl_mem* memory) {
auto texture = std::get_if<OpenClTexture>(&obj);
auto buffer = std::get_if<OpenClBuffer>(&obj);
if (texture && texture->memobj) {
*memory = texture->memobj;
} else if (buffer && buffer->memobj) {
*memory = buffer->memobj;
} else {
return absl::InvalidArgumentError("Missing OpenCL object.");
}
return absl::OkStatus();
}
// Implements conversion from OpenCL tensor to another OpenCL tensor.
class TensorToTensorConverter : public OpenClConverterImpl {
public:
static bool IsSupported(const ObjectDef& input, const ObjectDef& output) {
return IsOpenCLTensor(input) && IsOpenCLTensor(output);
}
absl::Status Init(const TensorObjectDef& input_def,
const TensorObjectDef& output_def,
Environment* environment) final {
src_tensor_descriptor_ =
TensorDescriptor(input_def.object_def.data_type,
ToTensorStorageType(input_def.object_def.object_type,
input_def.object_def.data_layout),
Layout::BHWC);
dst_tensor_descriptor_ =
TensorDescriptor(output_def.object_def.data_type,
ToTensorStorageType(output_def.object_def.object_type,
output_def.object_def.data_layout),
Layout::BHWC);
GPUOperation gpu_op =
CreateTensorToTensorOp(environment->GetDevicePtr()->GetInfo(),
src_tensor_descriptor_, dst_tensor_descriptor_);
gpu_op.code_ =
"#define MAIN_FUNCTION __kernel void tensor_to_tensor\n" + gpu_op.code_;
const bool need_fp16_support =
input_def.object_def.data_type == DataType::FLOAT16 ||
output_def.object_def.data_type == DataType::FLOAT16;
if (need_fp16_support) {
gpu_op.code_ =
"#pragma OPENCL EXTENSION cl_khr_fp16 : enable\n" + gpu_op.code_;
}
queue_ = environment->queue();
context_ = &environment->context();
shape_ = BHWC(input_def.dimensions.b, input_def.dimensions.h,
input_def.dimensions.w, input_def.dimensions.c);
RETURN_IF_ERROR(gpu_op.AssembleCode(environment->device().GetInfo()));
RETURN_IF_ERROR(cl_args_.Init(environment->device().GetInfo(), nullptr,
&gpu_op.args_, &gpu_op.code_));
return environment->program_cache()->GetOrCreateCLKernel(
gpu_op.code_, "tensor_to_tensor", environment->context(),
environment->device(), &kernel_);
}
absl::Status Convert(const TensorObject& input_obj,
const TensorObject& output_obj) override {
cl_mem in_memory;
RETURN_IF_ERROR(GetOpenCLMemory(input_obj, &in_memory));
cl_mem out_memory;
RETURN_IF_ERROR(GetOpenCLMemory(output_obj, &out_memory));
Tensor src_tensor;
TensorDescriptor descriptor_with_shape = src_tensor_descriptor_;
descriptor_with_shape.SetBHWCShape(shape_);
RETURN_IF_ERROR(CreateTensorShared(*context_, in_memory,
descriptor_with_shape, &src_tensor));
Tensor dst_tensor;
descriptor_with_shape = dst_tensor_descriptor_;
descriptor_with_shape.SetBHWCShape(shape_);
RETURN_IF_ERROR(CreateTensorShared(*context_, out_memory,
descriptor_with_shape, &dst_tensor));
RETURN_IF_ERROR(cl_args_.SetObjectRef("src_tensor", &src_tensor));
RETURN_IF_ERROR(cl_args_.SetObjectRef("dst_tensor", &dst_tensor));
RETURN_IF_ERROR(cl_args_.Bind(kernel_.kernel()));
const int64_t grid_x =
static_cast<int64_t>(dst_tensor.Width()) * dst_tensor.Batch();
if (grid_x > std::numeric_limits<int>::max()) {
return absl::InvalidArgumentError(
"Grid x-dimension exceeds 32-bit integer maximum.");
}
const int3 grid = int3(static_cast<int>(grid_x), dst_tensor.Height(),
dst_tensor.Slices());
const int3 work_group_size = {16, 8, 1};
const int3 work_groups_count = GetWorkGroupsCount(grid, work_group_size);
return queue_->Dispatch(kernel_, work_groups_count, work_group_size);
}
private:
TensorDescriptor src_tensor_descriptor_;
TensorDescriptor dst_tensor_descriptor_;
};
// Implements conversion from OpenCL-specific tensor layout to BHWC OpenCL
// buffer.
class TensorToBHWCBufferConverter : public OpenClConverterImpl {
public:
static bool IsSupported(const ObjectDef& input, const ObjectDef& output) {
return IsOpenCLTensor(input) && IsBHWCOpenCLBuffer(output);
}
absl::Status Init(const TensorObjectDef& input_def,
const TensorObjectDef& output_def,
Environment* environment) final {
TensorStorageType src_tensor_type = ToTensorStorageType(
input_def.object_def.object_type, input_def.object_def.data_layout);
tensor_descriptor_ = TensorDescriptor(input_def.object_def.data_type,
src_tensor_type, Layout::BHWC);
BufferDescriptor buffer_desc;
buffer_desc.element_type = output_def.object_def.data_type;
buffer_desc.element_size = 1;
buffer_desc.memory_type = MemoryType::GLOBAL;
GPUOperation gpu_op =
CreateTensorToBhwcBufferOp(environment->GetDevicePtr()->GetInfo(),
tensor_descriptor_, buffer_desc);
gpu_op.code_ =
"#define MAIN_FUNCTION __kernel void tensor_to_bhwc\n" + gpu_op.code_;
if (output_def.object_def.data_type == DataType::BOOL ||
input_def.object_def.data_type == DataType::BOOL) {
gpu_op.code_ =
"#define convert_bool4(value) (convert_uchar4((value) != 0) & "
"(uchar4) 1)\n#define bool4 uchar4\n" +
gpu_op.code_;
}
const bool need_fp16_support =
input_def.object_def.data_type == DataType::FLOAT16 ||
output_def.object_def.data_type == DataType::FLOAT16;
if (need_fp16_support) {
gpu_op.code_ =
"#pragma OPENCL EXTENSION cl_khr_fp16 : enable\n" + gpu_op.code_;
}
queue_ = environment->queue();
context_ = &environment->context();
shape_ = BHWC(input_def.dimensions.b, input_def.dimensions.h,
input_def.dimensions.w, input_def.dimensions.c);
RETURN_IF_ERROR(gpu_op.AssembleCode(environment->device().GetInfo()));
RETURN_IF_ERROR(cl_args_.Init(environment->device().GetInfo(), nullptr,
&gpu_op.args_, &gpu_op.code_));
return environment->program_cache()->GetOrCreateCLKernel(
gpu_op.code_, "tensor_to_bhwc", environment->context(),
environment->device(), &kernel_);
}
absl::Status Convert(const TensorObject& input_obj,
const TensorObject& output_obj) override {
auto output = std::get_if<OpenClBuffer>(&output_obj);
if (!output || !output->memobj) {
return absl::InvalidArgumentError(
"Missing output in tensor_to_bhwc converter");
}
cl_mem in_memory;
RETURN_IF_ERROR(GetOpenCLMemory(input_obj, &in_memory));
Tensor tensor;
TensorDescriptor descriptor_with_shape = tensor_descriptor_;
descriptor_with_shape.SetBHWCShape(shape_);
RETURN_IF_ERROR(CreateTensorShared(*context_, in_memory,
descriptor_with_shape, &tensor));
Buffer buffer = CreateBufferShared(output->memobj);
return DispatchKernel(&buffer, &tensor);
}
};
// Implements conversion from BHWC OpenCL buffer to OpenCL-specific tensor
// layout.
class BHWCBufferToTensorConverter : public OpenClConverterImpl {
public:
static bool IsSupported(const ObjectDef& input, const ObjectDef& output) {
return IsBHWCOpenCLBuffer(input) && IsOpenCLTensor(output);
}
absl::Status Init(const TensorObjectDef& input_def,
const TensorObjectDef& output_def,
Environment* environment) final {
TensorStorageType dst_tensor_type = ToTensorStorageType(
output_def.object_def.object_type, output_def.object_def.data_layout);
tensor_descriptor_ = TensorDescriptor(output_def.object_def.data_type,
dst_tensor_type, Layout::BHWC);
BufferDescriptor buffer_desc;
buffer_desc.element_type = input_def.object_def.data_type;
buffer_desc.element_size = 1;
buffer_desc.memory_type = MemoryType::GLOBAL;
GPUOperation gpu_op =
CreateBhwcBufferToTensorOp(environment->GetDevicePtr()->GetInfo(),
buffer_desc, tensor_descriptor_);
gpu_op.code_ =
"#define MAIN_FUNCTION __kernel void bhwc_to_tensor\n" + gpu_op.code_;
if (output_def.object_def.data_type == DataType::BOOL ||
input_def.object_def.data_type == DataType::BOOL) {
gpu_op.code_ =
"#define convert_bool4(value) (convert_uchar4((value) != 0) & "
"(uchar4) 1)\n#define bool4 uchar4\n" +
gpu_op.code_;
}
const bool need_fp16_support =
input_def.object_def.data_type == DataType::FLOAT16 ||
output_def.object_def.data_type == DataType::FLOAT16;
if (need_fp16_support) {
gpu_op.code_ =
"#pragma OPENCL EXTENSION cl_khr_fp16 : enable\n" + gpu_op.code_;
}
queue_ = environment->queue();
context_ = &environment->context();
shape_ = BHWC(output_def.dimensions.b, output_def.dimensions.h,
output_def.dimensions.w, output_def.dimensions.c);
RETURN_IF_ERROR(gpu_op.AssembleCode(environment->device().GetInfo()));
RETURN_IF_ERROR(cl_args_.Init(environment->device().GetInfo(), nullptr,
&gpu_op.args_, &gpu_op.code_));
return environment->program_cache()->GetOrCreateCLKernel(
gpu_op.code_, "bhwc_to_tensor", environment->context(),
environment->device(), &kernel_);
}
absl::Status Convert(const TensorObject& input_obj,
const TensorObject& output_obj) override {
auto input = std::get_if<OpenClBuffer>(&input_obj);
if (!input || !input->memobj) {
return absl::InvalidArgumentError(
"Missing input in bhwc_to_tensor converter");
}
cl_mem out_memory;
RETURN_IF_ERROR(GetOpenCLMemory(output_obj, &out_memory));
Tensor tensor;
TensorDescriptor descriptor_with_shape = tensor_descriptor_;
descriptor_with_shape.SetBHWCShape(shape_);
RETURN_IF_ERROR(CreateTensorShared(*context_, out_memory,
descriptor_with_shape, &tensor));
Buffer buffer = CreateBufferShared(input->memobj);
return DispatchKernel(&buffer, &tensor);
}
};
std::array<size_t, 3> CalculateTextureRegion(const TensorObjectDef& def) {
const auto& dims = def.dimensions;
std::array<size_t, 3> region = {0, 0, 1};
switch (ToTensorStorageType(def.object_def.object_type,
def.object_def.data_layout)) {
case TensorStorageType::SINGLE_TEXTURE_2D:
region[0] = static_cast<size_t>(dims.w) * dims.b;
region[1] = static_cast<size_t>(dims.h);
break;
case TensorStorageType::TEXTURE_2D:
region[0] = static_cast<size_t>(dims.w) * dims.b;
region[1] = static_cast<size_t>(dims.h) * dims.d();
break;
case TensorStorageType::TEXTURE_ARRAY:
region[0] = static_cast<size_t>(dims.w) * dims.b;
region[1] = static_cast<size_t>(dims.h);
region[2] = static_cast<size_t>(dims.d());
break;
default:
break;
}
return region;
}
bool IsOpenClTextureOrBuffer(ObjectType type) {
return type == ObjectType::OPENCL_BUFFER ||
type == ObjectType::OPENCL_TEXTURE;
}
// Copies data from one object of the same type and layout to another object.
class TrivialCopier : public OpenClConverterImpl {
public:
static bool IsSupported(const ObjectDef& input, const ObjectDef& output) {
return IsOpenClTextureOrBuffer(input.object_type) &&
input.data_type == output.data_type &&
input.object_type == output.object_type &&
input.data_layout == output.data_layout;
}
absl::Status Init(const TensorObjectDef& input_def,
const TensorObjectDef& output_def,
Environment* environment) final {
shape_ = BHWC(input_def.dimensions.b, input_def.dimensions.h,
input_def.dimensions.w, input_def.dimensions.c);
data_type_ = input_def.object_def.data_type;
data_layout_ = input_def.object_def.data_layout;
queue_ = environment->queue();
region_ = CalculateTextureRegion(output_def);
return absl::OkStatus();
}
absl::Status Convert(const TensorObject& input_obj,
const TensorObject& output_obj) override {
auto texture_input = std::get_if<OpenClTexture>(&input_obj);
auto texture_output = std::get_if<OpenClTexture>(&output_obj);
if (texture_input && texture_output) {
return Copy(*texture_input, *texture_output);
}
auto buffer_input = std::get_if<OpenClBuffer>(&input_obj);
auto buffer_output = std::get_if<OpenClBuffer>(&output_obj);
if (buffer_input && buffer_output) {
return Copy(*buffer_input, *buffer_output);
}
return absl::InvalidArgumentError("Unexpected object");
}
absl::Status Copy(const OpenClBuffer& input, const OpenClBuffer& output) {
if (input.memobj == output.memobj) {
return absl::OkStatus();
}
const size_t channels =
(data_layout_ == DataLayout::BHWC) ? shape_.c : AlignByN(shape_.c, 4);
return GetOpenCLError(clEnqueueCopyBuffer(
queue_->queue(), input.memobj, output.memobj, 0, 0,
SizeOf(data_type_) * shape_.w * shape_.h * channels * shape_.b, 0,
nullptr, nullptr));
}
absl::Status Copy(const OpenClTexture& input, const OpenClTexture& output) {
if (input.memobj == output.memobj) {
return absl::OkStatus();
}
size_t origin[3] = {0, 0, 0};
return GetOpenCLError(
clEnqueueCopyImage(queue_->queue(), input.memobj, output.memobj, origin,
origin, region_.data(), 0, nullptr, nullptr));
}
private:
DataType data_type_ = DataType::UNKNOWN;
DataLayout data_layout_ = DataLayout::UNKNOWN;
std::array<size_t, 3> region_;
};
// Copies data from/to CPU into a tensor.
class CpuCopier : public OpenClConverterImpl {
public:
explicit CpuCopier(bool asynchronous = false) : async_(asynchronous) {}
static bool IsSupported(const ObjectDef& input, const ObjectDef& output) {
return input.data_type == output.data_type &&
input.data_layout == output.data_layout &&
((input.object_type == ObjectType::CPU_MEMORY &&
IsOpenClTextureOrBuffer(output.object_type)) ||
(output.object_type == ObjectType::CPU_MEMORY &&
IsOpenClTextureOrBuffer(input.object_type)));
}
absl::Status Init(const TensorObjectDef& input_def,
const TensorObjectDef& output_def,
Environment* environment) final {
const TensorObjectDef& gpu_def =
input_def.object_def.object_type == ObjectType::CPU_MEMORY ? output_def
: input_def;
region_ = CalculateTextureRegion(gpu_def);
required_bytes_ =
NumElements(gpu_def) * SizeOf(gpu_def.object_def.data_type);
input_data_type_ = input_def.object_def.data_type;
output_data_type_ = output_def.object_def.data_type;
queue_ = environment->queue();
return absl::OkStatus();
}
absl::Status Convert(const TensorObject& input_obj,
const TensorObject& output_obj) override {
auto cpu_input = std::get_if<CpuMemory>(&input_obj);
auto cpu_output = std::get_if<CpuMemory>(&output_obj);
if (cpu_input) {
if (cpu_input->size_bytes < required_bytes_) {
return absl::InvalidArgumentError(
absl::StrCat("CPU input memory size ", cpu_input->size_bytes,
" is less than required ", required_bytes_));
}
if (output_data_type_ == DataType::BOOL) {
return CopyFromBoolCpu(cpu_input, output_obj);
}
auto texture_output = std::get_if<OpenClTexture>(&output_obj);
if (texture_output) {
return queue_->EnqueueWriteImage(
texture_output->memobj, int3(region_[0], region_[1], region_[2]),
cpu_input->data, async_);
}
auto buffer_output = std::get_if<OpenClBuffer>(&output_obj);
if (buffer_output) {
return queue_->EnqueueWriteBuffer(
buffer_output->memobj, required_bytes_, cpu_input->data, async_);
}
} else if (cpu_output) {
if (cpu_output->size_bytes < required_bytes_) {
return absl::InvalidArgumentError(
absl::StrCat("CPU output memory size ", cpu_output->size_bytes,
" is less than required ", required_bytes_));
}
if (input_data_type_ == DataType::BOOL) {
return CopyToBoolCpu(input_obj, cpu_output);
}
auto texture_input = std::get_if<OpenClTexture>(&input_obj);
if (texture_input) {
return queue_->EnqueueReadImage(
texture_input->memobj, int3(region_[0], region_[1], region_[2]),
cpu_output->data, async_);
}
auto buffer_input = std::get_if<OpenClBuffer>(&input_obj);
if (buffer_input) {
return queue_->EnqueueReadBuffer(buffer_input->memobj, required_bytes_,
cpu_output->data, async_);
}
}
return absl::InvalidArgumentError("Unexpected object");
}
private:
absl::Status CopyToBoolCpu(const TensorObject& tensor_obj,
const CpuMemory* cpu_memory) {
const size_t num_elements = required_bytes_;
std::vector<uint8_t> tmp_data(num_elements);
auto texture_input = std::get_if<OpenClTexture>(&tensor_obj);
if (texture_input) {
RETURN_IF_ERROR(queue_->EnqueueReadImage(
texture_input->memobj, int3(region_[0], region_[1], region_[2]),
tmp_data.data(), false));
} else {
auto buffer_input = std::get_if<OpenClBuffer>(&tensor_obj);
if (!buffer_input) {
return absl::InvalidArgumentError("Unexpected object");
}
RETURN_IF_ERROR(queue_->EnqueueReadBuffer(
buffer_input->memobj, tmp_data.size(), tmp_data.data(), false));
}
bool* output_data = reinterpret_cast<bool*>(cpu_memory->data);
for (size_t i = 0; i < num_elements; ++i) {
output_data[i] = tmp_data[i];
}
return absl::OkStatus();
}
absl::Status CopyFromBoolCpu(const CpuMemory* cpu_memory,
const TensorObject& tensor_obj) {
const size_t num_elements = required_bytes_;
const bool* bool_data = reinterpret_cast<bool*>(cpu_memory->data);
std::vector<uint8_t> tmp_bool_data;
tmp_bool_data.reserve(num_elements);
for (size_t i = 0; i < num_elements; ++i) {
tmp_bool_data.push_back(bool_data[i]);
}
auto texture_output = std::get_if<OpenClTexture>(&tensor_obj);
if (texture_output) {
return queue_->EnqueueWriteImage(texture_output->memobj,
int3(region_[0], region_[1], region_[2]),
tmp_bool_data.data(), false);
}
auto buffer_output = std::get_if<OpenClBuffer>(&tensor_obj);
if (buffer_output) {
return queue_->EnqueueWriteBuffer(buffer_output->memobj,
tmp_bool_data.size(),
tmp_bool_data.data(), false);
}
return absl::InvalidArgumentError("Unexpected object");
}
std::array<size_t, 3> region_;
size_t required_bytes_ = 0;
bool async_;
DataType input_data_type_;
DataType output_data_type_;
};
class OpenClTensorConverterBuilder : public TensorObjectConverterBuilder {
public:
explicit OpenClTensorConverterBuilder(Environment* environment)
: environment_(environment) {}
bool IsSupported(const TensorObjectDef& input,
const TensorObjectDef& output) const final {
const auto& input_def = input.object_def;
const auto& output_def = output.object_def;
return input.dimensions == output.dimensions &&
(TrivialCopier::IsSupported(input_def, output_def) ||
TensorToTensorConverter::IsSupported(input_def, output_def) ||
CpuCopier::IsSupported(input_def, output_def) ||
TensorToBHWCBufferConverter::IsSupported(input_def, output_def) ||
BHWCBufferToTensorConverter::IsSupported(input_def, output_def));
}
absl::Status MakeConverter(
const TensorObjectDef& input, const TensorObjectDef& output,
std::unique_ptr<TensorObjectConverter>* converter) final {
std::unique_ptr<OpenClConverterImpl> impl;
const auto& input_def = input.object_def;
const auto& output_def = output.object_def;
if (TrivialCopier::IsSupported(input_def, output_def)) {
impl = std::make_unique<TrivialCopier>();
} else if (TensorToTensorConverter::IsSupported(input_def, output_def)) {
impl = std::make_unique<TensorToTensorConverter>();
} else if (CpuCopier::IsSupported(input_def, output_def)) {
impl = std::make_unique<CpuCopier>(/*asynchronous*/ true);
} else if (TensorToBHWCBufferConverter::IsSupported(input_def,
output_def)) {
impl = std::make_unique<TensorToBHWCBufferConverter>();
} else if (BHWCBufferToTensorConverter::IsSupported(input_def,
output_def)) {
impl = std::make_unique<BHWCBufferToTensorConverter>();
} else {
return absl::UnimplementedError("Unsupported conversion");
}
RETURN_IF_ERROR(impl->Init(input, output, environment_));
impl->SetGpuInfo(environment_->GetDevicePtr()->GetInfo());
*converter = std::move(impl);
return absl::OkStatus();
}
private:
Environment* environment_;
};
} // namespace
std::unique_ptr<TensorObjectConverterBuilder> NewConverterBuilder(
Environment* environment) {
return std::make_unique<OpenClTensorConverterBuilder>(environment);
}
} // namespace cl
} // namespace gpu
} // namespace tflite
@@ -0,0 +1,37 @@
/* Copyright 2019 The TensorFlow Authors. All Rights Reserved.
Licensed 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.
==============================================================================*/
#ifndef TENSORFLOW_LITE_DELEGATES_GPU_CL_KERNELS_CONVERTER_H_
#define TENSORFLOW_LITE_DELEGATES_GPU_CL_KERNELS_CONVERTER_H_
#include <memory>
#include "tensorflow/lite/delegates/gpu/cl/environment.h"
#include "tensorflow/lite/delegates/gpu/spi.h"
namespace tflite {
namespace gpu {
namespace cl {
// Supports conversions from BHWC to internal OpenCL tensor representation and
// back. Also supports F16/F32.
std::unique_ptr<TensorObjectConverterBuilder> NewConverterBuilder(
Environment* environment);
} // namespace cl
} // namespace gpu
} // namespace tflite
#endif // TENSORFLOW_LITE_DELEGATES_GPU_CL_KERNELS_CONVERTER_H_
@@ -0,0 +1,34 @@
/* Copyright 2020 The TensorFlow Authors. All Rights Reserved.
Licensed 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.
==============================================================================*/
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include "tensorflow/lite/delegates/gpu/cl/kernels/cl_test.h"
#include "tensorflow/lite/delegates/gpu/common/operations.h"
#include "tensorflow/lite/delegates/gpu/common/status.h"
#include "tensorflow/lite/delegates/gpu/common/tasks/convolution_transposed_3x3_test_util.h"
namespace tflite {
namespace gpu {
namespace cl {
TEST_F(OpenCLOperationTest, ConvolutionTransposed3x3) {
auto status = ConvolutionTransposed3x3Test(&exec_env_);
ASSERT_TRUE(status.ok()) << status.message();
}
} // namespace cl
} // namespace gpu
} // namespace tflite
@@ -0,0 +1,39 @@
/* Copyright 2019 The TensorFlow Authors. All Rights Reserved.
Licensed 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.
==============================================================================*/
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include "tensorflow/lite/delegates/gpu/cl/kernels/cl_test.h"
#include "tensorflow/lite/delegates/gpu/common/operations.h"
#include "tensorflow/lite/delegates/gpu/common/status.h"
#include "tensorflow/lite/delegates/gpu/common/tasks/convolution_transposed_3x3_thin_test_util.h"
namespace tflite {
namespace gpu {
namespace cl {
TEST_F(OpenCLOperationTest, ConvolutionTransposed3x3ThinSimpleWeights) {
auto status = ConvolutionTransposed3x3ThinSimpleWeightsTest(&exec_env_);
ASSERT_TRUE(status.ok()) << status.message();
}
TEST_F(OpenCLOperationTest, ConvolutionTransposed3x3Thin) {
auto status = ConvolutionTransposed3x3ThinTest(&exec_env_);
ASSERT_TRUE(status.ok()) << status.message();
}
} // namespace cl
} // namespace gpu
} // namespace tflite
@@ -0,0 +1,38 @@
/* Copyright 2019 The TensorFlow Authors. All Rights Reserved.
Licensed 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.
==============================================================================*/
#include <vector>
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include "tensorflow/lite/delegates/gpu/cl/kernels/cl_test.h"
#include "tensorflow/lite/delegates/gpu/common/operations.h"
#include "tensorflow/lite/delegates/gpu/common/status.h"
#include "tensorflow/lite/delegates/gpu/common/tasks/convolution_transposed_4x4_test_util.h"
namespace tflite {
namespace gpu {
namespace cl {
namespace {
TEST_F(OpenCLOperationTest, ConvolutionTransposed4x4SimpleWeights) {
auto status = ConvolutionTransposed4x4SimpleWeightsTest(&exec_env_);
ASSERT_TRUE(status.ok()) << status.message();
}
} // namespace
} // namespace cl
} // namespace gpu
} // namespace tflite
@@ -0,0 +1,43 @@
/* Copyright 2019 The TensorFlow Authors. All Rights Reserved.
Licensed 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.
==============================================================================*/
#include <vector>
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include "tensorflow/lite/delegates/gpu/cl/kernels/cl_test.h"
#include "tensorflow/lite/delegates/gpu/common/operations.h"
#include "tensorflow/lite/delegates/gpu/common/status.h"
#include "tensorflow/lite/delegates/gpu/common/tasks/convolution_transposed_test_util.h"
namespace tflite {
namespace gpu {
namespace cl {
namespace {
TEST_F(OpenCLOperationTest, ConvolutionTransposedSimpleWeights) {
auto status = ConvolutionTransposedSimpleWeightsTest(&exec_env_);
ASSERT_TRUE(status.ok()) << status.message();
}
TEST_F(OpenCLOperationTest, ConvolutionTransposed) {
auto status = ConvolutionTransposedTest(&exec_env_);
ASSERT_TRUE(status.ok()) << status.message();
}
} // namespace
} // namespace cl
} // namespace gpu
} // namespace tflite
@@ -0,0 +1,39 @@
/* Copyright 2019 The TensorFlow Authors. All Rights Reserved.
Licensed 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.
==============================================================================*/
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include "tensorflow/lite/delegates/gpu/cl/kernels/cl_test.h"
#include "tensorflow/lite/delegates/gpu/common/operations.h"
#include "tensorflow/lite/delegates/gpu/common/status.h"
#include "tensorflow/lite/delegates/gpu/common/tasks/convolution_transposed_thin_test_util.h"
namespace tflite {
namespace gpu {
namespace cl {
TEST_F(OpenCLOperationTest, ConvolutionTransposedThinSimpleWeights) {
auto status = ConvolutionTransposedThinSimpleWeightsTest(&exec_env_);
ASSERT_TRUE(status.ok()) << status.message();
}
TEST_F(OpenCLOperationTest, ConvolutionTransposedThin) {
auto status = ConvolutionTransposedThinTest(&exec_env_);
ASSERT_TRUE(status.ok()) << status.message();
}
} // namespace cl
} // namespace gpu
} // namespace tflite
@@ -0,0 +1,37 @@
/* Copyright 2022 The TensorFlow Authors. All Rights Reserved.
Licensed 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.
==============================================================================*/
#include <gtest/gtest.h>
#include "tensorflow/lite/delegates/gpu/cl/kernels/cl_test.h"
#include "tensorflow/lite/delegates/gpu/common/tasks/cumsum_test_util.h"
namespace tflite {
namespace gpu {
namespace cl {
namespace {
TEST_F(OpenCLOperationTest, CumsumHWCTest) {
absl::Status status = CumsumHWCTest(&exec_env_);
ASSERT_TRUE(status.ok()) << status.message();
}
TEST_F(OpenCLOperationTest, CumsumBHWCTest) {
absl::Status status = CumsumBHWCTest(&exec_env_);
ASSERT_TRUE(status.ok()) << status.message();
}
} // namespace
} // namespace cl
} // namespace gpu
} // namespace tflite
@@ -0,0 +1,49 @@
/* Copyright 2019 The TensorFlow Authors. All Rights Reserved.
Licensed 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.
==============================================================================*/
#include <vector>
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include "tensorflow/lite/delegates/gpu/cl/kernels/cl_test.h"
#include "tensorflow/lite/delegates/gpu/common/operations.h"
#include "tensorflow/lite/delegates/gpu/common/status.h"
#include "tensorflow/lite/delegates/gpu/common/tasks/depthwise_conv_3x3_stride_h2_test_util.h"
#include "tensorflow/lite/delegates/gpu/common/tasks/depthwise_conv_3x3_test_util.h"
namespace tflite {
namespace gpu {
namespace cl {
namespace {
TEST_F(OpenCLOperationTest, DepthwiseConv3x3SimpleWeights) {
auto status = DepthwiseConv3x3SimpleWeightsTest(&exec_env_);
ASSERT_TRUE(status.ok()) << status.message();
}
TEST_F(OpenCLOperationTest, DepthwiseConv3x3) {
auto status = DepthwiseConv3x3Test(&exec_env_);
ASSERT_TRUE(status.ok()) << status.message();
}
TEST_F(OpenCLOperationTest, DepthWiseConv3x3StrideH2SimpleWeights) {
auto status = DepthWiseConv3x3StrideH2SimpleWeightsTest(&exec_env_);
ASSERT_TRUE(status.ok()) << status.message();
}
} // namespace
} // namespace cl
} // namespace gpu
} // namespace tflite
@@ -0,0 +1,48 @@
/* Copyright 2019 The TensorFlow Authors. All Rights Reserved.
Licensed 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.
==============================================================================*/
#include <vector>
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include "tensorflow/lite/delegates/gpu/cl/kernels/cl_test.h"
#include "tensorflow/lite/delegates/gpu/common/operations.h"
#include "tensorflow/lite/delegates/gpu/common/status.h"
#include "tensorflow/lite/delegates/gpu/common/tasks/depthwise_conv_test_util.h"
namespace tflite {
namespace gpu {
namespace cl {
namespace {
TEST_F(OpenCLOperationTest, DepthwiseConvSimpleWeights) {
auto status = DepthwiseConvSimpleWeightsTest(&exec_env_);
ASSERT_TRUE(status.ok()) << status.message();
}
TEST_F(OpenCLOperationTest, DepthwiseConvNoMultiplier) {
auto status = DepthwiseConvNoMultiplierTest(&exec_env_);
ASSERT_TRUE(status.ok()) << status.message();
}
TEST_F(OpenCLOperationTest, DepthwiseConvMultiplier2) {
auto status = DepthwiseConvMultiplier2Test(&exec_env_);
ASSERT_TRUE(status.ok()) << status.message();
}
} // namespace
} // namespace cl
} // namespace gpu
} // namespace tflite
@@ -0,0 +1,157 @@
/* Copyright 2019 The TensorFlow Authors. All Rights Reserved.
Licensed 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.
==============================================================================*/
#include <vector>
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include "tensorflow/lite/delegates/gpu/cl/kernels/cl_test.h"
#include "tensorflow/lite/delegates/gpu/common/operations.h"
#include "tensorflow/lite/delegates/gpu/common/status.h"
#include "tensorflow/lite/delegates/gpu/common/tasks/elementwise_test_util.h"
namespace tflite {
namespace gpu {
namespace cl {
namespace {
TEST_F(OpenCLOperationTest, Abs) { ASSERT_OK(AbsTest(&exec_env_)); }
TEST_F(OpenCLOperationTest, Cos) { ASSERT_OK(CosTest(&exec_env_)); }
TEST_F(OpenCLOperationTest, Copy) { ASSERT_OK(CopyTest(&exec_env_)); }
TEST_F(OpenCLOperationTest, Elu) { ASSERT_OK(EluTest(&exec_env_)); }
TEST_F(OpenCLOperationTest, Exp) { ASSERT_OK(ExpTest(&exec_env_)); }
TEST_F(OpenCLOperationTest, Floor) { ASSERT_OK(FloorTest(&exec_env_)); }
TEST_F(OpenCLOperationTest, FloorDiv) { ASSERT_OK(FloorDivTest(&exec_env_)); }
TEST_F(OpenCLOperationTest, FloorMod) { ASSERT_OK(FloorModTest(&exec_env_)); }
TEST_F(OpenCLOperationTest, Gelu) { ASSERT_OK(GeluTest(&exec_env_)); }
TEST_F(OpenCLOperationTest, HardSwish) { ASSERT_OK(HardSwishTest(&exec_env_)); }
TEST_F(OpenCLOperationTest, Log) { ASSERT_OK(LogTest(&exec_env_)); }
TEST_F(OpenCLOperationTest, Neg) { ASSERT_OK(NegTest(&exec_env_)); }
TEST_F(OpenCLOperationTest, Rsqrt) { ASSERT_OK(RsqrtTest(&exec_env_)); }
TEST_F(OpenCLOperationTest, Sigmoid) { ASSERT_OK(SigmoidTest(&exec_env_)); }
TEST_F(OpenCLOperationTest, Sin) { ASSERT_OK(SinTest(&exec_env_)); }
TEST_F(OpenCLOperationTest, Sqrt) { ASSERT_OK(SqrtTest(&exec_env_)); }
TEST_F(OpenCLOperationTest, Square) { ASSERT_OK(SquareTest(&exec_env_)); }
TEST_F(OpenCLOperationTest, Tanh) { ASSERT_OK(TanhTest(&exec_env_)); }
TEST_F(OpenCLOperationTest, Sub) { ASSERT_OK(SubTest(&exec_env_)); }
TEST_F(OpenCLOperationTest, SquaredDiff) {
ASSERT_OK(SquaredDiffTest(&exec_env_));
}
TEST_F(OpenCLOperationTest, Div) { ASSERT_OK(DivTest(&exec_env_)); }
TEST_F(OpenCLOperationTest, Pow) { ASSERT_OK(PowTest(&exec_env_)); }
TEST_F(OpenCLOperationTest, Add) { ASSERT_OK(AddTest(&exec_env_)); }
TEST_F(OpenCLOperationTest, Maximum) { ASSERT_OK(MaximumTest(&exec_env_)); }
TEST_F(OpenCLOperationTest, MaximumWithScalar) {
ASSERT_OK(MaximumWithScalarTest(&exec_env_));
}
TEST_F(OpenCLOperationTest, MaximumWithConstantLinearTensor) {
ASSERT_OK(MaximumWithConstantLinearTensorTest(&exec_env_));
}
TEST_F(OpenCLOperationTest, MaximumWithConstantHWCTensor) {
ASSERT_OK(MaximumWithConstantHWCTensorTest(&exec_env_));
}
TEST_F(OpenCLOperationTest, MaximumWithConstantHWCTensorBroadcastChannels) {
ASSERT_OK(MaximumWithConstantHWCTensorBroadcastChannelsTest(&exec_env_));
}
TEST_F(OpenCLOperationTest, Minimum) { ASSERT_OK(MinimumTest(&exec_env_)); }
TEST_F(OpenCLOperationTest, MinimumWithScalar) {
ASSERT_OK(MinimumWithScalarTest(&exec_env_));
}
TEST_F(OpenCLOperationTest, Mul) { ASSERT_OK(MulTest(&exec_env_)); }
TEST_F(OpenCLOperationTest, MulBroadcastHW) {
ASSERT_OK(MulBroadcastHWTest(&exec_env_));
}
TEST_F(OpenCLOperationTest, MulBroadcastChannels) {
ASSERT_OK(MulBroadcastChannelsTest(&exec_env_));
}
TEST_F(OpenCLOperationTest, SubWithScalarAtFirstPosition) {
ASSERT_OK(SubWithScalarAtFirstPositionTest(&exec_env_));
}
TEST_F(OpenCLOperationTest, Less) { ASSERT_OK(LessTest(&exec_env_)); }
TEST_F(OpenCLOperationTest, LessEqual) { ASSERT_OK(LessEqualTest(&exec_env_)); }
TEST_F(OpenCLOperationTest, Greater) { ASSERT_OK(GreaterTest(&exec_env_)); }
TEST_F(OpenCLOperationTest, GreaterEqual) {
ASSERT_OK(GreaterEqualTest(&exec_env_));
}
TEST_F(OpenCLOperationTest, Equal) { ASSERT_OK(EqualTest(&exec_env_)); }
TEST_F(OpenCLOperationTest, NotEqual) { ASSERT_OK(NotEqualTest(&exec_env_)); }
TEST_F(OpenCLOperationTest, CosBroadcast) {
ASSERT_OK(CosBroadcastTest(&exec_env_));
}
TEST_F(OpenCLOperationTest, MaximumScalarBroadcastInput) {
ASSERT_OK(MaximumScalarBroadcastInputTest(&exec_env_));
}
TEST_F(OpenCLOperationTest, MulLinearBroadcastInput) {
ASSERT_OK(MulLinearBroadcastInputTest(&exec_env_));
}
TEST_F(OpenCLOperationTest, MulBroadcastBothInputs) {
ASSERT_OK(MulBroadcastBothInputsTest(&exec_env_));
}
TEST_F(OpenCLOperationTest, LogicalAndTest) {
ASSERT_OK(LogicalAndTest(&exec_env_));
}
TEST_F(OpenCLOperationTest, LogicalAndWithConstantTest) {
ASSERT_OK(LogicalAndWithConstantTest(&exec_env_));
}
} // namespace
} // namespace cl
} // namespace gpu
} // namespace tflite
@@ -0,0 +1,136 @@
/* Copyright 2019 The TensorFlow Authors. All Rights Reserved.
Licensed 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.
==============================================================================*/
#include "tensorflow/lite/delegates/gpu/common/tasks/fully_connected.h"
#include <vector>
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include "tensorflow/lite/delegates/gpu/cl/environment.h"
#include "tensorflow/lite/delegates/gpu/cl/kernels/cl_test.h"
#include "tensorflow/lite/delegates/gpu/common/data_type.h"
#include "tensorflow/lite/delegates/gpu/common/operations.h"
#include "tensorflow/lite/delegates/gpu/common/shape.h"
#include "tensorflow/lite/delegates/gpu/common/task/gpu_operation.h"
#include "tensorflow/lite/delegates/gpu/common/tasks/fully_connected_test_util.h"
#include "tensorflow/lite/delegates/gpu/common/tensor.h"
using ::testing::ElementsAreArray;
namespace tflite {
namespace gpu {
namespace cl {
namespace {
TEST_F(OpenCLOperationTest, FullyConnected) {
auto status = FullyConnectedTest(&exec_env_);
ASSERT_TRUE(status.ok()) << status.message();
}
TEST_F(OpenCLOperationTest, FullyConnectedLarge) {
auto status = FullyConnectedLargeTest(&exec_env_);
ASSERT_TRUE(status.ok()) << status.message();
}
TEST_F(OpenCLOperationTest, FullyConnectedExtraLarge) {
auto status = FullyConnectedExtraLargeTest(&exec_env_);
ASSERT_TRUE(status.ok()) << status.message();
}
TEST_F(OpenCLOperationTest, FullyConnectedInt8) {
auto status = FullyConnectedInt8Test(&exec_env_);
ASSERT_TRUE(status.ok()) << status.message();
}
TEST_F(OpenCLOperationTest, RearrageWeights) {
tflite::gpu::Tensor<OHWI, DataType::FLOAT32> weights;
weights.shape = OHWI(8, 1, 1, 8);
weights.data = {
0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, //
10.0f, 11.0f, 12.0f, 13.0f, 14.0f, 15.0f, 16.0f, 17.0f, //
20.0f, 21.0f, 22.0f, 23.0f, 24.0f, 25.0f, 26.0f, 27.0f, //
30.0f, 31.0f, 32.0f, 33.0f, 34.0f, 35.0f, 36.0f, 37.0f, //
40.0f, 41.0f, 42.0f, 43.0f, 44.0f, 45.0f, 46.0f, 47.0f, //
50.0f, 51.0f, 52.0f, 53.0f, 54.0f, 55.0f, 56.0f, 57.0f, //
60.0f, 61.0f, 62.0f, 63.0f, 64.0f, 65.0f, 66.0f, 67.0f, //
70.0f, 71.0f, 72.0f, 73.0f, 74.0f, 75.0f, 76.0f, 77.0f //
};
std::vector<float> expected_rearranged_data = {
// Top-left block
0.0f, 10.0f, 20.0f, 30.0f, 1.0f, 11.0f, 21.0f, 31.0f, 2.0f, 12.0f, 22.0f,
32.0f, 3.0f, 13.0f, 23.0f, 33.0f,
// Bottom-left block
40.0f, 50.0f, 60.0f, 70.0f, 41.0f, 51.0f, 61.0f, 71.0f, 42.0f, 52.0f,
62.0f, 72.0f, 43.0f, 53.0f, 63.0f, 73.0f,
// Top-right block
4.0f, 14.0f, 24.0f, 34.0f, 5.0f, 15.0f, 25.0f, 35.0f, 6.0f, 16.0f, 26.0f,
36.0f, 7.0f, 17.0f, 27.0f, 37.0f,
// Bottom-right block
44.0f, 54.0f, 64.0f, 74.0f, 45.0f, 55.0f, 65.0f, 75.0f, 46.0f, 56.0f,
66.0f, 76.0f, 47.0f, 57.0f, 67.0f, 77.0f};
std::vector<float> data(8 * 8);
RearrangeFCWeightsToIOO4I4(weights, data.data());
EXPECT_THAT(data, ElementsAreArray(expected_rearranged_data));
}
TEST_F(OpenCLOperationTest, RearrageWeightsWhenPaddingIsRequired) {
tflite::gpu::Tensor<OHWI, DataType::FLOAT32> weights;
weights.shape = OHWI(9, 1, 1, 7);
weights.data = {
0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, //
10.0f, 11.0f, 12.0f, 13.0f, 14.0f, 15.0f, 16.0f, //
20.0f, 21.0f, 22.0f, 23.0f, 24.0f, 25.0f, 26.0f, //
30.0f, 31.0f, 32.0f, 33.0f, 34.0f, 35.0f, 36.0f, //
40.0f, 41.0f, 42.0f, 43.0f, 44.0f, 45.0f, 46.0f, //
50.0f, 51.0f, 52.0f, 53.0f, 54.0f, 55.0f, 56.0f, //
60.0f, 61.0f, 62.0f, 63.0f, 64.0f, 65.0f, 66.0f, //
70.0f, 71.0f, 72.0f, 73.0f, 74.0f, 75.0f, 76.0f, //
80.0f, 81.0f, 82.0f, 83.0f, 84.0f, 85.0f, 86.0f, //
};
std::vector<float> expected_rearranged_data = {
// Top-left block
0.0f, 10.0f, 20.0f, 30.0f, 1.0f, 11.0f, 21.0f, 31.0f, 2.0f, 12.0f, 22.0f,
32.0f, 3.0f, 13.0f, 23.0f, 33.0f,
// Mid-left block
40.0f, 50.0f, 60.0f, 70.0f, 41.0f, 51.0f, 61.0f, 71.0f, 42.0f, 52.0f,
62.0f, 72.0f, 43.0f, 53.0f, 63.0f, 73.0f,
// Bottom-left block
80.0f, 0.0f, 0.0f, 0.0f, 81.0f, 0.0f, 0.0f, 0.0f, 82.0f, 0.0f, 0.0f, 0.0f,
83.0f, 0.0f, 0.0f, 0.0f,
// Top-right block
4.0f, 14.0f, 24.0f, 34.0f, 5.0f, 15.0f, 25.0f, 35.0f, 6.0f, 16.0f, 26.0f,
36.0f, 0.0f, 0.0f, 0.0f, 0.0f,
// Mid-left block
44.0f, 54.0f, 64.0f, 74.0f, 45.0f, 55.0f, 65.0f, 75.0f, 46.0f, 56.0f,
66.0f, 76.0f, 0.0f, 0.0f, 0.0f, 0.0f,
// Bottom-right block
84.0f, 0.0f, 0.0f, 0.0f, 85.0f, 0.0f, 0.0f, 0.0f, 86.0f, 0.0f, 0.0f, 0.0f,
0.0f, 0.0f, 0.0f, 0.0f};
std::vector<float> data(12 * 8);
RearrangeFCWeightsToIOO4I4(weights, data.data());
EXPECT_THAT(data, ElementsAreArray(expected_rearranged_data));
}
} // namespace
} // namespace cl
} // namespace gpu
} // namespace tflite
@@ -0,0 +1,69 @@
/* Copyright 2021 The TensorFlow Authors. All Rights Reserved.
Licensed 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.
==============================================================================*/
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include "tensorflow/lite/delegates/gpu/cl/kernels/cl_test.h"
#include "tensorflow/lite/delegates/gpu/common/operations.h"
#include "tensorflow/lite/delegates/gpu/common/status.h"
#include "tensorflow/lite/delegates/gpu/common/tasks/gather_test_util.h"
namespace tflite {
namespace gpu {
namespace cl {
TEST_F(OpenCLOperationTest, GatherBatch) {
auto status = GatherBatchTest(&exec_env_, false);
ASSERT_TRUE(status.ok()) << status.message();
}
TEST_F(OpenCLOperationTest, GatherBatchConst) {
auto status = GatherBatchTest(&exec_env_, true);
ASSERT_TRUE(status.ok()) << status.message();
}
TEST_F(OpenCLOperationTest, GatherHeight) {
auto status = GatherHeightTest(&exec_env_, false);
ASSERT_TRUE(status.ok()) << status.message();
}
TEST_F(OpenCLOperationTest, GatherHeightConst) {
auto status = GatherHeightTest(&exec_env_, true);
ASSERT_TRUE(status.ok()) << status.message();
}
TEST_F(OpenCLOperationTest, GatherWidth) {
auto status = GatherWidthTest(&exec_env_, false);
ASSERT_TRUE(status.ok()) << status.message();
}
TEST_F(OpenCLOperationTest, GatherWidthConst) {
auto status = GatherWidthTest(&exec_env_, true);
ASSERT_TRUE(status.ok()) << status.message();
}
TEST_F(OpenCLOperationTest, GatherChannels) {
auto status = GatherChannelsTest(&exec_env_, false);
ASSERT_TRUE(status.ok()) << status.message();
}
TEST_F(OpenCLOperationTest, GatherChannelsConst) {
auto status = GatherChannelsTest(&exec_env_, true);
ASSERT_TRUE(status.ok()) << status.message();
}
} // namespace cl
} // namespace gpu
} // namespace tflite
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,38 @@
/* Copyright 2019 The TensorFlow Authors. All Rights Reserved.
Licensed 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.
==============================================================================*/
#include <cmath>
#include <cstdlib>
#include <vector>
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include "tensorflow/lite/delegates/gpu/cl/kernels/cl_test.h"
#include "tensorflow/lite/delegates/gpu/common/operations.h"
#include "tensorflow/lite/delegates/gpu/common/status.h"
#include "tensorflow/lite/delegates/gpu/common/tasks/lstm_test_util.h"
namespace tflite {
namespace gpu {
namespace cl {
TEST_F(OpenCLOperationTest, LSTM) {
auto status = LstmTest(&exec_env_);
ASSERT_TRUE(status.ok()) << status.message();
}
} // namespace cl
} // namespace gpu
} // namespace tflite
@@ -0,0 +1,38 @@
/* Copyright 2019 The TensorFlow Authors. All Rights Reserved.
Licensed 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.
==============================================================================*/
#include <vector>
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include "tensorflow/lite/delegates/gpu/cl/kernels/cl_test.h"
#include "tensorflow/lite/delegates/gpu/common/operations.h"
#include "tensorflow/lite/delegates/gpu/common/status.h"
#include "tensorflow/lite/delegates/gpu/common/tasks/max_unpooling_test_util.h"
namespace tflite {
namespace gpu {
namespace cl {
namespace {
TEST_F(OpenCLOperationTest, MaxUnpooling) {
auto status = MaxUnpoolingTest(&exec_env_);
ASSERT_TRUE(status.ok()) << status.message();
}
} // namespace
} // namespace cl
} // namespace gpu
} // namespace tflite
@@ -0,0 +1,87 @@
/* Copyright 2020 The TensorFlow Authors. All Rights Reserved.
Licensed 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.
==============================================================================*/
#include <vector>
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include "tensorflow/lite/delegates/gpu/cl/kernels/cl_test.h"
#include "tensorflow/lite/delegates/gpu/common/operations.h"
#include "tensorflow/lite/delegates/gpu/common/status.h"
#include "tensorflow/lite/delegates/gpu/common/tasks/mean_stddev_normalization_test_util.h"
namespace tflite {
namespace gpu {
namespace cl {
namespace {
// note: 100.01 is not representable in FP16 (is in FP32), so use 101.0 instead.
TEST_F(OpenCLOperationTest, MeanStddevNormSeparateBatches) {
// zero mean, zero variance
auto status = MeanStddevNormSeparateBatchesTest(0.0f, 0.0f, 0.0f, &exec_env_);
ASSERT_TRUE(status.ok()) << status.message();
// zero mean, small variance
status = MeanStddevNormSeparateBatchesTest(0.0f, 0.01f, 2.63e-4f, &exec_env_);
ASSERT_TRUE(status.ok()) << status.message();
// zero mean, large variance
status =
MeanStddevNormSeparateBatchesTest(0.0f, 100.0f, 2.63e-4f, &exec_env_);
ASSERT_TRUE(status.ok()) << status.message();
// small mean, zero variance
status = MeanStddevNormSeparateBatchesTest(0.01f, 0.0f, 0.0f, &exec_env_);
ASSERT_TRUE(status.ok()) << status.message();
// small mean, small variance
status =
MeanStddevNormSeparateBatchesTest(0.01f, 0.01f, 3.57e-4f, &exec_env_);
ASSERT_TRUE(status.ok()) << status.message();
// small mean, large variance
status =
MeanStddevNormSeparateBatchesTest(1.0f, 100.0f, 2.63e-4f, &exec_env_);
ASSERT_TRUE(status.ok()) << status.message();
// large mean, zero variance
status = MeanStddevNormSeparateBatchesTest(100.0f, 0.0f, 0.0f, &exec_env_);
ASSERT_TRUE(status.ok()) << status.message();
// large mean, small variance
status =
MeanStddevNormSeparateBatchesTest(100.0f, 1.0f, 2.63e-4f, &exec_env_);
ASSERT_TRUE(status.ok()) << status.message();
// large mean, large variance
status =
MeanStddevNormSeparateBatchesTest(100.0f, 100.0f, 2.63e-4f, &exec_env_);
ASSERT_TRUE(status.ok()) << status.message();
}
TEST_F(OpenCLOperationTest, MeanStddevNormalizationAllBatches) {
auto status = MeanStddevNormalizationAllBatchesTest(&exec_env_);
ASSERT_TRUE(status.ok()) << status.message();
}
TEST_F(OpenCLOperationTest, MeanStddevNormalizationLargeVector) {
auto status = MeanStddevNormalizationLargeVectorTest(&exec_env_);
ASSERT_TRUE(status.ok()) << status.message();
}
} // namespace
} // namespace cl
} // namespace gpu
} // namespace tflite
@@ -0,0 +1,41 @@
/* Copyright 2022 The TensorFlow Authors. All Rights Reserved.
Licensed 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.
==============================================================================*/
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include "tensorflow/lite/delegates/gpu/cl/kernels/cl_test.h"
#include "tensorflow/lite/delegates/gpu/common/operations.h"
#include "tensorflow/lite/delegates/gpu/common/status.h"
#include "tensorflow/lite/delegates/gpu/common/tasks/one_hot_test_util.h"
namespace tflite {
namespace gpu {
namespace cl {
namespace {
TEST_F(OpenCLOperationTest, OneHot) {
auto status = OneHotTest(&exec_env_);
ASSERT_TRUE(status.ok()) << status.message();
}
TEST_F(OpenCLOperationTest, OneHotBatch) {
auto status = OneHotBatchTest(&exec_env_);
ASSERT_TRUE(status.ok()) << status.message();
}
} // namespace
} // namespace cl
} // namespace gpu
} // namespace tflite
@@ -0,0 +1,88 @@
/* Copyright 2019 The TensorFlow Authors. All Rights Reserved.
Licensed 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.
==============================================================================*/
#include <vector>
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include "tensorflow/lite/delegates/gpu/cl/kernels/cl_test.h"
#include "tensorflow/lite/delegates/gpu/common/operations.h"
#include "tensorflow/lite/delegates/gpu/common/status.h"
#include "tensorflow/lite/delegates/gpu/common/tasks/padding_test_util.h"
namespace tflite {
namespace gpu {
namespace cl {
namespace {
TEST_F(OpenCLOperationTest, PaddingAppendWidth) {
auto status = PaddingAppendWidthTest(&exec_env_);
ASSERT_TRUE(status.ok()) << status.message();
}
TEST_F(OpenCLOperationTest, PaddingAppendWidthConstValues) {
auto status = PaddingAppendWidthConstValuesTest(&exec_env_);
ASSERT_TRUE(status.ok()) << status.message();
}
TEST_F(OpenCLOperationTest, PaddingPrependWidth) {
auto status = PaddingPrependWidthTest(&exec_env_);
ASSERT_TRUE(status.ok()) << status.message();
}
TEST_F(OpenCLOperationTest, PaddingAppendHeight) {
auto status = PaddingAppendHeightTest(&exec_env_);
ASSERT_TRUE(status.ok()) << status.message();
}
TEST_F(OpenCLOperationTest, PaddingPrependHeight) {
auto status = PaddingPrependHeightTest(&exec_env_);
ASSERT_TRUE(status.ok()) << status.message();
}
TEST_F(OpenCLOperationTest, PaddingAppendChannels) {
auto status = PaddingAppendChannelsTest(&exec_env_);
ASSERT_TRUE(status.ok()) << status.message();
}
TEST_F(OpenCLOperationTest, PaddingPrependChannels) {
auto status = PaddingPrependChannelsTest(&exec_env_);
ASSERT_TRUE(status.ok()) << status.message();
}
TEST_F(OpenCLOperationTest, PaddingPrependChannelsX4) {
auto status = PaddingPrependChannelsX4Test(&exec_env_);
ASSERT_TRUE(status.ok()) << status.message();
}
TEST_F(OpenCLOperationTest, PaddingComplex) {
auto status = PaddingComplexTest(&exec_env_);
ASSERT_TRUE(status.ok()) << status.message();
}
TEST_F(OpenCLOperationTest, PaddingReflectWidth) {
auto status = PaddingReflectWidthTest(&exec_env_);
ASSERT_TRUE(status.ok()) << status.message();
}
TEST_F(OpenCLOperationTest, PaddingReflectChannels) {
auto status = PaddingReflectChannelsTest(&exec_env_);
ASSERT_TRUE(status.ok()) << status.message();
}
} // namespace
} // namespace cl
} // namespace gpu
} // namespace tflite
@@ -0,0 +1,53 @@
/* Copyright 2019 The TensorFlow Authors. All Rights Reserved.
Licensed 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.
==============================================================================*/
#include <vector>
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include "tensorflow/lite/delegates/gpu/cl/kernels/cl_test.h"
#include "tensorflow/lite/delegates/gpu/common/operations.h"
#include "tensorflow/lite/delegates/gpu/common/status.h"
#include "tensorflow/lite/delegates/gpu/common/tasks/pooling_test_util.h"
namespace tflite {
namespace gpu {
namespace cl {
namespace {
TEST_F(OpenCLOperationTest, AveragePooling) {
auto status = AveragePoolingTest(&exec_env_);
ASSERT_TRUE(status.ok()) << status.message();
}
TEST_F(OpenCLOperationTest, AveragePoolingNonEmptyPadding) {
auto status = AveragePoolingNonEmptyPaddingTest(&exec_env_);
ASSERT_TRUE(status.ok()) << status.message();
}
TEST_F(OpenCLOperationTest, MaxPooling) {
auto status = MaxPoolingTest(&exec_env_);
ASSERT_TRUE(status.ok()) << status.message();
}
TEST_F(OpenCLOperationTest, MaxPoolingIndices) {
auto status = MaxPoolingIndicesTest(&exec_env_);
ASSERT_TRUE(status.ok()) << status.message();
}
} // namespace
} // namespace cl
} // namespace gpu
} // namespace tflite
@@ -0,0 +1,43 @@
/* Copyright 2019 The TensorFlow Authors. All Rights Reserved.
Licensed 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.
==============================================================================*/
#include <vector>
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include "tensorflow/lite/delegates/gpu/cl/kernels/cl_test.h"
#include "tensorflow/lite/delegates/gpu/common/operations.h"
#include "tensorflow/lite/delegates/gpu/common/status.h"
#include "tensorflow/lite/delegates/gpu/common/tasks/prelu_test_util.h"
namespace tflite {
namespace gpu {
namespace cl {
namespace {
TEST_F(OpenCLOperationTest, PReLUAlpha) {
auto status = PReLUAlphaTest(&exec_env_);
ASSERT_TRUE(status.ok()) << status.message();
}
TEST_F(OpenCLOperationTest, PReLUHWCAlpha) {
auto status = PReLUHWCAlphaTest(&exec_env_);
ASSERT_TRUE(status.ok()) << status.message();
}
} // namespace
} // namespace cl
} // namespace gpu
} // namespace tflite
@@ -0,0 +1,53 @@
/* Copyright 2020 The TensorFlow Authors. All Rights Reserved.
Licensed 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.
==============================================================================*/
#include <vector>
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include "tensorflow/lite/delegates/gpu/cl/kernels/cl_test.h"
#include "tensorflow/lite/delegates/gpu/common/operations.h"
#include "tensorflow/lite/delegates/gpu/common/status.h"
#include "tensorflow/lite/delegates/gpu/common/tasks/quantize_and_dequantize_test_util.h"
namespace tflite {
namespace gpu {
namespace cl {
namespace {
TEST_F(OpenCLOperationTest, QuantAndDequant_Dim2Bits8) {
auto status = QuantAndDequant_Dim2Bits8Test(&exec_env_);
ASSERT_TRUE(status.ok()) << status.message();
}
TEST_F(OpenCLOperationTest, QuantAndDequant_Dim3Bits8_NegativeRange) {
auto status = QuantAndDequant_Dim3Bits8_NegativeRangeTest(&exec_env_);
ASSERT_TRUE(status.ok()) << status.message();
}
TEST_F(OpenCLOperationTest, QuantAndDequant_Dim3Bits16) {
auto status = QuantAndDequant_Dim3Bits16Test(&exec_env_);
ASSERT_TRUE(status.ok()) << status.message();
}
TEST_F(OpenCLOperationTest, QuantAndDequant_Dim2Bits16_NegativeRange) {
auto status = QuantAndDequant_Dim2Bits16_NegativeRangeTest(&exec_env_);
ASSERT_TRUE(status.ok()) << status.message();
}
} // namespace
} // namespace cl
} // namespace gpu
} // namespace tflite
@@ -0,0 +1,58 @@
/* Copyright 2020 The TensorFlow Authors. All Rights Reserved.
Licensed 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.
==============================================================================*/
#include <vector>
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include "tensorflow/lite/delegates/gpu/cl/kernels/cl_test.h"
#include "tensorflow/lite/delegates/gpu/common/operations.h"
#include "tensorflow/lite/delegates/gpu/common/status.h"
#include "tensorflow/lite/delegates/gpu/common/tasks/reduce_test_util.h"
namespace tflite {
namespace gpu {
namespace cl {
namespace {
TEST_F(OpenCLOperationTest, MeanHW) {
auto status = MeanHWTest(&exec_env_);
ASSERT_TRUE(status.ok()) << status.message();
}
TEST_F(OpenCLOperationTest, ReduceSumChannels) {
auto status = ReduceSumChannelsTest(&exec_env_);
ASSERT_TRUE(status.ok()) << status.message();
}
TEST_F(OpenCLOperationTest, ReduceProductChannels) {
auto status = ReduceProductChannelsTest(&exec_env_);
ASSERT_TRUE(status.ok()) << status.message();
}
TEST_F(OpenCLOperationTest, ReduceMaxChannels) {
auto status = ReduceMaxChannelsTest(&exec_env_);
ASSERT_TRUE(status.ok()) << status.message();
}
TEST_F(OpenCLOperationTest, ReduceMinChannels) {
auto status = ReduceMinChannelsTest(&exec_env_);
ASSERT_TRUE(status.ok()) << status.message();
}
} // namespace
} // namespace cl
} // namespace gpu
} // namespace tflite
@@ -0,0 +1,71 @@
/* Copyright 2019 The TensorFlow Authors. All Rights Reserved.
Licensed 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.
==============================================================================*/
#include <vector>
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include "tensorflow/lite/delegates/gpu/cl/kernels/cl_test.h"
#include "tensorflow/lite/delegates/gpu/common/operations.h"
#include "tensorflow/lite/delegates/gpu/common/status.h"
#include "tensorflow/lite/delegates/gpu/common/tasks/relu_test_util.h"
namespace tflite {
namespace gpu {
namespace cl {
TEST_F(OpenCLOperationTest, ReLUNoClipNoAlpha) {
auto status = ReLUNoClipNoAlphaTest(&exec_env_);
ASSERT_TRUE(status.ok()) << status.message();
}
TEST_F(OpenCLOperationTest, ReLUClip) {
auto status = ReLUClipTest(&exec_env_);
ASSERT_TRUE(status.ok()) << status.message();
}
TEST_F(OpenCLOperationTest, ReLUAlpha) {
auto status = ReLUAlphaTest(&exec_env_);
ASSERT_TRUE(status.ok()) << status.message();
}
TEST_F(OpenCLOperationTest, ReLUAlphaClip) {
auto status = ReLUAlphaClipTest(&exec_env_);
ASSERT_TRUE(status.ok()) << status.message();
}
TEST_F(OpenCLOperationTest, ReLULN1NoClipNoAlpha) {
auto status = ReLUN1NoClipNoAlphaTest(&exec_env_);
ASSERT_TRUE(status.ok()) << status;
}
TEST_F(OpenCLOperationTest, ReLUN1Clip) {
auto status = ReLUN1ClipTest(&exec_env_);
ASSERT_TRUE(status.ok()) << status;
}
TEST_F(OpenCLOperationTest, ReLULN1Alpha) {
auto status = ReLUN1AlphaTest(&exec_env_);
ASSERT_TRUE(status.ok()) << status;
}
TEST_F(OpenCLOperationTest, ReLUN1AlphaClip) {
auto status = ReLUN1AlphaClipTest(&exec_env_);
ASSERT_TRUE(status.ok()) << status;
}
} // namespace cl
} // namespace gpu
} // namespace tflite
@@ -0,0 +1,42 @@
/* Copyright 2021 The TensorFlow Authors. All Rights Reserved.
Licensed 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.
==============================================================================*/
#include <vector>
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include "tensorflow/lite/delegates/gpu/cl/kernels/cl_test.h"
#include "tensorflow/lite/delegates/gpu/common/operations.h"
#include "tensorflow/lite/delegates/gpu/common/status.h"
#include "tensorflow/lite/delegates/gpu/common/tasks/resampler_test_util.h"
namespace tflite {
namespace gpu {
namespace cl {
TEST_F(OpenCLOperationTest, ResamplerIdentity) {
auto status = ResamplerIdentityTest(BHWC(1, 2, 2, 1), &exec_env_);
ASSERT_TRUE(status.ok()) << status.message();
status = ResamplerIdentityTest(BHWC(1, 3, 5, 3), &exec_env_);
ASSERT_TRUE(status.ok()) << status.message();
status = ResamplerIdentityTest(BHWC(1, 6, 1, 7), &exec_env_);
ASSERT_TRUE(status.ok()) << status.message();
}
} // namespace cl
} // namespace gpu
} // namespace tflite
@@ -0,0 +1,38 @@
/* Copyright 2019 The TensorFlow Authors. All Rights Reserved.
Licensed 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.
==============================================================================*/
#include <vector>
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include "tensorflow/lite/delegates/gpu/cl/kernels/cl_test.h"
#include "tensorflow/lite/delegates/gpu/common/operations.h"
#include "tensorflow/lite/delegates/gpu/common/status.h"
#include "tensorflow/lite/delegates/gpu/common/tasks/reshape_test_util.h"
namespace tflite {
namespace gpu {
namespace cl {
namespace {
TEST_F(OpenCLOperationTest, Reshape) {
auto status = ReshapeTest(&exec_env_);
ASSERT_TRUE(status.ok()) << status.message();
}
} // namespace
} // namespace cl
} // namespace gpu
} // namespace tflite
@@ -0,0 +1,38 @@
/* Copyright 2019 The TensorFlow Authors. All Rights Reserved.
Licensed 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.
==============================================================================*/
#include <vector>
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include "tensorflow/lite/delegates/gpu/cl/kernels/cl_test.h"
#include "tensorflow/lite/delegates/gpu/common/operations.h"
#include "tensorflow/lite/delegates/gpu/common/status.h"
#include "tensorflow/lite/delegates/gpu/common/tasks/reshape_test_util.h"
namespace tflite {
namespace gpu {
namespace cl {
namespace {
TEST_F(OpenCLOperationTest, Reshapex4) {
auto status = Reshapex4Test(&exec_env_);
ASSERT_TRUE(status.ok()) << status.message();
}
} // namespace
} // namespace cl
} // namespace gpu
} // namespace tflite
@@ -0,0 +1,68 @@
/* Copyright 2020 The TensorFlow Authors. All Rights Reserved.
Licensed 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.
==============================================================================*/
#include <vector>
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include "tensorflow/lite/delegates/gpu/cl/kernels/cl_test.h"
#include "tensorflow/lite/delegates/gpu/common/operations.h"
#include "tensorflow/lite/delegates/gpu/common/status.h"
#include "tensorflow/lite/delegates/gpu/common/tasks/resize_test_util.h"
namespace tflite {
namespace gpu {
namespace cl {
namespace {
TEST_F(OpenCLOperationTest, ResizeBilinearAligned) {
auto status = ResizeBilinearAlignedTest(&exec_env_);
ASSERT_TRUE(status.ok()) << status.message();
}
TEST_F(OpenCLOperationTest, ResizeBilinearNonAligned) {
auto status = ResizeBilinearNonAlignedTest(&exec_env_);
ASSERT_TRUE(status.ok()) << status.message();
}
TEST_F(OpenCLOperationTest, ResizeBilinearWithoutHalfPixel) {
auto status = ResizeBilinearWithoutHalfPixelTest(&exec_env_);
ASSERT_TRUE(status.ok()) << status.message();
}
TEST_F(OpenCLOperationTest, ResizeBilinearWithHalfPixel) {
auto status = ResizeBilinearWithHalfPixelTest(&exec_env_);
ASSERT_TRUE(status.ok()) << status.message();
}
TEST_F(OpenCLOperationTest, ResizeNearest) {
auto status = ResizeNearestTest(&exec_env_);
ASSERT_TRUE(status.ok()) << status.message();
}
TEST_F(OpenCLOperationTest, ResizeNearestAlignCorners) {
auto status = ResizeNearestAlignCornersTest(&exec_env_);
ASSERT_TRUE(status.ok()) << status.message();
}
TEST_F(OpenCLOperationTest, ResizeNearestHalfPixelCenters) {
auto status = ResizeNearestHalfPixelCentersTest(&exec_env_);
ASSERT_TRUE(status.ok()) << status.message();
}
} // namespace
} // namespace cl
} // namespace gpu
} // namespace tflite
@@ -0,0 +1,68 @@
/* Copyright 2022 The TensorFlow Authors. All Rights Reserved.
Licensed 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.
==============================================================================*/
#include <gtest/gtest.h>
#include "tensorflow/lite/delegates/gpu/cl/kernels/cl_test.h"
#include "tensorflow/lite/delegates/gpu/common/tasks/select_v2_test_util.h"
namespace tflite {
namespace gpu {
namespace cl {
namespace {
TEST_F(OpenCLOperationTest, SelectV2) {
auto status = SelectV2Test(&exec_env_);
ASSERT_TRUE(status.ok()) << status.message();
}
TEST_F(OpenCLOperationTest, SelectV2Batch) {
auto status = SelectV2BatchTest(&exec_env_);
ASSERT_TRUE(status.ok()) << status.message();
}
TEST_F(OpenCLOperationTest, SelectV2Channels) {
auto status = SelectV2ChannelsTest(&exec_env_);
ASSERT_TRUE(status.ok()) << status.message();
}
TEST_F(OpenCLOperationTest, SelectV2ChannelsBatch) {
auto status = SelectV2ChannelsBatchTest(&exec_env_);
ASSERT_TRUE(status.ok()) << status.message();
}
TEST_F(OpenCLOperationTest, SelectV2BroadcastTrue) {
auto status = SelectV2BroadcastTrueTest(&exec_env_);
ASSERT_TRUE(status.ok()) << status.message();
}
TEST_F(OpenCLOperationTest, SelectV2BroadcastFalse) {
auto status = SelectV2BroadcastFalseTest(&exec_env_);
ASSERT_TRUE(status.ok()) << status.message();
}
TEST_F(OpenCLOperationTest, SelectV2BroadcastBoth) {
auto status = SelectV2BroadcastBothTest(&exec_env_);
ASSERT_TRUE(status.ok()) << status.message();
}
TEST_F(OpenCLOperationTest, SelectV2ChannelsBroadcastFalse) {
auto status = SelectV2ChannelsBroadcastFalseTest(&exec_env_);
ASSERT_TRUE(status.ok()) << status.message();
}
} // namespace
} // namespace cl
} // namespace gpu
} // namespace tflite
@@ -0,0 +1,43 @@
/* Copyright 2019 The TensorFlow Authors. All Rights Reserved.
Licensed 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.
==============================================================================*/
#include <vector>
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include "tensorflow/lite/delegates/gpu/cl/kernels/cl_test.h"
#include "tensorflow/lite/delegates/gpu/common/operations.h"
#include "tensorflow/lite/delegates/gpu/common/status.h"
#include "tensorflow/lite/delegates/gpu/common/tasks/softmax_test_util.h"
namespace tflite {
namespace gpu {
namespace cl {
namespace {
TEST_F(OpenCLOperationTest, Softmax1x1) {
auto status = Softmax1x1Test(&exec_env_);
ASSERT_TRUE(status.ok()) << status.message();
}
TEST_F(OpenCLOperationTest, Softmax1x1BigNumber) {
auto status = Softmax1x1BigNumberTest(&exec_env_);
ASSERT_TRUE(status.ok()) << status.message();
}
} // namespace
} // namespace cl
} // namespace gpu
} // namespace tflite
@@ -0,0 +1,43 @@
/* Copyright 2019 The TensorFlow Authors. All Rights Reserved.
Licensed 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.
==============================================================================*/
#include <vector>
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include "tensorflow/lite/delegates/gpu/cl/kernels/cl_test.h"
#include "tensorflow/lite/delegates/gpu/common/operations.h"
#include "tensorflow/lite/delegates/gpu/common/status.h"
#include "tensorflow/lite/delegates/gpu/common/tasks/softmax_test_util.h"
namespace tflite {
namespace gpu {
namespace cl {
namespace {
TEST_F(OpenCLOperationTest, Softmax) {
auto status = SoftmaxTest(&exec_env_);
ASSERT_TRUE(status.ok()) << status.message();
}
TEST_F(OpenCLOperationTest, SoftmaxBigNumber) {
auto status = SoftmaxBigNumberTest(&exec_env_);
ASSERT_TRUE(status.ok()) << status.message();
}
} // namespace
} // namespace cl
} // namespace gpu
} // namespace tflite
@@ -0,0 +1,53 @@
/* Copyright 2020 The TensorFlow Authors. All Rights Reserved.
Licensed 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.
==============================================================================*/
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include "tensorflow/lite/delegates/gpu/cl/kernels/cl_test.h"
#include "tensorflow/lite/delegates/gpu/common/operations.h"
#include "tensorflow/lite/delegates/gpu/common/status.h"
#include "tensorflow/lite/delegates/gpu/common/tasks/space_to_depth_test_util.h"
namespace tflite {
namespace gpu {
namespace cl {
namespace {
// A known Qualcomm Adreno bug makes the 1 channel test fail on some Adreno
// 5xxs.
TEST_F(OpenCLOperationTest, SpaceToDepthTensorShape1x2x2x1BlockSize2) {
ASSERT_OK(SpaceToDepthTensorShape1x2x2x1BlockSize2Test(&exec_env_));
}
TEST_F(OpenCLOperationTest, SpaceToDepthTensorShape1x2x2x2BlockSize2) {
ASSERT_OK(SpaceToDepthTensorShape1x2x2x2BlockSize2Test(&exec_env_));
}
TEST_F(OpenCLOperationTest, SpaceToDepthTensorShape1x2x2x3BlockSize2) {
ASSERT_OK(SpaceToDepthTensorShape1x2x2x3BlockSize2Test(&exec_env_));
}
TEST_F(OpenCLOperationTest, SpaceToDepthTensorShape1x4x4x1BlockSize2) {
ASSERT_OK(SpaceToDepthTensorShape1x4x4x1BlockSize2Test(&exec_env_));
}
TEST_F(OpenCLOperationTest, SpaceToDepthTensorShape1x6x6x1BlockSize3) {
ASSERT_OK(SpaceToDepthTensorShape1x6x6x1BlockSize3Test(&exec_env_));
}
} // namespace
} // namespace cl
} // namespace gpu
} // namespace tflite
@@ -0,0 +1,61 @@
/* Copyright 2021 The TensorFlow Authors. All Rights Reserved.
Licensed 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.
==============================================================================*/
#include <vector>
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include "tensorflow/lite/delegates/gpu/cl/kernels/cl_test.h"
#include "tensorflow/lite/delegates/gpu/common/operations.h"
#include "tensorflow/lite/delegates/gpu/common/status.h"
#include "tensorflow/lite/delegates/gpu/common/tasks/split_test_util.h"
namespace tflite {
namespace gpu {
namespace cl {
TEST_F(OpenCLOperationTest, SplitChannels) {
auto status = SplitChannelsTest(&exec_env_);
ASSERT_TRUE(status.ok()) << status.message();
}
TEST_F(OpenCLOperationTest, SplitChannelsX4) {
auto status = SplitChannelsX4Test(&exec_env_);
ASSERT_TRUE(status.ok()) << status.message();
}
TEST_F(OpenCLOperationTest, SplitWidth) {
auto status = SplitWidthTest(&exec_env_);
ASSERT_TRUE(status.ok()) << status.message();
}
TEST_F(OpenCLOperationTest, SplitHeight) {
auto status = SplitHeightTest(&exec_env_);
ASSERT_TRUE(status.ok()) << status.message();
}
TEST_F(OpenCLOperationTest, SplitBatch) {
auto status = SplitBatchTest(&exec_env_);
ASSERT_TRUE(status.ok()) << status.message();
}
TEST_F(OpenCLOperationTest, SplitDepth) {
auto status = SplitDepthTest(&exec_env_);
ASSERT_TRUE(status.ok()) << status.message();
}
} // namespace cl
} // namespace gpu
} // namespace tflite
@@ -0,0 +1,38 @@
/* Copyright 2019 The TensorFlow Authors. All Rights Reserved.
Licensed 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.
==============================================================================*/
#include <vector>
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include "tensorflow/lite/delegates/gpu/cl/kernels/cl_test.h"
#include "tensorflow/lite/delegates/gpu/common/operations.h"
#include "tensorflow/lite/delegates/gpu/common/status.h"
#include "tensorflow/lite/delegates/gpu/common/tasks/strided_slice_test_util.h"
namespace tflite {
namespace gpu {
namespace cl {
namespace {
TEST_F(OpenCLOperationTest, StridedSlice) {
auto status = StridedSliceTest(&exec_env_);
ASSERT_TRUE(status.ok()) << status.message();
}
} // namespace
} // namespace cl
} // namespace gpu
} // namespace tflite
@@ -0,0 +1,54 @@
/* Copyright 2021 The TensorFlow Authors. All Rights Reserved.
Licensed 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.
==============================================================================*/
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include "tensorflow/lite/delegates/gpu/cl/kernels/cl_test.h"
#include "tensorflow/lite/delegates/gpu/common/operations.h"
#include "tensorflow/lite/delegates/gpu/common/status.h"
#include "tensorflow/lite/delegates/gpu/common/tasks/tile_test_util.h"
namespace tflite {
namespace gpu {
namespace cl {
TEST_F(OpenCLOperationTest, TileChannels) {
auto status = TileChannelsTest(&exec_env_);
ASSERT_TRUE(status.ok()) << status.message();
}
TEST_F(OpenCLOperationTest, TileChannelsX4) {
auto status = TileChannelsX4Test(&exec_env_);
ASSERT_TRUE(status.ok()) << status.message();
}
TEST_F(OpenCLOperationTest, TileWidth) {
auto status = TileWidthTest(&exec_env_);
ASSERT_TRUE(status.ok()) << status.message();
}
TEST_F(OpenCLOperationTest, TileHeight) {
auto status = TileHeightTest(&exec_env_);
ASSERT_TRUE(status.ok()) << status.message();
}
TEST_F(OpenCLOperationTest, TileHWC) {
auto status = TileHWCTest(&exec_env_);
ASSERT_TRUE(status.ok()) << status.message();
}
} // namespace cl
} // namespace gpu
} // namespace tflite
@@ -0,0 +1,38 @@
/* Copyright 2019 The TensorFlow Authors. All Rights Reserved.
Licensed 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.
==============================================================================*/
#include <vector>
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include "tensorflow/lite/delegates/gpu/cl/kernels/cl_test.h"
#include "tensorflow/lite/delegates/gpu/common/operations.h"
#include "tensorflow/lite/delegates/gpu/common/status.h"
#include "tensorflow/lite/delegates/gpu/common/tasks/transpose_test_util.h"
namespace tflite {
namespace gpu {
namespace cl {
namespace {
TEST_F(OpenCLOperationTest, Transpose) {
auto status = TransposeTest(&exec_env_);
ASSERT_TRUE(status.ok()) << status.message();
}
} // namespace
} // namespace cl
} // namespace gpu
} // namespace tflite
@@ -0,0 +1,54 @@
/* Copyright 2020 The TensorFlow Authors. All Rights Reserved.
Licensed 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.
==============================================================================*/
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include "tensorflow/lite/delegates/gpu/cl/kernels/cl_test.h"
#include "tensorflow/lite/delegates/gpu/common/operations.h"
#include "tensorflow/lite/delegates/gpu/common/status.h"
#include "tensorflow/lite/delegates/gpu/common/tasks/winograd_test_util.h"
namespace tflite {
namespace gpu {
namespace cl {
TEST_F(OpenCLOperationTest, Winograd4x4To36TileX6) {
auto status = Winograd4x4To36TileX6Test(&exec_env_);
ASSERT_TRUE(status.ok()) << status.message();
}
TEST_F(OpenCLOperationTest, Winograd36To4x4Tile4x1) {
auto status = Winograd36To4x4Tile4x1Test(&exec_env_);
ASSERT_TRUE(status.ok()) << status.message();
}
TEST_F(OpenCLOperationTest, Winograd4x4To36) {
auto status = Winograd4x4To36Test(&exec_env_);
ASSERT_TRUE(status.ok()) << status.message();
}
TEST_F(OpenCLOperationTest, Winograd4x4To36Batch) {
auto status = Winograd4x4To36BatchTest(&exec_env_);
ASSERT_TRUE(status.ok()) << status.message();
}
TEST_F(OpenCLOperationTest, Winograd36To4x4) {
auto status = Winograd36To4x4Test(&exec_env_);
ASSERT_TRUE(status.ok()) << status.message();
}
} // namespace cl
} // namespace gpu
} // namespace tflite