a
    ,gh                     @   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 n0 td tjtjt}tj	|dd}tj	|dd}| j
 }tjdkrd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}|rg 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"   (   