a
    5PÎj  ã                   @   s¦   d dl Z d dlZd dlZd dlZd dlZd dlZd dlZd dlZd dl	m
Z
mZmZmZmZmZmZmZ ej ejd  dd¡Zdadd„ Zdd„ Ze jdd
d„ƒZdS )é    N)ÚObjectIDÚObjectNotAvailableÚPlasmaBufferÚPlasmaClientÚconnectÚPlasmaObjectExistsÚPlasmaObjectNotFoundÚPlasmaStoreFullÚ
tensorflowúplasma_op.soc                  C   s   dd l } |  t¡ad S )Nr   )r
   Úload_op_libraryÚTF_PLASMA_OP_PATHÚtf_plasma_op)Útf© r   ú^/mounts/lovelace/software/anaconda3/envs/metadmg/lib/python3.9/site-packages/pyarrow/plasma.pyÚload_plasma_tensorflow_op.   s    r   c                  C   s&  zdd l } td| j ƒ W n ty,   Y nö0 tdƒ tj tj t¡¡}tj 	|dd¡}tj 	|dd¡}| j
 ¡ }tjdkrŠdd	g| }d
ddd|d|ddt ¡  g	}|dd„ t ¡ D ƒ7 }|g d¢7 }||7 }|| j
 ¡ 7 }|dg7 }| j ¡ rþ|dg7 }tdt|ƒ ƒ t |¡ |  t¡ad S )Nr   zTensorFlow version: z!Compiling Plasma TensorFlow Op...r
   zplasma_op.ccr   Údarwinz
-undefinedZdynamic_lookupzg++z
-std=c++11z-gz-sharedz-oz-DNDEBUGz-Ic                 S   s   g | ]}d | ‘qS )z-Lr   )Ú.0Údirr   r   r   Ú
<listcomp>E   ó    z.build_plasma_tensorflow_op.<locals>.<listcomp>)z-lplasmaz-larrow_pythonz-larrowz-fPICz-O2z-DGOOGLE_CUDAzRunning command )r
   ÚprintÚ__version__ÚImportErrorÚosÚpathÚdirnameÚrealpathÚ__file__ÚjoinÚ	sysconfigZget_compile_flagsÚsysÚplatformÚpaZget_includeZget_library_dirsZget_link_flagsÚtestZis_built_with_cudaÚstrÚ
subprocessÚ
check_callr   r   r   )r   Zdir_pathZcc_pathZso_pathZ	tf_cflagsÚcmdr   r   r   Úbuild_plasma_tensorflow_op4   s2    


ÿ



r*   Fc              	   c   s”  |r|rt dƒ‚tjdd�}�zNtj |d¡}tj tjd d¡}tj |¡s`tj t	j
dd¡}|d|d	t| ƒg}	|r‚|	d
|g7 }	|r�|	dg7 }	|dur¤|	d|g7 }	d}
d}|rØg d¢|	 }	tj|	|
|d�}t d¡ nH|�rddg|	 }	tj|	|
|d�}t d¡ ntj|	|
|d�}t d¡ | ¡ }|du�r@td|f ƒ‚||fV  W | ¡ du �rb| ¡  t |¡ n"| ¡ du �r„| ¡  t |¡ 0 dS )ab  
    Start a plasma store process.

    Parameters
    ----------
    plasma_store_memory : int
        Capacity of the plasma store in bytes.
    use_valgrind : bool
        True if the plasma store should be started inside of valgrind. If this
        is True, use_profiler must be False.
    use_profiler : bool
        True if the plasma store should be started inside a profiler. If this
        is True, use_valgrind must be False.
    plasma_directory : str
        Directory where plasma memory mapped files will be stored.
    use_hugepages : bool
        True if the plasma store should use huge pages.
    external_store : str
        External store to use for evicted objects.

    Returns
    -------
    result : (str, subprocess.Popen)
        A tuple of the name of the plasma store socket and the process ID of
        the plasma store process.
    z2Cannot use valgrind and profiler at the same time.ztest_plasma-)Úprefixzplasma.sockr   zplasma-store-serverÚbinz-sz-mz-dz-hNz-e)Úvalgrindz--track-origins=yesz--leak-check=fullz--show-leak-kinds=allz!--leak-check-heuristics=stdstringz--error-exitcode=1)ÚstdoutÚstderrg      ð?r-   z--tool=callgrindgš™™™™™¹?z-plasma_store exited unexpectedly with code %d)Ú	ExceptionÚtempfileÚmkdtempr   r   r    r$   Ú__path__Úexistsr"   r+   r&   r'   ÚPopenÚtimeÚsleepÚpollÚRuntimeErrorÚkillÚshutilÚrmtree)Zplasma_store_memoryZuse_valgrindZuse_profilerZplasma_directoryZuse_hugepagesZexternal_storeZtmpdirZplasma_store_nameZplasma_store_executableÚcommandZstdout_fileZstderr_fileÚprocÚrcr   r   r   Ústart_plasma_storeQ   sl    
ÿÿþ
ûÿÿÿ

ÿþr@   )FFNFN)Ú
contextlibr   Zpyarrowr$   r;   r'   r"   r1   r6   Zpyarrow._plasmar   r   r   r   r   r   r   r	   r   r    r3   r   r   r   r*   Úcontextmanagerr@   r   r   r   r   Ú<module>   s"   (   ý