Commit 887f79c6 authored by Kenneth Moreland's avatar Kenneth Moreland

Make a vtkm_worklet library

This is a library that contains parts of worklets that can be
precompiled into a library.

Currently, this library contains the implementation of ScatterCounting.
parent ef0054ee
......@@ -69,7 +69,7 @@ set(benchmarks
)
foreach (benchmark ${benchmarks})
add_benchmark(${benchmark} ${benchmark}.cxx vtkm_cont)
add_benchmark(${benchmark} ${benchmark}.cxx vtkm_filter)
endforeach ()
if(TARGET vtkm_rendering)
......
......@@ -28,13 +28,13 @@ find_package(VTKm REQUIRED QUIET)
add_executable(Clipping_SERIAL Clipping.cxx)
target_compile_definitions(Clipping_SERIAL PRIVATE
"VTKM_DEVICE_ADAPTER=VTKM_DEVICE_ADAPTER_SERIAL")
target_link_libraries(Clipping_SERIAL PRIVATE vtkm_cont)
target_link_libraries(Clipping_SERIAL PRIVATE vtkm_filter)
if(TARGET vtkm::tbb)
add_executable(Clipping_TBB Clipping.cxx)
target_compile_definitions(Clipping_TBB PRIVATE
"VTKM_DEVICE_ADAPTER=VTKM_DEVICE_ADAPTER_TBB")
target_link_libraries(Clipping_TBB PRIVATE vtkm_cont)
target_link_libraries(Clipping_TBB PRIVATE vtkm_filter)
endif()
if(TARGET vtkm::cuda)
......@@ -43,5 +43,5 @@ if(TARGET vtkm::cuda)
target_compile_definitions(Clipping_CUDA PRIVATE
"VTKM_DEVICE_ADAPTER=VTKM_DEVICE_ADAPTER_CUDA")
target_link_libraries(Clipping_CUDA PRIVATE vtkm_cont)
target_link_libraries(Clipping_CUDA PRIVATE vtkm_filter)
endif()
......@@ -26,10 +26,10 @@ project(ContourTree CXX)
find_package(VTKm REQUIRED QUIET)
add_executable(ContourTreeMesh2D_SERIAL ContourTreeMesh2D.cxx)
target_link_libraries(ContourTreeMesh2D_SERIAL vtkm_cont)
target_link_libraries(ContourTreeMesh2D_SERIAL vtkm_filter)
add_executable(ContourTreeMesh3D_SERIAL ContourTreeMesh3D.cxx)
target_link_libraries(ContourTreeMesh3D_SERIAL vtkm_cont)
target_link_libraries(ContourTreeMesh3D_SERIAL vtkm_filter)
target_compile_definitions(ContourTreeMesh2D_SERIAL PRIVATE
"VTKM_DEVICE_ADAPTER=VTKM_DEVICE_ADAPTER_SERIAL")
......@@ -43,8 +43,8 @@ if(TARGET vtkm::cuda)
vtkm_compile_as_cuda(cudaSource ContourTreeMesh3D.cxx)
add_executable(ContourTreeMesh3D_CUDA ${cudaSource})
target_link_libraries(ContourTreeMesh2D_CUDA vtkm_cont)
target_link_libraries(ContourTreeMesh3D_CUDA vtkm_cont)
target_link_libraries(ContourTreeMesh2D_CUDA vtkm_filter)
target_link_libraries(ContourTreeMesh3D_CUDA vtkm_filter)
target_compile_definitions(ContourTreeMesh2D_CUDA PRIVATE
"VTKM_DEVICE_ADAPTER=VTKM_DEVICE_ADAPTER_CUDA")
......@@ -56,8 +56,8 @@ if(TARGET vtkm::tbb)
add_executable(ContourTreeMesh2D_TBB ContourTreeMesh2D.cxx)
add_executable(ContourTreeMesh3D_TBB ContourTreeMesh3D.cxx)
target_link_libraries(ContourTreeMesh2D_TBB vtkm_cont)
target_link_libraries(ContourTreeMesh3D_TBB vtkm_cont)
target_link_libraries(ContourTreeMesh2D_TBB vtkm_filter)
target_link_libraries(ContourTreeMesh3D_TBB vtkm_filter)
target_compile_definitions(ContourTreeMesh2D_TBB PRIVATE
"VTKM_DEVICE_ADAPTER=VTKM_DEVICE_ADAPTER_TBB")
......
......@@ -77,7 +77,7 @@ find_package(VTKm REQUIRED QUIET)
####################################
# Serial 2D / 3D / MC
add_executable(ContourTree_PPP2_SERIAL ContourTreeApp.cxx)
target_link_libraries(ContourTree_PPP2_SERIAL vtkm_cont)
target_link_libraries(ContourTree_PPP2_SERIAL vtkm_filter)
target_compile_definitions(ContourTree_PPP2_SERIAL PRIVATE
"VTKM_DEVICE_ADAPTER=VTKM_DEVICE_ADAPTER_SERIAL")
......@@ -88,7 +88,7 @@ target_compile_definitions(ContourTree_PPP2_SERIAL PRIVATE
# Debug Serial 2D / 3D / MC
add_executable(ContourTree_PPP2_SERIAL_DEBUG ContourTreeApp.cxx)
target_link_libraries(ContourTree_PPP2_SERIAL_DEBUG vtkm_cont)
target_link_libraries(ContourTree_PPP2_SERIAL_DEBUG vtkm_filter)
target_compile_definitions(ContourTree_PPP2_SERIAL_DEBUG PRIVATE
"VTKM_DEVICE_ADAPTER=VTKM_DEVICE_ADAPTER_SERIAL" "DEBUG_PRINT")
......@@ -96,13 +96,13 @@ target_compile_definitions(ContourTree_PPP2_SERIAL_DEBUG PRIVATE
if(TARGET vtkm::tbb)
# TBB 2D/3D/MC
add_executable(ContourTree_PPP2_TBB ContourTreeApp.cxx)
target_link_libraries(ContourTree_PPP2_TBB vtkm_cont)
target_link_libraries(ContourTree_PPP2_TBB vtkm_filter)
target_compile_definitions(ContourTree_PPP2_TBB PRIVATE
"VTKM_DEVICE_ADAPTER=VTKM_DEVICE_ADAPTER_TBB" "ENABLE_SET_NUM_THREADS")
# TBB 2D/3D/MC DEBUG
add_executable(ContourTree_PPP2_TBB_DEBUG ContourTreeApp.cxx)
target_link_libraries(ContourTree_PPP2_TBB_DEBUG vtkm_cont)
target_link_libraries(ContourTree_PPP2_TBB_DEBUG vtkm_filter)
target_compile_definitions(ContourTree_PPP2_TBB_DEBUG PRIVATE
"VTKM_DEVICE_ADAPTER=VTKM_DEVICE_ADAPTER_TBB" "ENABLE_SET_NUM_THREADS" "DEBUG_PRINT")
......@@ -112,14 +112,14 @@ if(TARGET vtkm::cuda)
# CUDA 2D/3D/MC
vtkm_compile_as_cuda(cudaSource ContourTreeApp.cxx)
add_executable(ContourTree_PPP2_CUDA ${cudaSource})
target_link_libraries(ContourTree_PPP2_CUDA vtkm_cont)
target_link_libraries(ContourTree_PPP2_CUDA vtkm_filter)
target_compile_definitions(ContourTree_PPP2_CUDA PRIVATE
"VTKM_DEVICE_ADAPTER=VTKM_DEVICE_ADAPTER_CUDA")
# CUDA 2D/3D/MC
# vtkm_compile_as_cuda(cudaSource ContourTreeApp.cxx)
add_executable(ContourTree_PPP2_CUDA_DEBUG ${cudaSource})
target_link_libraries(ContourTree_PPP2_CUDA_DEBUG vtkm_cont)
target_link_libraries(ContourTree_PPP2_CUDA_DEBUG vtkm_filter)
target_compile_definitions(ContourTree_PPP2_CUDA_DEBUG PRIVATE
"VTKM_DEVICE_ADAPTER=VTKM_DEVICE_ADAPTER_CUDA" "DEBUG_PRINT")
endif()
......@@ -36,5 +36,5 @@ else()
add_executable(CosmoHaloFinder CosmoHaloFinder.cxx)
endif()
target_link_libraries(CosmoCenterFinder PRIVATE vtkm_cont)
target_link_libraries(CosmoHaloFinder PRIVATE vtkm_cont)
target_link_libraries(CosmoCenterFinder PRIVATE vtkm_filter)
target_link_libraries(CosmoHaloFinder PRIVATE vtkm_filter)
......@@ -35,5 +35,5 @@ if(TARGET OpenGL::GL AND
add_executable(GameOfLife GameOfLife.cxx LoadShaders.h)
endif()
target_link_libraries(GameOfLife PRIVATE vtkm_cont OpenGL::GL GLEW::GLEW GLUT::GLUT)
target_link_libraries(GameOfLife PRIVATE vtkm_filter OpenGL::GL GLEW::GLEW GLUT::GLUT)
endif()
......@@ -37,6 +37,6 @@ if(TARGET OpenGL::GL AND
else()
add_executable(HelloWorld HelloWorld.cxx LoadShaders.h)
endif()
target_link_libraries(HelloWorld PRIVATE vtkm_cont ${gl_libs})
target_link_libraries(HelloWorld PRIVATE vtkm_filter ${gl_libs})
endif()
......@@ -28,13 +28,13 @@ if (VTKm_ENABLE_MPI)
add_executable(Histogram_SERIAL Histogram.cxx HistogramMPI.h HistogramMPI.hxx)
target_compile_definitions(Histogram_SERIAL PRIVATE
"VTKM_DEVICE_ADAPTER=VTKM_DEVICE_ADAPTER_SERIAL")
target_link_libraries(Histogram_SERIAL PRIVATE vtkm_cont)
target_link_libraries(Histogram_SERIAL PRIVATE vtkm_filter)
if(TARGET vtkm::tbb)
add_executable(Histogram_TBB Histogram.cxx HistogramMPI.h HistogramMPI.hxx)
target_compile_definitions(Histogram_TBB PRIVATE
"VTKM_DEVICE_ADAPTER=VTKM_DEVICE_ADAPTER_TBB")
target_link_libraries(Histogram_TBB PRIVATE vtkm_cont)
target_link_libraries(Histogram_TBB PRIVATE vtkm_filter)
endif()
if(TARGET vtkm::cuda)
......@@ -43,6 +43,6 @@ if (VTKm_ENABLE_MPI)
target_compile_definitions(Histogram_CUDA PRIVATE
"VTKM_DEVICE_ADAPTER=VTKM_DEVICE_ADAPTER_CUDA")
target_link_libraries(Histogram_CUDA PRIVATE vtkm_cont)
target_link_libraries(Histogram_CUDA PRIVATE vtkm_filter)
endif()
endif()
......@@ -34,16 +34,16 @@ if(TARGET OpenGL::GL AND
set(gl_libs OpenGL::GL OpenGL::GLU GLEW::GLEW GLUT::GLUT)
add_executable(IsosurfaceUniformGrid_SERIAL IsosurfaceUniformGrid.cxx quaternion.h)
target_link_libraries(IsosurfaceUniformGrid_SERIAL PRIVATE vtkm_cont ${gl_libs})
target_link_libraries(IsosurfaceUniformGrid_SERIAL PRIVATE vtkm_filter ${gl_libs})
if(TARGET vtkm::cuda)
add_executable(IsosurfaceUniformGrid_CUDA IsosurfaceUniformGrid.cu quaternion.h)
target_link_libraries(IsosurfaceUniformGrid_CUDA PRIVATE vtkm_cont ${gl_libs})
target_link_libraries(IsosurfaceUniformGrid_CUDA PRIVATE vtkm_filter ${gl_libs})
endif()
if(TARGET vtkm::tbb)
add_executable(IsosurfaceUniformGrid_TBB IsosurfaceUniformGridTBB.cxx quaternion.h)
target_link_libraries(IsosurfaceUniformGrid_TBB PRIVATE vtkm_cont ${gl_libs})
target_link_libraries(IsosurfaceUniformGrid_TBB PRIVATE vtkm_filter ${gl_libs})
endif()
endif()
......@@ -25,5 +25,5 @@ find_package(VTKm REQUIRED QUIET)
add_executable(Lagrangian_SERIAL lagrangian.cxx ABCfield.h)
target_compile_definitions(Lagrangian_SERIAL PRIVATE "VTKM_DEVICE_ADAPTER=VTKM_DEVICE_ADAPTER_SERIAL")
target_link_libraries(Lagrangian_SERIAL PRIVATE vtkm_cont)
target_link_libraries(Lagrangian_SERIAL PRIVATE vtkm_filter)
target_link_libraries(Lagrangian_SERIAL ${VTKm_LIBRARIES})
......@@ -47,4 +47,4 @@ if(TARGET vtkm::cuda)
endif()
add_executable(MultiBackend ${device_srcs} ${srcs} ${headers})
target_link_libraries(MultiBackend PRIVATE vtkm_cont Threads::Threads)
target_link_libraries(MultiBackend PRIVATE vtkm_filter Threads::Threads)
......@@ -28,13 +28,13 @@ find_package(VTKm REQUIRED QUIET)
add_executable(Oscillator_SERIAL Oscillator.cxx)
target_compile_definitions(Oscillator_SERIAL PRIVATE
"VTKM_DEVICE_ADAPTER=VTKM_DEVICE_ADAPTER_SERIAL")
target_link_libraries(Oscillator_SERIAL PRIVATE vtkm_cont)
target_link_libraries(Oscillator_SERIAL PRIVATE vtkm_filter)
if (TARGET vtkm::tbb)
add_executable(Oscillator_TBB Oscillator.cxx)
target_compile_definitions(Oscillator_TBB PRIVATE
"VTKM_DEVICE_ADAPTER=VTKM_DEVICE_ADAPTER_TBB")
target_link_libraries(Oscillator_TBB PRIVATE vtkm_cont)
target_link_libraries(Oscillator_TBB PRIVATE vtkm_filter)
endif()
if (TARGET vtkm::cuda)
......@@ -42,5 +42,5 @@ if (TARGET vtkm::cuda)
add_executable(Oscillator_CUDA ${oscillatorCudaSrc})
target_compile_definitions(Oscillator_CUDA PRIVATE
"VTKM_DEVICE_ADAPTER=VTKM_DEVICE_ADAPTER_CUDA")
target_link_libraries(Oscillator_CUDA PRIVATE vtkm_cont)
target_link_libraries(Oscillator_CUDA PRIVATE vtkm_filter)
endif()
......@@ -26,14 +26,14 @@ project(ParticleAdvection CXX)
find_package(VTKm REQUIRED QUIET)
add_executable(Particle_Advection_SERIAL ParticleAdvection.cxx)
target_link_libraries(Particle_Advection_SERIAL PRIVATE vtkm_cont)
target_link_libraries(Particle_Advection_SERIAL PRIVATE vtkm_filter)
if(TARGET vtkm::tbb)
add_executable(Particle_Advection_TBB ParticleAdvectionTBB.cxx)
target_link_libraries(Particle_Advection_TBB PRIVATE vtkm_cont)
target_link_libraries(Particle_Advection_TBB PRIVATE vtkm_filter)
endif()
if(TARGET vtkm::cuda)
add_executable(Particle_Advection_CUDA ParticleAdvection.cu)
target_link_libraries(Particle_Advection_CUDA PRIVATE vtkm_cont)
target_link_libraries(Particle_Advection_CUDA PRIVATE vtkm_filter)
endif()
......@@ -27,13 +27,13 @@ find_package(VTKm REQUIRED QUIET)
add_executable(RedistributePoints_SERIAL RedistributePoints.cxx RedistributePoints.h)
target_compile_definitions(RedistributePoints_SERIAL PRIVATE
"VTKM_DEVICE_ADAPTER=VTKM_DEVICE_ADAPTER_SERIAL")
target_link_libraries(RedistributePoints_SERIAL PRIVATE vtkm_cont)
target_link_libraries(RedistributePoints_SERIAL PRIVATE vtkm_filter)
if(TARGET vtkm::tbb)
add_executable(RedistributePoints_TBB RedistributePoints.cxx RedistributePoints.h)
target_compile_definitions(RedistributePoints_TBB PRIVATE
"VTKM_DEVICE_ADAPTER=VTKM_DEVICE_ADAPTER_TBB")
target_link_libraries(RedistributePoints_TBB PRIVATE vtkm_cont)
target_link_libraries(RedistributePoints_TBB PRIVATE vtkm_filter)
endif()
if(TARGET vtkm::cuda)
......@@ -42,5 +42,5 @@ if(TARGET vtkm::cuda)
target_compile_definitions(RedistributePoints_CUDA PRIVATE
"VTKM_DEVICE_ADAPTER=VTKM_DEVICE_ADAPTER_CUDA")
target_link_libraries(RedistributePoints_CUDA PRIVATE vtkm_cont)
target_link_libraries(RedistributePoints_CUDA PRIVATE vtkm_filter)
endif()
......@@ -33,16 +33,16 @@ if(TARGET OpenGL::GL AND
set(gl_libs OpenGL::GL OpenGL::GLU GLEW::GLEW GLUT::GLUT)
add_executable(StreamLineUniformGrid_SERIAL StreamLineUniformGrid.cxx)
target_link_libraries(StreamLineUniformGrid_SERIAL PRIVATE vtkm_cont ${gl_libs})
target_link_libraries(StreamLineUniformGrid_SERIAL PRIVATE vtkm_filter ${gl_libs})
if(TARGET vtkm::cont)
add_executable(StreamLineUniformGrid_CUDA StreamLineUniformGrid.cu)
target_link_libraries(StreamLineUniformGrid_CUDA PRIVATE vtkm_cont ${gl_libs})
target_link_libraries(StreamLineUniformGrid_CUDA PRIVATE vtkm_filter ${gl_libs})
endif()
if(TARGET vtkm::tbb)
add_executable(StreamLineUniformGrid_TBB StreamLineUniformGridTBB.cxx)
target_link_libraries(StreamLineUniformGrid_TBB PRIVATE vtkm_cont ${gl_libs})
target_link_libraries(StreamLineUniformGrid_TBB PRIVATE vtkm_filter ${gl_libs})
endif()
endif()
......@@ -28,14 +28,14 @@ project(TemporalAdvection CXX)
find_package(VTKm REQUIRED QUIET)
add_executable(Temporal_Advection_SERIAL TemporalAdvection.cxx)
target_link_libraries(Temporal_Advection_SERIAL PRIVATE vtkm_cont)
target_link_libraries(Temporal_Advection_SERIAL PRIVATE vtkm_filter)
if(TARGET vtkm::tbb)
add_executable(Temporal_Advection_TBB TemporalAdvectionTBB.cxx)
target_link_libraries(Temporal_Advection_TBB PRIVATE vtkm_cont)
target_link_libraries(Temporal_Advection_TBB PRIVATE vtkm_filter)
endif()
if(TARGET vtkm::cuda)
add_executable(Temporal_Advection_CUDA TemporalAdvection.cu)
target_link_libraries(Temporal_Advection_CUDA PRIVATE vtkm_cont)
target_link_libraries(Temporal_Advection_CUDA PRIVATE vtkm_filter)
endif()
......@@ -37,10 +37,10 @@ if(TARGET OpenGL::GL AND
add_executable(TetrahedralizeUniformGrid_SERIAL TetrahedralizeUniformGrid.cxx)
add_executable(TriangulateUniformGrid_SERIAL TriangulateUniformGrid.cxx)
target_link_libraries(TetrahedralizeExplicitGrid_SERIAL PRIVATE vtkm_cont ${gl_libs})
target_link_libraries(TriangulateExplicitGrid_SERIAL PRIVATE vtkm_cont ${gl_libs})
target_link_libraries(TetrahedralizeUniformGrid_SERIAL PRIVATE vtkm_cont ${gl_libs})
target_link_libraries(TriangulateUniformGrid_SERIAL PRIVATE vtkm_cont ${gl_libs})
target_link_libraries(TetrahedralizeExplicitGrid_SERIAL PRIVATE vtkm_filter ${gl_libs})
target_link_libraries(TriangulateExplicitGrid_SERIAL PRIVATE vtkm_filter ${gl_libs})
target_link_libraries(TetrahedralizeUniformGrid_SERIAL PRIVATE vtkm_filter ${gl_libs})
target_link_libraries(TriangulateUniformGrid_SERIAL PRIVATE vtkm_filter ${gl_libs})
if(TARGET vtkm::cuda)
add_executable(TetrahedralizeExplicitGrid_CUDA TetrahedralizeExplicitGrid.cu)
......@@ -48,10 +48,10 @@ if(TARGET OpenGL::GL AND
add_executable(TetrahedralizeUniformGrid_CUDA TetrahedralizeUniformGrid.cu)
add_executable(TriangulateUniformGrid_CUDA TriangulateUniformGrid.cu)
target_link_libraries(TetrahedralizeExplicitGrid_CUDA PRIVATE vtkm_cont ${gl_libs})
target_link_libraries(TriangulateExplicitGrid_CUDA PRIVATE vtkm_cont ${gl_libs})
target_link_libraries(TetrahedralizeUniformGrid_CUDA PRIVATE vtkm_cont ${gl_libs})
target_link_libraries(TriangulateUniformGrid_CUDA PRIVATE vtkm_cont ${gl_libs})
target_link_libraries(TetrahedralizeExplicitGrid_CUDA PRIVATE vtkm_filter ${gl_libs})
target_link_libraries(TriangulateExplicitGrid_CUDA PRIVATE vtkm_filter ${gl_libs})
target_link_libraries(TetrahedralizeUniformGrid_CUDA PRIVATE vtkm_filter ${gl_libs})
target_link_libraries(TriangulateUniformGrid_CUDA PRIVATE vtkm_filter ${gl_libs})
endif()
if(TARGET vtkm::tbb)
......@@ -60,9 +60,9 @@ if(TARGET OpenGL::GL AND
add_executable(TetrahedralizeUniformGrid_TBB TetrahedralizeUniformGridTBB.cxx)
add_executable(TriangulateUniformGrid_TBB TriangulateUniformGridTBB.cxx)
target_link_libraries(TetrahedralizeExplicitGrid_TBB PRIVATE vtkm_cont ${gl_libs})
target_link_libraries(TriangulateExplicitGrid_TBB PRIVATE vtkm_cont ${gl_libs})
target_link_libraries(TetrahedralizeUniformGrid_TBB PRIVATE vtkm_cont ${gl_libs})
target_link_libraries(TriangulateUniformGrid_TBB PRIVATE vtkm_cont ${gl_libs})
target_link_libraries(TetrahedralizeExplicitGrid_TBB PRIVATE vtkm_filter ${gl_libs})
target_link_libraries(TriangulateExplicitGrid_TBB PRIVATE vtkm_filter ${gl_libs})
target_link_libraries(TetrahedralizeUniformGrid_TBB PRIVATE vtkm_filter ${gl_libs})
target_link_libraries(TriangulateUniformGrid_TBB PRIVATE vtkm_filter ${gl_libs})
endif()
endif()
......@@ -27,6 +27,6 @@ find_package(VTKm REQUIRED QUIET)
if(TARGET vtkm::cuda)
add_executable(UnifiedMemory_CUDA UnifiedMemory.cu)
target_link_libraries(UnifiedMemory_CUDA PRIVATE vtkm_cont)
target_link_libraries(UnifiedMemory_CUDA PRIVATE vtkm_filter)
endif()
......@@ -135,6 +135,13 @@ set(header_template_sources
vtkm_declare_headers(${headers})
# Create an interface library for vtkm_filter. At some point, this will be replaced with a real
# library that contains pre-built filters. That would be created with the vtkm_library CMake
# function (defined in VTKmWrappers.cmake).
add_library(vtkm_filter INTERFACE)
target_link_libraries(vtkm_filter INTERFACE vtkm_worklet)
install(TARGETS vtkm_filter EXPORT ${VTKm_EXPORT_NAME})
add_subdirectory(internal)
#-----------------------------------------------------------------------------
......
......@@ -66,4 +66,8 @@ set(unit_tests
UnitTestZFP.cxx
)
vtkm_unit_tests(SOURCES ${unit_tests} ALL_BACKENDS)
vtkm_unit_tests(
SOURCES ${unit_tests}
LIBRARIES vtkm_filter
ALL_BACKENDS
)
......@@ -202,7 +202,7 @@ elseif(VTKm_ENABLE_EGL_CONTEXT)
endif()
#-----------------------------------------------------------------------------
target_link_libraries(vtkm_rendering PUBLIC vtkm_cont)
target_link_libraries(vtkm_rendering PUBLIC vtkm_filter)
if(UNIX AND NOT APPLE)
......
......@@ -98,6 +98,18 @@ set(header_impls
)
# This is a list of sources that does not have code that runs on devices. It only
# needs a standard system C++ compiler.
set(sources_no_device
)
# This is a list of sources that has code that runs on devices and might need to
# be compiled with a device-specific compiler (like CUDA).
set(sources_device
ScatterCounting.cxx
)
#-----------------------------------------------------------------------------
add_subdirectory(internal)
add_subdirectory(clip)
......@@ -115,9 +127,14 @@ add_subdirectory(wavelets)
add_subdirectory(particleadvection)
add_subdirectory(zfp)
vtkm_declare_headers(${headers}
${header_impls}
)
vtkm_library(
NAME vtkm_worklet
SOURCES ${sources_no_device}
TEMPLATE_SOURCES ${header_impls}
HEADERS ${headers}
WRAP_FOR_CUDA ${sources_device}
)
target_link_libraries(vtkm_worklet PUBLIC vtkm_cont)
#-----------------------------------------------------------------------------
......
//=============================================================================
//
// 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 2019 National Technology & Engineering Solutions of Sandia, LLC (NTESS).
// Copyright 2019 UT-Battelle, LLC.
// Copyright 2019 Los Alamos National Security.
//
// Under the terms of Contract DE-NA0003525 with NTESS,
// the U.S. Government retains certain rights in this software.
// Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
// Laboratory (LANL), the U.S. Government retains certain rights in
// this software.
//
//=============================================================================
#include <vtkm/worklet/ScatterCounting.h>
#include <vtkm/cont/Algorithm.h>
#include <vtkm/cont/ArrayCopy.h>
#include <vtkm/cont/ArrayHandleCast.h>
#include <vtkm/cont/ArrayHandleConcatenate.h>
#include <vtkm/cont/ArrayHandleConstant.h>
#include <vtkm/cont/ArrayHandleIndex.h>
#include <vtkm/cont/ArrayHandleView.h>
#include <vtkm/cont/ErrorBadValue.h>
#include <vtkm/exec/FunctorBase.h>
#include <vtkm/worklet/DispatcherMapField.h>
#include <vtkm/worklet/WorkletMapField.h>
#include <sstream>
namespace
{
VTKM_CONT
inline vtkm::cont::ArrayHandleConcatenate<
vtkm::cont::ArrayHandleConstant<vtkm::Id>,
vtkm::cont::ArrayHandleView<vtkm::cont::ArrayHandle<vtkm::Id>>>
ShiftArrayHandleByOne(const vtkm::cont::ArrayHandle<vtkm::Id>& array)
{
return vtkm::cont::make_ArrayHandleConcatenate(
vtkm::cont::make_ArrayHandleConstant<vtkm::Id>(0, 1),
vtkm::cont::make_ArrayHandleView(array, 0, array.GetNumberOfValues() - 1));
}
struct ReverseInputToOutputMapWorklet : vtkm::worklet::WorkletMapField
{
using ControlSignature = void(FieldIn outputStartIndices,
FieldIn outputEndIndices,
WholeArrayOut outputToInputMap,
WholeArrayOut visit);
using ExecutionSignature = void(_1, _2, _3, _4, InputIndex);
using InputDomain = _2;
template <typename OutputMapType, typename VisitType>
VTKM_EXEC void operator()(vtkm::Id outputStartIndex,
vtkm::Id outputEndIndex,
const OutputMapType& outputToInputMap,
const VisitType& visit,
vtkm::Id inputIndex) const
{
vtkm::IdComponent visitIndex = 0;
for (vtkm::Id outputIndex = outputStartIndex; outputIndex < outputEndIndex; outputIndex++)
{
outputToInputMap.Set(outputIndex, inputIndex);
visit.Set(outputIndex, visitIndex);
visitIndex++;
}
}
VTKM_CONT
static void Run(const vtkm::cont::ArrayHandle<vtkm::Id>& inputToOutputMap,
const vtkm::cont::ArrayHandle<vtkm::Id>& outputToInputMap,
const vtkm::cont::ArrayHandle<vtkm::IdComponent>& visit,
vtkm::cont::DeviceAdapterId device)
{
vtkm::worklet::DispatcherMapField<ReverseInputToOutputMapWorklet> dispatcher;
dispatcher.SetDevice(device);
dispatcher.Invoke(
ShiftArrayHandleByOne(inputToOutputMap), inputToOutputMap, outputToInputMap, visit);
}
};
struct SubtractToVisitIndexWorklet : vtkm::worklet::WorkletMapField
{
using ControlSignature = void(FieldIn startsOfGroup, WholeArrayOut visit);
using ExecutionSignature = void(InputIndex, _1, _2);
using InputDomain = _1;
template <typename VisitType>
VTKM_EXEC void operator()(vtkm::Id inputIndex,
vtkm::Id startOfGroup,
const VisitType& visit) const
{
vtkm::IdComponent visitIndex = static_cast<vtkm::IdComponent>(inputIndex - startOfGroup);
visit.Set(inputIndex, visitIndex);
}
};
} // anonymous namespace
namespace vtkm
{
namespace worklet
{
namespace detail
{
struct ScatterCountingBuilder
{
template <typename CountArrayType>
VTKM_CONT static void BuildArrays(vtkm::worklet::ScatterCounting* self,
const CountArrayType& countArray,
vtkm::cont::DeviceAdapterId device,
bool saveInputToOutputMap)
{
VTKM_IS_ARRAY_HANDLE(CountArrayType);
self->InputRange = countArray.GetNumberOfValues();
// The input to output map is actually built off by one. The first entry
// is actually for the second value. The last entry is the total number of
// output. This off-by-one is so that an upper bound find will work when
// building the output to input map. Later we will either correct the
// map or delete it.
vtkm::cont::ArrayHandle<vtkm::Id> inputToOutputMapOffByOne;
vtkm::Id outputSize = vtkm::cont::Algorithm::ScanInclusive(
device, vtkm::cont::make_ArrayHandleCast(countArray, vtkm::Id()), inputToOutputMapOffByOne);
// We have implemented two different ways to compute the output to input
// map. The first way is to use a binary search on each output index into
// the input map. The second way is to schedule on each input and
// iteratively fill all the output indices for that input. The first way is
// faster for output sizes that are small relative to the input (typical in
// Marching Cubes, for example) and also tends to be well load balanced.
// The second way is faster for larger outputs (typical in triangulation,
// for example). We will use the first method for small output sizes and
// the second for large output sizes. Toying with this might be a good
// place for optimization.
if (outputSize < self->InputRange)
{
BuildOutputToInputMapWithFind(self, outputSize, device, inputToOutputMapOffByOne);
}
else
{
BuildOutputToInputMapWithIterate(self, outputSize, device, inputToOutputMapOffByOne);
}
if (saveInputToOutputMap)
{
// Since we are saving it, correct the input to output map.
vtkm::cont::Algorithm::Copy(
device, ShiftArrayHandleByOne(inputToOutputMapOffByOne), self->InputToOutputMap);
}
}
VTKM_CONT static void BuildOutputToInputMapWithFind(
vtkm::worklet::ScatterCounting* self,
vtkm::Id outputSize,
vtkm::cont::DeviceAdapterId device,
vtkm::cont::ArrayHandle<vtkm::Id> inputToOutputMapOffByOne)
{
vtkm::cont::ArrayHandleIndex outputIndices(outputSize);
vtkm::cont::Algorithm::UpperBounds(
device, inputToOutputMapOffByOne, outputIndices, self->OutputToInputMap);
vtkm::cont::ArrayHandle<vtkm::Id> startsOfGroups;
// This find gives the index of the start of a group.
vtkm::cont::Algorithm::LowerBounds(
device, self->OutputToInputMap, self->OutputToInputMap, startsOfGroups);
self->VisitArray.Allocate(outputSize);
vtkm::worklet::DispatcherMapField<SubtractToVisitIndexWorklet> dispatcher;
dispatcher.SetDevice(device);
dispatcher.Invoke(startsOfGroups, self->VisitArray);
}
VTKM_CONT static void BuildOutputToInputMapWithIterate(
vtkm::worklet::ScatterCounting* self,
vtkm::Id outputSize,
vtkm::cont::DeviceAdapterId device,
vtkm::cont::ArrayHandle<vtkm::Id> inputToOutputMapOffByOne)
{
self->OutputToInputMap.Allocate(outputSize);
self->VisitArray.Allocate(outputSize);
ReverseInputToOutputMapWorklet::Run(
inputToOutputMapOffByOne, self->OutputToInputMap, self->VisitArray, device);
}
template <typename ArrayType>
void operator()(const ArrayType& countArray,
vtkm::cont::DeviceAdapterId device,
bool saveInputToOutputMap,
vtkm::worklet::ScatterCounting* self)
{
BuildArrays(self, countArray, device, saveInputToOutputMap);
}
};
}
}
} // namespace vtkm::worklet::detail
void vtkm::worklet::ScatterCounting::BuildArrays(const VariantArrayHandleCount& countArray,
vtkm::cont::DeviceAdapterId device,
bool saveInputToOutputMap)
{
countArray.CastAndCall(
vtkm::worklet::detail::ScatterCountingBuilder(), device, saveInputToOutputMap, this);
}
......@@ -22,22 +22,9 @@
#ifndef vtk_m_worklet_ScatterCounting_h
#define vtk_m_worklet_ScatterCounting_h
#include <vtkm/cont/Algorithm.h>
#include <vtkm/cont/ArrayCopy.h>
#include <vtkm/cont/ArrayHandle.h>
#include <vtkm/cont/ArrayHandleCast.h>
#include <vtkm/cont/ArrayHandleConcatenate.h>
#include <vtkm/cont/ArrayHandleConstant.h>
#include <vtkm/cont/ArrayHandleIndex.h>
#include <vtkm/cont/ArrayHandleView.h>
#include <vtkm/cont/ErrorBadValue.h>
#include <vtkm/worklet/vtkm_worklet_export.h>
#include <vtkm/exec/FunctorBase.h>
#include <vtkm/worklet/DispatcherMapField.h>
#include <vtkm/worklet/WorkletMapField.h>
#include <sstream>
#include <vtkm/cont/VariantArrayHandle.h>
namespace vtkm
{
......@@ -47,70 +34,7 @@ namespace worklet
namespace detail
{
VTKM_CONT
inline vtkm::cont::ArrayHandleConcatenate<
vtkm::cont::ArrayHandleConstant<vtkm::Id>,
vtkm::cont::ArrayHandleView<vtkm::cont::ArrayHandle<vtkm::Id>>>
ShiftArrayHandleByOne(const vtkm::cont::ArrayHandle<vtkm::Id>& array)
{
return vtkm::cont::make_ArrayHandleConcatenate(
vtkm::cont::make_ArrayHandleConstant<vtkm::Id>(0, 1),
vtkm::cont::make_ArrayHandleView(array, 0, array.GetNumberOfValues() - 1));
}
struct ReverseInputToOutputMapWorklet : vtkm::worklet::WorkletMapField
{
using ControlSignature = void(FieldIn outputStartIndices,
FieldIn outputEndIndices,
WholeArrayOut outputToInputMap,
WholeArrayOut visit);
using ExecutionSignature = void(_1, _2, _3, _4, InputIndex);
using InputDomain = _2;
template <typename OutputMapType, typename VisitType>
VTKM_EXEC void operator()(vtkm::Id outputStartIndex,
vtkm::Id outputEndIndex,
const OutputMapType& outputToInputMap,
const VisitType& visit,
vtkm::Id inputIndex) const
{
vtkm::IdComponent visitIndex = 0;
for (vtkm::Id outputIndex = outputStartIndex; outputIndex < outputEndIndex; outputIndex++)
{
outputToInputMap.Set(outputIndex, inputIndex);
visit.Set(outputIndex, visitIndex);
visitIndex++;
}
}
VTKM_CONT
static void Run(const vtkm::cont::ArrayHandle<vtkm::Id>& inputToOutputMap,
const vtkm::cont::ArrayHandle<vtkm::Id>& outputToInputMap,
const vtkm::cont::ArrayHandle<vtkm::IdComponent>& visit,
vtkm::cont::DeviceAdapterId device)
{
vtkm::worklet::DispatcherMapField<ReverseInputToOutputMapWorklet> dispatcher;
dispatcher.SetDevice(device);
dispatcher.Invoke(
ShiftArrayHandleByOne(inputToOutputMap), inputToOutputMap, outputToInputMap, visit);
}
};