U
    d                     @   s   d dl mZmZ d dlmZ d dlmZ d dlZ	d dl
Z
d dlZd dlm  mZ dZG dd dZdd ZG d	d
 d
ejZedkrd dlZe  dS )    )givensettingsN)ProcessZGLOOc                   @   s   e Zd Zdd Zdd ZdS )TemporaryDirectoryc                 C   s   t  | _| jS N)tempfilemkdtemptmpdir)self r   A/tmp/pip-unpacked-wheel-ua33x9lu/caffe2/python/allcompare_test.py	__enter__   s    
zTemporaryDirectory.__enter__c                 C   s   t | j d S r   )shutilrmtreer	   )r
   typevalue	tracebackr   r   r   __exit__   s    zTemporaryDirectory.__exit__N)__name__
__module____qualname__r   r   r   r   r   r   r      s   r   c                 C   s   ddl m}m}m}m} ddlm} ddlm}	 |	d |
|jdg dg| d td||td d	}
| }|
|_|d
| ||d
||	jd d S )Nr   )coredata_parallel_model	workspacedyndep)ModelHelper)
caffe2_pb2z2@/caffe2/caffe2/distributed:file_store_handler_opsZFileStoreHandlerCreateZstore_handler)path)Z
kv_handlerZshard_idZ
num_shardsZengineZ	exit_nets	test_data)Zcaffe2.pythonr   r   r   r   Zcaffe2.python.model_helperr   Zcaffe2.protor   ZInitOpsLibraryZRunOperatorOnceZCreateOperatordict	op_engineZ_rendezvousZFeedBlobZ_RunComparisonZDeviceOptionZCPU)Zfilestore_dirZ
process_iddata	num_procsr   r   r   r   r   r   Z
rendezvousmodelr   r   r   allcompare_process   s6    
     r$   c                   @   sD   e Zd Zeeddeddedddeddd	d
 ZdS )TestAllCompare               )dnr"   i'  )deadlinec              	   C   s   g }t |D ]}|tjjd|d qtjjt|dtj}t	 \}g }t |D ]*}	t
t||	||fd}
||
 |
  qVt|dkr| }
|
  qW 5 Q R X d S )Nr&   )high)size)targetargsr   )rangeappendnprandomrandintZranftupleZastypeZfloat32r   r   r$   startlenpopjoin)r
   r+   r,   r"   Zdims_r   tempdirZ	processesidxprocessr   r   r   test_allcompare<   s     


zTestAllCompare.test_allcompareN)r   r   r   r   stZintegersr   r@   r   r   r   r   r%   ;   s   
 
 
r%   __main__)Z
hypothesisr   r   Zhypothesis.strategiesZ
strategiesrA   multiprocessingr   Znumpyr4   r   r   Z"caffe2.python.hypothesis_test_utilpythonZhypothesis_test_utilhur    r   r$   ZHypothesisTestCaser%   r   Zunittestmainr   r   r   r   <module>   s   	