Commit 7158d56c authored by Kenneth Moreland's avatar Kenneth Moreland Committed by Kitware Robot
Browse files

Merge topic 'allocate-implicit-storage'

e62091a6

 Add ability to "allocate" implicit storage
Acked-by: Kitware Robot's avatarKitware Robot <kwrobot@kitware.com>
Acked-by: Haocheng LIU's avatarHaocheng LIU <haocheng.liu@kitware.com>
Merge-request: !1252
parents 02ce5abe e62091a6
......@@ -70,6 +70,7 @@ public:
VTKM_CONT
Storage(const PortalConstType& portal = PortalConstType())
: Portal(portal)
, NumberOfValues(portal.GetNumberOfValues())
{
}
......@@ -79,22 +80,25 @@ public:
VTKM_CONT
PortalConstType GetPortalConst() const { return this->Portal; }
VTKM_CONT
vtkm::Id GetNumberOfValues() const { return this->Portal.GetNumberOfValues(); }
vtkm::Id GetNumberOfValues() const { return this->NumberOfValues; }
VTKM_CONT
void Allocate(vtkm::Id vtkmNotUsed(numberOfValues))
void Allocate(vtkm::Id numberOfValues)
{
throw vtkm::cont::ErrorBadValue("Implicit arrays are read-only.");
VTKM_ASSERT(numberOfValues <= this->Portal.GetNumberOfValues());
this->NumberOfValues = numberOfValues;
}
VTKM_CONT
void Shrink(vtkm::Id vtkmNotUsed(numberOfValues))
void Shrink(vtkm::Id numberOfValues)
{
throw vtkm::cont::ErrorBadValue("Implicit arrays are read-only.");
VTKM_ASSERT(numberOfValues <= this->Portal.GetNumberOfValues());
this->NumberOfValues = numberOfValues;
}
VTKM_CONT
void ReleaseResources() {}
private:
PortalConstType Portal;
vtkm::Id NumberOfValues;
};
template <typename T, class ArrayPortalType, class DeviceAdapterTag>
......
......@@ -33,6 +33,8 @@
namespace
{
const vtkm::Id ARRAY_SIZE = 10;
template <typename T>
struct TestImplicitStorage
{
......@@ -46,14 +48,12 @@ struct TestImplicitStorage
}
VTKM_EXEC_CONT
vtkm::Id GetNumberOfValues() const { return 1; }
vtkm::Id GetNumberOfValues() const { return ARRAY_SIZE; }
VTKM_EXEC_CONT
ValueType Get(vtkm::Id vtkmNotUsed(index)) const { return Temp; }
};
const vtkm::Id ARRAY_SIZE = 1;
template <typename T>
struct TemplatedTests
{
......@@ -68,39 +68,46 @@ struct TemplatedTests
{
StorageType arrayStorage;
// The implicit portal defined for this test always returns 1 for the
// The implicit portal defined for this test always returns ARRAY_SIZE for the
// number of values. We should get that.
VTKM_TEST_ASSERT(arrayStorage.GetNumberOfValues() == 1,
VTKM_TEST_ASSERT(arrayStorage.GetNumberOfValues() == ARRAY_SIZE,
"Implicit Storage GetNumberOfValues returned wrong size.");
try
{
arrayStorage.Allocate(ARRAY_SIZE);
VTKM_TEST_ASSERT(false == true, "Implicit Storage Allocate method didn't throw error.");
}
catch (vtkm::cont::ErrorBadValue&)
{
}
try
{
arrayStorage.Shrink(ARRAY_SIZE);
VTKM_TEST_ASSERT(true == false,
"Array shrink do a larger size was possible. This can't be allowed.");
}
catch (vtkm::cont::ErrorBadValue&)
{
}
// Make sure you can allocate and shrink to any value <= the reported portal size.
arrayStorage.Allocate(ARRAY_SIZE / 2);
VTKM_TEST_ASSERT(arrayStorage.GetNumberOfValues() == ARRAY_SIZE / 2,
"Cannot re-Allocate array to half size.");
arrayStorage.Allocate(0);
VTKM_TEST_ASSERT(arrayStorage.GetNumberOfValues() == 0, "Cannot re-Allocate array to zero.");
arrayStorage.Allocate(ARRAY_SIZE);
VTKM_TEST_ASSERT(arrayStorage.GetNumberOfValues() == ARRAY_SIZE,
"Cannot re-Allocate array to original size.");
arrayStorage.Shrink(ARRAY_SIZE / 2);
VTKM_TEST_ASSERT(arrayStorage.GetNumberOfValues() == ARRAY_SIZE / 2,
"Cannot Shrink array to half size.");
arrayStorage.Shrink(0);
VTKM_TEST_ASSERT(arrayStorage.GetNumberOfValues() == 0, "Cannot Shrink array to zero.");
arrayStorage.Shrink(ARRAY_SIZE);
VTKM_TEST_ASSERT(arrayStorage.GetNumberOfValues() == ARRAY_SIZE,
"Cannot Shrink array to original size.");
//verify that calling ReleaseResources doesn't throw an exception
arrayStorage.ReleaseResources();
//verify that you can allocate after releasing resources.
arrayStorage.Allocate(ARRAY_SIZE);
}
void BasicAccess()
{
TestImplicitStorage<T> portal;
vtkm::cont::ArrayHandle<T, StorageTagType> implictHandle(portal);
VTKM_TEST_ASSERT(implictHandle.GetNumberOfValues() == 1, "handle should have size 1");
VTKM_TEST_ASSERT(implictHandle.GetNumberOfValues() == ARRAY_SIZE, "handle has wrong size");
VTKM_TEST_ASSERT(implictHandle.GetPortalConstControl().Get(0) == T(1),
"portals first values should be 1");
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment