Fix GPU utils test
authorMark Abraham <mark.j.abraham@gmail.com>
Fri, 23 Feb 2018 14:15:46 +0000 (15:15 +0100)
committerMark Abraham <mark.j.abraham@gmail.com>
Tue, 27 Feb 2018 09:14:47 +0000 (10:14 +0100)
We should only attempt device-side work when we have compatible GPUs.

Fixes #2405 for CUDA

Change-Id: Idc28c7e89a5f08ee1d19943e3663385f2b23ff44

src/gromacs/gpu_utils/tests/devicetransfers.cu
src/gromacs/gpu_utils/tests/devicetransfers_ocl.cpp

index e2d6a0d2bad543767c380f2642d06d6f5a392ab8..88a497c19ee3dd54c558875863941b7bb801f088 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2017, by the GROMACS development team, led by
+ * Copyright (c) 2017,2018, 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.
@@ -49,6 +49,7 @@
 #include "devicetransfers.h"
 
 #include "gromacs/gpu_utils/cudautils.cuh"
+#include "gromacs/gpu_utils/gpu_utils.h"
 #include "gromacs/hardware/gpu_hw_info.h"
 #include "gromacs/utility/arrayref.h"
 #include "gromacs/utility/exceptions.h"
@@ -79,20 +80,21 @@ void doDeviceTransfers(const gmx_gpu_info_t &gpuInfo,
                        ArrayRef<char>        output)
 {
     GMX_RELEASE_ASSERT(input.size() == output.size(), "Input and output must have matching size");
-    if (gpuInfo.n_dev == 0)
+    const auto compatibleGpus = getCompatibleGpus(gpuInfo);
+    if (compatibleGpus.empty())
     {
         std::copy(input.begin(), input.end(), output.begin());
         return;
     }
     cudaError_t status;
 
-    const auto &device = gpuInfo.gpu_dev[0];
+    const auto *device = getDeviceInfo(gpuInfo, compatibleGpus[0]);
     int         oldDeviceId;
 
     status = cudaGetDevice(&oldDeviceId);
     throwUponFailure(status, "getting old device id");
-    status = cudaSetDevice(device.id);
-    throwUponFailure(status, "setting device id to 0");
+    status = cudaSetDevice(device->id);
+    throwUponFailure(status, "setting device id to the first compatible GPU");
 
     void       *devicePointer;
     status = cudaMalloc(&devicePointer, input.size());
index ace54963b862992dc990d1e42f9e5b1aa7d1a853..7c0215ef26ee92479f1a66b90309dbce9e8e0949 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2017, by the GROMACS development team, led by
+ * Copyright (c) 2017,2018, 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.
@@ -41,6 +41,7 @@
 #include "gmxpre.h"
 
 #include "gromacs/gpu_utils/gmxopencl.h"
+#include "gromacs/gpu_utils/gpu_utils.h"
 #include "gromacs/gpu_utils/oclutils.h"
 #include "gromacs/hardware/gpu_hw_info.h"
 #include "gromacs/utility/arrayref.h"
@@ -74,22 +75,23 @@ void doDeviceTransfers(const gmx_gpu_info_t &gpuInfo,
                        ArrayRef<char>        output)
 {
     GMX_RELEASE_ASSERT(input.size() == output.size(), "Input and output must have matching size");
-    if (gpuInfo.n_dev == 0)
+    const auto compatibleGpus = getCompatibleGpus(gpuInfo);
+    if (compatibleGpus.empty())
     {
         std::copy(input.begin(), input.end(), output.begin());
         return;
     }
     cl_int                status;
 
-    const auto           &device       = gpuInfo.gpu_dev[0];
+    const auto           *device       = getDeviceInfo(gpuInfo, compatibleGpus[0]);
     cl_context_properties properties[] = {
         CL_CONTEXT_PLATFORM,
-        (cl_context_properties) device.ocl_gpu_id.ocl_platform_id,
+        (cl_context_properties) device->ocl_gpu_id.ocl_platform_id,
         0
     };
     // Give uncrustify more space
 
-    auto deviceId = device.ocl_gpu_id.ocl_device_id;
+    auto deviceId = device->ocl_gpu_id.ocl_device_id;
     auto context  = clCreateContext(properties, 1, &deviceId, NULL, NULL, &status);
     throwUponFailure(status, "creating context");
     auto commandQueue = clCreateCommandQueue(context, deviceId, 0, &status);