-
Notifications
You must be signed in to change notification settings - Fork 60
/
cudalt.py
79 lines (64 loc) · 1.77 KB
/
cudalt.py
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
#!/usr/bin/python
# libtoolish hack: compile a .cu file like libtool does
import sys
import os
lo_filepath = sys.argv[1]
o_filepath = lo_filepath.replace(".lo", ".o")
try:
i = o_filepath.rindex("/")
lo_dir = o_filepath[0:i+1]
o_filename = o_filepath[i+1:]
except ValueError:
lo_dir = ""
o_filename = o_filepath
local_pic_dir = ".libs/"
local_npic_dir = ""
pic_dir = lo_dir + local_pic_dir
npic_dir = lo_dir + local_npic_dir
pic_filepath = pic_dir + o_filename
npic_filepath = npic_dir + o_filename
local_pic_filepath = local_pic_dir + o_filename
local_npic_filepath = local_npic_dir + o_filename
# Make lib dir
try:
os.mkdir(pic_dir)
except OSError:
pass
# generate the command to compile the .cu for shared library
args = sys.argv[2:]
args.extend(["-Xcompiler","-fPIC"]) # position indep code
args.append("-o")
args.append(pic_filepath)
command = " ".join(args)
print command
# compile the .cu
rv = os.system(command)
if rv != 0:
sys.exit(1)
# generate the command to compile the .cu for static library
args = sys.argv[2:]
args.append("-o")
args.append(npic_filepath)
command = " ".join(args)
print command
# compile the .cu
rv = os.system(command)
if rv != 0:
sys.exit(1)
# get libtool version
fd = os.popen("libtool --version")
libtool_version = fd.readline()
fd.close()
# generate the .lo file
f = open(lo_filepath, "w")
f.write("# " + lo_filepath + " - a libtool object file\n")
f.write("# Generated by " + libtool_version + "\n")
f.write("#\n")
f.write("# Please DO NOT delete this file!\n")
f.write("# It is necessary for linking the library.\n\n")
f.write("# Name of the PIC object.\n")
f.write("pic_object='" + local_pic_filepath + "'\n\n")
f.write("# Name of the non-PIC object.\n")
f.write("non_pic_object='" + local_npic_filepath + "'\n")
f.close()
sys.exit(0)