some cleanups and small bugfixes to conform better with python conventions
This commit is contained in:
@ -1,20 +1,23 @@
|
||||
#!/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
|
||||
"""
|
||||
Install.py tool to build the GPU library
|
||||
used to automate the steps described in the README file in this dir
|
||||
"""
|
||||
|
||||
from __future__ import print_function
|
||||
import sys,os,subprocess,shutil
|
||||
import sys, os, subprocess, shutil
|
||||
from argparse import ArgumentParser
|
||||
|
||||
sys.path.append('..')
|
||||
from install_helpers import get_cpus
|
||||
from argparse import ArgumentParser
|
||||
|
||||
parser = ArgumentParser(prog='Install.py',
|
||||
description="LAMMPS library build wrapper script")
|
||||
|
||||
# help message
|
||||
|
||||
help = """
|
||||
HELP = """
|
||||
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
|
||||
|
||||
@ -41,10 +44,10 @@ parser.add_argument("-b", "--build", action="store_true",
|
||||
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'],
|
||||
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'],
|
||||
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>")
|
||||
@ -56,9 +59,9 @@ parser.add_argument("-o", "--output",
|
||||
args = parser.parse_args()
|
||||
|
||||
# print help message and exit, if neither build nor output options are given
|
||||
if args.build == False and not args.output:
|
||||
if not args.build and not args.output:
|
||||
parser.print_help()
|
||||
sys.exit(help)
|
||||
sys.exit(HELP)
|
||||
|
||||
hflag = 0
|
||||
eflag = 0
|
||||
@ -71,9 +74,12 @@ if args.build:
|
||||
isuffix = args.machine
|
||||
arch = args.arch
|
||||
|
||||
if args.precision == "double": precstr = "-D_DOUBLE_DOUBLE"
|
||||
elif args.precision == "mixed": precstr = "-D_SINGLE_DOUBLE"
|
||||
else: precstr = "-D_SINGLE_SINGLE"
|
||||
if args.precision == "double":
|
||||
precstr = "-D_DOUBLE_DOUBLE"
|
||||
elif args.precision == "mixed":
|
||||
precstr = "-D_SINGLE_DOUBLE"
|
||||
else:
|
||||
precstr = "-D_SINGLE_SINGLE"
|
||||
|
||||
lmpsuffix = args.extramake
|
||||
|
||||
@ -91,8 +97,8 @@ if args.output:
|
||||
if not os.path.exists("Makefile.%s" % isuffix):
|
||||
sys.exit("lib/gpu/Makefile.%s does not exist" % isuffix)
|
||||
|
||||
lines = open("Makefile.%s" % isuffix,'r').readlines()
|
||||
fp = open("Makefile.auto",'w')
|
||||
lines = open("Makefile.%s" % isuffix, 'r').readlines()
|
||||
fp = open("Makefile.auto", 'w')
|
||||
|
||||
for line in lines:
|
||||
words = line.split()
|
||||
@ -101,13 +107,13 @@ for line in lines:
|
||||
continue
|
||||
|
||||
if hflag and words[0] == "CUDA_HOME" and words[1] == '=':
|
||||
line = line.replace(words[2],hdir)
|
||||
line = line.replace(words[2], hdir)
|
||||
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 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] == '=':
|
||||
line = line.replace(words[2],"Makefile.lammps.%s" % lmpsuffix)
|
||||
line = line.replace(words[2], "Makefile.lammps.%s" % lmpsuffix)
|
||||
|
||||
fp.write(line)
|
||||
fp.close()
|
||||
@ -122,7 +128,7 @@ if makeflag:
|
||||
n_cpus = get_cpus()
|
||||
cmd = "make -f Makefile.auto clean; make -f Makefile.auto -j%d" % n_cpus
|
||||
try:
|
||||
txt = subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
|
||||
txt = subprocess.check_output(cmd, stderr=subprocess.STDOUT, shell=True)
|
||||
print(txt.decode('UTF-8'))
|
||||
except subprocess.CalledProcessError as e:
|
||||
print("Make failed with:\n %s" % e.output.decode('UTF-8'))
|
||||
@ -138,4 +144,3 @@ if makeflag:
|
||||
if outflag:
|
||||
print("Creating new Makefile.%s" % osuffix)
|
||||
shutil.copyfile("Makefile.auto", "Makefile.%s" % osuffix)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user