diff --git a/vtkm/rendering/raytracing/CMakeLists.txt b/vtkm/rendering/raytracing/CMakeLists.txt index 8823c51e9..9ec3ad07f 100644 --- a/vtkm/rendering/raytracing/CMakeLists.txt +++ b/vtkm/rendering/raytracing/CMakeLists.txt @@ -23,7 +23,7 @@ set(headers Logger.h MeshConnectivityBuilder.h MeshConnectivityContainers.h - MeshConnectivityBase.h + MeshConnectivity.h MortonCodes.h PartialComposite.h QuadExtractor.h diff --git a/vtkm/rendering/raytracing/ConnectivityTracer.cxx b/vtkm/rendering/raytracing/ConnectivityTracer.cxx index 59f3a74f3..b1bdf23e7 100644 --- a/vtkm/rendering/raytracing/ConnectivityTracer.cxx +++ b/vtkm/rendering/raytracing/ConnectivityTracer.cxx @@ -19,7 +19,6 @@ #include #include #include -#include #include #include #include @@ -396,7 +395,7 @@ public: vtkm::Int32& enterFace, vtkm::UInt8& rayStatus, const vtkm::Vec& origin, - const MeshWrapper& meshConn) const + const MeshConnectivity& meshConn) const { if (enterFace != -1 && rayStatus == RAY_ACTIVE) { @@ -505,7 +504,7 @@ public: vtkm::UInt8& rayStatus, const vtkm::Vec& origin, vtkm::Vec& rdir, - const MeshWrapper& meshConn, + const MeshConnectivity& meshConn, const LocatorType& locator) const { // We only process lost rays @@ -1036,7 +1035,7 @@ public: vtkm::UInt8& rayStatus, const vtkm::Id& pixelIndex, const vtkm::Vec& origin, - MeshWrapper& meshConn, + MeshConnectivity& meshConn, const ColorMapType& colorMap, FrameBufferType& frameBuffer, const FloatType& maxDistance) const diff --git a/vtkm/rendering/raytracing/ConnectivityTracer.h b/vtkm/rendering/raytracing/ConnectivityTracer.h index ba0112780..ce3f434c5 100644 --- a/vtkm/rendering/raytracing/ConnectivityTracer.h +++ b/vtkm/rendering/raytracing/ConnectivityTracer.h @@ -108,7 +108,7 @@ public: void SetSampleDistance(const vtkm::Float32& distance); void SetColorMap(const vtkm::cont::ArrayHandle& colorMap); - MeshConnContainer* GetMeshContainer() { return MeshContainer; } + MeshConnectivityContainer* GetMeshContainer() { return MeshContainer; } void Init(); @@ -193,7 +193,7 @@ protected: vtkm::Id RaysLost; IntegrationMode Integrator; - MeshConnContainer* MeshContainer; + MeshConnectivityContainer* MeshContainer; vtkm::cont::CellLocatorGeneral Locator; vtkm::Float64 BumpEpsilon; vtkm::Float64 BumpDistance; diff --git a/vtkm/rendering/raytracing/MeshConnectivityBase.h b/vtkm/rendering/raytracing/MeshConnectivity.h similarity index 58% rename from vtkm/rendering/raytracing/MeshConnectivityBase.h rename to vtkm/rendering/raytracing/MeshConnectivity.h index 898a66fc2..c740c9d35 100644 --- a/vtkm/rendering/raytracing/MeshConnectivityBase.h +++ b/vtkm/rendering/raytracing/MeshConnectivity.h @@ -7,14 +7,14 @@ // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // PURPOSE. See the above copyright notice for more information. //============================================================================ -#ifndef vtk_m_rendering_raytracing_MeshConnectivityBase -#define vtk_m_rendering_raytracing_MeshConnectivityBase +#ifndef vtk_m_rendering_raytracing_MeshConnectivity +#define vtk_m_rendering_raytracing_MeshConnectivity #include #include -#include #include #include +#include #include #include #include @@ -27,71 +27,24 @@ namespace rendering { namespace raytracing { -// -// Base class for different types of face-to-connecting-cell -// and other mesh information -// -class VTKM_ALWAYS_EXPORT MeshConnectivityBase : public VirtualObjectBase -{ -public: - VTKM_EXEC_CONT - virtual vtkm::Id GetConnectingCell(const vtkm::Id& cellId, const vtkm::Id& face) const = 0; - VTKM_EXEC_CONT - virtual vtkm::Int32 GetCellIndices(vtkm::Id cellIndices[8], const vtkm::Id& cellId) const = 0; - - VTKM_EXEC_CONT - virtual vtkm::UInt8 GetCellShape(const vtkm::Id& cellId) const = 0; -}; - -// A simple concrete type to wrap MeshConnectivityBase so we can -// pass an ExeObject to worklets. -class MeshWrapper -{ -private: - MeshConnectivityBase* MeshConn; - -public: - MeshWrapper() {} - - MeshWrapper(MeshConnectivityBase* meshConn) - : MeshConn(meshConn){}; - - VTKM_EXEC_CONT - vtkm::Id GetConnectingCell(const vtkm::Id& cellId, const vtkm::Id& face) const - { - return MeshConn->GetConnectingCell(cellId, face); - } - - VTKM_EXEC_CONT - vtkm::Int32 GetCellIndices(vtkm::Id cellIndices[8], const vtkm::Id& cellId) const - { - return MeshConn->GetCellIndices(cellIndices, cellId); - } - - VTKM_EXEC_CONT - vtkm::UInt8 GetCellShape(const vtkm::Id& cellId) const { return MeshConn->GetCellShape(cellId); } -}; - -class VTKM_ALWAYS_EXPORT MeshConnStructured : public MeshConnectivityBase +class VTKM_ALWAYS_EXPORT MeshConnectivityStructured { protected: typedef typename vtkm::cont::ArrayHandle Id4Handle; vtkm::Id3 CellDims; vtkm::Id3 PointDims; - VTKM_CONT MeshConnStructured() = default; - public: VTKM_CONT - MeshConnStructured(const vtkm::Id3& cellDims, const vtkm::Id3& pointDims) + MeshConnectivityStructured(const vtkm::Id3& cellDims, const vtkm::Id3& pointDims) : CellDims(cellDims) , PointDims(pointDims) { } VTKM_EXEC_CONT - vtkm::Id GetConnectingCell(const vtkm::Id& cellId, const vtkm::Id& face) const override + vtkm::Id GetConnectingCell(const vtkm::Id& cellId, const vtkm::Id& face) const { //TODO: there is probably a better way to do this. vtkm::Id3 logicalCellId; @@ -128,7 +81,7 @@ public: } VTKM_EXEC_CONT - vtkm::Int32 GetCellIndices(vtkm::Id cellIndices[8], const vtkm::Id& cellIndex) const override + vtkm::Int32 GetCellIndices(vtkm::Id cellIndices[8], const vtkm::Id& cellIndex) const { vtkm::Id3 cellId; cellId[0] = cellIndex % CellDims[0]; @@ -146,14 +99,13 @@ public: } VTKM_EXEC - vtkm::UInt8 GetCellShape(const vtkm::Id& vtkmNotUsed(cellId)) const override + vtkm::UInt8 GetCellShape(const vtkm::Id& vtkmNotUsed(cellId)) const { return vtkm::UInt8(CELL_SHAPE_HEXAHEDRON); } }; // MeshConnStructured -template -class VTKM_ALWAYS_EXPORT MeshConnUnstructured : public MeshConnectivityBase +class VTKM_ALWAYS_EXPORT MeshConnectivityUnstructured { protected: using IdHandle = typename vtkm::cont::ArrayHandle; @@ -170,26 +122,25 @@ protected: IdConstPortal CellOffsetsPortal; UCharConstPortal ShapesPortal; - VTKM_CONT MeshConnUnstructured() = default; - public: VTKM_CONT - MeshConnUnstructured(const IdHandle& faceConnectivity, - const IdHandle& faceOffsets, - const IdHandle& cellConn, - const IdHandle& cellOffsets, - const UCharHandle& shapes, - vtkm::cont::Token& token) - : FaceConnPortal(faceConnectivity.PrepareForInput(Device(), token)) - , FaceOffsetsPortal(faceOffsets.PrepareForInput(Device(), token)) - , CellConnPortal(cellConn.PrepareForInput(Device(), token)) - , CellOffsetsPortal(cellOffsets.PrepareForInput(Device(), token)) - , ShapesPortal(shapes.PrepareForInput(Device(), token)) + MeshConnectivityUnstructured(const IdHandle& faceConnectivity, + const IdHandle& faceOffsets, + const IdHandle& cellConn, + const IdHandle& cellOffsets, + const UCharHandle& shapes, + vtkm::cont::DeviceAdapterId device, + vtkm::cont::Token& token) + : FaceConnPortal(faceConnectivity.PrepareForInput(device, token)) + , FaceOffsetsPortal(faceOffsets.PrepareForInput(device, token)) + , CellConnPortal(cellConn.PrepareForInput(device, token)) + , CellOffsetsPortal(cellOffsets.PrepareForInput(device, token)) + , ShapesPortal(shapes.PrepareForInput(device, token)) { } VTKM_EXEC_CONT - vtkm::Id GetConnectingCell(const vtkm::Id& cellId, const vtkm::Id& face) const override + vtkm::Id GetConnectingCell(const vtkm::Id& cellId, const vtkm::Id& face) const { BOUNDS_CHECK(FaceOffsetsPortal, cellId); vtkm::Id cellStartIndex = FaceOffsetsPortal.Get(cellId); @@ -199,7 +150,7 @@ public: //---------------------------------------------------------------------------- VTKM_EXEC - vtkm::Int32 GetCellIndices(vtkm::Id cellIndices[8], const vtkm::Id& cellId) const override + vtkm::Int32 GetCellIndices(vtkm::Id cellIndices[8], const vtkm::Id& cellId) const { const vtkm::Int32 shapeId = static_cast(ShapesPortal.Get(cellId)); CellTables tables; @@ -217,7 +168,7 @@ public: //---------------------------------------------------------------------------- VTKM_EXEC - vtkm::UInt8 GetCellShape(const vtkm::Id& cellId) const override + vtkm::UInt8 GetCellShape(const vtkm::Id& cellId) const { BOUNDS_CHECK(ShapesPortal, cellId); return ShapesPortal.Get(cellId); @@ -225,8 +176,7 @@ public: }; // MeshConnUnstructured -template -class MeshConnSingleType : public MeshConnectivityBase +class MeshConnectivitySingleType { protected: using IdHandle = typename vtkm::cont::ArrayHandle; @@ -243,22 +193,19 @@ protected: vtkm::Int32 NumIndices; vtkm::Int32 NumFaces; -private: - VTKM_CONT - MeshConnSingleType() {} - public: VTKM_CONT - MeshConnSingleType(IdHandle& faceConn, - IdHandle& cellConn, - CountingHandle& cellOffsets, - vtkm::Int32 shapeId, - vtkm::Int32 numIndices, - vtkm::Int32 numFaces, - vtkm::cont::Token& token) - : FaceConnPortal(faceConn.PrepareForInput(Device(), token)) - , CellConnectivityPortal(cellConn.PrepareForInput(Device(), token)) - , CellOffsetsPortal(cellOffsets.PrepareForInput(Device(), token)) + MeshConnectivitySingleType(const IdHandle& faceConn, + const IdHandle& cellConn, + const CountingHandle& cellOffsets, + vtkm::Int32 shapeId, + vtkm::Int32 numIndices, + vtkm::Int32 numFaces, + vtkm::cont::DeviceAdapterId device, + vtkm::cont::Token& token) + : FaceConnPortal(faceConn.PrepareForInput(device, token)) + , CellConnectivityPortal(cellConn.PrepareForInput(device, token)) + , CellOffsetsPortal(cellOffsets.PrepareForInput(device, token)) , ShapeId(shapeId) , NumIndices(numIndices) , NumFaces(numFaces) @@ -269,7 +216,7 @@ public: // Execution Environment Methods //---------------------------------------------------------------------------- VTKM_EXEC - vtkm::Id GetConnectingCell(const vtkm::Id& cellId, const vtkm::Id& face) const override + vtkm::Id GetConnectingCell(const vtkm::Id& cellId, const vtkm::Id& face) const { BOUNDS_CHECK(CellOffsetsPortal, cellId); vtkm::Id cellStartIndex = cellId * NumFaces; @@ -278,7 +225,7 @@ public: } VTKM_EXEC - vtkm::Int32 GetCellIndices(vtkm::Id cellIndices[8], const vtkm::Id& cellId) const override + vtkm::Int32 GetCellIndices(vtkm::Id cellIndices[8], const vtkm::Id& cellId) const { BOUNDS_CHECK(CellOffsetsPortal, cellId); const vtkm::Id cellOffset = CellOffsetsPortal.Get(cellId); @@ -294,55 +241,89 @@ public: //---------------------------------------------------------------------------- VTKM_EXEC - vtkm::UInt8 GetCellShape(const vtkm::Id& vtkmNotUsed(cellId)) const override + vtkm::UInt8 GetCellShape(const vtkm::Id& vtkmNotUsed(cellId)) const { return vtkm::UInt8(ShapeId); } }; //MeshConn Single type specialization -class VTKM_ALWAYS_EXPORT MeshConnHandle - : public vtkm::cont::VirtualObjectHandle +/// \brief General version of mesh connectivity that can be used for all supported mesh types. +class VTKM_ALWAYS_EXPORT MeshConnectivity { -private: - using Superclass = vtkm::cont::VirtualObjectHandle; + using ConnectivityType = vtkm::exec::internal:: + Variant; + ConnectivityType Connectivity; public: - MeshConnHandle() = default; - - template - explicit MeshConnHandle(MeshConnType* meshConn, - bool aquireOwnership = true, - DeviceAdapterList devices = DeviceAdapterList()) - : Superclass(meshConn, aquireOwnership, devices) + // Constructor for structured connectivity + VTKM_CONT MeshConnectivity(const vtkm::Id3& cellDims, const vtkm::Id3& pointDims) + : Connectivity(MeshConnectivityStructured(cellDims, pointDims)) { } + + // Constructor for unstructured connectivity + VTKM_CONT MeshConnectivity(const vtkm::cont::ArrayHandle& faceConnectivity, + const vtkm::cont::ArrayHandle& faceOffsets, + const vtkm::cont::ArrayHandle& cellConn, + const vtkm::cont::ArrayHandle& cellOffsets, + const vtkm::cont::ArrayHandle& shapes, + vtkm::cont::DeviceAdapterId device, + vtkm::cont::Token& token) + : Connectivity(MeshConnectivityUnstructured(faceConnectivity, + faceOffsets, + cellConn, + cellOffsets, + shapes, + device, + token)) + { + } + + // Constructor for unstructured connectivity with single cell type + VTKM_CONT MeshConnectivity(const vtkm::cont::ArrayHandle& faceConn, + const vtkm::cont::ArrayHandle& cellConn, + const vtkm::cont::ArrayHandleCounting& cellOffsets, + vtkm::Int32 shapeId, + vtkm::Int32 numIndices, + vtkm::Int32 numFaces, + vtkm::cont::DeviceAdapterId device, + vtkm::cont::Token& token) + : Connectivity(MeshConnectivitySingleType(faceConn, + cellConn, + cellOffsets, + shapeId, + numIndices, + numFaces, + device, + token)) + { + } + + VTKM_EXEC_CONT + vtkm::Id GetConnectingCell(const vtkm::Id& cellId, const vtkm::Id& face) const + { + return this->Connectivity.CastAndCall( + [=](auto conn) { return conn.GetConnectingCell(cellId, face); }); + } + + VTKM_EXEC_CONT + vtkm::Int32 GetCellIndices(vtkm::Id cellIndices[8], const vtkm::Id& cellId) const + { + return this->Connectivity.CastAndCall( + [=](auto conn) { return conn.GetCellIndices(cellIndices, cellId); }); + } + + VTKM_EXEC_CONT + vtkm::UInt8 GetCellShape(const vtkm::Id& cellId) const + { + return this->Connectivity.CastAndCall([=](auto conn) { return conn.GetCellShape(cellId); }); + } }; -template -VTKM_CONT MeshConnHandle make_MeshConnHandle(MeshConnType&& func, - DeviceAdapterList devices = DeviceAdapterList()) -{ - using IFType = typename std::remove_reference::type; - return MeshConnHandle(new IFType(std::forward(func)), true, devices); -} } } } //namespace vtkm::rendering::raytracing -// Cuda seems to have a bug where it expects the template class VirtualObjectTransfer -// to be instantiated in a consistent order among all the translation units of an -// executable. Failing to do so results in random crashes and incorrect results. -// We workaroud this issue by explicitly instantiating VirtualObjectTransfer for -// all the implicit functions here. -#ifdef VTKM_CUDA -#include -VTKM_EXPLICITLY_INSTANTIATE_TRANSFER(vtkm::rendering::raytracing::MeshConnStructured); -VTKM_EXPLICITLY_INSTANTIATE_TRANSFER_CUDA( - vtkm::rendering::raytracing::MeshConnUnstructured); -VTKM_EXPLICITLY_INSTANTIATE_TRANSFER_KOKKOS( - vtkm::rendering::raytracing::MeshConnUnstructured); -#endif - -#endif // MeshConnectivityBase +#endif // MeshConnectivity diff --git a/vtkm/rendering/raytracing/MeshConnectivityBuilder.cxx b/vtkm/rendering/raytracing/MeshConnectivityBuilder.cxx index 0ac3cbb7d..c9fb9aa98 100644 --- a/vtkm/rendering/raytracing/MeshConnectivityBuilder.cxx +++ b/vtkm/rendering/raytracing/MeshConnectivityBuilder.cxx @@ -839,7 +839,7 @@ vtkm::cont::ArrayHandle MeshConnectivityBuilder::GetTriangles() } VTKM_CONT -MeshConnContainer* MeshConnectivityBuilder::BuildConnectivity( +MeshConnectivityContainer* MeshConnectivityBuilder::BuildConnectivity( const vtkm::cont::DynamicCellSet& cellset, const vtkm::cont::CoordinateSystem& coordinates) { @@ -891,7 +891,7 @@ MeshConnContainer* MeshConnectivityBuilder::BuildConnectivity( Logger* logger = Logger::GetInstance(); logger->OpenLogEntry("mesh_conn_construction"); - MeshConnContainer* meshConn = nullptr; + MeshConnectivityContainer* meshConn = nullptr; vtkm::cont::Timer timer; timer.Start(); @@ -899,20 +899,21 @@ MeshConnContainer* MeshConnectivityBuilder::BuildConnectivity( { vtkm::cont::CellSetExplicit<> cells = cellset.Cast>(); this->BuildConnectivity(cells, coordinates.GetDataAsMultiplexer(), coordBounds); - meshConn = - new UnstructuredContainer(cells, coordinates, FaceConnectivity, FaceOffsets, Triangles); + meshConn = new MeshConnectivityContainerUnstructured( + cells, coordinates, FaceConnectivity, FaceOffsets, Triangles); } else if (type == UnstructuredSingle) { vtkm::cont::CellSetSingleType<> cells = cellset.Cast>(); this->BuildConnectivity(cells, coordinates.GetDataAsMultiplexer(), coordBounds); - meshConn = new UnstructuredSingleContainer(cells, coordinates, FaceConnectivity, Triangles); + meshConn = + new MeshConnectivityContainerSingleType(cells, coordinates, FaceConnectivity, Triangles); } else if (type == Structured) { vtkm::cont::CellSetStructured<3> cells = cellset.Cast>(); Triangles = this->ExternalTrianglesStructured(cells); - meshConn = new StructuredContainer(cells, coordinates, Triangles); + meshConn = new MeshConnectivityContainerStructured(cells, coordinates, Triangles); } else { diff --git a/vtkm/rendering/raytracing/MeshConnectivityBuilder.h b/vtkm/rendering/raytracing/MeshConnectivityBuilder.h index 102615fda..0fc68e256 100644 --- a/vtkm/rendering/raytracing/MeshConnectivityBuilder.h +++ b/vtkm/rendering/raytracing/MeshConnectivityBuilder.h @@ -27,8 +27,8 @@ public: ~MeshConnectivityBuilder(); VTKM_CONT - MeshConnContainer* BuildConnectivity(const vtkm::cont::DynamicCellSet& cellset, - const vtkm::cont::CoordinateSystem& coordinates); + MeshConnectivityContainer* BuildConnectivity(const vtkm::cont::DynamicCellSet& cellset, + const vtkm::cont::CoordinateSystem& coordinates); VTKM_CONT vtkm::cont::ArrayHandle ExternalTrianglesStructured( diff --git a/vtkm/rendering/raytracing/MeshConnectivityContainers.cxx b/vtkm/rendering/raytracing/MeshConnectivityContainers.cxx index c9330b1b3..3428d4f36 100644 --- a/vtkm/rendering/raytracing/MeshConnectivityContainers.cxx +++ b/vtkm/rendering/raytracing/MeshConnectivityContainers.cxx @@ -14,7 +14,7 @@ #include #include #include -#include +#include #include #include #include @@ -25,11 +25,11 @@ namespace rendering namespace raytracing { -MeshConnContainer::MeshConnContainer(){}; -MeshConnContainer::~MeshConnContainer(){}; +MeshConnectivityContainer::MeshConnectivityContainer(){}; +MeshConnectivityContainer::~MeshConnectivityContainer(){}; template -VTKM_CONT void MeshConnContainer::FindEntryImpl(Ray& rays) +VTKM_CONT void MeshConnectivityContainer::FindEntryImpl(Ray& rays) { bool getCellIndex = true; @@ -38,28 +38,23 @@ VTKM_CONT void MeshConnContainer::FindEntryImpl(Ray& rays) Intersector.IntersectRays(rays, getCellIndex); } -MeshWrapper MeshConnContainer::PrepareForExecution(const vtkm::cont::DeviceAdapterId deviceId, - vtkm::cont::Token& token) -{ - return MeshWrapper(const_cast(this->Construct(deviceId, token))); -} - -void MeshConnContainer::FindEntry(Ray& rays) +void MeshConnectivityContainer::FindEntry(Ray& rays) { this->FindEntryImpl(rays); } -void MeshConnContainer::FindEntry(Ray& rays) +void MeshConnectivityContainer::FindEntry(Ray& rays) { this->FindEntryImpl(rays); } VTKM_CONT -UnstructuredContainer::UnstructuredContainer(const vtkm::cont::CellSetExplicit<>& cellset, - const vtkm::cont::CoordinateSystem& coords, - IdHandle& faceConn, - IdHandle& faceOffsets, - Id4Handle& triangles) +MeshConnectivityContainerUnstructured::MeshConnectivityContainerUnstructured( + const vtkm::cont::CellSetExplicit<>& cellset, + const vtkm::cont::CoordinateSystem& coords, + const IdHandle& faceConn, + const IdHandle& faceOffsets, + const Id4Handle& triangles) : FaceConnectivity(faceConn) , FaceOffsets(faceOffsets) , Cellset(cellset) @@ -78,96 +73,27 @@ UnstructuredContainer::UnstructuredContainer(const vtkm::cont::CellSetExplicit<> Intersector.SetData(Coords, Triangles); } -UnstructuredContainer::~UnstructuredContainer(){}; +MeshConnectivityContainerUnstructured::~MeshConnectivityContainerUnstructured(){}; -const MeshConnectivityBase* UnstructuredContainer::Construct( - const vtkm::cont::DeviceAdapterId deviceId, - vtkm::cont::Token& token) +MeshConnectivity MeshConnectivityContainerUnstructured::PrepareForExecution( + vtkm::cont::DeviceAdapterId deviceId, + vtkm::cont::Token& token) const { - switch (deviceId.GetValue()) - { -#ifdef VTKM_ENABLE_OPENMP - case VTKM_DEVICE_ADAPTER_OPENMP: - using OMP = vtkm::cont::DeviceAdapterTagOpenMP; - { - MeshConnUnstructured conn(this->FaceConnectivity, - this->FaceOffsets, - this->CellConn, - this->CellOffsets, - this->Shapes, - token); - Handle = make_MeshConnHandle(conn); - } - return Handle.PrepareForExecution(OMP(), token); -#endif -#ifdef VTKM_ENABLE_TBB - case VTKM_DEVICE_ADAPTER_TBB: - using TBB = vtkm::cont::DeviceAdapterTagTBB; - { - MeshConnUnstructured conn(this->FaceConnectivity, - this->FaceOffsets, - this->CellConn, - this->CellOffsets, - this->Shapes, - token); - Handle = make_MeshConnHandle(conn); - } - return Handle.PrepareForExecution(TBB(), token); -#endif -#ifdef VTKM_ENABLE_CUDA - case VTKM_DEVICE_ADAPTER_CUDA: - using CUDA = vtkm::cont::DeviceAdapterTagCuda; - { - MeshConnUnstructured conn(this->FaceConnectivity, - this->FaceOffsets, - this->CellConn, - this->CellOffsets, - this->Shapes, - token); - Handle = make_MeshConnHandle(conn); - } - return Handle.PrepareForExecution(CUDA(), token); -#endif -#ifdef VTKM_ENABLE_KOKKOS - case VTKM_DEVICE_ADAPTER_KOKKOS: - using KOKKOS = vtkm::cont::DeviceAdapterTagKokkos; - { - MeshConnUnstructured conn(this->FaceConnectivity, - this->FaceOffsets, - this->CellConn, - this->CellOffsets, - this->Shapes, - token); - Handle = make_MeshConnHandle(conn); - } - return Handle.PrepareForExecution(KOKKOS(), token); -#endif - case VTKM_DEVICE_ADAPTER_SERIAL: - VTKM_FALLTHROUGH; - default: - using SERIAL = vtkm::cont::DeviceAdapterTagSerial; - { - MeshConnUnstructured conn(this->FaceConnectivity, - this->FaceOffsets, - this->CellConn, - this->CellOffsets, - this->Shapes, - token); - Handle = make_MeshConnHandle(conn); - } - return Handle.PrepareForExecution(SERIAL(), token); - } + return MeshConnectivity(this->FaceConnectivity, + this->FaceOffsets, + this->CellConn, + this->CellOffsets, + this->Shapes, + deviceId, + token); } VTKM_CONT -UnstructuredSingleContainer::UnstructuredSingleContainer() {} - -VTKM_CONT -UnstructuredSingleContainer::UnstructuredSingleContainer( +MeshConnectivityContainerSingleType::MeshConnectivityContainerSingleType( const vtkm::cont::CellSetSingleType<>& cellset, const vtkm::cont::CoordinateSystem& coords, - IdHandle& faceConn, - Id4Handle& triangles) + const IdHandle& faceConn, + const Id4Handle& triangles) : FaceConnectivity(faceConn) , Coords(coords) , Cellset(cellset) @@ -177,16 +103,16 @@ UnstructuredSingleContainer::UnstructuredSingleContainer( this->Intersector.SetUseWaterTight(true); - CellConnectivity = + this->CellConnectivity = Cellset.GetConnectivityArray(vtkm::TopologyElementTagCell(), vtkm::TopologyElementTagPoint()); vtkm::cont::ArrayHandleConstant shapes = Cellset.GetShapesArray(vtkm::TopologyElementTagCell(), vtkm::TopologyElementTagPoint()); - ShapeId = shapes.ReadPortal().Get(0); + this->ShapeId = shapes.ReadPortal().Get(0); CellTables tables; - NumIndices = tables.FaceLookUp(tables.CellTypeLookUp(ShapeId), 2); + this->NumIndices = tables.FaceLookUp(tables.CellTypeLookUp(ShapeId), 2); - if (NumIndices == 0) + if (this->NumIndices == 0) { std::stringstream message; message << "Unstructured Mesh Connecitity Single type Error: unsupported cell type: "; @@ -194,147 +120,53 @@ UnstructuredSingleContainer::UnstructuredSingleContainer( throw vtkm::cont::ErrorBadValue(message.str()); } vtkm::Id start = 0; - NumFaces = tables.FaceLookUp(tables.CellTypeLookUp(ShapeId), 1); - vtkm::Id numCells = CellConnectivity.ReadPortal().GetNumberOfValues(); - CellOffsets = vtkm::cont::make_ArrayHandleCounting(start, NumIndices, numCells); + this->NumFaces = tables.FaceLookUp(tables.CellTypeLookUp(this->ShapeId), 1); + vtkm::Id numCells = this->CellConnectivity.ReadPortal().GetNumberOfValues(); + this->CellOffsets = + vtkm::cont::make_ArrayHandleCounting(start, this->NumIndices, numCells); Logger* logger = Logger::GetInstance(); logger->OpenLogEntry("mesh_conn_construction"); - Intersector.SetData(Coords, Triangles); + this->Intersector.SetData(Coords, Triangles); } -const MeshConnectivityBase* UnstructuredSingleContainer::Construct( - const vtkm::cont::DeviceAdapterId deviceId, - vtkm::cont::Token& token) +MeshConnectivity MeshConnectivityContainerSingleType::PrepareForExecution( + vtkm::cont::DeviceAdapterId deviceId, + vtkm::cont::Token& token) const { - switch (deviceId.GetValue()) - { -#ifdef VTKM_ENABLE_OPENMP - case VTKM_DEVICE_ADAPTER_OPENMP: - using OMP = vtkm::cont::DeviceAdapterTagOpenMP; - { - MeshConnSingleType conn(this->FaceConnectivity, - this->CellConnectivity, - this->CellOffsets, - this->ShapeId, - this->NumIndices, - this->NumFaces, - token); - Handle = make_MeshConnHandle(conn); - } - return Handle.PrepareForExecution(OMP(), token); -#endif -#ifdef VTKM_ENABLE_TBB - case VTKM_DEVICE_ADAPTER_TBB: - using TBB = vtkm::cont::DeviceAdapterTagTBB; - { - MeshConnSingleType conn(this->FaceConnectivity, - this->CellConnectivity, - this->CellOffsets, - this->ShapeId, - this->NumIndices, - this->NumFaces, - token); - Handle = make_MeshConnHandle(conn); - } - return Handle.PrepareForExecution(TBB(), token); -#endif -#ifdef VTKM_ENABLE_CUDA - case VTKM_DEVICE_ADAPTER_CUDA: - using CUDA = vtkm::cont::DeviceAdapterTagCuda; - { - MeshConnSingleType conn(this->FaceConnectivity, - this->CellConnectivity, - this->CellOffsets, - this->ShapeId, - this->NumIndices, - this->NumFaces, - token); - Handle = make_MeshConnHandle(conn); - } - return Handle.PrepareForExecution(CUDA(), token); -#endif -#ifdef VTKM_ENABLE_KOKKOS - case VTKM_DEVICE_ADAPTER_KOKKOS: - using KOKKOS = vtkm::cont::DeviceAdapterTagKokkos; - { - MeshConnSingleType conn(this->FaceConnectivity, - this->CellConnectivity, - this->CellOffsets, - this->ShapeId, - this->NumIndices, - this->NumFaces, - token); - Handle = make_MeshConnHandle(conn); - } - return Handle.PrepareForExecution(KOKKOS(), token); -#endif - case VTKM_DEVICE_ADAPTER_SERIAL: - VTKM_FALLTHROUGH; - default: - using SERIAL = vtkm::cont::DeviceAdapterTagSerial; - { - MeshConnSingleType conn(this->FaceConnectivity, - this->CellConnectivity, - this->CellOffsets, - this->ShapeId, - this->NumIndices, - this->NumFaces, - token); - Handle = make_MeshConnHandle(conn); - } - return Handle.PrepareForExecution(SERIAL(), token); - } + return MeshConnectivity(this->FaceConnectivity, + this->CellConnectivity, + this->CellOffsets, + this->ShapeId, + this->NumIndices, + this->NumFaces, + deviceId, + token); } -StructuredContainer::StructuredContainer(const vtkm::cont::CellSetStructured<3>& cellset, - const vtkm::cont::CoordinateSystem& coords, - Id4Handle& triangles) +MeshConnectivityContainerStructured::MeshConnectivityContainerStructured( + const vtkm::cont::CellSetStructured<3>& cellset, + const vtkm::cont::CoordinateSystem& coords, + const Id4Handle& triangles) : Coords(coords) , Cellset(cellset) { - Triangles = triangles; - Intersector.SetUseWaterTight(true); + this->Triangles = triangles; + this->Intersector.SetUseWaterTight(true); - PointDims = Cellset.GetPointDimensions(); - CellDims = Cellset.GetCellDimensions(); + this->PointDims = this->Cellset.GetPointDimensions(); + this->CellDims = this->Cellset.GetCellDimensions(); this->Intersector.SetData(Coords, Triangles); } -const MeshConnectivityBase* StructuredContainer::Construct( - const vtkm::cont::DeviceAdapterId deviceId, - vtkm::cont::Token& token) +MeshConnectivity MeshConnectivityContainerStructured::PrepareForExecution( + vtkm::cont::DeviceAdapterId, + vtkm::cont::Token&) const { - - MeshConnStructured conn(CellDims, PointDims); - Handle = make_MeshConnHandle(conn); - - switch (deviceId.GetValue()) - { -#ifdef VTKM_ENABLE_OPENMP - case VTKM_DEVICE_ADAPTER_OPENMP: - return Handle.PrepareForExecution(vtkm::cont::DeviceAdapterTagOpenMP(), token); -#endif -#ifdef VTKM_ENABLE_TBB - case VTKM_DEVICE_ADAPTER_TBB: - return Handle.PrepareForExecution(vtkm::cont::DeviceAdapterTagTBB(), token); -#endif -#ifdef VTKM_ENABLE_CUDA - case VTKM_DEVICE_ADAPTER_CUDA: - return Handle.PrepareForExecution(vtkm::cont::DeviceAdapterTagCuda(), token); -#endif -#ifdef VTKM_ENABLE_KOKKOS - case VTKM_DEVICE_ADAPTER_KOKKOS: - return Handle.PrepareForExecution(vtkm::cont::DeviceAdapterTagKokkos(), token); -#endif - case VTKM_DEVICE_ADAPTER_SERIAL: - VTKM_FALLTHROUGH; - default: - return Handle.PrepareForExecution(vtkm::cont::DeviceAdapterTagSerial(), token); - } + return MeshConnectivity(CellDims, PointDims); } } } diff --git a/vtkm/rendering/raytracing/MeshConnectivityContainers.h b/vtkm/rendering/raytracing/MeshConnectivityContainers.h index 2a19f34b8..80d8b673d 100644 --- a/vtkm/rendering/raytracing/MeshConnectivityContainers.h +++ b/vtkm/rendering/raytracing/MeshConnectivityContainers.h @@ -11,7 +11,7 @@ #define vtk_m_rendering_raytracing_MeshConnectivityContainer_h #include -#include +#include #include namespace vtkm @@ -21,20 +21,14 @@ namespace rendering namespace raytracing { -class MeshConnContainer : vtkm::cont::ExecutionObjectBase +class MeshConnectivityContainer : vtkm::cont::ExecutionObjectBase { public: - MeshConnContainer(); - virtual ~MeshConnContainer(); + MeshConnectivityContainer(); + virtual ~MeshConnectivityContainer(); - virtual const MeshConnectivityBase* Construct(const vtkm::cont::DeviceAdapterId deviceId, - vtkm::cont::Token& token) = 0; - - MeshWrapper PrepareForExecution(const vtkm::cont::DeviceAdapterId deviceId, - vtkm::cont::Token& token); - - template - VTKM_CONT void FindEntryImpl(Ray& rays); + virtual MeshConnectivity PrepareForExecution(vtkm::cont::DeviceAdapterId deviceId, + vtkm::cont::Token& token) const = 0; void FindEntry(Ray& rays); @@ -45,10 +39,13 @@ protected: // Mesh Boundary Id4Handle Triangles; TriangleIntersector Intersector; - MeshConnHandle Handle; + +private: + template + VTKM_CONT void FindEntryImpl(Ray& rays); }; -class UnstructuredContainer : public MeshConnContainer +class MeshConnectivityContainerUnstructured : public MeshConnectivityContainer { public: typedef vtkm::cont::ArrayHandle IdHandle; @@ -67,25 +64,21 @@ public: vtkm::cont::CellSetExplicit<> Cellset; vtkm::cont::CoordinateSystem Coords; -private: - VTKM_CONT - UnstructuredContainer(){}; - public: VTKM_CONT - UnstructuredContainer(const vtkm::cont::CellSetExplicit<>& cellset, - const vtkm::cont::CoordinateSystem& coords, - IdHandle& faceConn, - IdHandle& faceOffsets, - Id4Handle& triangles); + MeshConnectivityContainerUnstructured(const vtkm::cont::CellSetExplicit<>& cellset, + const vtkm::cont::CoordinateSystem& coords, + const IdHandle& faceConn, + const IdHandle& faceOffsets, + const Id4Handle& triangles); - virtual ~UnstructuredContainer(); + virtual ~MeshConnectivityContainerUnstructured(); - const MeshConnectivityBase* Construct(const vtkm::cont::DeviceAdapterId deviceId, - vtkm::cont::Token& token) override; + MeshConnectivity PrepareForExecution(vtkm::cont::DeviceAdapterId deviceId, + vtkm::cont::Token& token) const override; }; -class StructuredContainer : public MeshConnContainer +class MeshConnectivityContainerStructured : public MeshConnectivityContainer { protected: typedef vtkm::cont::ArrayHandle Id4Handle; @@ -95,22 +88,18 @@ protected: vtkm::cont::CoordinateSystem Coords; vtkm::cont::CellSetStructured<3> Cellset; -private: - VTKM_CONT - StructuredContainer() {} - public: VTKM_CONT - StructuredContainer(const vtkm::cont::CellSetStructured<3>& cellset, - const vtkm::cont::CoordinateSystem& coords, - Id4Handle& triangles); + MeshConnectivityContainerStructured(const vtkm::cont::CellSetStructured<3>& cellset, + const vtkm::cont::CoordinateSystem& coords, + const Id4Handle& triangles); - const MeshConnectivityBase* Construct(const vtkm::cont::DeviceAdapterId deviceId, - vtkm::cont::Token& token) override; + MeshConnectivity PrepareForExecution(vtkm::cont::DeviceAdapterId deviceId, + vtkm::cont::Token& token) const override; }; //structure mesh conn -class UnstructuredSingleContainer : public MeshConnContainer +class MeshConnectivityContainerSingleType : public MeshConnectivityContainer { public: typedef vtkm::cont::ArrayHandle IdHandle; @@ -131,19 +120,15 @@ public: vtkm::Int32 NumIndices; vtkm::Int32 NumFaces; -private: - VTKM_CONT - UnstructuredSingleContainer(); - public: VTKM_CONT - UnstructuredSingleContainer(const vtkm::cont::CellSetSingleType<>& cellset, - const vtkm::cont::CoordinateSystem& coords, - IdHandle& faceConn, - Id4Handle& externalFaces); + MeshConnectivityContainerSingleType(const vtkm::cont::CellSetSingleType<>& cellset, + const vtkm::cont::CoordinateSystem& coords, + const IdHandle& faceConn, + const Id4Handle& externalFaces); - const MeshConnectivityBase* Construct(const vtkm::cont::DeviceAdapterId deviceId, - vtkm::cont::Token& token) override; + MeshConnectivity PrepareForExecution(vtkm::cont::DeviceAdapterId deviceId, + vtkm::cont::Token& token) const override; }; //UnstructuredSingleContainer }