-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathmy_static_build.py
More file actions
33 lines (31 loc) · 945 Bytes
/
my_static_build.py
File metadata and controls
33 lines (31 loc) · 945 Bytes
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
# partial_static_build.py
import torch
from torch.utils.cpp_extension import load
import os
# 清理缓存
os.system('rm -rf /root/.cache/torch_extensions/py310_cu124/curope')
print("部分静态链接(只链接 stdc++)...")
try:
curope = load(
name='curope',
sources=['curope.cpp', 'kernels.cu'],
extra_cflags=['-O3', '-fPIC'],
extra_cuda_cflags=[
'-O3',
'--ptxas-options=-v',
'--use_fast_math',
],
# 只静态链接 libstdc++,其他库动态链接
extra_ldflags=[
'-Wl,-Bstatic', '-lstdc++', '-Wl,-Bdynamic',
'-lpthread', # 确保 pthread 动态链接
],
verbose=True,
with_cuda=True
)
print("部分静态链接成功!")
print(f"编译后的模块位置: {curope.__file__}")
except Exception as e:
print(f"编译失败: {e}")
import traceback
traceback.print_exc()