diff --git a/IO/CatalystConduit/vtkConduitArrayUtilities.cxx b/IO/CatalystConduit/vtkConduitArrayUtilities.cxx index 36ca9e2d19016e3e3b9dbba19424b3d1d9fc4f81..a4ba7ef0cac335ed7fbbb15db04b10bdc3010685 100644 --- a/IO/CatalystConduit/vtkConduitArrayUtilities.cxx +++ b/IO/CatalystConduit/vtkConduitArrayUtilities.cxx @@ -214,6 +214,26 @@ VTK_ABI_NAMESPACE_END VTK_ABI_NAMESPACE_BEGIN vtkStandardNewMacro(vtkConduitArrayUtilities); + +#if VTK_MODULE_ENABLE_VTK_AcceleratorsVTKmDataModel +#define IS_DEVICE_POINTER(memory) \ + void* __ptr = memory; \ + int8_t __id; \ + bool isDevicePointer = vtkConduitArrayUtilities::IsDevicePointer(__ptr, __id); \ + auto deviceAdapterId = vtkm::cont::make_DeviceAdapterId(__id); \ + if (isDevicePointer && !vtkConduitArrayUtilitiesDevice::CanRunOn(deviceAdapterId)) \ + { \ + vtkLogF(ERROR, "Device %d is not available at runtime", __id); \ + return nullptr; \ + } + +#else +#define IS_DEVICE_POINTER(memory) \ + void* __ptr = memory; \ + int8_t __id; \ + bool isDevicePointer = vtkConduitArrayUtilities::IsDevicePointer(__ptr, __id); +#endif + //---------------------------------------------------------------------------- vtkConduitArrayUtilities::vtkConduitArrayUtilities() = default; @@ -331,17 +351,7 @@ vtkSmartPointer<vtkDataArray> vtkConduitArrayUtilities::MCArrayToVTKArrayImpl( } } - void* ptr = mcarray.child(0).element_ptr(0); - int8_t id; - bool isDevicePointer = vtkConduitArrayUtilities::IsDevicePointer(ptr, id); -#if VTK_MODULE_ENABLE_VTK_AcceleratorsVTKmDataModel - auto deviceAdapterId = vtkm::cont::make_DeviceAdapterId(id); - if (isDevicePointer && !vtkConduitArrayUtilitiesDevice::CanRunOn(deviceAdapterId)) - { - vtkLogF(ERROR, "Device %d is not available at runtime", id); - return nullptr; - } -#endif + IS_DEVICE_POINTER(mcarray.child(0).element_ptr(0)); if (conduit_cpp::BlueprintMcArray::is_interleaved(mcarray)) { @@ -567,21 +577,34 @@ vtkSmartPointer<vtkCellArray> vtkConduitArrayUtilities::MCArrayToVTKCellArray( } vtkSmartPointer<vtkCellArray> vtkConduitArrayUtilities::MCArrayToVTKCellArray( - vtkIdType numberOfPoints, int cellType, vtkIdType cellSize, const conduit_node* mcarray) + vtkIdType numberOfPoints, int cellType, vtkIdType cellSize, const conduit_node* c_mcarray) { auto connectivity = - vtkConduitArrayUtilities::MCArrayToVTKArrayImpl(mcarray, /*force_signed*/ true); + vtkConduitArrayUtilities::MCArrayToVTKArrayImpl(c_mcarray, /*force_signed*/ true); + conduit_cpp::Node mcarray = conduit_cpp::cpp_node(const_cast<conduit_node*>(c_mcarray)); + + IS_DEVICE_POINTER(mcarray.element_ptr(0)); + if (!connectivity) { return nullptr; } vtkNew<vtkCellArray> cellArray; + if (isDevicePointer) + { #if VTK_MODULE_ENABLE_VTK_AcceleratorsVTKmDataModel - if (!vtkConduitArrayUtilitiesDevice::IfVTKmConvertVTKMonoShapedCellArray( - numberOfPoints, cellType, cellSize, connectivity, cellArray)) + if (!vtkConduitArrayUtilitiesDevice::IfVTKmConvertVTKMonoShapedCellArray( + numberOfPoints, cellType, cellSize, connectivity, cellArray)) + { + vtkLogF(ERROR, "Cannot convert connectivity to a vtkmArray"); + return nullptr; + } #else - (void)numberOfPoints; // avoid unused variable warning + (void)cellType; + (void)numberOfPoints; // avoid unused variable warning #endif // VTK_MODULE_ENABLE_VTK_AcceleratorsVTKmDataModel + } + else { // cell arrays are in host memory cellArray->SetData(cellSize, connectivity); @@ -602,15 +625,20 @@ vtkSmartPointer<vtkCellArray> vtkConduitArrayUtilities::O2MRelationToVTKCellArra // if arrays for the conduit nodes are stored in host memory, numberOfPoints=0 is not used // if arrays are stored in device memory, we'll get an error - however this case did not work // for the deprecated function. - return O2MRelationToVTKCellArray(0, c_o2mrelation, leafname); + // leafname is always "connectivity" + (void)leafname; + return O2MRelationToVTKCellArray(0, c_o2mrelation); } vtkSmartPointer<vtkCellArray> vtkConduitArrayUtilities::O2MRelationToVTKCellArray( - vtkIdType numberOfPoints, const conduit_node* c_o2mrelation, const std::string& leafname) + vtkIdType numberOfPoints, const conduit_node* c_o2mrelation) { const conduit_cpp::Node o2mrelation = conduit_cpp::cpp_node(const_cast<conduit_node*>(c_o2mrelation)); - const auto leaf = o2mrelation[leafname]; + const auto leaf = o2mrelation["connectivity"]; + + IS_DEVICE_POINTER(const_cast<void*>(leaf.element_ptr(0))); + auto elements = vtkConduitArrayUtilities::MCArrayToVTKArrayImpl( conduit_cpp::c_node(&leaf), /*force_signed*/ true); if (!elements) @@ -626,16 +654,24 @@ vtkSmartPointer<vtkCellArray> vtkConduitArrayUtilities::O2MRelationToVTKCellArra const auto node_offsets = o2mrelation["offsets"]; auto offsets = vtkConduitArrayUtilities::MCArrayToVTKArrayImpl( conduit_cpp::c_node(&node_offsets), /*force_signed*/ true); - const auto node_shapes = o2mrelation["shapes"]; - auto shapes = vtkConduitArrayUtilities::MCArrayToVTKArrayImpl( - conduit_cpp::c_node(&node_shapes), /*force_signed*/ true); vtkNew<vtkCellArray> cellArray; + if (isDevicePointer) + { #if VTK_MODULE_ENABLE_VTK_AcceleratorsVTKmDataModel - if (!vtkConduitArrayUtilitiesDevice::IfVTKmConvertVTKMixedCellArray( - numberOfPoints, offsets, shapes, elements, cellArray)) + const auto node_shapes = o2mrelation["shapes"]; + auto shapes = vtkConduitArrayUtilities::MCArrayToVTKArrayImpl( + conduit_cpp::c_node(&node_shapes), /*force_signed*/ true); + if (!vtkConduitArrayUtilitiesDevice::IfVTKmConvertVTKMixedCellArray( + numberOfPoints, offsets, shapes, elements, cellArray)) + { + vtkLogF(ERROR, "Cannot convert connectivity to a vtkmArray"); + return nullptr; + } #else - (void)numberOfPoints; // avoid unused variable warning + (void)numberOfPoints; // avoid unused variable warning #endif + } + else { // offsets and connectivity are in host memory using ConduitDispatcher = diff --git a/IO/CatalystConduit/vtkConduitArrayUtilities.h b/IO/CatalystConduit/vtkConduitArrayUtilities.h index 0e7b77b0aab0350a2b8abefe9cf148612bbca6f7..feef2fec880128dec3b83212fba81017b843062a 100644 --- a/IO/CatalystConduit/vtkConduitArrayUtilities.h +++ b/IO/CatalystConduit/vtkConduitArrayUtilities.h @@ -87,11 +87,12 @@ public: * Read a O2MRelation element */ VTK_DEPRECATED_IN_9_4_0("Version with additional `numberOfPoints` parameter needed with " - "zero-copy arrays stored on acceleration devices such as CUDA") + "zero-copy arrays stored on acceleration devices such as CUDA. " + "`leafname` is always connectivity, so it is removed in the new version.") static vtkSmartPointer<vtkCellArray> O2MRelationToVTKCellArray( const conduit_node* o2mrelation, const std::string& leafname); static vtkSmartPointer<vtkCellArray> O2MRelationToVTKCellArray( - vtkIdType numberOfPoints, const conduit_node* o2mrelation, const std::string& leafname); + vtkIdType numberOfPoints, const conduit_node* o2mrelation); protected: vtkConduitArrayUtilities(); diff --git a/IO/CatalystConduit/vtkConduitToDataObject.cxx b/IO/CatalystConduit/vtkConduitToDataObject.cxx index 30c55483cb65e041514730838865ea8ee34eb785..750847e49c193ab456053b884c7436f8516574c8 100644 --- a/IO/CatalystConduit/vtkConduitToDataObject.cxx +++ b/IO/CatalystConduit/vtkConduitToDataObject.cxx @@ -731,9 +731,9 @@ vtkSmartPointer<vtkDataSet> CreateMonoShapedUnstructuredGrid( conduit_cpp::Node t_elements = topologyNode["elements"]; conduit_cpp::Node t_subelements = topologyNode["subelements"]; auto elements = vtkConduitArrayUtilities::O2MRelationToVTKCellArray( - numberOfPoints, conduit_cpp::c_node(&t_elements), "connectivity"); + numberOfPoints, conduit_cpp::c_node(&t_elements)); auto subelements = vtkConduitArrayUtilities::O2MRelationToVTKCellArray( - numberOfPoints, conduit_cpp::c_node(&t_subelements), "connectivity"); + numberOfPoints, conduit_cpp::c_node(&t_subelements)); SetPolyhedralCells(unstructured, elements, subelements); } @@ -743,7 +743,7 @@ vtkSmartPointer<vtkDataSet> CreateMonoShapedUnstructuredGrid( // differently. conduit_cpp::Node t_elements = topologyNode["elements"]; auto cellArray = vtkConduitArrayUtilities::O2MRelationToVTKCellArray( - numberOfPoints, conduit_cpp::c_node(&t_elements), "connectivity"); + numberOfPoints, conduit_cpp::c_node(&t_elements)); unstructured->SetCells(vtk_cell_type, cellArray); } else @@ -880,7 +880,7 @@ vtkSmartPointer<vtkDataSet> CreateMixedUnstructuredGrid( auto shapes = vtkConduitArrayUtilities::MCArrayToVTKArray(conduit_cpp::c_node(&t_elementShapes)); auto elements = vtkConduitArrayUtilities::O2MRelationToVTKCellArray( - numberOfPoints, conduit_cpp::c_node(&t_elements), "connectivity"); + numberOfPoints, conduit_cpp::c_node(&t_elements)); if (!elements || !shapes) { throw std::runtime_error("elements or elements/shapes not available (nullptr)"); @@ -890,7 +890,7 @@ vtkSmartPointer<vtkDataSet> CreateMixedUnstructuredGrid( { conduit_cpp::Node t_subelements = topologyNode["subelements"]; auto subelements = vtkConduitArrayUtilities::O2MRelationToVTKCellArray( - numberOfPoints, conduit_cpp::c_node(&t_subelements), "connectivity"); + numberOfPoints, conduit_cpp::c_node(&t_subelements)); if (!subelements) { throw std::runtime_error("subelements not available (nullptr)");