#
# This file is part of the GROMACS molecular simulation package.
#
-# Copyright (c) 2013, by the GROMACS development team, led by
-# David van der Spoel, Berk Hess, Erik Lindahl, and including many
-# others, as listed in the AUTHORS file in the top-level source
-# directory and at http://www.gromacs.org.
+# Copyright (c) 2013,2014, by the GROMACS development team, led by
+# Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
+# and including many others, as listed in the AUTHORS file in the
+# top-level source directory and at http://www.gromacs.org.
#
# GROMACS is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public License
#
# GROMACS is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# official version at http://www.gromacs.org.
#
# To help us fund GROMACS development, we humbly ask that you cite
-# the research papers on the package. Check out http://www.gromacs.org
+# the research papers on the package. Check out http://www.gromacs.org.
# This script is used by the GROMACS developers to build most of the
# files from which the nbnxn kernels are compiled. It is not called at
# kernel logic. A run-time error occurs if an inappropriate kernel
# dispatcher function is called (but that is normally impossible).
+import re
import sys
import os
+os.chdir(os.path.dirname(os.path.abspath(__file__)))
import collections # Requires Python 2.7
-
-FileHeader = \
-'/*\n' \
-' * This file is part of the GROMACS molecular simulation package.\n' \
-' *\n' \
-' * Copyright (c) 2012,2013, by the GROMACS development team, led by\n' \
-' * David van der Spoel, Berk Hess, Erik Lindahl, and including many\n' \
-' * others, as listed in the AUTHORS file in the top-level source\n' \
-' * directory and at http://www.gromacs.org.\n' \
-' *\n' \
-' * GROMACS is free software; you can redistribute it and/or\n' \
-' * modify it under the terms of the GNU Lesser General Public License\n' \
-' * as published by the Free Software Foundation; either version 2.1\n' \
-' * of the License, or (at your option) any later version.\n' \
-' *\n' \
-' * GROMACS is distributed in the hope that it will be useful,\n' \
-' * but WITHOUT ANY WARRANTY; without even the implied warranty of\n' \
-' * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n' \
-' * Lesser General Public License for more details.\n' \
-' *\n' \
-' * You should have received a copy of the GNU Lesser General Public\n' \
-' * License along with GROMACS; if not, see\n' \
-' * http://www.gnu.org/licenses, or write to the Free Software Foundation,\n' \
-' * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.\n' \
-' *\n' \
-' * If you want to redistribute modifications to GROMACS, please\n' \
-' * consider that scientific software is very special. Version\n' \
-' * control is crucial - bugs must be traceable. We will be happy to\n' \
-' * consider code for inclusion in the official distribution, but\n' \
-' * derived work must not be called official GROMACS. Details are found\n' \
-' * in the README & COPYING files - if they are missing, get the\n' \
-' * official version at http://www.gromacs.org.\n' \
-' *\n' \
-' * To help us fund GROMACS development, we humbly ask that you cite\n' \
-' * the research papers on the package. Check out http://www.gromacs.org.\n' \
-' */\n' \
-'/*\n' \
-' * Note: this file was generated by the Verlet kernel generator for\n' \
-' * kernel type {0}.\n' \
-' */\n\n'
+sys.path.append('../../../../../admin')
+from copyright import create_copyright_header
+
+FileHeader = create_copyright_header('2012,2013,2014')
+FileHeader += """/*
+ * Note: this file was generated by the Verlet kernel generator for
+ * kernel type {0}.
+ */
+
+"""
+
+def read_kernel_template(filename):
+ with open(filename, "r") as TemplateFile:
+ TemplateText = TemplateFile.read()
+ copyright_re = r'/\*\n \* This file is part of the GROMACS molecular simulation package\.\n( \*.*\n)* \*/\n'
+ match = re.match(copyright_re, TemplateText)
+ if match:
+ TemplateText = TemplateText[match.end():]
+ return TemplateText
# The dict order must match the order of an enumeration in
# nbnxn_kernel_simd_template.c.pre
ElectrostaticsDict = collections.OrderedDict()
-ElectrostaticsDict['rf'] = { 'define' : '#define CALC_COUL_RF' }
-ElectrostaticsDict['tab'] = { 'define' : '#define CALC_COUL_TAB' }
-ElectrostaticsDict['tab_twin'] = { 'define' : '#define CALC_COUL_TAB\n#define VDW_CUTOFF_CHECK /* Use twin-range cut-off */' }
-ElectrostaticsDict['ewald'] = { 'define' : '#define CALC_COUL_EWALD' }
-ElectrostaticsDict['ewald_twin'] = { 'define' : '#define CALC_COUL_EWALD\n#define VDW_CUTOFF_CHECK /* Use twin-range cut-off */' }
-
+ElectrostaticsDict['ElecRF'] = { 'define' : '#define CALC_COUL_RF' }
+ElectrostaticsDict['ElecQSTab'] = { 'define' : '#define CALC_COUL_TAB' }
+ElectrostaticsDict['ElecQSTabTwinCut'] = { 'define' : '#define CALC_COUL_TAB\n#define VDW_CUTOFF_CHECK /* Use twin-range cut-off */' }
+ElectrostaticsDict['ElecEw'] = { 'define' : '#define CALC_COUL_EWALD' }
+ElectrostaticsDict['ElecEwTwinCut'] = { 'define' : '#define CALC_COUL_EWALD\n#define VDW_CUTOFF_CHECK /* Use twin-range cut-off */' }
+
# The dict order must match the order of a C enumeration.
-LJCombinationRuleDict = collections.OrderedDict()
-LJCombinationRuleDict['geom'] = { 'define' : '#define LJ_COMB_GEOM' }
-LJCombinationRuleDict['lb'] = { 'define' : '#define LJ_COMB_LB' }
-LJCombinationRuleDict['none'] = { 'define' : '/* Use no LJ combination rule */' }
+VdwTreatmentDict = collections.OrderedDict()
+VdwTreatmentDict['VdwLJCombGeom'] = { 'define' : '#define LJ_CUT\n#define LJ_COMB_GEOM' }
+VdwTreatmentDict['VdwLJCombLB'] = { 'define' : '#define LJ_CUT\n#define LJ_COMB_LB' }
+VdwTreatmentDict['VdwLJ'] = { 'define' : '#define LJ_CUT\n/* Use full LJ combination matrix */' }
+VdwTreatmentDict['VdwLJFSw'] = { 'define' : '#define LJ_FORCE_SWITCH\n/* Use full LJ combination matrix */' }
+VdwTreatmentDict['VdwLJPSw'] = { 'define' : '#define LJ_POT_SWITCH\n/* Use full LJ combination matrix */' }
+VdwTreatmentDict['VdwLJEwCombGeom'] = { 'define' : '#define LJ_CUT\n#define LJ_EWALD_GEOM\n/* Use full LJ combination matrix + geometric rule for the grid correction */' }
# This is OK as an unordered dict
EnergiesComputationDict = {
- 'ener' : {
+ 'F' : {
+ 'function type' : 'nbk_func_noener',
+ 'define' : '/* Will not calculate energies */',
+ },
+ 'VF' : {
'function type' : 'nbk_func_ener',
'define' : '#define CALC_ENERGIES',
},
- 'energrp' : {
+ 'VgrpF' : {
'function type' : 'nbk_func_ener',
'define' : '#define CALC_ENERGIES\n#define ENERGY_GROUPS',
},
- 'noener' : {
- 'function type' : 'nbk_func_noener',
- 'define' : '/* Will not calculate energies */',
- },
}
# This is OK as an unordered dict
'2xnn' : {
'Define' : 'GMX_NBNXN_SIMD_2XNN',
'WidthSetup' : '/* Include the full-width SIMD macros */\n',
- 'WidthCheck' : ('#if !(GMX_SIMD_WIDTH_HERE == 8 || GMX_SIMD_WIDTH_HERE == 16)\n' \
+ 'WidthCheck' : ('#if !(GMX_SIMD_REAL_WIDTH == 8 || GMX_SIMD_REAL_WIDTH == 16)\n' \
'#error "unsupported SIMD width"\n' \
'#endif\n'),
'UnrollSize' : 2,
},
'4xn' : {
'Define' : 'GMX_NBNXN_SIMD_4XN',
- 'WidthSetup' : ('#ifdef GMX_NBNXN_HALF_WIDTH_SIMD\n' \
- '#define GMX_USE_HALF_WIDTH_SIMD_HERE\n' \
- '#endif\n'),
- 'WidthCheck' : ('#if !(GMX_SIMD_WIDTH_HERE == 2 || GMX_SIMD_WIDTH_HERE == 4 || GMX_SIMD_WIDTH_HERE == 8)\n' \
+ 'WidthSetup' : (''),
+ 'WidthCheck' : ('#if !(GMX_SIMD_REAL_WIDTH == 2 || GMX_SIMD_REAL_WIDTH == 4 || GMX_SIMD_REAL_WIDTH == 8)\n' \
'#error "unsupported SIMD width"\n' \
'#endif\n'),
'UnrollSize' : 1,
},
}
-with open ("nbnxn_kernel_simd_template.c.pre", "r") as KernelDispatcherTemplateFile:
- KernelDispatcherTemplate = KernelDispatcherTemplateFile.read()
-
-with open ("nbnxn_kernel_simd_template.h.pre", "r") as KernelsHeaderTemplateFile:
- KernelsHeaderTemplate = KernelsHeaderTemplateFile.read()
+KernelDispatcherTemplate = read_kernel_template("nbnxn_kernel_simd_template.c.pre")
+KernelsHeaderTemplate = read_kernel_template("nbnxn_kernel_simd_template.h.pre")
# For each Verlet kernel type, write three kinds of files:
# a header file defining the functions for all the kernels,
# for each kernel, a file defining the single C function for that kernel
for type in VerletKernelTypeDict:
DirName = "../simd_{0}".format(type)
- KernelNamePrefix = 'nbnxn_kernel_simd_{0}'.format(type)
- KernelsHeaderFileName = "{0}.h".format(KernelNamePrefix)
+ KernelNamePrefix = 'nbnxn_kernel'
+ KernelsName = "{0}_simd_{1}".format(KernelNamePrefix,type)
+ KernelsHeaderFileName = "{0}.h".format(KernelsName,type)
+ KernelsHeaderPathName = "gromacs/mdlib/nbnxn_kernels/simd_{0}/{1}".format(type,KernelsHeaderFileName)
KernelFunctionLookupTable = {}
KernelDeclarations = ''
- with open ("{1}_kernel.c.pre".format(DirName,KernelNamePrefix), "r") as KernelTemplateFile:
- KernelTemplate = KernelTemplateFile.read()
+ KernelTemplate = read_kernel_template("{0}_kernel.c.pre".format(KernelsName))
# Loop over all kernels
for ener in EnergiesComputationDict:
KernelFunctionLookupTable[ener] = '{\n'
for elec in ElectrostaticsDict:
KernelFunctionLookupTable[ener] += ' {\n'
- for ljcomb in LJCombinationRuleDict:
- KernelName = ('{0}_{1}_comb_{2}_{3}'
- .format(KernelNamePrefix,elec,ljcomb,ener))
+ for ljtreat in VdwTreatmentDict:
+ KernelName = ('{0}_{1}_{2}_{3}_{4}'
+ .format(KernelNamePrefix,elec,ljtreat,ener,type))
# Declare the kernel function
KernelDeclarations += ('{1:21} {0};\n'
kernelfp.write(KernelTemplate
.format(VerletKernelTypeDict[type]['Define'],
ElectrostaticsDict[elec]['define'],
- LJCombinationRuleDict[ljcomb]['define'],
+ VdwTreatmentDict[ljtreat]['define'],
EnergiesComputationDict[ener]['define'],
- KernelsHeaderFileName,
+ KernelsHeaderPathName,
KernelName,
" " * (len(KernelName) + 1),
VerletKernelTypeDict[type]['UnrollSize'],
with open('{0}/{1}'.format(DirName,KernelsHeaderFileName),'w') as fp:
fp.write(FileHeader.format(type))
fp.write(KernelsHeaderTemplate
- .format(KernelNamePrefix,
- " " * (len(KernelNamePrefix) + 1),
+ .format(KernelsName,
+ " " * (len(KernelsName) + 1),
KernelDeclarations))
# Write the file defining the kernel dispatcher
# function for this type
- with open('{0}/{1}'.format(DirName,"{0}.c".format(KernelNamePrefix)),'w') as fp:
+ with open('{0}/{1}'.format(DirName,"{0}.c".format(KernelsName,type)),'w') as fp:
fp.write(FileHeader.format(type))
fp.write(KernelDispatcherTemplate
.format(VerletKernelTypeDict[type]['Define'],
VerletKernelTypeDict[type]['WidthCheck'],
VerletKernelTypeDict[type]['UnrollSize'],
KernelsHeaderFileName,
- KernelNamePrefix,
- ' ' * (len(KernelNamePrefix)+1),
- KernelFunctionLookupTable['ener'],
- KernelFunctionLookupTable['energrp'],
- KernelFunctionLookupTable['noener'],
+ KernelsName,
+ ' ' * (len(KernelsName)+1),
+ KernelFunctionLookupTable['F'],
+ KernelFunctionLookupTable['VF'],
+ KernelFunctionLookupTable['VgrpF'],
)
)