
    )`i                         d Z ddlZddlZddlZddlmZ ddlmZ ddlm	Z	m
Z
mZmZ ddlZddlmZ  G d de          Zd	 Zd
ej        dee         deddfdZdS )a3  
Copyright (c) 2025 by FlashInfer team.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

  http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
    N)
namedtuple)Enum)AnyDictListTuple)TraceGeneratorc                       e Zd ZdZdZdZdS )	EventTyper         N)__name__
__module____qualname__kBeginkEndkInstant     p/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/flashinfer/profiler/__init__.pyr   r      s        FDHHHr   r   c                 ^    | dz	  dz  }| dz	  dz  }| dz	  dz  }| dz  }||z  }||z  }|||||fS )z
    Decode a profiler tag into (block_idx, group_idx, event_idx, event_type, sm_id).
    Tag layout:
      bits 0-1: event_type
      bits 2-11: event_idx
      bits 12-23: block_group_idx
      bits 24-31: sm_id
             i  r   i     r   )	tag
num_blocks
num_groupssm_idblock_group_idx	event_idx
event_type	block_idx	group_idxs	            r   
decode_tagr%   "   s\     BY$EbyE)OU"IsJ:-I*,IiJ==r   profiler_bufferevent_names	file_namereturnc                    | j         t          j        k    sJ |                                 }|d d                             t          j                  \  }}t          |          }t          |          }t          |          }i }i }i }	t          dt          |                    D ]}
||
         dk    r||
|
dz                                t          j
                  \  }}t          |          }t          |          }t          |||          \  }}}}}||vr|                    d| d|           ||<   ||         }||f|vr|                    d|           |||f<   |||f         }||         }|||f|	v r|	|||f         }n|                                }||	|||f<   |t          j        j        k    r|                    ||           .|t          j        j        k    r|                    |           Z|t          j        j        k    r|                    ||           |                                 d S )Nr   )dtyper   sm__block_group_)r+   torchuint64cpuviewint32intr	   rangelenuint32r%   create_groupcreate_trackr   r   valueopenr   closer   instantflush)r&   r'   r(   profiler_buffer_hostr   r   tgenpid_maptid_map	track_mapir   	timestampr#   r$   r!   r"   r   pidtideventtracks                         r   export_to_perfetto_tracerJ   4   ss   
  EL0000*..001"1"5:::MMJ
ZJZJ)$$DGG13I1c.//00 , ,"a''-a!a%i8==EL=QQY#hh	NN	=GZ>
 >
:	9iU
 G##!%!2!23R3R3Ry3R3R!S!SGIi y!00.1.>.>?S	?S?S.T.TGY	*+y),-I&y),	99y)Y?@EE$$&&E;@Iy)Y78)///JJy%((((9>///KK	""""9-333MM)U+++JJLLLLLr   )__doc__argparsecsvjsoncollectionsr   enumr   typingr   r   r   r   r/   tg4perfettor	   r   r%   TensorstrrJ   r   r   r   <module>rU      s      



  " " " " " "       ) ) ) ) ) ) ) ) ) ) ) )  & & & & & &       > > >$1\1c1 1 
	1 1 1 1 1 1r   