Make corresponding device active before each TestDevice is created
authorArtem Zhmurov <zhmurov@gmail.com>
Tue, 17 Nov 2020 14:22:41 +0000 (17:22 +0300)
committerSzilárd Páll <pall.szilard@gmail.com>
Mon, 23 Nov 2020 17:56:11 +0000 (17:56 +0000)
When populating the list of GPU devices for tests, the DeviceContext and
DeviceStream objects are created for each TestDevice. In CUDA, the
active device has to be explicitly set by the API since the DeviceStream
is created for the active device. Otherwise, all the streams are created
for the first device. When these streams are later used for the devices
other than first, CUDA API returns an invalid argument error. The bug only
affects unit tests in CUDA builds for systems with more than one GPU.
Does not affect OpenCL/SYCL builds, because they use DeviceContext to
attach the device to the stream (queue).

Fixes #3781, #3782 and #3805.

src/testutils/test_hardware_environment.cpp

index 267c73cf27b927af5b3c6b0c520cc377784e8b65..5a06c351318f4ad0d88848e12b741ee4087db4d1 100644 (file)
@@ -99,6 +99,7 @@ void TestHardwareEnvironment::SetUp()
     // Constructing contexts for all compatible GPUs - will be empty on non-GPU builds
     for (const DeviceInformation& compatibleDeviceInfo : getCompatibleDevices(hardwareInfo_->deviceInfoList))
     {
+        setActiveDevice(compatibleDeviceInfo);
         std::string description = getDeviceInformationString(compatibleDeviceInfo);
         testDeviceList_.emplace_back(std::make_unique<TestDevice>(description.c_str(), compatibleDeviceInfo));
     }