Added tests for Texture2D.

PiperOrigin-RevId: 275110447
Change-Id: Ifc4bb2d99acde0cca56f1a770e7e8024a0e80939
This commit is contained in:
A. Unique TensorFlower 2019-10-16 14:11:27 -07:00 committed by TensorFlower Gardener
parent d722fffc7b
commit 7874c7034c
2 changed files with 77 additions and 0 deletions

View File

@ -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( cc_library(
name = "tensor", name = "tensor",
srcs = ["tensor.cc"], srcs = ["tensor.cc"],

View File

@ -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 <vector>
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#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<float> 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<float> gpu_data;
ASSERT_OK(texture.ReadData<float>(env_.queue(), &gpu_data));
EXPECT_THAT(gpu_data, Pointwise(FloatNear(0.0f), data));
}
TEST_F(OpenCLTest, Texture2DTestHalf) {
const std::vector<half> 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<half> gpu_data;
ASSERT_OK(texture.ReadData<half>(env_.queue(), &gpu_data));
EXPECT_THAT(gpu_data, Pointwise(FloatNear(0.0f), data));
}
} // namespace
} // namespace cl
} // namespace gpu
} // namespace tflite