From fbdcfb2f7255e0813fe373bf0f9455441f9395e5 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 10 May 2021 09:16:51 -0400 Subject: [PATCH] preliminary interface to detect whether a viable GPU is present --- lib/gpu/lal_device.cpp | 9 +++++++++ src/info.cpp | 12 ++++++++++++ src/info.h | 1 + 3 files changed, 22 insertions(+) diff --git a/lib/gpu/lal_device.cpp b/lib/gpu/lal_device.cpp index 1c19cf9186..cd38e9d959 100644 --- a/lib/gpu/lal_device.cpp +++ b/lib/gpu/lal_device.cpp @@ -1026,6 +1026,15 @@ Device global_device; } using namespace LAMMPS_AL; + +bool lmp_has_device() +{ + auto tmpgpu = new UCL_Device(); + int num = tmpgpu->num_platforms(); + delete tmpgpu; + return num > 0; +} + int lmp_init_device(MPI_Comm world, MPI_Comm replica, const int ngpu, const int first_gpu_id, const int gpu_mode, const double particle_split, const int t_per_atom, diff --git a/src/info.cpp b/src/info.cpp index 512858b9f2..a033d6608f 100644 --- a/src/info.cpp +++ b/src/info.cpp @@ -320,6 +320,7 @@ 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 (flags & MEMORY) { @@ -1139,6 +1140,17 @@ 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(); + +bool Info::has_gpu_device() +{ + return lmp_has_device(); +} +#else +bool Info::has_gpu_device() +{ + return false; +} #endif #if defined(LMP_KOKKOS) diff --git a/src/info.h b/src/info.h index 9eb84d9312..ff649cc2bb 100644 --- a/src/info.h +++ b/src/info.h @@ -47,6 +47,7 @@ class Info : public Command { static bool has_accelerator_feature(const std::string &, const std::string &, const std::string &); + static bool has_gpu_device(); static std::string get_os_info(); static std::string get_compiler_info();