forked from llmsystem/llmsys_s25_hw1
-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathmigrate_kernel.py
More file actions
56 lines (44 loc) · 1.46 KB
/
migrate_kernel.py
File metadata and controls
56 lines (44 loc) · 1.46 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
import argparse
import os
import shutil
import subprocess
import sys
def main():
parser = argparse.ArgumentParser(description="Copy kernel from hw1 to hw2 directory")
parser.add_argument(
"--hw1-dir",
type=str,
required=True,
help="Path to the hw1 directory"
)
parser.add_argument(
"--hw2-dir",
type=str,
required=True,
help="Path to the hw2 directory"
)
args = parser.parse_args()
hw1_dir = os.path.abspath(args.hw1_dir)
hw2_dir = os.path.abspath(args.hw2_dir)
if not os.path.isdir(hw1_dir):
print(f"Err: {hw1_dir} is not a valid directory", file=sys.stderr)
sys.exit(1)
if not os.path.isdir(hw2_dir):
print(f"Err: {hw2_dir} is not a valid directory", file=sys.stderr)
sys.exit(1)
src_file = os.path.join(hw1_dir, "src/combine.cu")
dst_file = os.path.join(hw2_dir, "src/combine.cu")
so_file = os.path.join(hw2_dir, "minitorch/cuda_kernels/combine.so")
if not os.path.isfile(src_file):
print(f"Error: {src_file} does not exist", file=sys.stderr)
sys.exit(1)
os.makedirs(os.path.dirname(dst_file), exist_ok=True)
os.makedirs(os.path.dirname(so_file), exist_ok=True)
shutil.copy2(src_file, dst_file)
commands = [
["nvcc", "-o", so_file, "--shared", dst_file, "-Xcompiler", "-fPIC"]
]
for cmd in commands:
subprocess.run(cmd, check=True)
if __name__ == "__main__":
main()