Commit 23d05aed authored by Yohann Bearzi's avatar Yohann Bearzi

Splitting VTKmCore into Core and DataModel

parent 9e752561
Pipeline #196308 running with stage
......@@ -17,34 +17,18 @@
list(INSERT 0 CMAKE_MODULE_PATH
"${VTK_SOURCE_DIR}/ThirdParty/vtkm/vtkvtkm/vtk-m/CMake")
set(sources
vtkmlib/ArrayConvertersReal.cxx
vtkmlib/ArrayConvertersSigned.cxx
vtkmlib/ArrayConvertersUnsigned.cxx)
set(private_headers
vtkmlib/ArrayConverters.hxx
vtkmlib/vtkmDataArray.hxx
vtkmlib/DataArrayConverters.hxx
vtkmlib/Portals.hxx
vtkmlib/PortalTraits.h)
set(impl_classes
vtkmDataArray
vtkmDataSet
)
set(private_impl_classes
vtkmlib/ArrayConverters
vtkmlib/CellSetConverters
vtkmlib/DataSetConverters
vtkmlib/ImageDataConverter
vtkmlib/ImplicitFunctionConverter
vtkmlib/PolyDataConverter
vtkmlib/Portals
vtkmlib/UnstructuredGridConverter)
set(headers
vtkmFilterPolicy.h)
vtkmlib/DataArrayConverters
vtkmlib/Portals)
foreach (class IN LISTS impl_classes)
list(APPEND sources "${class}.cxx")
......@@ -56,8 +40,6 @@ foreach (class IN LISTS private_impl_classes)
list(APPEND private_headers "${class}.h")
endforeach ()
set(VTKM_FILTER_INCLUDE_AOS ${VTK_DISPATCH_AOS_ARRAYS})
set(VTKM_FILTER_INCLUDE_SOA ${VTK_DISPATCH_SOA_ARRAYS})
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/vtkmConfigCore.h.in"
"${CMAKE_CURRENT_BINARY_DIR}/vtkmConfigCore.h"
......
......@@ -3,7 +3,7 @@
# in cuda. We have not identified the root cause of the problem yet.
vtk_add_test_cxx(vtkAcceleratorsVTKmCoreCxxTests tests
TestVTKMDataArray.cxx,NO_VALID
TestVTKMDataSet.cxx,NO_VALID
TestVTKMImplicitDataArray,VALID
)
if (TARGET vtkm::cuda)
......
......@@ -6,7 +6,6 @@ DESCRIPTION
VTKm data structures
DEPENDS
VTK::CommonCore
VTK::CommonDataModel
VTK::vtkm
TEST_DEPENDS
VTK::CommonSystem
......
......@@ -18,10 +18,6 @@
/*--------------------------------------------------------------------------*/
/* Other Configuration Options */
/* Determine what types the vtkm policy will need to support for arrays */
#cmakedefine VTKM_FILTER_INCLUDE_AOS
#cmakedefine VTKM_FILTER_INCLUDE_SOA
#include <vtkm/internal/Configure.h>
#include "vtkAcceleratorsVTKmCoreModule.h" //required for correct implementation
......
......@@ -13,7 +13,7 @@
// the U.S. Government retains certain rights in this software.
//
//=============================================================================
#include "ArrayConverters.hxx"
#include "DataArrayConverters.hxx"
#include "vtkmDataArray.h"
#include "vtkmFilterPolicy.h"
......@@ -23,112 +23,9 @@
#include <vtkm/cont/ArrayHandle.h>
#include <vtkm/cont/DataSet.h>
#include "vtkCellData.h"
#include "vtkDataArray.h"
#include "vtkDataObject.h"
#include "vtkDataSet.h"
#include "vtkPointData.h"
#include "vtkPoints.h"
namespace tovtkm
{
void ProcessFields(vtkDataSet* input, vtkm::cont::DataSet& dataset, tovtkm::FieldsFlag fields)
{
if ((fields & tovtkm::FieldsFlag::Points) != tovtkm::FieldsFlag::None)
{
vtkPointData* pd = input->GetPointData();
for (int i = 0; i < pd->GetNumberOfArrays(); i++)
{
vtkDataArray* array = pd->GetArray(i);
if (array == nullptr)
{
continue;
}
vtkm::cont::Field pfield = tovtkm::Convert(array, vtkDataObject::FIELD_ASSOCIATION_POINTS);
dataset.AddField(pfield);
}
}
if ((fields & tovtkm::FieldsFlag::Cells) != tovtkm::FieldsFlag::None)
{
vtkCellData* cd = input->GetCellData();
for (int i = 0; i < cd->GetNumberOfArrays(); i++)
{
vtkDataArray* array = cd->GetArray(i);
if (array == nullptr)
{
continue;
}
vtkm::cont::Field cfield = tovtkm::Convert(array, vtkDataObject::FIELD_ASSOCIATION_CELLS);
dataset.AddField(cfield);
}
}
}
template <typename T>
vtkm::cont::Field Convert(vtkmDataArray<T>* input, int association)
{
// we need to switch on if we are a cell or point field first!
// The problem is that the constructor signature for fields differ based
// on if they are a cell or point field.
if (association == vtkDataObject::FIELD_ASSOCIATION_POINTS)
{
return vtkm::cont::make_FieldPoint(input->GetName(), input->GetVtkmVariantArrayHandle());
}
else if (association == vtkDataObject::FIELD_ASSOCIATION_CELLS)
{
return vtkm::cont::make_FieldCell(input->GetName(), input->GetVtkmVariantArrayHandle());
}
return vtkm::cont::Field();
}
// determine the type and call the proper Convert routine
vtkm::cont::Field Convert(vtkDataArray* input, int association)
{
// The association will tell us if we have a cell or point field
// We need to properly deduce the ValueType of the array. This means
// that we need to switch on Float/Double/Int, and then figure out the
// number of components. The upside is that the Convert Method can internally
// figure out the number of components, and not have to generate a lot
// of template to do so
// Investigate using vtkArrayDispatch, AOS for all types, and than SOA for
// just
// float/double
vtkm::cont::Field field;
switch (input->GetDataType())
{
vtkTemplateMacro(
vtkAOSDataArrayTemplate<VTK_TT>* typedIn1 =
vtkAOSDataArrayTemplate<VTK_TT>::FastDownCast(input);
if (typedIn1) { field = Convert(typedIn1, association); } else {
vtkSOADataArrayTemplate<VTK_TT>* typedIn2 =
vtkSOADataArrayTemplate<VTK_TT>::FastDownCast(input);
if (typedIn2)
{
field = Convert(typedIn2, association);
}
else
{
vtkmDataArray<VTK_TT>* typedIn3 = vtkmDataArray<VTK_TT>::SafeDownCast(input);
if (typedIn3)
{
field = Convert(typedIn3, association);
}
}
});
// end vtkTemplateMacro
}
return field;
}
} // namespace tovtkm
namespace fromvtkm
{
......@@ -315,31 +212,4 @@ vtkPoints* Convert(const vtkm::cont::CoordinateSystem& input)
return points;
}
bool ConvertArrays(const vtkm::cont::DataSet& input, vtkDataSet* output)
{
vtkPointData* pd = output->GetPointData();
vtkCellData* cd = output->GetCellData();
vtkm::IdComponent numFields = input.GetNumberOfFields();
for (vtkm::IdComponent i = 0; i < numFields; ++i)
{
const vtkm::cont::Field& f = input.GetField(i);
vtkDataArray* vfield = Convert(f);
if (vfield && f.GetAssociation() == vtkm::cont::Field::Association::POINTS)
{
pd->AddArray(vfield);
vfield->FastDelete();
}
else if (vfield && f.GetAssociation() == vtkm::cont::Field::Association::CELL_SET)
{
cd->AddArray(vfield);
vfield->FastDelete();
}
else if (vfield)
{
vfield->Delete();
}
}
return true;
}
}
......@@ -14,8 +14,8 @@
//
//=============================================================================
#ifndef vtkmlib_ArrayConverters_h
#define vtkmlib_ArrayConverters_h
#ifndef vtkmlib_DataArrayConverters_h
#define vtkmlib_DataArrayConverters_h
#include "vtkAcceleratorsVTKmCoreModule.h" //required for correct implementation
#include "vtkmConfigCore.h" //required for general vtkm setup
......@@ -29,14 +29,12 @@
#include <type_traits> // for std::underlying_type
class vtkDataArray;
class vtkDataSet;
class vtkPoints;
namespace vtkm
{
namespace cont
{
class DataSet;
class CoordinateSystem;
}
}
......@@ -106,12 +104,6 @@ enum class FieldsFlag
PointsAndCells = Points | Cells
};
VTKACCELERATORSVTKMCORE_EXPORT
void ProcessFields(vtkDataSet* input, vtkm::cont::DataSet& dataset, tovtkm::FieldsFlag fields);
// determine the type and call the proper Convert routine
VTKACCELERATORSVTKMCORE_EXPORT
vtkm::cont::Field Convert(vtkDataArray* input, int association);
}
namespace fromvtkm
......@@ -126,8 +118,6 @@ vtkDataArray* Convert(const vtkm::cont::VariantArrayHandle& input, const char* n
VTKACCELERATORSVTKMCORE_EXPORT
vtkPoints* Convert(const vtkm::cont::CoordinateSystem& input);
VTKACCELERATORSVTKMCORE_EXPORT
bool ConvertArrays(const vtkm::cont::DataSet& input, vtkDataSet* output);
}
inline tovtkm::FieldsFlag operator&(const tovtkm::FieldsFlag& a, const tovtkm::FieldsFlag& b)
......
//=============================================================================
//
// Copyright (c) Kitware, Inc.
// All rights reserved.
// See LICENSE.txt for details.
//
// This software is distributed WITHOUT ANY WARRANTY; without even
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
// PURPOSE. See the above copyright notice for more information.
//
// Copyright 2012 Sandia Corporation.
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
// the U.S. Government retains certain rights in this software.
//
//=============================================================================
#ifndef vtkmlib_DataArrayConverters_hxx
#define vtkmlib_DataArrayConverters_hxx
#include "DataArrayConverters.h"
#include <vtkm/cont/ArrayHandleGroupVecVariable.h>
#include "vtkDataArray.h"
namespace tovtkm
{
template <typename DataArrayType>
vtkm::cont::VariantArrayHandle vtkDataArrayToVariantArrayHandle(DataArrayType* input)
{
int numComps = input->GetNumberOfComponents();
switch (numComps)
{
case 1:
return vtkm::cont::VariantArrayHandle(DataArrayToArrayHandle<DataArrayType, 1>::Wrap(input));
case 2:
return vtkm::cont::VariantArrayHandle(DataArrayToArrayHandle<DataArrayType, 2>::Wrap(input));
case 3:
return vtkm::cont::VariantArrayHandle(DataArrayToArrayHandle<DataArrayType, 3>::Wrap(input));
case 4:
return vtkm::cont::VariantArrayHandle(DataArrayToArrayHandle<DataArrayType, 4>::Wrap(input));
case 6:
return vtkm::cont::VariantArrayHandle(DataArrayToArrayHandle<DataArrayType, 6>::Wrap(input));
case 9:
return vtkm::cont::VariantArrayHandle(DataArrayToArrayHandle<DataArrayType, 9>::Wrap(input));
default:
{
vtkm::Id numTuples = input->GetNumberOfTuples();
auto subHandle = DataArrayToArrayHandle<DataArrayType, 1>::Wrap(input);
auto offsets =
vtkm::cont::ArrayHandleCounting<vtkm::Id>(vtkm::Id(0), vtkm::Id(numComps), numTuples);
auto handle = vtkm::cont::make_ArrayHandleGroupVecVariable(subHandle, offsets);
return vtkm::cont::VariantArrayHandle(handle);
}
}
}
template <typename DataArrayType>
vtkm::cont::Field ConvertPointField(DataArrayType* input)
{
auto vhandle = vtkDataArrayToVariantArrayHandle(input);
return vtkm::cont::make_FieldPoint(input->GetName(), vhandle);
}
template <typename DataArrayType>
vtkm::cont::Field ConvertCellField(DataArrayType* input)
{
auto vhandle = vtkDataArrayToVariantArrayHandle(input);
return vtkm::cont::make_FieldCell(input->GetName(), vhandle);
}
} // tovtkm
#endif
##=============================================================================
##
## Copyright (c) Kitware, Inc.
## All rights reserved.
## See LICENSE.txt for details.
##
## This software is distributed WITHOUT ANY WARRANTY; without even
## the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
## PURPOSE. See the above copyright notice for more information.
##
## Copyright 2012 Sandia Corporation.
## Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
## the U.S. Government retains certain rights in this software.
##
##=============================================================================
list(INSERT 0 CMAKE_MODULE_PATH
"${VTK_SOURCE_DIR}/ThirdParty/vtkm/vtkvtkm/vtk-m/CMake")
set(sources
vtkmlib/ArrayConvertersReal.cxx
vtkmlib/ArrayConvertersSigned.cxx
vtkmlib/ArrayConvertersUnsigned.cxx)
set(private_headers
vtkmlib/ArrayConverters.hxx)
set(impl_classes
vtkmDataSet
)
set(private_impl_classes
vtkmlib/ArrayConverters
vtkmlib/CellSetConverters
vtkmlib/DataSetConverters
vtkmlib/ImageDataConverter
vtkmlib/ImplicitFunctionConverter
vtkmlib/PolyDataConverter
vtkmlib/UnstructuredGridConverter)
foreach (class IN LISTS impl_classes)
list(APPEND sources "${class}.cxx")
list(APPEND headers "${class}.h")
endforeach ()
foreach (class IN LISTS private_impl_classes)
list(APPEND sources "${class}.cxx")
list(APPEND private_headers "${class}.h")
endforeach ()
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/vtkmConfigDataModel.h.in"
"${CMAKE_CURRENT_BINARY_DIR}/vtkmConfigDataModel.h"
@ONLY)
list(APPEND headers
"${CMAKE_CURRENT_BINARY_DIR}/vtkmConfigDataModel.h")
if (TARGET vtkm::cuda)
enable_language(CUDA)
# Temporarily suppress "has address taken but no possible call to it" warnings,
# until we figure out its implications.
# We are disabling all warnings as nvlink has no known way to suppress
# individual warning types.
string(APPEND CMAKE_CUDA_FLAGS " -Xnvlink -w")
endif ()
if(TARGET vtkm::cuda AND BUILD_SHARED_LIBS)
message("Cuda is enabled. All VTK-m base modules will be forced to build as static.")
vtk_module_add_module(VTK::AcceleratorsVTKmDataModel
FORCE_STATIC
SOURCES ${sources}
HEADERS ${headers}
PRIVATE_HEADERS ${private_headers})
else()
vtk_module_add_module(VTK::AcceleratorsVTKmDataModel
SOURCES ${sources}
HEADERS ${headers}
PRIVATE_HEADERS ${private_headers})
endif()
_vtk_module_real_target(vtkm_accel_target VTK::AcceleratorsVTKmDataModel)
vtkm_add_target_information(${vtkm_accel_target}
EXTENDS_VTKM
MODIFY_CUDA_FLAGS
DEVICE_SOURCES ${sources})
vtk_module_set_property(VTK::AcceleratorsVTKmDataModel
PROPERTY JOB_POOL_COMPILE
VALUE vtkm_pool)
if (TARGET vtkm::cuda)
vtk_module_set_property(VTK::AcceleratorsVTKmDataModel
PROPERTY CUDA_SEPARABLE_COMPILATION
VALUE ON)
vtk_module_compile_options(VTK::AcceleratorsVTKmDataModel
PUBLIC $<$<COMPILE_LANGUAGE:CUDA>:-Xcudafe --diag_suppress=extra_semicolon>)
endif ()
# We need to install the private headers so that consumers of VTK can write
# new VTK-m filters and do data conversions correctly.
vtk_module_install_headers(
FILES ${private_headers}
SUBDIR "vtkmlib")
if (MSVC)
set(msvc_warning_flags
# Generates numerous false positives with template code about unreachable
# code
/wd4702
# Generates numerous warning that implicit assignment operators can't be
# constructed. This is understood and we don't care.
/wd4512
# Generates numerous warning that implicit constructors can't be
# constructed. This is understood and we don't care.
/wd4510
# Generates warnings when decorated names are over 4096 characters
# This compiler warning is deprecated and no longer occurs with VS2017+.
# So we suppress for VS2015
/wd4503
)
set(vtkm_msvc_flags)
foreach (msvc_warning_flag IN LISTS msvc_warning_flags)
if (TARGET vtkm::cuda)
list(APPEND vtkm_msvc_flags
$<$<COMPILE_LANGUAGE:CUDA>:-Xcompiler=${msvc_warning_flag},${msvc_warning_flag}>)
else ()
list(APPEND vtkm_msvc_flags
${msvc_warning_flag})
endif ()
endforeach ()
vtk_module_compile_options(VTK::AcceleratorsVTKmDataModel
PRIVATE
${vtkm_msvc_flags})
endif ()
# We are splitting the tests into two executables to workaround an issue in
# cuda. With all the tests in the same executable several tests are failing
# in cuda. We have not identified the root cause of the problem yet.
vtk_add_test_cxx(vtkAcceleratorsVTKmDataModelCxxTests tests
TestVTKMDataSet.cxx,NO_VALID
)
if (TARGET vtkm::cuda)
#the enable_language call is scoped! so we have to re-enable
#cuda in the test directory
enable_language(CUDA)
foreach(src IN LISTS tests)
set_source_files_properties(${src}.cxx PROPERTIES LANGUAGE "CUDA")
endforeach()
#the tests aren't scoped as a child directory of vtkAcceleratorsVTKmDataModel
#so we need to redo this logic
vtkm_get_cuda_flags(CMAKE_CUDA_FLAGS)
# Temporarily suppress "has address taken but no possible call to it" warnings,
# until we figure out its implications.
# We are disabling all warnings as nvlink has no known way to suppress
# individual warning types.
string(APPEND CMAKE_CUDA_FLAGS " -Xnvlink -w")
endif()
vtk_test_cxx_executable(vtkAcceleratorsVTKmDataModelCxxTests tests
RENDERING_FACTORY
)
if (TARGET vtkm::cuda)
# When cuda is enabled VTK::AcceleratorsVTKmDataModel is built statically but with fpic
# enabled so the tests are also built with fpic enabled
set_target_properties(vtkAcceleratorsVTKmDataModelCxxTests PROPERTIES POSITION_INDEPENDENT_CODE ON)
endif()
NAME
VTK::AcceleratorsVTKmDataModel
LIBRARY_NAME
vtkAcceleratorsVTKmDataModel
DESCRIPTION
VTKm data structures
DEPENDS
VTK::AcceleratorsVTKmCore
VTK::CommonCore
VTK::CommonDataModel
VTK::vtkm
TEST_DEPENDS
VTK::FiltersGeneral
VTK::TestingCore
VTK::TestingRendering
/*=========================================================================
Program: Visualization Toolkit
Module: ObjectFactory.cxx
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm 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 vtkConfigDataModel_h
#define vtkConfigDataModel_h
/*--------------------------------------------------------------------------*/
/* Other Configuration Options */
#include <vtkm/internal/Configure.h>
#include "vtkAcceleratorsVTKmDataModelModule.h" //required for correct implementation
/*--------------------------------------------------------------------------*/
/* Make sure we use the same id's in VTK and VTK-m */
#include "vtkType.h"
#ifdef VTK_USE_64BIT_IDS
# ifndef VTKM_USE_64BIT_IDS
# error VTK was defined with 64-bit ids but VTK-m with 32-bit ids.
# endif
#else // !VTK_USE_64BIT_IDS
# ifdef VTKM_USE_64BIT_IDS
# error VTK was defined with 32-bit ids but VTK-m with 64-bit ids.
# endif
#endif
#ifndef VTKACCELERATORSVTKMDATAMODEL_TEMPLATE_EXPORT
# if !defined(VTKACCELERATORSVTKMDATAMODEL_STATIC_DEFINE) && defined(_MSC_VER)
/* Warning C4910 on windows state that extern explicit template can't be
labeled with __declspec(dllexport). So that is why we use a new custom
define. But when other modules ( e.g. rendering ) include this header
we need them to see that the extern template is actually being imported.
*/
/* We are building this library with MSVC */
# define VTKACCELERATORSVTKMDATAMODEL_TEMPLATE_EXPORT
# else
/* Defer to the config module */
# define VTKACCELERATORSVTKMDATAMODEL_TEMPLATE_EXPORT VTKACCELERATORSVTKMDATAMODEL_EXPORT
# endif
#endif
#endif // vtkConfigDataModel_h
......@@ -20,7 +20,7 @@
#ifndef vtkmDataSet_h
#define vtkmDataSet_h
#include "vtkAcceleratorsVTKmCoreModule.h" // For export macro
#include "vtkAcceleratorsVTKmDataModelModule.h" // For export macro
#include "vtkDataSet.h"
#include <memory> // for std::shared_ptr
......@@ -39,7 +39,7 @@ class vtkPoints;
class vtkCell;
class vtkGenericCell;
class VTKACCELERATORSVTKMCORE_EXPORT vtkmDataSet : public vtkDataSet
class VTKACCELERATORSVTKMDATAMODEL_EXPORT vtkmDataSet : public vtkDataSet
{
public:
vtkTypeMacro(vtkmDataSet, vtkDataSet);
......
//=============================================================================
//
// Copyright (c) Kitware, Inc.