-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.py
More file actions
36 lines (29 loc) · 932 Bytes
/
build.py
File metadata and controls
36 lines (29 loc) · 932 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
34
35
36
import subprocess
import shutil
import os
import glob
CUDA_INC = "C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v11.0/include"
CUDA_LIB = "C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v11.0/lib/x64"
SRC = "src"
DIST = "dist"
BIN = "cuda-matmul.exe"
KERNEL = "matmul"
def run_cmd(cmd):
print(cmd)
step = subprocess.run(cmd)
step.check_returncode()
def clear_dir(dir):
try:
shutil.rmtree(dir, ignore_errors=True)
except FileNotFoundError:
pass
os.mkdir(dir)
def build_bin():
cpp = glob.glob(f"{SRC}/*.cpp")
run_cmd(f'g++ -g3 -O3 "-I{CUDA_INC}" "-L{CUDA_LIB}" {" ".join(cpp)} -o {DIST}/{BIN} -lcuda -lcublas')
def build_cuda():
run_cmd(f"nvcc --ptx --generate-line-info --source-in-ptx --output-file {DIST}/{KERNEL}.ptx {SRC}/{KERNEL}.cu")
if __name__ == "__main__":
clear_dir(DIST)
build_bin()
build_cuda()