2016-12-16 22:05:45 +00:00
|
|
|
//============================================================================
|
|
|
|
// Copyright (c) Kitware, Inc.
|
|
|
|
// All rights reserved.
|
|
|
|
// See LICENSE.txt for details.
|
2019-04-15 23:24:21 +00:00
|
|
|
//
|
2016-12-16 22:05:45 +00:00
|
|
|
// This software is distributed WITHOUT ANY WARRANTY; without even
|
|
|
|
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
|
|
// PURPOSE. See the above copyright notice for more information.
|
|
|
|
//============================================================================
|
|
|
|
|
|
|
|
#include <vtkm/cont/ArrayHandle.h>
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
namespace vtkm
|
|
|
|
{
|
|
|
|
namespace cont
|
|
|
|
{
|
2020-04-22 19:58:59 +00:00
|
|
|
namespace detail
|
|
|
|
{
|
|
|
|
|
|
|
|
VTKM_CONT void ArrayHandleReleaseResourcesExecution(
|
|
|
|
const std::vector<vtkm::cont::internal::Buffer>& buffers)
|
|
|
|
{
|
|
|
|
vtkm::cont::Token token;
|
|
|
|
|
|
|
|
for (auto&& buf : buffers)
|
|
|
|
{
|
2020-08-24 21:26:57 +00:00
|
|
|
buf.ReleaseDeviceResources();
|
2020-04-22 19:58:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
VTKM_CONT bool ArrayHandleIsOnDevice(const std::vector<vtkm::cont::internal::Buffer>& buffers,
|
|
|
|
vtkm::cont::DeviceAdapterId device)
|
|
|
|
{
|
|
|
|
for (auto&& buf : buffers)
|
|
|
|
{
|
|
|
|
if (!buf.IsAllocatedOnDevice(device))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} // namespace vtkm::cont::detail
|
|
|
|
|
|
|
|
namespace
|
|
|
|
{
|
|
|
|
|
|
|
|
struct DeviceCheckFunctor
|
|
|
|
{
|
|
|
|
vtkm::cont::DeviceAdapterId FoundDevice = vtkm::cont::DeviceAdapterTagUndefined{};
|
2016-12-16 22:05:45 +00:00
|
|
|
|
2020-04-22 19:58:59 +00:00
|
|
|
VTKM_CONT void operator()(vtkm::cont::DeviceAdapterId device,
|
|
|
|
const std::vector<vtkm::cont::internal::Buffer>& buffers)
|
|
|
|
{
|
|
|
|
if (this->FoundDevice == vtkm::cont::DeviceAdapterTagUndefined{})
|
|
|
|
{
|
|
|
|
if (vtkm::cont::detail::ArrayHandleIsOnDevice(buffers, device))
|
|
|
|
{
|
|
|
|
this->FoundDevice = device;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
} // anonymous namespace
|
|
|
|
|
|
|
|
namespace vtkm
|
|
|
|
{
|
|
|
|
namespace cont
|
|
|
|
{
|
|
|
|
namespace detail
|
|
|
|
{
|
|
|
|
|
|
|
|
VTKM_CONT vtkm::cont::DeviceAdapterId ArrayHandleGetDeviceAdapterId(
|
|
|
|
const std::vector<vtkm::cont::internal::Buffer>& buffers)
|
|
|
|
{
|
|
|
|
DeviceCheckFunctor functor;
|
|
|
|
|
|
|
|
vtkm::ListForEach(functor, VTKM_DEFAULT_DEVICE_ADAPTER_LIST{}, buffers);
|
|
|
|
|
|
|
|
return functor.FoundDevice;
|
|
|
|
}
|
|
|
|
}
|
2016-12-16 22:05:45 +00:00
|
|
|
}
|
2020-04-22 19:58:59 +00:00
|
|
|
} // namespace vtkm::cont::detail
|