vtk-m/vtkm/cont/ArrayHandleStreaming.h

259 lines
6.5 KiB
C
Raw Normal View History

//============================================================================
// 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.
//
// Copyright 2014 Sandia Corporation.
// Copyright 2014 UT-Battelle, LLC.
// Copyright 2014 Los Alamos National Security.
//
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
// the U.S. Government retains certain rights in this software.
//
// Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
// Laboratory (LANL), the U.S. Government retains certain rights in
// this software.
//============================================================================
#ifndef vtk_m_cont_ArrayHandleStreaming_h
#define vtk_m_cont_ArrayHandleStreaming_h
2016-08-03 21:34:43 +00:00
#include <vtkm/cont/ArrayHandle.h>
#include <vtkm/cont/ArrayPortal.h>
2017-05-18 14:29:41 +00:00
namespace vtkm
{
namespace cont
{
namespace internal
{
2016-08-03 21:34:43 +00:00
2017-05-18 14:29:41 +00:00
template <typename P>
class VTKM_ALWAYS_EXPORT ArrayPortalStreaming
2016-08-03 21:34:43 +00:00
{
public:
typedef P PortalType;
typedef typename PortalType::ValueType ValueType;
VTKM_CONT
2017-05-18 14:29:41 +00:00
ArrayPortalStreaming()
: InputPortal()
, BlockIndex(0)
, BlockSize(0)
, CurBlockSize(0)
{
}
2016-08-03 21:34:43 +00:00
VTKM_CONT
2017-05-18 14:29:41 +00:00
ArrayPortalStreaming(const PortalType& inputPortal, vtkm::Id blockIndex, vtkm::Id blockSize,
vtkm::Id curBlockSize)
: InputPortal(inputPortal)
, BlockIndex(blockIndex)
, BlockSize(blockSize)
, CurBlockSize(curBlockSize)
{
}
2016-08-03 21:34:43 +00:00
2017-05-18 14:29:41 +00:00
template <typename OtherP>
VTKM_CONT ArrayPortalStreaming(const ArrayPortalStreaming<OtherP>& src)
: InputPortal(src.GetPortal())
, BlockIndex(src.GetBlockIndex())
, BlockSize(src.GetBlockSize())
, CurBlockSize(src.GetCurBlockSize())
{
}
2016-08-03 21:34:43 +00:00
VTKM_CONT
2017-05-18 14:29:41 +00:00
vtkm::Id GetNumberOfValues() const { return this->CurBlockSize; }
2016-08-03 21:34:43 +00:00
VTKM_CONT
2017-05-18 14:29:41 +00:00
ValueType Get(vtkm::Id index) const
{
return this->InputPortal.Get(this->BlockIndex * this->BlockSize + index);
2016-08-03 21:34:43 +00:00
}
VTKM_CONT
2017-05-18 14:29:41 +00:00
void Set(vtkm::Id index, const ValueType& value) const
{
this->InputPortal.Set(this->BlockIndex * this->BlockSize + index, value);
2016-08-03 21:34:43 +00:00
}
VTKM_CONT
2017-05-18 14:29:41 +00:00
const PortalType& GetPortal() const { return this->InputPortal; }
2016-08-03 21:34:43 +00:00
VTKM_CONT
void SetBlockSize(vtkm::Id blockSize) { this->BlockSize = blockSize; }
2016-08-03 21:34:43 +00:00
VTKM_CONT
void SetBlockIndex(vtkm::Id blockIndex) { this->BlockIndex = blockIndex; }
2016-08-03 21:34:43 +00:00
VTKM_CONT
void SetCurBlockSize(vtkm::Id curBlockSize) { this->CurBlockSize = curBlockSize; }
2016-08-03 21:34:43 +00:00
VTKM_CONT
2016-08-03 21:34:43 +00:00
vtkm::Id GetBlockSize() { return this->BlockSize; }
VTKM_CONT
2016-08-03 21:34:43 +00:00
vtkm::Id GetBlockIndex() { return this->BlockIndex; }
VTKM_CONT
2016-08-03 21:34:43 +00:00
vtkm::Id GetCurBlockSize() { return this->CurBlockSize; }
private:
PortalType InputPortal;
vtkm::Id BlockIndex;
vtkm::Id BlockSize;
2016-08-03 21:34:43 +00:00
vtkm::Id CurBlockSize;
};
} // internal
2016-08-03 21:34:43 +00:00
2017-05-18 14:29:41 +00:00
template <typename ArrayHandleInputType>
struct VTKM_ALWAYS_EXPORT StorageTagStreaming
{
};
2016-08-03 21:34:43 +00:00
2017-05-18 14:29:41 +00:00
namespace internal
{
2016-08-03 21:34:43 +00:00
2017-05-18 14:29:41 +00:00
template <typename ArrayHandleInputType>
class Storage<typename ArrayHandleInputType::ValueType, StorageTagStreaming<ArrayHandleInputType>>
2016-08-03 21:34:43 +00:00
{
public:
typedef typename ArrayHandleInputType::ValueType ValueType;
2017-05-18 14:29:41 +00:00
typedef vtkm::cont::internal::ArrayPortalStreaming<typename ArrayHandleInputType::PortalControl>
PortalType;
typedef vtkm::cont::internal::ArrayPortalStreaming<
2017-05-18 14:29:41 +00:00
typename ArrayHandleInputType::PortalConstControl>
PortalConstType;
2016-08-03 21:34:43 +00:00
VTKM_CONT
2017-05-18 14:29:41 +00:00
Storage()
: Valid(false)
{
}
2016-08-03 21:34:43 +00:00
VTKM_CONT
2017-05-18 14:29:41 +00:00
Storage(const ArrayHandleInputType inputArray, vtkm::Id blockSize, vtkm::Id blockIndex,
vtkm::Id curBlockSize)
: InputArray(inputArray)
, BlockSize(blockSize)
, BlockIndex(blockIndex)
, CurBlockSize(curBlockSize)
, Valid(true)
{
}
2016-08-03 21:34:43 +00:00
VTKM_CONT
2017-05-18 14:29:41 +00:00
PortalType GetPortal()
{
2016-08-03 21:34:43 +00:00
VTKM_ASSERT(this->Valid);
2017-05-18 14:29:41 +00:00
return PortalType(this->InputArray.GetPortalControl(), BlockSize, BlockIndex, CurBlockSize);
2016-08-03 21:34:43 +00:00
}
VTKM_CONT
2017-05-18 14:29:41 +00:00
PortalConstType GetPortalConst() const
{
2016-08-03 21:34:43 +00:00
VTKM_ASSERT(this->Valid);
2017-05-18 14:29:41 +00:00
return PortalConstType(this->InputArray.GetPortalConstControl(), BlockSize, BlockIndex,
CurBlockSize);
2016-08-03 21:34:43 +00:00
}
VTKM_CONT
2017-05-18 14:29:41 +00:00
vtkm::Id GetNumberOfValues() const
{
2016-08-03 21:34:43 +00:00
VTKM_ASSERT(this->Valid);
return CurBlockSize;
2016-08-03 21:34:43 +00:00
}
VTKM_CONT
2017-05-18 14:29:41 +00:00
void Allocate(vtkm::Id numberOfValues) const
{
(void)numberOfValues;
2016-08-03 21:34:43 +00:00
// Do nothing, since we only allocate a streaming array once at the beginning
}
VTKM_CONT
2017-05-18 14:29:41 +00:00
void AllocateFullArray(vtkm::Id numberOfValues)
{
2016-08-03 21:34:43 +00:00
VTKM_ASSERT(this->Valid);
this->InputArray.Allocate(numberOfValues);
}
VTKM_CONT
2017-05-18 14:29:41 +00:00
void Shrink(vtkm::Id numberOfValues)
{
2016-08-03 21:34:43 +00:00
VTKM_ASSERT(this->Valid);
this->InputArray.Shrink(numberOfValues);
}
VTKM_CONT
2017-05-18 14:29:41 +00:00
void ReleaseResources()
{
2016-08-03 21:34:43 +00:00
VTKM_ASSERT(this->Valid);
this->InputArray.ReleaseResources();
}
VTKM_CONT
2017-05-18 14:29:41 +00:00
const ArrayHandleInputType& GetArray() const
{
2016-08-03 21:34:43 +00:00
VTKM_ASSERT(this->Valid);
return this->InputArray;
}
private:
ArrayHandleInputType InputArray;
vtkm::Id BlockSize;
vtkm::Id BlockIndex;
vtkm::Id CurBlockSize;
bool Valid;
2016-08-03 21:34:43 +00:00
};
}
}
}
2017-05-18 14:29:41 +00:00
namespace vtkm
{
namespace cont
{
2016-08-03 21:34:43 +00:00
2017-05-18 14:29:41 +00:00
template <typename ArrayHandleInputType>
2016-08-03 21:34:43 +00:00
class ArrayHandleStreaming
2017-05-18 14:29:41 +00:00
: public vtkm::cont::ArrayHandle<typename ArrayHandleInputType::ValueType,
StorageTagStreaming<ArrayHandleInputType>>
2016-08-03 21:34:43 +00:00
{
public:
2017-05-18 14:29:41 +00:00
VTKM_ARRAY_HANDLE_SUBCLASS(ArrayHandleStreaming, (ArrayHandleStreaming<ArrayHandleInputType>),
(vtkm::cont::ArrayHandle<typename ArrayHandleInputType::ValueType,
StorageTagStreaming<ArrayHandleInputType>>));
2016-08-03 21:34:43 +00:00
private:
2017-05-18 14:29:41 +00:00
typedef vtkm::cont::internal::Storage<ValueType, StorageTag> StorageType;
2016-08-03 21:34:43 +00:00
public:
VTKM_CONT
2017-05-18 14:29:41 +00:00
ArrayHandleStreaming(const ArrayHandleInputType& inputArray, const vtkm::Id blockIndex,
const vtkm::Id blockSize, const vtkm::Id curBlockSize)
: Superclass(StorageType(inputArray, blockIndex, blockSize, curBlockSize))
{
2016-08-03 21:34:43 +00:00
this->GetPortalConstControl().SetBlockIndex(blockIndex);
this->GetPortalConstControl().SetBlockSize(blockSize);
this->GetPortalConstControl().SetCurBlockSize(curBlockSize);
}
VTKM_CONT
2017-05-18 14:29:41 +00:00
void AllocateFullArray(vtkm::Id numberOfValues)
{
2016-08-03 21:34:43 +00:00
this->ReleaseResourcesExecutionInternal();
this->Internals->ControlArray.AllocateFullArray(numberOfValues);
this->Internals->ControlArrayValid = true;
}
};
}
}
#endif //vtk_m_cont_ArrayHandleStreaming_h