
    x-j	                         d dl Z d dlmZmZmZmZmZmZmZm	Z	 d Z
 e            s e            s e
            s
 e	            r
d dlmZ d ZndZd Zd Zg dZd Z G d	 d
          ZdS )    N)	CUDAPlaceCustomPlaceXPUPlaceget_all_custom_device_typeis_compiled_with_cudais_compiled_with_custom_deviceis_compiled_with_rocmis_compiled_with_xpuc                  V    d} t                      }|D ]}t          |          rd}  n| S )NFT)r   r   )custom_device_flagcustom_devices_typesdevice_types      Y/var/www/html/banglarbhumi/venv/lib/python3.11/site-packages/paddle/device/cuda/graphs.py!check_compiled_with_custom_devicer      sK    577+  )+66 	!%E	     )	CUDAGraphc                      dS )NT r   r   r   is_cuda_graph_supportedr   /   s    tr   c                      dS )NFr   r   r   r   r   r   4   s    ur   c                      t                      D ]T} t          j        d|  dd                              d          }t	          |d                   }t          | |          c S d S )NFLAGS_selected_s0,r   )r   osgetenvsplitintr   )deviceselected_devices	device_ids      r   current_expected_placer#   8   sx    ,.. . .9%@v%@%@%@#FFLL
 
 (+,,	69-----4r   )globalthread_localrelaxedc                   6    e Zd Zd	dZd Zd Zd Zd Zd
dZdS )r   Nr%   c                 2   t           
J d            d | _        |t                      rt                      }n|t	                      r=t          t          j                            dd                    }t          |          }nZt                      r=t          t          j                            dd                    }t          |          }nt          d          || _        |t          v sJ t                              |          | _        || _        d S )NzFCUDA Graph is only supported on PaddlePaddle compiled with NVIDIA GPU.FLAGS_selected_gpusr   FLAGS_selected_xpuszNot Supported devices)CoreCUDAGraph_graphr   r#   r   r   r   environgetr   r
   r   RuntimeError_place	ALL_MODESindex_mode_pool_id)selfplacemodepool_idr"   s        r   __init__zCUDAGraph.__init__G   s    ((T )(( =>@@=*,,EE]$&& <
/Da H HII	!),,%'' <
/Da H HII	 ++"#:;;;y    __T**
r   c                 P    t          j        | j        | j        | j                   d S N)r+   begin_capture_with_pool_idr0   r3   r4   r5   s    r   capture_beginzCUDAGraph.capture_begin^   s.    0KT]	
 	
 	
 	
 	
r   c                 6    t          j                    | _        d S r;   )r+   end_capturer,   r=   s    r   capture_endzCUDAGraph.capture_endc   s    #/11r   c                 8    | j                                          d S r;   )r,   replayr=   s    r   rC   zCUDAGraph.replayf   s    r   c                 8    | j                                          d S r;   )r,   resetr=   s    r   rE   zCUDAGraph.reseti   s    r   c                    t          |t          t          f          s|j        }t	          j        |d           t          j                            |          sJ d| d            |d}| j        	                    ||           d S )NT)nameexist_okzThe dirname z should be a directoryi  )

isinstancestrbytesrG   r   makedirspathisdirr,   print_to_dot_files)r5   dirnameflagss      r   rO   zCUDAGraph.print_to_dot_filesl   s    'C<00 	#lG
40000w}}W%% 	
 	
:7:::	
 	
% =E&&w66666r   )Nr%   Nr;   )	__name__
__module____qualname__r9   r>   rA   rC   rE   rO   r   r   r   r   r   F   sx               .
 
 

2 2 2    	7 	7 	7 	7 	7 	7r   r   )r   paddle.base.corer   r   r   r   r   r   r	   r
   r   r   r+   r   r#   r1   cuda_graph_idr   r   r   <module>rW      s^   
				 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	    )(** 	 <;;;;;    M     211	/7 /7 /7 /7 /7 /7 /7 /7 /7 /7r   