Use common device context header for OpenCL
authorArtem Zhmurov <zhmurov@gmail.com>
Tue, 15 Sep 2020 16:43:43 +0000 (16:43 +0000)
committerPaul Bauer <paul.bauer.q@gmail.com>
Tue, 15 Sep 2020 16:43:43 +0000 (16:43 +0000)
This moves the OpenCL specific definition into under macro in the main header.
Makes device stream and context definitions more consistent.

src/gromacs/gpu_utils/tests/CMakeLists.txt
src/gromacs/gpu_utils/tests/device_stream_manager.cpp
src/gromacs/gpu_utils/tests/devicetransfers_ocl.cpp
src/gromacs/gpu_utils/tests/gputest.cpp [deleted file]
src/gromacs/gpu_utils/tests/gputest.h [deleted file]
src/gromacs/gpu_utils/tests/hostallocator.cpp
src/gromacs/gpu_utils/tests/pinnedmemorychecker.cpp
src/gromacs/gpu_utils/tests/typecasts.cpp
src/gromacs/gpu_utils/tests/typecasts_runner.cpp
src/gromacs/gpu_utils/tests/typecasts_runner.cu
src/gromacs/gpu_utils/tests/typecasts_runner.h

index 93e385806b7e538072b570dbef48117dcecb3567..18674a3e3854910093d88605ccfb64a394e90684 100644 (file)
 # different files and strategies for the different GPU implementation
 # flavours.
 
