diff --git a/lib/gpu/lal_device.cpp b/lib/gpu/lal_device.cpp index cd38e9d959..e2b5b9cdb5 100644 --- a/lib/gpu/lal_device.cpp +++ b/lib/gpu/lal_device.cpp @@ -18,6 +18,7 @@ #include #include #include +#include #if (LAL_USE_OMP == 1) #include #endif @@ -1027,12 +1028,19 @@ Device global_device; using namespace LAMMPS_AL; -bool lmp_has_device() +bool lmp_has_gpu_device() { - auto tmpgpu = new UCL_Device(); - int num = tmpgpu->num_platforms(); - delete tmpgpu; - return num > 0; + UCL_Device gpu; + return (gpu.num_platforms() > 0); +} + +std::string lmp_gpu_device_info() +{ + std::ostringstream out; + UCL_Device gpu; + if (gpu.num_platforms() > 0) + gpu.print_all(out); + return out.str(); } int lmp_init_device(MPI_Comm world, MPI_Comm replica, const int ngpu, diff --git a/src/info.cpp b/src/info.cpp index a033d6608f..cae3865785 100644 --- a/src/info.cpp +++ b/src/info.cpp @@ -320,7 +320,8 @@ void Info::command(int narg, char **arg) if (flags & ACCELERATOR) { fmt::print(out,"\nAccelerator configuration:\n\n{}", get_accelerator_info()); - fmt::print(out,"\nGPU present: {}\n",has_gpu_device() ? "yes" : "no"); + if (Info::has_gpu_device()) + fmt::print(out,"\nAvailable GPU devices:\n{}\n",get_gpu_device_info()); } if (flags & MEMORY) { @@ -1140,17 +1141,27 @@ bool Info::has_package(const std::string &package_name) { #if defined(LMP_GPU) extern bool lmp_gpu_config(const std::string &, const std::string &); -extern bool lmp_has_device(); +extern bool lmp_has_gpu_device(); +extern std::string lmp_gpu_device_info(); bool Info::has_gpu_device() { - return lmp_has_device(); + return lmp_has_gpu_device(); +} + +std::string Info::get_gpu_device_info() +{ + return lmp_gpu_device_info(); } #else bool Info::has_gpu_device() { return false; } +std::string Info::get_gpu_device_info() +{ + return ""; +} #endif #if defined(LMP_KOKKOS) diff --git a/src/info.h b/src/info.h index ff649cc2bb..f376adf8dc 100644 --- a/src/info.h +++ b/src/info.h @@ -48,6 +48,7 @@ class Info : public Command { const std::string &, const std::string &); static bool has_gpu_device(); + static std::string get_gpu_device_info(); static std::string get_os_info(); static std::string get_compiler_info(); diff --git a/src/lammps.cpp b/src/lammps.cpp index 9e0aa1845d..85d56069bc 100644 --- a/src/lammps.cpp +++ b/src/lammps.cpp @@ -1328,6 +1328,7 @@ void LAMMPS::print_config(FILE *fp) fmt::print(fp,"Accelerator configuration:\n\n{}\n", Info::get_accelerator_info()); + fmt::print(fp,"GPU present: {}\n\n",Info::has_gpu_device() ? "yes" : "no"); fputs("Active compile time flags:\n\n",fp); if (Info::has_gzip_support()) fputs("-DLAMMPS_GZIP\n",fp);