1 /* Copyright 2019 The TensorFlow Authors. All Rights Reserved. 2 3 Licensed under the Apache License, Version 2.0 (the "License"); 4 you may not use this file except in compliance with the License. 5 You may obtain a copy of the License at 6 7 http://www.apache.org/licenses/LICENSE-2.0 8 9 Unless required by applicable law or agreed to in writing, software 10 distributed under the License is distributed on an "AS IS" BASIS, 11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 See the License for the specific language governing permissions and 13 limitations under the License. 14 ==============================================================================*/ 15 16 #ifndef TENSORFLOW_LITE_DELEGATES_GPU_CL_KERNELS_CL_TEST_H_ 17 #define TENSORFLOW_LITE_DELEGATES_GPU_CL_KERNELS_CL_TEST_H_ 18 19 #include <memory> 20 #include <vector> 21 22 #include <gmock/gmock.h> 23 #include <gtest/gtest.h> 24 #include "tensorflow/lite/delegates/gpu/cl/environment.h" 25 #include "tensorflow/lite/delegates/gpu/cl/opencl_wrapper.h" 26 #include "tensorflow/lite/delegates/gpu/common/status.h" 27 #include "tensorflow/lite/delegates/gpu/common/task/testing_util.h" 28 29 namespace tflite { 30 namespace gpu { 31 namespace cl { 32 33 class ClExecutionEnvironment : public TestExecutionEnvironment { 34 public: 35 ClExecutionEnvironment() = default; 36 ~ClExecutionEnvironment() override = default; 37 38 absl::Status Init(); 39 40 std::vector<CalculationsPrecision> GetSupportedPrecisions() const override; 41 std::vector<TensorStorageType> GetSupportedStorages( 42 DataType data_type) const override; 43 44 const GpuInfo& GetGpuInfo() const override; 45 46 absl::Status ExecuteGpuOperationInternal( 47 const std::vector<TensorDescriptor*>& src_cpu, 48 const std::vector<TensorDescriptor*>& dst_cpu, 49 std::unique_ptr<GPUOperation>&& operation) override; 50 51 absl::Status ExecuteGPUOperation( 52 const std::vector<Tensor5DFloat32>& src_cpu, 53 std::unique_ptr<GPUOperation>&& operation, 54 const std::vector<BHWDC>& dst_sizes, 55 const std::vector<Tensor5DFloat32*>& dst_cpu) override; 56 57 private: 58 Environment env_; 59 }; 60 61 class OpenCLOperationTest : public ::testing::Test { 62 public: SetUp()63 void SetUp() override { 64 ASSERT_OK(LoadOpenCL()); 65 ASSERT_OK(exec_env_.Init()); 66 } 67 68 protected: 69 ClExecutionEnvironment exec_env_; 70 }; 71 } // namespace cl 72 } // namespace gpu 73 } // namespace tflite 74 75 #endif // TENSORFLOW_LITE_DELEGATES_GPU_CL_KERNELS_CL_TEST_H_ 76