mirror of
https://gitlab.kitware.com/vtk/vtk-m
synced 2024-09-16 17:22:55 +00:00
Merge topic 'move-device-tests'
d96720581 Consolidate UnitTestVirtualObjectHandle 896065044 Consolidate UnitTestPointLocatorSparseGrid d569bbca4 Consolidate UnitTestImplicitFunction b2b075f04 Consolidate UnitTestDataSet* f48789f57 Consolidate UnitTestComputeRange bda676e7d Consolidate UnitTestColorTable 12c1a8021 Consolidate UnitTestCellLocator* 891cfcfa8 Consolidate UnitTestBitField ... Acked-by: Kitware Robot <kwrobot@kitware.com> Acked-by: Li-Ta Lo <ollie@lanl.gov> Merge-request: !2812
This commit is contained in:
commit
e39b8ed8ce
@ -9,30 +9,11 @@
|
||||
##============================================================================
|
||||
|
||||
set(unit_tests
|
||||
UnitTestCudaArrayHandle.cu
|
||||
UnitTestCudaArrayHandleFancy.cu
|
||||
UnitTestCudaArrayHandleMultiplexer.cu
|
||||
UnitTestCudaBitField.cu
|
||||
UnitTestCudaCellLocatorRectilinearGrid.cu
|
||||
UnitTestCudaCellLocatorTwoLevel.cu
|
||||
UnitTestCudaCellLocatorUniformGrid.cu
|
||||
UnitTestCudaComputeRange.cu
|
||||
UnitTestCudaColorTable.cu
|
||||
UnitTestCudaDataSetExplicit.cu
|
||||
UnitTestCudaDataSetSingleType.cu
|
||||
UnitTestCudaDeviceAdapter.cu
|
||||
UnitTestCudaImplicitFunction.cu
|
||||
UnitTestCudaIterators.cu
|
||||
UnitTestCudaMathEdgeCases.cu
|
||||
UnitTestCudaShareUserProvidedManagedMemory.cu
|
||||
UnitTestCudaPointLocatorSparseGrid.cu
|
||||
UnitTestCudaRuntimeDeviceConfiguration.cu
|
||||
)
|
||||
|
||||
if (NOT VTKm_NO_DEPRECATED_VIRTUAL)
|
||||
set(unit_tests ${unit_tests}
|
||||
UnitTestCudaVirtualObjectHandle.cu
|
||||
)
|
||||
endif()
|
||||
|
||||
vtkm_unit_tests(SOURCES ${unit_tests} LABEL "CUDA" LIBRARIES vtkm_worklet BACKEND cuda)
|
||||
|
@ -1,20 +0,0 @@
|
||||
//============================================================================
|
||||
// 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/cuda/DeviceAdapterCuda.h>
|
||||
#include <vtkm/cont/testing/TestingArrayHandles.h>
|
||||
|
||||
int UnitTestCudaArrayHandle(int argc, char* argv[])
|
||||
{
|
||||
auto& tracker = vtkm::cont::GetRuntimeDeviceTracker();
|
||||
tracker.ForceDevice(vtkm::cont::DeviceAdapterTagCuda{});
|
||||
return vtkm::cont::testing::TestingArrayHandles<vtkm::cont::DeviceAdapterTagCuda>::Run(argc,
|
||||
argv);
|
||||
}
|
@ -1,23 +0,0 @@
|
||||
//============================================================================
|
||||
// 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/cuda/DeviceAdapterCuda.h>
|
||||
|
||||
#include <vtkm/cont/cuda/internal/testing/Testing.h>
|
||||
#include <vtkm/cont/testing/TestingFancyArrayHandles.h>
|
||||
|
||||
int UnitTestCudaArrayHandleFancy(int argc, char* argv[])
|
||||
{
|
||||
auto& tracker = vtkm::cont::GetRuntimeDeviceTracker();
|
||||
tracker.ForceDevice(vtkm::cont::DeviceAdapterTagCuda{});
|
||||
int result = vtkm::cont::testing::TestingFancyArrayHandles<vtkm::cont::DeviceAdapterTagCuda>::Run(
|
||||
argc, argv);
|
||||
return vtkm::cont::cuda::internal::Testing::CheckCudaBeforeExit(result);
|
||||
}
|
@ -1,20 +0,0 @@
|
||||
//============================================================================
|
||||
// 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/cuda/DeviceAdapterCuda.h>
|
||||
#include <vtkm/cont/testing/TestingArrayHandleMultiplexer.h>
|
||||
|
||||
int UnitTestCudaArrayHandleMultiplexer(int argc, char* argv[])
|
||||
{
|
||||
auto& tracker = vtkm::cont::GetRuntimeDeviceTracker();
|
||||
tracker.ForceDevice(vtkm::cont::DeviceAdapterTagCuda{});
|
||||
return vtkm::cont::testing::TestingArrayHandleMultiplexer<vtkm::cont::DeviceAdapterTagCuda>::Run(
|
||||
argc, argv);
|
||||
}
|
@ -1,18 +0,0 @@
|
||||
//============================================================================
|
||||
// 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/cuda/DeviceAdapterCuda.h>
|
||||
#include <vtkm/cont/testing/TestingBitField.h>
|
||||
|
||||
int UnitTestCudaBitField(int argc, char* argv[])
|
||||
{
|
||||
auto& tracker = vtkm::cont::GetRuntimeDeviceTracker();
|
||||
tracker.ForceDevice(vtkm::cont::DeviceAdapterTagCuda{});
|
||||
return vtkm::cont::testing::TestingBitField<vtkm::cont::DeviceAdapterTagCuda>::Run(argc, argv);
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
//============================================================================
|
||||
// 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/testing/TestingCellLocatorRectilinearGrid.h>
|
||||
|
||||
int UnitTestCudaCellLocatorRectilinearGrid(int argc, char* argv[])
|
||||
{
|
||||
auto& tracker = vtkm::cont::GetRuntimeDeviceTracker();
|
||||
tracker.ForceDevice(vtkm::cont::DeviceAdapterTagCuda{});
|
||||
return vtkm::cont::testing::Testing::Run(
|
||||
TestingCellLocatorRectilinearGrid<vtkm::cont::DeviceAdapterTagCuda>(), argc, argv);
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
//============================================================================
|
||||
// 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/testing/TestingCellLocatorTwoLevel.h>
|
||||
|
||||
int UnitTestCudaCellLocatorTwoLevel(int argc, char* argv[])
|
||||
{
|
||||
auto& tracker = vtkm::cont::GetRuntimeDeviceTracker();
|
||||
tracker.ForceDevice(vtkm::cont::DeviceAdapterTagCuda{});
|
||||
return vtkm::cont::testing::Testing::Run(
|
||||
TestingCellLocatorTwoLevel<vtkm::cont::DeviceAdapterTagCuda>, argc, argv);
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
//============================================================================
|
||||
// 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/testing/TestingCellLocatorUniformGrid.h>
|
||||
|
||||
int UnitTestCudaCellLocatorUniformGrid(int argc, char* argv[])
|
||||
{
|
||||
auto& tracker = vtkm::cont::GetRuntimeDeviceTracker();
|
||||
tracker.ForceDevice(vtkm::cont::DeviceAdapterTagCuda{});
|
||||
return vtkm::cont::testing::Testing::Run(
|
||||
TestingCellLocatorUniformGrid<vtkm::cont::DeviceAdapterTagCuda>(), argc, argv);
|
||||
}
|
@ -1,20 +0,0 @@
|
||||
//============================================================================
|
||||
// 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/cuda/DeviceAdapterCuda.h>
|
||||
|
||||
#include <vtkm/cont/testing/TestingColorTable.h>
|
||||
|
||||
int UnitTestCudaColorTable(int argc, char* argv[])
|
||||
{
|
||||
auto& tracker = vtkm::cont::GetRuntimeDeviceTracker();
|
||||
tracker.ForceDevice(vtkm::cont::DeviceAdapterTagCuda{});
|
||||
return vtkm::cont::testing::TestingColorTable<vtkm::cont::DeviceAdapterTagCuda>::Run(argc, argv);
|
||||
}
|
@ -1,23 +0,0 @@
|
||||
//============================================================================
|
||||
// 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/cuda/DeviceAdapterCuda.h>
|
||||
|
||||
#include <vtkm/cont/cuda/internal/testing/Testing.h>
|
||||
#include <vtkm/cont/testing/TestingComputeRange.h>
|
||||
|
||||
int UnitTestCudaComputeRange(int argc, char* argv[])
|
||||
{
|
||||
auto& tracker = vtkm::cont::GetRuntimeDeviceTracker();
|
||||
tracker.ForceDevice(vtkm::cont::DeviceAdapterTagCuda{});
|
||||
int result =
|
||||
vtkm::cont::testing::TestingComputeRange<vtkm::cont::DeviceAdapterTagCuda>::Run(argc, argv);
|
||||
return vtkm::cont::cuda::internal::Testing::CheckCudaBeforeExit(result);
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
//============================================================================
|
||||
// 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/cuda/DeviceAdapterCuda.h>
|
||||
#include <vtkm/cont/cuda/internal/testing/Testing.h>
|
||||
#include <vtkm/cont/testing/TestingDataSetExplicit.h>
|
||||
|
||||
int UnitTestCudaDataSetExplicit(int argc, char* argv[])
|
||||
{
|
||||
auto& tracker = vtkm::cont::GetRuntimeDeviceTracker();
|
||||
tracker.ForceDevice(vtkm::cont::DeviceAdapterTagCuda{});
|
||||
int result =
|
||||
vtkm::cont::testing::TestingDataSetExplicit<vtkm::cont::DeviceAdapterTagCuda>::Run(argc, argv);
|
||||
return vtkm::cont::cuda::internal::Testing::CheckCudaBeforeExit(result);
|
||||
}
|
@ -1,23 +0,0 @@
|
||||
//============================================================================
|
||||
// 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/cuda/DeviceAdapterCuda.h>
|
||||
|
||||
#include <vtkm/cont/cuda/internal/testing/Testing.h>
|
||||
#include <vtkm/cont/testing/TestingDataSetSingleType.h>
|
||||
|
||||
int UnitTestCudaDataSetSingleType(int argc, char* argv[])
|
||||
{
|
||||
auto& tracker = vtkm::cont::GetRuntimeDeviceTracker();
|
||||
tracker.ForceDevice(vtkm::cont::DeviceAdapterTagCuda{});
|
||||
int result = vtkm::cont::testing::TestingDataSetSingleType<vtkm::cont::DeviceAdapterTagCuda>::Run(
|
||||
argc, argv);
|
||||
return vtkm::cont::cuda::internal::Testing::CheckCudaBeforeExit(result);
|
||||
}
|
@ -1,29 +0,0 @@
|
||||
//============================================================================
|
||||
// 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/testing/TestingImplicitFunction.h>
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
void TestImplicitFunctions()
|
||||
{
|
||||
vtkm::cont::testing::TestingImplicitFunction testing;
|
||||
testing.Run(vtkm::cont::DeviceAdapterTagCuda());
|
||||
}
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
int UnitTestCudaImplicitFunction(int argc, char* argv[])
|
||||
{
|
||||
auto& tracker = vtkm::cont::GetRuntimeDeviceTracker();
|
||||
tracker.ForceDevice(vtkm::cont::DeviceAdapterTagCuda{});
|
||||
return vtkm::cont::testing::Testing::Run(TestImplicitFunctions, argc, argv);
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
//============================================================================
|
||||
// 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/testing/TestingPointLocatorSparseGrid.h>
|
||||
|
||||
int UnitTestCudaPointLocatorSparseGrid(int argc, char* argv[])
|
||||
{
|
||||
auto& tracker = vtkm::cont::GetRuntimeDeviceTracker();
|
||||
tracker.ForceDevice(vtkm::cont::DeviceAdapterTagCuda{});
|
||||
return vtkm::cont::testing::Testing::Run(
|
||||
TestingPointLocatorSparseGrid<vtkm::cont::DeviceAdapterTagCuda>(), argc, argv);
|
||||
}
|
@ -1,35 +0,0 @@
|
||||
//============================================================================
|
||||
// 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/RuntimeDeviceTracker.h>
|
||||
#include <vtkm/cont/testing/TestingVirtualObjectHandle.h>
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
void TestVirtualObjectHandle()
|
||||
{
|
||||
auto& tracker = vtkm::cont::GetRuntimeDeviceTracker();
|
||||
|
||||
tracker.ForceDevice(vtkm::cont::DeviceAdapterTagCuda{});
|
||||
using DeviceAdapterList = vtkm::List<vtkm::cont::DeviceAdapterTagCuda>;
|
||||
vtkm::cont::testing::TestingVirtualObjectHandle<DeviceAdapterList>::Run();
|
||||
|
||||
tracker.Reset();
|
||||
using DeviceAdapterList2 =
|
||||
vtkm::List<vtkm::cont::DeviceAdapterTagSerial, vtkm::cont::DeviceAdapterTagCuda>;
|
||||
vtkm::cont::testing::TestingVirtualObjectHandle<DeviceAdapterList2>::Run();
|
||||
}
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
int UnitTestCudaVirtualObjectHandle(int argc, char* argv[])
|
||||
{
|
||||
return vtkm::cont::testing::Testing::Run(TestVirtualObjectHandle, argc, argv);
|
||||
}
|
@ -9,29 +9,10 @@
|
||||
##============================================================================
|
||||
|
||||
set(unit_tests
|
||||
UnitTestKokkosArrayHandle.cxx
|
||||
UnitTestKokkosArrayHandleFancy.cxx
|
||||
UnitTestKokkosArrayHandleMultiplexer.cxx
|
||||
UnitTestKokkosBitField.cxx
|
||||
UnitTestKokkosCellLocatorRectilinearGrid.cxx
|
||||
UnitTestKokkosCellLocatorTwoLevel.cxx
|
||||
UnitTestKokkosCellLocatorUniformGrid.cxx
|
||||
UnitTestKokkosComputeRange.cxx
|
||||
UnitTestKokkosColorTable.cxx
|
||||
UnitTestKokkosDataSetExplicit.cxx
|
||||
UnitTestKokkosDataSetSingleType.cxx
|
||||
UnitTestKokkosDeviceAdapter.cxx
|
||||
UnitTestKokkosImplicitFunction.cxx
|
||||
UnitTestKokkosPointLocatorSparseGrid.cxx
|
||||
UnitTestKokkosRuntimeDeviceConfiguration.cxx
|
||||
)
|
||||
|
||||
if (NOT VTKm_NO_DEPRECATED_VIRTUAL)
|
||||
set(unit_tests ${unit_tests}
|
||||
UnitTestKokkosVirtualObjectHandle.cxx
|
||||
)
|
||||
endif()
|
||||
|
||||
vtkm_unit_tests(SOURCES ${unit_tests} LABEL "KOKKOS" LIBRARIES vtkm_worklet BACKEND kokkos)
|
||||
|
||||
if (TARGET vtkm::kokkos_cuda)
|
||||
|
@ -1,20 +0,0 @@
|
||||
//============================================================================
|
||||
// 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/kokkos/DeviceAdapterKokkos.h>
|
||||
#include <vtkm/cont/testing/TestingArrayHandles.h>
|
||||
|
||||
int UnitTestKokkosArrayHandle(int argc, char* argv[])
|
||||
{
|
||||
auto& tracker = vtkm::cont::GetRuntimeDeviceTracker();
|
||||
tracker.ForceDevice(vtkm::cont::DeviceAdapterTagKokkos{});
|
||||
return vtkm::cont::testing::TestingArrayHandles<vtkm::cont::DeviceAdapterTagKokkos>::Run(argc,
|
||||
argv);
|
||||
}
|
@ -1,20 +0,0 @@
|
||||
//============================================================================
|
||||
// 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/kokkos/DeviceAdapterKokkos.h>
|
||||
#include <vtkm/cont/testing/TestingFancyArrayHandles.h>
|
||||
|
||||
int UnitTestKokkosArrayHandleFancy(int argc, char* argv[])
|
||||
{
|
||||
auto& tracker = vtkm::cont::GetRuntimeDeviceTracker();
|
||||
tracker.ForceDevice(vtkm::cont::DeviceAdapterTagKokkos{});
|
||||
return vtkm::cont::testing::TestingFancyArrayHandles<vtkm::cont::DeviceAdapterTagKokkos>::Run(
|
||||
argc, argv);
|
||||
}
|
@ -1,20 +0,0 @@
|
||||
//============================================================================
|
||||
// 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/kokkos/DeviceAdapterKokkos.h>
|
||||
#include <vtkm/cont/testing/TestingArrayHandleMultiplexer.h>
|
||||
|
||||
int UnitTestKokkosArrayHandleMultiplexer(int argc, char* argv[])
|
||||
{
|
||||
auto& tracker = vtkm::cont::GetRuntimeDeviceTracker();
|
||||
tracker.ForceDevice(vtkm::cont::DeviceAdapterTagKokkos{});
|
||||
return vtkm::cont::testing::TestingArrayHandleMultiplexer<
|
||||
vtkm::cont::DeviceAdapterTagKokkos>::Run(argc, argv);
|
||||
}
|
@ -1,18 +0,0 @@
|
||||
//============================================================================
|
||||
// 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/kokkos/DeviceAdapterKokkos.h>
|
||||
#include <vtkm/cont/testing/TestingBitField.h>
|
||||
|
||||
int UnitTestKokkosBitField(int argc, char* argv[])
|
||||
{
|
||||
auto& tracker = vtkm::cont::GetRuntimeDeviceTracker();
|
||||
tracker.ForceDevice(vtkm::cont::DeviceAdapterTagKokkos{});
|
||||
return vtkm::cont::testing::TestingBitField<vtkm::cont::DeviceAdapterTagKokkos>::Run(argc, argv);
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
//============================================================================
|
||||
// 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/testing/TestingCellLocatorRectilinearGrid.h>
|
||||
|
||||
int UnitTestKokkosCellLocatorRectilinearGrid(int argc, char* argv[])
|
||||
{
|
||||
auto& tracker = vtkm::cont::GetRuntimeDeviceTracker();
|
||||
tracker.ForceDevice(vtkm::cont::DeviceAdapterTagKokkos{});
|
||||
return vtkm::cont::testing::Testing::Run(
|
||||
TestingCellLocatorRectilinearGrid<vtkm::cont::DeviceAdapterTagKokkos>(), argc, argv);
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
//============================================================================
|
||||
// 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/testing/TestingCellLocatorTwoLevel.h>
|
||||
|
||||
int UnitTestKokkosCellLocatorTwoLevel(int argc, char* argv[])
|
||||
{
|
||||
auto& tracker = vtkm::cont::GetRuntimeDeviceTracker();
|
||||
tracker.ForceDevice(vtkm::cont::DeviceAdapterTagKokkos{});
|
||||
return vtkm::cont::testing::Testing::Run(
|
||||
TestingCellLocatorTwoLevel<vtkm::cont::DeviceAdapterTagKokkos>, argc, argv);
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
//============================================================================
|
||||
// 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/testing/TestingCellLocatorUniformGrid.h>
|
||||
|
||||
int UnitTestKokkosCellLocatorUniformGrid(int argc, char* argv[])
|
||||
{
|
||||
auto& tracker = vtkm::cont::GetRuntimeDeviceTracker();
|
||||
tracker.ForceDevice(vtkm::cont::DeviceAdapterTagKokkos{});
|
||||
return vtkm::cont::testing::Testing::Run(
|
||||
TestingCellLocatorUniformGrid<vtkm::cont::DeviceAdapterTagKokkos>(), argc, argv);
|
||||
}
|
@ -1,20 +0,0 @@
|
||||
//============================================================================
|
||||
// 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/kokkos/DeviceAdapterKokkos.h>
|
||||
#include <vtkm/cont/testing/TestingColorTable.h>
|
||||
|
||||
int UnitTestKokkosColorTable(int argc, char* argv[])
|
||||
{
|
||||
auto& tracker = vtkm::cont::GetRuntimeDeviceTracker();
|
||||
tracker.ForceDevice(vtkm::cont::DeviceAdapterTagKokkos{});
|
||||
return vtkm::cont::testing::TestingColorTable<vtkm::cont::DeviceAdapterTagKokkos>::Run(argc,
|
||||
argv);
|
||||
}
|
@ -1,20 +0,0 @@
|
||||
//============================================================================
|
||||
// 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/kokkos/DeviceAdapterKokkos.h>
|
||||
#include <vtkm/cont/testing/TestingComputeRange.h>
|
||||
|
||||
int UnitTestKokkosComputeRange(int argc, char* argv[])
|
||||
{
|
||||
auto& tracker = vtkm::cont::GetRuntimeDeviceTracker();
|
||||
tracker.ForceDevice(vtkm::cont::DeviceAdapterTagKokkos{});
|
||||
return vtkm::cont::testing::TestingComputeRange<vtkm::cont::DeviceAdapterTagKokkos>::Run(argc,
|
||||
argv);
|
||||
}
|
@ -1,20 +0,0 @@
|
||||
//============================================================================
|
||||
// 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/kokkos/DeviceAdapterKokkos.h>
|
||||
#include <vtkm/cont/testing/TestingDataSetExplicit.h>
|
||||
|
||||
int UnitTestKokkosDataSetExplicit(int argc, char* argv[])
|
||||
{
|
||||
auto& tracker = vtkm::cont::GetRuntimeDeviceTracker();
|
||||
tracker.ForceDevice(vtkm::cont::DeviceAdapterTagKokkos{});
|
||||
return vtkm::cont::testing::TestingDataSetExplicit<vtkm::cont::DeviceAdapterTagKokkos>::Run(argc,
|
||||
argv);
|
||||
}
|
@ -1,20 +0,0 @@
|
||||
//============================================================================
|
||||
// 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/kokkos/DeviceAdapterKokkos.h>
|
||||
#include <vtkm/cont/testing/TestingDataSetSingleType.h>
|
||||
|
||||
int UnitTestKokkosDataSetSingleType(int argc, char* argv[])
|
||||
{
|
||||
auto& tracker = vtkm::cont::GetRuntimeDeviceTracker();
|
||||
tracker.ForceDevice(vtkm::cont::DeviceAdapterTagKokkos{});
|
||||
return vtkm::cont::testing::TestingDataSetSingleType<vtkm::cont::DeviceAdapterTagKokkos>::Run(
|
||||
argc, argv);
|
||||
}
|
@ -1,29 +0,0 @@
|
||||
//============================================================================
|
||||
// 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/testing/TestingImplicitFunction.h>
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
void TestImplicitFunctions()
|
||||
{
|
||||
vtkm::cont::testing::TestingImplicitFunction testing;
|
||||
testing.Run(vtkm::cont::DeviceAdapterTagKokkos());
|
||||
}
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
int UnitTestKokkosImplicitFunction(int argc, char* argv[])
|
||||
{
|
||||
auto& tracker = vtkm::cont::GetRuntimeDeviceTracker();
|
||||
tracker.ForceDevice(vtkm::cont::DeviceAdapterTagKokkos{});
|
||||
return vtkm::cont::testing::Testing::Run(TestImplicitFunctions, argc, argv);
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
//============================================================================
|
||||
// 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/testing/TestingPointLocatorSparseGrid.h>
|
||||
|
||||
int UnitTestKokkosPointLocatorSparseGrid(int argc, char* argv[])
|
||||
{
|
||||
auto& tracker = vtkm::cont::GetRuntimeDeviceTracker();
|
||||
tracker.ForceDevice(vtkm::cont::DeviceAdapterTagKokkos{});
|
||||
return vtkm::cont::testing::Testing::Run(
|
||||
TestingPointLocatorSparseGrid<vtkm::cont::DeviceAdapterTagKokkos>(), argc, argv);
|
||||
}
|
@ -1,35 +0,0 @@
|
||||
//============================================================================
|
||||
// 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/RuntimeDeviceTracker.h>
|
||||
#include <vtkm/cont/testing/TestingVirtualObjectHandle.h>
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
void TestVirtualObjectHandle()
|
||||
{
|
||||
auto& tracker = vtkm::cont::GetRuntimeDeviceTracker();
|
||||
|
||||
tracker.ForceDevice(vtkm::cont::DeviceAdapterTagKokkos{});
|
||||
using DeviceAdapterList = vtkm::List<vtkm::cont::DeviceAdapterTagKokkos>;
|
||||
vtkm::cont::testing::TestingVirtualObjectHandle<DeviceAdapterList>::Run();
|
||||
|
||||
tracker.Reset();
|
||||
using DeviceAdapterList2 =
|
||||
vtkm::List<vtkm::cont::DeviceAdapterTagSerial, vtkm::cont::DeviceAdapterTagKokkos>;
|
||||
vtkm::cont::testing::TestingVirtualObjectHandle<DeviceAdapterList2>::Run();
|
||||
}
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
int UnitTestKokkosVirtualObjectHandle(int argc, char* argv[])
|
||||
{
|
||||
return vtkm::cont::testing::Testing::Run(TestVirtualObjectHandle, argc, argv);
|
||||
}
|
@ -9,29 +9,10 @@
|
||||
##============================================================================
|
||||
|
||||
set(unit_tests
|
||||
UnitTestOpenMPArrayHandle.cxx
|
||||
UnitTestOpenMPArrayHandleFancy.cxx
|
||||
UnitTestOpenMPArrayHandleMultiplexer.cxx
|
||||
UnitTestOpenMPBitField.cxx
|
||||
UnitTestOpenMPCellLocatorRectilinearGrid.cxx
|
||||
UnitTestOpenMPCellLocatorTwoLevel.cxx
|
||||
UnitTestOpenMPCellLocatorUniformGrid.cxx
|
||||
UnitTestOpenMPColorTable.cxx
|
||||
UnitTestOpenMPComputeRange.cxx
|
||||
UnitTestOpenMPDataSetExplicit.cxx
|
||||
UnitTestOpenMPDataSetSingleType.cxx
|
||||
UnitTestOpenMPDeviceAdapter.cxx
|
||||
UnitTestOpenMPImplicitFunction.cxx
|
||||
UnitTestOpenMPPointLocatorSparseGrid.cxx
|
||||
UnitTestOpenMPRuntimeDeviceConfiguration.cxx
|
||||
)
|
||||
|
||||
if (NOT VTKm_NO_DEPRECATED_VIRTUAL)
|
||||
set(unit_tests ${unit_tests}
|
||||
UnitTestOpenMPVirtualObjectHandle.cxx
|
||||
)
|
||||
endif()
|
||||
|
||||
vtkm_unit_tests(SOURCES ${unit_tests}
|
||||
LABEL "OPENMP"
|
||||
DEFINES VTKM_NO_ERROR_ON_MIXED_CUDA_CXX_TAG
|
||||
|
@ -1,19 +0,0 @@
|
||||
//============================================================================
|
||||
// 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/openmp/DeviceAdapterOpenMP.h>
|
||||
#include <vtkm/cont/testing/TestingArrayHandles.h>
|
||||
|
||||
int UnitTestOpenMPArrayHandle(int argc, char* argv[])
|
||||
{
|
||||
auto& tracker = vtkm::cont::GetRuntimeDeviceTracker();
|
||||
tracker.ForceDevice(vtkm::cont::DeviceAdapterTagOpenMP{});
|
||||
return vtkm::cont::testing::TestingArrayHandles<vtkm::cont::DeviceAdapterTagOpenMP>::Run(argc,
|
||||
argv);
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
//============================================================================
|
||||
// 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/openmp/DeviceAdapterOpenMP.h>
|
||||
#include <vtkm/cont/testing/TestingFancyArrayHandles.h>
|
||||
|
||||
int UnitTestOpenMPArrayHandleFancy(int argc, char* argv[])
|
||||
{
|
||||
auto& tracker = vtkm::cont::GetRuntimeDeviceTracker();
|
||||
tracker.ForceDevice(vtkm::cont::DeviceAdapterTagOpenMP{});
|
||||
return vtkm::cont::testing::TestingFancyArrayHandles<vtkm::cont::DeviceAdapterTagOpenMP>::Run(
|
||||
argc, argv);
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
//============================================================================
|
||||
// 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/openmp/DeviceAdapterOpenMP.h>
|
||||
#include <vtkm/cont/testing/TestingArrayHandleMultiplexer.h>
|
||||
|
||||
int UnitTestOpenMPArrayHandleMultiplexer(int argc, char* argv[])
|
||||
{
|
||||
auto& tracker = vtkm::cont::GetRuntimeDeviceTracker();
|
||||
tracker.ForceDevice(vtkm::cont::DeviceAdapterTagOpenMP{});
|
||||
return vtkm::cont::testing::TestingArrayHandleMultiplexer<
|
||||
vtkm::cont::DeviceAdapterTagOpenMP>::Run(argc, argv);
|
||||
}
|
@ -1,18 +0,0 @@
|
||||
//============================================================================
|
||||
// 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/openmp/DeviceAdapterOpenMP.h>
|
||||
#include <vtkm/cont/testing/TestingBitField.h>
|
||||
|
||||
int UnitTestOpenMPBitField(int argc, char* argv[])
|
||||
{
|
||||
auto& tracker = vtkm::cont::GetRuntimeDeviceTracker();
|
||||
tracker.ForceDevice(vtkm::cont::DeviceAdapterTagOpenMP{});
|
||||
return vtkm::cont::testing::TestingBitField<vtkm::cont::DeviceAdapterTagOpenMP>::Run(argc, argv);
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
//============================================================================
|
||||
// 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/testing/TestingCellLocatorRectilinearGrid.h>
|
||||
|
||||
int UnitTestOpenMPCellLocatorRectilinearGrid(int argc, char* argv[])
|
||||
{
|
||||
auto& tracker = vtkm::cont::GetRuntimeDeviceTracker();
|
||||
tracker.ForceDevice(vtkm::cont::DeviceAdapterTagOpenMP{});
|
||||
return vtkm::cont::testing::Testing::Run(
|
||||
TestingCellLocatorRectilinearGrid<vtkm::cont::DeviceAdapterTagOpenMP>(), argc, argv);
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
//============================================================================
|
||||
// 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/openmp/DeviceAdapterOpenMP.h>
|
||||
#include <vtkm/cont/testing/TestingCellLocatorTwoLevel.h>
|
||||
|
||||
int UnitTestOpenMPCellLocatorTwoLevel(int argc, char* argv[])
|
||||
{
|
||||
auto& tracker = vtkm::cont::GetRuntimeDeviceTracker();
|
||||
tracker.ForceDevice(vtkm::cont::DeviceAdapterTagOpenMP{});
|
||||
return vtkm::cont::testing::Testing::Run(
|
||||
TestingCellLocatorTwoLevel<vtkm::cont::DeviceAdapterTagOpenMP>, argc, argv);
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
//============================================================================
|
||||
// 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/testing/TestingCellLocatorUniformGrid.h>
|
||||
|
||||
int UnitTestOpenMPCellLocatorUniformGrid(int argc, char* argv[])
|
||||
{
|
||||
auto& tracker = vtkm::cont::GetRuntimeDeviceTracker();
|
||||
tracker.ForceDevice(vtkm::cont::DeviceAdapterTagOpenMP{});
|
||||
return vtkm::cont::testing::Testing::Run(
|
||||
TestingCellLocatorUniformGrid<vtkm::cont::DeviceAdapterTagOpenMP>(), argc, argv);
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
//============================================================================
|
||||
// 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/openmp/DeviceAdapterOpenMP.h>
|
||||
#include <vtkm/cont/testing/TestingColorTable.h>
|
||||
|
||||
int UnitTestOpenMPColorTable(int argc, char* argv[])
|
||||
{
|
||||
auto& tracker = vtkm::cont::GetRuntimeDeviceTracker();
|
||||
tracker.ForceDevice(vtkm::cont::DeviceAdapterTagOpenMP{});
|
||||
return vtkm::cont::testing::TestingColorTable<vtkm::cont::DeviceAdapterTagOpenMP>::Run(argc,
|
||||
argv);
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
//============================================================================
|
||||
// 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/openmp/DeviceAdapterOpenMP.h>
|
||||
#include <vtkm/cont/testing/TestingComputeRange.h>
|
||||
|
||||
int UnitTestOpenMPComputeRange(int argc, char* argv[])
|
||||
{
|
||||
auto& tracker = vtkm::cont::GetRuntimeDeviceTracker();
|
||||
tracker.ForceDevice(vtkm::cont::DeviceAdapterTagOpenMP{});
|
||||
return vtkm::cont::testing::TestingComputeRange<vtkm::cont::DeviceAdapterTagOpenMP>::Run(argc,
|
||||
argv);
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
//============================================================================
|
||||
// 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/openmp/DeviceAdapterOpenMP.h>
|
||||
#include <vtkm/cont/testing/TestingDataSetExplicit.h>
|
||||
|
||||
int UnitTestOpenMPDataSetExplicit(int argc, char* argv[])
|
||||
{
|
||||
auto& tracker = vtkm::cont::GetRuntimeDeviceTracker();
|
||||
tracker.ForceDevice(vtkm::cont::DeviceAdapterTagOpenMP{});
|
||||
return vtkm::cont::testing::TestingDataSetExplicit<vtkm::cont::DeviceAdapterTagOpenMP>::Run(argc,
|
||||
argv);
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
//============================================================================
|
||||
// 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/openmp/DeviceAdapterOpenMP.h>
|
||||
#include <vtkm/cont/testing/TestingDataSetSingleType.h>
|
||||
|
||||
int UnitTestOpenMPDataSetSingleType(int argc, char* argv[])
|
||||
{
|
||||
auto& tracker = vtkm::cont::GetRuntimeDeviceTracker();
|
||||
tracker.ForceDevice(vtkm::cont::DeviceAdapterTagOpenMP{});
|
||||
return vtkm::cont::testing::TestingDataSetSingleType<vtkm::cont::DeviceAdapterTagOpenMP>::Run(
|
||||
argc, argv);
|
||||
}
|
@ -1,30 +0,0 @@
|
||||
//============================================================================
|
||||
// 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/openmp/DeviceAdapterOpenMP.h>
|
||||
#include <vtkm/cont/testing/TestingImplicitFunction.h>
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
void TestImplicitFunctions()
|
||||
{
|
||||
auto& tracker = vtkm::cont::GetRuntimeDeviceTracker();
|
||||
tracker.ForceDevice(vtkm::cont::DeviceAdapterTagOpenMP{});
|
||||
|
||||
vtkm::cont::testing::TestingImplicitFunction testing;
|
||||
testing.Run(vtkm::cont::DeviceAdapterTagOpenMP());
|
||||
}
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
int UnitTestOpenMPImplicitFunction(int argc, char* argv[])
|
||||
{
|
||||
return vtkm::cont::testing::Testing::Run(TestImplicitFunctions, argc, argv);
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
//============================================================================
|
||||
// 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/openmp/DeviceAdapterOpenMP.h>
|
||||
#include <vtkm/cont/testing/TestingPointLocatorSparseGrid.h>
|
||||
|
||||
int UnitTestOpenMPPointLocatorSparseGrid(int argc, char* argv[])
|
||||
{
|
||||
auto& tracker = vtkm::cont::GetRuntimeDeviceTracker();
|
||||
tracker.ForceDevice(vtkm::cont::DeviceAdapterTagOpenMP{});
|
||||
return vtkm::cont::testing::Testing::Run(
|
||||
TestingPointLocatorSparseGrid<vtkm::cont::DeviceAdapterTagOpenMP>(), argc, argv);
|
||||
}
|
@ -1,37 +0,0 @@
|
||||
//============================================================================
|
||||
// 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/RuntimeDeviceTracker.h>
|
||||
#include <vtkm/cont/openmp/DeviceAdapterOpenMP.h>
|
||||
#include <vtkm/cont/testing/TestingVirtualObjectHandle.h>
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
void TestVirtualObjectHandle()
|
||||
{
|
||||
using DeviceAdapterList = vtkm::List<vtkm::cont::DeviceAdapterTagOpenMP>;
|
||||
using DeviceAdapterList2 =
|
||||
vtkm::List<vtkm::cont::DeviceAdapterTagSerial, vtkm::cont::DeviceAdapterTagOpenMP>;
|
||||
|
||||
auto& tracker = vtkm::cont::GetRuntimeDeviceTracker();
|
||||
|
||||
tracker.ForceDevice(vtkm::cont::DeviceAdapterTagOpenMP{});
|
||||
vtkm::cont::testing::TestingVirtualObjectHandle<DeviceAdapterList>::Run();
|
||||
|
||||
tracker.Reset();
|
||||
vtkm::cont::testing::TestingVirtualObjectHandle<DeviceAdapterList2>::Run();
|
||||
}
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
int UnitTestOpenMPVirtualObjectHandle(int argc, char* argv[])
|
||||
{
|
||||
return vtkm::cont::testing::Testing::Run(TestVirtualObjectHandle, argc, argv);
|
||||
}
|
@ -9,28 +9,9 @@
|
||||
##============================================================================
|
||||
|
||||
set(unit_tests
|
||||
UnitTestSerialArrayHandle.cxx
|
||||
UnitTestSerialArrayHandleFancy.cxx
|
||||
UnitTestSerialArrayHandleMultiplexer.cxx
|
||||
UnitTestSerialBitField.cxx
|
||||
UnitTestSerialCellLocatorRectilinearGrid.cxx
|
||||
UnitTestSerialCellLocatorTwoLevel.cxx
|
||||
UnitTestSerialCellLocatorUniformGrid.cxx
|
||||
UnitTestSerialComputeRange.cxx
|
||||
UnitTestSerialColorTable.cxx
|
||||
UnitTestSerialDataSetExplicit.cxx
|
||||
UnitTestSerialDataSetSingleType.cxx
|
||||
UnitTestSerialDeviceAdapter.cxx
|
||||
UnitTestSerialImplicitFunction.cxx
|
||||
UnitTestSerialPointLocatorSparseGrid.cxx
|
||||
)
|
||||
|
||||
if (NOT VTKm_NO_DEPRECATED_VIRTUAL)
|
||||
set(unit_tests ${unit_tests}
|
||||
UnitTestSerialVirtualObjectHandle.cxx
|
||||
)
|
||||
endif()
|
||||
|
||||
vtkm_unit_tests(SOURCES ${unit_tests}
|
||||
LABEL "SERIAL"
|
||||
DEFINES VTKM_NO_ERROR_ON_MIXED_CUDA_CXX_TAG
|
||||
|
@ -1,20 +0,0 @@
|
||||
//============================================================================
|
||||
// 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/serial/DeviceAdapterSerial.h>
|
||||
#include <vtkm/cont/testing/TestingArrayHandles.h>
|
||||
|
||||
int UnitTestSerialArrayHandle(int argc, char* argv[])
|
||||
{
|
||||
auto& tracker = vtkm::cont::GetRuntimeDeviceTracker();
|
||||
tracker.ForceDevice(vtkm::cont::DeviceAdapterTagSerial{});
|
||||
return vtkm::cont::testing::TestingArrayHandles<vtkm::cont::DeviceAdapterTagSerial>::Run(argc,
|
||||
argv);
|
||||
}
|
@ -1,20 +0,0 @@
|
||||
//============================================================================
|
||||
// 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/serial/DeviceAdapterSerial.h>
|
||||
|
||||
#include <vtkm/cont/testing/TestingFancyArrayHandles.h>
|
||||
|
||||
int UnitTestSerialArrayHandleFancy(int argc, char* argv[])
|
||||
{
|
||||
auto& tracker = vtkm::cont::GetRuntimeDeviceTracker();
|
||||
tracker.ForceDevice(vtkm::cont::DeviceAdapterTagSerial{});
|
||||
return vtkm::cont::testing::TestingFancyArrayHandles<vtkm::cont::DeviceAdapterTagSerial>::Run(
|
||||
argc, argv);
|
||||
}
|
@ -1,21 +0,0 @@
|
||||
//============================================================================
|
||||
// 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/RuntimeDeviceTracker.h>
|
||||
#include <vtkm/cont/serial/DeviceAdapterSerial.h>
|
||||
#include <vtkm/cont/testing/TestingArrayHandleMultiplexer.h>
|
||||
|
||||
int UnitTestSerialArrayHandleMultiplexer(int argc, char* argv[])
|
||||
{
|
||||
auto& tracker = vtkm::cont::GetRuntimeDeviceTracker();
|
||||
tracker.ForceDevice(vtkm::cont::DeviceAdapterTagSerial{});
|
||||
return vtkm::cont::testing::TestingArrayHandleMultiplexer<
|
||||
vtkm::cont::DeviceAdapterTagSerial>::Run(argc, argv);
|
||||
}
|
@ -1,18 +0,0 @@
|
||||
//============================================================================
|
||||
// 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/serial/DeviceAdapterSerial.h>
|
||||
#include <vtkm/cont/testing/TestingBitField.h>
|
||||
|
||||
int UnitTestSerialBitField(int argc, char* argv[])
|
||||
{
|
||||
auto& tracker = vtkm::cont::GetRuntimeDeviceTracker();
|
||||
tracker.ForceDevice(vtkm::cont::DeviceAdapterTagSerial{});
|
||||
return vtkm::cont::testing::TestingBitField<vtkm::cont::DeviceAdapterTagSerial>::Run(argc, argv);
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
//============================================================================
|
||||
// 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/testing/TestingCellLocatorRectilinearGrid.h>
|
||||
|
||||
int UnitTestSerialCellLocatorRectilinearGrid(int argc, char* argv[])
|
||||
{
|
||||
auto& tracker = vtkm::cont::GetRuntimeDeviceTracker();
|
||||
tracker.ForceDevice(vtkm::cont::DeviceAdapterTagSerial{});
|
||||
return vtkm::cont::testing::Testing::Run(
|
||||
TestingCellLocatorRectilinearGrid<vtkm::cont::DeviceAdapterTagSerial>(), argc, argv);
|
||||
}
|
@ -1,20 +0,0 @@
|
||||
//============================================================================
|
||||
// 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/serial/DeviceAdapterSerial.h>
|
||||
#include <vtkm/cont/testing/TestingCellLocatorTwoLevel.h>
|
||||
|
||||
int UnitTestSerialCellLocatorTwoLevel(int argc, char* argv[])
|
||||
{
|
||||
auto& tracker = vtkm::cont::GetRuntimeDeviceTracker();
|
||||
tracker.ForceDevice(vtkm::cont::DeviceAdapterTagSerial{});
|
||||
return vtkm::cont::testing::Testing::Run(
|
||||
TestingCellLocatorTwoLevel<vtkm::cont::DeviceAdapterTagSerial>, argc, argv);
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
//============================================================================
|
||||
// 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/testing/TestingCellLocatorUniformGrid.h>
|
||||
|
||||
int UnitTestSerialCellLocatorUniformGrid(int argc, char* argv[])
|
||||
{
|
||||
auto& tracker = vtkm::cont::GetRuntimeDeviceTracker();
|
||||
tracker.ForceDevice(vtkm::cont::DeviceAdapterTagSerial{});
|
||||
return vtkm::cont::testing::Testing::Run(
|
||||
TestingCellLocatorUniformGrid<vtkm::cont::DeviceAdapterTagSerial>(), argc, argv);
|
||||
}
|
@ -1,20 +0,0 @@
|
||||
//============================================================================
|
||||
// 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/serial/DeviceAdapterSerial.h>
|
||||
|
||||
#include <vtkm/cont/testing/TestingColorTable.h>
|
||||
|
||||
int UnitTestSerialColorTable(int argc, char* argv[])
|
||||
{
|
||||
//TestingColorTable forces the device
|
||||
return vtkm::cont::testing::TestingColorTable<vtkm::cont::DeviceAdapterTagSerial>::Run(argc,
|
||||
argv);
|
||||
}
|
@ -1,20 +0,0 @@
|
||||
//============================================================================
|
||||
// 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/serial/DeviceAdapterSerial.h>
|
||||
|
||||
#include <vtkm/cont/testing/TestingComputeRange.h>
|
||||
|
||||
int UnitTestSerialComputeRange(int argc, char* argv[])
|
||||
{
|
||||
//TestingComputeRange forces the device
|
||||
return vtkm::cont::testing::TestingComputeRange<vtkm::cont::DeviceAdapterTagSerial>::Run(argc,
|
||||
argv);
|
||||
}
|
@ -1,20 +0,0 @@
|
||||
//============================================================================
|
||||
// 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/serial/DeviceAdapterSerial.h>
|
||||
#include <vtkm/cont/testing/TestingDataSetExplicit.h>
|
||||
|
||||
int UnitTestSerialDataSetExplicit(int argc, char* argv[])
|
||||
{
|
||||
auto& tracker = vtkm::cont::GetRuntimeDeviceTracker();
|
||||
tracker.ForceDevice(vtkm::cont::DeviceAdapterTagSerial{});
|
||||
return vtkm::cont::testing::TestingDataSetExplicit<vtkm::cont::DeviceAdapterTagSerial>::Run(argc,
|
||||
argv);
|
||||
}
|
@ -1,20 +0,0 @@
|
||||
//============================================================================
|
||||
// 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/serial/DeviceAdapterSerial.h>
|
||||
#include <vtkm/cont/testing/TestingDataSetSingleType.h>
|
||||
|
||||
int UnitTestSerialDataSetSingleType(int argc, char* argv[])
|
||||
{
|
||||
auto& tracker = vtkm::cont::GetRuntimeDeviceTracker();
|
||||
tracker.ForceDevice(vtkm::cont::DeviceAdapterTagSerial{});
|
||||
return vtkm::cont::testing::TestingDataSetSingleType<vtkm::cont::DeviceAdapterTagSerial>::Run(
|
||||
argc, argv);
|
||||
}
|
@ -1,29 +0,0 @@
|
||||
//============================================================================
|
||||
// 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/testing/TestingImplicitFunction.h>
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
void TestImplicitFunctions()
|
||||
{
|
||||
vtkm::cont::testing::TestingImplicitFunction testing;
|
||||
testing.Run(vtkm::cont::DeviceAdapterTagSerial());
|
||||
}
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
int UnitTestSerialImplicitFunction(int argc, char* argv[])
|
||||
{
|
||||
auto& tracker = vtkm::cont::GetRuntimeDeviceTracker();
|
||||
tracker.ForceDevice(vtkm::cont::DeviceAdapterTagSerial{});
|
||||
return vtkm::cont::testing::Testing::Run(TestImplicitFunctions, argc, argv);
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
//============================================================================
|
||||
// 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/testing/TestingPointLocatorSparseGrid.h>
|
||||
|
||||
int UnitTestSerialPointLocatorSparseGrid(int argc, char* argv[])
|
||||
{
|
||||
auto& tracker = vtkm::cont::GetRuntimeDeviceTracker();
|
||||
tracker.ForceDevice(vtkm::cont::DeviceAdapterTagSerial{});
|
||||
return vtkm::cont::testing::Testing::Run(
|
||||
TestingPointLocatorSparseGrid<vtkm::cont::DeviceAdapterTagSerial>(), argc, argv);
|
||||
}
|
@ -1,30 +0,0 @@
|
||||
//============================================================================
|
||||
// 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/RuntimeDeviceTracker.h>
|
||||
#include <vtkm/cont/testing/TestingVirtualObjectHandle.h>
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
void TestVirtualObjectHandle()
|
||||
{
|
||||
using DeviceAdapterList = vtkm::List<vtkm::cont::DeviceAdapterTagSerial>;
|
||||
vtkm::cont::testing::TestingVirtualObjectHandle<DeviceAdapterList>::Run();
|
||||
}
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
int UnitTestSerialVirtualObjectHandle(int argc, char* argv[])
|
||||
{
|
||||
auto& tracker = vtkm::cont::GetRuntimeDeviceTracker();
|
||||
tracker.ForceDevice(vtkm::cont::DeviceAdapterTagSerial{});
|
||||
return vtkm::cont::testing::Testing::Run(TestVirtualObjectHandle, argc, argv);
|
||||
}
|
@ -9,29 +9,10 @@
|
||||
##============================================================================
|
||||
|
||||
set(unit_tests
|
||||
UnitTestTBBArrayHandle.cxx
|
||||
UnitTestTBBArrayHandleFancy.cxx
|
||||
UnitTestTBBArrayHandleMultiplexer.cxx
|
||||
UnitTestTBBBitField.cxx
|
||||
UnitTestTBBCellLocatorRectilinearGrid.cxx
|
||||
UnitTestTBBCellLocatorTwoLevel.cxx
|
||||
UnitTestTBBCellLocatorUniformGrid.cxx
|
||||
UnitTestTBBColorTable.cxx
|
||||
UnitTestTBBComputeRange.cxx
|
||||
UnitTestTBBDataSetExplicit.cxx
|
||||
UnitTestTBBDataSetSingleType.cxx
|
||||
UnitTestTBBDeviceAdapter.cxx
|
||||
UnitTestTBBImplicitFunction.cxx
|
||||
UnitTestTBBPointLocatorSparseGrid.cxx
|
||||
UnitTestTBBRuntimeDeviceConfiguration.cxx
|
||||
)
|
||||
|
||||
if (NOT VTKm_NO_DEPRECATED_VIRTUAL)
|
||||
set(unit_tests ${unit_tests}
|
||||
UnitTestTBBVirtualObjectHandle.cxx
|
||||
)
|
||||
endif()
|
||||
|
||||
vtkm_unit_tests(SOURCES ${unit_tests}
|
||||
LABEL "TBB"
|
||||
DEFINES VTKM_NO_ERROR_ON_MIXED_CUDA_CXX_TAG
|
||||
|
@ -1,19 +0,0 @@
|
||||
//============================================================================
|
||||
// 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/tbb/DeviceAdapterTBB.h>
|
||||
#include <vtkm/cont/testing/TestingArrayHandles.h>
|
||||
|
||||
int UnitTestTBBArrayHandle(int argc, char* argv[])
|
||||
{
|
||||
auto& tracker = vtkm::cont::GetRuntimeDeviceTracker();
|
||||
tracker.ForceDevice(vtkm::cont::DeviceAdapterTagTBB{});
|
||||
return vtkm::cont::testing::TestingArrayHandles<vtkm::cont::DeviceAdapterTagTBB>::Run(argc, argv);
|
||||
}
|
@ -1,20 +0,0 @@
|
||||
//============================================================================
|
||||
// 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/tbb/DeviceAdapterTBB.h>
|
||||
#include <vtkm/cont/testing/TestingFancyArrayHandles.h>
|
||||
|
||||
int UnitTestTBBArrayHandleFancy(int argc, char* argv[])
|
||||
{
|
||||
auto& tracker = vtkm::cont::GetRuntimeDeviceTracker();
|
||||
tracker.ForceDevice(vtkm::cont::DeviceAdapterTagTBB{});
|
||||
return vtkm::cont::testing::TestingFancyArrayHandles<vtkm::cont::DeviceAdapterTagTBB>::Run(argc,
|
||||
argv);
|
||||
}
|
@ -1,20 +0,0 @@
|
||||
//============================================================================
|
||||
// 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/tbb/DeviceAdapterTBB.h>
|
||||
#include <vtkm/cont/testing/TestingArrayHandleMultiplexer.h>
|
||||
|
||||
int UnitTestTBBArrayHandleMultiplexer(int argc, char* argv[])
|
||||
{
|
||||
auto& tracker = vtkm::cont::GetRuntimeDeviceTracker();
|
||||
tracker.ForceDevice(vtkm::cont::DeviceAdapterTagTBB{});
|
||||
return vtkm::cont::testing::TestingArrayHandleMultiplexer<vtkm::cont::DeviceAdapterTagTBB>::Run(
|
||||
argc, argv);
|
||||
}
|
@ -1,18 +0,0 @@
|
||||
//============================================================================
|
||||
// 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/tbb/DeviceAdapterTBB.h>
|
||||
#include <vtkm/cont/testing/TestingBitField.h>
|
||||
|
||||
int UnitTestTBBBitField(int argc, char* argv[])
|
||||
{
|
||||
auto& tracker = vtkm::cont::GetRuntimeDeviceTracker();
|
||||
tracker.ForceDevice(vtkm::cont::DeviceAdapterTagTBB{});
|
||||
return vtkm::cont::testing::TestingBitField<vtkm::cont::DeviceAdapterTagTBB>::Run(argc, argv);
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
//============================================================================
|
||||
// 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/testing/TestingCellLocatorRectilinearGrid.h>
|
||||
|
||||
int UnitTestTBBCellLocatorRectilinearGrid(int argc, char* argv[])
|
||||
{
|
||||
auto& tracker = vtkm::cont::GetRuntimeDeviceTracker();
|
||||
tracker.ForceDevice(vtkm::cont::DeviceAdapterTagTBB{});
|
||||
return vtkm::cont::testing::Testing::Run(
|
||||
TestingCellLocatorRectilinearGrid<vtkm::cont::DeviceAdapterTagTBB>(), argc, argv);
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
//============================================================================
|
||||
// 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/testing/TestingCellLocatorTwoLevel.h>
|
||||
|
||||
int UnitTestTBBCellLocatorTwoLevel(int argc, char* argv[])
|
||||
{
|
||||
auto& tracker = vtkm::cont::GetRuntimeDeviceTracker();
|
||||
tracker.ForceDevice(vtkm::cont::DeviceAdapterTagTBB{});
|
||||
return vtkm::cont::testing::Testing::Run(
|
||||
TestingCellLocatorTwoLevel<vtkm::cont::DeviceAdapterTagTBB>, argc, argv);
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
//============================================================================
|
||||
// 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/testing/TestingCellLocatorUniformGrid.h>
|
||||
|
||||
int UnitTestTBBCellLocatorUniformGrid(int argc, char* argv[])
|
||||
{
|
||||
auto& tracker = vtkm::cont::GetRuntimeDeviceTracker();
|
||||
tracker.ForceDevice(vtkm::cont::DeviceAdapterTagTBB{});
|
||||
return vtkm::cont::testing::Testing::Run(
|
||||
TestingCellLocatorUniformGrid<vtkm::cont::DeviceAdapterTagTBB>(), argc, argv);
|
||||
}
|
@ -1,20 +0,0 @@
|
||||
//============================================================================
|
||||
// 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/tbb/DeviceAdapterTBB.h>
|
||||
|
||||
#include <vtkm/cont/testing/TestingColorTable.h>
|
||||
|
||||
int UnitTestTBBColorTable(int argc, char* argv[])
|
||||
{
|
||||
auto& tracker = vtkm::cont::GetRuntimeDeviceTracker();
|
||||
tracker.ForceDevice(vtkm::cont::DeviceAdapterTagTBB{});
|
||||
return vtkm::cont::testing::TestingColorTable<vtkm::cont::DeviceAdapterTagTBB>::Run(argc, argv);
|
||||
}
|
@ -1,20 +0,0 @@
|
||||
//============================================================================
|
||||
// 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/tbb/DeviceAdapterTBB.h>
|
||||
|
||||
#include <vtkm/cont/testing/TestingComputeRange.h>
|
||||
|
||||
int UnitTestTBBComputeRange(int argc, char* argv[])
|
||||
{
|
||||
auto& tracker = vtkm::cont::GetRuntimeDeviceTracker();
|
||||
tracker.ForceDevice(vtkm::cont::DeviceAdapterTagTBB{});
|
||||
return vtkm::cont::testing::TestingComputeRange<vtkm::cont::DeviceAdapterTagTBB>::Run(argc, argv);
|
||||
}
|
@ -1,21 +0,0 @@
|
||||
//============================================================================
|
||||
// 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/tbb/DeviceAdapterTBB.h>
|
||||
|
||||
#include <vtkm/cont/testing/TestingDataSetExplicit.h>
|
||||
|
||||
int UnitTestTBBDataSetExplicit(int argc, char* argv[])
|
||||
{
|
||||
auto& tracker = vtkm::cont::GetRuntimeDeviceTracker();
|
||||
tracker.ForceDevice(vtkm::cont::DeviceAdapterTagTBB{});
|
||||
return vtkm::cont::testing::TestingDataSetExplicit<vtkm::cont::DeviceAdapterTagTBB>::Run(argc,
|
||||
argv);
|
||||
}
|
@ -1,21 +0,0 @@
|
||||
//============================================================================
|
||||
// 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/tbb/DeviceAdapterTBB.h>
|
||||
|
||||
#include <vtkm/cont/testing/TestingDataSetSingleType.h>
|
||||
|
||||
int UnitTestTBBDataSetSingleType(int argc, char* argv[])
|
||||
{
|
||||
auto& tracker = vtkm::cont::GetRuntimeDeviceTracker();
|
||||
tracker.ForceDevice(vtkm::cont::DeviceAdapterTagTBB{});
|
||||
return vtkm::cont::testing::TestingDataSetSingleType<vtkm::cont::DeviceAdapterTagTBB>::Run(argc,
|
||||
argv);
|
||||
}
|
@ -1,29 +0,0 @@
|
||||
//============================================================================
|
||||
// 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/testing/TestingImplicitFunction.h>
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
void TestImplicitFunctions()
|
||||
{
|
||||
vtkm::cont::testing::TestingImplicitFunction testing;
|
||||
testing.Run(vtkm::cont::DeviceAdapterTagTBB());
|
||||
}
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
int UnitTestTBBImplicitFunction(int argc, char* argv[])
|
||||
{
|
||||
auto& tracker = vtkm::cont::GetRuntimeDeviceTracker();
|
||||
tracker.ForceDevice(vtkm::cont::DeviceAdapterTagTBB{});
|
||||
return vtkm::cont::testing::Testing::Run(TestImplicitFunctions, argc, argv);
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
//============================================================================
|
||||
// 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/testing/TestingPointLocatorSparseGrid.h>
|
||||
|
||||
int UnitTestTBBPointLocatorSparseGrid(int argc, char* argv[])
|
||||
{
|
||||
auto& tracker = vtkm::cont::GetRuntimeDeviceTracker();
|
||||
tracker.ForceDevice(vtkm::cont::DeviceAdapterTagTBB{});
|
||||
return vtkm::cont::testing::Testing::Run(
|
||||
TestingPointLocatorSparseGrid<vtkm::cont::DeviceAdapterTagTBB>(), argc, argv);
|
||||
}
|
@ -1,37 +0,0 @@
|
||||
//============================================================================
|
||||
// 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/RuntimeDeviceTracker.h>
|
||||
#include <vtkm/cont/testing/TestingVirtualObjectHandle.h>
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
void TestVirtualObjectHandle()
|
||||
{
|
||||
auto& tracker = vtkm::cont::GetRuntimeDeviceTracker();
|
||||
|
||||
tracker.ForceDevice(vtkm::cont::DeviceAdapterTagTBB{});
|
||||
using DeviceAdapterList = vtkm::List<vtkm::cont::DeviceAdapterTagTBB>;
|
||||
vtkm::cont::testing::TestingVirtualObjectHandle<DeviceAdapterList>::Run();
|
||||
|
||||
tracker.Reset();
|
||||
using DeviceAdapterList2 =
|
||||
vtkm::List<vtkm::cont::DeviceAdapterTagSerial, vtkm::cont::DeviceAdapterTagTBB>;
|
||||
vtkm::cont::testing::TestingVirtualObjectHandle<DeviceAdapterList2>::Run();
|
||||
}
|
||||
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
int UnitTestTBBVirtualObjectHandle(int argc, char* argv[])
|
||||
{
|
||||
return vtkm::cont::testing::Testing::Run(TestVirtualObjectHandle, argc, argv);
|
||||
}
|
@ -12,22 +12,9 @@ set(headers
|
||||
ExplicitTestData.h
|
||||
MakeTestDataSet.h
|
||||
Testing.h
|
||||
TestingArrayHandles.h
|
||||
TestingArrayHandleMultiplexer.h
|
||||
TestingCellLocatorRectilinearGrid.h
|
||||
TestingCellLocatorTwoLevel.h
|
||||
TestingCellLocatorUniformGrid.h
|
||||
TestingColorTable.h
|
||||
TestingComputeRange.h
|
||||
TestingDeviceAdapter.h
|
||||
TestingDataSetExplicit.h
|
||||
TestingDataSetSingleType.h
|
||||
TestingFancyArrayHandles.h
|
||||
TestingImplicitFunction.h
|
||||
TestingPointLocatorSparseGrid.h
|
||||
TestingRuntimeDeviceConfiguration.h
|
||||
TestingSerialization.h
|
||||
TestingVirtualObjectHandle.h
|
||||
)
|
||||
|
||||
set(unit_tests
|
||||
@ -35,10 +22,8 @@ set(unit_tests
|
||||
UnitTestArrayGetValues.cxx
|
||||
UnitTestArrayHandleCartesianProduct.cxx
|
||||
UnitTestArrayHandleCompositeVector.cxx
|
||||
UnitTestArrayHandleConcatenate.cxx
|
||||
UnitTestArrayHandleCounting.cxx
|
||||
UnitTestArrayHandleDiscard.cxx
|
||||
UnitTestArrayHandleImplicit.cxx
|
||||
UnitTestArrayHandleIndex.cxx
|
||||
UnitTestArrayHandleOffsetsToNumComponents.cxx
|
||||
UnitTestArrayHandleRandomUniformBits.cxx
|
||||
@ -47,12 +32,14 @@ set(unit_tests
|
||||
UnitTestArrayHandleUniformPointCoordinates.cxx
|
||||
UnitTestArrayHandleVirtual.cxx
|
||||
UnitTestArrayPortalToIterators.cxx
|
||||
UnitTestComputeRange.cxx
|
||||
UnitTestContTesting.cxx
|
||||
UnitTestDataSetBuilderCurvilinear.cxx
|
||||
UnitTestDataSetBuilderExplicit.cxx
|
||||
UnitTestDataSetBuilderRectilinear.cxx
|
||||
UnitTestDataSetBuilderUniform.cxx
|
||||
UnitTestDataSetConvertToExpected.cxx
|
||||
UnitTestDataSetExplicit.cxx
|
||||
UnitTestDataSetRectilinear.cxx
|
||||
UnitTestDataSetUniform.cxx
|
||||
UnitTestDeviceAdapterAlgorithmGeneral.cxx
|
||||
@ -82,26 +69,52 @@ set(unit_tests
|
||||
set(unit_tests_device
|
||||
UnitTestAlgorithm.cxx
|
||||
UnitTestArrayCopy.cxx
|
||||
UnitTestArrayHandle.cxx
|
||||
UnitTestArrayHandleConcatenate.cxx
|
||||
UnitTestArrayHandleConstant.cxx
|
||||
UnitTestArrayHandleCast.cxx
|
||||
UnitTestArrayHandleDecorator.cxx
|
||||
UnitTestArrayHandleExtractComponent.cxx
|
||||
UnitTestArrayHandleGroupVec.cxx
|
||||
UnitTestArrayHandleGroupVecVariable.cxx
|
||||
UnitTestArrayHandleImplicit.cxx
|
||||
UnitTestArrayHandleMultiplexer.cxx
|
||||
UnitTestArrayHandlePermutation.cxx
|
||||
UnitTestArrayHandleRandomStandardNormal.cxx
|
||||
UnitTestArrayHandleRandomUniformReal.cxx
|
||||
UnitTestArrayHandleRecombineVec.cxx
|
||||
UnitTestArrayHandleSOA.cxx
|
||||
UnitTestArrayHandleSwizzle.cxx
|
||||
UnitTestArrayHandleTransform.cxx
|
||||
UnitTestArrayHandleView.cxx
|
||||
UnitTestArrayHandleXGCCoordinates.cxx
|
||||
UnitTestArrayHandleZip.cxx
|
||||
UnitTestArrayRangeCompute.cxx
|
||||
UnitTestBitField.cxx
|
||||
UnitTestCellLocatorChooser.cxx
|
||||
UnitTestCellLocatorGeneral.cxx
|
||||
UnitTestCellLocatorRectilinearGrid.cxx
|
||||
UnitTestCellLocatorTwoLevel.cxx
|
||||
UnitTestCellLocatorUniformGrid.cxx
|
||||
UnitTestCellSet.cxx
|
||||
UnitTestCellSetExplicit.cxx
|
||||
UnitTestCellSetExtrude.cxx
|
||||
UnitTestCellSetPermutation.cxx
|
||||
UnitTestColorTable.cxx
|
||||
UnitTestDataSetPermutation.cxx
|
||||
UnitTestDataSetSingleType.cxx
|
||||
UnitTestDeviceAdapterAlgorithmDependency.cxx
|
||||
UnitTestImplicitFunction.cxx
|
||||
UnitTestParticleArrayCopy.cxx
|
||||
UnitTestPointLocatorSparseGrid.cxx
|
||||
)
|
||||
|
||||
if (NOT VTKm_NO_DEPRECATED_VIRTUAL)
|
||||
list(APPEND unit_tests_device
|
||||
UnitTestVirtualObjectHandle.cxx
|
||||
)
|
||||
endif()
|
||||
|
||||
set(library_sources
|
||||
TestEqualArrayHandles.cxx
|
||||
Testing.cxx
|
||||
@ -116,7 +129,7 @@ vtkm_library(
|
||||
DEVICE_SOURCES ${library_sources_device}
|
||||
HEADERS ${headers}
|
||||
)
|
||||
target_link_libraries(vtkm_cont_testing PUBLIC vtkm_cont)
|
||||
target_link_libraries(vtkm_cont_testing PUBLIC vtkm_cont vtkm_worklet)
|
||||
|
||||
if(VTKm_ENABLE_TESTING)
|
||||
vtkm_unit_tests(SOURCES ${unit_tests} DEVICE_SOURCES ${unit_tests_device})
|
||||
|
@ -1,198 +0,0 @@
|
||||
//============================================================================
|
||||
// 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.
|
||||
//============================================================================
|
||||
#ifndef vtk_m_cont_testing_TestingArrayHandleMultiplexer_h
|
||||
#define vtk_m_cont_testing_TestingArrayHandleMultiplexer_h
|
||||
|
||||
#include <vtkm/cont/ArrayHandleConstant.h>
|
||||
#include <vtkm/cont/ArrayHandleCounting.h>
|
||||
#include <vtkm/cont/ArrayHandleImplicit.h>
|
||||
#include <vtkm/cont/ArrayHandleMultiplexer.h>
|
||||
#include <vtkm/cont/ArrayHandleUniformPointCoordinates.h>
|
||||
#include <vtkm/cont/DeviceAdapterAlgorithm.h>
|
||||
#include <vtkm/cont/RuntimeDeviceTracker.h>
|
||||
|
||||
#include <vtkm/BinaryOperators.h>
|
||||
|
||||
#include <vtkm/cont/testing/Testing.h>
|
||||
|
||||
namespace vtkm
|
||||
{
|
||||
namespace cont
|
||||
{
|
||||
namespace testing
|
||||
{
|
||||
|
||||
template <typename T>
|
||||
struct TestValueFunctor
|
||||
{
|
||||
VTKM_EXEC_CONT T operator()(vtkm::Id index) const { return TestValue(index, T()); }
|
||||
};
|
||||
|
||||
template <typename DeviceAdapter>
|
||||
class TestingArrayHandleMultiplexer
|
||||
{
|
||||
static constexpr vtkm::Id ARRAY_SIZE = 10;
|
||||
|
||||
template <typename... Ts0, typename... Ts1>
|
||||
static void CheckArray(const vtkm::cont::ArrayHandleMultiplexer<Ts0...>& multiplexerArray,
|
||||
const vtkm::cont::ArrayHandle<Ts1...>& expectedArray)
|
||||
{
|
||||
using T = typename std::remove_reference<decltype(multiplexerArray)>::type::ValueType;
|
||||
|
||||
vtkm::cont::printSummary_ArrayHandle(multiplexerArray, std::cout);
|
||||
VTKM_TEST_ASSERT(test_equal_portals(multiplexerArray.ReadPortal(), expectedArray.ReadPortal()),
|
||||
"Multiplexer array gave wrong result in control environment");
|
||||
|
||||
vtkm::cont::ArrayHandle<T> copy;
|
||||
vtkm::cont::DeviceAdapterAlgorithm<DeviceAdapter>::Copy(multiplexerArray, copy);
|
||||
VTKM_TEST_ASSERT(test_equal_portals(copy.ReadPortal(), expectedArray.ReadPortal()),
|
||||
"Multiplexer did not copy correctly in execution environment");
|
||||
}
|
||||
|
||||
static void BasicSwitch()
|
||||
{
|
||||
std::cout << "\n--- Basic switch" << std::endl;
|
||||
|
||||
using ValueType = vtkm::FloatDefault;
|
||||
|
||||
using ArrayType1 = vtkm::cont::ArrayHandleConstant<ValueType>;
|
||||
ArrayType1 array1(TestValue(0, vtkm::FloatDefault{}), ARRAY_SIZE);
|
||||
|
||||
using ArrayType2 = vtkm::cont::ArrayHandleCounting<ValueType>;
|
||||
ArrayType2 array2(TestValue(1, vtkm::FloatDefault{}), 1.0f, ARRAY_SIZE);
|
||||
|
||||
auto array3 = vtkm::cont::make_ArrayHandleImplicit(TestValueFunctor<ValueType>{}, ARRAY_SIZE);
|
||||
using ArrayType3 = decltype(array3);
|
||||
|
||||
vtkm::cont::ArrayHandleMultiplexer<ArrayType1, ArrayType2, ArrayType3> multiplexer;
|
||||
|
||||
std::cout << "Check array1" << std::endl;
|
||||
multiplexer = array1;
|
||||
CheckArray(multiplexer, array1);
|
||||
|
||||
std::cout << "Check array2" << std::endl;
|
||||
multiplexer = array2;
|
||||
CheckArray(multiplexer, array2);
|
||||
|
||||
std::cout << "Check array3" << std::endl;
|
||||
multiplexer = array3;
|
||||
CheckArray(multiplexer, array3);
|
||||
}
|
||||
|
||||
static void Reduce()
|
||||
{
|
||||
// Regression test for an issue with compiling ArrayHandleMultiplexer with the thrust reduce
|
||||
// algorithm on CUDA. Most likely related to:
|
||||
// https://github.com/thrust/thrust/issues/928
|
||||
// https://github.com/thrust/thrust/issues/1044
|
||||
std::cout << "\n--- Reduce" << std::endl;
|
||||
|
||||
using ValueType = vtkm::Vec3f;
|
||||
using MultiplexerType = vtkm::cont::ArrayHandleMultiplexer<
|
||||
vtkm::cont::ArrayHandleConstant<ValueType>,
|
||||
vtkm::cont::ArrayHandleCounting<ValueType>,
|
||||
vtkm::cont::ArrayHandle<ValueType>,
|
||||
vtkm::cont::ArrayHandleUniformPointCoordinates,
|
||||
vtkm::cont::ArrayHandleCartesianProduct<vtkm::cont::ArrayHandle<vtkm::FloatDefault>,
|
||||
vtkm::cont::ArrayHandle<vtkm::FloatDefault>,
|
||||
vtkm::cont::ArrayHandle<vtkm::FloatDefault>>>;
|
||||
|
||||
MultiplexerType multiplexer =
|
||||
vtkm::cont::ArrayHandleCounting<ValueType>(vtkm::Vec3f(1), vtkm::Vec3f(1), ARRAY_SIZE);
|
||||
|
||||
using Algorithm = vtkm::cont::DeviceAdapterAlgorithm<DeviceAdapter>;
|
||||
|
||||
{
|
||||
std::cout << "Basic Reduce" << std::endl;
|
||||
ValueType result = Algorithm::Reduce(multiplexer, ValueType(0.0));
|
||||
VTKM_TEST_ASSERT(test_equal(result, ValueType(0.5 * (ARRAY_SIZE * (ARRAY_SIZE + 1)))));
|
||||
}
|
||||
|
||||
{
|
||||
std::cout << "Reduce with custom operator" << std::endl;
|
||||
vtkm::Vec<ValueType, 2> initial(ValueType(10000), ValueType(0));
|
||||
vtkm::Vec<ValueType, 2> result =
|
||||
Algorithm::Reduce(multiplexer, initial, vtkm::MinAndMax<ValueType>{});
|
||||
VTKM_TEST_ASSERT(test_equal(result[0], ValueType(1)));
|
||||
VTKM_TEST_ASSERT(
|
||||
test_equal(result[1], ValueType(static_cast<vtkm::FloatDefault>(ARRAY_SIZE))));
|
||||
}
|
||||
}
|
||||
|
||||
static void Fill()
|
||||
{
|
||||
std::cout << "\n--- Fill" << std::endl;
|
||||
|
||||
using ValueType = vtkm::Vec3f;
|
||||
using MultiplexerType = vtkm::cont::ArrayHandleMultiplexer<
|
||||
vtkm::cont::ArrayHandleConstant<ValueType>,
|
||||
vtkm::cont::ArrayHandleCounting<ValueType>,
|
||||
vtkm::cont::ArrayHandle<ValueType>,
|
||||
vtkm::cont::ArrayHandleUniformPointCoordinates,
|
||||
vtkm::cont::ArrayHandleCartesianProduct<vtkm::cont::ArrayHandle<vtkm::FloatDefault>,
|
||||
vtkm::cont::ArrayHandle<vtkm::FloatDefault>,
|
||||
vtkm::cont::ArrayHandle<vtkm::FloatDefault>>>;
|
||||
|
||||
const ValueType testValue1 = TestValue(1, ValueType{});
|
||||
const ValueType testValue2 = TestValue(2, ValueType{});
|
||||
|
||||
MultiplexerType multiplexer = vtkm::cont::ArrayHandle<ValueType>{};
|
||||
|
||||
multiplexer.AllocateAndFill(ARRAY_SIZE, testValue1);
|
||||
{
|
||||
auto portal = multiplexer.ReadPortal();
|
||||
VTKM_TEST_ASSERT(portal.GetNumberOfValues() == ARRAY_SIZE);
|
||||
for (vtkm::Id index = 0; index < ARRAY_SIZE; ++index)
|
||||
{
|
||||
VTKM_TEST_ASSERT(portal.Get(index) == testValue1);
|
||||
}
|
||||
}
|
||||
|
||||
vtkm::cont::ArrayHandle<vtkm::FloatDefault> array1;
|
||||
array1.Allocate(ARRAY_SIZE);
|
||||
vtkm::cont::ArrayHandle<vtkm::FloatDefault> array2;
|
||||
array2.Allocate(ARRAY_SIZE);
|
||||
vtkm::cont::ArrayHandle<vtkm::FloatDefault> array3;
|
||||
array3.Allocate(ARRAY_SIZE);
|
||||
multiplexer = vtkm::cont::make_ArrayHandleCartesianProduct(array1, array2, array3);
|
||||
|
||||
multiplexer.Fill(testValue2);
|
||||
{
|
||||
auto portal1 = array1.ReadPortal();
|
||||
auto portal2 = array2.ReadPortal();
|
||||
auto portal3 = array3.ReadPortal();
|
||||
for (vtkm::Id index = 0; index < ARRAY_SIZE; ++index)
|
||||
{
|
||||
VTKM_TEST_ASSERT(portal1.Get(index) == testValue2[0]);
|
||||
VTKM_TEST_ASSERT(portal2.Get(index) == testValue2[1]);
|
||||
VTKM_TEST_ASSERT(portal3.Get(index) == testValue2[2]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void TestAll()
|
||||
{
|
||||
BasicSwitch();
|
||||
Reduce();
|
||||
Fill();
|
||||
}
|
||||
|
||||
public:
|
||||
static int Run(int argc, char* argv[])
|
||||
{
|
||||
vtkm::cont::ScopedRuntimeDeviceTracker device(DeviceAdapter{});
|
||||
return vtkm::cont::testing::Testing::Run(TestAll, argc, argv);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
} // namespace vtkm::cont::testing
|
||||
|
||||
#endif //vtk_m_cont_testing_TestingArrayHandleMultiplexer_h
|
@ -1,764 +0,0 @@
|
||||
//============================================================================
|
||||
// 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.
|
||||
//============================================================================
|
||||
#ifndef vtk_m_cont_testing_TestingArrayHandles_h
|
||||
#define vtk_m_cont_testing_TestingArrayHandles_h
|
||||
|
||||
#include <vtkm/TypeTraits.h>
|
||||
#include <vtkm/cont/ArrayHandle.h>
|
||||
#include <vtkm/cont/RuntimeDeviceTracker.h>
|
||||
|
||||
#include <vtkm/worklet/DispatcherMapField.h>
|
||||
#include <vtkm/worklet/WorkletMapField.h>
|
||||
|
||||
#include <vtkm/cont/ArrayHandleExtractComponent.h>
|
||||
#include <vtkm/cont/testing/Testing.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <vector>
|
||||
|
||||
namespace vtkm
|
||||
{
|
||||
namespace cont
|
||||
{
|
||||
namespace testing
|
||||
{
|
||||
|
||||
namespace array_handle_testing
|
||||
{
|
||||
template <class IteratorType, typename T>
|
||||
void CheckValues(IteratorType begin, IteratorType end, T)
|
||||
{
|
||||
|
||||
vtkm::Id index = 0;
|
||||
for (IteratorType iter = begin; iter != end; iter++)
|
||||
{
|
||||
T expectedValue = TestValue(index, T());
|
||||
if (!test_equal(*iter, expectedValue))
|
||||
{
|
||||
std::stringstream message;
|
||||
message << "Got unexpected value in array." << std::endl
|
||||
<< "Expected: " << expectedValue << ", Found: " << *iter << std::endl;
|
||||
VTKM_TEST_FAIL(message.str().c_str());
|
||||
}
|
||||
|
||||
index++;
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void CheckArray(const vtkm::cont::ArrayHandle<T>& handle)
|
||||
{
|
||||
CheckPortal(handle.ReadPortal());
|
||||
}
|
||||
}
|
||||
|
||||
// Use to get an arbitrarily different valuetype than T:
|
||||
template <typename T>
|
||||
struct OtherType
|
||||
{
|
||||
using Type = vtkm::Int32;
|
||||
};
|
||||
template <>
|
||||
struct OtherType<vtkm::Int32>
|
||||
{
|
||||
using Type = vtkm::UInt8;
|
||||
};
|
||||
|
||||
/// This class has a single static member, Run, that tests that all Fancy Array
|
||||
/// Handles work with the given DeviceAdapter
|
||||
///
|
||||
template <class DeviceAdapterTag>
|
||||
struct TestingArrayHandles
|
||||
{
|
||||
// Make sure deprecated types still work (while applicable)
|
||||
VTKM_DEPRECATED_SUPPRESS_BEGIN
|
||||
VTKM_STATIC_ASSERT(
|
||||
(std::is_same<typename vtkm::cont::ArrayHandle<vtkm::Id>::ReadPortalType,
|
||||
typename vtkm::cont::ArrayHandle<vtkm::Id>::template ExecutionTypes<
|
||||
DeviceAdapterTag>::PortalConst>::value));
|
||||
VTKM_STATIC_ASSERT((std::is_same<typename vtkm::cont::ArrayHandle<vtkm::Id>::WritePortalType,
|
||||
typename vtkm::cont::ArrayHandle<vtkm::Id>::
|
||||
template ExecutionTypes<DeviceAdapterTag>::Portal>::value));
|
||||
VTKM_DEPRECATED_SUPPRESS_END
|
||||
|
||||
template <typename PortalType>
|
||||
struct PortalExecObjectWrapper : vtkm::cont::ExecutionObjectBase
|
||||
{
|
||||
PortalType Portal;
|
||||
PortalExecObjectWrapper(const PortalType& portal)
|
||||
: Portal(portal)
|
||||
{
|
||||
}
|
||||
|
||||
PortalType PrepareForExecution(DeviceAdapterTag, vtkm::cont::Token&) const
|
||||
{
|
||||
return this->Portal;
|
||||
}
|
||||
|
||||
template <typename OtherDevice>
|
||||
PortalType PrepareForExecution(OtherDevice, vtkm::cont::Token&) const
|
||||
{
|
||||
VTKM_TEST_FAIL("Executing on wrong device.");
|
||||
return this->Portal;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename PortalType>
|
||||
static PortalExecObjectWrapper<PortalType> WrapPortal(const PortalType& portal)
|
||||
{
|
||||
return PortalExecObjectWrapper<PortalType>(portal);
|
||||
}
|
||||
|
||||
struct PassThrough : public vtkm::worklet::WorkletMapField
|
||||
{
|
||||
using ControlSignature = void(FieldIn, ExecObject, FieldOut);
|
||||
using ExecutionSignature = _3(_2, InputIndex);
|
||||
|
||||
template <typename PortalType>
|
||||
VTKM_EXEC typename PortalType::ValueType operator()(const PortalType& portal,
|
||||
vtkm::Id index) const
|
||||
{
|
||||
return portal.Get(index);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T, typename ExecutionPortalType>
|
||||
struct AssignTestValue : public vtkm::exec::FunctorBase
|
||||
{
|
||||
ExecutionPortalType Portal;
|
||||
VTKM_CONT
|
||||
AssignTestValue(ExecutionPortalType p)
|
||||
: Portal(p)
|
||||
{
|
||||
}
|
||||
|
||||
VTKM_EXEC
|
||||
void operator()(vtkm::Id index) const { this->Portal.Set(index, TestValue(index, T())); }
|
||||
};
|
||||
|
||||
template <typename T, typename ExecutionPortalType>
|
||||
struct InplaceFunctor : public vtkm::exec::FunctorBase
|
||||
{
|
||||
ExecutionPortalType Portal;
|
||||
VTKM_CONT
|
||||
InplaceFunctor(const ExecutionPortalType& p)
|
||||
: Portal(p)
|
||||
{
|
||||
}
|
||||
|
||||
VTKM_EXEC
|
||||
void operator()(vtkm::Id index) const
|
||||
{
|
||||
this->Portal.Set(index, T(this->Portal.Get(index) + T(1)));
|
||||
}
|
||||
};
|
||||
|
||||
private:
|
||||
static constexpr vtkm::Id ARRAY_SIZE = 100;
|
||||
|
||||
using Algorithm = vtkm::cont::DeviceAdapterAlgorithm<DeviceAdapterTag>;
|
||||
|
||||
using DispatcherPassThrough = vtkm::worklet::DispatcherMapField<PassThrough>;
|
||||
struct VerifyEmptyArrays
|
||||
{
|
||||
template <typename T>
|
||||
VTKM_CONT void operator()(T) const
|
||||
{
|
||||
std::cout << "Try operations on empty arrays." << std::endl;
|
||||
// After each operation, reinitialize array in case something gets
|
||||
// allocated.
|
||||
vtkm::cont::ArrayHandle<T> arrayHandle = vtkm::cont::ArrayHandle<T>();
|
||||
VTKM_TEST_ASSERT(arrayHandle.GetNumberOfValues() == 0,
|
||||
"Uninitialized array does not report zero values.");
|
||||
arrayHandle = vtkm::cont::ArrayHandle<T>();
|
||||
VTKM_TEST_ASSERT(arrayHandle.ReadPortal().GetNumberOfValues() == 0,
|
||||
"Uninitialized array does not give portal with zero values.");
|
||||
vtkm::cont::Token token;
|
||||
arrayHandle = vtkm::cont::ArrayHandle<T>();
|
||||
arrayHandle.Allocate(0, vtkm::CopyFlag::On);
|
||||
arrayHandle = vtkm::cont::ArrayHandle<T>();
|
||||
arrayHandle.ReleaseResourcesExecution();
|
||||
arrayHandle = vtkm::cont::ArrayHandle<T>();
|
||||
arrayHandle.ReleaseResources();
|
||||
arrayHandle = vtkm::cont::make_ArrayHandleMove(std::vector<T>());
|
||||
arrayHandle.PrepareForInput(DeviceAdapterTag(), token);
|
||||
arrayHandle = vtkm::cont::ArrayHandle<T>();
|
||||
arrayHandle.PrepareForInPlace(DeviceAdapterTag(), token);
|
||||
arrayHandle = vtkm::cont::ArrayHandle<T>();
|
||||
arrayHandle.PrepareForOutput(ARRAY_SIZE, DeviceAdapterTag(), token);
|
||||
}
|
||||
};
|
||||
|
||||
struct VerifyUserOwnedMemory
|
||||
{
|
||||
template <typename T>
|
||||
VTKM_CONT void operator()(T) const
|
||||
{
|
||||
std::cout << "Creating array with user-allocated memory." << std::endl;
|
||||
std::vector<T> buffer(ARRAY_SIZE);
|
||||
for (vtkm::Id index = 0; index < ARRAY_SIZE; index++)
|
||||
{
|
||||
buffer[static_cast<std::size_t>(index)] = TestValue(index, T());
|
||||
}
|
||||
|
||||
vtkm::cont::ArrayHandle<T> arrayHandle =
|
||||
vtkm::cont::make_ArrayHandle(buffer, vtkm::CopyFlag::Off);
|
||||
|
||||
VTKM_TEST_ASSERT(arrayHandle.GetNumberOfValues() == ARRAY_SIZE,
|
||||
"ArrayHandle has wrong number of entries.");
|
||||
|
||||
std::cout << "Check array with user provided memory." << std::endl;
|
||||
array_handle_testing::CheckArray(arrayHandle);
|
||||
|
||||
std::cout << "Check out execution array behavior." << std::endl;
|
||||
{ //as input
|
||||
vtkm::cont::Token token;
|
||||
typename vtkm::cont::ArrayHandle<T>::ReadPortalType executionPortal =
|
||||
arrayHandle.PrepareForInput(DeviceAdapterTag(), token);
|
||||
token.DetachFromAll();
|
||||
static_cast<void>(executionPortal);
|
||||
|
||||
//use a worklet to verify the input transfer worked properly
|
||||
vtkm::cont::ArrayHandle<T> result;
|
||||
DispatcherPassThrough().Invoke(arrayHandle, WrapPortal(executionPortal), result);
|
||||
array_handle_testing::CheckArray(result);
|
||||
}
|
||||
|
||||
std::cout << "Check out inplace." << std::endl;
|
||||
{ //as inplace
|
||||
vtkm::cont::Token token;
|
||||
typename vtkm::cont::ArrayHandle<T>::WritePortalType executionPortal =
|
||||
arrayHandle.PrepareForInPlace(DeviceAdapterTag(), token);
|
||||
token.DetachFromAll();
|
||||
static_cast<void>(executionPortal);
|
||||
|
||||
//use a worklet to verify the inplace transfer worked properly
|
||||
vtkm::cont::ArrayHandle<T> result;
|
||||
DispatcherPassThrough().Invoke(arrayHandle, WrapPortal(executionPortal), result);
|
||||
array_handle_testing::CheckArray(result);
|
||||
}
|
||||
|
||||
//clear out user array for next test
|
||||
std::fill(buffer.begin(), buffer.end(), static_cast<T>(-1));
|
||||
|
||||
std::cout << "Check out output." << std::endl;
|
||||
{ //as output with same length as user provided. This should work
|
||||
//as no new memory needs to be allocated
|
||||
vtkm::cont::Token token;
|
||||
auto outputPortal = arrayHandle.PrepareForOutput(ARRAY_SIZE, DeviceAdapterTag(), token);
|
||||
|
||||
//fill array on device
|
||||
Algorithm::Schedule(AssignTestValue<T, decltype(outputPortal)>{ outputPortal }, ARRAY_SIZE);
|
||||
|
||||
//sync data, which should fill up the user buffer
|
||||
token.DetachFromAll();
|
||||
arrayHandle.SyncControlArray();
|
||||
|
||||
//check that we got the proper values in the user array
|
||||
array_handle_testing::CheckValues(buffer.begin(), buffer.end(), T{});
|
||||
}
|
||||
|
||||
{ //as output with a length larger than the memory provided by the user
|
||||
//this should fail
|
||||
bool gotException = false;
|
||||
try
|
||||
{
|
||||
//you should not be able to allocate a size larger than the
|
||||
//user provided and get the results
|
||||
vtkm::cont::Token token;
|
||||
arrayHandle.PrepareForOutput(ARRAY_SIZE * 2, DeviceAdapterTag(), token);
|
||||
token.DetachFromAll();
|
||||
arrayHandle.WritePortal();
|
||||
}
|
||||
catch (vtkm::cont::Error&)
|
||||
{
|
||||
gotException = true;
|
||||
}
|
||||
VTKM_TEST_ASSERT(gotException,
|
||||
"PrepareForOutput should fail when asked to "
|
||||
"re-allocate user provided memory.");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
struct VerifyUserTransferredMemory
|
||||
{
|
||||
template <typename T>
|
||||
VTKM_CONT void operator()(T) const
|
||||
{
|
||||
T* buffer = new T[ARRAY_SIZE];
|
||||
for (vtkm::Id index = 0; index < ARRAY_SIZE; index++)
|
||||
{
|
||||
buffer[static_cast<std::size_t>(index)] = TestValue(index, T());
|
||||
}
|
||||
|
||||
auto user_free_function = [](void* ptr) { delete[] static_cast<T*>(ptr); };
|
||||
vtkm::cont::ArrayHandleBasic<T> arrayHandle(buffer, ARRAY_SIZE, user_free_function);
|
||||
|
||||
VTKM_TEST_ASSERT(arrayHandle.GetNumberOfValues() == ARRAY_SIZE,
|
||||
"ArrayHandle has wrong number of entries.");
|
||||
|
||||
std::cout << "Check array with user transferred memory." << std::endl;
|
||||
array_handle_testing::CheckArray(arrayHandle);
|
||||
|
||||
std::cout << "Check out execution array behavior." << std::endl;
|
||||
{ //as input
|
||||
vtkm::cont::Token token;
|
||||
typename vtkm::cont::ArrayHandle<T>::ReadPortalType executionPortal =
|
||||
arrayHandle.PrepareForInput(DeviceAdapterTag(), token);
|
||||
token.DetachFromAll();
|
||||
static_cast<void>(executionPortal);
|
||||
|
||||
//use a worklet to verify the input transfer worked properly
|
||||
vtkm::cont::ArrayHandle<T> result;
|
||||
DispatcherPassThrough().Invoke(arrayHandle, WrapPortal(executionPortal), result);
|
||||
array_handle_testing::CheckArray(result);
|
||||
}
|
||||
|
||||
std::cout << "Check out inplace." << std::endl;
|
||||
{ //as inplace
|
||||
vtkm::cont::Token token;
|
||||
typename vtkm::cont::ArrayHandle<T>::WritePortalType executionPortal =
|
||||
arrayHandle.PrepareForInPlace(DeviceAdapterTag(), token);
|
||||
token.DetachFromAll();
|
||||
static_cast<void>(executionPortal);
|
||||
|
||||
//use a worklet to verify the inplace transfer worked properly
|
||||
vtkm::cont::ArrayHandle<T> result;
|
||||
DispatcherPassThrough().Invoke(arrayHandle, WrapPortal(executionPortal), result);
|
||||
array_handle_testing::CheckArray(result);
|
||||
}
|
||||
|
||||
std::cout << "Check out output." << std::endl;
|
||||
{ //as output with same length as user provided. This should work
|
||||
//as no new memory needs to be allocated
|
||||
vtkm::cont::Token token;
|
||||
arrayHandle.PrepareForOutput(ARRAY_SIZE, DeviceAdapterTag(), token);
|
||||
token.DetachFromAll();
|
||||
|
||||
//we can't verify output contents as those aren't fetched, we
|
||||
//can just make sure the allocation didn't throw an exception
|
||||
}
|
||||
|
||||
{ //as output with a length larger than the memory provided by the user
|
||||
//this should fail
|
||||
bool gotException = false;
|
||||
try
|
||||
{
|
||||
//you should not be able to allocate a size larger than the
|
||||
//user provided and get the results
|
||||
vtkm::cont::Token token;
|
||||
arrayHandle.PrepareForOutput(ARRAY_SIZE * 2, DeviceAdapterTag(), token);
|
||||
token.DetachFromAll();
|
||||
arrayHandle.WritePortal();
|
||||
}
|
||||
catch (vtkm::cont::Error&)
|
||||
{
|
||||
gotException = true;
|
||||
}
|
||||
VTKM_TEST_ASSERT(gotException,
|
||||
"PrepareForOutput should fail when asked to "
|
||||
"re-allocate user provided memory.");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
struct VerifyVectorMovedMemory
|
||||
{
|
||||
template <typename T>
|
||||
VTKM_CONT void operator()(T) const
|
||||
{
|
||||
std::cout << "Creating moved std::vector memory." << std::endl;
|
||||
std::vector<T> buffer(ARRAY_SIZE);
|
||||
for (vtkm::Id index = 0; index < ARRAY_SIZE; index++)
|
||||
{
|
||||
buffer[static_cast<std::size_t>(index)] = TestValue(index, T());
|
||||
}
|
||||
|
||||
vtkm::cont::ArrayHandle<T> arrayHandle = vtkm::cont::make_ArrayHandleMove(std::move(buffer));
|
||||
// buffer is now invalid
|
||||
|
||||
VTKM_TEST_ASSERT(arrayHandle.GetNumberOfValues() == ARRAY_SIZE,
|
||||
"ArrayHandle has wrong number of entries.");
|
||||
|
||||
std::cout << "Check array with moved std::vector memory." << std::endl;
|
||||
array_handle_testing::CheckArray(arrayHandle);
|
||||
|
||||
std::cout << "Check out execution array behavior." << std::endl;
|
||||
{ //as input
|
||||
vtkm::cont::Token token;
|
||||
typename vtkm::cont::ArrayHandle<T>::ReadPortalType executionPortal;
|
||||
executionPortal = arrayHandle.PrepareForInput(DeviceAdapterTag(), token);
|
||||
token.DetachFromAll();
|
||||
|
||||
//use a worklet to verify the input transfer worked properly
|
||||
vtkm::cont::ArrayHandle<T> result;
|
||||
DispatcherPassThrough().Invoke(arrayHandle, WrapPortal(executionPortal), result);
|
||||
array_handle_testing::CheckArray(result);
|
||||
}
|
||||
|
||||
std::cout << "Check out inplace." << std::endl;
|
||||
{ //as inplace
|
||||
vtkm::cont::Token token;
|
||||
typename vtkm::cont::ArrayHandle<T>::WritePortalType executionPortal;
|
||||
executionPortal = arrayHandle.PrepareForInPlace(DeviceAdapterTag(), token);
|
||||
token.DetachFromAll();
|
||||
|
||||
//use a worklet to verify the inplace transfer worked properly
|
||||
vtkm::cont::ArrayHandle<T> result;
|
||||
DispatcherPassThrough().Invoke(arrayHandle, WrapPortal(executionPortal), result);
|
||||
array_handle_testing::CheckArray(result);
|
||||
}
|
||||
|
||||
std::cout << "Check out output." << std::endl;
|
||||
{ //as output with same length as user provided. This should work
|
||||
//as no new memory needs to be allocated
|
||||
vtkm::cont::Token token;
|
||||
arrayHandle.PrepareForOutput(ARRAY_SIZE, DeviceAdapterTag(), token);
|
||||
token.DetachFromAll();
|
||||
|
||||
//we can't verify output contents as those aren't fetched, we
|
||||
//can just make sure the allocation didn't throw an exception
|
||||
}
|
||||
|
||||
{ //as a vector moved to the ArrayHandle, reallocation should be possible
|
||||
vtkm::cont::Token token;
|
||||
arrayHandle.PrepareForOutput(ARRAY_SIZE * 2, DeviceAdapterTag(), token);
|
||||
token.DetachFromAll();
|
||||
|
||||
//we can't verify output contents as those aren't fetched, we
|
||||
//can just make sure the allocation didn't throw an exception
|
||||
VTKM_TEST_ASSERT(arrayHandle.GetNumberOfValues() == ARRAY_SIZE * 2);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
struct VerifyInitializerList
|
||||
{
|
||||
template <typename T>
|
||||
VTKM_CONT void operator()(T) const
|
||||
{
|
||||
std::cout << "Creating array with initializer list memory." << std::endl;
|
||||
vtkm::cont::ArrayHandle<T> arrayHandle =
|
||||
vtkm::cont::make_ArrayHandle({ TestValue(0, T()), TestValue(1, T()), TestValue(2, T()) });
|
||||
|
||||
VTKM_TEST_ASSERT(arrayHandle.GetNumberOfValues() == 3,
|
||||
"ArrayHandle has wrong number of entries.");
|
||||
|
||||
std::cout << "Check array with initializer list memory." << std::endl;
|
||||
array_handle_testing::CheckArray(arrayHandle);
|
||||
|
||||
std::cout << "Check out execution array behavior." << std::endl;
|
||||
{ //as input
|
||||
vtkm::cont::Token token;
|
||||
typename vtkm::cont::ArrayHandle<T>::ReadPortalType executionPortal;
|
||||
executionPortal = arrayHandle.PrepareForInput(DeviceAdapterTag(), token);
|
||||
token.DetachFromAll();
|
||||
|
||||
//use a worklet to verify the input transfer worked properly
|
||||
vtkm::cont::ArrayHandle<T> result;
|
||||
DispatcherPassThrough().Invoke(arrayHandle, WrapPortal(executionPortal), result);
|
||||
array_handle_testing::CheckArray(result);
|
||||
}
|
||||
|
||||
std::cout << "Check out inplace." << std::endl;
|
||||
{ //as inplace
|
||||
vtkm::cont::Token token;
|
||||
typename vtkm::cont::ArrayHandle<T>::WritePortalType executionPortal;
|
||||
executionPortal = arrayHandle.PrepareForInPlace(DeviceAdapterTag(), token);
|
||||
token.DetachFromAll();
|
||||
|
||||
//use a worklet to verify the inplace transfer worked properly
|
||||
vtkm::cont::ArrayHandle<T> result;
|
||||
DispatcherPassThrough().Invoke(arrayHandle, WrapPortal(executionPortal), result);
|
||||
array_handle_testing::CheckArray(result);
|
||||
}
|
||||
|
||||
std::cout << "Check out output." << std::endl;
|
||||
{ //as output with same length as user provided. This should work
|
||||
//as no new memory needs to be allocated
|
||||
vtkm::cont::Token token;
|
||||
arrayHandle.PrepareForOutput(3, DeviceAdapterTag(), token);
|
||||
token.DetachFromAll();
|
||||
|
||||
//we can't verify output contents as those aren't fetched, we
|
||||
//can just make sure the allocation didn't throw an exception
|
||||
}
|
||||
|
||||
{ //as a vector moved to the ArrayHandle, reallocation should be possible
|
||||
vtkm::cont::Token token;
|
||||
arrayHandle.PrepareForOutput(ARRAY_SIZE * 2, DeviceAdapterTag(), token);
|
||||
token.DetachFromAll();
|
||||
|
||||
//we can't verify output contents as those aren't fetched, we
|
||||
//can just make sure the allocation didn't throw an exception
|
||||
VTKM_TEST_ASSERT(arrayHandle.GetNumberOfValues() == ARRAY_SIZE * 2);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
struct VerifyVTKMAllocatedHandle
|
||||
{
|
||||
template <typename T>
|
||||
VTKM_CONT void operator()(T) const
|
||||
{
|
||||
vtkm::cont::ArrayHandle<T> arrayHandle;
|
||||
|
||||
VTKM_TEST_ASSERT(arrayHandle.GetNumberOfValues() == 0,
|
||||
"ArrayHandle has wrong number of entries.");
|
||||
{
|
||||
vtkm::cont::Token token;
|
||||
using ExecutionPortalType = typename vtkm::cont::ArrayHandle<T>::WritePortalType;
|
||||
ExecutionPortalType executionPortal =
|
||||
arrayHandle.PrepareForOutput(ARRAY_SIZE * 2, DeviceAdapterTag(), token);
|
||||
|
||||
//we drop down to manually scheduling so that we don't need
|
||||
//need to bring in array handle counting
|
||||
AssignTestValue<T, ExecutionPortalType> functor(executionPortal);
|
||||
Algorithm::Schedule(functor, ARRAY_SIZE * 2);
|
||||
}
|
||||
|
||||
VTKM_TEST_ASSERT(arrayHandle.GetNumberOfValues() == ARRAY_SIZE * 2,
|
||||
"Array not allocated correctly.");
|
||||
array_handle_testing::CheckArray(arrayHandle);
|
||||
|
||||
std::cout << "Try shrinking the array." << std::endl;
|
||||
arrayHandle.Allocate(ARRAY_SIZE, vtkm::CopyFlag::On);
|
||||
VTKM_TEST_ASSERT(arrayHandle.GetNumberOfValues() == ARRAY_SIZE,
|
||||
"Array size did not shrink correctly.");
|
||||
array_handle_testing::CheckArray(arrayHandle);
|
||||
|
||||
std::cout << "Try reallocating array." << std::endl;
|
||||
arrayHandle.Allocate(ARRAY_SIZE * 2);
|
||||
VTKM_TEST_ASSERT(arrayHandle.GetNumberOfValues() == ARRAY_SIZE * 2,
|
||||
"Array size did not allocate correctly.");
|
||||
// No point in checking values. This method can invalidate them.
|
||||
|
||||
std::cout << "Try in place operation." << std::endl;
|
||||
{
|
||||
vtkm::cont::Token token;
|
||||
using ExecutionPortalType = typename vtkm::cont::ArrayHandle<T>::WritePortalType;
|
||||
|
||||
// Reset array data.
|
||||
Algorithm::Schedule(AssignTestValue<T, ExecutionPortalType>{ arrayHandle.PrepareForOutput(
|
||||
ARRAY_SIZE * 2, DeviceAdapterTag{}, token) },
|
||||
ARRAY_SIZE * 2);
|
||||
|
||||
ExecutionPortalType executionPortal =
|
||||
arrayHandle.PrepareForInPlace(DeviceAdapterTag(), token);
|
||||
|
||||
//in place can't be done through the dispatcher
|
||||
//instead we have to drop down to manually scheduling
|
||||
InplaceFunctor<T, ExecutionPortalType> functor(executionPortal);
|
||||
Algorithm::Schedule(functor, ARRAY_SIZE * 2);
|
||||
}
|
||||
typename vtkm::cont::ArrayHandle<T>::ReadPortalType controlPortal = arrayHandle.ReadPortal();
|
||||
for (vtkm::Id index = 0; index < ARRAY_SIZE; index++)
|
||||
{
|
||||
VTKM_TEST_ASSERT(test_equal(controlPortal.Get(index), TestValue(index, T()) + T(1)),
|
||||
"Did not get result from in place operation.");
|
||||
}
|
||||
|
||||
VTKM_TEST_ASSERT(arrayHandle == arrayHandle, "Array handle does not equal itself.");
|
||||
VTKM_TEST_ASSERT(arrayHandle != vtkm::cont::ArrayHandle<T>(),
|
||||
"Array handle equals different array.");
|
||||
}
|
||||
};
|
||||
|
||||
struct VerifyVTKMTransferredOwnership
|
||||
{
|
||||
template <typename T>
|
||||
VTKM_CONT void operator()(T) const
|
||||
{
|
||||
|
||||
vtkm::cont::internal::TransferredBuffer transferredMemory;
|
||||
|
||||
//Steal memory from a handle that has multiple copies to verify all
|
||||
//copies are updated correctly
|
||||
{
|
||||
vtkm::cont::ArrayHandle<T> arrayHandle;
|
||||
auto copyOfHandle = arrayHandle;
|
||||
|
||||
VTKM_TEST_ASSERT(arrayHandle.GetNumberOfValues() == 0,
|
||||
"ArrayHandle has wrong number of entries.");
|
||||
{
|
||||
vtkm::cont::Token token;
|
||||
using ExecutionPortalType = typename vtkm::cont::ArrayHandle<T>::WritePortalType;
|
||||
ExecutionPortalType executionPortal =
|
||||
arrayHandle.PrepareForOutput(ARRAY_SIZE * 2, DeviceAdapterTag(), token);
|
||||
|
||||
//we drop down to manually scheduling so that we don't need
|
||||
//need to bring in array handle counting
|
||||
AssignTestValue<T, ExecutionPortalType> functor(executionPortal);
|
||||
Algorithm::Schedule(functor, ARRAY_SIZE * 2);
|
||||
}
|
||||
|
||||
transferredMemory = copyOfHandle.GetBuffers()[0].TakeHostBufferOwnership();
|
||||
|
||||
VTKM_TEST_ASSERT(copyOfHandle.GetNumberOfValues() == ARRAY_SIZE * 2,
|
||||
"Array not allocated correctly.");
|
||||
array_handle_testing::CheckArray(arrayHandle);
|
||||
|
||||
std::cout << "Try in place operation." << std::endl;
|
||||
{
|
||||
vtkm::cont::Token token;
|
||||
using ExecutionPortalType = typename vtkm::cont::ArrayHandle<T>::WritePortalType;
|
||||
|
||||
// Reset array data.
|
||||
Algorithm::Schedule(AssignTestValue<T, ExecutionPortalType>{ arrayHandle.PrepareForOutput(
|
||||
ARRAY_SIZE * 2, DeviceAdapterTag{}, token) },
|
||||
ARRAY_SIZE * 2);
|
||||
|
||||
ExecutionPortalType executionPortal =
|
||||
arrayHandle.PrepareForInPlace(DeviceAdapterTag(), token);
|
||||
|
||||
//in place can't be done through the dispatcher
|
||||
//instead we have to drop down to manually scheduling
|
||||
InplaceFunctor<T, ExecutionPortalType> functor(executionPortal);
|
||||
Algorithm::Schedule(functor, ARRAY_SIZE * 2);
|
||||
}
|
||||
typename vtkm::cont::ArrayHandle<T>::ReadPortalType controlPortal =
|
||||
arrayHandle.ReadPortal();
|
||||
for (vtkm::Id index = 0; index < ARRAY_SIZE; index++)
|
||||
{
|
||||
VTKM_TEST_ASSERT(test_equal(controlPortal.Get(index), TestValue(index, T()) + T(1)),
|
||||
"Did not get result from in place operation.");
|
||||
}
|
||||
}
|
||||
|
||||
transferredMemory.Delete(transferredMemory.Container);
|
||||
}
|
||||
};
|
||||
|
||||
struct VerifyEqualityOperators
|
||||
{
|
||||
template <typename T>
|
||||
VTKM_CONT void operator()(T) const
|
||||
{
|
||||
std::cout << "Verify that shallow copied array handles compare equal:\n";
|
||||
{
|
||||
vtkm::cont::ArrayHandle<T> a1;
|
||||
vtkm::cont::ArrayHandle<T> a2 = a1; // shallow copy
|
||||
vtkm::cont::ArrayHandle<T> a3;
|
||||
VTKM_TEST_ASSERT(a1 == a2, "Shallow copied array not equal.");
|
||||
VTKM_TEST_ASSERT(!(a1 != a2), "Shallow copied array not equal.");
|
||||
VTKM_TEST_ASSERT(a1 != a3, "Distinct arrays compared equal.");
|
||||
VTKM_TEST_ASSERT(!(a1 == a3), "Distinct arrays compared equal.");
|
||||
|
||||
// Operations on a1 shouldn't affect equality
|
||||
a1.Allocate(200);
|
||||
VTKM_TEST_ASSERT(a1 == a2, "Shallow copied array not equal.");
|
||||
VTKM_TEST_ASSERT(!(a1 != a2), "Shallow copied array not equal.");
|
||||
|
||||
a1.ReadPortal();
|
||||
VTKM_TEST_ASSERT(a1 == a2, "Shallow copied array not equal.");
|
||||
VTKM_TEST_ASSERT(!(a1 != a2), "Shallow copied array not equal.");
|
||||
|
||||
vtkm::cont::Token token;
|
||||
a1.PrepareForInPlace(DeviceAdapterTag(), token);
|
||||
VTKM_TEST_ASSERT(a1 == a2, "Shallow copied array not equal.");
|
||||
VTKM_TEST_ASSERT(!(a1 != a2), "Shallow copied array not equal.");
|
||||
}
|
||||
|
||||
std::cout << "Verify that handles with different storage types are not equal.\n";
|
||||
{
|
||||
vtkm::cont::ArrayHandle<T, StorageTagBasic> a1;
|
||||
vtkm::cont::ArrayHandle<vtkm::Vec<T, 3>, StorageTagBasic> tmp;
|
||||
auto a2 = vtkm::cont::make_ArrayHandleExtractComponent(tmp, 1);
|
||||
|
||||
VTKM_TEST_ASSERT(a1 != a2, "Arrays with different storage type compared equal.");
|
||||
VTKM_TEST_ASSERT(!(a1 == a2), "Arrays with different storage type compared equal.");
|
||||
}
|
||||
|
||||
std::cout << "Verify that handles with different value types are not equal.\n";
|
||||
{
|
||||
vtkm::cont::ArrayHandle<T, StorageTagBasic> a1;
|
||||
vtkm::cont::ArrayHandle<typename OtherType<T>::Type, StorageTagBasic> a2;
|
||||
|
||||
VTKM_TEST_ASSERT(a1 != a2, "Arrays with different value type compared equal.");
|
||||
VTKM_TEST_ASSERT(!(a1 == a2), "Arrays with different value type compared equal.");
|
||||
}
|
||||
|
||||
std::cout << "Verify that handles with different storage and value types are not equal.\n";
|
||||
{
|
||||
vtkm::cont::ArrayHandle<T, StorageTagBasic> a1;
|
||||
vtkm::cont::ArrayHandle<vtkm::Vec<typename OtherType<T>::Type, 3>, StorageTagBasic> tmp;
|
||||
auto a2 = vtkm::cont::make_ArrayHandleExtractComponent(tmp, 1);
|
||||
|
||||
VTKM_TEST_ASSERT(a1 != a2, "Arrays with different storage and value type compared equal.");
|
||||
VTKM_TEST_ASSERT(!(a1 == a2),
|
||||
"Arrays with different storage and value type compared equal.");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
struct VerifyFill
|
||||
{
|
||||
template <typename T>
|
||||
VTKM_CONT void operator()(T) const
|
||||
{
|
||||
std::cout << "Initialize values of array." << std::endl;
|
||||
const T testValue1 = TestValue(13, T{});
|
||||
vtkm::cont::ArrayHandle<T> array;
|
||||
array.AllocateAndFill(ARRAY_SIZE, testValue1);
|
||||
{
|
||||
auto portal = array.ReadPortal();
|
||||
for (vtkm::Id index = 0; index < ARRAY_SIZE; ++index)
|
||||
{
|
||||
VTKM_TEST_ASSERT(portal.Get(index) == testValue1);
|
||||
}
|
||||
}
|
||||
|
||||
std::cout << "Grow array with new values." << std::endl;
|
||||
const T testValue2 = TestValue(42, T{});
|
||||
array.AllocateAndFill(ARRAY_SIZE * 2, testValue2, vtkm::CopyFlag::On);
|
||||
{
|
||||
auto portal = array.ReadPortal();
|
||||
for (vtkm::Id index = 0; index < ARRAY_SIZE; ++index)
|
||||
{
|
||||
VTKM_TEST_ASSERT(portal.Get(index) == testValue1);
|
||||
}
|
||||
for (vtkm::Id index = ARRAY_SIZE; index < ARRAY_SIZE * 2; ++index)
|
||||
{
|
||||
VTKM_TEST_ASSERT(portal.Get(index) == testValue2);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
struct TryArrayHandleType
|
||||
{
|
||||
void operator()() const
|
||||
{
|
||||
vtkm::testing::Testing::TryTypes(VerifyEmptyArrays{});
|
||||
vtkm::testing::Testing::TryTypes(VerifyUserOwnedMemory{});
|
||||
vtkm::testing::Testing::TryTypes(VerifyUserTransferredMemory{});
|
||||
vtkm::testing::Testing::TryTypes(VerifyVectorMovedMemory{});
|
||||
vtkm::testing::Testing::TryTypes(VerifyInitializerList{});
|
||||
vtkm::testing::Testing::TryTypes(VerifyVTKMAllocatedHandle{});
|
||||
vtkm::testing::Testing::TryTypes(VerifyVTKMTransferredOwnership{});
|
||||
vtkm::testing::Testing::TryTypes(VerifyEqualityOperators{});
|
||||
vtkm::testing::Testing::TryTypes(VerifyFill{});
|
||||
}
|
||||
};
|
||||
|
||||
public:
|
||||
static VTKM_CONT int Run(int argc, char* argv[])
|
||||
{
|
||||
vtkm::cont::GetRuntimeDeviceTracker().ForceDevice(DeviceAdapterTag());
|
||||
return vtkm::cont::testing::Testing::Run(TryArrayHandleType(), argc, argv);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
} // namespace vtkm::cont::testing
|
||||
|
||||
#endif //vtk_m_cont_testing_TestingArrayHandles_h
|
@ -1,714 +0,0 @@
|
||||
//============================================================================
|
||||
// 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.
|
||||
//============================================================================
|
||||
#ifndef vtk_m_cont_testing_TestingBitFields_h
|
||||
#define vtk_m_cont_testing_TestingBitFields_h
|
||||
|
||||
#include <vtkm/cont/ArrayHandleBitField.h>
|
||||
#include <vtkm/cont/ArrayHandleCounting.h>
|
||||
#include <vtkm/cont/BitField.h>
|
||||
#include <vtkm/cont/DeviceAdapterAlgorithm.h>
|
||||
#include <vtkm/cont/Invoker.h>
|
||||
#include <vtkm/cont/RuntimeDeviceTracker.h>
|
||||
|
||||
#include <vtkm/worklet/WorkletMapField.h>
|
||||
|
||||
#include <vtkm/cont/testing/Testing.h>
|
||||
|
||||
#include <vtkm/exec/FunctorBase.h>
|
||||
|
||||
#include <cstdio>
|
||||
|
||||
#define DEVICE_ASSERT_MSG(cond, message) \
|
||||
do \
|
||||
{ \
|
||||
if (!(cond)) \
|
||||
{ \
|
||||
printf("Testing assert failed at %s:%d\n\t- Condition: %s\n\t- Subtest: %s\n", \
|
||||
__FILE__, \
|
||||
__LINE__, \
|
||||
#cond, \
|
||||
message); \
|
||||
return false; \
|
||||
} \
|
||||
} while (false)
|
||||
|
||||
#define DEVICE_ASSERT(cond) \
|
||||
do \
|
||||
{ \
|
||||
if (!(cond)) \
|
||||
{ \
|
||||
printf("Testing assert failed at %s:%d\n\t- Condition: %s\n", __FILE__, __LINE__, #cond); \
|
||||
return false; \
|
||||
} \
|
||||
} while (false)
|
||||
|
||||
// Test with some trailing bits in partial last word:
|
||||
#define NUM_BITS \
|
||||
vtkm::Id { 7681 }
|
||||
|
||||
using vtkm::cont::BitField;
|
||||
|
||||
namespace vtkm
|
||||
{
|
||||
namespace cont
|
||||
{
|
||||
namespace testing
|
||||
{
|
||||
|
||||
// Takes an ArrayHandleBitField as the boolean condition field
|
||||
class ConditionalMergeWorklet : public vtkm::worklet::WorkletMapField
|
||||
{
|
||||
public:
|
||||
using ControlSignature = void(FieldIn cond, FieldIn trueVals, FieldIn falseVals, FieldOut result);
|
||||
using ExecutionSignature = _4(_1, _2, _3);
|
||||
|
||||
template <typename T>
|
||||
VTKM_EXEC T operator()(bool cond, const T& trueVal, const T& falseVal) const
|
||||
{
|
||||
return cond ? trueVal : falseVal;
|
||||
}
|
||||
};
|
||||
|
||||
// Takes a BitFieldInOut as the condition information, and reverses
|
||||
// the bits in place after performing the merge.
|
||||
class ConditionalMergeWorklet2 : public vtkm::worklet::WorkletMapField
|
||||
{
|
||||
public:
|
||||
using ControlSignature = void(BitFieldInOut bits,
|
||||
FieldIn trueVals,
|
||||
FieldIn falseVal,
|
||||
FieldOut result);
|
||||
using ExecutionSignature = _4(InputIndex, _1, _2, _3);
|
||||
using InputDomain = _2;
|
||||
|
||||
template <typename BitPortal, typename T>
|
||||
VTKM_EXEC T
|
||||
operator()(const vtkm::Id i, BitPortal& bits, const T& trueVal, const T& falseVal) const
|
||||
{
|
||||
return bits.XorBitAtomic(i, true) ? trueVal : falseVal;
|
||||
}
|
||||
};
|
||||
|
||||
/// This class has a single static member, Run, that runs all tests with the
|
||||
/// given DeviceAdapter.
|
||||
template <class DeviceAdapterTag>
|
||||
struct TestingBitField
|
||||
{
|
||||
using Algo = vtkm::cont::DeviceAdapterAlgorithm<DeviceAdapterTag>;
|
||||
using Traits = vtkm::cont::detail::BitFieldTraits;
|
||||
using WordTypes = vtkm::AtomicTypesSupported;
|
||||
|
||||
VTKM_EXEC_CONT
|
||||
static bool RandomBitFromIndex(vtkm::Id idx) noexcept
|
||||
{
|
||||
// Some random operations that will give a pseudorandom stream of bits:
|
||||
auto m = idx + (idx * 2) - (idx / 3) + (idx * 5 / 7) - (idx * 11 / 13);
|
||||
return (m % 2) == 1;
|
||||
}
|
||||
|
||||
template <typename WordType>
|
||||
VTKM_EXEC_CONT static WordType RandomWordFromIndex(vtkm::Id idx) noexcept
|
||||
{
|
||||
vtkm::UInt64 m = static_cast<vtkm::UInt64>(idx * (NUM_BITS - 1) + (idx + 1) * NUM_BITS);
|
||||
m ^= m << 3;
|
||||
m ^= m << 7;
|
||||
m ^= m << 15;
|
||||
m ^= m << 31;
|
||||
m = (m << 32) | (m >> 32);
|
||||
|
||||
const size_t mBits = 64;
|
||||
const size_t wordBits = sizeof(WordType) * CHAR_BIT;
|
||||
|
||||
const WordType highWord = static_cast<WordType>(m >> (mBits - wordBits));
|
||||
return highWord;
|
||||
}
|
||||
|
||||
VTKM_CONT
|
||||
static BitField RandomBitField(vtkm::Id numBits = NUM_BITS)
|
||||
{
|
||||
BitField field;
|
||||
field.Allocate(numBits);
|
||||
auto portal = field.WritePortal();
|
||||
for (vtkm::Id i = 0; i < numBits; ++i)
|
||||
{
|
||||
portal.SetBit(i, RandomBitFromIndex(i));
|
||||
}
|
||||
|
||||
return field;
|
||||
}
|
||||
|
||||
VTKM_CONT
|
||||
static void TestBlockAllocation()
|
||||
{
|
||||
BitField field;
|
||||
field.Allocate(NUM_BITS);
|
||||
|
||||
// NumBits should be rounded up to the nearest block of bytes, as defined in
|
||||
// the traits:
|
||||
const vtkm::BufferSizeType bytesInFieldData = field.GetBuffer().GetNumberOfBytes();
|
||||
|
||||
const vtkm::BufferSizeType blockSize = vtkm::cont::detail::BitFieldTraits::BlockSize;
|
||||
const vtkm::BufferSizeType numBytes = (NUM_BITS + CHAR_BIT - 1) / CHAR_BIT;
|
||||
const vtkm::BufferSizeType numBlocks = (numBytes + blockSize - 1) / blockSize;
|
||||
const vtkm::BufferSizeType expectedBytes = numBlocks * blockSize;
|
||||
|
||||
VTKM_TEST_ASSERT(bytesInFieldData == expectedBytes,
|
||||
"The BitField allocation does not round up to the nearest "
|
||||
"block. This can cause access-by-word to read/write invalid "
|
||||
"memory.");
|
||||
}
|
||||
|
||||
template <typename PortalType>
|
||||
VTKM_EXEC_CONT static bool TestBitValue(const char* operation,
|
||||
vtkm::Id i,
|
||||
PortalType portal,
|
||||
bool& bit,
|
||||
bool originalBit)
|
||||
{
|
||||
auto expected = bit;
|
||||
auto result = portal.GetBitAtomic(i);
|
||||
DEVICE_ASSERT_MSG(result == expected, operation);
|
||||
|
||||
// Reset
|
||||
bit = originalBit;
|
||||
portal.SetBitAtomic(i, bit);
|
||||
return true;
|
||||
}
|
||||
|
||||
template <typename PortalType>
|
||||
VTKM_EXEC_CONT static bool HelpTestBit(vtkm::Id i, PortalType portal)
|
||||
{
|
||||
const auto origBit = RandomBitFromIndex(i);
|
||||
auto bit = origBit;
|
||||
|
||||
const auto mod = RandomBitFromIndex(i + NUM_BITS);
|
||||
|
||||
bit = mod;
|
||||
portal.SetBitAtomic(i, mod);
|
||||
DEVICE_ASSERT(TestBitValue("SetBitAtomic", i, portal, bit, origBit));
|
||||
|
||||
bit = !bit;
|
||||
portal.NotBitAtomic(i);
|
||||
DEVICE_ASSERT(TestBitValue("NotBitAtomic", i, portal, bit, origBit));
|
||||
|
||||
bit = bit && mod;
|
||||
portal.AndBitAtomic(i, mod);
|
||||
DEVICE_ASSERT(TestBitValue("AndBitAtomic", i, portal, bit, origBit));
|
||||
|
||||
bit = bit || mod;
|
||||
portal.OrBitAtomic(i, mod);
|
||||
DEVICE_ASSERT(TestBitValue("OrBitAtomic", i, portal, bit, origBit));
|
||||
|
||||
bit = bit != mod;
|
||||
portal.XorBitAtomic(i, mod);
|
||||
DEVICE_ASSERT(TestBitValue("XorBitAtomic", i, portal, bit, origBit));
|
||||
|
||||
const auto notBit = !bit;
|
||||
// A compare-exchange that should fail
|
||||
auto expectedBit = notBit;
|
||||
bool cxResult = portal.CompareExchangeBitAtomic(i, &expectedBit, bit);
|
||||
DEVICE_ASSERT(!cxResult);
|
||||
DEVICE_ASSERT(expectedBit != notBit);
|
||||
DEVICE_ASSERT(portal.GetBit(i) == expectedBit);
|
||||
DEVICE_ASSERT(portal.GetBit(i) == bit);
|
||||
|
||||
// A compare-exchange that should succeed.
|
||||
expectedBit = bit;
|
||||
cxResult = portal.CompareExchangeBitAtomic(i, &expectedBit, notBit);
|
||||
DEVICE_ASSERT(cxResult);
|
||||
DEVICE_ASSERT(expectedBit == bit);
|
||||
DEVICE_ASSERT(portal.GetBit(i) == notBit);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
template <typename WordType, typename PortalType>
|
||||
VTKM_EXEC_CONT static bool TestWordValue(const char* operation,
|
||||
vtkm::Id i,
|
||||
const PortalType& portal,
|
||||
WordType& word,
|
||||
WordType originalWord)
|
||||
{
|
||||
auto expected = word;
|
||||
auto result = portal.template GetWordAtomic<WordType>(i);
|
||||
DEVICE_ASSERT_MSG(result == expected, operation);
|
||||
|
||||
// Reset
|
||||
word = originalWord;
|
||||
portal.SetWordAtomic(i, word);
|
||||
return true;
|
||||
}
|
||||
|
||||
template <typename WordType, typename PortalType>
|
||||
VTKM_EXEC_CONT static bool HelpTestWord(vtkm::Id i, PortalType portal)
|
||||
{
|
||||
const auto origWord = RandomWordFromIndex<WordType>(i);
|
||||
auto word = origWord;
|
||||
|
||||
const auto mod = RandomWordFromIndex<WordType>(i + NUM_BITS);
|
||||
|
||||
portal.SetWord(i, word);
|
||||
DEVICE_ASSERT(TestWordValue("SetWord", i, portal, word, origWord));
|
||||
|
||||
word = mod;
|
||||
portal.SetWordAtomic(i, mod);
|
||||
DEVICE_ASSERT(TestWordValue("SetWordAtomic", i, portal, word, origWord));
|
||||
|
||||
// C++ promotes e.g. uint8 to int32 when performing bitwise not. Silence
|
||||
// conversion warning and mask unimportant bits:
|
||||
word = static_cast<WordType>(~word);
|
||||
portal.template NotWordAtomic<WordType>(i);
|
||||
DEVICE_ASSERT(TestWordValue("NotWordAtomic", i, portal, word, origWord));
|
||||
|
||||
word = word & mod;
|
||||
portal.AndWordAtomic(i, mod);
|
||||
DEVICE_ASSERT(TestWordValue("AndWordAtomic", i, portal, word, origWord));
|
||||
|
||||
word = word | mod;
|
||||
portal.OrWordAtomic(i, mod);
|
||||
DEVICE_ASSERT(TestWordValue("OrWordAtomic", i, portal, word, origWord));
|
||||
|
||||
word = word ^ mod;
|
||||
portal.XorWordAtomic(i, mod);
|
||||
DEVICE_ASSERT(TestWordValue("XorWordAtomic", i, portal, word, origWord));
|
||||
|
||||
// Compare-exchange that should fail
|
||||
const WordType notWord = static_cast<WordType>(~word);
|
||||
WordType expectedWord = notWord;
|
||||
bool cxResult = portal.CompareExchangeWordAtomic(i, &expectedWord, word);
|
||||
DEVICE_ASSERT(!cxResult);
|
||||
DEVICE_ASSERT(expectedWord != notWord);
|
||||
DEVICE_ASSERT(portal.template GetWord<WordType>(i) == expectedWord);
|
||||
DEVICE_ASSERT(portal.template GetWord<WordType>(i) == word);
|
||||
|
||||
// Compare-exchange that should succeed
|
||||
expectedWord = word;
|
||||
cxResult = portal.CompareExchangeWordAtomic(i, &expectedWord, notWord);
|
||||
DEVICE_ASSERT(cxResult);
|
||||
DEVICE_ASSERT(expectedWord == word);
|
||||
DEVICE_ASSERT(portal.template GetWord<WordType>(i) == notWord);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
template <typename PortalType>
|
||||
struct HelpTestWordOpsControl
|
||||
{
|
||||
PortalType Portal;
|
||||
|
||||
VTKM_CONT
|
||||
HelpTestWordOpsControl(PortalType portal)
|
||||
: Portal(portal)
|
||||
{
|
||||
}
|
||||
|
||||
template <typename WordType>
|
||||
VTKM_CONT void operator()(WordType)
|
||||
{
|
||||
const auto numWords = this->Portal.template GetNumberOfWords<WordType>();
|
||||
for (vtkm::Id i = 0; i < numWords; ++i)
|
||||
{
|
||||
VTKM_TEST_ASSERT(HelpTestWord<WordType>(i, this->Portal));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Portal>
|
||||
VTKM_CONT static void HelpTestPortalsControl(Portal portal)
|
||||
{
|
||||
const auto numWords8 = (NUM_BITS + 7) / 8;
|
||||
const auto numWords16 = (NUM_BITS + 15) / 16;
|
||||
const auto numWords32 = (NUM_BITS + 31) / 32;
|
||||
const auto numWords64 = (NUM_BITS + 63) / 64;
|
||||
|
||||
VTKM_TEST_ASSERT(portal.GetNumberOfBits() == NUM_BITS);
|
||||
VTKM_TEST_ASSERT(portal.template GetNumberOfWords<vtkm::UInt8>() == numWords8);
|
||||
VTKM_TEST_ASSERT(portal.template GetNumberOfWords<vtkm::UInt16>() == numWords16);
|
||||
VTKM_TEST_ASSERT(portal.template GetNumberOfWords<vtkm::UInt32>() == numWords32);
|
||||
VTKM_TEST_ASSERT(portal.template GetNumberOfWords<vtkm::UInt64>() == numWords64);
|
||||
|
||||
for (vtkm::Id i = 0; i < NUM_BITS; ++i)
|
||||
{
|
||||
HelpTestBit(i, portal);
|
||||
}
|
||||
|
||||
HelpTestWordOpsControl<Portal> test(portal);
|
||||
vtkm::ListForEach(test, vtkm::AtomicTypesSupported{});
|
||||
}
|
||||
|
||||
VTKM_CONT
|
||||
static void TestControlPortals()
|
||||
{
|
||||
auto field = RandomBitField();
|
||||
|
||||
HelpTestPortalsControl(field.WritePortal());
|
||||
}
|
||||
|
||||
template <typename Portal>
|
||||
VTKM_EXEC_CONT static bool HelpTestPortalSanityExecution(Portal portal)
|
||||
{
|
||||
const auto numWords8 = (NUM_BITS + 7) / 8;
|
||||
const auto numWords16 = (NUM_BITS + 15) / 16;
|
||||
const auto numWords32 = (NUM_BITS + 31) / 32;
|
||||
const auto numWords64 = (NUM_BITS + 63) / 64;
|
||||
|
||||
DEVICE_ASSERT(portal.GetNumberOfBits() == NUM_BITS);
|
||||
DEVICE_ASSERT(portal.template GetNumberOfWords<vtkm::UInt8>() == numWords8);
|
||||
DEVICE_ASSERT(portal.template GetNumberOfWords<vtkm::UInt16>() == numWords16);
|
||||
DEVICE_ASSERT(portal.template GetNumberOfWords<vtkm::UInt32>() == numWords32);
|
||||
DEVICE_ASSERT(portal.template GetNumberOfWords<vtkm::UInt64>() == numWords64);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
template <typename WordType, typename PortalType>
|
||||
struct HelpTestPortalsExecutionWordsFunctor : vtkm::exec::FunctorBase
|
||||
{
|
||||
PortalType Portal;
|
||||
|
||||
HelpTestPortalsExecutionWordsFunctor(PortalType portal)
|
||||
: Portal(portal)
|
||||
{
|
||||
}
|
||||
|
||||
VTKM_EXEC_CONT
|
||||
void operator()(vtkm::Id i) const
|
||||
{
|
||||
if (i == 0)
|
||||
{
|
||||
if (!HelpTestPortalSanityExecution(this->Portal))
|
||||
{
|
||||
this->RaiseError("Testing Portal sanity failed.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (!HelpTestWord<WordType>(i, this->Portal))
|
||||
{
|
||||
this->RaiseError("Testing word operations failed.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
template <typename PortalType>
|
||||
struct HelpTestPortalsExecutionBitsFunctor : vtkm::exec::FunctorBase
|
||||
{
|
||||
PortalType Portal;
|
||||
|
||||
HelpTestPortalsExecutionBitsFunctor(PortalType portal)
|
||||
: Portal(portal)
|
||||
{
|
||||
}
|
||||
|
||||
VTKM_EXEC_CONT
|
||||
void operator()(vtkm::Id i) const
|
||||
{
|
||||
if (!HelpTestBit(i, this->Portal))
|
||||
{
|
||||
this->RaiseError("Testing bit operations failed.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
template <typename PortalType>
|
||||
struct HelpTestWordOpsExecution
|
||||
{
|
||||
PortalType Portal;
|
||||
|
||||
VTKM_CONT
|
||||
HelpTestWordOpsExecution(PortalType portal)
|
||||
: Portal(portal)
|
||||
{
|
||||
}
|
||||
|
||||
template <typename WordType>
|
||||
VTKM_CONT void operator()(WordType)
|
||||
{
|
||||
const auto numWords = this->Portal.template GetNumberOfWords<WordType>();
|
||||
|
||||
using WordFunctor = HelpTestPortalsExecutionWordsFunctor<WordType, PortalType>;
|
||||
WordFunctor test{ this->Portal };
|
||||
Algo::Schedule(test, numWords);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Portal>
|
||||
VTKM_CONT static void HelpTestPortalsExecution(Portal portal)
|
||||
{
|
||||
HelpTestPortalsExecutionBitsFunctor<Portal> bitTest{ portal };
|
||||
Algo::Schedule(bitTest, portal.GetNumberOfBits());
|
||||
|
||||
|
||||
HelpTestWordOpsExecution<Portal> test(portal);
|
||||
vtkm::ListForEach(test, vtkm::AtomicTypesSupported{});
|
||||
}
|
||||
|
||||
VTKM_CONT
|
||||
static void TestExecutionPortals()
|
||||
{
|
||||
vtkm::cont::Token token;
|
||||
auto field = RandomBitField();
|
||||
auto portal = field.PrepareForInPlace(DeviceAdapterTag{}, token);
|
||||
|
||||
HelpTestPortalsExecution(portal);
|
||||
}
|
||||
|
||||
VTKM_CONT
|
||||
static void TestFinalWordMask()
|
||||
{
|
||||
auto testMask32 = [](vtkm::Id numBits, vtkm::UInt32 expectedMask) {
|
||||
vtkm::cont::BitField field;
|
||||
field.Allocate(numBits);
|
||||
auto mask = field.ReadPortal().GetFinalWordMask<vtkm::UInt32>();
|
||||
|
||||
VTKM_TEST_ASSERT(expectedMask == mask,
|
||||
"Unexpected mask for BitField size ",
|
||||
numBits,
|
||||
": Expected 0x",
|
||||
std::hex,
|
||||
expectedMask,
|
||||
" got 0x",
|
||||
mask);
|
||||
};
|
||||
|
||||
auto testMask64 = [](vtkm::Id numBits, vtkm::UInt64 expectedMask) {
|
||||
vtkm::cont::BitField field;
|
||||
field.Allocate(numBits);
|
||||
auto mask = field.ReadPortal().GetFinalWordMask<vtkm::UInt64>();
|
||||
|
||||
VTKM_TEST_ASSERT(expectedMask == mask,
|
||||
"Unexpected mask for BitField size ",
|
||||
numBits,
|
||||
": Expected 0x",
|
||||
std::hex,
|
||||
expectedMask,
|
||||
" got 0x",
|
||||
mask);
|
||||
};
|
||||
|
||||
testMask32(0, 0x00000000);
|
||||
testMask32(1, 0x00000001);
|
||||
testMask32(2, 0x00000003);
|
||||
testMask32(3, 0x00000007);
|
||||
testMask32(4, 0x0000000f);
|
||||
testMask32(5, 0x0000001f);
|
||||
testMask32(8, 0x000000ff);
|
||||
testMask32(16, 0x0000ffff);
|
||||
testMask32(24, 0x00ffffff);
|
||||
testMask32(25, 0x01ffffff);
|
||||
testMask32(31, 0x7fffffff);
|
||||
testMask32(32, 0xffffffff);
|
||||
testMask32(64, 0xffffffff);
|
||||
testMask32(128, 0xffffffff);
|
||||
testMask32(129, 0x00000001);
|
||||
|
||||
testMask64(0, 0x0000000000000000);
|
||||
testMask64(1, 0x0000000000000001);
|
||||
testMask64(2, 0x0000000000000003);
|
||||
testMask64(3, 0x0000000000000007);
|
||||
testMask64(4, 0x000000000000000f);
|
||||
testMask64(5, 0x000000000000001f);
|
||||
testMask64(8, 0x00000000000000ff);
|
||||
testMask64(16, 0x000000000000ffff);
|
||||
testMask64(24, 0x0000000000ffffff);
|
||||
testMask64(25, 0x0000000001ffffff);
|
||||
testMask64(31, 0x000000007fffffff);
|
||||
testMask64(32, 0x00000000ffffffff);
|
||||
testMask64(40, 0x000000ffffffffff);
|
||||
testMask64(48, 0x0000ffffffffffff);
|
||||
testMask64(56, 0x00ffffffffffffff);
|
||||
testMask64(64, 0xffffffffffffffff);
|
||||
testMask64(128, 0xffffffffffffffff);
|
||||
testMask64(129, 0x0000000000000001);
|
||||
}
|
||||
|
||||
VTKM_CONT static void TestFill()
|
||||
{
|
||||
vtkm::cont::BitField bitField;
|
||||
bitField.Allocate(NUM_BITS);
|
||||
|
||||
bitField.Fill(true);
|
||||
{
|
||||
auto portal = bitField.ReadPortal();
|
||||
for (vtkm::Id index = 0; index < NUM_BITS; ++index)
|
||||
{
|
||||
VTKM_TEST_ASSERT(portal.GetBit(index));
|
||||
}
|
||||
}
|
||||
|
||||
constexpr vtkm::UInt8 word8 = 0xA6;
|
||||
bitField.Fill(word8);
|
||||
{
|
||||
auto portal = bitField.ReadPortal();
|
||||
for (vtkm::Id index = 0; index < NUM_BITS; ++index)
|
||||
{
|
||||
VTKM_TEST_ASSERT(portal.GetBit(index) == ((word8 >> (index % 8)) & 0x01));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct ArrayHandleBitFieldChecker : vtkm::exec::FunctorBase
|
||||
{
|
||||
using PortalType = vtkm::cont::ArrayHandleBitField::WritePortalType;
|
||||
|
||||
PortalType Portal;
|
||||
bool InvertReference;
|
||||
|
||||
VTKM_EXEC_CONT
|
||||
ArrayHandleBitFieldChecker(PortalType portal, bool invert)
|
||||
: Portal(portal)
|
||||
, InvertReference(invert)
|
||||
{
|
||||
}
|
||||
|
||||
VTKM_EXEC
|
||||
void operator()(vtkm::Id i) const
|
||||
{
|
||||
const bool ref = this->InvertReference ? !RandomBitFromIndex(i) : RandomBitFromIndex(i);
|
||||
if (this->Portal.Get(i) != ref)
|
||||
{
|
||||
this->RaiseError("Unexpected value from ArrayHandleBitField portal.");
|
||||
return;
|
||||
}
|
||||
|
||||
// Flip the bit for the next kernel launch, which tests that the bitfield
|
||||
// is inverted.
|
||||
this->Portal.Set(i, !ref);
|
||||
}
|
||||
};
|
||||
|
||||
VTKM_CONT
|
||||
static void TestArrayHandleBitField()
|
||||
{
|
||||
auto handle = vtkm::cont::make_ArrayHandleBitField(RandomBitField());
|
||||
const vtkm::Id numBits = handle.GetNumberOfValues();
|
||||
|
||||
VTKM_TEST_ASSERT(numBits == NUM_BITS,
|
||||
"ArrayHandleBitField returned the wrong number of values. "
|
||||
"Expected: ",
|
||||
NUM_BITS,
|
||||
" got: ",
|
||||
numBits);
|
||||
|
||||
{
|
||||
vtkm::cont::Token token;
|
||||
Algo::Schedule(
|
||||
ArrayHandleBitFieldChecker{ handle.PrepareForInPlace(DeviceAdapterTag{}, token), false },
|
||||
numBits);
|
||||
Algo::Schedule(
|
||||
ArrayHandleBitFieldChecker{ handle.PrepareForInPlace(DeviceAdapterTag{}, token), true },
|
||||
numBits);
|
||||
}
|
||||
|
||||
handle.Fill(true);
|
||||
{
|
||||
auto portal = handle.ReadPortal();
|
||||
for (vtkm::Id index = 0; index < NUM_BITS; ++index)
|
||||
{
|
||||
VTKM_TEST_ASSERT(portal.Get(index));
|
||||
}
|
||||
}
|
||||
|
||||
handle.Fill(false, 24);
|
||||
handle.Fill(true, 64);
|
||||
{
|
||||
auto portal = handle.ReadPortal();
|
||||
for (vtkm::Id index = 0; index < NUM_BITS; ++index)
|
||||
{
|
||||
VTKM_TEST_ASSERT(portal.Get(index) == ((index < 24) || (index >= 64)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
VTKM_CONT
|
||||
static void TestArrayInvokeWorklet()
|
||||
{
|
||||
auto condArray = vtkm::cont::make_ArrayHandleBitField(RandomBitField());
|
||||
auto trueArray = vtkm::cont::make_ArrayHandleCounting<vtkm::Id>(20, 2, NUM_BITS);
|
||||
auto falseArray = vtkm::cont::make_ArrayHandleCounting<vtkm::Id>(13, 2, NUM_BITS);
|
||||
vtkm::cont::ArrayHandle<vtkm::Id> output;
|
||||
|
||||
vtkm::cont::Invoker invoke;
|
||||
invoke(ConditionalMergeWorklet{}, condArray, trueArray, falseArray, output);
|
||||
|
||||
auto condVals = condArray.ReadPortal();
|
||||
auto trueVals = trueArray.ReadPortal();
|
||||
auto falseVals = falseArray.ReadPortal();
|
||||
auto outVals = output.ReadPortal();
|
||||
|
||||
VTKM_TEST_ASSERT(condVals.GetNumberOfValues() == trueVals.GetNumberOfValues());
|
||||
VTKM_TEST_ASSERT(condVals.GetNumberOfValues() == falseVals.GetNumberOfValues());
|
||||
VTKM_TEST_ASSERT(condVals.GetNumberOfValues() == outVals.GetNumberOfValues());
|
||||
|
||||
for (vtkm::Id i = 0; i < condVals.GetNumberOfValues(); ++i)
|
||||
{
|
||||
VTKM_TEST_ASSERT(outVals.Get(i) == (condVals.Get(i) ? trueVals.Get(i) : falseVals.Get(i)));
|
||||
}
|
||||
}
|
||||
|
||||
VTKM_CONT
|
||||
static void TestArrayInvokeWorklet2()
|
||||
{
|
||||
auto condBits = RandomBitField();
|
||||
auto trueArray = vtkm::cont::make_ArrayHandleCounting<vtkm::Id>(20, 2, NUM_BITS);
|
||||
auto falseArray = vtkm::cont::make_ArrayHandleCounting<vtkm::Id>(13, 2, NUM_BITS);
|
||||
vtkm::cont::ArrayHandle<vtkm::Id> output;
|
||||
|
||||
vtkm::cont::Invoker invoke;
|
||||
invoke(ConditionalMergeWorklet2{}, condBits, trueArray, falseArray, output);
|
||||
|
||||
auto condVals = condBits.ReadPortal();
|
||||
auto trueVals = trueArray.ReadPortal();
|
||||
auto falseVals = falseArray.ReadPortal();
|
||||
auto outVals = output.ReadPortal();
|
||||
|
||||
VTKM_TEST_ASSERT(condVals.GetNumberOfBits() == trueVals.GetNumberOfValues());
|
||||
VTKM_TEST_ASSERT(condVals.GetNumberOfBits() == falseVals.GetNumberOfValues());
|
||||
VTKM_TEST_ASSERT(condVals.GetNumberOfBits() == outVals.GetNumberOfValues());
|
||||
|
||||
for (vtkm::Id i = 0; i < condVals.GetNumberOfBits(); ++i)
|
||||
{
|
||||
// The worklet flips the bitfield in place after choosing true/false paths
|
||||
VTKM_TEST_ASSERT(condVals.GetBit(i) == !RandomBitFromIndex(i));
|
||||
VTKM_TEST_ASSERT(outVals.Get(i) ==
|
||||
(!condVals.GetBit(i) ? trueVals.Get(i) : falseVals.Get(i)));
|
||||
}
|
||||
}
|
||||
|
||||
struct TestRunner
|
||||
{
|
||||
VTKM_CONT
|
||||
void operator()() const
|
||||
{
|
||||
TestingBitField::TestBlockAllocation();
|
||||
TestingBitField::TestControlPortals();
|
||||
TestingBitField::TestExecutionPortals();
|
||||
TestingBitField::TestFinalWordMask();
|
||||
TestingBitField::TestFill();
|
||||
TestingBitField::TestArrayHandleBitField();
|
||||
TestingBitField::TestArrayInvokeWorklet();
|
||||
TestingBitField::TestArrayInvokeWorklet2();
|
||||
}
|
||||
};
|
||||
|
||||
public:
|
||||
static VTKM_CONT int Run(int argc, char* argv[])
|
||||
{
|
||||
vtkm::cont::GetRuntimeDeviceTracker().ForceDevice(DeviceAdapterTag());
|
||||
return vtkm::cont::testing::Testing::Run(TestRunner{}, argc, argv);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
} // namespace vtkm::cont::testing
|
||||
|
||||
#endif // vtk_m_cont_testing_TestingBitFields_h
|
@ -1,207 +0,0 @@
|
||||
//============================================================================
|
||||
// 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.
|
||||
//============================================================================
|
||||
#ifndef vtk_m_cont_testing_TestingCellLocatorRectilinearGrid_h
|
||||
#define vtk_m_cont_testing_TestingCellLocatorRectilinearGrid_h
|
||||
|
||||
#include <random>
|
||||
#include <string>
|
||||
|
||||
#include <vtkm/cont/CellLocatorRectilinearGrid.h>
|
||||
#include <vtkm/cont/DataSet.h>
|
||||
#include <vtkm/cont/DataSetBuilderRectilinear.h>
|
||||
|
||||
#include <vtkm/cont/testing/Testing.h>
|
||||
|
||||
#include <vtkm/exec/CellLocatorRectilinearGrid.h>
|
||||
|
||||
#include <vtkm/worklet/DispatcherMapField.h>
|
||||
#include <vtkm/worklet/WorkletMapField.h>
|
||||
|
||||
template <typename DeviceAdapter>
|
||||
class LocatorWorklet : public vtkm::worklet::WorkletMapField
|
||||
{
|
||||
public:
|
||||
using AxisHandle = vtkm::cont::ArrayHandle<vtkm::FloatDefault>;
|
||||
using AxisPortalType = typename AxisHandle::ReadPortalType;
|
||||
using RectilinearType =
|
||||
vtkm::cont::ArrayHandleCartesianProduct<AxisHandle, AxisHandle, AxisHandle>;
|
||||
using RectilinearPortalType = typename RectilinearType::ReadPortalType;
|
||||
|
||||
LocatorWorklet(vtkm::Bounds& bounds,
|
||||
vtkm::Id3& dims,
|
||||
const RectilinearType& coords,
|
||||
vtkm::cont::Token& token)
|
||||
: Bounds(bounds)
|
||||
, Dims(dims)
|
||||
{
|
||||
RectilinearPortalType coordsPortal = coords.PrepareForInput(DeviceAdapter(), token);
|
||||
xAxis = coordsPortal.GetFirstPortal();
|
||||
yAxis = coordsPortal.GetSecondPortal();
|
||||
zAxis = coordsPortal.GetThirdPortal();
|
||||
}
|
||||
|
||||
using ControlSignature =
|
||||
void(FieldIn pointIn, ExecObject locator, FieldOut cellId, FieldOut parametric, FieldOut match);
|
||||
|
||||
using ExecutionSignature = void(_1, _2, _3, _4, _5);
|
||||
|
||||
template <typename PointType>
|
||||
VTKM_EXEC vtkm::Id CalculateCellId(const PointType& point) const
|
||||
{
|
||||
if (!Bounds.Contains(point))
|
||||
return -1;
|
||||
vtkm::Id3 logical(-1, -1, -1);
|
||||
// Linear search in the coordinates.
|
||||
vtkm::Id index;
|
||||
/*Get floor X location*/
|
||||
if (point[0] == xAxis.Get(this->Dims[0] - 1))
|
||||
logical[0] = this->Dims[0] - 1;
|
||||
else
|
||||
for (index = 0; index < this->Dims[0] - 1; index++)
|
||||
if (xAxis.Get(index) <= point[0] && point[0] < xAxis.Get(index + 1))
|
||||
{
|
||||
logical[0] = index;
|
||||
break;
|
||||
}
|
||||
/*Get floor Y location*/
|
||||
if (point[1] == yAxis.Get(this->Dims[1] - 1))
|
||||
logical[1] = this->Dims[1] - 1;
|
||||
else
|
||||
for (index = 0; index < this->Dims[1] - 1; index++)
|
||||
if (yAxis.Get(index) <= point[1] && point[1] < yAxis.Get(index + 1))
|
||||
{
|
||||
logical[1] = index;
|
||||
break;
|
||||
}
|
||||
/*Get floor Z location*/
|
||||
if (point[2] == zAxis.Get(this->Dims[2] - 1))
|
||||
logical[2] = this->Dims[2] - 1;
|
||||
else
|
||||
for (index = 0; index < this->Dims[2] - 1; index++)
|
||||
if (zAxis.Get(index) <= point[2] && point[2] < zAxis.Get(index + 1))
|
||||
{
|
||||
logical[2] = index;
|
||||
break;
|
||||
}
|
||||
if (logical[0] == -1 || logical[1] == -1 || logical[2] == -1)
|
||||
return -1;
|
||||
return logical[2] * (Dims[0] - 1) * (Dims[1] - 1) + logical[1] * (Dims[0] - 1) + logical[0];
|
||||
}
|
||||
|
||||
template <typename PointType, typename LocatorType>
|
||||
VTKM_EXEC void operator()(const PointType& pointIn,
|
||||
const LocatorType& locator,
|
||||
vtkm::Id& cellId,
|
||||
PointType& parametric,
|
||||
bool& match) const
|
||||
{
|
||||
vtkm::Id calculated = CalculateCellId(pointIn);
|
||||
vtkm::ErrorCode status = locator.FindCell(pointIn, cellId, parametric);
|
||||
if (status != vtkm::ErrorCode::Success)
|
||||
{
|
||||
this->RaiseError(vtkm::ErrorString(status));
|
||||
match = false;
|
||||
return;
|
||||
}
|
||||
match = (calculated == cellId);
|
||||
}
|
||||
|
||||
private:
|
||||
vtkm::Bounds Bounds;
|
||||
vtkm::Id3 Dims;
|
||||
AxisPortalType xAxis;
|
||||
AxisPortalType yAxis;
|
||||
AxisPortalType zAxis;
|
||||
};
|
||||
|
||||
template <typename DeviceAdapter>
|
||||
class TestingCellLocatorRectilinearGrid
|
||||
{
|
||||
public:
|
||||
using Algorithm = vtkm::cont::DeviceAdapterAlgorithm<DeviceAdapter>;
|
||||
|
||||
void TestTest() const
|
||||
{
|
||||
vtkm::cont::DataSetBuilderRectilinear dsb;
|
||||
std::vector<vtkm::Float32> X(4), Y(3), Z(5);
|
||||
X[0] = 0.0f;
|
||||
X[1] = 1.0f;
|
||||
X[2] = 3.0f;
|
||||
X[3] = 4.0f;
|
||||
Y[0] = 0.0f;
|
||||
Y[1] = 1.0f;
|
||||
Y[2] = 2.0f;
|
||||
Z[0] = 0.0f;
|
||||
Z[1] = 1.0f;
|
||||
Z[2] = 3.0f;
|
||||
Z[3] = 5.0f;
|
||||
Z[4] = 6.0f;
|
||||
vtkm::cont::DataSet dataset = dsb.Create(X, Y, Z);
|
||||
|
||||
using StructuredType = vtkm::cont::CellSetStructured<3>;
|
||||
using AxisHandle = vtkm::cont::ArrayHandle<vtkm::FloatDefault>;
|
||||
using RectilinearType =
|
||||
vtkm::cont::ArrayHandleCartesianProduct<AxisHandle, AxisHandle, AxisHandle>;
|
||||
|
||||
vtkm::cont::CoordinateSystem coords = dataset.GetCoordinateSystem();
|
||||
vtkm::cont::UnknownCellSet cellSet = dataset.GetCellSet();
|
||||
vtkm::Bounds bounds = coords.GetBounds();
|
||||
vtkm::Id3 dims =
|
||||
cellSet.AsCellSet<StructuredType>().GetSchedulingRange(vtkm::TopologyElementTagPoint());
|
||||
|
||||
// Generate some sample points.
|
||||
using PointType = vtkm::Vec3f;
|
||||
std::vector<PointType> pointsVec;
|
||||
std::default_random_engine dre;
|
||||
std::uniform_real_distribution<vtkm::Float32> xCoords(0.0f, 4.0f);
|
||||
std::uniform_real_distribution<vtkm::Float32> yCoords(0.0f, 2.0f);
|
||||
std::uniform_real_distribution<vtkm::Float32> zCoords(0.0f, 6.0f);
|
||||
for (size_t i = 0; i < 10; i++)
|
||||
{
|
||||
PointType point = vtkm::make_Vec(xCoords(dre), yCoords(dre), zCoords(dre));
|
||||
pointsVec.push_back(point);
|
||||
}
|
||||
|
||||
vtkm::cont::ArrayHandle<PointType> points =
|
||||
vtkm::cont::make_ArrayHandle(pointsVec, vtkm::CopyFlag::Off);
|
||||
|
||||
// Initialize locator
|
||||
vtkm::cont::CellLocatorRectilinearGrid locator;
|
||||
locator.SetCoordinates(coords);
|
||||
locator.SetCellSet(cellSet);
|
||||
locator.Update();
|
||||
|
||||
// Query the points using the locator.
|
||||
vtkm::cont::ArrayHandle<vtkm::Id> cellIds;
|
||||
vtkm::cont::ArrayHandle<PointType> parametric;
|
||||
vtkm::cont::ArrayHandle<bool> match;
|
||||
vtkm::cont::Token token;
|
||||
LocatorWorklet<DeviceAdapter> worklet(
|
||||
bounds, dims, coords.GetData().template AsArrayHandle<RectilinearType>(), token);
|
||||
|
||||
vtkm::worklet::DispatcherMapField<LocatorWorklet<DeviceAdapter>> dispatcher(worklet);
|
||||
dispatcher.SetDevice(DeviceAdapter());
|
||||
dispatcher.Invoke(points, locator, cellIds, parametric, match);
|
||||
|
||||
auto matchPortal = match.ReadPortal();
|
||||
for (vtkm::Id index = 0; index < match.GetNumberOfValues(); index++)
|
||||
{
|
||||
VTKM_TEST_ASSERT(matchPortal.Get(index), "Points do not match");
|
||||
}
|
||||
}
|
||||
|
||||
void operator()() const
|
||||
{
|
||||
vtkm::cont::GetRuntimeDeviceTracker().ForceDevice(DeviceAdapter());
|
||||
this->TestTest();
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
@ -1,174 +0,0 @@
|
||||
//============================================================================
|
||||
// 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.
|
||||
//============================================================================
|
||||
#ifndef vtk_m_cont_testing_TestingCellLocatorUniformGrid_h
|
||||
#define vtk_m_cont_testing_TestingCellLocatorUniformGrid_h
|
||||
|
||||
#include <random>
|
||||
#include <string>
|
||||
|
||||
#include <vtkm/cont/CellLocatorUniformGrid.h>
|
||||
#include <vtkm/cont/DataSet.h>
|
||||
|
||||
#include <vtkm/cont/testing/MakeTestDataSet.h>
|
||||
#include <vtkm/cont/testing/Testing.h>
|
||||
|
||||
#include <vtkm/exec/CellLocatorUniformGrid.h>
|
||||
|
||||
#include <vtkm/worklet/DispatcherMapField.h>
|
||||
#include <vtkm/worklet/WorkletMapField.h>
|
||||
|
||||
class LocatorWorklet : public vtkm::worklet::WorkletMapField
|
||||
{
|
||||
public:
|
||||
LocatorWorklet(vtkm::Bounds& bounds, vtkm::Id3& cellDims)
|
||||
: Bounds(bounds)
|
||||
, CellDims(cellDims)
|
||||
{
|
||||
}
|
||||
|
||||
using ControlSignature =
|
||||
void(FieldIn pointIn, ExecObject locator, FieldOut cellId, FieldOut parametric, FieldOut match);
|
||||
|
||||
using ExecutionSignature = void(_1, _2, _3, _4, _5);
|
||||
|
||||
template <typename PointType>
|
||||
VTKM_EXEC vtkm::Id CalculateCellId(const PointType& point) const
|
||||
{
|
||||
if (!Bounds.Contains(point))
|
||||
return -1;
|
||||
|
||||
vtkm::Id3 logical;
|
||||
logical[0] = (point[0] == Bounds.X.Max)
|
||||
? CellDims[0] - 1
|
||||
: static_cast<vtkm::Id>(vtkm::Floor((point[0] / Bounds.X.Length()) *
|
||||
static_cast<vtkm::FloatDefault>(CellDims[0])));
|
||||
logical[1] = (point[1] == Bounds.Y.Max)
|
||||
? CellDims[1] - 1
|
||||
: static_cast<vtkm::Id>(vtkm::Floor((point[1] / Bounds.Y.Length()) *
|
||||
static_cast<vtkm::FloatDefault>(CellDims[1])));
|
||||
logical[2] = (point[2] == Bounds.Z.Max)
|
||||
? CellDims[2] - 1
|
||||
: static_cast<vtkm::Id>(vtkm::Floor((point[2] / Bounds.Z.Length()) *
|
||||
static_cast<vtkm::FloatDefault>(CellDims[2])));
|
||||
|
||||
return logical[2] * CellDims[0] * CellDims[1] + logical[1] * CellDims[0] + logical[0];
|
||||
}
|
||||
|
||||
template <typename PointType, typename LocatorType>
|
||||
VTKM_EXEC void operator()(const PointType& pointIn,
|
||||
const LocatorType& locator,
|
||||
vtkm::Id& cellId,
|
||||
PointType& parametric,
|
||||
bool& match) const
|
||||
{
|
||||
vtkm::Id calculated = CalculateCellId(pointIn);
|
||||
vtkm::ErrorCode status = locator.FindCell(pointIn, cellId, parametric);
|
||||
if ((status != vtkm::ErrorCode::Success) && (status != vtkm::ErrorCode::CellNotFound))
|
||||
{
|
||||
this->RaiseError(vtkm::ErrorString(status));
|
||||
match = false;
|
||||
return;
|
||||
}
|
||||
match = (calculated == cellId);
|
||||
}
|
||||
|
||||
private:
|
||||
vtkm::Bounds Bounds;
|
||||
vtkm::Id3 CellDims;
|
||||
};
|
||||
|
||||
template <typename DeviceAdapter>
|
||||
class TestingCellLocatorUniformGrid
|
||||
{
|
||||
public:
|
||||
using Algorithm = vtkm::cont::DeviceAdapterAlgorithm<DeviceAdapter>;
|
||||
|
||||
void TestTest() const
|
||||
{
|
||||
vtkm::cont::DataSet dataset = vtkm::cont::testing::MakeTestDataSet().Make3DUniformDataSet1();
|
||||
vtkm::cont::CoordinateSystem coords = dataset.GetCoordinateSystem();
|
||||
vtkm::cont::UnknownCellSet cellSet = dataset.GetCellSet();
|
||||
|
||||
vtkm::Bounds bounds = coords.GetBounds();
|
||||
std::cout << "X bounds : " << bounds.X.Min << " to " << bounds.X.Max << std::endl;
|
||||
std::cout << "Y bounds : " << bounds.Y.Min << " to " << bounds.Y.Max << std::endl;
|
||||
std::cout << "Z bounds : " << bounds.Z.Min << " to " << bounds.Z.Max << std::endl;
|
||||
|
||||
using StructuredType = vtkm::cont::CellSetStructured<3>;
|
||||
vtkm::Id3 cellDims =
|
||||
cellSet.AsCellSet<StructuredType>().GetSchedulingRange(vtkm::TopologyElementTagCell());
|
||||
std::cout << "Dimensions of dataset : " << cellDims << std::endl;
|
||||
|
||||
vtkm::cont::CellLocatorUniformGrid locator;
|
||||
locator.SetCoordinates(coords);
|
||||
locator.SetCellSet(cellSet);
|
||||
|
||||
locator.Update();
|
||||
|
||||
// Generate some sample points.
|
||||
using PointType = vtkm::Vec3f;
|
||||
std::vector<PointType> pointsVec;
|
||||
std::default_random_engine dre;
|
||||
std::uniform_real_distribution<vtkm::Float32> inBounds(0.0f, 4.0f);
|
||||
for (size_t i = 0; i < 10; i++)
|
||||
{
|
||||
PointType point = vtkm::make_Vec(inBounds(dre), inBounds(dre), inBounds(dre));
|
||||
pointsVec.push_back(point);
|
||||
}
|
||||
std::uniform_real_distribution<vtkm::Float32> outBounds(4.0f, 5.0f);
|
||||
for (size_t i = 0; i < 5; i++)
|
||||
{
|
||||
PointType point = vtkm::make_Vec(outBounds(dre), outBounds(dre), outBounds(dre));
|
||||
pointsVec.push_back(point);
|
||||
}
|
||||
std::uniform_real_distribution<vtkm::Float32> outBounds2(-1.0f, 0.0f);
|
||||
for (size_t i = 0; i < 5; i++)
|
||||
{
|
||||
PointType point = vtkm::make_Vec(outBounds2(dre), outBounds2(dre), outBounds2(dre));
|
||||
pointsVec.push_back(point);
|
||||
}
|
||||
|
||||
// Add points right on the boundary.
|
||||
pointsVec.push_back(vtkm::make_Vec(0, 0, 0));
|
||||
pointsVec.push_back(vtkm::make_Vec(4, 4, 4));
|
||||
pointsVec.push_back(vtkm::make_Vec(4, 0, 0));
|
||||
pointsVec.push_back(vtkm::make_Vec(0, 4, 0));
|
||||
pointsVec.push_back(vtkm::make_Vec(0, 0, 4));
|
||||
pointsVec.push_back(vtkm::make_Vec(4, 4, 0));
|
||||
pointsVec.push_back(vtkm::make_Vec(0, 4, 4));
|
||||
pointsVec.push_back(vtkm::make_Vec(4, 0, 4));
|
||||
|
||||
vtkm::cont::ArrayHandle<PointType> points =
|
||||
vtkm::cont::make_ArrayHandle(pointsVec, vtkm::CopyFlag::Off);
|
||||
// Query the points using the locators.
|
||||
vtkm::cont::ArrayHandle<vtkm::Id> cellIds;
|
||||
vtkm::cont::ArrayHandle<PointType> parametric;
|
||||
vtkm::cont::ArrayHandle<bool> match;
|
||||
LocatorWorklet worklet(bounds, cellDims);
|
||||
vtkm::worklet::DispatcherMapField<LocatorWorklet> dispatcher(worklet);
|
||||
dispatcher.SetDevice(DeviceAdapter());
|
||||
dispatcher.Invoke(points, locator, cellIds, parametric, match);
|
||||
|
||||
auto matchPortal = match.ReadPortal();
|
||||
for (vtkm::Id index = 0; index < match.GetNumberOfValues(); index++)
|
||||
{
|
||||
VTKM_TEST_ASSERT(matchPortal.Get(index), "Points do not match");
|
||||
}
|
||||
std::cout << "Test finished successfully." << std::endl;
|
||||
}
|
||||
|
||||
void operator()() const
|
||||
{
|
||||
vtkm::cont::GetRuntimeDeviceTracker().ForceDevice(DeviceAdapter());
|
||||
this->TestTest();
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
@ -1,526 +0,0 @@
|
||||
//============================================================================
|
||||
// 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.
|
||||
//============================================================================
|
||||
#ifndef vtk_m_cont_testing_TestingColorTable_h
|
||||
#define vtk_m_cont_testing_TestingColorTable_h
|
||||
|
||||
#include <vtkm/Types.h>
|
||||
#include <vtkm/cont/ColorTable.h>
|
||||
#include <vtkm/cont/ColorTableMap.h>
|
||||
#include <vtkm/cont/ColorTableSamples.h>
|
||||
#include <vtkm/cont/testing/Testing.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
|
||||
namespace vtkm
|
||||
{
|
||||
namespace cont
|
||||
{
|
||||
namespace testing
|
||||
{
|
||||
|
||||
template <typename DeviceAdapterTag>
|
||||
class TestingColorTable
|
||||
{
|
||||
|
||||
template <vtkm::IdComponent N>
|
||||
static void CheckColors(vtkm::cont::ArrayHandle<vtkm::Vec<vtkm::UInt8, N>> result,
|
||||
const std::vector<vtkm::Vec<vtkm::UInt8, N>>& expected)
|
||||
{
|
||||
using Vec = vtkm::Vec<vtkm::UInt8, N>;
|
||||
|
||||
VTKM_TEST_ASSERT(result.GetNumberOfValues() == static_cast<vtkm::Id>(expected.size()));
|
||||
auto portal = result.ReadPortal();
|
||||
for (vtkm::Id index = 0; index < portal.GetNumberOfValues(); ++index)
|
||||
{
|
||||
Vec resultValue = portal.Get(index);
|
||||
Vec expectedValue = expected[static_cast<std::size_t>(index)];
|
||||
VTKM_TEST_ASSERT(
|
||||
resultValue == expectedValue, "Expected color ", expectedValue, " but got ", resultValue);
|
||||
}
|
||||
}
|
||||
|
||||
public:
|
||||
static void TestConstructors()
|
||||
{
|
||||
vtkm::Range inValidRange{ 1.0, 0.0 };
|
||||
vtkm::Range range{ 0.0, 1.0 };
|
||||
vtkm::Vec<float, 3> rgb1{ 0.0f, 0.0f, 0.0f };
|
||||
vtkm::Vec<float, 3> rgb2{ 1.0f, 1.0f, 1.0f };
|
||||
auto rgbspace = vtkm::ColorSpace::RGB;
|
||||
auto hsvspace = vtkm::ColorSpace::HSV;
|
||||
auto diverging = vtkm::ColorSpace::Diverging;
|
||||
|
||||
vtkm::cont::ColorTable table(rgbspace);
|
||||
VTKM_TEST_ASSERT(table.GetColorSpace() == rgbspace, "color space not saved");
|
||||
VTKM_TEST_ASSERT(table.GetRange() == inValidRange, "default range incorrect");
|
||||
|
||||
vtkm::cont::ColorTable tableRGB(range, rgb1, rgb2, hsvspace);
|
||||
VTKM_TEST_ASSERT(tableRGB.GetColorSpace() == hsvspace, "color space not saved");
|
||||
VTKM_TEST_ASSERT(tableRGB.GetRange() == range, "color range not saved");
|
||||
|
||||
vtkm::Vec<float, 4> rgba1{ 0.0f, 0.0f, 0.0f, 1.0f };
|
||||
vtkm::Vec<float, 4> rgba2{ 1.0f, 1.0f, 1.0f, 0.0f };
|
||||
vtkm::cont::ColorTable tableRGBA(range, rgba1, rgba2, diverging);
|
||||
VTKM_TEST_ASSERT(tableRGBA.GetColorSpace() == diverging, "color space not saved");
|
||||
VTKM_TEST_ASSERT(tableRGBA.GetRange() == range, "color range not saved");
|
||||
|
||||
//verify we can store a vector of tables
|
||||
std::vector<vtkm::cont::ColorTable> tables;
|
||||
tables.push_back(table);
|
||||
tables.push_back(tableRGB);
|
||||
tables.push_back(tableRGBA);
|
||||
tables.push_back(tableRGBA);
|
||||
tables.push_back(tableRGB);
|
||||
tables.push_back(table);
|
||||
}
|
||||
|
||||
static void TestLoadPresets()
|
||||
{
|
||||
vtkm::Range range{ 0.0, 1.0 };
|
||||
auto rgbspace = vtkm::ColorSpace::RGB;
|
||||
auto hsvspace = vtkm::ColorSpace::HSV;
|
||||
auto labspace = vtkm::ColorSpace::Lab;
|
||||
auto diverging = vtkm::ColorSpace::Diverging;
|
||||
|
||||
{
|
||||
vtkm::cont::ColorTable table(rgbspace);
|
||||
VTKM_TEST_ASSERT(table.LoadPreset("Cool to Warm"));
|
||||
VTKM_TEST_ASSERT(table.GetColorSpace() == diverging,
|
||||
"color space not switched when loading preset");
|
||||
VTKM_TEST_ASSERT(table.GetRange() == range, "color range not correct after loading preset");
|
||||
VTKM_TEST_ASSERT(table.GetNumberOfPoints() == 3);
|
||||
|
||||
VTKM_TEST_ASSERT(table.LoadPreset(vtkm::cont::ColorTable::Preset::CoolToWarmExtended));
|
||||
VTKM_TEST_ASSERT(table.GetColorSpace() == labspace,
|
||||
"color space not switched when loading preset");
|
||||
VTKM_TEST_ASSERT(table.GetRange() == range, "color range not correct after loading preset");
|
||||
VTKM_TEST_ASSERT(table.GetNumberOfPoints() == 35);
|
||||
|
||||
table.SetColorSpace(hsvspace);
|
||||
VTKM_TEST_ASSERT((table.LoadPreset("no table with this name") == false),
|
||||
"failed to error out on bad preset table name");
|
||||
//verify that after a failure we still have the previous preset loaded
|
||||
VTKM_TEST_ASSERT(table.GetColorSpace() == hsvspace,
|
||||
"color space not switched when loading preset");
|
||||
VTKM_TEST_ASSERT(table.GetRange() == range, "color range not correct after failing preset");
|
||||
VTKM_TEST_ASSERT(table.GetNumberOfPoints() == 35);
|
||||
}
|
||||
|
||||
|
||||
//verify that we can get the presets
|
||||
std::set<std::string> names = vtkm::cont::ColorTable::GetPresets();
|
||||
VTKM_TEST_ASSERT(names.size() == 18, "incorrect number of names in preset set");
|
||||
|
||||
VTKM_TEST_ASSERT(names.count("Inferno") == 1, "names should contain inferno");
|
||||
VTKM_TEST_ASSERT(names.count("Black-Body Radiation") == 1,
|
||||
"names should contain black-body radiation");
|
||||
VTKM_TEST_ASSERT(names.count("Viridis") == 1, "names should contain viridis");
|
||||
VTKM_TEST_ASSERT(names.count("Black - Blue - White") == 1,
|
||||
"names should contain black, blue and white");
|
||||
VTKM_TEST_ASSERT(names.count("Blue to Orange") == 1, "names should contain samsel fire");
|
||||
VTKM_TEST_ASSERT(names.count("Jet") == 1, "names should contain jet");
|
||||
|
||||
// verify that we can load in all the listed color tables
|
||||
for (auto&& name : names)
|
||||
{
|
||||
vtkm::cont::ColorTable table(name);
|
||||
VTKM_TEST_ASSERT(table.GetNumberOfPoints() > 0, "Issue loading preset ", name);
|
||||
}
|
||||
|
||||
auto presetEnum = { vtkm::cont::ColorTable::Preset::Default,
|
||||
vtkm::cont::ColorTable::Preset::CoolToWarm,
|
||||
vtkm::cont::ColorTable::Preset::CoolToWarmExtended,
|
||||
vtkm::cont::ColorTable::Preset::Viridis,
|
||||
vtkm::cont::ColorTable::Preset::Inferno,
|
||||
vtkm::cont::ColorTable::Preset::Plasma,
|
||||
vtkm::cont::ColorTable::Preset::BlackBodyRadiation,
|
||||
vtkm::cont::ColorTable::Preset::XRay,
|
||||
vtkm::cont::ColorTable::Preset::Green,
|
||||
vtkm::cont::ColorTable::Preset::BlackBlueWhite,
|
||||
vtkm::cont::ColorTable::Preset::BlueToOrange,
|
||||
vtkm::cont::ColorTable::Preset::GrayToRed,
|
||||
vtkm::cont::ColorTable::Preset::ColdAndHot,
|
||||
vtkm::cont::ColorTable::Preset::BlueGreenOrange,
|
||||
vtkm::cont::ColorTable::Preset::YellowGrayBlue,
|
||||
vtkm::cont::ColorTable::Preset::RainbowUniform,
|
||||
vtkm::cont::ColorTable::Preset::Jet,
|
||||
vtkm::cont::ColorTable::Preset::RainbowDesaturated };
|
||||
for (vtkm::cont::ColorTable::Preset preset : presetEnum)
|
||||
{
|
||||
vtkm::cont::ColorTable table(preset);
|
||||
VTKM_TEST_ASSERT(table.GetNumberOfPoints() > 0, "Issue loading preset");
|
||||
}
|
||||
}
|
||||
|
||||
static void TestClamping()
|
||||
{
|
||||
std::cout << "Test Clamping" << std::endl;
|
||||
|
||||
vtkm::Range range{ 0.0, 1.0 };
|
||||
vtkm::Vec<float, 3> rgb1{ 0.0f, 1.0f, 0.0f };
|
||||
vtkm::Vec<float, 3> rgb2{ 1.0f, 0.0f, 1.0f };
|
||||
auto rgbspace = vtkm::ColorSpace::RGB;
|
||||
|
||||
vtkm::cont::ColorTable table(range, rgb1, rgb2, rgbspace);
|
||||
VTKM_TEST_ASSERT(table.GetClamping() == true, "clamping not setup properly");
|
||||
|
||||
auto field = vtkm::cont::make_ArrayHandle({ -1, 0, 1, 2 });
|
||||
|
||||
vtkm::cont::ArrayHandle<vtkm::Vec3ui_8> colors;
|
||||
const bool ran = vtkm::cont::ColorTableMap(field, table, colors);
|
||||
VTKM_TEST_ASSERT(ran, "color table failed to execute");
|
||||
|
||||
//verify that we clamp the values to the expected range
|
||||
CheckColors(colors, { { 0, 255, 0 }, { 0, 255, 0 }, { 255, 0, 255 }, { 255, 0, 255 } });
|
||||
}
|
||||
|
||||
static void TestRangeColors()
|
||||
{
|
||||
std::cout << "Test default ranges" << std::endl;
|
||||
|
||||
vtkm::Range range{ -1.0, 2.0 };
|
||||
vtkm::Vec<float, 3> rgb1{ 0.0f, 1.0f, 0.0f };
|
||||
vtkm::Vec<float, 3> rgb2{ 1.0f, 0.0f, 1.0f };
|
||||
auto rgbspace = vtkm::ColorSpace::RGB;
|
||||
|
||||
vtkm::cont::ColorTable table(range, rgb1, rgb2, rgbspace);
|
||||
table.SetClampingOff();
|
||||
VTKM_TEST_ASSERT(table.GetClamping() == false, "clamping not setup properly");
|
||||
|
||||
auto field = vtkm::cont::make_ArrayHandle({ -2, -1, 2, 3 });
|
||||
|
||||
vtkm::cont::ArrayHandle<vtkm::Vec3ui_8> colors;
|
||||
const bool ran = vtkm::cont::ColorTableMap(field, table, colors);
|
||||
VTKM_TEST_ASSERT(ran, "color table failed to execute");
|
||||
|
||||
//verify that both the above and below range colors are used,
|
||||
//and that the default value of both is 0,0,0
|
||||
CheckColors(colors, { { 0, 0, 0 }, { 0, 255, 0 }, { 255, 0, 255 }, { 0, 0, 0 } });
|
||||
|
||||
|
||||
std::cout << "Test specified ranges" << std::endl;
|
||||
//verify that we can specify custom above and below range colors
|
||||
table.SetAboveRangeColor(vtkm::Vec<float, 3>{ 1.0f, 0.0f, 0.0f }); //red
|
||||
table.SetBelowRangeColor(vtkm::Vec<float, 3>{ 0.0f, 0.0f, 1.0f }); //green
|
||||
const bool ran2 = vtkm::cont::ColorTableMap(field, table, colors);
|
||||
VTKM_TEST_ASSERT(ran2, "color table failed to execute");
|
||||
CheckColors(colors, { { 0, 0, 255 }, { 0, 255, 0 }, { 255, 0, 255 }, { 255, 0, 0 } });
|
||||
}
|
||||
|
||||
static void TestRescaleRange()
|
||||
{
|
||||
std::cout << "Test Rescale Range" << std::endl;
|
||||
vtkm::Range range{ -100.0, 100.0 };
|
||||
|
||||
//implement a blue2yellow color table
|
||||
vtkm::Vec<float, 3> rgb1{ 0.0f, 0.0f, 1.0f };
|
||||
vtkm::Vec<float, 3> rgb2{ 1.0f, 1.0f, 0.0f };
|
||||
auto lab = vtkm::ColorSpace::Lab;
|
||||
|
||||
vtkm::cont::ColorTable table(range, rgb1, rgb2, lab);
|
||||
table.AddPoint(0.0, vtkm::Vec<float, 3>{ 0.5f, 0.5f, 0.5f });
|
||||
VTKM_TEST_ASSERT(table.GetRange() == range, "custom range not saved");
|
||||
|
||||
vtkm::cont::ColorTable newTable = table.MakeDeepCopy();
|
||||
VTKM_TEST_ASSERT(newTable.GetRange() == range, "custom range not saved");
|
||||
|
||||
vtkm::Range normalizedRange{ 0.0, 50.0 };
|
||||
newTable.RescaleToRange(normalizedRange);
|
||||
VTKM_TEST_ASSERT(table.GetRange() == range, "deep copy not working properly");
|
||||
VTKM_TEST_ASSERT(newTable.GetRange() == normalizedRange, "rescale of range failed");
|
||||
VTKM_TEST_ASSERT(newTable.GetNumberOfPoints() == 3,
|
||||
"rescaled has incorrect number of control points");
|
||||
|
||||
//Verify that the rescaled color table generates correct colors
|
||||
auto field = vtkm::cont::make_ArrayHandle({ 0, 10, 20, 30, 40, 50 });
|
||||
|
||||
vtkm::cont::ArrayHandle<vtkm::Vec3ui_8> colors;
|
||||
const bool ran = vtkm::cont::ColorTableMap(field, newTable, colors);
|
||||
VTKM_TEST_ASSERT(ran, "color table failed to execute");
|
||||
|
||||
//values confirmed with ParaView 5.4
|
||||
CheckColors(colors,
|
||||
{ { 0, 0, 255 },
|
||||
{ 105, 69, 204 },
|
||||
{ 126, 109, 153 },
|
||||
{ 156, 151, 117 },
|
||||
{ 207, 202, 87 },
|
||||
{ 255, 255, 0 } });
|
||||
}
|
||||
|
||||
static void TestAddPoints()
|
||||
{
|
||||
std::cout << "Test Add Points" << std::endl;
|
||||
|
||||
vtkm::Range range{ -20, 20.0 };
|
||||
auto rgbspace = vtkm::ColorSpace::RGB;
|
||||
|
||||
vtkm::cont::ColorTable table(rgbspace);
|
||||
table.AddPoint(-10.0, vtkm::Vec<float, 3>{ 0.0f, 1.0f, 1.0f });
|
||||
table.AddPoint(-20.0, vtkm::Vec<float, 3>{ 1.0f, 1.0f, 1.0f });
|
||||
table.AddPoint(20.0, vtkm::Vec<float, 3>{ 0.0f, 0.0f, 0.0f });
|
||||
table.AddPoint(0.0, vtkm::Vec<float, 3>{ 0.0f, 0.0f, 1.0f });
|
||||
|
||||
VTKM_TEST_ASSERT(table.GetRange() == range, "adding points to make range expand properly");
|
||||
VTKM_TEST_ASSERT(table.GetNumberOfPoints() == 4,
|
||||
"adding points caused number of control points to be wrong");
|
||||
|
||||
vtkm::cont::ArrayHandle<vtkm::Vec3ui_8> colors;
|
||||
auto field = vtkm::cont::make_ArrayHandle({ 10.0f, -5.0f, -15.0f });
|
||||
const bool ran = vtkm::cont::ColorTableMap(field, table, colors);
|
||||
VTKM_TEST_ASSERT(ran, "color table failed to execute");
|
||||
|
||||
CheckColors(colors, { { 0, 0, 128 }, { 0, 128, 255 }, { 128, 255, 255 } });
|
||||
}
|
||||
|
||||
static void TestAddSegments()
|
||||
{
|
||||
std::cout << "Test Add Segments" << std::endl;
|
||||
|
||||
vtkm::Range range{ 0.0, 50.0 };
|
||||
auto diverging = vtkm::ColorSpace::Diverging;
|
||||
|
||||
vtkm::cont::ColorTable table(vtkm::cont::ColorTable::Preset::CoolToWarm);
|
||||
VTKM_TEST_ASSERT(table.GetColorSpace() == diverging,
|
||||
"color space not switched when loading preset");
|
||||
|
||||
|
||||
//Opacity Ramp from 0 to 1
|
||||
table.AddSegmentAlpha(0.0, 0.0f, 1.0, 1.0f);
|
||||
VTKM_TEST_ASSERT(table.GetNumberOfPointsAlpha() == 2, "incorrect number of alpha points");
|
||||
|
||||
table.RescaleToRange(range);
|
||||
|
||||
//Verify that the opacity points have moved
|
||||
vtkm::Vec<double, 4> opacityData;
|
||||
table.GetPointAlpha(1, opacityData);
|
||||
VTKM_TEST_ASSERT(test_equal(opacityData[0], range.Max), "rescale to range failed on opacity");
|
||||
VTKM_TEST_ASSERT(opacityData[1] == 1.0, "rescale changed opacity values");
|
||||
VTKM_TEST_ASSERT(opacityData[2] == 0.5, "rescale modified mid/sharp of opacity");
|
||||
VTKM_TEST_ASSERT(opacityData[3] == 0.0, "rescale modified mid/sharp of opacity");
|
||||
|
||||
|
||||
vtkm::cont::ArrayHandle<vtkm::Vec4ui_8> colors;
|
||||
auto field = vtkm::cont::make_ArrayHandle({ 0, 10, 20, 30, 40, 50 });
|
||||
const bool ran = vtkm::cont::ColorTableMap(field, table, colors);
|
||||
VTKM_TEST_ASSERT(ran, "color table failed to execute");
|
||||
|
||||
//values confirmed with ParaView 5.4
|
||||
CheckColors(colors,
|
||||
{ { 59, 76, 192, 0 },
|
||||
{ 124, 159, 249, 51 },
|
||||
{ 192, 212, 245, 102 },
|
||||
{ 242, 203, 183, 153 },
|
||||
{ 238, 133, 104, 204 },
|
||||
{ 180, 4, 38, 255 } });
|
||||
}
|
||||
|
||||
static void TestRemovePoints()
|
||||
{
|
||||
std::cout << "Test Remove Points" << std::endl;
|
||||
|
||||
auto hsv = vtkm::ColorSpace::HSV;
|
||||
|
||||
vtkm::cont::ColorTable table(hsv);
|
||||
//implement Blue to Red Rainbow color table
|
||||
table.AddSegment(0,
|
||||
vtkm::Vec<float, 3>{ 0.0f, 0.0f, 1.0f },
|
||||
1., //second points color should be replaced by following segment
|
||||
vtkm::Vec<float, 3>{ 1.0f, 0.0f, 0.0f });
|
||||
|
||||
table.AddPoint(-10.0, vtkm::Vec<float, 3>{ 0.0f, 1.0f, 1.0f });
|
||||
table.AddPoint(-20.0, vtkm::Vec<float, 3>{ 1.0f, 1.0f, 1.0f });
|
||||
table.AddPoint(20.0, vtkm::Vec<float, 3>{ 1.0f, 0.0f, 0.0f });
|
||||
|
||||
VTKM_TEST_ASSERT(table.RemovePoint(-10.) == true, "failed to remove a existing point");
|
||||
VTKM_TEST_ASSERT(table.RemovePoint(-20.) == true, "failed to remove a existing point");
|
||||
VTKM_TEST_ASSERT(table.RemovePoint(20.) == true, "failed to remove a existing point");
|
||||
VTKM_TEST_ASSERT(table.RemovePoint(20.) == false, "can't remove a point that doesn't exist");
|
||||
|
||||
VTKM_TEST_ASSERT((table.GetRange() == vtkm::Range{ 0.0, 1.0 }),
|
||||
"removing points didn't update range");
|
||||
table.RescaleToRange(vtkm::Range{ 0.0, 50.0 });
|
||||
|
||||
vtkm::cont::ArrayHandle<vtkm::Vec3ui_8> colors;
|
||||
auto field = vtkm::cont::make_ArrayHandle({ 0.0f, 10.0f, 20.0f, 30.0f, 40.0f, 50.0f });
|
||||
const bool ran = vtkm::cont::ColorTableMap(field, table, colors);
|
||||
VTKM_TEST_ASSERT(ran, "color table failed to execute");
|
||||
|
||||
//values confirmed with ParaView 5.4
|
||||
CheckColors(colors,
|
||||
{ { 0, 0, 255 },
|
||||
{ 0, 204, 255 },
|
||||
{ 0, 255, 102 },
|
||||
{ 102, 255, 0 },
|
||||
{ 255, 204, 0 },
|
||||
{ 255, 0, 0 } });
|
||||
|
||||
std::cout << " Change Color Space" << std::endl;
|
||||
vtkm::cont::ArrayHandle<vtkm::Vec3ui_8> colors_rgb;
|
||||
table.SetColorSpace(vtkm::ColorSpace::RGB);
|
||||
vtkm::cont::ColorTableMap(field, table, colors_rgb);
|
||||
|
||||
CheckColors(colors_rgb,
|
||||
{ { 0, 0, 255 },
|
||||
{ 51, 0, 204 },
|
||||
{ 102, 0, 153 },
|
||||
{ 153, 0, 102 },
|
||||
{ 204, 0, 51 },
|
||||
{ 255, 0, 0 } });
|
||||
}
|
||||
|
||||
static void TestOpacityOnlyPoints()
|
||||
{
|
||||
std::cout << "Test Opacity Only Points" << std::endl;
|
||||
|
||||
auto hsv = vtkm::ColorSpace::HSV;
|
||||
|
||||
vtkm::cont::ColorTable table(hsv);
|
||||
//implement only a color table
|
||||
table.AddPointAlpha(0.0, 0.0f, 0.75f, 0.25f);
|
||||
table.AddPointAlpha(1.0, 1.0f);
|
||||
|
||||
table.AddPointAlpha(10.0, 0.5f, 0.5f, 0.0f);
|
||||
table.AddPointAlpha(-10.0, 0.0f);
|
||||
table.AddPointAlpha(-20.0, 1.0f);
|
||||
table.AddPointAlpha(20.0, 0.5f);
|
||||
|
||||
VTKM_TEST_ASSERT(table.RemovePointAlpha(10.) == true, "failed to remove a existing point");
|
||||
VTKM_TEST_ASSERT(table.RemovePointAlpha(-10.) == true, "failed to remove a existing point");
|
||||
VTKM_TEST_ASSERT(table.RemovePointAlpha(-20.) == true, "failed to remove a existing point");
|
||||
VTKM_TEST_ASSERT(table.RemovePointAlpha(20.) == true, "failed to remove a existing point");
|
||||
VTKM_TEST_ASSERT(table.RemovePointAlpha(20.) == false,
|
||||
"can't remove a point that doesn't exist");
|
||||
|
||||
VTKM_TEST_ASSERT((table.GetRange() == vtkm::Range{ 0.0, 1.0 }),
|
||||
"removing points didn't update range");
|
||||
table.RescaleToRange(vtkm::Range{ 0.0, 50.0 });
|
||||
|
||||
vtkm::cont::ArrayHandle<vtkm::Vec4ui_8> colors;
|
||||
auto field = vtkm::cont::make_ArrayHandle({ 0.0f, 10.0f, 20.0f, 30.0f, 40.0f, 50.0f });
|
||||
const bool ran = vtkm::cont::ColorTableMap(field, table, colors);
|
||||
VTKM_TEST_ASSERT(ran, "color table failed to execute");
|
||||
|
||||
//values confirmed with ParaView 5.4
|
||||
CheckColors(colors,
|
||||
{ { 0, 0, 0, 0 },
|
||||
{ 0, 0, 0, 1 },
|
||||
{ 0, 0, 0, 11 },
|
||||
{ 0, 0, 0, 52 },
|
||||
{ 0, 0, 0, 203 },
|
||||
{ 0, 0, 0, 255 } });
|
||||
}
|
||||
|
||||
static void TestWorkletTransport()
|
||||
{
|
||||
std::cout << "Test Worklet Transport" << std::endl;
|
||||
|
||||
using namespace vtkm::worklet::colorconversion;
|
||||
|
||||
vtkm::cont::ColorTable table(vtkm::cont::ColorTable::Preset::Green);
|
||||
VTKM_TEST_ASSERT((table.GetRange() == vtkm::Range{ 0.0, 1.0 }),
|
||||
"loading linear green table failed with wrong range");
|
||||
VTKM_TEST_ASSERT((table.GetNumberOfPoints() == 21),
|
||||
"loading linear green table failed with number of control points");
|
||||
|
||||
auto samples = vtkm::cont::make_ArrayHandle({ 0.0, 0.5, 1.0 });
|
||||
|
||||
vtkm::cont::ArrayHandle<vtkm::Vec4ui_8> colors;
|
||||
vtkm::cont::Invoker invoke;
|
||||
invoke(TransferFunction{}, samples, table, colors);
|
||||
|
||||
CheckColors(colors, { { 14, 28, 31, 255 }, { 21, 150, 21, 255 }, { 255, 251, 230, 255 } });
|
||||
}
|
||||
|
||||
static void TestSampling()
|
||||
{
|
||||
std::cout << "Test Sampling" << std::endl;
|
||||
|
||||
vtkm::cont::ColorTable table(vtkm::cont::ColorTable::Preset::Green);
|
||||
VTKM_TEST_ASSERT((table.GetRange() == vtkm::Range{ 0.0, 1.0 }),
|
||||
"loading linear green table failed with wrong range");
|
||||
VTKM_TEST_ASSERT((table.GetNumberOfPoints() == 21),
|
||||
"loading linear green table failed with number of control points");
|
||||
|
||||
vtkm::cont::ArrayHandle<vtkm::Vec4ui_8> colors;
|
||||
constexpr vtkm::Id nvals = 3;
|
||||
table.Sample(nvals, colors);
|
||||
|
||||
CheckColors(colors, { { 14, 28, 31, 255 }, { 21, 150, 21, 255 }, { 255, 251, 230, 255 } });
|
||||
}
|
||||
|
||||
static void TestLookupTable()
|
||||
{
|
||||
std::cout << "Test Lookup Table" << std::endl;
|
||||
|
||||
//build a color table with clamping off and verify that sampling works
|
||||
vtkm::Range range{ 0.0, 50.0 };
|
||||
vtkm::cont::ColorTable table(vtkm::cont::ColorTable::Preset::CoolToWarm);
|
||||
table.RescaleToRange(range);
|
||||
table.SetClampingOff();
|
||||
table.SetAboveRangeColor(vtkm::Vec<float, 3>{ 1.0f, 0.0f, 0.0f }); //red
|
||||
table.SetBelowRangeColor(vtkm::Vec<float, 3>{ 0.0f, 0.0f, 1.0f }); //green
|
||||
|
||||
vtkm::cont::ColorTableSamplesRGB samples;
|
||||
table.Sample(256, samples);
|
||||
VTKM_TEST_ASSERT((samples.Samples.GetNumberOfValues() == 260), "invalid sample length");
|
||||
|
||||
vtkm::cont::ArrayHandle<vtkm::Vec3ui_8> colors;
|
||||
auto field = vtkm::cont::make_ArrayHandle({ -1, 0, 10, 20, 30, 40, 50, 60 });
|
||||
const bool ran = vtkm::cont::ColorTableMap(field, samples, colors);
|
||||
VTKM_TEST_ASSERT(ran, "color table failed to execute");
|
||||
|
||||
//values confirmed with ParaView 5.4
|
||||
CheckColors(colors,
|
||||
{ { 0, 0, 255 },
|
||||
{ 59, 76, 192 },
|
||||
{ 122, 157, 248 },
|
||||
{ 191, 211, 246 },
|
||||
{ 241, 204, 184 },
|
||||
{ 238, 134, 105 },
|
||||
{ 180, 4, 38 },
|
||||
{ 255, 0, 0 } });
|
||||
}
|
||||
|
||||
struct TestAll
|
||||
{
|
||||
VTKM_CONT void operator()() const
|
||||
{
|
||||
TestConstructors();
|
||||
TestLoadPresets();
|
||||
TestClamping();
|
||||
TestRangeColors();
|
||||
|
||||
TestRescaleRange(); //uses Lab
|
||||
TestAddPoints(); //uses RGB
|
||||
TestAddSegments(); //uses Diverging && opacity
|
||||
TestRemovePoints(); //use HSV
|
||||
|
||||
TestOpacityOnlyPoints();
|
||||
|
||||
TestWorkletTransport();
|
||||
TestSampling();
|
||||
TestLookupTable();
|
||||
}
|
||||
};
|
||||
|
||||
static int Run(int argc, char* argv[])
|
||||
{
|
||||
//We need to verify the color table runs on this specific device
|
||||
//so we need to force our single device
|
||||
vtkm::cont::GetRuntimeDeviceTracker().ForceDevice(DeviceAdapterTag());
|
||||
return vtkm::cont::testing::Testing::Run(TestAll(), argc, argv);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
@ -1,164 +0,0 @@
|
||||
//============================================================================
|
||||
// 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.
|
||||
//============================================================================
|
||||
#ifndef vtk_m_cont_testing_TestingComputeRange_h
|
||||
#define vtk_m_cont_testing_TestingComputeRange_h
|
||||
|
||||
#include <vtkm/Types.h>
|
||||
#include <vtkm/cont/CoordinateSystem.h>
|
||||
#include <vtkm/cont/Field.h>
|
||||
#include <vtkm/cont/RuntimeDeviceTracker.h>
|
||||
#include <vtkm/cont/testing/Testing.h>
|
||||
|
||||
// Required for implementation of ArrayRangeCompute for virtual arrays
|
||||
#include <vtkm/cont/ArrayRangeComputeTemplate.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <random>
|
||||
|
||||
namespace vtkm
|
||||
{
|
||||
namespace cont
|
||||
{
|
||||
namespace testing
|
||||
{
|
||||
|
||||
using CustomTypeList = vtkm::List<vtkm::Vec<Int32, 3>,
|
||||
vtkm::Vec<Int64, 3>,
|
||||
vtkm::Vec<Float32, 3>,
|
||||
vtkm::Vec<Float64, 3>,
|
||||
vtkm::Vec<Int32, 9>,
|
||||
vtkm::Vec<Int64, 9>,
|
||||
vtkm::Vec<Float32, 9>,
|
||||
vtkm::Vec<Float64, 9>>;
|
||||
|
||||
template <typename DeviceAdapterTag>
|
||||
class TestingComputeRange
|
||||
{
|
||||
private:
|
||||
template <typename T>
|
||||
static void TestScalarField()
|
||||
{
|
||||
const vtkm::Id nvals = 11;
|
||||
T data[nvals] = { 1, 2, 3, 4, 5, -5, -4, -3, -2, -1, 0 };
|
||||
std::random_device rng;
|
||||
std::mt19937 urng(rng());
|
||||
std::shuffle(data, data + nvals, urng);
|
||||
auto field = vtkm::cont::make_Field(
|
||||
"TestField", vtkm::cont::Field::Association::Points, data, nvals, vtkm::CopyFlag::Off);
|
||||
|
||||
vtkm::Range result;
|
||||
field.GetRange(&result);
|
||||
|
||||
std::cout << result << std::endl;
|
||||
VTKM_TEST_ASSERT((test_equal(result.Min, -5.0) && test_equal(result.Max, 5.0)),
|
||||
"Unexpected scalar field range.");
|
||||
}
|
||||
|
||||
template <typename T, vtkm::IdComponent NumberOfComponents>
|
||||
static void TestVecField()
|
||||
{
|
||||
const vtkm::Id nvals = 11;
|
||||
T data[nvals] = { 1, 2, 3, 4, 5, -5, -4, -3, -2, -1, 0 };
|
||||
vtkm::Vec<T, NumberOfComponents> fieldData[nvals];
|
||||
std::random_device rng;
|
||||
std::mt19937 urng(rng());
|
||||
for (vtkm::IdComponent i = 0; i < NumberOfComponents; ++i)
|
||||
{
|
||||
std::shuffle(data, data + nvals, urng);
|
||||
for (vtkm::Id j = 0; j < nvals; ++j)
|
||||
{
|
||||
fieldData[j][i] = data[j];
|
||||
}
|
||||
}
|
||||
auto field = vtkm::cont::make_Field(
|
||||
"TestField", vtkm::cont::Field::Association::Points, fieldData, nvals, vtkm::CopyFlag::Off);
|
||||
|
||||
vtkm::Range result[NumberOfComponents];
|
||||
field.GetRange(result);
|
||||
|
||||
for (vtkm::IdComponent i = 0; i < NumberOfComponents; ++i)
|
||||
{
|
||||
VTKM_TEST_ASSERT((test_equal(result[i].Min, -5.0) && test_equal(result[i].Max, 5.0)),
|
||||
"Unexpected vector field range.");
|
||||
}
|
||||
}
|
||||
|
||||
static void TestUniformCoordinateField()
|
||||
{
|
||||
vtkm::cont::CoordinateSystem field("TestField",
|
||||
vtkm::Id3(10, 20, 5),
|
||||
vtkm::Vec3f(0.0f, -5.0f, 4.0f),
|
||||
vtkm::Vec3f(1.0f, 0.5f, 2.0f));
|
||||
|
||||
vtkm::Bounds result = field.GetBounds();
|
||||
|
||||
VTKM_TEST_ASSERT(test_equal(result.X.Min, 0.0), "Min x wrong.");
|
||||
VTKM_TEST_ASSERT(test_equal(result.X.Max, 9.0), "Max x wrong.");
|
||||
VTKM_TEST_ASSERT(test_equal(result.Y.Min, -5.0), "Min y wrong.");
|
||||
VTKM_TEST_ASSERT(test_equal(result.Y.Max, 4.5), "Max y wrong.");
|
||||
VTKM_TEST_ASSERT(test_equal(result.Z.Min, 4.0), "Min z wrong.");
|
||||
VTKM_TEST_ASSERT(test_equal(result.Z.Max, 12.0), "Max z wrong.");
|
||||
}
|
||||
|
||||
struct TestAll
|
||||
{
|
||||
VTKM_CONT void operator()() const
|
||||
{
|
||||
std::cout << "Testing (Int32, 1)..." << std::endl;
|
||||
TestingComputeRange::TestScalarField<vtkm::Int32>();
|
||||
std::cout << "Testing (Int64, 1)..." << std::endl;
|
||||
TestingComputeRange::TestScalarField<vtkm::Int64>();
|
||||
std::cout << "Testing (Float32, 1)..." << std::endl;
|
||||
TestingComputeRange::TestScalarField<vtkm::Float32>();
|
||||
std::cout << "Testing (Float64, 1)..." << std::endl;
|
||||
TestingComputeRange::TestScalarField<vtkm::Float64>();
|
||||
|
||||
std::cout << "Testing (Int32, 3)..." << std::endl;
|
||||
TestingComputeRange::TestVecField<vtkm::Int32, 3>();
|
||||
std::cout << "Testing (Int64, 3)..." << std::endl;
|
||||
TestingComputeRange::TestVecField<vtkm::Int64, 3>();
|
||||
std::cout << "Testing (Float32, 3)..." << std::endl;
|
||||
TestingComputeRange::TestVecField<vtkm::Float32, 3>();
|
||||
std::cout << "Testing (Float64, 3)..." << std::endl;
|
||||
TestingComputeRange::TestVecField<vtkm::Float64, 3>();
|
||||
|
||||
// TODO: These tests are temporarily disabled because the existing version of
|
||||
// Field::GetRange does not compute the ranges for vectors of size 9. However,
|
||||
// issue #575 would fix this issue. This test should be renabled when that is
|
||||
// implemented.
|
||||
#if 0
|
||||
std::cout << "Testing (Int32, 9)..." << std::endl;
|
||||
TestingComputeRange::TestVecField<vtkm::Int32, 9>();
|
||||
std::cout << "Testing (Int64, 9)..." << std::endl;
|
||||
TestingComputeRange::TestVecField<vtkm::Int64, 9>();
|
||||
std::cout << "Testing (Float32, 9)..." << std::endl;
|
||||
TestingComputeRange::TestVecField<vtkm::Float32, 9>();
|
||||
std::cout << "Testing (Float64, 9)..." << std::endl;
|
||||
TestingComputeRange::TestVecField<vtkm::Float64, 9>();
|
||||
#endif
|
||||
|
||||
std::cout << "Testing UniformPointCoords..." << std::endl;
|
||||
TestingComputeRange::TestUniformCoordinateField();
|
||||
}
|
||||
};
|
||||
|
||||
public:
|
||||
static VTKM_CONT int Run(int argc, char* argv[])
|
||||
{
|
||||
vtkm::cont::GetRuntimeDeviceTracker().ForceDevice(DeviceAdapterTag());
|
||||
return vtkm::cont::testing::Testing::Run(TestAll(), argc, argv);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
} // namespace vtkm::cont::testing
|
||||
|
||||
#endif //vtk_m_cont_testing_TestingComputeRange_h
|
@ -1,165 +0,0 @@
|
||||
//============================================================================
|
||||
// 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.
|
||||
//============================================================================
|
||||
|
||||
#ifndef vtk_m_cont_testing_TestingDataSetExplicit_h
|
||||
#define vtk_m_cont_testing_TestingDataSetExplicit_h
|
||||
|
||||
#include <vtkm/cont/DataSet.h>
|
||||
#include <vtkm/cont/DeviceAdapterAlgorithm.h>
|
||||
#include <vtkm/cont/testing/MakeTestDataSet.h>
|
||||
#include <vtkm/cont/testing/Testing.h>
|
||||
|
||||
#include <set>
|
||||
|
||||
namespace vtkm
|
||||
{
|
||||
namespace cont
|
||||
{
|
||||
namespace testing
|
||||
{
|
||||
|
||||
/// This class has a single static member, Run, that tests DataSetExplicit
|
||||
/// with the given DeviceAdapter
|
||||
///
|
||||
template <class DeviceAdapterTag>
|
||||
class TestingDataSetExplicit
|
||||
{
|
||||
private:
|
||||
template <typename T, typename Storage>
|
||||
static bool TestArrayHandle(const vtkm::cont::ArrayHandle<T, Storage>& ah,
|
||||
const T* expected,
|
||||
vtkm::Id size)
|
||||
{
|
||||
if (size != ah.GetNumberOfValues())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
auto ahPortal = ah.ReadPortal();
|
||||
for (vtkm::Id i = 0; i < size; ++i)
|
||||
{
|
||||
if (ahPortal.Get(i) != expected[i])
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static void TestDataSet_Explicit()
|
||||
{
|
||||
vtkm::cont::testing::MakeTestDataSet tds;
|
||||
vtkm::cont::DataSet ds = tds.Make3DExplicitDataSet0();
|
||||
|
||||
VTKM_TEST_ASSERT(ds.GetNumberOfFields() == 2, "Incorrect number of fields");
|
||||
|
||||
// test various field-getting methods and associations
|
||||
const vtkm::cont::Field& f1 = ds.GetField("pointvar");
|
||||
VTKM_TEST_ASSERT(f1.GetAssociation() == vtkm::cont::Field::Association::Points,
|
||||
"Association of 'pointvar' was not Association::Points");
|
||||
try
|
||||
{
|
||||
ds.GetCellField("cellvar");
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
VTKM_TEST_FAIL("Failed to get field 'cellvar' with Association::Cells.");
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
ds.GetPointField("cellvar");
|
||||
VTKM_TEST_FAIL("Failed to get expected error for association mismatch.");
|
||||
}
|
||||
catch (vtkm::cont::ErrorBadValue& error)
|
||||
{
|
||||
std::cout << "Caught expected error for association mismatch: " << std::endl
|
||||
<< " " << error.GetMessage() << std::endl;
|
||||
}
|
||||
|
||||
VTKM_TEST_ASSERT(ds.GetNumberOfCoordinateSystems() == 1,
|
||||
"Incorrect number of coordinate systems");
|
||||
|
||||
// test cell-to-point connectivity
|
||||
vtkm::cont::CellSetExplicit<> cellset;
|
||||
ds.GetCellSet().AsCellSet(cellset);
|
||||
|
||||
vtkm::Id connectivitySize = 7;
|
||||
vtkm::Id numPoints = 5;
|
||||
|
||||
vtkm::UInt8 correctShapes[] = { 1, 1, 1, 1, 1 };
|
||||
vtkm::IdComponent correctNumIndices[] = { 1, 2, 2, 1, 1 };
|
||||
vtkm::Id correctConnectivity[] = { 0, 0, 1, 0, 1, 1, 1 };
|
||||
|
||||
vtkm::cont::ArrayHandleConstant<vtkm::UInt8> shapes =
|
||||
cellset.GetShapesArray(vtkm::TopologyElementTagPoint(), vtkm::TopologyElementTagCell());
|
||||
auto numIndices =
|
||||
cellset.GetNumIndicesArray(vtkm::TopologyElementTagPoint(), vtkm::TopologyElementTagCell());
|
||||
vtkm::cont::ArrayHandle<vtkm::Id> conn =
|
||||
cellset.GetConnectivityArray(vtkm::TopologyElementTagPoint(), vtkm::TopologyElementTagCell());
|
||||
|
||||
VTKM_TEST_ASSERT(TestArrayHandle(shapes, correctShapes, numPoints), "Got incorrect shapes");
|
||||
VTKM_TEST_ASSERT(TestArrayHandle(numIndices, correctNumIndices, numPoints),
|
||||
"Got incorrect numIndices");
|
||||
|
||||
// Some device adapters have unstable sorts, which may cause the order of
|
||||
// the indices for each point to be different but still correct. Iterate
|
||||
// over all the points and check the connectivity for each one.
|
||||
VTKM_TEST_ASSERT(conn.GetNumberOfValues() == connectivitySize,
|
||||
"Connectivity array wrong size.");
|
||||
vtkm::Id connectivityIndex = 0;
|
||||
auto connPortal = conn.ReadPortal();
|
||||
for (vtkm::Id pointIndex = 0; pointIndex < numPoints; pointIndex++)
|
||||
{
|
||||
vtkm::IdComponent numIncidentCells = correctNumIndices[pointIndex];
|
||||
std::set<vtkm::Id> correctIncidentCells;
|
||||
for (vtkm::IdComponent cellIndex = 0; cellIndex < numIncidentCells; cellIndex++)
|
||||
{
|
||||
correctIncidentCells.insert(correctConnectivity[connectivityIndex + cellIndex]);
|
||||
}
|
||||
for (vtkm::IdComponent cellIndex = 0; cellIndex < numIncidentCells; cellIndex++)
|
||||
{
|
||||
vtkm::Id expectedCell = connPortal.Get(connectivityIndex + cellIndex);
|
||||
std::set<vtkm::Id>::iterator foundCell = correctIncidentCells.find(expectedCell);
|
||||
VTKM_TEST_ASSERT(foundCell != correctIncidentCells.end(),
|
||||
"An incident cell in the connectivity list is wrong or repeated.");
|
||||
correctIncidentCells.erase(foundCell);
|
||||
}
|
||||
connectivityIndex += numIncidentCells;
|
||||
}
|
||||
|
||||
//verify that GetIndices works properly
|
||||
vtkm::Id expectedPointIds[4] = { 2, 1, 3, 4 };
|
||||
vtkm::Id4 retrievedPointIds;
|
||||
cellset.GetIndices(1, retrievedPointIds);
|
||||
for (vtkm::IdComponent i = 0; i < 4; i++)
|
||||
{
|
||||
VTKM_TEST_ASSERT(retrievedPointIds[i] == expectedPointIds[i],
|
||||
"Incorrect point ID for quad cell");
|
||||
}
|
||||
}
|
||||
|
||||
struct TestAll
|
||||
{
|
||||
VTKM_CONT void operator()() const { TestingDataSetExplicit::TestDataSet_Explicit(); }
|
||||
};
|
||||
|
||||
public:
|
||||
static VTKM_CONT int Run(int argc, char* argv[])
|
||||
{
|
||||
return vtkm::cont::testing::Testing::Run(TestAll(), argc, argv);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
} // namespace vtkm::cont::testing
|
||||
|
||||
#endif // vtk_m_cont_testing_TestingDataSetExplicit_h
|
@ -1,153 +0,0 @@
|
||||
//============================================================================
|
||||
// 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.
|
||||
//============================================================================
|
||||
|
||||
#ifndef vtk_m_cont_testing_TestingDataSetSingleType_h
|
||||
#define vtk_m_cont_testing_TestingDataSetSingleType_h
|
||||
|
||||
#include <vtkm/cont/CellSetSingleType.h>
|
||||
#include <vtkm/cont/DataSet.h>
|
||||
#include <vtkm/cont/DataSetBuilderExplicit.h>
|
||||
#include <vtkm/cont/DeviceAdapterAlgorithm.h>
|
||||
#include <vtkm/cont/testing/Testing.h>
|
||||
|
||||
#include <vtkm/filter/field_conversion/worklet/CellAverage.h>
|
||||
#include <vtkm/worklet/DispatcherMapTopology.h>
|
||||
|
||||
namespace vtkm
|
||||
{
|
||||
namespace cont
|
||||
{
|
||||
namespace testing
|
||||
{
|
||||
|
||||
/// This class has a single static member, Run, that tests DataSetSingleType
|
||||
/// with the given DeviceAdapter
|
||||
///
|
||||
template <class DeviceAdapterTag>
|
||||
class TestingDataSetSingleType
|
||||
{
|
||||
private:
|
||||
template <typename T, typename Storage>
|
||||
static bool TestArrayHandle(const vtkm::cont::ArrayHandle<T, Storage>& ah,
|
||||
const T* expected,
|
||||
vtkm::Id size)
|
||||
{
|
||||
if (size != ah.GetNumberOfValues())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
auto portal = ah.ReadPortal();
|
||||
for (vtkm::Id i = 0; i < size; ++i)
|
||||
{
|
||||
if (portal.Get(i) != expected[i])
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static inline vtkm::cont::DataSet make_SingleTypeDataSet()
|
||||
{
|
||||
using CoordType = vtkm::Vec3f_32;
|
||||
std::vector<CoordType> coordinates;
|
||||
coordinates.push_back(CoordType(0, 0, 0));
|
||||
coordinates.push_back(CoordType(1, 0, 0));
|
||||
coordinates.push_back(CoordType(1, 1, 0));
|
||||
coordinates.push_back(CoordType(2, 1, 0));
|
||||
coordinates.push_back(CoordType(2, 2, 0));
|
||||
|
||||
std::vector<vtkm::Id> conn;
|
||||
// First Cell
|
||||
conn.push_back(0);
|
||||
conn.push_back(1);
|
||||
conn.push_back(2);
|
||||
// Second Cell
|
||||
conn.push_back(1);
|
||||
conn.push_back(2);
|
||||
conn.push_back(3);
|
||||
// Third Cell
|
||||
conn.push_back(2);
|
||||
conn.push_back(3);
|
||||
conn.push_back(4);
|
||||
|
||||
vtkm::cont::DataSet ds;
|
||||
vtkm::cont::DataSetBuilderExplicit builder;
|
||||
ds = builder.Create(coordinates, vtkm::CellShapeTagTriangle(), 3, conn);
|
||||
|
||||
//Set point scalar
|
||||
const int nVerts = 5;
|
||||
vtkm::Float32 vars[nVerts] = { 10.1f, 20.1f, 30.2f, 40.2f, 50.3f };
|
||||
|
||||
ds.AddPointField("pointvar", vars, nVerts);
|
||||
|
||||
return ds;
|
||||
}
|
||||
|
||||
static void TestDataSet_SingleType()
|
||||
{
|
||||
vtkm::cont::DataSet dataSet = make_SingleTypeDataSet();
|
||||
|
||||
//verify that we can get a CellSetSingleType from a dataset
|
||||
vtkm::cont::CellSetSingleType<> cellset;
|
||||
dataSet.GetCellSet().AsCellSet(cellset);
|
||||
|
||||
//verify that the point to cell connectivity types are correct
|
||||
vtkm::cont::ArrayHandleConstant<vtkm::UInt8> shapesPointToCell =
|
||||
cellset.GetShapesArray(vtkm::TopologyElementTagCell(), vtkm::TopologyElementTagPoint());
|
||||
vtkm::cont::ArrayHandle<vtkm::Id> connPointToCell =
|
||||
cellset.GetConnectivityArray(vtkm::TopologyElementTagCell(), vtkm::TopologyElementTagPoint());
|
||||
|
||||
VTKM_TEST_ASSERT(shapesPointToCell.GetNumberOfValues() == 3, "Wrong number of shapes");
|
||||
VTKM_TEST_ASSERT(connPointToCell.GetNumberOfValues() == 9, "Wrong connectivity length");
|
||||
|
||||
//verify that the cell to point connectivity types are correct
|
||||
//note the handle storage types differ compared to point to cell
|
||||
vtkm::cont::ArrayHandleConstant<vtkm::UInt8> shapesCellToPoint =
|
||||
cellset.GetShapesArray(vtkm::TopologyElementTagPoint(), vtkm::TopologyElementTagCell());
|
||||
vtkm::cont::ArrayHandle<vtkm::Id> connCellToPoint =
|
||||
cellset.GetConnectivityArray(vtkm::TopologyElementTagPoint(), vtkm::TopologyElementTagCell());
|
||||
|
||||
VTKM_TEST_ASSERT(shapesCellToPoint.GetNumberOfValues() == 5, "Wrong number of shapes");
|
||||
VTKM_TEST_ASSERT(connCellToPoint.GetNumberOfValues() == 9, "Wrong connectivity length");
|
||||
|
||||
//run a basic for-each topology algorithm on this
|
||||
vtkm::cont::ArrayHandle<vtkm::Float32> result;
|
||||
vtkm::worklet::DispatcherMapTopology<vtkm::worklet::CellAverage> dispatcher;
|
||||
dispatcher.SetDevice(DeviceAdapterTag());
|
||||
dispatcher.Invoke(cellset, dataSet.GetField("pointvar"), result);
|
||||
|
||||
vtkm::Float32 expected[3] = { 20.1333f, 30.1667f, 40.2333f };
|
||||
auto portal = result.ReadPortal();
|
||||
for (int i = 0; i < 3; ++i)
|
||||
{
|
||||
VTKM_TEST_ASSERT(test_equal(portal.Get(i), expected[i]),
|
||||
"Wrong result for CellAverage worklet on explicit single type cellset data");
|
||||
}
|
||||
}
|
||||
|
||||
struct TestAll
|
||||
{
|
||||
VTKM_CONT void operator()() const { TestingDataSetSingleType::TestDataSet_SingleType(); }
|
||||
};
|
||||
|
||||
public:
|
||||
static VTKM_CONT int Run(int argc, char* argv[])
|
||||
{
|
||||
return vtkm::cont::testing::Testing::Run(TestAll(), argc, argv);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
} // namespace vtkm::cont::testing
|
||||
|
||||
#endif // vtk_m_cont_testing_TestingDataSetSingleType_h
|
File diff suppressed because it is too large
Load Diff
@ -1,423 +0,0 @@
|
||||
//============================================================================
|
||||
// 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.
|
||||
//============================================================================
|
||||
#ifndef vtk_m_cont_testing_TestingImplicitFunction_h
|
||||
#define vtk_m_cont_testing_TestingImplicitFunction_h
|
||||
|
||||
#include <vtkm/ImplicitFunction.h>
|
||||
|
||||
#include <vtkm/cont/CoordinateSystem.h>
|
||||
#include <vtkm/cont/DeviceAdapterList.h>
|
||||
#include <vtkm/cont/DeviceAdapterTag.h>
|
||||
#include <vtkm/cont/testing/MakeTestDataSet.h>
|
||||
#include <vtkm/cont/testing/Testing.h>
|
||||
|
||||
#ifndef VTKM_NO_DEPRECATED_VIRTUAL
|
||||
#include <vtkm/cont/ImplicitFunctionHandle.h>
|
||||
#endif //!VTKM_NO_DEPRECATED_VIRTUAL
|
||||
|
||||
#include <vtkm/worklet/DispatcherMapField.h>
|
||||
#include <vtkm/worklet/WorkletMapField.h>
|
||||
|
||||
#include <array>
|
||||
|
||||
namespace vtkm
|
||||
{
|
||||
namespace cont
|
||||
{
|
||||
namespace testing
|
||||
{
|
||||
|
||||
namespace implicit_function_detail
|
||||
{
|
||||
|
||||
class EvaluateImplicitFunction : public vtkm::worklet::WorkletMapField
|
||||
{
|
||||
public:
|
||||
using ControlSignature = void(FieldIn, FieldOut, FieldOut, ExecObject);
|
||||
using ExecutionSignature = void(_1, _2, _3, _4);
|
||||
|
||||
template <typename VecType, typename ScalarType, typename FunctionType>
|
||||
VTKM_EXEC void operator()(const VecType& point,
|
||||
ScalarType& val,
|
||||
VecType& gradient,
|
||||
const FunctionType& function) const
|
||||
{
|
||||
val = function.Value(point);
|
||||
gradient = function.Gradient(point);
|
||||
}
|
||||
|
||||
#ifndef VTKM_NO_DEPRECATED_VIRTUAL
|
||||
VTKM_DEPRECATED_SUPPRESS_BEGIN
|
||||
template <typename VecType, typename ScalarType, typename FunctionType>
|
||||
VTKM_EXEC void operator()(const VecType& point,
|
||||
ScalarType& val,
|
||||
VecType& gradient,
|
||||
const FunctionType* function) const
|
||||
{
|
||||
val = function->Value(point);
|
||||
gradient = function->Gradient(point);
|
||||
}
|
||||
VTKM_DEPRECATED_SUPPRESS_END
|
||||
#endif //!VTKM_NO_DEPRECATED_VIRTUAL
|
||||
};
|
||||
|
||||
template <typename ImplicitFunctionType>
|
||||
void EvaluateOnCoordinates(vtkm::cont::CoordinateSystem points,
|
||||
const ImplicitFunctionType& function,
|
||||
vtkm::cont::ArrayHandle<vtkm::FloatDefault>& values,
|
||||
vtkm::cont::ArrayHandle<vtkm::Vec<vtkm::FloatDefault, 3>>& gradients,
|
||||
vtkm::cont::DeviceAdapterId device)
|
||||
{
|
||||
vtkm::cont::Invoker invoke{ device };
|
||||
invoke(EvaluateImplicitFunction{}, points.GetDataAsMultiplexer(), values, gradients, function);
|
||||
}
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
class TestingImplicitFunction
|
||||
{
|
||||
public:
|
||||
TestingImplicitFunction()
|
||||
: Input(vtkm::cont::testing::MakeTestDataSet().Make3DExplicitDataSet2())
|
||||
{
|
||||
}
|
||||
|
||||
template <typename DeviceAdapter>
|
||||
void Run(DeviceAdapter device)
|
||||
{
|
||||
this->TestBox(device);
|
||||
this->TestCylinder(device);
|
||||
this->TestFrustum(device);
|
||||
this->TestPlane(device);
|
||||
this->TestSphere(device);
|
||||
}
|
||||
|
||||
private:
|
||||
template <typename ImplicitFunctorType>
|
||||
void Try(ImplicitFunctorType& function,
|
||||
const std::array<vtkm::FloatDefault, 8>& expectedValues,
|
||||
const std::array<vtkm::Vec3f, 8>& expectedGradients,
|
||||
vtkm::cont::DeviceAdapterId device)
|
||||
{
|
||||
auto expectedValuesArray =
|
||||
vtkm::cont::make_ArrayHandle(expectedValues.data(), 8, vtkm::CopyFlag::Off);
|
||||
auto expectedGradientsArray =
|
||||
vtkm::cont::make_ArrayHandle(expectedGradients.data(), 8, vtkm::CopyFlag::Off);
|
||||
|
||||
{
|
||||
vtkm::cont::ArrayHandle<vtkm::FloatDefault> values;
|
||||
vtkm::cont::ArrayHandle<vtkm::Vec<vtkm::FloatDefault, 3>> gradients;
|
||||
implicit_function_detail::EvaluateOnCoordinates(
|
||||
this->Input.GetCoordinateSystem(0), function, values, gradients, device);
|
||||
|
||||
VTKM_TEST_ASSERT(test_equal_ArrayHandles(values, expectedValuesArray));
|
||||
VTKM_TEST_ASSERT(test_equal_ArrayHandles(gradients, expectedGradientsArray));
|
||||
}
|
||||
|
||||
#ifndef VTKM_NO_DEPRECATED_VIRTUAL
|
||||
VTKM_DEPRECATED_SUPPRESS_BEGIN
|
||||
{
|
||||
vtkm::cont::ImplicitFunctionHandle functionHandle(&function, false);
|
||||
vtkm::cont::ArrayHandle<vtkm::FloatDefault> values;
|
||||
vtkm::cont::ArrayHandle<vtkm::Vec<vtkm::FloatDefault, 3>> gradients;
|
||||
implicit_function_detail::EvaluateOnCoordinates(
|
||||
this->Input.GetCoordinateSystem(0), functionHandle, values, gradients, device);
|
||||
|
||||
VTKM_TEST_ASSERT(test_equal_ArrayHandles(values, expectedValuesArray));
|
||||
VTKM_TEST_ASSERT(test_equal_ArrayHandles(gradients, expectedGradientsArray));
|
||||
}
|
||||
VTKM_DEPRECATED_SUPPRESS_END
|
||||
#endif //!VTKM_NO_DEPRECATED_VIRTUAL
|
||||
|
||||
{
|
||||
vtkm::ImplicitFunctionMultiplexer<ImplicitFunctorType> functionChoose(function);
|
||||
vtkm::cont::ArrayHandle<vtkm::FloatDefault> values;
|
||||
vtkm::cont::ArrayHandle<vtkm::Vec<vtkm::FloatDefault, 3>> gradients;
|
||||
implicit_function_detail::EvaluateOnCoordinates(
|
||||
this->Input.GetCoordinateSystem(0), functionChoose, values, gradients, device);
|
||||
|
||||
VTKM_TEST_ASSERT(test_equal_ArrayHandles(values, expectedValuesArray));
|
||||
VTKM_TEST_ASSERT(test_equal_ArrayHandles(gradients, expectedGradientsArray));
|
||||
}
|
||||
|
||||
{
|
||||
vtkm::ImplicitFunctionGeneral functionChoose(function);
|
||||
vtkm::cont::ArrayHandle<vtkm::FloatDefault> values;
|
||||
vtkm::cont::ArrayHandle<vtkm::Vec<vtkm::FloatDefault, 3>> gradients;
|
||||
implicit_function_detail::EvaluateOnCoordinates(
|
||||
this->Input.GetCoordinateSystem(0), functionChoose, values, gradients, device);
|
||||
|
||||
VTKM_TEST_ASSERT(test_equal_ArrayHandles(values, expectedValuesArray));
|
||||
VTKM_TEST_ASSERT(test_equal_ArrayHandles(gradients, expectedGradientsArray));
|
||||
}
|
||||
}
|
||||
|
||||
template <typename DeviceAdapter>
|
||||
void TestBox(DeviceAdapter device)
|
||||
{
|
||||
std::cout << "Testing vtkm::Box on "
|
||||
<< vtkm::cont::DeviceAdapterTraits<DeviceAdapter>::GetName() << "\n";
|
||||
|
||||
std::cout << " default box" << std::endl;
|
||||
vtkm::Box box;
|
||||
this->Try(box,
|
||||
{ { -0.5f, 0.5f, 0.707107f, 0.5f, 0.5f, 0.707107f, 0.866025f, 0.707107f } },
|
||||
{ { vtkm::Vec3f{ -1.0f, 0.0f, 0.0f },
|
||||
vtkm::Vec3f{ 1.0f, 0.0f, 0.0f },
|
||||
vtkm::Vec3f{ 0.707107f, 0.0f, 0.707107f },
|
||||
vtkm::Vec3f{ 0.0f, 0.0f, 1.0f },
|
||||
vtkm::Vec3f{ 0.0f, 1.0f, 0.0f },
|
||||
vtkm::Vec3f{ 0.707107f, 0.707107f, 0.0f },
|
||||
vtkm::Vec3f{ 0.57735f, 0.57735f, 0.57735f },
|
||||
vtkm::Vec3f{ 0.0f, 0.707107f, 0.707107f } } },
|
||||
device);
|
||||
|
||||
std::cout << " Specified min/max box" << std::endl;
|
||||
box.SetMinPoint({ 0.0f, -0.5f, -0.5f });
|
||||
box.SetMaxPoint({ 1.5f, 1.5f, 0.5f });
|
||||
this->Try(box,
|
||||
{ { 0.0f, -0.5f, 0.5f, 0.5f, 0.0f, -0.5f, 0.5f, 0.5f } },
|
||||
{ { vtkm::Vec3f{ -1.0f, 0.0f, 0.0f },
|
||||
vtkm::Vec3f{ 1.0f, 0.0f, 0.0f },
|
||||
vtkm::Vec3f{ 0.0f, 0.0f, 1.0f },
|
||||
vtkm::Vec3f{ 0.0f, 0.0f, 1.0f },
|
||||
vtkm::Vec3f{ -1.0f, 0.0f, 0.0f },
|
||||
vtkm::Vec3f{ 1.0f, 0.0f, 0.0f },
|
||||
vtkm::Vec3f{ 0.0f, 0.0f, 1.0f },
|
||||
vtkm::Vec3f{ 0.0f, 0.0f, 1.0f } } },
|
||||
device);
|
||||
|
||||
std::cout << " Specified bounds box" << std::endl;
|
||||
box.SetBounds({ vtkm::Range(0.0, 1.5), vtkm::Range(-0.5, 1.5), vtkm::Range(-0.5, 0.5) });
|
||||
this->Try(box,
|
||||
{ { 0.0f, -0.5f, 0.5f, 0.5f, 0.0f, -0.5f, 0.5f, 0.5f } },
|
||||
{ { vtkm::Vec3f{ -1.0f, 0.0f, 0.0f },
|
||||
vtkm::Vec3f{ 1.0f, 0.0f, 0.0f },
|
||||
vtkm::Vec3f{ 0.0f, 0.0f, 1.0f },
|
||||
vtkm::Vec3f{ 0.0f, 0.0f, 1.0f },
|
||||
vtkm::Vec3f{ -1.0f, 0.0f, 0.0f },
|
||||
vtkm::Vec3f{ 1.0f, 0.0f, 0.0f },
|
||||
vtkm::Vec3f{ 0.0f, 0.0f, 1.0f },
|
||||
vtkm::Vec3f{ 0.0f, 0.0f, 1.0f } } },
|
||||
device);
|
||||
}
|
||||
|
||||
template <typename DeviceAdapter>
|
||||
void TestCylinder(DeviceAdapter device)
|
||||
{
|
||||
std::cout << "Testing vtkm::Cylinder on "
|
||||
<< vtkm::cont::DeviceAdapterTraits<DeviceAdapter>::GetName() << "\n";
|
||||
|
||||
std::cout << " Default cylinder" << std::endl;
|
||||
vtkm::Cylinder cylinder;
|
||||
this->Try(cylinder,
|
||||
{ { -0.25f, 0.75f, 1.75f, 0.75f, -0.25f, 0.75f, 1.75f, 0.75f } },
|
||||
{ { vtkm::Vec3f{ 0.0f, 0.0f, 0.0f },
|
||||
vtkm::Vec3f{ 2.0f, 0.0f, 0.0f },
|
||||
vtkm::Vec3f{ 2.0f, 0.0f, 2.0f },
|
||||
vtkm::Vec3f{ 0.0f, 0.0f, 2.0f },
|
||||
vtkm::Vec3f{ 0.0f, 0.0f, 0.0f },
|
||||
vtkm::Vec3f{ 2.0f, 0.0f, 0.0f },
|
||||
vtkm::Vec3f{ 2.0f, 0.0f, 2.0f },
|
||||
vtkm::Vec3f{ 0.0f, 0.0f, 2.0f } } },
|
||||
device);
|
||||
|
||||
std::cout << " Translated, scaled cylinder" << std::endl;
|
||||
cylinder.SetCenter({ 0.0f, 0.0f, 1.0f });
|
||||
cylinder.SetAxis({ 0.0f, 1.0f, 0.0f });
|
||||
cylinder.SetRadius(1.0f);
|
||||
this->Try(cylinder,
|
||||
{ { 0.0f, 1.0f, 0.0f, -1.0f, 0.0f, 1.0f, 0.0f, -1.0f } },
|
||||
{ { vtkm::Vec3f{ 0.0f, 0.0f, -2.0f },
|
||||
vtkm::Vec3f{ 2.0f, 0.0f, -2.0f },
|
||||
vtkm::Vec3f{ 2.0f, 0.0f, 0.0f },
|
||||
vtkm::Vec3f{ 0.0f, 0.0f, 0.0f },
|
||||
vtkm::Vec3f{ 0.0f, 0.0f, -2.0f },
|
||||
vtkm::Vec3f{ 2.0f, 0.0f, -2.0f },
|
||||
vtkm::Vec3f{ 2.0f, 0.0f, 0.0f },
|
||||
vtkm::Vec3f{ 0.0f, 0.0f, 0.0f } } },
|
||||
device);
|
||||
|
||||
std::cout << " Non-unit axis" << std::endl;
|
||||
cylinder.SetCenter({ 0.0f, 0.0f, 0.0f });
|
||||
cylinder.SetAxis({ 1.0f, 1.0f, 0.0f });
|
||||
cylinder.SetRadius(1.0f);
|
||||
this->Try(cylinder,
|
||||
{ { -1.0f, -0.5f, 0.5f, 0.0f, -0.5f, -1.0f, 0.0f, 0.5f } },
|
||||
{ { vtkm::Vec3f{ 0.0f, 0.0f, 0.0f },
|
||||
vtkm::Vec3f{ 1.0f, -1.0f, 0.0f },
|
||||
vtkm::Vec3f{ 1.0f, -1.0f, 2.0f },
|
||||
vtkm::Vec3f{ 0.0f, 0.0f, 2.0f },
|
||||
vtkm::Vec3f{ -1.0f, 1.0f, 0.0f },
|
||||
vtkm::Vec3f{ 0.0f, 0.0f, 0.0f },
|
||||
vtkm::Vec3f{ 0.0f, 0.0f, 2.0f },
|
||||
vtkm::Vec3f{ -1.0f, 1.0f, 2.0f } } },
|
||||
device);
|
||||
}
|
||||
|
||||
template <typename DeviceAdapter>
|
||||
void TestFrustum(DeviceAdapter device)
|
||||
{
|
||||
std::cout << "Testing vtkm::Frustum on "
|
||||
<< vtkm::cont::DeviceAdapterTraits<DeviceAdapter>::GetName() << "\n";
|
||||
|
||||
std::cout << " With corner points" << std::endl;
|
||||
vtkm::Vec3f cornerPoints[8] = {
|
||||
{ -0.5f, 0.0f, -0.5f }, // 0
|
||||
{ -0.5f, 0.0f, 0.5f }, // 1
|
||||
{ 0.5f, 0.0f, 0.5f }, // 2
|
||||
{ 0.5f, 0.0f, -0.5f }, // 3
|
||||
{ -0.5f, 1.0f, -0.5f }, // 4
|
||||
{ -0.5f, 1.0f, 0.5f }, // 5
|
||||
{ 1.5f, 1.0f, 0.5f }, // 6
|
||||
{ 1.5f, 1.0f, -0.5f } // 7
|
||||
};
|
||||
vtkm::Frustum frustum{ cornerPoints };
|
||||
this->Try(frustum,
|
||||
{ { 0.0f, 0.353553f, 0.5f, 0.5f, 0.0f, 0.0f, 0.5f, 0.5f } },
|
||||
{ { vtkm::Vec3f{ 0.0f, -1.0f, 0.0f },
|
||||
vtkm::Vec3f{ 0.707107f, -0.707107f, 0.0f },
|
||||
vtkm::Vec3f{ 0.0f, 0.0f, 1.0f },
|
||||
vtkm::Vec3f{ 0.0f, 0.0f, 1.0f },
|
||||
vtkm::Vec3f{ 0.0f, 1.0f, 0.0f },
|
||||
vtkm::Vec3f{ 0.0f, 1.0f, 0.0f },
|
||||
vtkm::Vec3f{ 0.0f, 0.0f, 1.0f },
|
||||
vtkm::Vec3f{ 0.0f, 0.0f, 1.0f } } },
|
||||
device);
|
||||
|
||||
std::cout << " With 6 planes" << std::endl;
|
||||
vtkm::Vec3f planePoints[6] = { { 0.0f, 0.0f, 0.0f }, { 1.0f, 1.0f, 0.0f },
|
||||
{ -0.5f, 0.0f, 0.0f }, { 0.5f, 0.0f, 0.0f },
|
||||
{ 0.0f, 0.0f, -0.5f }, { 0.0f, 0.0f, 0.5f } };
|
||||
vtkm::Vec3f planeNormals[6] = { { 0.0f, -1.0f, 0.0f }, { 0.707107f, 0.707107f, 0.0f },
|
||||
{ -1.0f, 0.0f, 0.0f }, { 0.707107f, -0.707107f, 0.0f },
|
||||
{ 0.0f, 0.0f, -1.0f }, { 0.0f, 0.0f, 1.0f } };
|
||||
frustum.SetPlanes(planePoints, planeNormals);
|
||||
this->Try(frustum,
|
||||
{ { 0.0f, 0.353553f, 0.5f, 0.5f, -0.5f, 0.0f, 0.5f, 0.5f } },
|
||||
{ { vtkm::Vec3f{ 0.0f, -1.0f, 0.0f },
|
||||
vtkm::Vec3f{ 0.707107f, -0.707107f, 0.0f },
|
||||
vtkm::Vec3f{ 0.0f, 0.0f, 1.0f },
|
||||
vtkm::Vec3f{ 0.0f, 0.0f, 1.0f },
|
||||
vtkm::Vec3f{ -1.0f, 0.0f, 0.0f },
|
||||
vtkm::Vec3f{ 0.707107f, 0.707107f, 0.0f },
|
||||
vtkm::Vec3f{ 0.0f, 0.0f, 1.0f },
|
||||
vtkm::Vec3f{ 0.0f, 0.0f, 1.0f } } },
|
||||
device);
|
||||
}
|
||||
|
||||
template <typename DeviceAdapter>
|
||||
void TestPlane(DeviceAdapter device)
|
||||
{
|
||||
std::cout << "Testing vtkm::Plane on "
|
||||
<< vtkm::cont::DeviceAdapterTraits<DeviceAdapter>::GetName() << "\n";
|
||||
|
||||
std::cout << " Default plane" << std::endl;
|
||||
vtkm::Plane plane;
|
||||
this->Try(plane,
|
||||
{ { 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f } },
|
||||
{ { vtkm::Vec3f{ 0.0f, 0.0f, 1.0f },
|
||||
vtkm::Vec3f{ 0.0f, 0.0f, 1.0f },
|
||||
vtkm::Vec3f{ 0.0f, 0.0f, 1.0f },
|
||||
vtkm::Vec3f{ 0.0f, 0.0f, 1.0f },
|
||||
vtkm::Vec3f{ 0.0f, 0.0f, 1.0f },
|
||||
vtkm::Vec3f{ 0.0f, 0.0f, 1.0f },
|
||||
vtkm::Vec3f{ 0.0f, 0.0f, 1.0f },
|
||||
vtkm::Vec3f{ 0.0f, 0.0f, 1.0f } } },
|
||||
device);
|
||||
|
||||
std::cout << " Normal of length 2" << std::endl;
|
||||
plane.SetOrigin({ 1.0f, 1.0f, 1.0f });
|
||||
plane.SetNormal({ 0.0f, 0.0f, 2.0f });
|
||||
this->Try(plane,
|
||||
{ { -2.0f, -2.0f, 0.0f, 0.0f, -2.0f, -2.0f, 0.0f, 0.0f } },
|
||||
{ { vtkm::Vec3f{ 0.0f, 0.0f, 2.0f },
|
||||
vtkm::Vec3f{ 0.0f, 0.0f, 2.0f },
|
||||
vtkm::Vec3f{ 0.0f, 0.0f, 2.0f },
|
||||
vtkm::Vec3f{ 0.0f, 0.0f, 2.0f },
|
||||
vtkm::Vec3f{ 0.0f, 0.0f, 2.0f },
|
||||
vtkm::Vec3f{ 0.0f, 0.0f, 2.0f },
|
||||
vtkm::Vec3f{ 0.0f, 0.0f, 2.0f },
|
||||
vtkm::Vec3f{ 0.0f, 0.0f, 2.0f } } },
|
||||
device);
|
||||
|
||||
std::cout << " Oblique plane" << std::endl;
|
||||
plane.SetOrigin({ 0.5f, 0.5f, 0.5f });
|
||||
plane.SetNormal({ 1.0f, 0.0f, 1.0f });
|
||||
this->Try(plane,
|
||||
{ { -1.0f, 0.0f, 1.0f, 0.0f, -1.0f, 0.0f, 1.0f, 0.0f } },
|
||||
{ { vtkm::Vec3f{ 1.0f, 0.0f, 1.0f },
|
||||
vtkm::Vec3f{ 1.0f, 0.0f, 1.0f },
|
||||
vtkm::Vec3f{ 1.0f, 0.0f, 1.0f },
|
||||
vtkm::Vec3f{ 1.0f, 0.0f, 1.0f },
|
||||
vtkm::Vec3f{ 1.0f, 0.0f, 1.0f },
|
||||
vtkm::Vec3f{ 1.0f, 0.0f, 1.0f },
|
||||
vtkm::Vec3f{ 1.0f, 0.0f, 1.0f },
|
||||
vtkm::Vec3f{ 1.0f, 0.0f, 1.0f } } },
|
||||
device);
|
||||
|
||||
std::cout << " Another oblique plane" << std::endl;
|
||||
plane.SetNormal({ -1.0f, 0.0f, -1.0f });
|
||||
this->Try(plane,
|
||||
{ { 1.0f, 0.0f, -1.0f, 0.0f, 1.0f, 0.0f, -1.0f, 0.0f } },
|
||||
{ { vtkm::Vec3f{ -1.0f, 0.0f, -1.0f },
|
||||
vtkm::Vec3f{ -1.0f, 0.0f, -1.0f },
|
||||
vtkm::Vec3f{ -1.0f, 0.0f, -1.0f },
|
||||
vtkm::Vec3f{ -1.0f, 0.0f, -1.0f },
|
||||
vtkm::Vec3f{ -1.0f, 0.0f, -1.0f },
|
||||
vtkm::Vec3f{ -1.0f, 0.0f, -1.0f },
|
||||
vtkm::Vec3f{ -1.0f, 0.0f, -1.0f },
|
||||
vtkm::Vec3f{ -1.0f, 0.0f, -1.0f } } },
|
||||
device);
|
||||
}
|
||||
|
||||
template <typename DeviceAdapter>
|
||||
void TestSphere(DeviceAdapter device)
|
||||
{
|
||||
std::cout << "Testing vtkm::Sphere on "
|
||||
<< vtkm::cont::DeviceAdapterTraits<DeviceAdapter>::GetName() << "\n";
|
||||
|
||||
std::cout << " Default sphere" << std::endl;
|
||||
vtkm::Sphere sphere;
|
||||
this->Try(sphere,
|
||||
{ { -0.25f, 0.75f, 1.75f, 0.75f, 0.75f, 1.75f, 2.75f, 1.75f } },
|
||||
{ { vtkm::Vec3f{ 0.0f, 0.0f, 0.0f },
|
||||
vtkm::Vec3f{ 2.0f, 0.0f, 0.0f },
|
||||
vtkm::Vec3f{ 2.0f, 0.0f, 2.0f },
|
||||
vtkm::Vec3f{ 0.0f, 0.0f, 2.0f },
|
||||
vtkm::Vec3f{ 0.0f, 2.0f, 0.0f },
|
||||
vtkm::Vec3f{ 2.0f, 2.0f, 0.0f },
|
||||
vtkm::Vec3f{ 2.0f, 2.0f, 2.0f },
|
||||
vtkm::Vec3f{ 0.0f, 2.0f, 2.0f } } },
|
||||
device);
|
||||
|
||||
std::cout << " Shifted and scaled sphere" << std::endl;
|
||||
sphere.SetCenter({ 1.0f, 1.0f, 1.0f });
|
||||
sphere.SetRadius(1.0f);
|
||||
this->Try(sphere,
|
||||
{ { 2.0f, 1.0f, 0.0f, 1.0f, 1.0f, 0.0f, -1.0f, 0.0f } },
|
||||
{ { vtkm::Vec3f{ -2.0f, -2.0f, -2.0f },
|
||||
vtkm::Vec3f{ 0.0f, -2.0f, -2.0f },
|
||||
vtkm::Vec3f{ 0.0f, -2.0f, 0.0f },
|
||||
vtkm::Vec3f{ -2.0f, -2.0f, 0.0f },
|
||||
vtkm::Vec3f{ -2.0f, 0.0f, -2.0f },
|
||||
vtkm::Vec3f{ 0.0f, 0.0f, -2.0f },
|
||||
vtkm::Vec3f{ 0.0f, 0.0f, 0.0f },
|
||||
vtkm::Vec3f{ -2.0f, 0.0f, 0.0f } } },
|
||||
device);
|
||||
}
|
||||
|
||||
vtkm::cont::DataSet Input;
|
||||
};
|
||||
}
|
||||
}
|
||||
} // vtmk::cont::testing
|
||||
|
||||
#endif //vtk_m_cont_testing_TestingImplicitFunction_h
|
@ -1,195 +0,0 @@
|
||||
//============================================================================
|
||||
// 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.
|
||||
//============================================================================
|
||||
|
||||
#ifndef vtk_m_cont_testing_TestingPointLocatorSparseGrid_h
|
||||
#define vtk_m_cont_testing_TestingPointLocatorSparseGrid_h
|
||||
|
||||
#include <random>
|
||||
|
||||
#include <vtkm/cont/testing/Testing.h>
|
||||
|
||||
#include <vtkm/cont/PointLocatorSparseGrid.h>
|
||||
|
||||
#include <vtkm/worklet/WorkletMapField.h>
|
||||
|
||||
////brute force method /////
|
||||
template <typename CoordiVecT, typename CoordiPortalT, typename CoordiT>
|
||||
VTKM_EXEC_CONT vtkm::Id NNSVerify3D(CoordiVecT qc, CoordiPortalT coordiPortal, CoordiT& dis2)
|
||||
{
|
||||
dis2 = std::numeric_limits<CoordiT>::max();
|
||||
vtkm::Id nnpIdx = -1;
|
||||
|
||||
for (vtkm::Int32 i = 0; i < coordiPortal.GetNumberOfValues(); i++)
|
||||
{
|
||||
CoordiT splitX = coordiPortal.Get(i)[0];
|
||||
CoordiT splitY = coordiPortal.Get(i)[1];
|
||||
CoordiT splitZ = coordiPortal.Get(i)[2];
|
||||
CoordiT _dis2 = (splitX - qc[0]) * (splitX - qc[0]) + (splitY - qc[1]) * (splitY - qc[1]) +
|
||||
(splitZ - qc[2]) * (splitZ - qc[2]);
|
||||
if (_dis2 < dis2)
|
||||
{
|
||||
dis2 = _dis2;
|
||||
nnpIdx = i;
|
||||
}
|
||||
}
|
||||
return nnpIdx;
|
||||
}
|
||||
|
||||
class NearestNeighborSearchBruteForce3DWorklet : public vtkm::worklet::WorkletMapField
|
||||
{
|
||||
public:
|
||||
using ControlSignature = void(FieldIn qcIn,
|
||||
WholeArrayIn treeCoordiIn,
|
||||
FieldOut nnIdOut,
|
||||
FieldOut nnDisOut);
|
||||
using ExecutionSignature = void(_1, _2, _3, _4);
|
||||
|
||||
VTKM_CONT
|
||||
NearestNeighborSearchBruteForce3DWorklet() {}
|
||||
|
||||
template <typename CoordiVecType, typename CoordiPortalType, typename IdType, typename CoordiType>
|
||||
VTKM_EXEC void operator()(const CoordiVecType& qc,
|
||||
const CoordiPortalType& coordiPortal,
|
||||
IdType& nnId,
|
||||
CoordiType& nnDis) const
|
||||
{
|
||||
nnDis = std::numeric_limits<CoordiType>::max();
|
||||
|
||||
nnId = NNSVerify3D(qc, coordiPortal, nnDis);
|
||||
}
|
||||
};
|
||||
|
||||
class PointLocatorSparseGridWorklet : public vtkm::worklet::WorkletMapField
|
||||
{
|
||||
public:
|
||||
typedef void ControlSignature(FieldIn qcIn,
|
||||
ExecObject locator,
|
||||
FieldOut nnIdOut,
|
||||
FieldOut nnDistOut);
|
||||
|
||||
typedef void ExecutionSignature(_1, _2, _3, _4);
|
||||
|
||||
VTKM_CONT
|
||||
PointLocatorSparseGridWorklet() {}
|
||||
|
||||
template <typename CoordiVecType, typename Locator>
|
||||
VTKM_EXEC void operator()(const CoordiVecType& qc,
|
||||
const Locator& locator,
|
||||
vtkm::Id& nnIdOut,
|
||||
vtkm::FloatDefault& nnDis) const
|
||||
{
|
||||
locator.FindNearestNeighbor(qc, nnIdOut, nnDis);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename DeviceAdapter>
|
||||
class TestingPointLocatorSparseGrid
|
||||
{
|
||||
public:
|
||||
void TestTest() const
|
||||
{
|
||||
vtkm::Int32 nTrainingPoints = 5;
|
||||
vtkm::Int32 nTestingPoint = 1;
|
||||
|
||||
std::vector<vtkm::Vec3f_32> coordi;
|
||||
|
||||
///// randomly generate training points/////
|
||||
std::default_random_engine dre;
|
||||
std::uniform_real_distribution<vtkm::Float32> dr(0.0f, 10.0f);
|
||||
|
||||
for (vtkm::Int32 i = 0; i < nTrainingPoints; i++)
|
||||
{
|
||||
coordi.push_back(vtkm::make_Vec(dr(dre), dr(dre), dr(dre)));
|
||||
}
|
||||
// Add a point to each corner to test the case where points might slip out
|
||||
// of the range by epsilon
|
||||
coordi.push_back(vtkm::make_Vec(00.0f, 00.0f, 00.0f));
|
||||
coordi.push_back(vtkm::make_Vec(00.0f, 10.0f, 00.0f));
|
||||
coordi.push_back(vtkm::make_Vec(10.0f, 00.0f, 00.0f));
|
||||
coordi.push_back(vtkm::make_Vec(10.0f, 10.0f, 00.0f));
|
||||
coordi.push_back(vtkm::make_Vec(00.0f, 00.0f, 10.0f));
|
||||
coordi.push_back(vtkm::make_Vec(00.0f, 10.0f, 10.0f));
|
||||
coordi.push_back(vtkm::make_Vec(10.0f, 00.0f, 10.0f));
|
||||
coordi.push_back(vtkm::make_Vec(10.0f, 10.0f, 10.0f));
|
||||
auto coordi_Handle = vtkm::cont::make_ArrayHandle(coordi, vtkm::CopyFlag::Off);
|
||||
|
||||
vtkm::cont::CoordinateSystem coord("points", coordi_Handle);
|
||||
|
||||
vtkm::cont::PointLocatorSparseGrid locator;
|
||||
locator.SetCoordinates(coord);
|
||||
locator.SetRange({ { 0.0, 10.0 } });
|
||||
locator.SetNumberOfBins({ 5, 5, 5 });
|
||||
|
||||
locator.Update();
|
||||
|
||||
///// randomly generate testing points/////
|
||||
std::vector<vtkm::Vec3f_32> qcVec;
|
||||
for (vtkm::Int32 i = 0; i < nTestingPoint; i++)
|
||||
{
|
||||
qcVec.push_back(vtkm::make_Vec(dr(dre), dr(dre), dr(dre)));
|
||||
}
|
||||
// Test near each corner to make sure that corner gets included
|
||||
qcVec.push_back(vtkm::make_Vec(0.01f, 0.01f, 0.01f));
|
||||
qcVec.push_back(vtkm::make_Vec(0.01f, 9.99f, 0.01f));
|
||||
qcVec.push_back(vtkm::make_Vec(9.99f, 0.01f, 0.01f));
|
||||
qcVec.push_back(vtkm::make_Vec(9.99f, 9.99f, 0.01f));
|
||||
qcVec.push_back(vtkm::make_Vec(0.01f, 0.01f, 9.991f));
|
||||
qcVec.push_back(vtkm::make_Vec(0.01f, 9.99f, 9.99f));
|
||||
qcVec.push_back(vtkm::make_Vec(9.99f, 0.01f, 9.99f));
|
||||
qcVec.push_back(vtkm::make_Vec(9.99f, 9.99f, 9.99f));
|
||||
auto qc_Handle = vtkm::cont::make_ArrayHandle(qcVec, vtkm::CopyFlag::Off);
|
||||
|
||||
vtkm::cont::ArrayHandle<vtkm::Id> nnId_Handle;
|
||||
vtkm::cont::ArrayHandle<vtkm::FloatDefault> nnDis_Handle;
|
||||
|
||||
PointLocatorSparseGridWorklet pointLocatorSparseGridWorklet;
|
||||
vtkm::worklet::DispatcherMapField<PointLocatorSparseGridWorklet> locatorDispatcher(
|
||||
pointLocatorSparseGridWorklet);
|
||||
locatorDispatcher.SetDevice(DeviceAdapter());
|
||||
locatorDispatcher.Invoke(qc_Handle, locator, nnId_Handle, nnDis_Handle);
|
||||
|
||||
// brute force
|
||||
vtkm::cont::ArrayHandle<vtkm::Id> bfnnId_Handle;
|
||||
vtkm::cont::ArrayHandle<vtkm::Float32> bfnnDis_Handle;
|
||||
NearestNeighborSearchBruteForce3DWorklet nnsbf3dWorklet;
|
||||
vtkm::worklet::DispatcherMapField<NearestNeighborSearchBruteForce3DWorklet> nnsbf3DDispatcher(
|
||||
nnsbf3dWorklet);
|
||||
nnsbf3DDispatcher.SetDevice(DeviceAdapter());
|
||||
nnsbf3DDispatcher.Invoke(qc_Handle, coordi_Handle, bfnnId_Handle, bfnnDis_Handle);
|
||||
|
||||
///// verify search result /////
|
||||
bool passTest = true;
|
||||
auto nnPortal = nnDis_Handle.ReadPortal();
|
||||
auto bfPortal = bfnnDis_Handle.ReadPortal();
|
||||
for (vtkm::Int32 i = 0; i < nTestingPoint; i++)
|
||||
{
|
||||
vtkm::Id workletIdx = nnId_Handle.WritePortal().Get(i);
|
||||
vtkm::FloatDefault workletDis = nnPortal.Get(i);
|
||||
vtkm::Id bfworkletIdx = bfnnId_Handle.WritePortal().Get(i);
|
||||
vtkm::FloatDefault bfworkletDis = bfPortal.Get(i);
|
||||
|
||||
if (workletIdx != bfworkletIdx)
|
||||
{
|
||||
std::cout << "bf index: " << bfworkletIdx << ", dis: " << bfworkletDis
|
||||
<< ", grid: " << workletIdx << ", dis " << workletDis << std::endl;
|
||||
passTest = false;
|
||||
}
|
||||
}
|
||||
VTKM_TEST_ASSERT(passTest, "Uniform Grid NN search result incorrect.");
|
||||
}
|
||||
|
||||
void operator()() const
|
||||
{
|
||||
vtkm::cont::GetRuntimeDeviceTracker().ForceDevice(DeviceAdapter());
|
||||
this->TestTest();
|
||||
}
|
||||
};
|
||||
|
||||
#endif // vtk_m_cont_testing_TestingPointLocatorSparseGrid_h
|
@ -1,232 +0,0 @@
|
||||
//============================================================================
|
||||
// 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.
|
||||
//============================================================================
|
||||
#ifndef vtk_m_cont_testing_TestingVirtualObjectHandle_h
|
||||
#define vtk_m_cont_testing_TestingVirtualObjectHandle_h
|
||||
|
||||
#include <vtkm/Types.h>
|
||||
#include <vtkm/cont/ArrayHandle.h>
|
||||
#include <vtkm/cont/ArrayHandleTransform.h>
|
||||
#include <vtkm/cont/DeviceAdapterAlgorithm.h>
|
||||
#include <vtkm/cont/VirtualObjectHandle.h>
|
||||
#include <vtkm/cont/testing/Testing.h>
|
||||
|
||||
#ifdef VTKM_NO_DEPRECATED_VIRTUAL
|
||||
#error "This test should be disabled if the VTKm_NO_DEPRECATED_VIRTUAL is true."
|
||||
#endif //VTKM_NO_DEPRECATED_VIRTUAL
|
||||
|
||||
VTKM_DEPRECATED_SUPPRESS_BEGIN
|
||||
|
||||
#define ARRAY_LEN 8
|
||||
|
||||
namespace vtkm
|
||||
{
|
||||
namespace cont
|
||||
{
|
||||
namespace testing
|
||||
{
|
||||
|
||||
namespace virtual_object_detail
|
||||
{
|
||||
|
||||
class Transformer : public vtkm::VirtualObjectBase
|
||||
{
|
||||
public:
|
||||
VTKM_EXEC
|
||||
virtual vtkm::FloatDefault Eval(vtkm::FloatDefault val) const = 0;
|
||||
};
|
||||
|
||||
class Square : public Transformer
|
||||
{
|
||||
public:
|
||||
VTKM_EXEC
|
||||
vtkm::FloatDefault Eval(vtkm::FloatDefault val) const override { return val * val; }
|
||||
};
|
||||
|
||||
class Multiply : public Transformer
|
||||
{
|
||||
public:
|
||||
VTKM_CONT
|
||||
void SetMultiplicand(vtkm::FloatDefault val)
|
||||
{
|
||||
this->Multiplicand = val;
|
||||
this->Modified();
|
||||
}
|
||||
|
||||
VTKM_CONT
|
||||
vtkm::FloatDefault GetMultiplicand() const { return this->Multiplicand; }
|
||||
|
||||
VTKM_EXEC
|
||||
vtkm::FloatDefault Eval(vtkm::FloatDefault val) const override
|
||||
{
|
||||
return val * this->Multiplicand;
|
||||
}
|
||||
|
||||
private:
|
||||
vtkm::FloatDefault Multiplicand = 0.0f;
|
||||
};
|
||||
|
||||
class TransformerFunctor
|
||||
{
|
||||
public:
|
||||
TransformerFunctor() = default;
|
||||
explicit TransformerFunctor(const Transformer* impl)
|
||||
: Impl(impl)
|
||||
{
|
||||
}
|
||||
|
||||
VTKM_EXEC
|
||||
vtkm::FloatDefault operator()(vtkm::FloatDefault val) const { return this->Impl->Eval(val); }
|
||||
|
||||
private:
|
||||
const Transformer* Impl;
|
||||
};
|
||||
|
||||
} // virtual_object_detail
|
||||
|
||||
template <typename DeviceAdapterList>
|
||||
class TestingVirtualObjectHandle
|
||||
{
|
||||
private:
|
||||
using FloatArrayHandle = vtkm::cont::ArrayHandle<vtkm::FloatDefault>;
|
||||
using ArrayTransform =
|
||||
vtkm::cont::ArrayHandleTransform<FloatArrayHandle, virtual_object_detail::TransformerFunctor>;
|
||||
using TransformerHandle = vtkm::cont::VirtualObjectHandle<virtual_object_detail::Transformer>;
|
||||
|
||||
class TestStage1
|
||||
{
|
||||
public:
|
||||
TestStage1(const FloatArrayHandle& input, TransformerHandle& handle)
|
||||
: Input(&input)
|
||||
, Handle(&handle)
|
||||
{
|
||||
}
|
||||
|
||||
template <typename DeviceAdapter>
|
||||
void operator()(DeviceAdapter device) const
|
||||
{
|
||||
using Algorithm = vtkm::cont::DeviceAdapterAlgorithm<DeviceAdapter>;
|
||||
std::cout << "\tDeviceAdapter: " << vtkm::cont::DeviceAdapterTraits<DeviceAdapter>::GetName()
|
||||
<< std::endl;
|
||||
|
||||
for (int n = 0; n < 2; ++n)
|
||||
{
|
||||
vtkm::cont::Token token;
|
||||
virtual_object_detail::TransformerFunctor tfnctr(
|
||||
this->Handle->PrepareForExecution(device, token));
|
||||
ArrayTransform transformed(*this->Input, tfnctr);
|
||||
|
||||
FloatArrayHandle output;
|
||||
Algorithm::Copy(transformed, output);
|
||||
auto portal = output.ReadPortal();
|
||||
for (vtkm::Id i = 0; i < ARRAY_LEN; ++i)
|
||||
{
|
||||
vtkm::FloatDefault expected = TestValue(i, vtkm::FloatDefault{});
|
||||
expected = expected * expected;
|
||||
VTKM_TEST_ASSERT(
|
||||
test_equal(portal.Get(i), expected), "Expected ", expected, " but got ", portal.Get(i));
|
||||
}
|
||||
std::cout << "\tSuccess." << std::endl;
|
||||
|
||||
if (n == 0)
|
||||
{
|
||||
std::cout << "\tReleaseResources and test again..." << std::endl;
|
||||
this->Handle->ReleaseExecutionResources();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
const FloatArrayHandle* Input;
|
||||
TransformerHandle* Handle;
|
||||
};
|
||||
|
||||
class TestStage2
|
||||
{
|
||||
public:
|
||||
TestStage2(const FloatArrayHandle& input,
|
||||
virtual_object_detail::Multiply& mul,
|
||||
TransformerHandle& handle)
|
||||
: Input(&input)
|
||||
, Mul(&mul)
|
||||
, Handle(&handle)
|
||||
{
|
||||
}
|
||||
|
||||
template <typename DeviceAdapter>
|
||||
void operator()(DeviceAdapter device) const
|
||||
{
|
||||
using Algorithm = vtkm::cont::DeviceAdapterAlgorithm<DeviceAdapter>;
|
||||
std::cout << "\tDeviceAdapter: " << vtkm::cont::DeviceAdapterTraits<DeviceAdapter>::GetName()
|
||||
<< std::endl;
|
||||
|
||||
this->Mul->SetMultiplicand(2);
|
||||
for (int n = 0; n < 2; ++n)
|
||||
{
|
||||
vtkm::cont::Token token;
|
||||
virtual_object_detail::TransformerFunctor tfnctr(
|
||||
this->Handle->PrepareForExecution(device, token));
|
||||
ArrayTransform transformed(*this->Input, tfnctr);
|
||||
|
||||
FloatArrayHandle output;
|
||||
Algorithm::Copy(transformed, output);
|
||||
auto portal = output.ReadPortal();
|
||||
for (vtkm::Id i = 0; i < ARRAY_LEN; ++i)
|
||||
{
|
||||
vtkm::FloatDefault expected =
|
||||
TestValue(i, vtkm::FloatDefault{}) * this->Mul->GetMultiplicand();
|
||||
VTKM_TEST_ASSERT(
|
||||
test_equal(portal.Get(i), expected), "Expected ", expected, " but got ", portal.Get(i));
|
||||
}
|
||||
std::cout << "\tSuccess." << std::endl;
|
||||
|
||||
if (n == 0)
|
||||
{
|
||||
std::cout << "\tUpdate and test again..." << std::endl;
|
||||
this->Mul->SetMultiplicand(3);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
const FloatArrayHandle* Input;
|
||||
virtual_object_detail::Multiply* Mul;
|
||||
TransformerHandle* Handle;
|
||||
};
|
||||
|
||||
public:
|
||||
static void Run()
|
||||
{
|
||||
vtkm::cont::ArrayHandle<vtkm::FloatDefault> input;
|
||||
input.Allocate(ARRAY_LEN);
|
||||
SetPortal(input.WritePortal());
|
||||
|
||||
TransformerHandle handle;
|
||||
|
||||
std::cout << "Testing with concrete type 1 (Square)..." << std::endl;
|
||||
virtual_object_detail::Square sqr;
|
||||
handle.Reset(&sqr, false, DeviceAdapterList());
|
||||
vtkm::ListForEach(TestStage1(input, handle), DeviceAdapterList());
|
||||
|
||||
std::cout << "ReleaseResources..." << std::endl;
|
||||
handle.ReleaseResources();
|
||||
|
||||
std::cout << "Testing with concrete type 2 (Multiply)..." << std::endl;
|
||||
virtual_object_detail::Multiply mul;
|
||||
handle.Reset(&mul, false, DeviceAdapterList());
|
||||
vtkm::ListForEach(TestStage2(input, mul, handle), DeviceAdapterList());
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
} // vtkm::cont::testing
|
||||
|
||||
VTKM_DEPRECATED_SUPPRESS_END
|
||||
|
||||
#endif
|
569
vtkm/cont/testing/UnitTestArrayHandle.cxx
Normal file
569
vtkm/cont/testing/UnitTestArrayHandle.cxx
Normal file
@ -0,0 +1,569 @@
|
||||
//============================================================================
|
||||
// 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/TypeTraits.h>
|
||||
#include <vtkm/cont/ArrayHandle.h>
|
||||
|
||||
#include <vtkm/worklet/DispatcherMapField.h>
|
||||
#include <vtkm/worklet/WorkletMapField.h>
|
||||
|
||||
#include <vtkm/cont/ArrayHandleExtractComponent.h>
|
||||
#include <vtkm/cont/testing/Testing.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <vector>
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
template <class IteratorType, typename T>
|
||||
void CheckValues(IteratorType begin, IteratorType end, T offset)
|
||||
{
|
||||
|
||||
vtkm::Id index = 0;
|
||||
for (IteratorType iter = begin; iter != end; iter++)
|
||||
{
|
||||
T expectedValue = TestValue(index, T()) + offset;
|
||||
if (!test_equal(*iter, expectedValue))
|
||||
{
|
||||
std::stringstream message;
|
||||
message << "Got unexpected value in array." << std::endl
|
||||
<< "Expected: " << expectedValue << ", Found: " << *iter << std::endl;
|
||||
VTKM_TEST_FAIL(message.str().c_str());
|
||||
}
|
||||
|
||||
index++;
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void CheckArray(const vtkm::cont::ArrayHandle<T>& handle, T offset = T(0))
|
||||
{
|
||||
CheckPortal(handle.ReadPortal(), offset);
|
||||
}
|
||||
|
||||
// Use to get an arbitrarily different valuetype than T:
|
||||
template <typename T>
|
||||
struct OtherType
|
||||
{
|
||||
using Type = vtkm::Int32;
|
||||
};
|
||||
template <>
|
||||
struct OtherType<vtkm::Int32>
|
||||
{
|
||||
using Type = vtkm::UInt8;
|
||||
};
|
||||
|
||||
struct PassThrough : public vtkm::worklet::WorkletMapField
|
||||
{
|
||||
using ControlSignature = void(FieldIn, FieldOut);
|
||||
using ExecutionSignature = _2(_1);
|
||||
|
||||
template <typename T>
|
||||
VTKM_EXEC T operator()(const T& value) const
|
||||
{
|
||||
return value;
|
||||
}
|
||||
};
|
||||
|
||||
struct AssignTestValue : public vtkm::worklet::WorkletMapField
|
||||
{
|
||||
using ControlSignature = void(FieldIn indices, FieldOut values);
|
||||
|
||||
template <typename T>
|
||||
VTKM_EXEC void operator()(vtkm::Id index, T& valueOut) const
|
||||
{
|
||||
valueOut = TestValue(index, T());
|
||||
}
|
||||
};
|
||||
|
||||
struct InplaceAdd1 : public vtkm::worklet::WorkletMapField
|
||||
{
|
||||
using ControlSignature = void(FieldInOut);
|
||||
|
||||
template <typename T>
|
||||
VTKM_EXEC void operator()(T& value) const
|
||||
{
|
||||
value = static_cast<T>(value + T(1));
|
||||
}
|
||||
};
|
||||
|
||||
constexpr vtkm::Id ARRAY_SIZE = 100;
|
||||
|
||||
struct VerifyEmptyArrays
|
||||
{
|
||||
template <typename T>
|
||||
VTKM_CONT void operator()(T) const
|
||||
{
|
||||
std::cout << "Try operations on empty arrays." << std::endl;
|
||||
// After each operation, reinitialize array in case something gets
|
||||
// allocated.
|
||||
vtkm::cont::ArrayHandle<T> arrayHandle = vtkm::cont::ArrayHandle<T>();
|
||||
VTKM_TEST_ASSERT(arrayHandle.GetNumberOfValues() == 0,
|
||||
"Uninitialized array does not report zero values.");
|
||||
arrayHandle = vtkm::cont::ArrayHandle<T>();
|
||||
VTKM_TEST_ASSERT(arrayHandle.ReadPortal().GetNumberOfValues() == 0,
|
||||
"Uninitialized array does not give portal with zero values.");
|
||||
vtkm::cont::Token token;
|
||||
arrayHandle = vtkm::cont::ArrayHandle<T>();
|
||||
arrayHandle.Allocate(0, vtkm::CopyFlag::On);
|
||||
arrayHandle = vtkm::cont::ArrayHandle<T>();
|
||||
arrayHandle.ReleaseResourcesExecution();
|
||||
arrayHandle = vtkm::cont::ArrayHandle<T>();
|
||||
arrayHandle.ReleaseResources();
|
||||
arrayHandle = vtkm::cont::make_ArrayHandleMove(std::vector<T>());
|
||||
arrayHandle.PrepareForInput(vtkm::cont::DeviceAdapterTagSerial{}, token);
|
||||
arrayHandle = vtkm::cont::ArrayHandle<T>();
|
||||
arrayHandle.PrepareForInPlace(vtkm::cont::DeviceAdapterTagSerial{}, token);
|
||||
arrayHandle = vtkm::cont::ArrayHandle<T>();
|
||||
arrayHandle.PrepareForOutput(ARRAY_SIZE, vtkm::cont::DeviceAdapterTagSerial{}, token);
|
||||
}
|
||||
};
|
||||
|
||||
struct VerifyUserOwnedMemory
|
||||
{
|
||||
template <typename T>
|
||||
VTKM_CONT void operator()(T) const
|
||||
{
|
||||
vtkm::cont::Invoker invoke;
|
||||
|
||||
std::cout << "Creating array with user-allocated memory." << std::endl;
|
||||
std::vector<T> buffer(ARRAY_SIZE);
|
||||
for (vtkm::Id index = 0; index < ARRAY_SIZE; index++)
|
||||
{
|
||||
buffer[static_cast<std::size_t>(index)] = TestValue(index, T());
|
||||
}
|
||||
|
||||
vtkm::cont::ArrayHandle<T> arrayHandle =
|
||||
vtkm::cont::make_ArrayHandle(buffer, vtkm::CopyFlag::Off);
|
||||
|
||||
VTKM_TEST_ASSERT(arrayHandle.GetNumberOfValues() == ARRAY_SIZE,
|
||||
"ArrayHandle has wrong number of entries.");
|
||||
|
||||
std::cout << "Check array with user provided memory." << std::endl;
|
||||
CheckArray(arrayHandle);
|
||||
|
||||
std::cout << "Check out execution array behavior." << std::endl;
|
||||
{ //as input
|
||||
vtkm::cont::ArrayHandle<T> result;
|
||||
invoke(PassThrough{}, arrayHandle, result);
|
||||
CheckArray(result);
|
||||
}
|
||||
|
||||
std::cout << "Check out inplace." << std::endl;
|
||||
{ //as inplace
|
||||
invoke(InplaceAdd1{}, arrayHandle);
|
||||
CheckArray(arrayHandle, T(1));
|
||||
}
|
||||
|
||||
//clear out user array for next test
|
||||
std::fill(buffer.begin(), buffer.end(), static_cast<T>(-1));
|
||||
|
||||
std::cout << "Check out output." << std::endl;
|
||||
{ //as output with same length as user provided. This should work
|
||||
//as no new memory needs to be allocated
|
||||
invoke(AssignTestValue{}, vtkm::cont::ArrayHandleIndex(ARRAY_SIZE), arrayHandle);
|
||||
|
||||
//sync data, which should fill up the user buffer
|
||||
arrayHandle.SyncControlArray();
|
||||
|
||||
//check that we got the proper values in the user array
|
||||
CheckValues(buffer.begin(), buffer.end(), T{ 0 });
|
||||
}
|
||||
|
||||
std::cout << "Check invalid reallocation." << std::endl;
|
||||
{ //as output with a length larger than the memory provided by the user
|
||||
//this should fail
|
||||
bool gotException = false;
|
||||
try
|
||||
{
|
||||
//you should not be able to allocate a size larger than the
|
||||
//user provided and get the results
|
||||
vtkm::cont::Token token;
|
||||
arrayHandle.PrepareForOutput(ARRAY_SIZE * 2, vtkm::cont::DeviceAdapterTagSerial{}, token);
|
||||
token.DetachFromAll();
|
||||
arrayHandle.WritePortal();
|
||||
}
|
||||
catch (vtkm::cont::Error&)
|
||||
{
|
||||
gotException = true;
|
||||
}
|
||||
VTKM_TEST_ASSERT(gotException,
|
||||
"PrepareForOutput should fail when asked to "
|
||||
"re-allocate user provided memory.");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
struct VerifyUserTransferredMemory
|
||||
{
|
||||
template <typename T>
|
||||
VTKM_CONT void operator()(T) const
|
||||
{
|
||||
vtkm::cont::Invoker invoke;
|
||||
|
||||
T* buffer = new T[ARRAY_SIZE];
|
||||
for (vtkm::Id index = 0; index < ARRAY_SIZE; index++)
|
||||
{
|
||||
buffer[static_cast<std::size_t>(index)] = TestValue(index, T());
|
||||
}
|
||||
|
||||
auto user_free_function = [](void* ptr) { delete[] static_cast<T*>(ptr); };
|
||||
vtkm::cont::ArrayHandleBasic<T> arrayHandle(buffer, ARRAY_SIZE, user_free_function);
|
||||
|
||||
VTKM_TEST_ASSERT(arrayHandle.GetNumberOfValues() == ARRAY_SIZE,
|
||||
"ArrayHandle has wrong number of entries.");
|
||||
|
||||
std::cout << "Check array with user transferred memory." << std::endl;
|
||||
CheckArray(arrayHandle);
|
||||
|
||||
std::cout << "Check out execution array behavior." << std::endl;
|
||||
{ //as input
|
||||
vtkm::cont::ArrayHandle<T> result;
|
||||
invoke(PassThrough{}, arrayHandle, result);
|
||||
CheckArray(result);
|
||||
}
|
||||
|
||||
std::cout << "Check out inplace." << std::endl;
|
||||
{ //as inplace
|
||||
invoke(InplaceAdd1{}, arrayHandle);
|
||||
CheckArray(arrayHandle, T(1));
|
||||
}
|
||||
|
||||
std::cout << "Check out output." << std::endl;
|
||||
{ //as output with same length as user provided. This should work
|
||||
//as no new memory needs to be allocated
|
||||
invoke(AssignTestValue{}, vtkm::cont::ArrayHandleIndex(ARRAY_SIZE), arrayHandle);
|
||||
|
||||
//sync data, which should fill up the user buffer
|
||||
arrayHandle.SyncControlArray();
|
||||
|
||||
//check that we got the proper values in the user array
|
||||
CheckValues(buffer, buffer + ARRAY_SIZE, T{ 0 });
|
||||
}
|
||||
|
||||
{ //as output with a length larger than the memory provided by the user
|
||||
//this should fail
|
||||
bool gotException = false;
|
||||
try
|
||||
{
|
||||
//you should not be able to allocate a size larger than the
|
||||
//user provided and get the results
|
||||
vtkm::cont::Token token;
|
||||
arrayHandle.PrepareForOutput(ARRAY_SIZE * 2, vtkm::cont::DeviceAdapterTagSerial{}, token);
|
||||
token.DetachFromAll();
|
||||
arrayHandle.WritePortal();
|
||||
}
|
||||
catch (vtkm::cont::Error&)
|
||||
{
|
||||
gotException = true;
|
||||
}
|
||||
VTKM_TEST_ASSERT(gotException,
|
||||
"PrepareForOutput should fail when asked to "
|
||||
"re-allocate user provided memory.");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
struct VerifyVectorMovedMemory
|
||||
{
|
||||
template <typename T>
|
||||
VTKM_CONT void operator()(T) const
|
||||
{
|
||||
vtkm::cont::Invoker invoke;
|
||||
|
||||
std::cout << "Creating moved std::vector memory." << std::endl;
|
||||
std::vector<T> buffer(ARRAY_SIZE);
|
||||
for (vtkm::Id index = 0; index < ARRAY_SIZE; index++)
|
||||
{
|
||||
buffer[static_cast<std::size_t>(index)] = TestValue(index, T());
|
||||
}
|
||||
|
||||
vtkm::cont::ArrayHandle<T> arrayHandle = vtkm::cont::make_ArrayHandleMove(std::move(buffer));
|
||||
// buffer is now invalid
|
||||
|
||||
VTKM_TEST_ASSERT(arrayHandle.GetNumberOfValues() == ARRAY_SIZE,
|
||||
"ArrayHandle has wrong number of entries.");
|
||||
|
||||
std::cout << "Check array with moved std::vector memory." << std::endl;
|
||||
CheckArray(arrayHandle);
|
||||
|
||||
std::cout << "Check out execution array behavior." << std::endl;
|
||||
{ //as input
|
||||
vtkm::cont::ArrayHandle<T> result;
|
||||
invoke(PassThrough{}, arrayHandle, result);
|
||||
CheckArray(result);
|
||||
}
|
||||
|
||||
std::cout << "Check out inplace." << std::endl;
|
||||
{ //as inplace
|
||||
invoke(InplaceAdd1{}, arrayHandle);
|
||||
CheckArray(arrayHandle, T(1));
|
||||
}
|
||||
|
||||
std::cout << "Check out output." << std::endl;
|
||||
{ //as output with same length as user provided. This should work
|
||||
//as no new memory needs to be allocated
|
||||
invoke(AssignTestValue{}, vtkm::cont::ArrayHandleIndex(ARRAY_SIZE), arrayHandle);
|
||||
|
||||
//check that we got the proper values in the user array
|
||||
CheckArray(arrayHandle);
|
||||
}
|
||||
|
||||
{ //as a vector moved to the ArrayHandle, reallocation should be possible
|
||||
invoke(AssignTestValue{}, vtkm::cont::ArrayHandleIndex(ARRAY_SIZE * 2), arrayHandle);
|
||||
VTKM_TEST_ASSERT(arrayHandle.GetNumberOfValues() == ARRAY_SIZE * 2);
|
||||
|
||||
//check that we got the proper values in the user array
|
||||
CheckArray(arrayHandle);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
struct VerifyInitializerList
|
||||
{
|
||||
template <typename T>
|
||||
VTKM_CONT void operator()(T) const
|
||||
{
|
||||
vtkm::cont::Invoker invoke;
|
||||
|
||||
std::cout << "Creating array with initializer list memory." << std::endl;
|
||||
vtkm::cont::ArrayHandle<T> arrayHandle =
|
||||
vtkm::cont::make_ArrayHandle({ TestValue(0, T()), TestValue(1, T()), TestValue(2, T()) });
|
||||
|
||||
VTKM_TEST_ASSERT(arrayHandle.GetNumberOfValues() == 3,
|
||||
"ArrayHandle has wrong number of entries.");
|
||||
|
||||
std::cout << "Check array with initializer list memory." << std::endl;
|
||||
CheckArray(arrayHandle);
|
||||
|
||||
std::cout << "Check out execution array behavior." << std::endl;
|
||||
{ //as input
|
||||
vtkm::cont::ArrayHandle<T> result;
|
||||
invoke(PassThrough{}, arrayHandle, result);
|
||||
CheckArray(result);
|
||||
}
|
||||
|
||||
std::cout << "Check out inplace." << std::endl;
|
||||
{ //as inplace
|
||||
invoke(InplaceAdd1{}, arrayHandle);
|
||||
CheckArray(arrayHandle, T(1));
|
||||
}
|
||||
|
||||
std::cout << "Check out output." << std::endl;
|
||||
{ //as output with same length as user provided. This should work
|
||||
//as no new memory needs to be allocated
|
||||
invoke(AssignTestValue{}, vtkm::cont::ArrayHandleIndex(3), arrayHandle);
|
||||
|
||||
//check that we got the proper values in the user array
|
||||
CheckArray(arrayHandle);
|
||||
}
|
||||
|
||||
{ //as a vector moved to the ArrayHandle, reallocation should be possible
|
||||
invoke(AssignTestValue{}, vtkm::cont::ArrayHandleIndex(ARRAY_SIZE * 2), arrayHandle);
|
||||
VTKM_TEST_ASSERT(arrayHandle.GetNumberOfValues() == ARRAY_SIZE * 2);
|
||||
|
||||
//check that we got the proper values in the user array
|
||||
CheckArray(arrayHandle);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
struct VerifyVTKMAllocatedHandle
|
||||
{
|
||||
template <typename T>
|
||||
VTKM_CONT void operator()(T) const
|
||||
{
|
||||
vtkm::cont::Invoker invoke;
|
||||
|
||||
vtkm::cont::ArrayHandle<T> arrayHandle;
|
||||
|
||||
VTKM_TEST_ASSERT(arrayHandle.GetNumberOfValues() == 0,
|
||||
"ArrayHandle has wrong number of entries.");
|
||||
invoke(AssignTestValue{}, vtkm::cont::ArrayHandleIndex(ARRAY_SIZE * 2), arrayHandle);
|
||||
|
||||
VTKM_TEST_ASSERT(arrayHandle.GetNumberOfValues() == ARRAY_SIZE * 2,
|
||||
"Array not allocated correctly.");
|
||||
CheckArray(arrayHandle);
|
||||
|
||||
std::cout << "Try shrinking the array." << std::endl;
|
||||
arrayHandle.Allocate(ARRAY_SIZE, vtkm::CopyFlag::On);
|
||||
VTKM_TEST_ASSERT(arrayHandle.GetNumberOfValues() == ARRAY_SIZE,
|
||||
"Array size did not shrink correctly.");
|
||||
CheckArray(arrayHandle);
|
||||
|
||||
std::cout << "Try reallocating array." << std::endl;
|
||||
arrayHandle.Allocate(ARRAY_SIZE * 2);
|
||||
VTKM_TEST_ASSERT(arrayHandle.GetNumberOfValues() == ARRAY_SIZE * 2,
|
||||
"Array size did not allocate correctly.");
|
||||
// No point in checking values. This method can invalidate them.
|
||||
|
||||
std::cout << "Try in place operation." << std::endl;
|
||||
// Reset array data.
|
||||
invoke(AssignTestValue{}, vtkm::cont::ArrayHandleIndex(ARRAY_SIZE * 2), arrayHandle);
|
||||
|
||||
invoke(InplaceAdd1{}, arrayHandle);
|
||||
CheckArray(arrayHandle, T(1));
|
||||
|
||||
VTKM_TEST_ASSERT(arrayHandle == arrayHandle, "Array handle does not equal itself.");
|
||||
VTKM_TEST_ASSERT(arrayHandle != vtkm::cont::ArrayHandle<T>(),
|
||||
"Array handle equals different array.");
|
||||
}
|
||||
};
|
||||
|
||||
struct VerifyVTKMTransferredOwnership
|
||||
{
|
||||
template <typename T>
|
||||
VTKM_CONT void operator()(T) const
|
||||
{
|
||||
vtkm::cont::Invoker invoke;
|
||||
|
||||
vtkm::cont::internal::TransferredBuffer transferredMemory;
|
||||
|
||||
//Steal memory from a handle that has multiple copies to verify all
|
||||
//copies are updated correctly
|
||||
{
|
||||
vtkm::cont::ArrayHandle<T> arrayHandle;
|
||||
auto copyOfHandle = arrayHandle;
|
||||
|
||||
VTKM_TEST_ASSERT(arrayHandle.GetNumberOfValues() == 0,
|
||||
"ArrayHandle has wrong number of entries.");
|
||||
invoke(AssignTestValue{}, vtkm::cont::ArrayHandleIndex(ARRAY_SIZE * 2), arrayHandle);
|
||||
|
||||
transferredMemory = copyOfHandle.GetBuffers()[0].TakeHostBufferOwnership();
|
||||
|
||||
VTKM_TEST_ASSERT(copyOfHandle.GetNumberOfValues() == ARRAY_SIZE * 2,
|
||||
"Array not allocated correctly.");
|
||||
CheckArray(arrayHandle);
|
||||
|
||||
std::cout << "Try in place operation." << std::endl;
|
||||
invoke(InplaceAdd1{}, arrayHandle);
|
||||
CheckArray(arrayHandle, T(1));
|
||||
}
|
||||
|
||||
transferredMemory.Delete(transferredMemory.Container);
|
||||
}
|
||||
};
|
||||
|
||||
struct VerifyEqualityOperators
|
||||
{
|
||||
template <typename T>
|
||||
VTKM_CONT void operator()(T) const
|
||||
{
|
||||
std::cout << "Verify that shallow copied array handles compare equal:\n";
|
||||
{
|
||||
vtkm::cont::ArrayHandle<T> a1;
|
||||
vtkm::cont::ArrayHandle<T> a2 = a1; // shallow copy
|
||||
vtkm::cont::ArrayHandle<T> a3;
|
||||
VTKM_TEST_ASSERT(a1 == a2, "Shallow copied array not equal.");
|
||||
VTKM_TEST_ASSERT(!(a1 != a2), "Shallow copied array not equal.");
|
||||
VTKM_TEST_ASSERT(a1 != a3, "Distinct arrays compared equal.");
|
||||
VTKM_TEST_ASSERT(!(a1 == a3), "Distinct arrays compared equal.");
|
||||
|
||||
// Operations on a1 shouldn't affect equality
|
||||
a1.Allocate(200);
|
||||
VTKM_TEST_ASSERT(a1 == a2, "Shallow copied array not equal.");
|
||||
VTKM_TEST_ASSERT(!(a1 != a2), "Shallow copied array not equal.");
|
||||
|
||||
a1.ReadPortal();
|
||||
VTKM_TEST_ASSERT(a1 == a2, "Shallow copied array not equal.");
|
||||
VTKM_TEST_ASSERT(!(a1 != a2), "Shallow copied array not equal.");
|
||||
|
||||
vtkm::cont::Token token;
|
||||
a1.PrepareForInPlace(vtkm::cont::DeviceAdapterTagSerial{}, token);
|
||||
VTKM_TEST_ASSERT(a1 == a2, "Shallow copied array not equal.");
|
||||
VTKM_TEST_ASSERT(!(a1 != a2), "Shallow copied array not equal.");
|
||||
}
|
||||
|
||||
std::cout << "Verify that handles with different storage types are not equal.\n";
|
||||
{
|
||||
vtkm::cont::ArrayHandle<T, vtkm::cont::StorageTagBasic> a1;
|
||||
vtkm::cont::ArrayHandle<vtkm::Vec<T, 3>, vtkm::cont::StorageTagBasic> tmp;
|
||||
auto a2 = vtkm::cont::make_ArrayHandleExtractComponent(tmp, 1);
|
||||
|
||||
VTKM_TEST_ASSERT(a1 != a2, "Arrays with different storage type compared equal.");
|
||||
VTKM_TEST_ASSERT(!(a1 == a2), "Arrays with different storage type compared equal.");
|
||||
}
|
||||
|
||||
std::cout << "Verify that handles with different value types are not equal.\n";
|
||||
{
|
||||
vtkm::cont::ArrayHandle<T, vtkm::cont::StorageTagBasic> a1;
|
||||
vtkm::cont::ArrayHandle<typename OtherType<T>::Type, vtkm::cont::StorageTagBasic> a2;
|
||||
|
||||
VTKM_TEST_ASSERT(a1 != a2, "Arrays with different value type compared equal.");
|
||||
VTKM_TEST_ASSERT(!(a1 == a2), "Arrays with different value type compared equal.");
|
||||
}
|
||||
|
||||
std::cout << "Verify that handles with different storage and value types are not equal.\n";
|
||||
{
|
||||
vtkm::cont::ArrayHandle<T, vtkm::cont::StorageTagBasic> a1;
|
||||
vtkm::cont::ArrayHandle<vtkm::Vec<typename OtherType<T>::Type, 3>,
|
||||
vtkm::cont::StorageTagBasic>
|
||||
tmp;
|
||||
auto a2 = vtkm::cont::make_ArrayHandleExtractComponent(tmp, 1);
|
||||
|
||||
VTKM_TEST_ASSERT(a1 != a2, "Arrays with different storage and value type compared equal.");
|
||||
VTKM_TEST_ASSERT(!(a1 == a2), "Arrays with different storage and value type compared equal.");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
struct VerifyFill
|
||||
{
|
||||
template <typename T>
|
||||
VTKM_CONT void operator()(T) const
|
||||
{
|
||||
std::cout << "Initialize values of array." << std::endl;
|
||||
const T testValue1 = TestValue(13, T{});
|
||||
vtkm::cont::ArrayHandle<T> array;
|
||||
array.AllocateAndFill(ARRAY_SIZE, testValue1);
|
||||
{
|
||||
auto portal = array.ReadPortal();
|
||||
for (vtkm::Id index = 0; index < ARRAY_SIZE; ++index)
|
||||
{
|
||||
VTKM_TEST_ASSERT(portal.Get(index) == testValue1);
|
||||
}
|
||||
}
|
||||
|
||||
std::cout << "Grow array with new values." << std::endl;
|
||||
const T testValue2 = TestValue(42, T{});
|
||||
array.AllocateAndFill(ARRAY_SIZE * 2, testValue2, vtkm::CopyFlag::On);
|
||||
{
|
||||
auto portal = array.ReadPortal();
|
||||
for (vtkm::Id index = 0; index < ARRAY_SIZE; ++index)
|
||||
{
|
||||
VTKM_TEST_ASSERT(portal.Get(index) == testValue1);
|
||||
}
|
||||
for (vtkm::Id index = ARRAY_SIZE; index < ARRAY_SIZE * 2; ++index)
|
||||
{
|
||||
VTKM_TEST_ASSERT(portal.Get(index) == testValue2);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
VTKM_CONT void Run()
|
||||
{
|
||||
vtkm::testing::Testing::TryTypes(VerifyEmptyArrays{});
|
||||
vtkm::testing::Testing::TryTypes(VerifyUserOwnedMemory{});
|
||||
vtkm::testing::Testing::TryTypes(VerifyUserTransferredMemory{});
|
||||
vtkm::testing::Testing::TryTypes(VerifyVectorMovedMemory{});
|
||||
vtkm::testing::Testing::TryTypes(VerifyInitializerList{});
|
||||
vtkm::testing::Testing::TryTypes(VerifyVTKMAllocatedHandle{});
|
||||
vtkm::testing::Testing::TryTypes(VerifyVTKMTransferredOwnership{});
|
||||
vtkm::testing::Testing::TryTypes(VerifyEqualityOperators{});
|
||||
vtkm::testing::Testing::TryTypes(VerifyFill{});
|
||||
}
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
int UnitTestArrayHandle(int argc, char* argv[])
|
||||
{
|
||||
return vtkm::cont::testing::Testing::Run(Run, argc, argv);
|
||||
}
|
113
vtkm/cont/testing/UnitTestArrayHandleCast.cxx
Normal file
113
vtkm/cont/testing/UnitTestArrayHandleCast.cxx
Normal file
@ -0,0 +1,113 @@
|
||||
//============================================================================
|
||||
// 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/ArrayHandleCast.h>
|
||||
|
||||
#include <vtkm/cont/Invoker.h>
|
||||
|
||||
#include <vtkm/worklet/WorkletMapField.h>
|
||||
|
||||
#include <vtkm/cont/testing/Testing.h>
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
constexpr vtkm::Id ARRAY_SIZE = 10;
|
||||
|
||||
struct PassThrough : public vtkm::worklet::WorkletMapField
|
||||
{
|
||||
using ControlSignature = void(FieldIn, FieldOut);
|
||||
using ExecutionSignature = void(_1, _2);
|
||||
|
||||
template <typename InValue, typename OutValue>
|
||||
VTKM_EXEC void operator()(const InValue& inValue, OutValue& outValue) const
|
||||
{
|
||||
outValue = inValue;
|
||||
}
|
||||
};
|
||||
|
||||
struct TestCastAsInput
|
||||
{
|
||||
template <typename CastToType>
|
||||
VTKM_CONT void operator()(CastToType vtkmNotUsed(type)) const
|
||||
{
|
||||
vtkm::cont::Invoker invoke;
|
||||
using InputArrayType = vtkm::cont::ArrayHandleIndex;
|
||||
|
||||
InputArrayType input(ARRAY_SIZE);
|
||||
vtkm::cont::ArrayHandleCast<CastToType, InputArrayType> castArray =
|
||||
vtkm::cont::make_ArrayHandleCast(input, CastToType());
|
||||
vtkm::cont::ArrayHandle<CastToType> result;
|
||||
|
||||
invoke(PassThrough{}, castArray, result);
|
||||
|
||||
// verify results
|
||||
vtkm::Id length = ARRAY_SIZE;
|
||||
auto resultPortal = result.ReadPortal();
|
||||
auto inputPortal = input.ReadPortal();
|
||||
for (vtkm::Id i = 0; i < length; ++i)
|
||||
{
|
||||
VTKM_TEST_ASSERT(resultPortal.Get(i) == static_cast<CastToType>(inputPortal.Get(i)),
|
||||
"Casting ArrayHandle Failed");
|
||||
}
|
||||
|
||||
castArray.ReleaseResources();
|
||||
}
|
||||
};
|
||||
|
||||
struct TestCastAsOutput
|
||||
{
|
||||
template <typename CastFromType>
|
||||
VTKM_CONT void operator()(CastFromType vtkmNotUsed(type)) const
|
||||
{
|
||||
vtkm::cont::Invoker invoke;
|
||||
|
||||
using InputArrayType = vtkm::cont::ArrayHandleIndex;
|
||||
using ResultArrayType = vtkm::cont::ArrayHandle<CastFromType>;
|
||||
|
||||
InputArrayType input(ARRAY_SIZE);
|
||||
|
||||
ResultArrayType result;
|
||||
vtkm::cont::ArrayHandleCast<vtkm::Id, ResultArrayType> castArray =
|
||||
vtkm::cont::make_ArrayHandleCast<CastFromType>(result);
|
||||
|
||||
invoke(PassThrough{}, input, castArray);
|
||||
|
||||
// verify results
|
||||
vtkm::Id length = ARRAY_SIZE;
|
||||
auto inputPortal = input.ReadPortal();
|
||||
auto resultPortal = result.ReadPortal();
|
||||
for (vtkm::Id i = 0; i < length; ++i)
|
||||
{
|
||||
VTKM_TEST_ASSERT(inputPortal.Get(i) == static_cast<vtkm::Id>(resultPortal.Get(i)),
|
||||
"Casting ArrayHandle Failed");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
void Run()
|
||||
{
|
||||
using CastTypesToTest = vtkm::List<vtkm::Int32, vtkm::UInt32>;
|
||||
|
||||
std::cout << "-------------------------------------------" << std::endl;
|
||||
std::cout << "Testing ArrayHandleCast as Input" << std::endl;
|
||||
vtkm::testing::Testing::TryTypes(TestCastAsInput(), CastTypesToTest());
|
||||
|
||||
std::cout << "-------------------------------------------" << std::endl;
|
||||
std::cout << "Testing ArrayHandleCast as Output" << std::endl;
|
||||
vtkm::testing::Testing::TryTypes(TestCastAsOutput(), CastTypesToTest());
|
||||
}
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
int UnitTestArrayHandleCast(int argc, char* argv[])
|
||||
{
|
||||
return vtkm::cont::testing::Testing::Run(Run, argc, argv);
|
||||
}
|
@ -10,16 +10,101 @@
|
||||
|
||||
#include <vtkm/cont/ArrayHandleConcatenate.h>
|
||||
#include <vtkm/cont/ArrayHandleIndex.h>
|
||||
#include <vtkm/cont/Invoker.h>
|
||||
|
||||
#include <vtkm/worklet/WorkletMapField.h>
|
||||
|
||||
#include <vtkm/cont/testing/Testing.h>
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
constexpr vtkm::Id ARRAY_SIZE = 4;
|
||||
constexpr vtkm::Id ARRAY_SIZE = 10;
|
||||
|
||||
template <typename ValueType>
|
||||
struct IndexSquared
|
||||
{
|
||||
VTKM_EXEC_CONT
|
||||
ValueType operator()(vtkm::Id index) const
|
||||
{
|
||||
using ComponentType = typename vtkm::VecTraits<ValueType>::ComponentType;
|
||||
return ValueType(static_cast<ComponentType>(index * index));
|
||||
}
|
||||
};
|
||||
|
||||
struct PassThrough : public vtkm::worklet::WorkletMapField
|
||||
{
|
||||
using ControlSignature = void(FieldIn, FieldOut);
|
||||
using ExecutionSignature = void(_1, _2);
|
||||
|
||||
template <typename InValue, typename OutValue>
|
||||
VTKM_EXEC void operator()(const InValue& inValue, OutValue& outValue) const
|
||||
{
|
||||
outValue = inValue;
|
||||
}
|
||||
};
|
||||
|
||||
VTKM_CONT void TestConcatInvoke()
|
||||
{
|
||||
using ValueType = vtkm::Id;
|
||||
using FunctorType = IndexSquared<ValueType>;
|
||||
|
||||
using ValueHandleType = vtkm::cont::ArrayHandleImplicit<FunctorType>;
|
||||
using BasicArrayType = vtkm::cont::ArrayHandle<ValueType>;
|
||||
using ConcatenateType = vtkm::cont::ArrayHandleConcatenate<ValueHandleType, BasicArrayType>;
|
||||
|
||||
FunctorType functor;
|
||||
for (vtkm::Id start_pos = 0; start_pos < ARRAY_SIZE; start_pos += ARRAY_SIZE / 4)
|
||||
{
|
||||
vtkm::Id implicitLen = ARRAY_SIZE - start_pos;
|
||||
vtkm::Id basicLen = start_pos;
|
||||
|
||||
// make an implicit array
|
||||
ValueHandleType implicit = vtkm::cont::make_ArrayHandleImplicit(functor, implicitLen);
|
||||
// make a basic array
|
||||
std::vector<ValueType> basicVec;
|
||||
for (vtkm::Id i = 0; i < basicLen; i++)
|
||||
{
|
||||
basicVec.push_back(ValueType(i));
|
||||
}
|
||||
BasicArrayType basic = vtkm::cont::make_ArrayHandle(basicVec, vtkm::CopyFlag::Off);
|
||||
|
||||
// concatenate two arrays together
|
||||
ConcatenateType concatenate = vtkm::cont::make_ArrayHandleConcatenate(implicit, basic);
|
||||
|
||||
vtkm::cont::ArrayHandle<ValueType> result;
|
||||
|
||||
vtkm::cont::Invoker invoke;
|
||||
invoke(PassThrough{}, concatenate, result);
|
||||
|
||||
//verify that the control portal works
|
||||
auto resultPortal = result.ReadPortal();
|
||||
auto implicitPortal = implicit.ReadPortal();
|
||||
auto basicPortal = basic.ReadPortal();
|
||||
auto concatPortal = concatenate.ReadPortal();
|
||||
for (vtkm::Id i = 0; i < ARRAY_SIZE; ++i)
|
||||
{
|
||||
const ValueType result_v = resultPortal.Get(i);
|
||||
ValueType correct_value;
|
||||
if (i < implicitLen)
|
||||
correct_value = implicitPortal.Get(i);
|
||||
else
|
||||
correct_value = basicPortal.Get(i - implicitLen);
|
||||
const ValueType control_value = concatPortal.Get(i);
|
||||
VTKM_TEST_ASSERT(test_equal(result_v, correct_value),
|
||||
"ArrayHandleConcatenate as Input Failed");
|
||||
VTKM_TEST_ASSERT(test_equal(result_v, control_value),
|
||||
"ArrayHandleConcatenate as Input Failed");
|
||||
}
|
||||
|
||||
concatenate.ReleaseResources();
|
||||
}
|
||||
}
|
||||
|
||||
void TestConcatOfConcat()
|
||||
{
|
||||
std::cout << "Test concat of concat" << std::endl;
|
||||
|
||||
vtkm::cont::ArrayHandleIndex array1(ARRAY_SIZE);
|
||||
vtkm::cont::ArrayHandleIndex array2(2 * ARRAY_SIZE);
|
||||
|
||||
@ -56,6 +141,8 @@ void TestConcatOfConcat()
|
||||
|
||||
void TestConcatenateEmptyArray()
|
||||
{
|
||||
std::cout << "Test empty array" << std::endl;
|
||||
|
||||
std::vector<vtkm::Float64> vec;
|
||||
for (vtkm::Id i = 0; i < ARRAY_SIZE; i++)
|
||||
{
|
||||
@ -80,6 +167,8 @@ void TestConcatenateEmptyArray()
|
||||
|
||||
void TestConcatenateFill()
|
||||
{
|
||||
std::cout << "Test fill" << std::endl;
|
||||
|
||||
using T = vtkm::FloatDefault;
|
||||
vtkm::cont::ArrayHandle<T> array1;
|
||||
vtkm::cont::ArrayHandle<T> array2;
|
||||
@ -117,6 +206,7 @@ void TestConcatenateFill()
|
||||
|
||||
void TestArrayHandleConcatenate()
|
||||
{
|
||||
TestConcatInvoke();
|
||||
TestConcatOfConcat();
|
||||
TestConcatenateEmptyArray();
|
||||
TestConcatenateFill();
|
||||
|
82
vtkm/cont/testing/UnitTestArrayHandleConstant.cxx
Normal file
82
vtkm/cont/testing/UnitTestArrayHandleConstant.cxx
Normal file
@ -0,0 +1,82 @@
|
||||
//============================================================================
|
||||
// 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/ArrayHandleConstant.h>
|
||||
|
||||
#include <vtkm/cont/Invoker.h>
|
||||
|
||||
#include <vtkm/worklet/WorkletMapField.h>
|
||||
|
||||
#include <vtkm/cont/testing/Testing.h>
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
constexpr vtkm::Id ARRAY_SIZE = 10;
|
||||
|
||||
using HandleTypesToTest = vtkm::List<vtkm::Id, vtkm::Vec2i_32, vtkm::FloatDefault, vtkm::Vec3f_64>;
|
||||
|
||||
struct PassThrough : public vtkm::worklet::WorkletMapField
|
||||
{
|
||||
using ControlSignature = void(FieldIn, FieldOut);
|
||||
using ExecutionSignature = void(_1, _2);
|
||||
|
||||
template <typename InValue, typename OutValue>
|
||||
VTKM_EXEC void operator()(const InValue& inValue, OutValue& outValue) const
|
||||
{
|
||||
outValue = inValue;
|
||||
}
|
||||
};
|
||||
|
||||
struct TestConstantAsInput
|
||||
{
|
||||
template <typename ValueType>
|
||||
VTKM_CONT void operator()(const ValueType vtkmNotUsed(v)) const
|
||||
{
|
||||
const ValueType value = TestValue(43, ValueType());
|
||||
|
||||
vtkm::cont::ArrayHandleConstant<ValueType> constant =
|
||||
vtkm::cont::make_ArrayHandleConstant(value, ARRAY_SIZE);
|
||||
|
||||
VTKM_TEST_ASSERT(constant.GetValue() == value);
|
||||
|
||||
vtkm::cont::ArrayHandle<ValueType> result;
|
||||
|
||||
vtkm::cont::Invoker invoke;
|
||||
invoke(PassThrough{}, constant, result);
|
||||
|
||||
//verify that the control portal works
|
||||
auto resultPortal = result.ReadPortal();
|
||||
auto constantPortal = constant.ReadPortal();
|
||||
for (vtkm::Id i = 0; i < ARRAY_SIZE; ++i)
|
||||
{
|
||||
const ValueType result_v = resultPortal.Get(i);
|
||||
const ValueType control_value = constantPortal.Get(i);
|
||||
VTKM_TEST_ASSERT(test_equal(result_v, value), "Counting Handle Failed");
|
||||
VTKM_TEST_ASSERT(test_equal(result_v, control_value), "Counting Handle Control Failed");
|
||||
}
|
||||
|
||||
constant.ReleaseResources();
|
||||
}
|
||||
};
|
||||
|
||||
void Run()
|
||||
{
|
||||
std::cout << "-------------------------------------------" << std::endl;
|
||||
std::cout << "Testing ArrayHandleConstant as Input" << std::endl;
|
||||
vtkm::testing::Testing::TryTypes(TestConstantAsInput(), HandleTypesToTest());
|
||||
}
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
int UnitTestArrayHandleConstant(int argc, char* argv[])
|
||||
{
|
||||
return vtkm::cont::testing::Testing::Run(Run, argc, argv);
|
||||
}
|
150
vtkm/cont/testing/UnitTestArrayHandleGroupVec.cxx
Normal file
150
vtkm/cont/testing/UnitTestArrayHandleGroupVec.cxx
Normal file
@ -0,0 +1,150 @@
|
||||
//============================================================================
|
||||
// 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/ArrayHandleGroupVec.h>
|
||||
|
||||
#include <vtkm/cont/Invoker.h>
|
||||
|
||||
#include <vtkm/worklet/WorkletMapField.h>
|
||||
|
||||
#include <vtkm/cont/testing/Testing.h>
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
constexpr vtkm::Id ARRAY_SIZE = 10;
|
||||
|
||||
struct PassThrough : vtkm::worklet::WorkletMapField
|
||||
{
|
||||
using ControlSignature = void(FieldIn, FieldOut);
|
||||
using ExecutionSignature = void(_1, _2);
|
||||
|
||||
template <typename InValue, typename OutValue>
|
||||
VTKM_EXEC void operator()(const InValue& inValue, OutValue& outValue) const
|
||||
{
|
||||
outValue = inValue;
|
||||
}
|
||||
};
|
||||
|
||||
template <vtkm::IdComponent NUM_COMPONENTS>
|
||||
struct TestGroupVecAsInput
|
||||
{
|
||||
template <typename ComponentType>
|
||||
VTKM_CONT void operator()(ComponentType) const
|
||||
{
|
||||
using ValueType = vtkm::Vec<ComponentType, NUM_COMPONENTS>;
|
||||
|
||||
vtkm::cont::ArrayHandle<ComponentType> baseArray;
|
||||
baseArray.Allocate(ARRAY_SIZE * NUM_COMPONENTS);
|
||||
SetPortal(baseArray.WritePortal());
|
||||
|
||||
vtkm::cont::ArrayHandleGroupVec<vtkm::cont::ArrayHandle<ComponentType>, NUM_COMPONENTS>
|
||||
groupArray(baseArray);
|
||||
VTKM_TEST_ASSERT(groupArray.GetNumberOfValues() == ARRAY_SIZE,
|
||||
"Group array reporting wrong array size.");
|
||||
|
||||
vtkm::cont::ArrayHandle<ValueType> resultArray;
|
||||
|
||||
vtkm::worklet::DispatcherMapField<PassThrough> dispatcher;
|
||||
dispatcher.Invoke(groupArray, resultArray);
|
||||
|
||||
VTKM_TEST_ASSERT(resultArray.GetNumberOfValues() == ARRAY_SIZE, "Got bad result array size.");
|
||||
|
||||
//verify that the control portal works
|
||||
vtkm::Id totalIndex = 0;
|
||||
auto resultPortal = resultArray.ReadPortal();
|
||||
for (vtkm::Id index = 0; index < ARRAY_SIZE; ++index)
|
||||
{
|
||||
const ValueType result = resultPortal.Get(index);
|
||||
for (vtkm::IdComponent componentIndex = 0; componentIndex < NUM_COMPONENTS; componentIndex++)
|
||||
{
|
||||
const ComponentType expectedValue = TestValue(totalIndex, ComponentType());
|
||||
VTKM_TEST_ASSERT(test_equal(result[componentIndex], expectedValue),
|
||||
"Result array got wrong value.");
|
||||
totalIndex++;
|
||||
}
|
||||
}
|
||||
|
||||
groupArray.ReleaseResources();
|
||||
}
|
||||
};
|
||||
|
||||
template <vtkm::IdComponent NUM_COMPONENTS>
|
||||
struct TestGroupVecAsOutput
|
||||
{
|
||||
template <typename ComponentType>
|
||||
VTKM_CONT void operator()(ComponentType) const
|
||||
{
|
||||
using ValueType = vtkm::Vec<ComponentType, NUM_COMPONENTS>;
|
||||
|
||||
vtkm::cont::ArrayHandle<ValueType> baseArray;
|
||||
baseArray.Allocate(ARRAY_SIZE);
|
||||
SetPortal(baseArray.WritePortal());
|
||||
|
||||
vtkm::cont::ArrayHandle<ComponentType> resultArray;
|
||||
|
||||
vtkm::cont::ArrayHandleGroupVec<vtkm::cont::ArrayHandle<ComponentType>, NUM_COMPONENTS>
|
||||
groupArray(resultArray);
|
||||
|
||||
vtkm::worklet::DispatcherMapField<PassThrough> dispatcher;
|
||||
dispatcher.Invoke(baseArray, groupArray);
|
||||
|
||||
VTKM_TEST_ASSERT(groupArray.GetNumberOfValues() == ARRAY_SIZE,
|
||||
"Group array reporting wrong array size.");
|
||||
|
||||
VTKM_TEST_ASSERT(resultArray.GetNumberOfValues() == ARRAY_SIZE * NUM_COMPONENTS,
|
||||
"Got bad result array size.");
|
||||
|
||||
//verify that the control portal works
|
||||
vtkm::Id totalIndex = 0;
|
||||
auto resultPortal = resultArray.ReadPortal();
|
||||
for (vtkm::Id index = 0; index < ARRAY_SIZE; ++index)
|
||||
{
|
||||
const ValueType expectedValue = TestValue(index, ValueType());
|
||||
for (vtkm::IdComponent componentIndex = 0; componentIndex < NUM_COMPONENTS; componentIndex++)
|
||||
{
|
||||
const ComponentType result = resultPortal.Get(totalIndex);
|
||||
VTKM_TEST_ASSERT(test_equal(result, expectedValue[componentIndex]),
|
||||
"Result array got wrong value.");
|
||||
totalIndex++;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
void Run()
|
||||
{
|
||||
using HandleTypesToTest =
|
||||
vtkm::List<vtkm::Id, vtkm::Vec2i_32, vtkm::FloatDefault, vtkm::Vec3f_64>;
|
||||
using ScalarTypesToTest = vtkm::List<vtkm::UInt8, vtkm::FloatDefault>;
|
||||
|
||||
std::cout << "-------------------------------------------" << std::endl;
|
||||
std::cout << "Testing ArrayHandleGroupVec<3> as Input" << std::endl;
|
||||
vtkm::testing::Testing::TryTypes(TestGroupVecAsInput<3>(), HandleTypesToTest());
|
||||
|
||||
std::cout << "-------------------------------------------" << std::endl;
|
||||
std::cout << "Testing ArrayHandleGroupVec<4> as Input" << std::endl;
|
||||
vtkm::testing::Testing::TryTypes(TestGroupVecAsInput<4>(), HandleTypesToTest());
|
||||
|
||||
std::cout << "-------------------------------------------" << std::endl;
|
||||
std::cout << "Testing ArrayHandleGroupVec<2> as Output" << std::endl;
|
||||
vtkm::testing::Testing::TryTypes(TestGroupVecAsOutput<2>(), ScalarTypesToTest());
|
||||
|
||||
std::cout << "-------------------------------------------" << std::endl;
|
||||
std::cout << "Testing ArrayHandleGroupVec<3> as Output" << std::endl;
|
||||
vtkm::testing::Testing::TryTypes(TestGroupVecAsOutput<3>(), ScalarTypesToTest());
|
||||
}
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
int UnitTestArrayHandleGroupVec(int argc, char* argv[])
|
||||
{
|
||||
return vtkm::cont::testing::Testing::Run(Run, argc, argv);
|
||||
}
|
155
vtkm/cont/testing/UnitTestArrayHandleGroupVecVariable.cxx
Normal file
155
vtkm/cont/testing/UnitTestArrayHandleGroupVecVariable.cxx
Normal file
@ -0,0 +1,155 @@
|
||||
//============================================================================
|
||||
// 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/ArrayHandleGroupVecVariable.h>
|
||||
|
||||
#include <vtkm/cont/ArrayCopy.h>
|
||||
#include <vtkm/cont/ConvertNumComponentsToOffsets.h>
|
||||
#include <vtkm/cont/Invoker.h>
|
||||
|
||||
#include <vtkm/worklet/WorkletMapField.h>
|
||||
|
||||
#include <vtkm/cont/testing/Testing.h>
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
constexpr vtkm::Id ARRAY_SIZE = 10;
|
||||
|
||||
// GroupVecVariable is a bit strange because it supports values of different
|
||||
// lengths, so a simple pass through worklet will not work. Use custom
|
||||
// worklets.
|
||||
struct GroupVariableInputWorklet : public vtkm::worklet::WorkletMapField
|
||||
{
|
||||
using ControlSignature = void(FieldIn, FieldOut);
|
||||
using ExecutionSignature = void(_1, WorkIndex, _2);
|
||||
|
||||
template <typename InputType>
|
||||
VTKM_EXEC void operator()(const InputType& input, vtkm::Id workIndex, vtkm::Id& dummyOut) const
|
||||
{
|
||||
using ComponentType = typename InputType::ComponentType;
|
||||
vtkm::IdComponent expectedSize = static_cast<vtkm::IdComponent>(workIndex);
|
||||
if (expectedSize != input.GetNumberOfComponents())
|
||||
{
|
||||
this->RaiseError("Got unexpected number of components.");
|
||||
}
|
||||
|
||||
vtkm::Id valueIndex = workIndex * (workIndex - 1) / 2;
|
||||
dummyOut = valueIndex;
|
||||
for (vtkm::IdComponent componentIndex = 0; componentIndex < expectedSize; componentIndex++)
|
||||
{
|
||||
ComponentType expectedValue = TestValue(valueIndex, ComponentType());
|
||||
if (vtkm::Abs(expectedValue - input[componentIndex]) > 0.000001)
|
||||
{
|
||||
this->RaiseError("Got bad value in GroupVariableInputWorklet.");
|
||||
}
|
||||
valueIndex++;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
struct TestGroupVecVariableAsInput
|
||||
{
|
||||
template <typename ComponentType>
|
||||
VTKM_CONT void operator()(ComponentType) const
|
||||
{
|
||||
vtkm::cont::Invoker invoke;
|
||||
vtkm::Id sourceArraySize;
|
||||
|
||||
vtkm::cont::ArrayHandle<vtkm::Id> numComponentsArray;
|
||||
vtkm::cont::ArrayCopy(vtkm::cont::ArrayHandleIndex(ARRAY_SIZE), numComponentsArray);
|
||||
vtkm::cont::ArrayHandle<vtkm::Id> offsetsArray =
|
||||
vtkm::cont::ConvertNumComponentsToOffsets(numComponentsArray, sourceArraySize);
|
||||
|
||||
vtkm::cont::ArrayHandle<ComponentType> sourceArray;
|
||||
sourceArray.Allocate(sourceArraySize);
|
||||
SetPortal(sourceArray.WritePortal());
|
||||
|
||||
vtkm::cont::ArrayHandle<vtkm::Id> dummyArray;
|
||||
|
||||
auto groupVecArray = vtkm::cont::make_ArrayHandleGroupVecVariable(sourceArray, offsetsArray);
|
||||
|
||||
invoke(GroupVariableInputWorklet{}, groupVecArray, dummyArray);
|
||||
|
||||
dummyArray.ReadPortal();
|
||||
|
||||
groupVecArray.ReleaseResources();
|
||||
}
|
||||
};
|
||||
|
||||
// GroupVecVariable is a bit strange because it supports values of different
|
||||
// lengths, so a simple pass through worklet will not work. Use custom
|
||||
// worklets.
|
||||
struct GroupVariableOutputWorklet : public vtkm::worklet::WorkletMapField
|
||||
{
|
||||
using ControlSignature = void(FieldIn, FieldOut);
|
||||
using ExecutionSignature = void(_2, WorkIndex);
|
||||
|
||||
template <typename OutputType>
|
||||
VTKM_EXEC void operator()(OutputType& output, vtkm::Id workIndex) const
|
||||
{
|
||||
using ComponentType = typename OutputType::ComponentType;
|
||||
vtkm::IdComponent expectedSize = static_cast<vtkm::IdComponent>(workIndex);
|
||||
if (expectedSize != output.GetNumberOfComponents())
|
||||
{
|
||||
this->RaiseError("Got unexpected number of components.");
|
||||
}
|
||||
|
||||
vtkm::Id valueIndex = workIndex * (workIndex - 1) / 2;
|
||||
for (vtkm::IdComponent componentIndex = 0; componentIndex < expectedSize; componentIndex++)
|
||||
{
|
||||
output[componentIndex] = TestValue(valueIndex, ComponentType());
|
||||
valueIndex++;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
struct TestGroupVecVariableAsOutput
|
||||
{
|
||||
template <typename ComponentType>
|
||||
VTKM_CONT void operator()(ComponentType) const
|
||||
{
|
||||
vtkm::Id sourceArraySize;
|
||||
|
||||
vtkm::cont::ArrayHandle<vtkm::Id> numComponentsArray;
|
||||
vtkm::cont::ArrayCopy(vtkm::cont::ArrayHandleIndex(ARRAY_SIZE), numComponentsArray);
|
||||
vtkm::cont::ArrayHandle<vtkm::Id> offsetsArray =
|
||||
vtkm::cont::ConvertNumComponentsToOffsets(numComponentsArray, sourceArraySize);
|
||||
|
||||
vtkm::cont::ArrayHandle<ComponentType> sourceArray;
|
||||
sourceArray.Allocate(sourceArraySize);
|
||||
|
||||
vtkm::worklet::DispatcherMapField<GroupVariableOutputWorklet> dispatcher;
|
||||
dispatcher.Invoke(vtkm::cont::ArrayHandleIndex(ARRAY_SIZE),
|
||||
vtkm::cont::make_ArrayHandleGroupVecVariable(sourceArray, offsetsArray));
|
||||
|
||||
CheckPortal(sourceArray.ReadPortal());
|
||||
}
|
||||
};
|
||||
|
||||
void Run()
|
||||
{
|
||||
using ScalarTypesToTest = vtkm::List<vtkm::UInt8, vtkm::FloatDefault>;
|
||||
|
||||
std::cout << "-------------------------------------------" << std::endl;
|
||||
std::cout << "Testing ArrayHandleGroupVecVariable as Input" << std::endl;
|
||||
vtkm::testing::Testing::TryTypes(TestGroupVecVariableAsInput(), ScalarTypesToTest());
|
||||
|
||||
std::cout << "-------------------------------------------" << std::endl;
|
||||
std::cout << "Testing ArrayHandleGroupVecVariable as Output" << std::endl;
|
||||
vtkm::testing::Testing::TryTypes(TestGroupVecVariableAsOutput(), ScalarTypesToTest());
|
||||
}
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
int UnitTestArrayHandleGroupVecVariable(int argc, char* argv[])
|
||||
{
|
||||
return vtkm::cont::testing::Testing::Run(Run, argc, argv);
|
||||
}
|
@ -10,8 +10,11 @@
|
||||
|
||||
#include <vtkm/cont/ArrayHandle.h>
|
||||
#include <vtkm/cont/ArrayHandleImplicit.h>
|
||||
#include <vtkm/cont/Invoker.h>
|
||||
#include <vtkm/cont/serial/DeviceAdapterSerial.h>
|
||||
|
||||
#include <vtkm/worklet/WorkletMapField.h>
|
||||
|
||||
#include <vtkm/VecTraits.h>
|
||||
|
||||
#include <vtkm/cont/testing/Testing.h>
|
||||
@ -32,6 +35,18 @@ struct IndexSquared
|
||||
}
|
||||
};
|
||||
|
||||
struct PassThrough : public vtkm::worklet::WorkletMapField
|
||||
{
|
||||
using ControlSignature = void(FieldIn, FieldOut);
|
||||
using ExecutionSignature = void(_1, _2);
|
||||
|
||||
template <typename InValue, typename OutValue>
|
||||
VTKM_EXEC void operator()(const InValue& inValue, OutValue& outValue) const
|
||||
{
|
||||
outValue = inValue;
|
||||
}
|
||||
};
|
||||
|
||||
struct ImplicitTests
|
||||
{
|
||||
template <typename ValueType>
|
||||
@ -44,7 +59,7 @@ struct ImplicitTests
|
||||
|
||||
ImplicitHandle implicit = vtkm::cont::make_ArrayHandleImplicit(functor, ARRAY_SIZE);
|
||||
|
||||
//verify that the control portal works
|
||||
std::cout << "verify that the control portal works" << std::endl;
|
||||
auto implicitPortal = implicit.ReadPortal();
|
||||
for (int i = 0; i < ARRAY_SIZE; ++i)
|
||||
{
|
||||
@ -53,7 +68,7 @@ struct ImplicitTests
|
||||
VTKM_TEST_ASSERT(v == correct_value, "Implicit Handle Failed");
|
||||
}
|
||||
|
||||
//verify that the execution portal works
|
||||
std::cout << "verify that the execution portal works" << std::endl;
|
||||
vtkm::cont::Token token;
|
||||
using Device = vtkm::cont::DeviceAdapterTagSerial;
|
||||
using CEPortal = typename ImplicitHandle::ReadPortalType;
|
||||
@ -64,6 +79,18 @@ struct ImplicitTests
|
||||
const ValueType correct_value = functor(i);
|
||||
VTKM_TEST_ASSERT(v == correct_value, "Implicit Handle Failed");
|
||||
}
|
||||
|
||||
std::cout << "verify that the array handle works in a worklet on the device" << std::endl;
|
||||
vtkm::cont::Invoker invoke;
|
||||
vtkm::cont::ArrayHandle<ValueType> result;
|
||||
invoke(PassThrough{}, implicit, result);
|
||||
auto resultPortal = result.ReadPortal();
|
||||
for (int i = 0; i < ARRAY_SIZE; ++i)
|
||||
{
|
||||
const ValueType value = resultPortal.Get(i);
|
||||
const ValueType correctValue = functor(i);
|
||||
VTKM_TEST_ASSERT(test_equal(value, correctValue));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
183
vtkm/cont/testing/UnitTestArrayHandleMultiplexer.cxx
Normal file
183
vtkm/cont/testing/UnitTestArrayHandleMultiplexer.cxx
Normal file
@ -0,0 +1,183 @@
|
||||
//============================================================================
|
||||
// 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.
|
||||
//============================================================================
|
||||
#ifndef vtk_m_cont_testing_TestingArrayHandleMultiplexer_h
|
||||
#define vtk_m_cont_testing_TestingArrayHandleMultiplexer_h
|
||||
|
||||
#include <vtkm/cont/Algorithm.h>
|
||||
#include <vtkm/cont/ArrayHandleConstant.h>
|
||||
#include <vtkm/cont/ArrayHandleCounting.h>
|
||||
#include <vtkm/cont/ArrayHandleImplicit.h>
|
||||
#include <vtkm/cont/ArrayHandleMultiplexer.h>
|
||||
#include <vtkm/cont/ArrayHandleUniformPointCoordinates.h>
|
||||
|
||||
#include <vtkm/BinaryOperators.h>
|
||||
|
||||
#include <vtkm/cont/testing/Testing.h>
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
template <typename T>
|
||||
struct TestValueFunctor
|
||||
{
|
||||
VTKM_EXEC_CONT T operator()(vtkm::Id index) const { return TestValue(index, T()); }
|
||||
};
|
||||
|
||||
constexpr vtkm::Id ARRAY_SIZE = 10;
|
||||
|
||||
template <typename... Ts0, typename... Ts1>
|
||||
static void CheckArray(const vtkm::cont::ArrayHandleMultiplexer<Ts0...>& multiplexerArray,
|
||||
const vtkm::cont::ArrayHandle<Ts1...>& expectedArray)
|
||||
{
|
||||
using T = typename std::remove_reference<decltype(multiplexerArray)>::type::ValueType;
|
||||
|
||||
vtkm::cont::printSummary_ArrayHandle(multiplexerArray, std::cout);
|
||||
VTKM_TEST_ASSERT(test_equal_portals(multiplexerArray.ReadPortal(), expectedArray.ReadPortal()),
|
||||
"Multiplexer array gave wrong result in control environment");
|
||||
|
||||
vtkm::cont::ArrayHandle<T> copy;
|
||||
vtkm::cont::Algorithm::Copy(multiplexerArray, copy);
|
||||
VTKM_TEST_ASSERT(test_equal_portals(copy.ReadPortal(), expectedArray.ReadPortal()),
|
||||
"Multiplexer did not copy correctly in execution environment");
|
||||
}
|
||||
|
||||
void BasicSwitch()
|
||||
{
|
||||
std::cout << "\n--- Basic switch" << std::endl;
|
||||
|
||||
using ValueType = vtkm::FloatDefault;
|
||||
|
||||
using ArrayType1 = vtkm::cont::ArrayHandleConstant<ValueType>;
|
||||
ArrayType1 array1(TestValue(0, vtkm::FloatDefault{}), ARRAY_SIZE);
|
||||
|
||||
using ArrayType2 = vtkm::cont::ArrayHandleCounting<ValueType>;
|
||||
ArrayType2 array2(TestValue(1, vtkm::FloatDefault{}), 1.0f, ARRAY_SIZE);
|
||||
|
||||
auto array3 = vtkm::cont::make_ArrayHandleImplicit(TestValueFunctor<ValueType>{}, ARRAY_SIZE);
|
||||
using ArrayType3 = decltype(array3);
|
||||
|
||||
vtkm::cont::ArrayHandleMultiplexer<ArrayType1, ArrayType2, ArrayType3> multiplexer;
|
||||
|
||||
std::cout << "Check array1" << std::endl;
|
||||
multiplexer = array1;
|
||||
CheckArray(multiplexer, array1);
|
||||
|
||||
std::cout << "Check array2" << std::endl;
|
||||
multiplexer = array2;
|
||||
CheckArray(multiplexer, array2);
|
||||
|
||||
std::cout << "Check array3" << std::endl;
|
||||
multiplexer = array3;
|
||||
CheckArray(multiplexer, array3);
|
||||
}
|
||||
|
||||
void Reduce()
|
||||
{
|
||||
// Regression test for an issue with compiling ArrayHandleMultiplexer with the thrust reduce
|
||||
// algorithm on CUDA. Most likely related to:
|
||||
// https://github.com/thrust/thrust/issues/928
|
||||
// https://github.com/thrust/thrust/issues/1044
|
||||
std::cout << "\n--- Reduce" << std::endl;
|
||||
|
||||
using ValueType = vtkm::Vec3f;
|
||||
using MultiplexerType = vtkm::cont::ArrayHandleMultiplexer<
|
||||
vtkm::cont::ArrayHandleConstant<ValueType>,
|
||||
vtkm::cont::ArrayHandleCounting<ValueType>,
|
||||
vtkm::cont::ArrayHandle<ValueType>,
|
||||
vtkm::cont::ArrayHandleUniformPointCoordinates,
|
||||
vtkm::cont::ArrayHandleCartesianProduct<vtkm::cont::ArrayHandle<vtkm::FloatDefault>,
|
||||
vtkm::cont::ArrayHandle<vtkm::FloatDefault>,
|
||||
vtkm::cont::ArrayHandle<vtkm::FloatDefault>>>;
|
||||
|
||||
MultiplexerType multiplexer =
|
||||
vtkm::cont::ArrayHandleCounting<ValueType>(vtkm::Vec3f(1), vtkm::Vec3f(1), ARRAY_SIZE);
|
||||
|
||||
{
|
||||
std::cout << "Basic Reduce" << std::endl;
|
||||
ValueType result = vtkm::cont::Algorithm::Reduce(multiplexer, ValueType(0.0));
|
||||
VTKM_TEST_ASSERT(test_equal(result, ValueType(0.5 * (ARRAY_SIZE * (ARRAY_SIZE + 1)))));
|
||||
}
|
||||
|
||||
{
|
||||
std::cout << "Reduce with custom operator" << std::endl;
|
||||
vtkm::Vec<ValueType, 2> initial(ValueType(10000), ValueType(0));
|
||||
vtkm::Vec<ValueType, 2> result =
|
||||
vtkm::cont::Algorithm::Reduce(multiplexer, initial, vtkm::MinAndMax<ValueType>{});
|
||||
VTKM_TEST_ASSERT(test_equal(result[0], ValueType(1)));
|
||||
VTKM_TEST_ASSERT(test_equal(result[1], ValueType(static_cast<vtkm::FloatDefault>(ARRAY_SIZE))));
|
||||
}
|
||||
}
|
||||
|
||||
void Fill()
|
||||
{
|
||||
std::cout << "\n--- Fill" << std::endl;
|
||||
|
||||
using ValueType = vtkm::Vec3f;
|
||||
using MultiplexerType = vtkm::cont::ArrayHandleMultiplexer<
|
||||
vtkm::cont::ArrayHandleConstant<ValueType>,
|
||||
vtkm::cont::ArrayHandleCounting<ValueType>,
|
||||
vtkm::cont::ArrayHandle<ValueType>,
|
||||
vtkm::cont::ArrayHandleUniformPointCoordinates,
|
||||
vtkm::cont::ArrayHandleCartesianProduct<vtkm::cont::ArrayHandle<vtkm::FloatDefault>,
|
||||
vtkm::cont::ArrayHandle<vtkm::FloatDefault>,
|
||||
vtkm::cont::ArrayHandle<vtkm::FloatDefault>>>;
|
||||
|
||||
const ValueType testValue1 = TestValue(1, ValueType{});
|
||||
const ValueType testValue2 = TestValue(2, ValueType{});
|
||||
|
||||
MultiplexerType multiplexer = vtkm::cont::ArrayHandle<ValueType>{};
|
||||
|
||||
multiplexer.AllocateAndFill(ARRAY_SIZE, testValue1);
|
||||
{
|
||||
auto portal = multiplexer.ReadPortal();
|
||||
VTKM_TEST_ASSERT(portal.GetNumberOfValues() == ARRAY_SIZE);
|
||||
for (vtkm::Id index = 0; index < ARRAY_SIZE; ++index)
|
||||
{
|
||||
VTKM_TEST_ASSERT(portal.Get(index) == testValue1);
|
||||
}
|
||||
}
|
||||
|
||||
vtkm::cont::ArrayHandle<vtkm::FloatDefault> array1;
|
||||
array1.Allocate(ARRAY_SIZE);
|
||||
vtkm::cont::ArrayHandle<vtkm::FloatDefault> array2;
|
||||
array2.Allocate(ARRAY_SIZE);
|
||||
vtkm::cont::ArrayHandle<vtkm::FloatDefault> array3;
|
||||
array3.Allocate(ARRAY_SIZE);
|
||||
multiplexer = vtkm::cont::make_ArrayHandleCartesianProduct(array1, array2, array3);
|
||||
|
||||
multiplexer.Fill(testValue2);
|
||||
{
|
||||
auto portal1 = array1.ReadPortal();
|
||||
auto portal2 = array2.ReadPortal();
|
||||
auto portal3 = array3.ReadPortal();
|
||||
for (vtkm::Id index = 0; index < ARRAY_SIZE; ++index)
|
||||
{
|
||||
VTKM_TEST_ASSERT(portal1.Get(index) == testValue2[0]);
|
||||
VTKM_TEST_ASSERT(portal2.Get(index) == testValue2[1]);
|
||||
VTKM_TEST_ASSERT(portal3.Get(index) == testValue2[2]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TestAll()
|
||||
{
|
||||
BasicSwitch();
|
||||
Reduce();
|
||||
Fill();
|
||||
}
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
int UnitTestArrayHandleMultiplexer(int argc, char* argv[])
|
||||
{
|
||||
return vtkm::cont::testing::Testing::Run(TestAll, argc, argv);
|
||||
}
|
||||
|
||||
#endif //vtk_m_cont_testing_TestingArrayHandleMultiplexer_h
|
109
vtkm/cont/testing/UnitTestArrayHandleRecombineVec.cxx
Normal file
109
vtkm/cont/testing/UnitTestArrayHandleRecombineVec.cxx
Normal file
@ -0,0 +1,109 @@
|
||||
//============================================================================
|
||||
// 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/ArrayHandleRecombineVec.h>
|
||||
|
||||
#include <vtkm/cont/Invoker.h>
|
||||
|
||||
#include <vtkm/worklet/WorkletMapField.h>
|
||||
|
||||
#include <vtkm/cont/testing/Testing.h>
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
constexpr vtkm::Id ARRAY_SIZE = 10;
|
||||
|
||||
struct PassThrough : vtkm::worklet::WorkletMapField
|
||||
{
|
||||
using ControlSignature = void(FieldIn, FieldOut);
|
||||
using ExecutionSignature = void(_1, _2);
|
||||
|
||||
template <typename InValue, typename OutValue>
|
||||
VTKM_EXEC void operator()(const InValue& inValue, OutValue& outValue) const
|
||||
{
|
||||
outValue = inValue;
|
||||
}
|
||||
};
|
||||
|
||||
struct TestRecombineVecAsInput
|
||||
{
|
||||
template <typename T>
|
||||
VTKM_CONT void operator()(T) const
|
||||
{
|
||||
vtkm::cont::ArrayHandle<T> baseArray;
|
||||
baseArray.Allocate(ARRAY_SIZE);
|
||||
SetPortal(baseArray.WritePortal());
|
||||
|
||||
using VTraits = vtkm::VecTraits<T>;
|
||||
vtkm::cont::ArrayHandleRecombineVec<typename VTraits::ComponentType> recombinedArray;
|
||||
for (vtkm::IdComponent cIndex = 0; cIndex < VTraits::NUM_COMPONENTS; ++cIndex)
|
||||
{
|
||||
recombinedArray.AppendComponentArray(vtkm::cont::ArrayExtractComponent(baseArray, cIndex));
|
||||
}
|
||||
VTKM_TEST_ASSERT(recombinedArray.GetNumberOfComponents() == VTraits::NUM_COMPONENTS);
|
||||
VTKM_TEST_ASSERT(recombinedArray.GetNumberOfValues() == ARRAY_SIZE);
|
||||
|
||||
vtkm::cont::ArrayHandle<T> outputArray;
|
||||
vtkm::cont::Invoker invoke;
|
||||
invoke(PassThrough{}, recombinedArray, outputArray);
|
||||
|
||||
VTKM_TEST_ASSERT(test_equal_ArrayHandles(baseArray, outputArray));
|
||||
}
|
||||
};
|
||||
|
||||
struct TestRecombineVecAsOutput
|
||||
{
|
||||
template <typename T>
|
||||
VTKM_CONT void operator()(T) const
|
||||
{
|
||||
vtkm::cont::ArrayHandle<T> baseArray;
|
||||
baseArray.Allocate(ARRAY_SIZE);
|
||||
SetPortal(baseArray.WritePortal());
|
||||
|
||||
vtkm::cont::ArrayHandle<T> outputArray;
|
||||
outputArray.Allocate(ARRAY_SIZE); // Cannot resize after recombine
|
||||
|
||||
using VTraits = vtkm::VecTraits<T>;
|
||||
vtkm::cont::ArrayHandleRecombineVec<typename VTraits::ComponentType> recombinedArray;
|
||||
for (vtkm::IdComponent cIndex = 0; cIndex < VTraits::NUM_COMPONENTS; ++cIndex)
|
||||
{
|
||||
recombinedArray.AppendComponentArray(vtkm::cont::ArrayExtractComponent(outputArray, cIndex));
|
||||
}
|
||||
VTKM_TEST_ASSERT(recombinedArray.GetNumberOfComponents() == VTraits::NUM_COMPONENTS);
|
||||
VTKM_TEST_ASSERT(recombinedArray.GetNumberOfValues() == ARRAY_SIZE);
|
||||
|
||||
vtkm::cont::Invoker invoke;
|
||||
invoke(PassThrough{}, baseArray, recombinedArray);
|
||||
|
||||
VTKM_TEST_ASSERT(test_equal_ArrayHandles(baseArray, outputArray));
|
||||
}
|
||||
};
|
||||
|
||||
void Run()
|
||||
{
|
||||
using HandleTypesToTest =
|
||||
vtkm::List<vtkm::Id, vtkm::Vec2i_32, vtkm::FloatDefault, vtkm::Vec3f_64>;
|
||||
|
||||
std::cout << "-------------------------------------------" << std::endl;
|
||||
std::cout << "Testing ArrayHandleRecombineVec as Input" << std::endl;
|
||||
vtkm::testing::Testing::TryTypes(TestRecombineVecAsInput(), HandleTypesToTest{});
|
||||
|
||||
std::cout << "-------------------------------------------" << std::endl;
|
||||
std::cout << "Testing ArrayHandleRecombineVec as Output" << std::endl;
|
||||
vtkm::testing::Testing::TryTypes(TestRecombineVecAsOutput(), HandleTypesToTest{});
|
||||
}
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
int UnitTestArrayHandleRecombineVec(int argc, char* argv[])
|
||||
{
|
||||
return vtkm::cont::testing::Testing::Run(Run, argc, argv);
|
||||
}
|
235
vtkm/cont/testing/UnitTestArrayHandleSOA.cxx
Normal file
235
vtkm/cont/testing/UnitTestArrayHandleSOA.cxx
Normal file
@ -0,0 +1,235 @@
|
||||
//============================================================================
|
||||
// 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/ArrayHandleSOA.h>
|
||||
|
||||
#include <vtkm/cont/ArrayCopyDevice.h>
|
||||
#include <vtkm/cont/Invoker.h>
|
||||
|
||||
#include <vtkm/worklet/WorkletMapField.h>
|
||||
|
||||
#include <vtkm/cont/testing/Testing.h>
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
constexpr vtkm::Id ARRAY_SIZE = 10;
|
||||
|
||||
using ScalarTypesToTest = vtkm::List<vtkm::UInt8, vtkm::FloatDefault>;
|
||||
using VectorTypesToTest = vtkm::List<vtkm::Vec2i_8, vtkm::Vec3f_32>;
|
||||
|
||||
struct PassThrough : public vtkm::worklet::WorkletMapField
|
||||
{
|
||||
using ControlSignature = void(FieldIn, FieldOut);
|
||||
using ExecutionSignature = void(_1, _2);
|
||||
|
||||
template <typename InValue, typename OutValue>
|
||||
VTKM_EXEC void operator()(const InValue& inValue, OutValue& outValue) const
|
||||
{
|
||||
outValue = inValue;
|
||||
}
|
||||
};
|
||||
|
||||
struct TestArrayPortalSOA
|
||||
{
|
||||
template <typename ComponentType>
|
||||
VTKM_CONT void operator()(ComponentType) const
|
||||
{
|
||||
constexpr vtkm::IdComponent NUM_COMPONENTS = 4;
|
||||
using ValueType = vtkm::Vec<ComponentType, NUM_COMPONENTS>;
|
||||
using ComponentArrayType = vtkm::cont::ArrayHandle<ComponentType>;
|
||||
using SOAPortalType =
|
||||
vtkm::internal::ArrayPortalSOA<ValueType, typename ComponentArrayType::WritePortalType>;
|
||||
|
||||
std::cout << "Test SOA portal reflects data in component portals." << std::endl;
|
||||
SOAPortalType soaPortalIn(ARRAY_SIZE);
|
||||
|
||||
std::array<vtkm::cont::ArrayHandle<ComponentType>, NUM_COMPONENTS> implArrays;
|
||||
for (vtkm::IdComponent componentIndex = 0; componentIndex < NUM_COMPONENTS; ++componentIndex)
|
||||
{
|
||||
vtkm::cont::ArrayHandle<ComponentType> array;
|
||||
array.Allocate(ARRAY_SIZE);
|
||||
auto portal = array.WritePortal();
|
||||
for (vtkm::IdComponent valueIndex = 0; valueIndex < ARRAY_SIZE; ++valueIndex)
|
||||
{
|
||||
portal.Set(valueIndex, TestValue(valueIndex, ValueType{})[componentIndex]);
|
||||
}
|
||||
|
||||
soaPortalIn.SetPortal(componentIndex, portal);
|
||||
|
||||
implArrays[static_cast<std::size_t>(componentIndex)] = array;
|
||||
}
|
||||
|
||||
VTKM_TEST_ASSERT(soaPortalIn.GetNumberOfValues() == ARRAY_SIZE);
|
||||
CheckPortal(soaPortalIn);
|
||||
|
||||
std::cout << "Test data set in SOA portal gets set in component portals." << std::endl;
|
||||
{
|
||||
SOAPortalType soaPortalOut(ARRAY_SIZE);
|
||||
for (vtkm::IdComponent componentIndex = 0; componentIndex < NUM_COMPONENTS; ++componentIndex)
|
||||
{
|
||||
vtkm::cont::ArrayHandle<ComponentType> array;
|
||||
array.Allocate(ARRAY_SIZE);
|
||||
auto portal = array.WritePortal();
|
||||
soaPortalOut.SetPortal(componentIndex, portal);
|
||||
|
||||
implArrays[static_cast<std::size_t>(componentIndex)] = array;
|
||||
}
|
||||
|
||||
SetPortal(soaPortalOut);
|
||||
}
|
||||
|
||||
for (vtkm::IdComponent componentIndex = 0; componentIndex < NUM_COMPONENTS; ++componentIndex)
|
||||
{
|
||||
auto portal = implArrays[static_cast<size_t>(componentIndex)].ReadPortal();
|
||||
for (vtkm::Id valueIndex = 0; valueIndex < ARRAY_SIZE; ++valueIndex)
|
||||
{
|
||||
ComponentType x = TestValue(valueIndex, ValueType{})[componentIndex];
|
||||
VTKM_TEST_ASSERT(test_equal(x, portal.Get(valueIndex)));
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
struct TestSOAAsInput
|
||||
{
|
||||
template <typename ValueType>
|
||||
VTKM_CONT void operator()(const ValueType vtkmNotUsed(v)) const
|
||||
{
|
||||
using VTraits = vtkm::VecTraits<ValueType>;
|
||||
using ComponentType = typename VTraits::ComponentType;
|
||||
constexpr vtkm::IdComponent NUM_COMPONENTS = VTraits::NUM_COMPONENTS;
|
||||
|
||||
{
|
||||
vtkm::cont::ArrayHandleSOA<ValueType> soaArray;
|
||||
for (vtkm::IdComponent componentIndex = 0; componentIndex < NUM_COMPONENTS; ++componentIndex)
|
||||
{
|
||||
vtkm::cont::ArrayHandle<ComponentType> componentArray;
|
||||
componentArray.Allocate(ARRAY_SIZE);
|
||||
auto componentPortal = componentArray.WritePortal();
|
||||
for (vtkm::Id valueIndex = 0; valueIndex < ARRAY_SIZE; ++valueIndex)
|
||||
{
|
||||
componentPortal.Set(
|
||||
valueIndex, VTraits::GetComponent(TestValue(valueIndex, ValueType{}), componentIndex));
|
||||
}
|
||||
soaArray.SetArray(componentIndex, componentArray);
|
||||
}
|
||||
|
||||
VTKM_TEST_ASSERT(soaArray.GetNumberOfValues() == ARRAY_SIZE);
|
||||
VTKM_TEST_ASSERT(soaArray.ReadPortal().GetNumberOfValues() == ARRAY_SIZE);
|
||||
CheckPortal(soaArray.ReadPortal());
|
||||
|
||||
vtkm::cont::ArrayHandle<ValueType> basicArray;
|
||||
vtkm::cont::ArrayCopyDevice(soaArray, basicArray);
|
||||
VTKM_TEST_ASSERT(basicArray.GetNumberOfValues() == ARRAY_SIZE);
|
||||
CheckPortal(basicArray.ReadPortal());
|
||||
}
|
||||
|
||||
{
|
||||
// Check constructors
|
||||
using Vec3 = vtkm::Vec<ComponentType, 3>;
|
||||
std::vector<ComponentType> vector0;
|
||||
std::vector<ComponentType> vector1;
|
||||
std::vector<ComponentType> vector2;
|
||||
for (vtkm::Id valueIndex = 0; valueIndex < ARRAY_SIZE; ++valueIndex)
|
||||
{
|
||||
Vec3 value = TestValue(valueIndex, Vec3{});
|
||||
vector0.push_back(value[0]);
|
||||
vector1.push_back(value[1]);
|
||||
vector2.push_back(value[2]);
|
||||
}
|
||||
|
||||
{
|
||||
vtkm::cont::ArrayHandleSOA<Vec3> soaArray =
|
||||
vtkm::cont::make_ArrayHandleSOA<Vec3>({ vector0, vector1, vector2 });
|
||||
VTKM_TEST_ASSERT(soaArray.GetNumberOfValues() == ARRAY_SIZE);
|
||||
CheckPortal(soaArray.ReadPortal());
|
||||
}
|
||||
|
||||
{
|
||||
vtkm::cont::ArrayHandleSOA<Vec3> soaArray =
|
||||
vtkm::cont::make_ArrayHandleSOA(vtkm::CopyFlag::Off, vector0, vector1, vector2);
|
||||
VTKM_TEST_ASSERT(soaArray.GetNumberOfValues() == ARRAY_SIZE);
|
||||
CheckPortal(soaArray.ReadPortal());
|
||||
|
||||
// Make sure calling ReleaseResources does not result in error.
|
||||
soaArray.ReleaseResources();
|
||||
}
|
||||
|
||||
{
|
||||
vtkm::cont::ArrayHandleSOA<Vec3> soaArray = vtkm::cont::make_ArrayHandleSOA<Vec3>(
|
||||
{ vector0.data(), vector1.data(), vector2.data() }, ARRAY_SIZE, vtkm::CopyFlag::Off);
|
||||
VTKM_TEST_ASSERT(soaArray.GetNumberOfValues() == ARRAY_SIZE);
|
||||
CheckPortal(soaArray.ReadPortal());
|
||||
}
|
||||
|
||||
{
|
||||
vtkm::cont::ArrayHandleSOA<Vec3> soaArray = vtkm::cont::make_ArrayHandleSOA(
|
||||
ARRAY_SIZE, vtkm::CopyFlag::Off, vector0.data(), vector1.data(), vector2.data());
|
||||
VTKM_TEST_ASSERT(soaArray.GetNumberOfValues() == ARRAY_SIZE);
|
||||
CheckPortal(soaArray.ReadPortal());
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
struct TestSOAAsOutput
|
||||
{
|
||||
template <typename ValueType>
|
||||
VTKM_CONT void operator()(const ValueType vtkmNotUsed(v)) const
|
||||
{
|
||||
using VTraits = vtkm::VecTraits<ValueType>;
|
||||
using ComponentType = typename VTraits::ComponentType;
|
||||
constexpr vtkm::IdComponent NUM_COMPONENTS = VTraits::NUM_COMPONENTS;
|
||||
|
||||
vtkm::cont::ArrayHandle<ValueType> basicArray;
|
||||
basicArray.Allocate(ARRAY_SIZE);
|
||||
SetPortal(basicArray.WritePortal());
|
||||
|
||||
vtkm::cont::ArrayHandleSOA<ValueType> soaArray;
|
||||
vtkm::cont::Invoker{}(PassThrough{}, basicArray, soaArray);
|
||||
|
||||
VTKM_TEST_ASSERT(soaArray.GetNumberOfValues() == ARRAY_SIZE);
|
||||
for (vtkm::IdComponent componentIndex = 0; componentIndex < NUM_COMPONENTS; ++componentIndex)
|
||||
{
|
||||
vtkm::cont::ArrayHandle<ComponentType> componentArray = soaArray.GetArray(componentIndex);
|
||||
auto componentPortal = componentArray.ReadPortal();
|
||||
for (vtkm::Id valueIndex = 0; valueIndex < ARRAY_SIZE; ++valueIndex)
|
||||
{
|
||||
ComponentType expected =
|
||||
VTraits::GetComponent(TestValue(valueIndex, ValueType{}), componentIndex);
|
||||
ComponentType got = componentPortal.Get(valueIndex);
|
||||
VTKM_TEST_ASSERT(test_equal(expected, got));
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
static void Run()
|
||||
{
|
||||
std::cout << "-------------------------------------------" << std::endl;
|
||||
std::cout << "Testing ArrayPortalSOA" << std::endl;
|
||||
vtkm::testing::Testing::TryTypes(TestArrayPortalSOA(), ScalarTypesToTest());
|
||||
|
||||
std::cout << "-------------------------------------------" << std::endl;
|
||||
std::cout << "Testing ArrayHandleSOA as Input" << std::endl;
|
||||
vtkm::testing::Testing::TryTypes(TestSOAAsInput(), VectorTypesToTest());
|
||||
|
||||
std::cout << "-------------------------------------------" << std::endl;
|
||||
std::cout << "Testing ArrayHandleSOA as Output" << std::endl;
|
||||
vtkm::testing::Testing::TryTypes(TestSOAAsOutput(), VectorTypesToTest());
|
||||
}
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
int UnitTestArrayHandleSOA(int argc, char* argv[])
|
||||
{
|
||||
return vtkm::cont::testing::Testing::Run(Run, argc, argv);
|
||||
}
|
@ -75,6 +75,51 @@ VTKM_CONT void CheckControlPortals(const OriginalArrayHandleType& originalArray,
|
||||
}
|
||||
}
|
||||
|
||||
struct ValueScale
|
||||
{
|
||||
ValueScale()
|
||||
: Factor(1.0)
|
||||
{
|
||||
}
|
||||
|
||||
ValueScale(vtkm::Float64 factor)
|
||||
: Factor(factor)
|
||||
{
|
||||
}
|
||||
|
||||
template <typename ValueType>
|
||||
VTKM_EXEC_CONT ValueType operator()(const ValueType& v) const
|
||||
{
|
||||
using Traits = vtkm::VecTraits<ValueType>;
|
||||
using TTraits = vtkm::TypeTraits<ValueType>;
|
||||
using ComponentType = typename Traits::ComponentType;
|
||||
|
||||
ValueType result = TTraits::ZeroInitialization();
|
||||
for (vtkm::IdComponent i = 0; i < Traits::GetNumberOfComponents(v); ++i)
|
||||
{
|
||||
vtkm::Float64 vi = static_cast<vtkm::Float64>(Traits::GetComponent(v, i));
|
||||
vtkm::Float64 ri = vi * this->Factor;
|
||||
Traits::SetComponent(result, i, static_cast<ComponentType>(ri));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private:
|
||||
vtkm::Float64 Factor;
|
||||
};
|
||||
|
||||
struct PassThrough : public vtkm::worklet::WorkletMapField
|
||||
{
|
||||
using ControlSignature = void(FieldIn, FieldOut);
|
||||
using ExecutionSignature = void(_1, _2);
|
||||
|
||||
template <typename InValue, typename OutValue>
|
||||
VTKM_EXEC void operator()(const InValue& inValue, OutValue& outValue) const
|
||||
{
|
||||
outValue = inValue;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename InputValueType>
|
||||
struct TransformTests
|
||||
{
|
||||
@ -107,19 +152,13 @@ struct TransformTests
|
||||
|
||||
std::cout << "Test a transform handle with a normal handle as the values" << std::endl;
|
||||
//we are going to connect the two handles up, and than fill
|
||||
//the values and make the transform sees the new values in the handle
|
||||
//the values and make sure the transform sees the new values in the handle
|
||||
vtkm::cont::ArrayHandle<InputValueType> input;
|
||||
TransformHandle thandle(input, functor);
|
||||
|
||||
using Portal = typename vtkm::cont::ArrayHandle<InputValueType>::WritePortalType;
|
||||
input.Allocate(ARRAY_SIZE);
|
||||
{
|
||||
Portal portal = input.WritePortal();
|
||||
for (vtkm::Id index = 0; index < ARRAY_SIZE; ++index)
|
||||
{
|
||||
portal.Set(index, TestValue(index, InputValueType()));
|
||||
}
|
||||
}
|
||||
SetPortal(input.WritePortal());
|
||||
|
||||
CheckControlPortals(input, thandle);
|
||||
|
||||
@ -139,6 +178,33 @@ struct TransformTests
|
||||
|
||||
std::cout << " Verify that the execution portal works" << std::endl;
|
||||
invoke(CheckTransformWorklet{}, input, thandle);
|
||||
|
||||
std::cout << "Write to a transformed array with an inverse transform" << std::endl;
|
||||
{
|
||||
ValueScale scaleUp(2.0);
|
||||
ValueScale scaleDown(1.0 / 2.0);
|
||||
|
||||
input.Allocate(ARRAY_SIZE);
|
||||
SetPortal(input.WritePortal());
|
||||
|
||||
vtkm::cont::ArrayHandle<InputValueType> output;
|
||||
auto transformed = vtkm::cont::make_ArrayHandleTransform(output, scaleUp, scaleDown);
|
||||
|
||||
invoke(PassThrough{}, input, transformed);
|
||||
|
||||
//verify that the control portal works
|
||||
auto outputPortal = output.ReadPortal();
|
||||
auto transformedPortal = transformed.ReadPortal();
|
||||
for (vtkm::Id i = 0; i < ARRAY_SIZE; ++i)
|
||||
{
|
||||
const InputValueType result_v = outputPortal.Get(i);
|
||||
const InputValueType correct_value = scaleDown(TestValue(i, InputValueType()));
|
||||
const InputValueType control_value = transformedPortal.Get(i);
|
||||
VTKM_TEST_ASSERT(test_equal(result_v, correct_value), "Transform Handle Failed");
|
||||
VTKM_TEST_ASSERT(test_equal(scaleUp(result_v), control_value),
|
||||
"Transform Handle Control Failed");
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user