mirror of
https://github.com/pytorch/pytorch.git
synced 2025-10-20 21:14:14 +08:00
Summary: Provide a standalone path to compile and run a ExportedProgram in C. Test Plan: (1) Generate a compiled model from ExportedProgram ``` python generate_lowered_cpu.py --input-path /tmp/$USER/ep.pt --output-path /tmp/$USER/final.pt ``` (2) Compile a standalone test runner ``` TORCH_ROOT_DIR=/data/users/$USER/pytorch sh standalone_compile.sh standalone_test.cpp standalone_test.out ``` (3) Run test for the compiled model in step (1) ``` LD_LIBRARY_PATH=/data/users/$USER/pytorch/build/lib ./standalone_test.out /tmp/$USER/final.pt ``` Differential Revision: D66872380 Pull Request resolved: https://github.com/pytorch/pytorch/pull/142327 Approved by: https://github.com/hl475
27 lines
1011 B
Bash
27 lines
1011 B
Bash
#!/bin/sh
|
|
|
|
if [ -z "$CXX" ]; then
|
|
CXX="clang++"
|
|
echo "Using system default C++ compiler: $CXX"
|
|
else
|
|
echo "Using user-provided C++ compiler: $CXX"
|
|
fi
|
|
|
|
if [ -z "$TORCH_ROOT_DIR" ]; then
|
|
echo "Error: The TORCH_ROOT_DIR environment variable must be set." >&2
|
|
echo "Example: export TORCH_ROOT_DIR=/home/$USER/local/pytorch" >&2
|
|
exit 1
|
|
fi
|
|
|
|
if [ $# -lt 2 ]; then
|
|
echo "Usage: $0 <input file path> <output file path>."
|
|
echo "Example Usage: $0 standalone_test.cpp standalone_test.out."
|
|
exit 1
|
|
fi
|
|
|
|
# Building the wrapper
|
|
$CXX -I$TORCH_ROOT_DIR/build/aten/src -I$TORCH_ROOT_DIR/aten/src -I$TORCH_ROOT_DIR/build -I$TORCH_ROOT_DIR -I$TORCH_ROOT_DIR/build/caffe2/aten/src -I$TORCH_ROOT_DIR/torch/csrc/api -I$TORCH_ROOT_DIR/torch/csrc/api/include -std=gnu++17 -fPIE -o $1.o -c $1
|
|
|
|
# Linking
|
|
$CXX -rdynamic -Wl,--no-as-needed,$TORCH_ROOT_DIR/build/lib/libtorch.so $1.o -Wl,--no-as-needed,$TORCH_ROOT_DIR/build/lib/libtorch_cpu.so -Wl,--no-as-needed,$TORCH_ROOT_DIR/build/lib/libc10.so -o $2
|