make gpu library Install.py use argparse module
This commit is contained in:
@ -95,6 +95,7 @@ which GPU hardware to build for.
|
|||||||
|
|
||||||
GPU_ARCH settings for different GPU hardware is as follows:
|
GPU_ARCH settings for different GPU hardware is as follows:
|
||||||
|
|
||||||
|
sm_12 or sm_13 for GT200 (supported by CUDA 3.2 until CUDA 6.5)
|
||||||
sm_20 or sm_21 for Fermi (supported by CUDA 3.2 until CUDA 7.5)
|
sm_20 or sm_21 for Fermi (supported by CUDA 3.2 until CUDA 7.5)
|
||||||
sm_30 or sm_35 or sm_37 for Kepler (supported since CUDA 5)
|
sm_30 or sm_35 or sm_37 for Kepler (supported since CUDA 5)
|
||||||
sm_50 or sm_52 for Maxwell (supported since CUDA 6)
|
sm_50 or sm_52 for Maxwell (supported since CUDA 6)
|
||||||
@ -135,7 +136,7 @@ specified by the "-m" switch. For your convenience, machine makefiles
|
|||||||
for "mpi" and "serial" are provided, which have the same settings as
|
for "mpi" and "serial" are provided, which have the same settings as
|
||||||
the corresponding machine makefiles in the main LAMMPS source
|
the corresponding machine makefiles in the main LAMMPS source
|
||||||
folder. In addition you can alter 4 important settings in the
|
folder. In addition you can alter 4 important settings in the
|
||||||
Makefile.machine you start from via the corresponding -h, -a, -p, -e
|
Makefile.machine you start from via the corresponding -c, -a, -p, -e
|
||||||
switches (as in the examples above), and also save a copy of the new
|
switches (as in the examples above), and also save a copy of the new
|
||||||
Makefile if desired:
|
Makefile if desired:
|
||||||
|
|
||||||
|
|||||||
@ -4,9 +4,13 @@
|
|||||||
# used to automate the steps described in the README file in this dir
|
# used to automate the steps described in the README file in this dir
|
||||||
|
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
import sys,os,subprocess
|
import sys,os,subprocess,shutil
|
||||||
sys.path.append('..')
|
sys.path.append('..')
|
||||||
from install_helpers import error,get_cpus
|
from install_helpers import get_cpus
|
||||||
|
from argparse import ArgumentParser
|
||||||
|
|
||||||
|
parser = ArgumentParser(prog='Install.py',
|
||||||
|
description="LAMMPS library build wrapper script")
|
||||||
|
|
||||||
# help message
|
# help message
|
||||||
|
|
||||||
@ -23,29 +27,6 @@ optionally uses Makefile.auto to build the GPU library -> libgpu.a
|
|||||||
and to copy a Makefile.lammps.esuffix -> Makefile.lammps
|
and to copy a Makefile.lammps.esuffix -> Makefile.lammps
|
||||||
optionally copies Makefile.auto to a new Makefile.osuffix
|
optionally copies Makefile.auto to a new Makefile.osuffix
|
||||||
|
|
||||||
-m = use Makefile.machine as starting point, copy to Makefile.auto
|
|
||||||
default machine = linux
|
|
||||||
default for -h, -a, -p, -e settings are those in -m Makefile
|
|
||||||
-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
|
|
||||||
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
|
|
||||||
-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
|
|
||||||
-b = make the GPU library using Makefile.auto
|
|
||||||
first performs a "make clean"
|
|
||||||
then produces libgpu.a if successful
|
|
||||||
also copies EXTRAMAKE file -> Makefile.lammps
|
|
||||||
-e can set which Makefile.lammps.esuffix file is copied
|
|
||||||
-o = copy final Makefile.auto to Makefile.osuffix
|
|
||||||
|
|
||||||
Examples:
|
Examples:
|
||||||
|
|
||||||
make lib-gpu args="-b" # build GPU lib with default Makefile.linux
|
make lib-gpu args="-b" # build GPU lib with default Makefile.linux
|
||||||
@ -53,58 +34,56 @@ make lib-gpu args="-m xk7 -p single -o xk7.single" # create new Makefile.xk
|
|||||||
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
|
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
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# parse args
|
# parse and process arguments
|
||||||
|
|
||||||
args = sys.argv[1:]
|
parser.add_argument("-b", "--build", action="store_true",
|
||||||
nargs = len(args)
|
help="build the GPU library from scratch from a customized Makefile.auto")
|
||||||
if nargs == 0: error(help=help)
|
parser.add_argument("-m", "--machine", default='linux',
|
||||||
|
help="suffix of Makefile.machine used as base for customizing Makefile.auto")
|
||||||
|
parser.add_argument("-a", "--arch", default='sm_30',
|
||||||
|
choices=['sm_12','sm_13','sm_20','sm_21','sm_30','sm_35','sm_37',
|
||||||
|
'sm_50','sm_52','sm_60','sm_61','sm_70','sm_75'],
|
||||||
|
help="set GPU architecture and instruction set (default: 'sm_30')")
|
||||||
|
parser.add_argument("-p", "--precision", default='mixed', choices=['single','mixed','double'],
|
||||||
|
help="set GPU kernel precision mode (default: mixed)")
|
||||||
|
parser.add_argument("-e", "--extramake", default='standard',
|
||||||
|
help="set EXTRAMAKE variable in Makefile.auto to Makefile.lammps.<extramake>")
|
||||||
|
parser.add_argument("-c", "--cuda",
|
||||||
|
help="set CUDA_HOME variable in Makefile.auto. Will be used if $CUDA_HOME environment variable is not set")
|
||||||
|
parser.add_argument("-o", "--output",
|
||||||
|
help="if set, copy final Makefile.auto to Makefile.<output> for later re-use")
|
||||||
|
|
||||||
isuffix = "linux"
|
args = parser.parse_args()
|
||||||
hflag = aflag = pflag = eflag = 0
|
|
||||||
|
# print help message and exit, if neither build nor output options are given
|
||||||
|
if args.build == False and not args.output:
|
||||||
|
parser.print_help()
|
||||||
|
sys.exit(help)
|
||||||
|
|
||||||
|
hflag = 0
|
||||||
|
eflag = 0
|
||||||
makeflag = 0
|
makeflag = 0
|
||||||
outflag = 0
|
outflag = 0
|
||||||
|
|
||||||
iarg = 0
|
if args.build:
|
||||||
while iarg < nargs:
|
makeflag = 1
|
||||||
if args[iarg] == "-m":
|
|
||||||
if iarg+2 > nargs: error(help=help)
|
|
||||||
isuffix = args[iarg+1]
|
|
||||||
iarg += 2
|
|
||||||
elif args[iarg] == "-h":
|
|
||||||
if iarg+2 > nargs: error(help=help)
|
|
||||||
hflag = 1
|
|
||||||
hdir = args[iarg+1]
|
|
||||||
iarg += 2
|
|
||||||
elif args[iarg] == "-a":
|
|
||||||
if iarg+2 > nargs: error(help=help)
|
|
||||||
aflag = 1
|
|
||||||
arch = args[iarg+1]
|
|
||||||
iarg += 2
|
|
||||||
elif args[iarg] == "-p":
|
|
||||||
if iarg+2 > nargs: error(help=help)
|
|
||||||
pflag = 1
|
|
||||||
precision = args[iarg+1]
|
|
||||||
iarg += 2
|
|
||||||
elif args[iarg] == "-e":
|
|
||||||
if iarg+2 > nargs: error(help=help)
|
|
||||||
eflag = 1
|
|
||||||
lmpsuffix = args[iarg+1]
|
|
||||||
iarg += 2
|
|
||||||
elif args[iarg] == "-b":
|
|
||||||
makeflag = 1
|
|
||||||
iarg += 1
|
|
||||||
elif args[iarg] == "-o":
|
|
||||||
if iarg+2 > nargs: error(help=help)
|
|
||||||
outflag = 1
|
|
||||||
osuffix = args[iarg+1]
|
|
||||||
iarg += 2
|
|
||||||
else: error(help=help)
|
|
||||||
|
|
||||||
if pflag:
|
isuffix = args.machine
|
||||||
if precision == "double": precstr = "-D_DOUBLE_DOUBLE"
|
arch = args.arch
|
||||||
elif precision == "mixed": precstr = "-D_SINGLE_DOUBLE"
|
|
||||||
elif precision == "single": precstr = "-D_SINGLE_SINGLE"
|
if args.precision == "double": precstr = "-D_DOUBLE_DOUBLE"
|
||||||
else: error("Invalid precision setting")
|
elif args.precision == "mixed": precstr = "-D_SINGLE_DOUBLE"
|
||||||
|
else: precstr = "-D_SINGLE_SINGLE"
|
||||||
|
|
||||||
|
lmpsuffix = args.extramake
|
||||||
|
|
||||||
|
if args.cuda:
|
||||||
|
hflag = 1
|
||||||
|
hdir = args.cuda
|
||||||
|
|
||||||
|
if args.output:
|
||||||
|
outflag = 1
|
||||||
|
osuffix = args.output
|
||||||
|
|
||||||
# create Makefile.auto
|
# create Makefile.auto
|
||||||
# reset EXTRAMAKE, CUDA_HOME, CUDA_ARCH, CUDA_PRECISION if requested
|
# reset EXTRAMAKE, CUDA_HOME, CUDA_ARCH, CUDA_PRECISION if requested
|
||||||
@ -123,9 +102,9 @@ for line in lines:
|
|||||||
|
|
||||||
if hflag and words[0] == "CUDA_HOME" and words[1] == '=':
|
if hflag and words[0] == "CUDA_HOME" and words[1] == '=':
|
||||||
line = line.replace(words[2],hdir)
|
line = line.replace(words[2],hdir)
|
||||||
if aflag and words[0] == "CUDA_ARCH" and words[1] == '=':
|
if words[0] == "CUDA_ARCH" and words[1] == '=':
|
||||||
line = line.replace(words[2],"-arch=%s" % arch)
|
line = line.replace(words[2],"-arch=%s" % arch)
|
||||||
if pflag and words[0] == "CUDA_PRECISION" and words[1] == '=':
|
if words[0] == "CUDA_PRECISION" and words[1] == '=':
|
||||||
line = line.replace(words[2],precstr)
|
line = line.replace(words[2],precstr)
|
||||||
if eflag and words[0] == "EXTRAMAKE" and words[1] == '=':
|
if eflag and words[0] == "EXTRAMAKE" and words[1] == '=':
|
||||||
line = line.replace(words[2],"Makefile.lammps.%s" % lmpsuffix)
|
line = line.replace(words[2],"Makefile.lammps.%s" % lmpsuffix)
|
||||||
@ -158,5 +137,5 @@ if makeflag:
|
|||||||
|
|
||||||
if outflag:
|
if outflag:
|
||||||
print("Creating new Makefile.%s" % osuffix)
|
print("Creating new Makefile.%s" % osuffix)
|
||||||
cmd = "cp Makefile.auto Makefile.%s" % osuffix
|
shutil.copyfile("Makefile.auto", "Makefile.%s" % osuffix)
|
||||||
subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
|
|
||||||
|
|||||||
Reference in New Issue
Block a user