
    BVh
                         d Z ddlZddlmZ ddlmZ ddlmZ ddlm	Z
  G d de      Zej                  	 	 	 	 d
d	       Zy)z)A python interface for Grappler clusters.    N)step_stats_pb2)op_performance_data_pb2)device_properties_pb2)_pywrap_tf_clusterc                   `    e Zd ZdZ	 	 	 	 ddZd Zd Zed        Zd Z	d Z
d	 Zd
 Zd Zd Zy)ClusterzGrappler Clusters.Nc                     d| _         | | _        |t        j                  ||      | _         y|D cg c]  }|j	                          }}t        j
                  |      | _         yc c}w )a  Creates a Cluster.

    Args:
      allow_soft_placement: If True, TF will automatically fix illegal
        placements instead of erroring out if the placement isn't legal.
      disable_detailed_stats: If True, detailed statistics will not be
        available.
      disable_timeline: If True, the timeline information will not be reported.
      devices: A list of devices of type device_properties_pb2.NamedDevice.
        If None, a device list will be created based on the spec of
        the local machine.
    N)_tf_cluster_generate_timeline
tf_clusterTF_NewClusterSerializeToStringTF_NewVirtualCluster)selfallow_soft_placementdisable_detailed_statsdisable_timelinedevicesdevicedevices_serializeds          R/home/dcms/DCMS/lib/python3.12/site-packages/tensorflow/python/grappler/cluster.py__init__zCluster.__init__   sq    " D"22D#112F2HJd FMM6F446MM#889KLd Ns   A&c                 j    | j                   't        j                  | j                          d | _         y y N)r
   r   TF_ShutdownClusterr   s    r   ShutdownzCluster.Shutdown7   s/    ###D$4$45d $    c                 $    | j                          y r   )r   r   s    r   __del__zCluster.__del__<   s    MMOr   c                     | j                   S r   )r
   r   s    r   r   zCluster.tf_cluster?   s    r   c                     | j                   g S t        j                  | j                         D cg c]!  }t        j                  j                  |      # c}S c c}w )z-Returns a list of available hardware devices.)r
   r   TF_ListDevicesr   NamedDevice
FromStringr   r   s     r   ListDeviceszCluster.ListDevicesC   sY    i$33D4D4DEG "--88@ G G Gs   &Ac                 *    t        j                         S )zCReturns a list of all available operations (sorted alphabetically).)r   TF_ListAvailableOpsr   s    r   ListAvailableOpszCluster.ListAvailableOpsJ   s    ))++r   c                 V    t        j                  | j                  |j                        S r   )r   TF_GetSupportedDevicesr
   tf_itemr   items     r   GetSupportedDeviceszCluster.GetSupportedDevicesN   s    ,,T-=-=t||LLr   c                 H    t        j                  |j                               S r   )r   TF_EstimatePerformancer   r&   s     r   EstimatePerformancezCluster.EstimatePerformanceQ   s    ,,V-E-E-GHHr   c                    t        j                  |j                  | j                  | j                        \  }}}|D cg c]!  }t
        j                  j                  |      # }}||t        j                  j                  |      fS c c}w )zReturns the cost of running the specified item.

    Args:
      item: The item for which to measure the costs.
    Returns: The triplet op_perfs, runtime, step_stats.
    )
r   TF_MeasureCostsr-   r
   r   r   OpPerformancer%   r   	StepStats)r   r/   op_perf_bytes_listrun_timestep_stats_bytesop_perf_bytesop_perfss          r   MeasureCostszCluster.MeasureCostsT   s     6@5O5Od&&(?(?6A2"2 &89! (55@@O 9H 9h$$//0@AC C9s   &Bc                 V    t        j                  |j                  | j                        S )zReturns a snapshot of the peak memory usage.

    Args:
      item: The item for which to measure the costs.
    Returns: A hashtable indexed by device name.
    )r   TF_DeterminePeakMemoryUsager-   r
   r.   s     r   DeterminePeakMemoryUsagez Cluster.DeterminePeakMemoryUsagec   s(     11$,,262B2BD Dr   TTTN)__name__
__module____qualname____doc__r   r   r    propertyr   r'   r*   r0   r3   r=   r@    r   r   r   r      sZ     %)&* $	M6
  G,MICDr   r   c              #   P   K   t        | |||      }| |j                          y wr   )r   r   )r   r   r   r   clusters        r   	ProvisionrJ   n   s.     
 (*@$g/'-	s   $&rA   )rE   
contextlibtensorflow.core.frameworkr   tensorflow.core.grappler.costsr   tensorflow.core.protobufr   tensorflow.python.grapplerr   r   objectr   contextmanagerrJ   rG   r   r   <module>rR      sP    0  4 B : GRDf RDj #'%)# r   