-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild_plugin.sh
More file actions
executable file
·121 lines (102 loc) · 3.61 KB
/
build_plugin.sh
File metadata and controls
executable file
·121 lines (102 loc) · 3.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#!/bin/sh
#
# Build plugin version of onnxruntime with WebGPU as a shared library plugin
#
set -e
# Get the directory where this script is located
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
# Activate Python virtual environment
source "$SCRIPT_DIR/activate_env.sh"
if [ $? -ne 0 ]; then
echo "Failed to activate virtual environment"
exit 1
fi
# Detect OS for shared library extension
case "$(uname -s)" in
Darwin*)
SHARED_LIB_EXT="dylib"
;;
Linux*)
SHARED_LIB_EXT="so"
;;
*)
echo "Unsupported OS: $(uname -s)"
exit 1
;;
esac
echo "=== STEP 1a: Build onnxruntime with generic interface ==="
cd "$SCRIPT_DIR/external/onnxruntime"
./build.sh \
--parallel \
--config RelWithDebInfo \
--build_dir "$SCRIPT_DIR/ort_generic" \
--enable_generic_interface \
--skip_tests \
--build_shared_lib \
--target onnxruntime \
--disable_rtti \
--use_binskim_compliant_compile_flags \
--enable_lto
if [ $? -ne 0 ]; then
echo "Build failed with error $?"
exit 1
fi
echo "=== STEP 1b: Build onnxruntime WebGPU provider shared library ==="
./build.sh \
--parallel \
--config RelWithDebInfo \
--use_webgpu shared_lib \
--build_dir "$SCRIPT_DIR/ort_shared" \
--skip_tests \
--target onnxruntime_providers_webgpu \
--disable_rtti \
--use_binskim_compliant_compile_flags \
--enable_lto
if [ $? -ne 0 ]; then
echo "Build failed with error $?"
exit 1
fi
echo "=== STEP 2: Prepare ort_home_plugin ==="
mkdir -p "$SCRIPT_DIR/ort_home_plugin/include"
mkdir -p "$SCRIPT_DIR/ort_home_plugin/lib"
# Copy headers
cp -f "$SCRIPT_DIR/external/onnxruntime/include/onnxruntime/core/session/"*.h "$SCRIPT_DIR/ort_home_plugin/include/"
# Copy libraries
cp -f "$SCRIPT_DIR/ort_generic/RelWithDebInfo/libonnxruntime."* "$SCRIPT_DIR/ort_home_plugin/lib/" 2>/dev/null || \
cp -f "$SCRIPT_DIR/ort_generic/RelWithDebInfo/onnxruntime."* "$SCRIPT_DIR/ort_home_plugin/lib/" 2>/dev/null || true
echo "=== STEP 3: Build onnxruntime-genai (plugin) ==="
cd "$SCRIPT_DIR/external/onnxruntime-genai"
./build.sh \
--parallel \
--config RelWithDebInfo \
--build_dir "$SCRIPT_DIR/ort_genai_plugin" \
--skip_tests \
--skip_wheel \
--skip_examples \
--ort_home "$SCRIPT_DIR/ort_home_plugin" \
--cmake_extra_defines "ORT_GENAI_USE_WEBGPU_PLUGIN=ON"
if [ $? -ne 0 ]; then
echo "Build failed with error $?"
exit 1
fi
echo "=== STEP 4: Gather artifacts (plugin) ==="
mkdir -p "$SCRIPT_DIR/parity_plugin"
# Copy onnxruntime library
if [ -f "$SCRIPT_DIR/ort_generic/RelWithDebInfo/libonnxruntime.$SHARED_LIB_EXT" ]; then
cp -f "$SCRIPT_DIR/ort_generic/RelWithDebInfo/libonnxruntime.$SHARED_LIB_EXT" "$SCRIPT_DIR/parity_plugin/"
fi
# Copy onnxruntime_providers_webgpu library
if [ -f "$SCRIPT_DIR/ort_shared/RelWithDebInfo/libonnxruntime_providers_webgpu.$SHARED_LIB_EXT" ]; then
cp -f "$SCRIPT_DIR/ort_shared/RelWithDebInfo/libonnxruntime_providers_webgpu.$SHARED_LIB_EXT" "$SCRIPT_DIR/parity_plugin/"
fi
# Copy model_benchmark executable
if [ -f "$SCRIPT_DIR/ort_genai_plugin/RelWithDebInfo/benchmark/c/model_benchmark" ]; then
cp -f "$SCRIPT_DIR/ort_genai_plugin/RelWithDebInfo/benchmark/c/model_benchmark" "$SCRIPT_DIR/parity_plugin/"
fi
# Copy onnxruntime_genai library
if [ -f "$SCRIPT_DIR/ort_genai_plugin/RelWithDebInfo/libonnxruntime-genai.$SHARED_LIB_EXT" ]; then
cp -f "$SCRIPT_DIR/ort_genai_plugin/RelWithDebInfo/libonnxruntime-genai.$SHARED_LIB_EXT" "$SCRIPT_DIR/parity_plugin/"
fi
echo "=== Plugin build completed ==="
echo "Artifacts are in: $SCRIPT_DIR/parity_plugin/"
ls -la "$SCRIPT_DIR/parity_plugin/"