gmx_add_libgromacs_sources(
clfftinitializer.cpp
hostallocator.cpp
+ gpu_utils.cpp
)
if(GMX_USE_OPENCL)
gmx_add_libgromacs_sources(
pinning.cu
pmalloc_cuda.cu
)
-else()
- gmx_add_libgromacs_sources(
- gpu_utils.cpp
- )
endif()
if(GMX_USE_OPENCL)
#include "gpu_utils.h"
+#include "config.h"
+
+#include <cassert>
+
#include "gromacs/hardware/gpu_hw_info.h"
+#include "gromacs/utility/smalloc.h"
+#if !GMX_GPU
/*! \brief Set allocation functions used by the GPU host
*
* Since GPU support is not configured, there is no host memory to
*nb_free = nullptr;
}
-//! This function is documented in the header file
-std::vector<int> getCompatibleGpus(const gmx_gpu_info_t & /*gpu_info*/)
+int gpu_info_get_stat(const gmx_gpu_info_t & /*unused*/, int /*unused*/)
+{
+ return egpuNonexistent;
+}
+#endif
+
+void free_gpu_info(const gmx_gpu_info_t *gpu_info)
+{
+ sfree(static_cast<void*>(gpu_info->gpu_dev)); //circumvent is_pod check in sfree
+}
+
+std::vector<int> getCompatibleGpus(const gmx_gpu_info_t &gpu_info)
{
- // There can't be any compatible GPUs
- return std::vector<int>();
+ // Possible minor over-allocation here, but not important for anything
+ std::vector<int> compatibleGpus;
+ compatibleGpus.reserve(gpu_info.n_dev);
+ for (int i = 0; i < gpu_info.n_dev; i++)
+ {
+ assert(gpu_info.gpu_dev);
+ if (gpu_info_get_stat(gpu_info, i) == egpuCompatible)
+ {
+ compatibleGpus.push_back(i);
+ }
+ }
+ return compatibleGpus;
}
-const char *getGpuCompatibilityDescription(const gmx_gpu_info_t & /*gpu_info*/,
- int /*index*/)
+const char *getGpuCompatibilityDescription(const gmx_gpu_info_t &gpu_info,
+ int index)
{
- return gpu_detect_res_str[egpuNonexistent];
+ return (index >= gpu_info.n_dev ?
+ gpu_detect_res_str[egpuNonexistent] :
+ gpu_detect_res_str[gpu_info_get_stat(gpu_info, index)]);
}
gpu_info->gpu_dev = devs;
}
-std::vector<int> getCompatibleGpus(const gmx_gpu_info_t &gpu_info)
-{
- // Possible minor over-allocation here, but not important for anything
- std::vector<int> compatibleGpus;
- compatibleGpus.reserve(gpu_info.n_dev);
- for (int i = 0; i < gpu_info.n_dev; i++)
- {
- assert(gpu_info.gpu_dev);
- if (gpu_info.gpu_dev[i].stat == egpuCompatible)
- {
- compatibleGpus.push_back(i);
- }
- }
- return compatibleGpus;
-}
-
-const char *getGpuCompatibilityDescription(const gmx_gpu_info_t &gpu_info,
- int index)
-{
- return (index >= gpu_info.n_dev ?
- gpu_detect_res_str[egpuNonexistent] :
- gpu_detect_res_str[gpu_info.gpu_dev[index].stat]);
-}
-
-void free_gpu_info(const gmx_gpu_info_t *gpu_info)
-{
- if (gpu_info == NULL)
- {
- return;
- }
-
- sfree(gpu_info->gpu_dev);
-}
-
void get_gpu_device_info_string(char *s, const gmx_gpu_info_t &gpu_info, int index)
{
assert(s);
startGpuProfiler();
}
}
+
+int gpu_info_get_stat(const gmx_gpu_info_t &info, int index)
+{
+ return info.gpu_dev[index].stat;
+}
* the call to canDetectGpus() should always prevent this occuring)
*/
GPU_FUNC_QUALIFIER
-void findGpus(struct gmx_gpu_info_t *GPU_FUNC_ARGUMENT(gpu_info)) GPU_FUNC_TERM
+void findGpus(gmx_gpu_info_t *GPU_FUNC_ARGUMENT(gpu_info)) GPU_FUNC_TERM
/*! \brief Return a container of the detected GPUs that are compatible.
*
* \param[in] index index of GPU to ask about
* \returns A null-terminated C string describing the compatibility status, useful for error messages.
*/
-const char *getGpuCompatibilityDescription(const gmx_gpu_info_t &GPU_FUNC_ARGUMENT(gpu_info),
- int GPU_FUNC_ARGUMENT(index));
+const char *getGpuCompatibilityDescription(const gmx_gpu_info_t &gpu_info,
+ int index);
/*! \brief Frees the gpu_dev and dev_use array fields of \p gpu_info.
*
* \param[in] gpu_info pointer to structure holding GPU information
*/
-GPU_FUNC_QUALIFIER
-void free_gpu_info(const struct gmx_gpu_info_t *GPU_FUNC_ARGUMENT(gpu_info)) GPU_FUNC_TERM
+void free_gpu_info(const gmx_gpu_info_t *gpu_info);
/*! \brief Initializes the GPU described by \c deviceInfo.
*
*/
GPU_FUNC_QUALIFIER
void get_gpu_device_info_string(char *GPU_FUNC_ARGUMENT(s),
- const struct gmx_gpu_info_t &GPU_FUNC_ARGUMENT(gpu_info),
+ const gmx_gpu_info_t &GPU_FUNC_ARGUMENT(gpu_info),
int GPU_FUNC_ARGUMENT(index)) GPU_FUNC_TERM
/*! \brief Returns the size of the gpu_dev_info struct.
gmx_host_alloc_t **nb_alloc,
gmx_host_free_t **nb_free);
-
+//! Get status of device with specified index
+int gpu_info_get_stat(const gmx_gpu_info_t &info, int index);
/*! \brief Starts the GPU profiler if mdrun is being profiled.
*
* \returns true if the GPU properties passed indicate a compatible
* GPU, otherwise false.
*/
-static int is_gmx_supported_gpu_id(struct gmx_device_info_t *ocl_gpu_device)
+static int is_gmx_supported_gpu_id(gmx_device_info_t *ocl_gpu_device)
{
if ((getenv("GMX_OCL_DISABLE_COMPATIBILITY_CHECK")) != nullptr)
{
sfree(ocl_platform_ids);
}
-//! This function is documented in the header file
-void free_gpu_info(const gmx_gpu_info_t gmx_unused *gpu_info)
-{
- if (gpu_info == nullptr)
- {
- return;
- }
-
- sfree(gpu_info->gpu_dev);
-}
-
-//! This function is documented in the header file
-std::vector<int> getCompatibleGpus(const gmx_gpu_info_t &gpu_info)
-{
- // Possible minor over-allocation here, but not important for anything
- std::vector<int> compatibleGpus;
- compatibleGpus.reserve(gpu_info.n_dev);
- for (int i = 0; i < gpu_info.n_dev; i++)
- {
- assert(gpu_info.gpu_dev);
- if (gpu_info.gpu_dev[i].stat == egpuCompatible)
- {
- compatibleGpus.push_back(i);
- }
- }
- return compatibleGpus;
-}
-
-//! This function is documented in the header file
-const char *getGpuCompatibilityDescription(const gmx_gpu_info_t &gpu_info,
- int index)
-{
- return (index >= gpu_info.n_dev ?
- gpu_detect_res_str[egpuNonexistent] :
- gpu_detect_res_str[gpu_info.gpu_dev[index].stat]);
-}
-
//! 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)
{
*nb_free = nullptr;
}
}
+
+int gpu_info_get_stat(const gmx_gpu_info_t &info, int index)
+{
+ return info.gpu_dev[index].stat;
+}