
    N j"              
           S SK r S SKrS SKJr  / r\ R
                  " \5      rS\S\	\   S\
\\4   S-  S\S\4
S jrS\S\	\   S\S\4S	 jrg)
    N)IndentedBufferpackage_namemodel_namesexample_inputs_mapdevice_typereturnc                 \   [        5       nUR                  / SQ5        US:X  aE  [        R                  R                  (       a  UR                  S/5        OUR                  SS/5        U H  nUR                  SU  SU SU S	35        M      UR                  5         U H  nUR                  S
U S35        M     UR                  / SQ5        UR                  5          UR                  SU S35        UR                  S5        UR                  5          UR                  S5        UGb  [        U5       GHB  u  peX%   nUR                  SU 35        UR                  SUS-    S35        UR                  SU S35        UR                  5          UR                  SU S35        UR                  S5        UR                  S5        UR                  5          UR                  S5        UR                  S5        SSS5        UR                  S5        UR                  S5        UR                  S5        UR                  S US-    S!35        SSS5        UR                  S5        UR                  5         GME     UR                  5         UR                  S"5        [        [        U5      5       H$  nUR                  S#US-    S$3S%US-    S&3/5        M&     UR                  S'5        [        [        U5      5       H  nUR                  S(US-    S35        M     UR                  S)5        [        U5       HR  u  peUR                  S*US-    S+3S,US-    S-3S.US-    S/U S03S1US-    S23S3US-    S23S4S5U  SU S63S7US-    S83/5        MT     UGb#  UR                  S95        [        [        U5      5       HE  nUR                  S:US-    S;35        UR                  S7US-    S<US-    S=US-    S>US-    S?3	5        MG     UR                  S@5        [        [        U5      5       H$  nUR                  SAUS-    S$3SBUS-    SC3/5        M&     UR                  SD5        [        [        U5      5       H?  nUR                  SEUS-    SFUS-    SG35        UR                  SHUS-    SIUS-    SJ35        MA     UR                  SK5        SSS5        UR                  SL/5        UR                  5          UR                  SM5        UR                  S5        SSS5        UR                  S5        SSS5        UR                  S5        UR                  5       $ ! , (       d  f       GNb= f! , (       d  f       GN!= f! , (       d  f       N= f! , (       d  f       N}= f! , (       d  f       Nu= f)NaQ  
Generates a main.cpp file for AOTInductor standalone models in the specified package.

Args:
    package_name (str): Name of the package containing the models.
    model_names (List[str]): List of model names to include in the generated main.cpp.
    cuda (bool): Whether to generate code with CUDA support.
    example_inputs_map (Optional[Dict[str, List[Tensor]]]): A mapping from model name to
        its list of example input tensors. If provided, the generated main.cpp will
        load and run these inputs.

Returns:
    str: The contents of the generated main.cpp file as a string.
)z#include <dlfcn.h>z#include <fstream>z#include <iostream>z#include <memory>z#include <torch/torch.h>z#include <vector>z<#include <torch/csrc/inductor/aoti_torch/tensor_converter.h>cudaz#include <hip/hip_runtime.h>z#include <cuda.h>z#include <cuda_runtime_api.h>z
#include "/data/aotinductor//z.h"z+using torch::aot_inductor::AOTInductorModel;)z*using torch::aot_inductor::ConstantHandle;z'using torch::aot_inductor::ConstantMap; z"int main(int argc, char* argv[]) {zstd::string device_str = "z";ztry {zc10::Device device(device_str);Nz // Load input tensors for model z%std::vector<at::Tensor> input_tensors   zfor (int j = 0; j < z; ++j) {zstd::string filename = "z%_input_" + std::to_string(j) + ".pt";z-std::ifstream in(filename, std::ios::binary);zif (!in.is_open()) {z>std::cerr << "Failed to open file: " << filename << std::endl;z	return 1;}zastd::vector<char> buffer((std::istreambuf_iterator<char>(in)), std::istreambuf_iterator<char>());z2torch::IValue ivalue = torch::pickle_load(buffer);input_tensorsz).push_back(ivalue.toTensor().to(device));z!
// Create array of input handleszauto input_handlesz =zL    torch::aot_inductor::unsafe_alloc_new_handles_from_tensors(input_tensorsz);z#
// Create array for output handleszAtenTensorHandle output_handlez
// Create and load modelszauto constants_mapz# = std::make_shared<ConstantMap>();zauto constants_arrayz3 = std::make_shared<std::vector<ConstantHandle>>();z
auto modelz$ = std::make_unique<AOTInductorModelz>(z    std::move(constants_mapz),z    std::move(constants_arrayz    device_str,z    "z/");modelz->load_constants();z
// Run the modelsz,torch::aot_inductor::DeviceStreamType streamz = nullptr;z->run(&input_handlesz[0], &output_handlez, streamz, nullptr);z%
// Convert output handles to tensorszauto output_tensorzN    torch::aot_inductor::alloc_tensors_by_stealing_from_handles(&output_handlez, 1);z
// Validate outputszstd::cout << "output_tensorz\n" << output_tensorz << std::endl;ztorch::save(output_tensorz, "output_tensorz.pt");z	return 0;z#} catch (const std::exception &e) {z0std::cerr << "Error: " << e.what() << std::endl;)r   
writelinestorchversionhip	writelinenewlineindent	enumeraterangelengetvalue)r   r   r   r   ib
model_namei
num_inputss           q/root/GenerationalWealth/GenerationalWealth/venv/lib/python3.13/site-packages/torch/export/experimental/_utils.py_get_main_cpp_filer#      s   * 
	BMM	

 f==MM2 MM'3 "

&8Aj\QTU	
 "
 JJL!

B:,aPQ " MM	
 

1+bAB
WYY[LL:;!-%.{%;MA!3!?JLL#CJ<!PQLL#HQq!QRLL#7
|9!MN6zlBgh %TU%;<YY[LL ` LL5	 )
 S) P +AE72[\% %* LL%JJL9 &<< 

ABs;/0AMM0Qr:jklopkpjqqst 1 CDs;/0ALL#A!a%!JK 1 LL67!*;!7,QUG3VW.q1ug5hi$QUG+OPZ|[]^5a!eWB?7AwbA)~-?
|4PAw&9:	 "8 "-23s;/0ALLFq1ug[Y LLAw&:1q5'ATUVYZUZT[[cdehidicjjuv	 1 EFs;/0AMM0Qr:lmnqrmrlssxy 1 45s;/0ALL7Aw>STUXYTYSZZhk LL5a!eW<LQQRUGSY\	 1 LL%y | 	5	

 YY[LLKLLL%  	SW 
X LL;;=s )[ % [F [O 
sp   7VA<U;AU)	#U<AU)	I9U;*V2#VV
U&!U)	)
U83U;;
V		V
V	V
V+c                    [        5       nUR                  / SQ5        SSKJn  UR                  (       a  UR                  S5        US:X  aB  [        R                  R                  (       a  UR                  S5        OUR                  S5        UR                  5         U H  nUR                  SU  S	U S
35        M     UR                  S5        US:X  aC  [        R                  R                  (       a  UR                  S5        O)UR                  S5        OUS:X  a  UR                  S5        SR                  U5      nUR                  SU S35        US:X  ab  [        R                  R                  (       a!  UR                  S5        UR                  5       $ UR                  S5         UR                  5       $ US:X  a  UR                  S5        UR                  5       $ )N)z$cmake_minimum_required(VERSION 3.10)zproject(TestProject)r   zset(CMAKE_CXX_STANDARD 17)r   r   )test_configszfind_package(Torch REQUIRED)r
   zfind_package(hip REQUIRED)zfind_package(CUDA REQUIRED)zadd_subdirectory(r   z/)z
add_executable(main main.cpp)z0target_compile_definitions(main PRIVATE USE_HIP)z1target_compile_definitions(main PRIVATE USE_CUDA)xpuz0target_compile_definitions(main PRIVATE USE_XPU) z)target_link_libraries(main PRIVATE torch )z-target_link_libraries(main PRIVATE hip::host)z:target_link_libraries(main PRIVATE cuda ${CUDA_LIBRARIES})z2target_link_libraries(main PRIVATE sycl ze_loader))r   r   torch._inductor.configr%   use_libtorchr   r   r   r   r   joinr   )r   r   r   r   r%   r   
model_libss          r"   _get_make_filer-      s}   		BMM	
 4  
34f==LL56LL67JJL!

(6HTVWX " LL23f==LLKLLLLM		
GH+&JLL<ZLJKf==LLHI
 ;;= LLUV ;;= 
	
IJ;;=    )loggingr   torch._inductor.utilsr   __all__	getLogger__name__loggerstrlistdictintr#   r-    r.   r"   <module>r:      s      0 			8	$qqcq S#X-q 	q
 	qh/ /49 /3 /SV /r.   