Use vtkm::UInt64 for byte sizes.

vtkm::Id could be just 32bits, which limits the number of values we
would be able to store for large arrays.
This commit is contained in:
Allison Vacanti 2017-09-18 13:03:26 -04:00
parent c4c05d8b72
commit 00320e5dc0
8 changed files with 51 additions and 47 deletions

@ -115,7 +115,7 @@ public:
/// \brief Return the number of bytes allocated for this storage object.
VTKM_CONT
virtual vtkm::Id GetNumberOfBytes() const = 0;
virtual vtkm::UInt64 GetNumberOfBytes() const = 0;
/// \brief Allocates an array with the specified size in bytes.
///
@ -125,7 +125,7 @@ public:
/// ErrorBadValue if the allocation is not feasible (for example, the
/// array storage is read-only).
VTKM_CONT
virtual void AllocateBytes(vtkm::Id numberOfBytes) = 0;
virtual void AllocateBytes(vtkm::UInt64 numberOfBytes) = 0;
/// \brief Reduces the size of the array without changing its values.
///
@ -135,7 +135,7 @@ public:
/// equal or less than the preexisting size. That is, this method can only be
/// used to shorten the array, not lengthen.
VTKM_CONT
virtual void ShrinkBytes(vtkm::Id numberOfBytes) = 0;
virtual void ShrinkBytes(vtkm::UInt64 numberOfBytes) = 0;
/// \brief Frees any resources (i.e. memory) stored in this array.
///
@ -213,19 +213,20 @@ public:
vtkm::Id GetNumberOfValues() const { return this->NumberOfValues; }
VTKM_CONT
vtkm::Id GetNumberOfBytes() const final
vtkm::UInt64 GetNumberOfBytes() const final
{
return this->NumberOfValues * static_cast<vtkm::Id>(sizeof(ValueT));
return static_cast<vtkm::UInt64>(this->NumberOfValues) *
static_cast<vtkm::UInt64>(sizeof(ValueT));
}
VTKM_CONT
void Shrink(vtkm::Id numberOfValues);
VTKM_CONT
void AllocateBytes(vtkm::Id) final;
void AllocateBytes(vtkm::UInt64) final;
VTKM_CONT
void ShrinkBytes(vtkm::Id) final;
void ShrinkBytes(vtkm::UInt64) final;
VTKM_CONT
PortalType GetPortal() { return PortalType(this->Array, this->Array + this->NumberOfValues); }

