vtk-m/vtkm/cont/ArrayHandle.cxx
Kenneth Moreland 4345fe26b0 Store the number of bits of a BitField in the Buffer's metadata
The number of bits in a `BitField` cannot be directly implied from the
size of the buffer (because the buffer gets padded to the nearest sized
word). Thus, the `BitField stored the number of bits in its own
internals.

Unfortunately, that caused issues when passing the `BitField` data
between it and an `ArrayHandleBitField`. If the `ArrayHandleBitField`
resized itself, the `BitField` would not see the new size because it
ignored the new buffer size.

To get around this problem, `BitField` now declares its own
`BufferMetaData` that stores the number of bits. Now, since the number
of bits is stored in the `Buffer` object, it is sufficient to just share
the `Buffer` to synchronize all of the state.
2020-08-24 17:09:30 -06:00

88 lines
1.9 KiB
C++

//============================================================================
// Copyright (c) Kitware, Inc.
// All rights reserved.
// See LICENSE.txt for details.
//
// 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>
namespace vtkm
{
namespace cont
{
namespace detail
{
VTKM_CONT void ArrayHandleReleaseResourcesExecution(
const std::vector<vtkm::cont::internal::Buffer>& buffers)
{
vtkm::cont::Token token;
for (auto&& buf : buffers)
{
buf.ReleaseDeviceResources();
}
}
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{};
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;
}
}
}
} // namespace vtkm::cont::detail