U
    d                     @   s   d dl mZ d dlmZmZ d dlmZ d dlZd dl	Z	d dl
Z
dd Zdd Zed	kre  \ZZejrxejrxejse   ee dS )
    )
caffe2_pb2)core	workspace)ModelDownloaderNc                  C   s
  t jdd} | jdtddd | jdtdd	 | jd
tddd | jdtddd | jdtdd	 | jdtddd | jdtddd | jdddd | jdddd | jdtddd | jd dd!d | jd"td#d$ | jd%td&d$ | jd'd(dd) | jd*td+ | S ),NzCaffe2 benchmark.)descriptionz--batch_size   zThe batch size.)typedefaulthelpz--modelzThe model to benchmark.)r   r
   z--orderZNCHWzThe order to evaluate.z--deviceCPUzdevice to evaluate on.z
--cudnn_wszThe cudnn workspace size.z--iterations
   z(Number of iterations to run the network.z--warmup_iterationsz1Number of warm-up iterations before benchmarking.z--forward_only
store_truez"If set, only run the forward pass.)actionr
   z--layer_wise_benchmarkz.If True, run the layer-wise benchmark as well.z--engine z8If set, blindly prefer the given engine(s) for every op.z--dump_modelz*If True, dump the model prototxts to disk.z
--net_typesimple)r   r	   z--num_workers   z
--use-nvtxF)r	   r   z--htrace_span_log_path)r   )argparseArgumentParseradd_argumentintstr)parser r   F/tmp/pip-unpacked-wheel-ua33x9lu/caffe2/python/ideep/test_ideep_net.pyGetArgumentParser   s~    r   c              	      s  t d j t }| j\}}} fdd| D }t d| i }| D ] \}}tjj	| 
tj||< qX jdkrttj}	n@ jdkrttj}	n( jdkrttj}	ntd jt d	 j|	 |j|	 |jD ]}
|
j|	 qt| t }i }|D ]}t|||< q"| D ]\}}|||< q@t  t|	r | D ]\}}t|||	 qpt| t }t |j! j" j# j$}t d
d|d  d  j  W 5 Q R X d S )NzBatch size: {}c                    s*   i | ]"\}}| j g|d  dd  qS )   N)
batch_size).0kvargsr   r   
<dictcomp>S   s      zbenchmark.<locals>.<dictcomp>zinput info: {}r   ZMKLIDEEPzUnknown device: {}zDevice option: {}, {}zFPS: {:.2f}r   r   i  )%printformatr   r   Zget_c2_modelmodelitemsnprandomZrandnZastypeZfloat32Zdevicer   ZDeviceOptionr   r   ZMKLDNNr$   	Exceptiondevice_optionZCopyFromopr   Z
RunNetOnceZBlobsZ	FetchBlobZResetWorkspaceZDeviceScopeZFeedBlobZ	CreateNettimeZBenchmarkNetnameZwarmup_iterationsZ
iterationsZlayer_wise_benchmark)r"   ZmfZinit_netZpred_netZ
value_infoZinput_shapesZexternal_inputsr   r    r,   r-   Zbbweightsbr/   Zblobstartresr   r!   r   	benchmarkO   sL    





r4   __main__)Zcaffe2.protor   Zcaffe2.pythonr   r   Zcaffe2.python.models.downloadr   Znumpyr)   r   r.   r   r4   __name__parse_known_argsr"   
extra_argsr   r'   order
print_helpr   r   r   r   <module>   s"   A-
