MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / FunctionLibraryDefinition

Class FunctionLibraryDefinition

tensorflow/core/framework/function.h:314–505  ·  view source on GitHub ↗

Helper to maintain a map between function names in a given FunctionDefLibrary and function definitions. This class is thread-safe.

Source from the content-addressed store, hash-verified

312//
313// This class is thread-safe.
314class FunctionLibraryDefinition : public OpRegistryInterface {
315 public:
316 // Ops created for function arguments bear the name given by `kArgOp`; those
317 // created for return values bear the name given by `kRetOp`.
318 static constexpr const char* const kArgOp = "_Arg";
319 static constexpr const char* const kDeviceArgOp = "_DeviceArg";
320 static constexpr const char* const kRetOp = "_Retval";
321 static constexpr const char* const kDeviceRetOp = "_DeviceRetval";
322 static constexpr const char* const kIntsOnDeviceAttr =
323 "experimental_ints_on_device";
324
325 static constexpr const char* const kGradientOp = "SymbolicGradient";
326 static constexpr const char* const kFuncAttr = "f";
327
328 // Note: This constructor grabs `lib_def`'s lock in shared mode.
329 FunctionLibraryDefinition(const FunctionLibraryDefinition& lib_def);
330 FunctionLibraryDefinition(const OpRegistryInterface* default_registry,
331 const FunctionDefLibrary& lib_def);
332 ~FunctionLibraryDefinition() override;
333
334 FunctionLibraryDefinition& operator=(const FunctionLibraryDefinition&) =
335 delete;
336
337 // Returns True if the library contains `func`, False otherwise.
338 bool Contains(const string& func) const;
339
340 // Returns nullptr if "func" is not defined in "lib_def". Otherwise,
341 // returns its definition proto.
342 //
343 // NB: This function returns a borrowed pointer, which can be invalidated by a
344 // subsequent call to `ReplaceFunction()` with the given name.
345 const FunctionDef* Find(const string& func) const LOCKS_EXCLUDED(mu_);
346
347 // Adds function definition 'fdef' to this function library.
348 // Returns status 'ok' on success, or error otherwise. This is a no-op if
349 // 'fdef' already exists in this function library.
350 // If 'fdef' is successfully added to the library, it will be accessible
351 // from 'LookUp' and included in the proto returned by 'ToProto'.
352 // This operation is atomic.
353 Status AddFunctionDef(const FunctionDef& fdef) LOCKS_EXCLUDED(mu_);
354
355 // Adds gradient definition 'grad' to this function library.
356 // This is a no-op if 'grad' already exists in this function library.
357 // If 'grad' is successfully added, it will be accessible via 'FindGradient'
358 // and included in the proto returned by 'ToProto'.
359 // This operation is atomic.
360 Status AddGradientDef(const GradientDef& grad) LOCKS_EXCLUDED(mu_);
361
362 // Replaces the function corresponding to `func` with `fdef`. Returns
363 // a non-OK status if "func" was not found in the library, OK otherwise.
364 // Please be careful when replacing function: make sure all previous pointers
365 // returned by `Find()` are no longer in use.
366 Status ReplaceFunction(const string& func, const FunctionDef& fdef)
367 LOCKS_EXCLUDED(mu_);
368
369 // Replaces the gradient corresponding to `grad.function_name()`. Returns
370 // a non-OK status if "grad.function_name()" was not found in the library, OK
371 // otherwise.

Callers 4

InlineFunctionCallsFunction · 0.85
OptimizeMethod · 0.85
TEST_FFunction · 0.85

Calls

no outgoing calls

Tested by 1

TEST_FFunction · 0.68