tensorflow/compiler/tf2xla/tf2xla_util_test.cc
// Tests that CachedFunctionHandles class works.
Tests that CachedFunctionHandles class works.
Tests that CachedFunctionHandles class works .
TEST(CachedFunctionHandles, Basic) {
  FunctionDef func = FunctionDefHelper::Define(
      "TestFunc",
      {},
      {"y:T"},
      {"T:{float, double, int32, int64}"},
      {
          {{"y"}, "One", {}, {{"T", "$T"}}},
      });
  FunctionDefLibrary proto;
  *proto.add_function() = func;
  FunctionLibraryDefinition fld(OpRegistry::Global(), proto);
  std::unique_ptr<ProcessFunctionLibraryRuntime> pflr(
      new ProcessFunctionLibraryRuntime(
          nullptr, Env::Default(), nullptr,
          TF_GRAPH_DEF_VERSION, &fld, OptimizerOptions()));
  FunctionLibraryRuntime* flr =
      pflr->GetFLR(ProcessFunctionLibraryRuntime::kDefaultFLRDevice);
  CachedFunctionHandles cached_function_handles(flr);
  FunctionLibraryRuntime::Handle first_handle;
  AttrValue attr;
  attr.set_type(DT_FLOAT);
  AttrValueMap attrs;
  attrs["T"] = attr;
  TF_ASSERT_OK(cached_function_handles.GetOrInstantiate(
      "TestFunc", AttrSlice(&attrs), &first_handle));
  const FunctionBody* body = flr->GetFunctionBody(first_handle);
  EXPECT_NE(body, nullptr);
  FunctionLibraryRuntime::Handle second_handle;
  TF_ASSERT_OK(cached_function_handles.GetOrInstantiate(
      "TestFunc", AttrSlice(&attrs), &second_handle));
  EXPECT_EQ(first_handle, second_handle);
  attr.set_type(DT_INT32);
  attrs["T"] = attr;
  FunctionLibraryRuntime::Handle third_handle;
  TF_ASSERT_OK(cached_function_handles.GetOrInstantiate(
      "TestFunc", AttrSlice(&attrs), &third_handle));
  EXPECT_NE(first_handle, third_handle);
  TF_EXPECT_OK(cached_function_handles.ReleaseAllHandles());
}
TEST ( CachedFunctionHandles , Basic ) { FunctionDef func = FunctionDefHelper :: Define ( " " , { } , { " " } , { " " } , { { { " " } , " " , { } , { { " " , " " } } } , } ) ; FunctionDefLibrary proto ; * proto . add_function ( ) = func ; FunctionLibraryDefinition fld ( OpRegistry :: Global ( ) , proto ) ; std :: unique_ptr < ProcessFunctionLibraryRuntime > pflr ( new ProcessFunctionLibraryRuntime ( nullptr , Env :: Default ( ) , nullptr , TF_GRAPH_DEF_VERSION , & fld , OptimizerOptions ( ) ) ) ; FunctionLibraryRuntime * flr = pflr -> GetFLR ( ProcessFunctionLibraryRuntime :: kDefaultFLRDevice ) ; CachedFunctionHandles cached_function_handles ( flr ) ; FunctionLibraryRuntime :: Handle first_handle ; AttrValue attr ; attr . set_type ( DT_FLOAT ) ; AttrValueMap attrs ; attrs [ " " ] = attr ; TF_ASSERT_OK ( cached_function_handles . GetOrInstantiate ( " " , AttrSlice ( & attrs ) , & first_handle ) ) ; const FunctionBody * body = flr -> GetFunctionBody ( first_handle ) ; EXPECT_NE ( body , nullptr ) ; FunctionLibraryRuntime :: Handle second_handle ; TF_ASSERT_OK ( cached_function_handles . GetOrInstantiate ( " " , AttrSlice ( & attrs ) , & second_handle ) ) ; EXPECT_EQ ( first_handle , second_handle ) ; attr . set_type ( DT_INT32 ) ; attrs [ " " ] = attr ; FunctionLibraryRuntime :: Handle third_handle ; TF_ASSERT_OK ( cached_function_handles . GetOrInstantiate ( " " , AttrSlice ( & attrs ) , & third_handle ) ) ; EXPECT_NE ( first_handle , third_handle ) ; TF_EXPECT_OK ( cached_function_handles . ReleaseAllHandles ( ) ) ; }
Tests that CachedFunctionHandles class works.
Tests that CachedFunctionHandles class works .
// Name // Args // Return values // Attr def // Nodes /*device_mgr=*/ /*config=*/ // Tests that GetOrInstantiate() works. // Tests that we can get FunctionBody. // Tests that GetOrInstantiate() returns cached handle when called with same // function name and attributes. // Tests that GetOrInstantiate() returns new handle when called with same // function name but different attributes. // Tests that ReleaseAllHandles() works.