Exemple #1
0
def sync():
    """Synchronize the contents of the Python registry with C++."""
    with _sync_lock:
        p_buffer = c_api.TF_GetAllOpList()
        cpp_op_list = op_def_pb2.OpList()
        cpp_op_list.ParseFromString(c_api.TF_GetBuffer(p_buffer))
        register_op_list(cpp_op_list)
Exemple #2
0
    def __init__(self):
        op_def_proto = op_def_pb2.OpList()
        buf = c_api.TF_GetAllOpList()
        try:
            op_def_proto.ParseFromString(c_api.TF_GetBuffer(buf))
            self._api_def_map = c_api.TF_NewApiDefMap(buf)
        finally:
            c_api.TF_DeleteBuffer(buf)

        self._op_per_name = {}
        for op in op_def_proto.op:
            self._op_per_name[op.name] = op
Exemple #3
0
  def sync():
    p_buffer = c_api.TF_GetAllOpList()
    cpp_op_list = op_def_pb2.OpList()
    cpp_op_list.ParseFromString(c_api.TF_GetBuffer(p_buffer))

    registered_ops = op_def_registry.get_registered_ops()
    for op_def in cpp_op_list.op:
      # If an OpList is registered from a gen_*_ops.py, it does not any
      # descriptions. Strip them here as well to satisfy validation in
      # register_op_list.
      _remove_non_deprecated_descriptions(op_def)
      registered_ops[op_def.name] = op_def
Exemple #4
0
def sync():
  """Synchronize the contents of the Python registry with C++."""
  with _sync_lock:
    p_buffer = c_api.TF_GetAllOpList()
    cpp_op_list = op_def_pb2.OpList()
    cpp_op_list.ParseFromString(c_api.TF_GetBuffer(p_buffer))
    for op_def in cpp_op_list.op:
      # If an OpList is registered from a gen_*_ops.py, it does not any
      # descriptions. Strip them here as well to satisfy validation in
      # register_op_list.
      _remove_non_deprecated_descriptions(op_def)
      _registered_ops[op_def.name] = op_def
Exemple #5
0
def register_ops_if_needed(graph_ops):
    """Register graph ops absent in op_def_registry, if present in c++ registry.

  Args:
    graph_ops: set with graph op names to register.

  Raises:
    RuntimeError: if `graph_ops` contains ops that are not in either python or
      c++ registry.
  """
    missing_ops = graph_ops - set(op_def_registry.get_registered_ops().keys())

    if not missing_ops:
        return

    p_buffer = c_api.TF_GetAllOpList()
    cpp_op_list = op_def_pb2.OpList()
    cpp_op_list.ParseFromString(c_api.TF_GetBuffer(p_buffer))
    cpp_registry_ops = {op.name: op for op in cpp_op_list.op}

    missing_op_list = op_def_pb2.OpList()
    for missing_op in missing_ops:
        if missing_op not in cpp_registry_ops:
            tf.logging.info(
                "Op %s is missing from both the python and C++ registry.",
                missing_op)
        else:
            missing_op_list.op.extend([cpp_registry_ops[missing_op]])
            tf.logging.info(
                "Adding op %s from c++ registry to python registry.",
                missing_op)

    op_def_registry.register_op_list(missing_op_list)

    # Note: Only raise missing op ValueError after trying to load ops.
    # This allows the test to exercise all the calls into TensorFlow
    # without having to write a C + python test.
    if not missing_ops <= set(cpp_registry_ops.keys()):
        raise RuntimeError(
            "Graph ops missing from the python registry (%s) are also absent from "
            "the c++ registry." %
            missing_ops.difference(set(cpp_registry_ops.keys())))