From b6e61f9447376daa81093387244b492cc59ccf4c Mon Sep 17 00:00:00 2001 From: Kenneth Moreland Date: Mon, 29 May 2023 20:55:48 -0400 Subject: [PATCH] Fixed an issue with copying array from a disabled device The internal array copy has an optimization to use the device the array exists on to do the copy. However, if that device is disabled the copy would fail. This problem has been fixed. --- docs/changelog/copy-from-disabled-device.md | 5 +++++ vtkm/cont/internal/ArrayCopyUnknown.cxx | 3 ++- vtkm/cont/testing/UnitTestArrayCopy.cxx | 18 ++++++++++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 docs/changelog/copy-from-disabled-device.md diff --git a/docs/changelog/copy-from-disabled-device.md b/docs/changelog/copy-from-disabled-device.md new file mode 100644 index 000000000..c0657cdc3 --- /dev/null +++ b/docs/changelog/copy-from-disabled-device.md @@ -0,0 +1,5 @@ +# Fix an issue with copying array from a disabled device + +The internal array copy has an optimization to use the device the array +exists on to do the copy. However, if that device is disabled the copy +would fail. This problem has been fixed. diff --git a/vtkm/cont/internal/ArrayCopyUnknown.cxx b/vtkm/cont/internal/ArrayCopyUnknown.cxx index fdee4befc..bbeb16571 100644 --- a/vtkm/cont/internal/ArrayCopyUnknown.cxx +++ b/vtkm/cont/internal/ArrayCopyUnknown.cxx @@ -52,7 +52,8 @@ struct UnknownCopyOnDevice // by pulling out one of the component arrays and querying that. if (!this->Called && ((device == vtkm::cont::DeviceAdapterTagAny{}) || - (in.GetComponentArray(0).IsOnDevice(device)))) + (in.GetComponentArray(0).IsOnDevice(device) && + vtkm::cont::GetRuntimeDeviceTracker().CanRunOn(device)))) { vtkm::cont::Invoker invoke(device); invoke(CopyWorklet{}, in, out); diff --git a/vtkm/cont/testing/UnitTestArrayCopy.cxx b/vtkm/cont/testing/UnitTestArrayCopy.cxx index 4526f638b..0c36c12bb 100644 --- a/vtkm/cont/testing/UnitTestArrayCopy.cxx +++ b/vtkm/cont/testing/UnitTestArrayCopy.cxx @@ -199,6 +199,24 @@ void TryCopy() TestValues(input, output); } + { + std::cout << "unknown -> basic (different type, unsupported device)" << std::endl; + // Force the source to be on the Serial device. If the --vtkm-device argument was + // given with a different device (which is how ctest is set up if compiled with + // any device), then Serial will be turned off. + using SourceType = typename VTraits::template ReplaceComponentType; + auto rawInput = MakeInputArray(); + { + // Force moving the data to the Serial device. + vtkm::cont::Token token; + rawInput.PrepareForInput(vtkm::cont::DeviceAdapterTagSerial{}, token); + } + vtkm::cont::UnknownArrayHandle input = rawInput; + vtkm::cont::ArrayHandle output; + vtkm::cont::ArrayCopy(input, output); + TestValues(input, output); + } + // Test the copy methods in UnknownArrayHandle. Although this would be appropriate in // UnitTestUnknownArrayHandle, it is easier to test copies here. {