#include "gromacs/utility/smalloc.h"
#include "gromacs/utility/stringutil.h"
-#if !GMX_GPU
+#ifdef _MSC_VER
+#pragma warning(disable: 6237)
+#endif
+
+//! Constant used to help minimize preprocessed code
+static constexpr bool c_binarySupportsGpus = (GMX_GPU != GMX_GPU_NONE);
+
+bool canPerformGpuDetection()
+{
+ if (c_binarySupportsGpus &&
+ getenv("GMX_DISABLE_GPU_DETECTION") == nullptr)
+ {
+ return isGpuDetectionFunctional(nullptr);
+ }
+ else
+ {
+ return false;
+ }
+}
+
+#if GMX_GPU == GMX_GPU_NONE
int gpu_info_get_stat(const gmx_gpu_info_t & /*unused*/, int /*unused*/)
{
return egpuNonexistent;
{
errorReasons.emplace_back("double precision");
}
- if (GMX_GPU == GMX_GPU_NONE)
+ if (!c_binarySupportsGpus)
{
errorReasons.emplace_back("non-GPU build of GROMACS");
}
return egpuCompatible;
}
-bool canDetectGpus(std::string *errorMessage)
+bool isGpuDetectionFunctional(std::string *errorMessage)
{
cudaError_t stat;
int driverVersion = -1;
};
/*! \brief Return whether GPUs can be detected
+ *
+ * Returns true when this is a build of \Gromacs configured to support
+ * GPU usage, GPU detection is not disabled by an environment variable
+ * and a valid device driver, ICD, and/or runtime was detected.
+ * Does not throw. */
+bool canPerformGpuDetection();
+
+/*! \brief Return whether GPU detection is functioning correctly
*
* Returns true when this is a build of \Gromacs configured to support
* GPU usage, and a valid device driver, ICD, and/or runtime was detected.
*
* Does not throw. */
GPU_FUNC_QUALIFIER
-bool canDetectGpus(std::string *GPU_FUNC_ARGUMENT(errorMessage)) GPU_FUNC_TERM_WITH_RETURN(false);
+bool isGpuDetectionFunctional(std::string *GPU_FUNC_ARGUMENT(errorMessage)) GPU_FUNC_TERM_WITH_RETURN(false);
/*! \brief Find all GPUs in the system.
*
- * Will detect every GPU supported by the device driver in use. Must
- * only be called if canDetectGpus() has returned true. This routine
- * also checks for the compatibility of each and fill the
+ * Will detect every GPU supported by the device driver in use.
+ * Must only be called if canPerformGpuDetection() has returned true.
+ * This routine also checks for the compatibility of each and fill the
* gpu_info->gpu_dev array with the required information on each the
* device: ID, device properties, status.
*
return OCL_VENDOR_UNKNOWN;
}
-
-//! This function is documented in the header file
-bool canDetectGpus(std::string *errorMessage)
+bool isGpuDetectionFunctional(std::string *errorMessage)
{
cl_uint numPlatforms;
cl_int status = clGetPlatformIDs(0, nullptr, &numPlatforms);
return foundPlatform;
}
-//! This function is documented in the header file
void findGpus(gmx_gpu_info_t *gpu_info)
{
cl_uint ocl_platform_count;
sfree(ocl_platform_ids);
}
-//! This function is documented in the header file
void get_gpu_device_info_string(char *s, const gmx_gpu_info_t &gpu_info, int index)
{
assert(s);
return result;
}
-//! This function is documented in the header file
void init_gpu(const gmx_device_info_t *deviceInfo)
{
assert(deviceInfo);
}
}
-//! This function is documented in the header file
gmx_device_info_t *getDeviceInfo(const gmx_gpu_info_t &gpu_info,
int deviceId)
{
return &gpu_info.gpu_dev[deviceId];
}
-//! This function is documented in the header file
size_t sizeof_gpu_dev_info()
{
return sizeof(gmx_device_info_t);
/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2017,2018, by the GROMACS development team, led by
+ * Copyright (c) 2017,2018,2019, 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.
GpuTest::GpuTest()
{
snew(gpuInfo_, 1);
- if (canDetectGpus(nullptr))
+ if (isGpuDetectionFunctional(nullptr))
{
findGpus(gpuInfo_);
}
# define _SC_NPROCESSORS_CONF _SC_NPROC_CONF
#endif
-//! Constant used to help minimize preprocessed code
-static const bool bGPUBinary = GMX_GPU != GMX_GPU_NONE;
-
/*! \brief Information about the hardware of all nodes (common to all threads in this process).
*
* This information is constructed only when required, but thereafter
const PhysicalNodeCommunicator &physicalNodeComm,
compat::not_null<gmx_hw_info_t *> hardwareInfo)
{
- hardwareInfo->gpu_info.bDetectGPUs =
- (bGPUBinary && getenv("GMX_DISABLE_GPU_DETECTION") == nullptr);
+ hardwareInfo->gpu_info.bDetectGPUs = canPerformGpuDetection();
+
if (!hardwareInfo->gpu_info.bDetectGPUs)
{
return;
if (isMasterRankOfPhysicalNode || allRanksMustDetectGpus)
{
std::string errorMessage;
- gpusCanBeDetected = canDetectGpus(&errorMessage);
+ gpusCanBeDetected = isGpuDetectionFunctional(&errorMessage);
if (!gpusCanBeDetected)
{
GMX_LOG(mdlog.info).asParagraph().appendTextFormatted(
{
algorithmsNames.emplace_back("SHAKE");
algorithmsNames.emplace_back("LINCS");
- std::string errorMessage;
- if (GMX_GPU == GMX_GPU_CUDA && canDetectGpus(&errorMessage))
+ // TODO: Here we should check that at least 1 suitable GPU is available
+ if (GMX_GPU == GMX_GPU_CUDA && canPerformGpuDetection())
{
algorithmsNames.emplace_back("LINCS_CUDA");
}
};
-TEST_P(IntegratorTest, SimpleIntegration){
- // Do nothing if it is a CUDA build but there are no CUDA-capable GPUs
- std::string errorMessage;
- if (!canDetectGpus(&errorMessage))
+TEST_P(IntegratorTest, SimpleIntegration)
+{
+ // TODO: Here we should check that at least 1 suitable GPU is available
+ if (!canPerformGpuDetection())
{
return;
}
// 1. The code was compiled with cuda
// 2. There is a CUDA-capable GPU in a system
#if GMX_GPU == GMX_GPU_CUDA
- std::string errorMessage;
- if (canDetectGpus(&errorMessage))
+ // TODO: Here we should check that at least 1 suitable GPU is available
+ if (canPerformGpuDetection())
{
// Run the CUDA code and check if it gives identical results to CPU code
t_idef idef;
// there is no GPU support in the build.
//
// TODO report any error messages gracefully.
- if (canDetectGpus(nullptr))
+ if (canPerformGpuDetection())
{
findGpus(&gpuInfo);
s_hasCompatibleGpus = (gpuInfo.n_dev_compatible > 0);