o
    ãÊiD	  ã                   @   s,   d dl Z d dlZd dlZdd„ Zdd„ ZdS )é    Nc                  C   s¢   ddl } d}tj | j¡}tj ||¡}tj |¡r|S tj |¡}tj |ddd|¡}t |¡}|r7|d S tj tj tj t¡d|¡¡}tj |¡rO|S dS )a*  Get the path to the MPS ops library.

    Searches in the following locations:
    1. The torchao package directory (for pip-installed packages)
    2. The build directory (for development installs from source)
    3. The cmake-out directory relative to this file (for standalone CMake builds)
    r   Nzlibtorchao_ops_mps_aten.dylibÚbuildzlib.*Útorchaozcmake-out/lib/)	r   ÚosÚpathÚdirnameÚ__file__ÚjoinÚexistsÚglobÚabspath)r   ÚlibnameÚtorchao_dirÚpip_libpathÚ	repo_rootÚbuild_patternÚbuild_matchesÚcmake_libpath© r   úV/home/ubuntu/.local/lib/python3.10/site-packages/torchao/experimental/ops/mps/utils.pyÚ_get_torchao_mps_lib_path   s"   
ÿr   c                  C   sè   z!t ddƒD ]} ttjjd| › dƒ ttjjd| › dƒ qW dS  tys   tƒ }|du r3tdƒ‚ztj |¡ W n t	yQ } z
td	|› d
|› ƒ‚d}~ww t ddƒD ]} ttjjd| › dƒ ttjjd| › dƒ qWY dS w )zLoad the MPS ops library.é   é   Ú_linear_fp_act_Ú
bit_weightÚ_pack_weight_ÚbitNz`Could not find libtorchao_ops_mps_aten.dylib. Please build with TORCHAO_BUILD_EXPERIMENTAL_MPS=1zFailed to load library z: )
ÚrangeÚgetattrÚtorchÚopsr   ÚAttributeErrorr   ÚRuntimeErrorÚload_libraryÚ	Exception)ÚnbitÚlibpathÚer   r   r   Ú_load_torchao_mps_lib1   s,   þÿ€ÿþôr'   )r
   r   r   r   r'   r   r   r   r   Ú<module>   s
   $