1 /* Copyright 2017 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 // This demonstrates how to use hlo_test_base to create a file based testcase 17 // and compare results on gpu and cpu. 18 19 #include <string> 20 #include <vector> 21 22 #include "tensorflow/compiler/xla/service/platform_util.h" 23 #include "tensorflow/compiler/xla/test.h" 24 #include "tensorflow/compiler/xla/tests/hlo_test_base.h" 25 #include "tensorflow/compiler/xla/tests/literal_test_util.h" 26 #include "tensorflow/compiler/xla/types.h" 27 #include "tensorflow/core/lib/io/path.h" 28 #include "tensorflow/core/platform/test.h" 29 #include "tensorflow/core/platform/types.h" 30 31 namespace xla { 32 namespace { 33 34 class SampleFileTest : public HloTestBase { 35 protected: 36 SampleFileTest() 37 : HloTestBase( 38 /*test_platform=*/PlatformUtil::GetPlatform("gpu").ValueOrDie(), 39 /*reference_platform=*/PlatformUtil::GetPlatform("cpu") 40 .ValueOrDie()) {} 41 }; 42 43 TEST_F(SampleFileTest, Convolution) { 44 const string& filename = "compiler/xla/tests/isolated_convolution.hlo"; 45 string test_srcdir = tensorflow::testing::TensorFlowSrcRoot(); 46 EXPECT_TRUE(RunAndCompareFromFile( 47 tensorflow::io::JoinPath(test_srcdir, filename), ErrorSpec{0.01})); 48 } 49 50 } // namespace 51 } // namespace xla 52