-gmx_add_unit_test(GpuUtilsUnitTests gpu_utils-test
+gmx_add_unit_test(GpuUtilsUnitTests gpu_utils-test HARDWARE_DETECTION
     CPP_SOURCE_FILES
-        # Infrastructure
-        gputest.cpp
         # Tests of code
         clfftinitializer.cpp
         device_stream_manager.cpp
index 12221ef118bf7b7e44852b5ffe9e31f6940a4971..d01aff20ead9771860aa31cdf0f19893cafe2eea 100644 (file)
 
 #include <gtest/gtest.h>
 
+#include "gromacs/hardware/device_management.h"
 #include "gromacs/mdtypes/simulation_workload.h"
 #include "gromacs/utility/enumerationhelpers.h"
 
-#include "gputest.h"
+#include "testutils/test_hardware_environment.h"
 
 namespace gmx
 {
@@ -97,7 +98,7 @@ void expectInvalidStreams(DeviceStreamManager* manager, std::initializer_list<De
 }
 
 //! Test fixture
-class DeviceStreamManagerTest : public GpuTest
+class DeviceStreamManagerTest : public ::testing::Test
 {
 public:
 };
@@ -109,11 +110,11 @@ TEST_F(DeviceStreamManagerTest, CorrectStreamsAreReturnedOnNonbondedDevice)
     // that we've called, so it is not very useful.
     const bool useTiming = false;
 
-    for (const auto& deviceInfo : getDeviceInfoList())
+    const auto& testDeviceList = getTestHardwareEnvironment()->getTestDeviceList();
+    for (const auto& testDevice : testDeviceList)
     {
-        EXPECT_FALSE(deviceInfo == nullptr)
-                << "Device information should be provided for the GPU builds.";
-        // Test all the different cases successively.
+        const DeviceInformation& deviceInfo = testDevice->deviceInfo();
+        setActiveDevice(deviceInfo);
 
         {
             SCOPED_TRACE("No DD, no PME rank, no GPU update");
@@ -122,7 +123,7 @@ TEST_F(DeviceStreamManagerTest, CorrectStreamsAreReturnedOnNonbondedDevice)
             simulationWork.useGpuPmePpCommunication       = false;
             simulationWork.useGpuUpdate                   = false;
             bool                havePpDomainDecomposition = false;
-            DeviceStreamManager manager(*deviceInfo, havePpDomainDecomposition, simulationWork, useTiming);
+            DeviceStreamManager manager(deviceInfo, havePpDomainDecomposition, simulationWork, useTiming);
 
             expectValidStreams(&manager, { DeviceStreamType::NonBondedLocal });
             expectInvalidStreams(&manager, { DeviceStreamType::NonBondedNonLocal,
@@ -137,7 +138,7 @@ TEST_F(DeviceStreamManagerTest, CorrectStreamsAreReturnedOnNonbondedDevice)
             simulationWork.useGpuPmePpCommunication       = false;
             simulationWork.useGpuUpdate                   = false;
             bool                havePpDomainDecomposition = true;
-            DeviceStreamManager manager(*deviceInfo, havePpDomainDecomposition, simulationWork, useTiming);
+            DeviceStreamManager manager(deviceInfo, havePpDomainDecomposition, simulationWork, useTiming);
 
             expectValidStreams(&manager, { DeviceStreamType::NonBondedLocal,
                                            DeviceStreamType::NonBondedNonLocal });
@@ -152,7 +153,7 @@ TEST_F(DeviceStreamManagerTest, CorrectStreamsAreReturnedOnNonbondedDevice)
             simulationWork.useGpuPmePpCommunication       = true;
             simulationWork.useGpuUpdate                   = false;
             bool                havePpDomainDecomposition = false;
-            DeviceStreamManager manager(*deviceInfo, havePpDomainDecomposition, simulationWork, useTiming);
+            DeviceStreamManager manager(deviceInfo, havePpDomainDecomposition, simulationWork, useTiming);
 
             expectValidStreams(&manager, { DeviceStreamType::Pme, DeviceStreamType::NonBondedLocal,
                                            DeviceStreamType::PmePpTransfer,
@@ -167,7 +168,7 @@ TEST_F(DeviceStreamManagerTest, CorrectStreamsAreReturnedOnNonbondedDevice)
             simulationWork.useGpuPmePpCommunication       = true;
             simulationWork.useGpuUpdate                   = false;
             bool                havePpDomainDecomposition = true;
-            DeviceStreamManager manager(*deviceInfo, havePpDomainDecomposition, simulationWork, useTiming);
+            DeviceStreamManager manager(deviceInfo, havePpDomainDecomposition, simulationWork, useTiming);
 
             expectValidStreams(&manager, { DeviceStreamType::Pme, DeviceStreamType::NonBondedLocal,
                                            DeviceStreamType::NonBondedNonLocal, DeviceStreamType::PmePpTransfer,
@@ -181,7 +182,7 @@ TEST_F(DeviceStreamManagerTest, CorrectStreamsAreReturnedOnNonbondedDevice)
             simulationWork.useGpuPmePpCommunication       = false;
             simulationWork.useGpuUpdate                   = true;
             bool                havePpDomainDecomposition = false;
-            DeviceStreamManager manager(*deviceInfo, havePpDomainDecomposition, simulationWork, useTiming);
+            DeviceStreamManager manager(deviceInfo, havePpDomainDecomposition, simulationWork, useTiming);
 
             expectValidStreams(&manager, { DeviceStreamType::NonBondedLocal,
                                            DeviceStreamType::UpdateAndConstraints });
@@ -196,7 +197,7 @@ TEST_F(DeviceStreamManagerTest, CorrectStreamsAreReturnedOnNonbondedDevice)
             simulationWork.useGpuPmePpCommunication       = false;
             simulationWork.useGpuUpdate                   = true;
             bool                havePpDomainDecomposition = true;
-            DeviceStreamManager manager(*deviceInfo, havePpDomainDecomposition, simulationWork, useTiming);
+            DeviceStreamManager manager(deviceInfo, havePpDomainDecomposition, simulationWork, useTiming);
 
             expectValidStreams(&manager, { DeviceStreamType::NonBondedLocal, DeviceStreamType::NonBondedNonLocal,
                                            DeviceStreamType::UpdateAndConstraints });
@@ -210,7 +211,7 @@ TEST_F(DeviceStreamManagerTest, CorrectStreamsAreReturnedOnNonbondedDevice)
             simulationWork.useGpuPmePpCommunication       = true;
             simulationWork.useGpuUpdate                   = true;
             bool                havePpDomainDecomposition = false;
-            DeviceStreamManager manager(*deviceInfo, havePpDomainDecomposition, simulationWork, useTiming);
+            DeviceStreamManager manager(deviceInfo, havePpDomainDecomposition, simulationWork, useTiming);
 
             expectValidStreams(&manager, { DeviceStreamType::Pme, DeviceStreamType::NonBondedLocal,
                                            DeviceStreamType::PmePpTransfer,
@@ -225,7 +226,7 @@ TEST_F(DeviceStreamManagerTest, CorrectStreamsAreReturnedOnNonbondedDevice)
             simulationWork.useGpuPmePpCommunication       = true;
             simulationWork.useGpuUpdate                   = true;
             bool                havePpDomainDecomposition = true;
-            DeviceStreamManager manager(*deviceInfo, havePpDomainDecomposition, simulationWork, useTiming);
+            DeviceStreamManager manager(deviceInfo, havePpDomainDecomposition, simulationWork, useTiming);
 
             expectValidStreams(&manager, { DeviceStreamType::Pme, DeviceStreamType::NonBondedLocal,
                                            DeviceStreamType::NonBondedNonLocal, DeviceStreamType::PmePpTransfer,
index 012700123b449323537b603778c0c23a87eeb84d..1888a35729ee197f8ad9e18c18246a3079a4f55c 100644 (file)
@@ -80,7 +80,6 @@ void doDeviceTransfers(const DeviceInformation& deviceInfo, ArrayRef<const char>
     cl_context_properties properties[] = {
         CL_CONTEXT_PLATFORM, reinterpret_cast<cl_context_properties>(deviceInfo.oclPlatformId), 0
     };
-    // Give uncrustify more space
 
     auto deviceId = deviceInfo.oclDeviceId;
     auto context  = clCreateContext(properties, 1, &deviceId, nullptr, nullptr, &status);
diff --git a/src/gromacs/gpu_utils/tests/gputest.cpp b/src/gromacs/gpu_utils/tests/gputest.cpp
deleted file mode 100644 (file)
index e89581f..0000000
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * This file is part of the GROMACS molecular simulation package.
- *
- * Copyright (c) 2017,2018,2019,2020, 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.
- *
- * GROMACS is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public License
- * as published by the Free Software Foundation; either version 2.1
- * of the License, or (at your option) any later version.
- *
- * GROMACS is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with GROMACS; if not, see
- * http://www.gnu.org/licenses, or write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
- *
- * If you want to redistribute modifications to GROMACS, please
- * consider that scientific software is very special. Version
- * control is crucial - bugs must be traceable. We will be happy to
- * consider code for inclusion in the official distribution, but
- * derived work must not be called official GROMACS. Details are found
- * in the README & COPYING files - if they are missing, get the
- * official version at http://www.gromacs.org.
- *
- * To help us fund GROMACS development, we humbly ask that you cite
- * the research papers on the package. Check out http://www.gromacs.org.
- */
-/*! \internal \file
- * \brief
- * Tests utilities for GPU device allocation and free.
- *
- * \author Mark Abraham <mark.j.abraham@gmail.com>
- */
-#include "gmxpre.h"
-
-#include "gputest.h"
-
-#include <gtest/gtest.h>
-
-#include "gromacs/gpu_utils/gpu_utils.h"
-#include "gromacs/hardware/device_information.h"
-#include "gromacs/hardware/device_management.h"
-#include "gromacs/utility/smalloc.h"
-
-namespace gmx
-{
-namespace test
-{
-
-GpuTest::GpuTest()
-{
-    if (canPerformDeviceDetection(nullptr))
-    {
-        deviceInfoList_ = findDevices();
-    }
-    // Failing to find valid GPUs does not require further action
-}
-
-GpuTest::~GpuTest() = default;
-
-std::vector<std::unique_ptr<DeviceInformation>>& GpuTest::getDeviceInfoList()
-{
-    return deviceInfoList_;
-}
-
-} // namespace test
-} // namespace gmx
diff --git a/src/gromacs/gpu_utils/tests/gputest.h b/src/gromacs/gpu_utils/tests/gputest.h
deleted file mode 100644 (file)
index 46a53a4..0000000
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * This file is part of the GROMACS molecular simulation package.
- *
- * Copyright (c) 2017,2018,2019,2020, 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.
- *
- * GROMACS is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public License
- * as published by the Free Software Foundation; either version 2.1
- * of the License, or (at your option) any later version.
- *
- * GROMACS is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with GROMACS; if not, see
- * http://www.gnu.org/licenses, or write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
- *
- * If you want to redistribute modifications to GROMACS, please
- * consider that scientific software is very special. Version
- * control is crucial - bugs must be traceable. We will be happy to
- * consider code for inclusion in the official distribution, but
- * derived work must not be called official GROMACS. Details are found
- * in the README & COPYING files - if they are missing, get the
- * official version at http://www.gromacs.org.
- *
- * To help us fund GROMACS development, we humbly ask that you cite
- * the research papers on the package. Check out http://www.gromacs.org.
- */
-/*! \internal \file
- * \brief
- * Declares test fixture testing GPU utility components.
- *
- * \author Mark Abraham <mark.j.abraham@gmail.com>
- */
-#ifndef GMX_GPU_UTILS_TESTS_GPUTEST_H
-#define GMX_GPU_UTILS_TESTS_GPUTEST_H
-
-#include "gmxpre.h"
-
-#include <gtest/gtest.h>
-
-#include "gromacs/hardware/device_management.h"
-
-struct DeviceInformation;
-
-namespace gmx
-{
-namespace test
-{
-
-class GpuTest : public ::testing::Test
-{
-public:
-    //! List of all available devices
-    std::vector<std::unique_ptr<DeviceInformation>> deviceInfoList_;
-
-    GpuTest();
-    ~GpuTest() override;
-    //! Return a vector of handles, each to a device info for a compatible GPU.
-    std::vector<std::unique_ptr<DeviceInformation>>& getDeviceInfoList();
-};
-
-} // namespace test
-} // namespace gmx
-
-#endif
index 7f2408fb4480f96a11b0ca96a5bade06dc5ebe62..173ca15ee300ccba1c15093351769c1aa55c289e 100644 (file)
 #include <gtest/gtest.h>
 
 #include "gromacs/gpu_utils/gpu_utils.h"
+#include "gromacs/hardware/device_management.h"
 #include "gromacs/math/vectypes.h"
 #include "gromacs/utility/arrayref.h"
 #include "gromacs/utility/real.h"
 
 #include "gromacs/math/tests/testarrayrefs.h"
+#include "testutils/test_hardware_environment.h"
 
 #include "devicetransfers.h"
-#include "gputest.h"
 
 namespace gmx
 {
@@ -68,7 +69,7 @@ namespace test
 /*! \internal \brief Typed test fixture for infrastructure for
  * host-side memory used for GPU transfers. */
 template<typename T>
-class HostMemoryTest : public test::GpuTest
+class HostMemoryTest : public ::testing::Test
 {
 public:
     //! Convenience type
@@ -199,14 +200,15 @@ TYPED_TEST(HostAllocatorTestCopyable, VectorsWithDefaultHostAllocatorAlwaysWorks
 
 TYPED_TEST(HostAllocatorTestCopyable, TransfersWithoutPinningWork)
 {
-    for (const DeviceInformation& compatibleDeviceInfo : getCompatibleDevices(this->deviceInfoList_))
+    for (const auto& testDevice : getTestHardwareEnvironment()->getTestDeviceList())
     {
+        setActiveDevice(testDevice->deviceInfo());
         typename TestFixture::VectorType input;
         fillInput(&input, 1);
         typename TestFixture::VectorType output;
         output.resizeWithPadding(input.size());
 
-        runTest(compatibleDeviceInfo, makeArrayRef(input), makeArrayRef(output));
+        runTest(testDevice->deviceInfo(), makeArrayRef(input), makeArrayRef(output));
     }
 }
 
@@ -296,8 +298,9 @@ TYPED_TEST(HostAllocatorTestNoMem, Comparison)
 
 TYPED_TEST(HostAllocatorTestCopyable, TransfersWithPinningWorkWithCuda)
 {
-    for (auto& deviceInfo : this->deviceInfoList_)
+    for (const auto& testDevice : getTestHardwareEnvironment()->getTestDeviceList())
     {
+        setActiveDevice(testDevice->deviceInfo());
         typename TestFixture::VectorType input;
         changePinningPolicy(&input, PinningPolicy::PinnedIfSupported);
         fillInput(&input, 1);
@@ -305,7 +308,7 @@ TYPED_TEST(HostAllocatorTestCopyable, TransfersWithPinningWorkWithCuda)
         changePinningPolicy(&output, PinningPolicy::PinnedIfSupported);
         output.resizeWithPadding(input.size());
 
-        runTest(*deviceInfo, makeArrayRef(input), makeArrayRef(output));
+        runTest(testDevice->deviceInfo(), makeArrayRef(input), makeArrayRef(output));
     }
 }
 
@@ -319,40 +322,31 @@ bool isPinned(const VectorType& v)
 
 TYPED_TEST(HostAllocatorTestCopyable, ManualPinningOperationsWorkWithCuda)
 {
-    if (!canComputeOnDevice())
+    for (const auto& testDevice : getTestHardwareEnvironment()->getTestDeviceList())
     {
-        return;
+        setActiveDevice(testDevice->deviceInfo());
+        typename TestFixture::VectorType input;
+        changePinningPolicy(&input, PinningPolicy::PinnedIfSupported);
+        EXPECT_TRUE(input.get_allocator().pinningPolicy() == PinningPolicy::PinnedIfSupported);
+        EXPECT_TRUE(input.empty());
+        fillInput(&input, 1);
+        // realloc and copy).
+        auto oldInputData = input.data();
+        changePinningPolicy(&input, PinningPolicy::CannotBePinned);
+        EXPECT_FALSE(isPinned(input));
+        // These cannot be equal as both had to be allocated at the same
+        // time for the contents to be able to be copied.
+        EXPECT_NE(oldInputData, input.data());
+
+        // Switching policy to PinnedIfSupported must pin the buffer (via
+        // realloc and copy).
+        oldInputData = input.data();
+        changePinningPolicy(&input, PinningPolicy::PinnedIfSupported);
+        EXPECT_TRUE(isPinned(input));
+        // These cannot be equal as both had to be allocated at the same
+        // time for the contents to be able to be copied.
+        EXPECT_NE(oldInputData, input.data());
     }
-
-    typename TestFixture::VectorType input;
-    changePinningPolicy(&input, PinningPolicy::PinnedIfSupported);
-    EXPECT_TRUE(input.get_allocator().pinningPolicy() == PinningPolicy::PinnedIfSupported);
-    EXPECT_EQ(0, input.size());
-    EXPECT_EQ(0, input.paddedSize());
-    EXPECT_TRUE(input.empty());
-    EXPECT_FALSE(isPinned(input)) << "should not be pinned before allocation";
-
-    // Fill some contents, which will be pinned because of the policy.
-    fillInput(&input, 1);
-    EXPECT_TRUE(isPinned(input)) << "should be pinned after allocation";
-
-    // Switching policy to CannotBePinned must unpin the buffer (via
-    // realloc and copy).
-    auto oldInputData = input.data();
-    changePinningPolicy(&input, PinningPolicy::CannotBePinned);
-    EXPECT_FALSE(isPinned(input)) << "should not be pinned after changing policy to CannotBePinned";
-    // These cannot be equal as both had to be allocated at the same
-    // time for the contents to be able to be copied.
-    EXPECT_NE(oldInputData, input.data());
-
-    // Switching policy to PinnedIfSupported must pin the buffer (via
-    // realloc and copy).
-    oldInputData = input.data();
-    changePinningPolicy(&input, PinningPolicy::PinnedIfSupported);
-    EXPECT_TRUE(isPinned(input)) << "should be pinned after changing policy to PinnedIfSupported";
-    // These cannot be equal as both had to be allocated at the same
-    // time for the contents to be able to be copied.
-    EXPECT_NE(oldInputData, input.data());
 }
 
 #endif
index 9c2ae73c7c8b11a507184d7004f74bbbdc9b5168..26f492369f221be4cc8be9713233ee45e04c9b48 100644 (file)
@@ -54,7 +54,7 @@
 #    include "gromacs/utility/real.h"
 #    include "gromacs/utility/smalloc.h"
 
-#    include "gputest.h"
+#    include "testutils/test_hardware_environment.h"
 
 namespace gmx
 {
@@ -66,26 +66,10 @@ namespace
 {
 
 //! Test fixture
-using PinnedMemoryCheckerTest = GpuTest;
+using PinnedMemoryCheckerTest = ::testing::Test;
 
 TEST_F(PinnedMemoryCheckerTest, DefaultContainerIsRecognized)
 {
-    if (!canComputeOnDevice())
-    {
-        return;
-    }
-
-    std::vector<real> dummy(3, 1.5);
-    EXPECT_FALSE(isHostMemoryPinned(dummy.data()));
-}
-
-TEST_F(PinnedMemoryCheckerTest, NonpinnedContainerIsRecognized)
-{
-    if (!canComputeOnDevice())
-    {
-        return;
-    }
-
     HostVector<real> dummy(3, 1.5);
     changePinningPolicy(&dummy, PinningPolicy::CannotBePinned);
     EXPECT_FALSE(isHostMemoryPinned(dummy.data()));
@@ -93,11 +77,6 @@ TEST_F(PinnedMemoryCheckerTest, NonpinnedContainerIsRecognized)
 
 TEST_F(PinnedMemoryCheckerTest, PinnedContainerIsRecognized)
 {
-    if (!canComputeOnDevice())
-    {
-        return;
-    }
-
     HostVector<real> dummy(3, 1.5);
     changePinningPolicy(&dummy, PinningPolicy::PinnedIfSupported);
     EXPECT_TRUE(isHostMemoryPinned(dummy.data()));
@@ -105,11 +84,6 @@ TEST_F(PinnedMemoryCheckerTest, PinnedContainerIsRecognized)
 
 TEST_F(PinnedMemoryCheckerTest, PinningChangesAreRecognized)
 {
-    if (!canComputeOnDevice())
-    {
-        return;
-    }
-
     HostVector<real> dummy(3, 1.5);
     changePinningPolicy(&dummy, PinningPolicy::PinnedIfSupported);
     EXPECT_TRUE(isHostMemoryPinned(dummy.data())) << "memory starts pinned";
@@ -121,11 +95,6 @@ TEST_F(PinnedMemoryCheckerTest, PinningChangesAreRecognized)
 
 TEST_F(PinnedMemoryCheckerTest, DefaultCBufferIsRecognized)
 {
-    if (!canComputeOnDevice())
-    {
-        return;
-    }
-
     real* dummy;
     snew(dummy, 3);
     EXPECT_FALSE(isHostMemoryPinned(dummy));
@@ -134,11 +103,6 @@ TEST_F(PinnedMemoryCheckerTest, DefaultCBufferIsRecognized)
 
 TEST_F(PinnedMemoryCheckerTest, PinnedCBufferIsRecognized)
 {
-    if (!canComputeOnDevice())
-    {
-        return;
-    }
-
     real* dummy = nullptr;
     pmalloc(reinterpret_cast<void**>(&dummy), 3 * sizeof(real));
     EXPECT_TRUE(isHostMemoryPinned(dummy));
index 0246d4f106bbad06f96637b61dacdaade02d67a8..a27e2430ff88ae4763d9798a89493e2373e98acd 100644 (file)
 
 #if GMX_GPU_CUDA
 
-#    include <vector>
-
-#    include <gtest/gtest.h>
-
+#    include "gromacs/gpu_utils/gputraits.h"
 #    include "gromacs/hardware/device_management.h"
 #    include "gromacs/utility/exceptions.h"
 
+#    include "testutils/test_hardware_environment.h"
 #    include "testutils/testasserts.h"
 #    include "testutils/testmatchers.h"
 
@@ -65,19 +63,20 @@ namespace test
 //! Test data in RVec format
 static const std::vector<RVec> rVecInput = { { 1.0, 2.0, 3.0 }, { 4.0, 5.0, 6.0 } };
 
-TEST(GpuDataTypesCompatibilityTest, RVecAndFloat3OnHost)
+TEST(GpuDataTypesCompatibilityTest, RVecAndFloat3Host)
 {
     std::vector<RVec> rVecOutput(rVecInput.size());
     convertRVecToFloat3OnHost(rVecOutput, rVecInput);
     EXPECT_THAT(rVecInput, testing::Pointwise(RVecEq(ulpTolerance(0)), rVecOutput));
 }
 
-TEST(GpuDataTypesCompatibilityTest, RVecAndFloat3OnDevice)
+TEST(GpuDataTypesCompatibilityTest, RVecAndFloat3Device)
 {
-    if (canComputeOnDevice())
+    for (const auto& testDevice : getTestHardwareEnvironment()->getTestDeviceList())
     {
+        setActiveDevice(testDevice->deviceInfo());
         std::vector<RVec> rVecOutput(rVecInput.size());
-        convertRVecToFloat3OnDevice(rVecOutput, rVecInput);
+        convertRVecToFloat3OnDevice(rVecOutput, rVecInput, testDevice.get());
         EXPECT_THAT(rVecInput, testing::Pointwise(RVecEq(ulpTolerance(0)), rVecOutput));
     }
 }
index 71135fe85e642b2e0d38c9cf3685bc1bf27c8798..023f14ae43913fcd3820e399a27a4f2699482b25 100644 (file)
@@ -63,7 +63,8 @@ void convertRVecToFloat3OnHost(std::vector<gmx::RVec>& /* rVecOutput */,
 }
 
 void convertRVecToFloat3OnDevice(std::vector<gmx::RVec>& /* rVecOutput */,
-                                 const std::vector<gmx::RVec>& /* rVecInput*/)
+                                 const std::vector<gmx::RVec>& /* rVecInput */,
+                                 const TestDevice* /* testDevice */)
 {
     FAIL() << "Can't test float3 and RVec compatibility without CUDA.";
 }
index 0a4134bd9c01139ffea2c53c6b767c544e855bec..7d88601d9f35fe09b55c1c7c87a7fb309a5e0f88 100644 (file)
@@ -105,11 +105,14 @@ static __global__ void convertRVecToFloat3OnDevice_kernel(DeviceBuffer<float3> g
     }
 }
 
-void convertRVecToFloat3OnDevice(std::vector<gmx::RVec>& h_rVecOutput, const std::vector<gmx::RVec>& h_rVecInput)
+void convertRVecToFloat3OnDevice(std::vector<gmx::RVec>&       h_rVecOutput,
+                                 const std::vector<gmx::RVec>& h_rVecInput,
+                                 const TestDevice*             testDevice)
 {
-    DeviceInformation   deviceInfo;
-    const DeviceContext deviceContext(deviceInfo);
-    const DeviceStream  deviceStream(deviceContext, DeviceStreamPriority::Normal, false);
+    const DeviceContext& deviceContext = testDevice->deviceContext();
+    const DeviceStream&  deviceStream  = testDevice->deviceStream();
+
+    setActiveDevice(testDevice->deviceInfo());
 
     const int numElements = h_rVecInput.size();
 
index 79df67f72c8c1dbf32e0a29cd7392ae374fa5893..44a3247a45f0b6ec46c4fb8600208a2f1d1d8463 100644 (file)
 
 #include <vector>
 
+#include <gtest/gtest.h>
+
 #include "gromacs/math/vectypes.h"
 
+#include "testutils/test_device.h"
+
 namespace gmx
 {
 
@@ -64,8 +68,12 @@ void convertRVecToFloat3OnHost(std::vector<gmx::RVec>& rVecOutput, const std::ve
  *
  * \param[out] rVecOutput  Data in RVec format for the output.
  * \param[in]  rVecInput   Data in RVec format with the input.
+ * \param[in]  testDevice  Test herdware environment to get DeviceContext and DeviceStream from.
  */
-void convertRVecToFloat3OnDevice(std::vector<gmx::RVec>& rVecOutput, const std::vector<gmx::RVec>& rVecInput);
+void convertRVecToFloat3OnDevice(std::vector<gmx::RVec>&       rVecOutput,
+                                 const std::vector<gmx::RVec>& rVecInput,
+                                 const TestDevice*             testDevice);
+
 
 } // namespace test
 } // namespace gmx