2017-05-05 01:22:20 +08:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
# Install.py tool to build the GPU library
|
|
|
|
# used to automate the steps described in the README file in this dir
|
|
|
|
|
2017-08-09 04:57:27 +08:00
|
|
|
from __future__ import print_function
|
|
|
|
import sys,os,subprocess
|
2017-05-05 01:22:20 +08:00
|
|
|
|
|
|
|
# help message
|
|
|
|
|
|
|
|
help = """
|
2017-08-24 03:20:30 +08:00
|
|
|
Syntax from src dir: make lib-gpu args="-m machine -h hdir -a arch -p precision -e esuffix -b -o osuffix"
|
|
|
|
Syntax from lib dir: python Install.py -m machine -h hdir -a arch -p precision -e esuffix -b -o osuffix
|
2017-07-15 06:25:16 +08:00
|
|
|
|
|
|
|
specify one or more options, order does not matter
|
|
|
|
|
2017-08-11 09:14:40 +08:00
|
|
|
copies an existing Makefile.machine in lib/gpu to Makefile.auto
|
2017-07-15 06:25:16 +08:00
|
|
|
optionally edits these variables in Makefile.auto:
|
|
|
|
CUDA_HOME, CUDA_ARCH, CUDA_PRECISION, EXTRAMAKE
|
|
|
|
optionally uses Makefile.auto to build the GPU library -> libgpu.a
|
|
|
|
and to copy a Makefile.lammps.esuffix -> Makefile.lammps
|
|
|
|
optionally copies Makefile.auto to a new Makefile.osuffix
|
2017-05-05 01:22:20 +08:00
|
|
|
|
2017-08-09 04:57:27 +08:00
|
|
|
-m = use Makefile.machine as starting point, copy to Makefile.auto
|
|
|
|
default machine = linux
|
2018-08-15 21:31:31 +08:00
|
|
|
default for -h, -a, -p, -e settings are those in -m Makefile
|
2017-05-05 01:22:20 +08:00
|
|
|
-h = set CUDA_HOME variable in Makefile.auto to hdir
|
|
|
|
hdir = path to NVIDIA Cuda software, e.g. /usr/local/cuda
|
|
|
|
-a = set CUDA_ARCH variable in Makefile.auto to arch
|
2018-08-15 21:31:31 +08:00
|
|
|
use arch = sm_20 for Fermi (C2050/C2070, deprecated as of CUDA 8.0)
|
|
|
|
or GeForce GTX 580 or similar
|
|
|
|
use arch = sm_30 for Kepler (K10)
|
|
|
|
use arch = sm_35 for Kepler (K40) or GeForce GTX Titan or similar
|
|
|
|
use arch = sm_37 for Kepler (dual K80)
|
|
|
|
use arch = sm_60 for Pascal (P100)
|
|
|
|
use arch = sm_70 for Volta
|
2017-05-05 01:22:20 +08:00
|
|
|
-p = set CUDA_PRECISION variable in Makefile.auto to precision
|
|
|
|
use precision = double or mixed or single
|
|
|
|
-e = set EXTRAMAKE variable in Makefile.auto to Makefile.lammps.esuffix
|
2017-08-09 04:57:27 +08:00
|
|
|
-b = make the GPU library using Makefile.auto
|
2017-05-05 01:22:20 +08:00
|
|
|
first performs a "make clean"
|
2017-08-09 04:57:27 +08:00
|
|
|
then produces libgpu.a if successful
|
2017-05-05 01:22:20 +08:00
|
|
|
also copies EXTRAMAKE file -> Makefile.lammps
|
|
|
|
-e can set which Makefile.lammps.esuffix file is copied
|
|
|
|
-o = copy final Makefile.auto to Makefile.osuffix
|
2017-07-15 06:25:16 +08:00
|
|
|
|
|
|
|
Examples:
|
|
|
|
|
2017-08-09 04:57:27 +08:00
|
|
|
make lib-gpu args="-b" # build GPU lib with default Makefile.linux
|
|
|
|
make lib-gpu args="-m xk7 -p single -o xk7.single" # create new Makefile.xk7.single, altered for single-precision
|
2018-08-15 21:31:31 +08:00
|
|
|
make lib-gpu args="-m mpi -a sm_35 -p single -o mpi.mixed -b" # create new Makefile.mpi.mixed, also build GPU lib with these settings
|
2017-05-05 01:22:20 +08:00
|
|
|
"""
|
|
|
|
|
|
|
|
# print error message or help
|
|
|
|
|
|
|
|
def error(str=None):
|
2017-08-09 04:57:27 +08:00
|
|
|
if not str: print(help)
|
|
|
|
else: print("ERROR",str)
|
2017-05-05 01:22:20 +08:00
|
|
|
sys.exit()
|
|
|
|
|
|
|
|
# parse args
|
|
|
|
|
|
|
|
args = sys.argv[1:]
|
|
|
|
nargs = len(args)
|
|
|
|
if nargs == 0: error()
|
|
|
|
|
|
|
|
isuffix = "linux"
|
|
|
|
hflag = aflag = pflag = eflag = 0
|
|
|
|
makeflag = 0
|
|
|
|
outflag = 0
|
|
|
|
|
|
|
|
iarg = 0
|
|
|
|
while iarg < nargs:
|
2017-08-09 04:57:27 +08:00
|
|
|
if args[iarg] == "-m":
|
2017-05-05 01:22:20 +08:00
|
|
|
if iarg+2 > nargs: error()
|
|
|
|
isuffix = args[iarg+1]
|
|
|
|
iarg += 2
|
|
|
|
elif args[iarg] == "-h":
|
|
|
|
if iarg+2 > nargs: error()
|
|
|
|
hflag = 1
|
|
|
|
hdir = args[iarg+1]
|
|
|
|
iarg += 2
|
|
|
|
elif args[iarg] == "-a":
|
|
|
|
if iarg+2 > nargs: error()
|
|
|
|
aflag = 1
|
|
|
|
arch = args[iarg+1]
|
|
|
|
iarg += 2
|
|
|
|
elif args[iarg] == "-p":
|
|
|
|
if iarg+2 > nargs: error()
|
|
|
|
pflag = 1
|
|
|
|
precision = args[iarg+1]
|
|
|
|
iarg += 2
|
|
|
|
elif args[iarg] == "-e":
|
|
|
|
if iarg+2 > nargs: error()
|
|
|
|
eflag = 1
|
|
|
|
lmpsuffix = args[iarg+1]
|
|
|
|
iarg += 2
|
2017-08-09 04:57:27 +08:00
|
|
|
elif args[iarg] == "-b":
|
2017-05-05 01:22:20 +08:00
|
|
|
makeflag = 1
|
|
|
|
iarg += 1
|
|
|
|
elif args[iarg] == "-o":
|
|
|
|
if iarg+2 > nargs: error()
|
|
|
|
outflag = 1
|
|
|
|
osuffix = args[iarg+1]
|
|
|
|
iarg += 2
|
|
|
|
else: error()
|
|
|
|
|
|
|
|
if pflag:
|
|
|
|
if precision == "double": precstr = "-D_DOUBLE_DOUBLE"
|
|
|
|
elif precision == "mixed": precstr = "-D_SINGLE_DOUBLE"
|
|
|
|
elif precision == "single": precstr = "-D_SINGLE_SINGLE"
|
|
|
|
else: error("Invalid precision setting")
|
2017-08-11 09:14:40 +08:00
|
|
|
|
2017-05-05 01:22:20 +08:00
|
|
|
# create Makefile.auto
|
|
|
|
# reset EXTRAMAKE, CUDA_HOME, CUDA_ARCH, CUDA_PRECISION if requested
|
2017-08-11 09:14:40 +08:00
|
|
|
|
2017-05-05 01:22:20 +08:00
|
|
|
if not os.path.exists("Makefile.%s" % isuffix):
|
|
|
|
error("lib/gpu/Makefile.%s does not exist" % isuffix)
|
|
|
|
|
|
|
|
lines = open("Makefile.%s" % isuffix,'r').readlines()
|
|
|
|
fp = open("Makefile.auto",'w')
|
|
|
|
|
|
|
|
for line in lines:
|
|
|
|
words = line.split()
|
|
|
|
if len(words) != 3:
|
2017-08-09 04:57:27 +08:00
|
|
|
fp.write(line)
|
2017-05-05 01:22:20 +08:00
|
|
|
continue
|
2017-08-09 04:57:27 +08:00
|
|
|
|
2017-05-05 01:22:20 +08:00
|
|
|
if hflag and words[0] == "CUDA_HOME" and words[1] == '=':
|
|
|
|
line = line.replace(words[2],hdir)
|
|
|
|
if aflag and words[0] == "CUDA_ARCH" and words[1] == '=':
|
2018-08-15 21:31:31 +08:00
|
|
|
line = line.replace(words[2],"-arch=%s" % arch)
|
2017-05-05 01:22:20 +08:00
|
|
|
if pflag and words[0] == "CUDA_PRECISION" and words[1] == '=':
|
|
|
|
line = line.replace(words[2],precstr)
|
|
|
|
if eflag and words[0] == "EXTRAMAKE" and words[1] == '=':
|
|
|
|
line = line.replace(words[2],"Makefile.lammps.%s" % lmpsuffix)
|
|
|
|
|
2017-08-09 04:57:27 +08:00
|
|
|
fp.write(line)
|
2017-05-05 01:22:20 +08:00
|
|
|
fp.close()
|
|
|
|
|
|
|
|
# perform make
|
|
|
|
# make operations copies EXTRAMAKE file to Makefile.lammps
|
|
|
|
|
|
|
|
if makeflag:
|
2017-08-09 04:57:27 +08:00
|
|
|
print("Building libgpu.a ...")
|
2018-11-29 09:46:50 +08:00
|
|
|
if os.path.exists("libgpu.a"):
|
|
|
|
os.remove("libgpu.a")
|
2017-05-05 01:22:20 +08:00
|
|
|
cmd = "make -f Makefile.auto clean; make -f Makefile.auto"
|
2017-08-09 04:57:27 +08:00
|
|
|
txt = subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
|
|
|
|
print(txt.decode('UTF-8'))
|
2017-05-05 01:22:20 +08:00
|
|
|
if not os.path.exists("libgpu.a"):
|
|
|
|
error("Build of lib/gpu/libgpu.a was NOT successful")
|
|
|
|
if not os.path.exists("Makefile.lammps"):
|
|
|
|
error("lib/gpu/Makefile.lammps was NOT created")
|
|
|
|
|
|
|
|
# copy new Makefile.auto to Makefile.osuffix
|
|
|
|
|
|
|
|
if outflag:
|
2017-08-09 04:57:27 +08:00
|
|
|
print("Creating new Makefile.%s" % osuffix)
|
2017-05-05 01:22:20 +08:00
|
|
|
cmd = "cp Makefile.auto Makefile.%s" % osuffix
|
2017-08-09 04:57:27 +08:00
|
|
|
subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
|