From 4758e43a2ecc3f0ea826476c45d4936cab5abb13 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 11 Jan 2021 10:18:09 -0500 Subject: [PATCH 01/12] add support for setting -DLMP_GPU when the GPU package is installed --- cmake/Modules/Packages/GPU.cmake | 1 + src/GPU/Install.sh | 3 +++ 2 files changed, 4 insertions(+) diff --git a/cmake/Modules/Packages/GPU.cmake b/cmake/Modules/Packages/GPU.cmake index cad6e2bf9a..bc66ef04d2 100644 --- a/cmake/Modules/Packages/GPU.cmake +++ b/cmake/Modules/Packages/GPU.cmake @@ -2,6 +2,7 @@ set(GPU_SOURCES_DIR ${LAMMPS_SOURCE_DIR}/GPU) set(GPU_SOURCES ${GPU_SOURCES_DIR}/gpu_extra.h ${GPU_SOURCES_DIR}/fix_gpu.h ${GPU_SOURCES_DIR}/fix_gpu.cpp) +target_compile_definitions(lammps PRIVATE -DLMP_GPU) set(GPU_API "opencl" CACHE STRING "API used by GPU package") set(GPU_API_VALUES opencl cuda hip) diff --git a/src/GPU/Install.sh b/src/GPU/Install.sh index b83423eaa7..1fefb01d42 100755 --- a/src/GPU/Install.sh +++ b/src/GPU/Install.sh @@ -152,6 +152,8 @@ if (test $1 = 1) then if (test -e ../Makefile.package) then sed -i -e 's/[^ \t]*gpu[^ \t]* //' ../Makefile.package + sed -i -e 's/[^ \t]*GPU[^ \t]* //' ../Makefile.package + sed -i -e 's|^PKG_INC =[ \t]*|&-DLMP_GPU |' ../Makefile.package sed -i -e 's|^PKG_PATH =[ \t]*|&-L../../lib/gpu |' ../Makefile.package sed -i -e 's|^PKG_LIB =[ \t]*|&-lgpu |' ../Makefile.package sed -i -e 's|^PKG_SYSINC =[ \t]*|&$(gpu_SYSINC) |' ../Makefile.package @@ -171,6 +173,7 @@ elif (test $1 = 0) then if (test -e ../Makefile.package) then sed -i -e 's/[^ \t]*gpu[^ \t]* //' ../Makefile.package + sed -i -e 's/[^ \t]*GPU[^ \t]* //' ../Makefile.package fi if (test -e ../Makefile.package.settings) then From c5298c24be997b3a3787cb0504f5e0ec2e5af076 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 11 Jan 2021 11:08:22 -0500 Subject: [PATCH 02/12] start creating API for querying accelerator package features --- src/info.cpp | 41 +++++++++++++++++++++++++++++++++++++++-- src/info.h | 5 ++++- 2 files changed, 43 insertions(+), 3 deletions(-) diff --git a/src/info.cpp b/src/info.cpp index bb3111cb69..8e181a79ed 100644 --- a/src/info.cpp +++ b/src/info.cpp @@ -1120,15 +1120,52 @@ bool Info::has_exceptions() { #endif } -bool Info::has_package(const char * package_name) { +bool Info::has_package(const std::string &package_name) { for (int i = 0; LAMMPS::installed_packages[i] != nullptr; ++i) { - if (strcmp(package_name, LAMMPS::installed_packages[i]) == 0) { + if (package_name == LAMMPS::installed_packages[i]) { return true; } } return false; } +bool Info::has_accelerator_feature(const std::string &package, + const std::string &category, + const std::string &setting) +{ +#if defined(LMP_KOKKOS) + if (package == "KOKKOS") { + if (category == "precision") { + if (setting == "double") return true; + else return false; + } + } +#endif +#if defined(LMP_GPU) + if (package == "GPU") { + } +#endif +#if defined(LMP_USER_OMP) + if (package == "OPENMP") { + if (category == "precision") { + if (setting == "double") return true; + else return false; + } + } +#endif +#if defined(LMP_USER_INTEL) + if (package == "INTEL") { + if (category == "precision") { + if (setting == "double") return true; + else if (setting == "mixed") return true; + else if (setting == "single")return true; + else return false; + } + } +#endif + return false; +} + /* ---------------------------------------------------------------------- */ #define _INFOBUF_SIZE 256 diff --git a/src/info.h b/src/info.h index e14a2be8db..d8fa23489e 100644 --- a/src/info.h +++ b/src/info.h @@ -43,7 +43,10 @@ class Info : protected Pointers { static bool has_jpeg_support(); static bool has_ffmpeg_support(); static bool has_exceptions(); - static bool has_package(const char * package_name); + static bool has_package(const std::string &); + static bool has_accelerator_feature(const std::string &, + const std::string &, + const std::string &); static std::string get_os_info(); static std::string get_compiler_info(); From 56909e88b1dcf6b3c1d65a6ef54072d55fffe5a4 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 11 Jan 2021 17:03:23 -0500 Subject: [PATCH 03/12] implement accelerator introspection for GPU package --- lib/gpu/lal_device.cpp | 36 ++++++++++++++++++++++++++++++++++++ src/info.cpp | 25 +++++++++++++++++++++++++ 2 files changed, 61 insertions(+) diff --git a/lib/gpu/lal_device.cpp b/lib/gpu/lal_device.cpp index 6c6a206307..911cdda383 100644 --- a/lib/gpu/lal_device.cpp +++ b/lib/gpu/lal_device.cpp @@ -783,3 +783,39 @@ double lmp_gpu_forces(double **f, double **tor, double *eatom, double **vatom, double *virial, double &ecoul) { return global_device.fix_gpu(f,tor,eatom,vatom,virial,ecoul); } + +bool lmp_gpu_config(const std::string &category, const std::string &setting) +{ + if (category == "api") { +#if defined(USE_OPENCL) + return setting == "opencl"; +#elif defined(USE_HIP) + return setting == "hip"; +#elif defined(USE_CUDA) + return setting == "cuda"; +#endif + return false; + } + if (category == "precision") { + if (setting == "single") { +#if defined(_SINGLE_SINGLE) + return true; +#else + return false; +#endif + } else if (setting == "mixed") { +#if defined(_SINGLE_DOUBLE) + return true; +#else + return false; +#endif + } else if (setting == "double") { +#if defined(_DOUBLE_DOUBLE) + return true; +#else + return false; +#endif + } else return false; + } + return false; +} diff --git a/src/info.cpp b/src/info.cpp index 8e181a79ed..d18bd68171 100644 --- a/src/info.cpp +++ b/src/info.cpp @@ -94,6 +94,7 @@ enum {COMPUTES=1<<0, REGION_STYLES=1<<23, DUMP_STYLES=1<<24, COMMAND_STYLES=1<<25, + ACCELERATOR=1<<26, ALL=~0}; static const int STYLES = ATOM_STYLES | INTEGRATE_STYLES | MINIMIZE_STYLES @@ -198,6 +199,9 @@ void Info::command(int narg, char **arg) } else if (strncmp(arg[idx],"coeffs",3) == 0) { flags |= COEFFS; ++idx; + } else if (strncmp(arg[idx],"accelerator",3) == 0) { + flags |= ACCELERATOR; + ++idx; } else if (strncmp(arg[idx],"styles",3) == 0) { if (idx+1 < narg) { ++idx; @@ -314,6 +318,22 @@ void Info::command(int narg, char **arg) fputs("\n",out); } + if (flags & ACCELERATOR) { + fputs("\nAccelerator configuration:\n\n",out); + std::string mesg; + if (has_package("GPU")) { + mesg = "GPU package API: "; + if (has_accelerator_feature("GPU","api","cuda")) mesg += "CUDA\n"; + if (has_accelerator_feature("GPU","api","hip")) mesg += "HIP\n"; + if (has_accelerator_feature("GPU","api","opencl")) mesg += "OpenCL\n"; + mesg += "GPU package precision: "; + if (has_accelerator_feature("GPU","precision","single")) mesg += "single\n"; + if (has_accelerator_feature("GPU","precision","mixed")) mesg += "mixed\n"; + if (has_accelerator_feature("GPU","precision","double")) mesg += "double\n"; + fputs(mesg.c_str(),out); + } + } + if (flags & MEMORY) { double meminfo[3]; @@ -1129,6 +1149,10 @@ bool Info::has_package(const std::string &package_name) { return false; } +#if defined(LMP_GPU) +extern bool lmp_gpu_config(const std::string &, const std::string &); +#endif + bool Info::has_accelerator_feature(const std::string &package, const std::string &category, const std::string &setting) @@ -1143,6 +1167,7 @@ bool Info::has_accelerator_feature(const std::string &package, #endif #if defined(LMP_GPU) if (package == "GPU") { + return lmp_gpu_config(category,setting); } #endif #if defined(LMP_USER_OMP) From 2b1a93bd15b044e9ddd39c5d3670c0e4024d4403 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 11 Jan 2021 23:12:05 -0500 Subject: [PATCH 04/12] expand accelerator output options --- src/info.cpp | 64 +++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 56 insertions(+), 8 deletions(-) diff --git a/src/info.cpp b/src/info.cpp index d18bd68171..f9394a1433 100644 --- a/src/info.cpp +++ b/src/info.cpp @@ -322,14 +322,51 @@ void Info::command(int narg, char **arg) fputs("\nAccelerator configuration:\n\n",out); std::string mesg; if (has_package("GPU")) { - mesg = "GPU package API: "; - if (has_accelerator_feature("GPU","api","cuda")) mesg += "CUDA\n"; - if (has_accelerator_feature("GPU","api","hip")) mesg += "HIP\n"; - if (has_accelerator_feature("GPU","api","opencl")) mesg += "OpenCL\n"; - mesg += "GPU package precision: "; - if (has_accelerator_feature("GPU","precision","single")) mesg += "single\n"; - if (has_accelerator_feature("GPU","precision","mixed")) mesg += "mixed\n"; - if (has_accelerator_feature("GPU","precision","double")) mesg += "double\n"; + mesg = "GPU package API:"; + if (has_accelerator_feature("GPU","api","cuda")) mesg += " CUDA"; + if (has_accelerator_feature("GPU","api","hip")) mesg += " HIP"; + if (has_accelerator_feature("GPU","api","opencl")) mesg += " OpenCL"; + mesg += "\nGPU package precision:"; + if (has_accelerator_feature("GPU","precision","single")) mesg += " single"; + if (has_accelerator_feature("GPU","precision","mixed")) mesg += " mixed"; + if (has_accelerator_feature("GPU","precision","double")) mesg += " double"; + mesg += "\n"; + fputs(mesg.c_str(),out); + } + if (has_package("KOKKOS")) { + mesg = "KOKKOS package API:"; + if (has_accelerator_feature("KOKKOS","api","cuda")) mesg += " CUDA"; + if (has_accelerator_feature("KOKKOS","api","hip")) mesg += " HIP"; + if (has_accelerator_feature("KOKKOS","api","knl")) mesg += " KNL"; + if (has_accelerator_feature("KOKKOS","api","opencl")) mesg += " OpenCL"; + if (has_accelerator_feature("KOKKOS","api","openmp")) mesg += " OpenMP"; + if (has_accelerator_feature("KOKKOS","api","pthreads")) mesg += " Pthreads"; + mesg += "\nKOKKOS package precision:"; + if (has_accelerator_feature("KOKKOS","precision","single")) mesg += " single"; + if (has_accelerator_feature("KOKKOS","precision","mixed")) mesg += " mixed"; + if (has_accelerator_feature("KOKKOS","precision","double")) mesg += " double"; + mesg += "\n"; + fputs(mesg.c_str(),out); + } + if (has_package("USER-OMP")) { + mesg = "USER-OMP package API:"; + if (has_accelerator_feature("OPENMP","api","openmp")) mesg += " OpenMP"; + mesg += "\nUSER-OMP package precision:"; + if (has_accelerator_feature("OPENMP","precision","single")) mesg += " single"; + if (has_accelerator_feature("OPENMP","precision","mixed")) mesg += " mixed"; + if (has_accelerator_feature("OPENMP","precision","double")) mesg += " double"; + mesg += "\n"; + fputs(mesg.c_str(),out); + } + if (has_package("USER-INTEL")) { + mesg = "USER-INTEL package API:"; + if (has_accelerator_feature("INTEL","api","knl")) mesg += " KNL"; + if (has_accelerator_feature("INTEL","api","openmp")) mesg += " OpenMP"; + mesg += "\nUSER-INTEL package precision:"; + if (has_accelerator_feature("INTEL","precision","single")) mesg += " single"; + if (has_accelerator_feature("INTEL","precision","mixed")) mesg += " mixed"; + if (has_accelerator_feature("INTEL","precision","double")) mesg += " double"; + mesg += "\n"; fputs(mesg.c_str(),out); } } @@ -1176,6 +1213,13 @@ bool Info::has_accelerator_feature(const std::string &package, if (setting == "double") return true; else return false; } + if (category == "api") { +#if defined(_OPENMP) + if (setting == "openmp") return true; + else return false; +#endif + return false; + } } #endif #if defined(LMP_USER_INTEL) @@ -1186,6 +1230,10 @@ bool Info::has_accelerator_feature(const std::string &package, else if (setting == "single")return true; else return false; } + if (category == "api") { + if (setting == "openmp") return true; + else return false; + } } #endif return false; From 3d3590f02dd2959c18c9e4a71f3603bdb2e32a2e Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 12 Jan 2021 20:10:47 -0500 Subject: [PATCH 05/12] add c-library interface and export to python --- python/lammps/core.py | 28 ++++++++++++++++++++++++++++ src/library.cpp | 25 +++++++++++++++++++++++++ src/library.h | 2 ++ 3 files changed, 55 insertions(+) diff --git a/python/lammps/core.py b/python/lammps/core.py index c0cbaac533..01a3cce842 100644 --- a/python/lammps/core.py +++ b/python/lammps/core.py @@ -243,6 +243,7 @@ class lammps(object): self.lib.lammps_encode_image_flags.restype = self.c_imageint self.lib.lammps_config_package_name.argtypes = [c_int, c_char_p, c_int] + self.lib.lammps_config_accelerator.argtypes = [c_char_p, c_char_p, c_char_p] self.lib.lammps_set_variable.argtypes = [c_void_p, c_char_p, c_char_p] @@ -1435,6 +1436,33 @@ class lammps(object): # ------------------------------------------------------------------------- + @property + def accelerator_config(self): + """ Return table with available accelerator configuration settings. + + This is a wrapper around the :cpp:func:`lammps_config_accelerator` + function of the library interface which loops over all known packages + and settings and returns enabled features as a nested dictionary. + + :return: nested dictionary with all known enabled settings + :rtype: dictionary + """ + + result = {} + for p in [b'GPU', b'KOKKOS', b'USER-INTEL', b'USER-OMP']: + c = b'api' + result[p.decode()] = {} + for s in [b'cuda', b'hip', b'pthreads', b'opencl', b'openmp']: + if self.lib.lammps_config_accelerator(p,c,s): + result[p.decode()][c.decode()] = s.decode() + c = b'precision' + for s in [b'double', b'mixed', b'single']: + if self.lib.lammps_config_accelerator(p,c,s): + result[p.decode()][c.decode()] = s.decode() + return result + + # ------------------------------------------------------------------------- + @property def installed_packages(self): """ List of the names of enabled packages in the LAMMPS shared library diff --git a/src/library.cpp b/src/library.cpp index 7d3f2f8996..a4cfee979a 100644 --- a/src/library.cpp +++ b/src/library.cpp @@ -4303,6 +4303,31 @@ int lammps_config_package_name(int idx, char *buffer, int buf_size) { return 1; } +/** Check for compile time settings in accelerator packages included in LAMMPS. + * +\verbatim embed:rst +This function checks availability of compile time settings of included +:doc:`accelerator packages ` in LAMMPS. +Supported packages names are "GPU", "KOKKOS", "USER-INTEL", and "USER-OMP". +Supported categories are "api" with possible settings "cuda", "hip", "knl", +"pthreads", "opencl", "openmp", and "none", and "precision" with +possible settings "double", "mixed", and "single". If the combination +of package, category, and setting is available, the function returns 1, +otherwise 0. +\endverbatim + * + * \param package string with the name of the accelerator package + * \param category string with the category name of the setting + * \param setting string with the name of the specific setting + * \return 1 if available, 0 if not. + */ +int lammps_config_accelerator(const char *package, + const char *category, + const char *setting) +{ + return Info::has_accelerator_feature(package,category,setting) ? 1 : 0; +} + /* ---------------------------------------------------------------------- */ /** Check if a specific style has been included in LAMMPS diff --git a/src/library.h b/src/library.h index 14be4064ea..d98bf426b3 100644 --- a/src/library.h +++ b/src/library.h @@ -195,6 +195,8 @@ int lammps_config_has_package(const char *); int lammps_config_package_count(); int lammps_config_package_name(int, char *, int); +int lammps_config_accelerator(const char *, const char *, const char *); + int lammps_has_style(void *, const char *, const char *); int lammps_style_count(void *, const char *); int lammps_style_name(void *, const char *, int, char *, int); From 702de49f59f9464a95f691985fa9238af3f622ac Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 12 Jan 2021 20:11:38 -0500 Subject: [PATCH 06/12] add documentation for added keyword and library interface functions --- doc/src/Library_config.rst | 6 ++++++ doc/src/Python_config.rst | 4 +++- doc/src/info.rst | 6 +++++- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/doc/src/Library_config.rst b/doc/src/Library_config.rst index 24c412a23d..a5b87e23a7 100644 --- a/doc/src/Library_config.rst +++ b/doc/src/Library_config.rst @@ -14,6 +14,7 @@ This section documents the following functions: - :cpp:func:`lammps_config_has_package` - :cpp:func:`lammps_config_package_count` - :cpp:func:`lammps_config_package_name` +- :cpp:func:`lammps_config_accelerator` - :cpp:func:`lammps_has_style` - :cpp:func:`lammps_style_count` - :cpp:func:`lammps_style_name` @@ -126,6 +127,11 @@ approach. ----------------------- +.. doxygenfunction:: lammps_config_accelerator + :project: progguide + +----------------------- + .. doxygenfunction:: lammps_has_style :project: progguide diff --git a/doc/src/Python_config.rst b/doc/src/Python_config.rst index 2803b041c5..38f0ef0baf 100644 --- a/doc/src/Python_config.rst +++ b/doc/src/Python_config.rst @@ -39,7 +39,9 @@ about compile time settings and included packages and styles. * :py:attr:`lammps.has_jpeg_support ` * :py:attr:`lammps.has_ffmpeg_support ` -* :py:attr:`lammps.installed_packages ` +* :py:attr:`lammps.installed_packages ` + +* :py:meth:`lammps.get_accelerator_config ` * :py:meth:`lammps.has_style() ` * :py:meth:`lammps.available_styles() ` diff --git a/doc/src/info.rst b/doc/src/info.rst index 77d430ea66..395bc2c1f4 100644 --- a/doc/src/info.rst +++ b/doc/src/info.rst @@ -10,7 +10,7 @@ Syntax info args -* args = one or more of the following keywords: *out*\ , *all*\ , *system*\ , *memory*\ , *communication*\ , *computes*\ , *dumps*\ , *fixes*\ , *groups*\ , *regions*\ , *variables*\ , *coeffs*\ , *styles*\ , *time*\ , or *configuration* +* args = one or more of the following keywords: *out*\ , *all*\ , *system*\ , *memory*\ , *communication*\ , *computes*\ , *dumps*\ , *fixes*\ , *groups*\ , *regions*\ , *variables*\ , *coeffs*\ , *styles*\ , *time*\ , *accelerator*\ , or *configuration* * *out* values = *screen*\ , *log*\ , *append* filename, *overwrite* filename * *styles* values = *all*\ , *angle*\ , *atom*\ , *bond*\ , *compute*\ , *command*\ , *dump*\ , *dihedral*\ , *fix*\ , *improper*\ , *integrate*\ , *kspace*\ , *minimize*\ , *pair*\ , *region* @@ -88,6 +88,10 @@ The *coeffs* category prints a list for each defined force style corresponding coefficients have been set. This can be very helpful to debug error messages like "All pair coeffs are not set". +The *accelerator* category prints out information about compile time +settings of included accelerator support for the GPU, KOKKOS, USER-INTEL, +and USER-OMP packages. + The *styles* category prints the list of styles available in the current LAMMPS binary. It supports one of the following options to control which category of styles is printed out: From 22bf810b63c6db8c91f4559dcfecf244e68ce05d Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 12 Jan 2021 20:23:57 -0500 Subject: [PATCH 07/12] recover current package names. this will become simpler once #2525 is implemented --- python/lammps/core.py | 2 +- src/info.cpp | 13 +++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/python/lammps/core.py b/python/lammps/core.py index 01a3cce842..7349e877c6 100644 --- a/python/lammps/core.py +++ b/python/lammps/core.py @@ -1452,7 +1452,7 @@ class lammps(object): for p in [b'GPU', b'KOKKOS', b'USER-INTEL', b'USER-OMP']: c = b'api' result[p.decode()] = {} - for s in [b'cuda', b'hip', b'pthreads', b'opencl', b'openmp']: + for s in [b'cuda', b'hip', b'pthreads', b'opencl', b'openmp', b'serial']: if self.lib.lammps_config_accelerator(p,c,s): result[p.decode()][c.decode()] = s.decode() c = b'precision' diff --git a/src/info.cpp b/src/info.cpp index f9394a1433..27975a73c4 100644 --- a/src/info.cpp +++ b/src/info.cpp @@ -1208,7 +1208,7 @@ bool Info::has_accelerator_feature(const std::string &package, } #endif #if defined(LMP_USER_OMP) - if (package == "OPENMP") { + if (package == "USER-OMP") { if (category == "precision") { if (setting == "double") return true; else return false; @@ -1216,14 +1216,15 @@ bool Info::has_accelerator_feature(const std::string &package, if (category == "api") { #if defined(_OPENMP) if (setting == "openmp") return true; - else return false; +#else + if (setting == "serial") return true; #endif return false; } } #endif #if defined(LMP_USER_INTEL) - if (package == "INTEL") { + if (package == "USER-INTEL") { if (category == "precision") { if (setting == "double") return true; else if (setting == "mixed") return true; @@ -1231,8 +1232,12 @@ bool Info::has_accelerator_feature(const std::string &package, else return false; } if (category == "api") { +#if defined(_OPENMP) if (setting == "openmp") return true; - else return false; +#else + if (setting == "serial") return true; +#endif + return false; } } #endif From a644375afaa6a341bcc6df0b1566c2f6d629328b Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sat, 16 Jan 2021 00:23:44 -0500 Subject: [PATCH 08/12] make code python2/3 compatible --- python/lammps/core.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/python/lammps/core.py b/python/lammps/core.py index 7349e877c6..7c078b9841 100644 --- a/python/lammps/core.py +++ b/python/lammps/core.py @@ -1449,16 +1449,16 @@ class lammps(object): """ result = {} - for p in [b'GPU', b'KOKKOS', b'USER-INTEL', b'USER-OMP']: - c = b'api' - result[p.decode()] = {} - for s in [b'cuda', b'hip', b'pthreads', b'opencl', b'openmp', b'serial']: - if self.lib.lammps_config_accelerator(p,c,s): - result[p.decode()][c.decode()] = s.decode() - c = b'precision' - for s in [b'double', b'mixed', b'single']: - if self.lib.lammps_config_accelerator(p,c,s): - result[p.decode()][c.decode()] = s.decode() + for p in ['GPU', 'KOKKOS', 'USER-INTEL', 'USER-OMP']: + c = 'api' + result[p] = {} + for s in ['cuda', 'hip', 'pthreads', 'opencl', 'openmp', 'serial']: + if self.lib.lammps_config_accelerator(p.encode(),c.encode(),s.encode()): + result[p][c] = s + c = 'precision' + for s in ['double', 'mixed', 'single']: + if self.lib.lammps_config_accelerator(p.encode(),c.encode(),s.encode()): + result[p][c] = s return result # ------------------------------------------------------------------------- From a647c236d040736fe260c5c411ac7ace317297b4 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sat, 16 Jan 2021 00:56:27 -0500 Subject: [PATCH 09/12] make categories contain lists instead of strings as we may have multiple supported settings --- python/lammps/core.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/python/lammps/core.py b/python/lammps/core.py index 7c078b9841..3f39ead4b8 100644 --- a/python/lammps/core.py +++ b/python/lammps/core.py @@ -1450,15 +1450,17 @@ class lammps(object): result = {} for p in ['GPU', 'KOKKOS', 'USER-INTEL', 'USER-OMP']: - c = 'api' result[p] = {} + c = 'api' + result[p][c] = [] for s in ['cuda', 'hip', 'pthreads', 'opencl', 'openmp', 'serial']: if self.lib.lammps_config_accelerator(p.encode(),c.encode(),s.encode()): - result[p][c] = s + result[p][c].append(s) c = 'precision' + result[p][c] = [] for s in ['double', 'mixed', 'single']: if self.lib.lammps_config_accelerator(p.encode(),c.encode(),s.encode()): - result[p][c] = s + result[p][c].append(s) return result # ------------------------------------------------------------------------- From 99ae866973294ff23fa96192d0ee7bce699dfd28 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sat, 16 Jan 2021 00:57:46 -0500 Subject: [PATCH 10/12] add Kokkos introspection. correct package names. --- src/info.cpp | 44 +++++++++++++++++++++++++++++++++----------- 1 file changed, 33 insertions(+), 11 deletions(-) diff --git a/src/info.cpp b/src/info.cpp index 27975a73c4..6ab4864f33 100644 --- a/src/info.cpp +++ b/src/info.cpp @@ -337,9 +337,8 @@ void Info::command(int narg, char **arg) mesg = "KOKKOS package API:"; if (has_accelerator_feature("KOKKOS","api","cuda")) mesg += " CUDA"; if (has_accelerator_feature("KOKKOS","api","hip")) mesg += " HIP"; - if (has_accelerator_feature("KOKKOS","api","knl")) mesg += " KNL"; - if (has_accelerator_feature("KOKKOS","api","opencl")) mesg += " OpenCL"; if (has_accelerator_feature("KOKKOS","api","openmp")) mesg += " OpenMP"; + if (has_accelerator_feature("KOKKOS","api","serial")) mesg += " Serial"; if (has_accelerator_feature("KOKKOS","api","pthreads")) mesg += " Pthreads"; mesg += "\nKOKKOS package precision:"; if (has_accelerator_feature("KOKKOS","precision","single")) mesg += " single"; @@ -350,22 +349,23 @@ void Info::command(int narg, char **arg) } if (has_package("USER-OMP")) { mesg = "USER-OMP package API:"; - if (has_accelerator_feature("OPENMP","api","openmp")) mesg += " OpenMP"; + if (has_accelerator_feature("USER-OMP","api","openmp")) mesg += " OpenMP"; + if (has_accelerator_feature("USER-OMP","api","serial")) mesg += " Serial"; mesg += "\nUSER-OMP package precision:"; - if (has_accelerator_feature("OPENMP","precision","single")) mesg += " single"; - if (has_accelerator_feature("OPENMP","precision","mixed")) mesg += " mixed"; - if (has_accelerator_feature("OPENMP","precision","double")) mesg += " double"; + if (has_accelerator_feature("USER-OMP","precision","single")) mesg += " single"; + if (has_accelerator_feature("USER-OMP","precision","mixed")) mesg += " mixed"; + if (has_accelerator_feature("USER-OMP","precision","double")) mesg += " double"; mesg += "\n"; fputs(mesg.c_str(),out); } if (has_package("USER-INTEL")) { mesg = "USER-INTEL package API:"; - if (has_accelerator_feature("INTEL","api","knl")) mesg += " KNL"; - if (has_accelerator_feature("INTEL","api","openmp")) mesg += " OpenMP"; + if (has_accelerator_feature("USER-INTEL","api","knl")) mesg += " KNL"; + if (has_accelerator_feature("USER-INTEL","api","openmp")) mesg += " OpenMP"; mesg += "\nUSER-INTEL package precision:"; - if (has_accelerator_feature("INTEL","precision","single")) mesg += " single"; - if (has_accelerator_feature("INTEL","precision","mixed")) mesg += " mixed"; - if (has_accelerator_feature("INTEL","precision","double")) mesg += " double"; + if (has_accelerator_feature("USER-INTEL","precision","single")) mesg += " single"; + if (has_accelerator_feature("USER-INTEL","precision","mixed")) mesg += " mixed"; + if (has_accelerator_feature("USER-INTEL","precision","double")) mesg += " double"; mesg += "\n"; fputs(mesg.c_str(),out); } @@ -1190,6 +1190,10 @@ bool Info::has_package(const std::string &package_name) { extern bool lmp_gpu_config(const std::string &, const std::string &); #endif +#if defined(LMP_KOKKOS) +#include "Kokkos_Macros.hpp" +#endif + bool Info::has_accelerator_feature(const std::string &package, const std::string &category, const std::string &setting) @@ -1200,6 +1204,24 @@ bool Info::has_accelerator_feature(const std::string &package, if (setting == "double") return true; else return false; } + if (category == "api") { +#if defined(KOKKOS_ENABLE_OPENMP) + if (setting == "openmp") return true; +#endif +#if defined(KOKKOS_ENABLE_SERIAL) + if (setting == "serial") return true; +#endif +#if defined(KOKKOS_ENABLE_THREADS) + if (setting == "pthreads") return true; +#endif +#if defined(KOKKOS_ENABLE_CUDA) + if (setting == "cuda") return true; +#endif +#if defined(KOKKOS_ENABLE_HIP) + if (setting == "hip") return true; +#endif + return false; + } } #endif #if defined(LMP_GPU) From 1cdce9233ebf855409e05c1fca90bdbaa926677e Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sat, 16 Jan 2021 01:07:44 -0500 Subject: [PATCH 11/12] identify offloading to Xeon Phi accelerator coprocessors --- python/lammps/core.py | 7 ++++--- src/info.cpp | 6 ++++-- src/library.cpp | 4 ++-- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/python/lammps/core.py b/python/lammps/core.py index 3f39ead4b8..fe23fa587c 100644 --- a/python/lammps/core.py +++ b/python/lammps/core.py @@ -1442,9 +1442,10 @@ class lammps(object): This is a wrapper around the :cpp:func:`lammps_config_accelerator` function of the library interface which loops over all known packages - and settings and returns enabled features as a nested dictionary. + and categories and returns enabled features as a nested dictionary + with all enabled settings as list of strings. - :return: nested dictionary with all known enabled settings + :return: nested dictionary with all known enabled settings as list of strings :rtype: dictionary """ @@ -1453,7 +1454,7 @@ class lammps(object): result[p] = {} c = 'api' result[p][c] = [] - for s in ['cuda', 'hip', 'pthreads', 'opencl', 'openmp', 'serial']: + for s in ['cuda', 'hip', 'phi', 'pthreads', 'opencl', 'openmp', 'serial']: if self.lib.lammps_config_accelerator(p.encode(),c.encode(),s.encode()): result[p][c].append(s) c = 'precision' diff --git a/src/info.cpp b/src/info.cpp index 6ab4864f33..bf6f14a48a 100644 --- a/src/info.cpp +++ b/src/info.cpp @@ -360,7 +360,7 @@ void Info::command(int narg, char **arg) } if (has_package("USER-INTEL")) { mesg = "USER-INTEL package API:"; - if (has_accelerator_feature("USER-INTEL","api","knl")) mesg += " KNL"; + if (has_accelerator_feature("USER-INTEL","api","phi")) mesg += " Phi"; if (has_accelerator_feature("USER-INTEL","api","openmp")) mesg += " OpenMP"; mesg += "\nUSER-INTEL package precision:"; if (has_accelerator_feature("USER-INTEL","precision","single")) mesg += " single"; @@ -1254,7 +1254,9 @@ bool Info::has_accelerator_feature(const std::string &package, else return false; } if (category == "api") { -#if defined(_OPENMP) +#if defined(LMP_INTEL_OFFLOAD) + if (setting == "phi") return true; +#elif defined(_OPENMP) if (setting == "openmp") return true; #else if (setting == "serial") return true; diff --git a/src/library.cpp b/src/library.cpp index a4cfee979a..557d746226 100644 --- a/src/library.cpp +++ b/src/library.cpp @@ -4309,8 +4309,8 @@ int lammps_config_package_name(int idx, char *buffer, int buf_size) { This function checks availability of compile time settings of included :doc:`accelerator packages ` in LAMMPS. Supported packages names are "GPU", "KOKKOS", "USER-INTEL", and "USER-OMP". -Supported categories are "api" with possible settings "cuda", "hip", "knl", -"pthreads", "opencl", "openmp", and "none", and "precision" with +Supported categories are "api" with possible settings "cuda", "hip", "phi", +"pthreads", "opencl", "openmp", and "serial", and "precision" with possible settings "double", "mixed", and "single". If the combination of package, category, and setting is available, the function returns 1, otherwise 0. From a2d7d47cac6738b7718c1d5d56379352e0881011 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sat, 16 Jan 2021 17:12:29 -0500 Subject: [PATCH 12/12] add unittest for python interface of accelerator config introspection --- unittest/python/python-capabilities.py | 35 ++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/unittest/python/python-capabilities.py b/unittest/python/python-capabilities.py index 2b47b8ca90..372eecc869 100644 --- a/unittest/python/python-capabilities.py +++ b/unittest/python/python-capabilities.py @@ -123,5 +123,40 @@ class PythonCapabilities(unittest.TestCase): self.lmp.command('run 10') self.assertEqual(self.lmp.extract_global('ntimestep'),20) + def test_accelerator_config(self): + + settings = self.lmp.accelerator_config + if self.cmake_cache['PKG_USER-OMP']: + if self.cmake_cache['BUILD_OMP']: + self.assertIn('openmp',settings['USER-OMP']['api']) + else: + self.assertIn('serial',settings['USER-OMP']['api']) + self.assertIn('double',settings['USER-OMP']['precision']) + + if self.cmake_cache['PKG_USER-INTEL']: + if 'LMP_INTEL_OFFLOAD' in self.cmake_cache.keys(): + self.assertIn('phi',settings['USER-INTEL']['api']) + elif self.cmake_cache['BUILD_OMP']: + self.assertIn('openmp',settings['USER-INTEL']['api']) + else: + self.assertIn('serial',settings['USER-INTEL']['api']) + self.assertIn('double',settings['USER-INTEL']['precision']) + self.assertIn('mixed',settings['USER-INTEL']['precision']) + self.assertIn('single',settings['USER-INTEL']['precision']) + + if self.cmake_cache['PKG_GPU']: + if self.cmake_cache['GPU_API'].lower() == 'opencl': + self.assertIn('opencl',settings['GPU']['api']) + if self.cmake_cache['GPU_API'].lower() == 'cuda': + self.assertIn('cuda',settings['GPU']['api']) + if self.cmake_cache['GPU_API'].lower() == 'hip': + self.assertIn('hip',settings['GPU']['api']) + if self.cmake_cache['GPU_PREC'].lower() == 'double': + self.assertIn('double',settings['GPU']['precision']) + if self.cmake_cache['GPU_PREC'].lower() == 'mixed': + self.assertIn('mixed',settings['GPU']['precision']) + if self.cmake_cache['GPU_PREC'].lower() == 'single': + self.assertIn('single',settings['GPU']['precision']) + if __name__ == "__main__": unittest.main()