From 7874c7034cee69c5dd95a4674c0fc3ec822dfac7 Mon Sep 17 00:00:00 2001 From: "A. Unique TensorFlower" Date: Wed, 16 Oct 2019 14:11:27 -0700 Subject: [PATCH] Added tests for Texture2D. PiperOrigin-RevId: 275110447 Change-Id: Ifc4bb2d99acde0cca56f1a770e7e8024a0e80939 --- tensorflow/lite/delegates/gpu/cl/BUILD | 16 +++++ .../lite/delegates/gpu/cl/texture2d_test.cc | 61 +++++++++++++++++++ 2 files changed, 77 insertions(+) create mode 100644 tensorflow/lite/delegates/gpu/cl/texture2d_test.cc diff --git a/tensorflow/lite/delegates/gpu/cl/BUILD b/tensorflow/lite/delegates/gpu/cl/BUILD index d9ef111cb99..59790d156a5 100644 --- a/tensorflow/lite/delegates/gpu/cl/BUILD +++ b/tensorflow/lite/delegates/gpu/cl/BUILD @@ -261,6 +261,22 @@ cc_library( ], ) +cc_test( + name = "texture2d_test", + srcs = ["texture2d_test.cc"], + linkstatic = True, + tags = [ + "linux", + "local", + ], + deps = [ + ":cl_test", + ":texture2d", + "//tensorflow/lite/delegates/gpu/common:status", + "@com_google_googletest//:gtest_main", + ], +) + cc_library( name = "tensor", srcs = ["tensor.cc"], diff --git a/tensorflow/lite/delegates/gpu/cl/texture2d_test.cc b/tensorflow/lite/delegates/gpu/cl/texture2d_test.cc new file mode 100644 index 00000000000..fc6abc90eeb --- /dev/null +++ b/tensorflow/lite/delegates/gpu/cl/texture2d_test.cc @@ -0,0 +1,61 @@ +/* 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/texture2d.h" + +#include + +#include +#include +#include "tensorflow/lite/delegates/gpu/cl/cl_test.h" +#include "tensorflow/lite/delegates/gpu/common/status.h" + +using ::testing::FloatNear; +using ::testing::Pointwise; + +namespace tflite { +namespace gpu { +namespace cl { +namespace { + +TEST_F(OpenCLTest, Texture2DTestFloat) { + const std::vector data = {1.0, 2.0, 3.0, -4.0, 5.1, 6.7, 4.1, 6.17}; + Texture2D texture; + ASSERT_OK(CreateTexture2DRGBA32F(1, 2, &env_.context(), &texture)); + ASSERT_OK(texture.WriteData(env_.queue(), + absl::MakeConstSpan(data.data(), data.size()))); + std::vector gpu_data; + ASSERT_OK(texture.ReadData(env_.queue(), &gpu_data)); + + EXPECT_THAT(gpu_data, Pointwise(FloatNear(0.0f), data)); +} + +TEST_F(OpenCLTest, Texture2DTestHalf) { + const std::vector data = {half(1.4), half(2.1), half(2.2), half(1.34), + half(20.1), half(2.24), half(0.1), half(0.2)}; + Texture2D texture; + ASSERT_OK(CreateTexture2DRGBA16F(2, 1, &env_.context(), &texture)); + ASSERT_OK(texture.WriteData(env_.queue(), + absl::MakeConstSpan(data.data(), data.size()))); + std::vector gpu_data; + ASSERT_OK(texture.ReadData(env_.queue(), &gpu_data)); + + EXPECT_THAT(gpu_data, Pointwise(FloatNear(0.0f), data)); +} + +} // namespace +} // namespace cl +} // namespace gpu +} // namespace tflite