@ -123,18 +123,15 @@ void Storage<T, vtkm::cont::StorageTagBasic>::Allocate(vtkm::Id numberOfValues)
{
throw ErrorBadAllocation("Requested allocation exceeds size_t capacity.");
}
this->AllocateBytes(numberOfValues * static_cast<vtkm::Id>(sizeof(T)));
this->AllocateBytes(static_cast<vtkm::UInt64>(numberOfValues) *
static_cast<vtkm::UInt64>(sizeof(T)));
}
template <typename T>
void Storage<T, vtkm::cont::StorageTagBasic>::AllocateBytes(vtkm::Id numberOfBytes)
void Storage<T, vtkm::cont::StorageTagBasic>::AllocateBytes(vtkm::UInt64 numberOfBytes)
{
if (numberOfBytes < 0)
{
throw vtkm::cont::ErrorBadAllocation("Cannot allocate an array with negative size.");
}
const vtkm::Id numberOfValues = numberOfBytes / static_cast<vtkm::Id>(sizeof(T));
const vtkm::Id numberOfValues =
static_cast<vtkm::Id>(numberOfBytes / static_cast<vtkm::UInt64>(sizeof(T)));
// If we are allocating less data, just shrink the array.
// (If allocation empty, drop down so we can deallocate memory.)
@ -180,18 +177,20 @@ void Storage<T, vtkm::cont::StorageTagBasic>::AllocateBytes(vtkm::Id numberOfByt
template <typename T>
void Storage<T, vtkm::cont::StorageTagBasic>::Shrink(vtkm::Id numberOfValues)
{
this->ShrinkBytes(numberOfValues * static_cast<vtkm::Id>(sizeof(T)));
this->ShrinkBytes(static_cast<vtkm::UInt64>(numberOfValues) *
static_cast<vtkm::UInt64>(sizeof(T)));
}
template <typename T>
void Storage<T, vtkm::cont::StorageTagBasic>::ShrinkBytes(vtkm::Id numberOfBytes)
void Storage<T, vtkm::cont::StorageTagBasic>::ShrinkBytes(vtkm::UInt64 numberOfBytes)
{
if (numberOfBytes > this->GetNumberOfBytes())
{
throw vtkm::cont::ErrorBadValue("Shrink method cannot be used to grow array.");
}
this->NumberOfValues = numberOfBytes / static_cast<vtkm::Id>(sizeof(T));
this->NumberOfValues =
static_cast<vtkm::Id>(numberOfBytes / static_cast<vtkm::UInt64>(sizeof(T)));
}
template <typename T>

@ -44,13 +44,14 @@ DeviceAdapterId ExecutionArrayInterfaceBasic<DeviceAdapterTagCuda>::GetDeviceId(
}
void ExecutionArrayInterfaceBasic<DeviceAdapterTagCuda>::Allocate(TypelessExecutionArray& execArray,
vtkm::Id numBytes) const
vtkm::UInt64 numBytes) const
{
// Detect if we can reuse a device-accessible pointer from the control env:
if (CudaAllocator::IsDevicePointer(execArray.ArrayControl))
{
const vtkm::Id managedCapacity = static_cast<const char*>(execArray.ArrayControlCapacity) -
static_cast<const char*>(execArray.ArrayControl);
const vtkm::UInt64 managedCapacity =
static_cast<vtkm::UInt64>(static_cast<const char*>(execArray.ArrayControlCapacity) -
static_cast<const char*>(execArray.ArrayControl));
if (managedCapacity >= numBytes)
{
if (execArray.Array && execArray.Array != execArray.ArrayControl)
@ -67,8 +68,8 @@ void ExecutionArrayInterfaceBasic<DeviceAdapterTagCuda>::Allocate(TypelessExecut
if (execArray.Array != nullptr)
{
const vtkm::Id cap =
static_cast<char*>(execArray.ArrayCapacity) - static_cast<char*>(execArray.Array);
const vtkm::UInt64 cap = static_cast<vtkm::UInt64>(static_cast<char*>(execArray.ArrayCapacity) -
static_cast<char*>(execArray.Array));
if (cap < numBytes)
{ // Current allocation too small -- free & realloc
@ -123,9 +124,10 @@ void ExecutionArrayInterfaceBasic<DeviceAdapterTagCuda>::Free(
}
}
void ExecutionArrayInterfaceBasic<DeviceAdapterTagCuda>::CopyFromControl(const void* controlPtr,
void* executionPtr,
vtkm::Id numBytes) const
void ExecutionArrayInterfaceBasic<DeviceAdapterTagCuda>::CopyFromControl(
const void* controlPtr,
void* executionPtr,
vtkm::UInt64 numBytes) const
{
// Do nothing if we're sharing a device-accessible pointer between control and
// execution:
@ -143,7 +145,7 @@ void ExecutionArrayInterfaceBasic<DeviceAdapterTagCuda>::CopyFromControl(const v
void ExecutionArrayInterfaceBasic<DeviceAdapterTagCuda>::CopyToControl(const void* executionPtr,
void* controlPtr,
vtkm::Id numBytes) const
vtkm::UInt64 numBytes) const
{
// Do nothing if we're sharing a cuda managed pointer between control and execution:
if (controlPtr == executionPtr && CudaAllocator::IsDevicePointer(controlPtr))

@ -151,14 +151,14 @@ struct VTKM_CONT_EXPORT ExecutionArrayInterfaceBasic<DeviceAdapterTagCuda>
VTKM_CONT ExecutionArrayInterfaceBasic(StorageBasicBase& storage);
VTKM_CONT DeviceAdapterId GetDeviceId() const final;
VTKM_CONT void Allocate(TypelessExecutionArray& execArray, vtkm::Id numBytes) const final;
VTKM_CONT void Allocate(TypelessExecutionArray& execArray, vtkm::UInt64 numBytes) const final;
VTKM_CONT void Free(TypelessExecutionArray& execArray) const final;
VTKM_CONT void CopyFromControl(const void* controlPtr,
void* executionPtr,
vtkm::Id numBytes) const final;
vtkm::UInt64 numBytes) const final;
VTKM_CONT void CopyToControl(const void* executionPtr,
void* controlPtr,
vtkm::Id numBytes) const final;
vtkm::UInt64 numBytes) const final;
};
} // namespace internal

@ -94,7 +94,7 @@ struct VTKM_CONT_EXPORT ExecutionArrayInterfaceBasicBase
/// If (capacity - base) < @a numBytes, the buffer will be freed and
/// reallocated. If (capacity - base) >= numBytes, a new end is marked.
VTKM_CONT
virtual void Allocate(TypelessExecutionArray& execArray, vtkm::Id numBytes) const = 0;
virtual void Allocate(TypelessExecutionArray& execArray, vtkm::UInt64 numBytes) const = 0;
/// Release the buffer held by @a execArray and reset all pointer to null.
VTKM_CONT
@ -104,13 +104,13 @@ struct VTKM_CONT_EXPORT ExecutionArrayInterfaceBasicBase
VTKM_CONT
virtual void CopyFromControl(const void* controlPtr,
void* executionPtr,
vtkm::Id numBytes) const = 0;
vtkm::UInt64 numBytes) const = 0;
/// Copy @a numBytes from @a executionPtr to @a controlPtr.
VTKM_CONT
virtual void CopyToControl(const void* executionPtr,
void* controlPtr,
vtkm::Id numBytes) const = 0;
vtkm::UInt64 numBytes) const = 0;
protected:
StorageBasicBase& ControlStorage;

@ -197,7 +197,8 @@ void ArrayHandle<T, StorageTagBasic>::CopyInto(IteratorType dest, DeviceAdapterT
this->Internals->ExecutionInterface &&
this->Internals->ExecutionInterface->GetDeviceId() == devId)
{
vtkm::Id numBytes = static_cast<vtkm::Id>(sizeof(ValueType)) * this->GetNumberOfValues();
vtkm::UInt64 numBytes = static_cast<vtkm::UInt64>(sizeof(ValueType)) *
static_cast<vtkm::UInt64>(this->GetNumberOfValues());
this->Internals->ExecutionInterface->CopyToControl(
this->Internals->ExecutionArray, dest, numBytes);
}
@ -306,8 +307,8 @@ ArrayHandle<T, StorageTagBasic>::PrepareForInput(DeviceAdapterTag device) const
this->Internals->ControlArray.GetBasePointer(),
this->Internals->ControlArray.GetCapacityPointer());
const vtkm::Id numBytes =
static_cast<vtkm::Id>(sizeof(ValueType)) * this->GetStorage().GetNumberOfValues();
const vtkm::UInt64 numBytes = static_cast<vtkm::UInt64>(sizeof(ValueType)) *
static_cast<vtkm::UInt64>(this->GetStorage().GetNumberOfValues());
priv->ExecutionInterface->Allocate(execArray, numBytes);
@ -342,8 +343,8 @@ ArrayHandle<T, StorageTagBasic>::PrepareForOutput(vtkm::Id numVals, DeviceAdapte
this->Internals->ControlArray.GetBasePointer(),
this->Internals->ControlArray.GetCapacityPointer());
this->Internals->ExecutionInterface->Allocate(execArray,
static_cast<vtkm::Id>(sizeof(ValueType)) * numVals);
this->Internals->ExecutionInterface->Allocate(
execArray, static_cast<vtkm::UInt64>(sizeof(ValueType)) * static_cast<vtkm::UInt64>(numVals));
this->Internals->ExecutionArrayValid = true;
@ -377,8 +378,8 @@ ArrayHandle<T, StorageTagBasic>::PrepareForInPlace(DeviceAdapterTag device)
this->Internals->ControlArray.GetBasePointer(),
this->Internals->ControlArray.GetCapacityPointer());
vtkm::Id numBytes =
static_cast<vtkm::Id>(sizeof(ValueType)) * this->GetStorage().GetNumberOfValues();
vtkm::UInt64 numBytes = static_cast<vtkm::UInt64>(sizeof(ValueType)) *
static_cast<vtkm::UInt64>(this->GetStorage().GetNumberOfValues());
priv->ExecutionInterface->Allocate(execArray, numBytes);
@ -454,7 +455,8 @@ void ArrayHandle<T, StorageTagBasic>::SyncControlArray() const
{
const vtkm::Id numValues =
static_cast<vtkm::Id>(this->Internals->ExecutionArrayEnd - this->Internals->ExecutionArray);
const vtkm::Id numBytes = static_cast<vtkm::Id>(sizeof(ValueType)) * numValues;
const vtkm::UInt64 numBytes =
static_cast<vtkm::UInt64>(sizeof(ValueType)) * static_cast<vtkm::UInt64>(numValues);
priv->ControlArray.Allocate(numValues);
priv->ExecutionInterface->CopyToControl(
priv->ExecutionArray, priv->ControlArray.GetArray(), numBytes);

@ -34,7 +34,7 @@ ExecutionArrayInterfaceBasicShareWithControl::ExecutionArrayInterfaceBasicShareW
}
void ExecutionArrayInterfaceBasicShareWithControl::Allocate(TypelessExecutionArray& execArray,
Id numBytes) const
vtkm::UInt64 numBytes) const
{
this->ControlStorage.AllocateBytes(numBytes);
@ -54,7 +54,7 @@ void ExecutionArrayInterfaceBasicShareWithControl::Free(TypelessExecutionArray&
void ExecutionArrayInterfaceBasicShareWithControl::CopyFromControl(const void* src,
void* dst,
Id bytes) const
vtkm::UInt64 bytes) const
{
if (src != dst)
{
@ -67,7 +67,7 @@ void ExecutionArrayInterfaceBasicShareWithControl::CopyFromControl(const void* s
void ExecutionArrayInterfaceBasicShareWithControl::CopyToControl(const void* src,
void* dst,
Id bytes) const
vtkm::UInt64 bytes) const
{
if (src != dst)
{

@ -151,10 +151,10 @@ struct VTKM_CONT_EXPORT ExecutionArrayInterfaceBasicShareWithControl
VTKM_CONT ExecutionArrayInterfaceBasicShareWithControl(StorageBasicBase& storage);
VTKM_CONT void Allocate(TypelessExecutionArray& execArray, vtkm::Id numBytes) const final;
VTKM_CONT void Allocate(TypelessExecutionArray& execArray, vtkm::UInt64 numBytes) const final;
VTKM_CONT void Free(TypelessExecutionArray& execArray) const final;
VTKM_CONT void CopyFromControl(const void* src, void* dst, vtkm::Id bytes) const final;
VTKM_CONT void CopyToControl(const void* src, void* dst, vtkm::Id bytes) const final;
VTKM_CONT void CopyFromControl(const void* src, void* dst, vtkm::UInt64 bytes) const final;
VTKM_CONT void CopyToControl(const void* src, void* dst, vtkm::UInt64 bytes) const final;
};
}
}