
    h                     \    S SK Jr  SSKJrJrJr  SSKJr  SSKJ	r	J
r
  S\4S jrS\4S jrg	)
    )cast   )cupy
tensorflowtorch)ArrayXd)get_torch_default_devicetensorflow2xpsize_in_bytesc                    [        SU 5      n [        R                  " U S-  4[        R                  R                  S9n[        [        [        U5      5      n[        UR                  5      n[        R                  R                  R                  X0U5      n[        R                  R                  R                  US5      $ )a  Function that can be passed into cupy.cuda.set_allocator, to have cupy
allocate memory via TensorFlow. This is important when using the two libraries
together, as otherwise OOM errors can occur when there's available memory
sitting in the other library's pool.
      )dtyper   )maxr   zerosdtypesfloat32r   r   r
   intdatar   cudamemoryUnownedMemoryMemoryPointer)r   tensor
cupy_arrayaddressr   s        Y/home/james-whalen/.local/lib/python3.13/site-packages/thinc/backends/_cupy_allocators.pycupy_tensorflow_allocatorr      s     m,M}13:;L;L;T;TUFg}V45J*//"GYY++GJOF99))&!44    c                 ,   [        5       n [        SU 5      n [        R                  " U S-  4SUS9nUR	                  5       n[
        R                  R                  R                  X0U5      n[
        R                  R                  R                  US5      $ )Nr   r   F)requires_graddevicer   )
r	   r   r   r   data_ptrr   r   r   r   r   )r   r"   torch_tensorr   r   s        r   cupy_pytorch_allocatorr%      s    %'F m,M
 ;;	!	U6L
 ##%GYY++GLQF99))&!44r   N)typingr   compatr   r   r   typesr   utilr	   r
   r   r   r%    r   r   <module>r+      s,     , ,  :5S 5"5# 5r   