Upload
freira
View
117
Download
0
Embed Size (px)
DESCRIPTION
Dax Tutorial. Many-Core Code Sprint September 19, 2012. Dax: A Toolkit for Accelerated Visualization. The Dax Toolkit brings together parallel modules to supplement combinable visualization algorithms. Mapping on Fields. Topology Generation. Connectivity Reconstruction. Extracted cells - PowerPoint PPT Presentation
Citation preview
Sandia National Laboratories is a multi-program laboratory managed and operated by Sandia Corporation, a wholly owned subsidiary of Lockheed Martin Corporation, for the U.S. Department of Energy’s National Nuclear Security Administration under contract DE-AC04-94AL85000. SAND NO. 2012-7796P
Dax TutorialMany-Core Code Sprint
September 19, 2012
Dax: A Toolkit for Accelerated Visualization
Mapping on Fields
Topology Generation
Connectivity Reconstruction
The Dax Toolkit brings together parallel modules to supplement combinable visualization algorithms.
Extracted cellsof large gradient and compacted points Simplical subdivision
with quadratic smoothing
Surface improvements through connection construction.
Contour with subsequent vertex welding, coarsening, subdivision, and curvature estimation
GETTING STARTED
Prerequisites
git CMake (2.8.8 or newer recommended) Boost 1.48.0 CUDA Toolkit 4+ (for CUDA backend) Thrust 1.4 or 1.5 (comes with CUDA)
Getting Dax
Clone from one of the git repositories http://public.kitware.com/DaxToolkit.git https://github.com/Kitware/DaxToolkit.git
git clone http://public.kitware.com/DaxToolkit.git
Configuring Dax
Create a build directory Run ccmake (or cmake-gui) pointing back to source directory
git clone http://public.kitware.com/DaxToolkit.gitmkdir daxBuildcd daxBuildccmake ../DaxToolkit
Important Configuration Parameters
Variable DescriptionDAX_ENABLE_CUDA Turn this ON to enable CUDA backend. Requires
CUDA Toolkit and Thrust.DAX_ENABLE_OPENMP Turn this ON to enable OpenMP backend.
Requires Thrust and OpenMP compiler support (not Clang).
DAX_ENABLE_TESTING Turn on header, unit, and benchmark tests.
DAX_USE_64BIT_IDS Enable 64bit index support. Using this with CUDA backend generally requires a Tesla card.
DAX_USE_DOUBLE_PRECISION Enable using double as the representation type for dax::Scalar. Using this with CUDA backend generally requires a Tesla card.
CMAKE_BUILD_TYPE Debug, RelWithDebInfo, or Release
CMAKE_INSTALL_PREFIX Location to install headers
Building Dax
(Technically optional but a good check for your system.) Run make (or use your favorite IDE) Run tests (“make test” or “ctest”) Parallel builds (-j flag) work, too.
git clone http://public.kitware.com/DaxToolkit.gitmkdir daxBuildcd daxBuildccmake ../DaxToolkitmakectest
Installing Dax
(Optional but good if your project doesn’t use CMake) make install target
git clone http://public.kitware.com/DaxToolkit.gitmkdir daxBuildcd daxBuildccmake ../DaxToolkitmakectestmake install
More Information
We know, documentation is sparse http://daxtoolkit.org
Click down to “Using Dax” Doxygen: http://daxtoolkit.org/Doc/classes.html
BASIC COMMON SUPPORT TYPES AND FUNCTIONS
Basic Types
#include <dax/Types.h> dax::Id
Integer/index type dax::Scalar
Floating point Use of core C types (int, float, double, etc.) discouraged.
Basic Tuples
#include <dax/Types.h> dax::Id3, dax::Vector2, dax::Vector3, dax::Vector4
Operator [] overloaded for component access Operators +, -, *, / overloaded for component-wise arithmetic make_Id3(), make_Vector2(), make_Vector3(), etc. dax::dot() Generic dax::Tuple<type,size>
Vector Traits
#include<dax/VectorTraits.h> template<class VectorType> struct VectorTraits
NUM_COMPONENTS GetComponent() SetComponent()
Basic Math
#include <dax/math/Compare.h> dax::math::Min(x,y), dax::math::Max(x,y)
#include <dax/math/Precision.h> dax::math::Nan(), dax::math::Infinity(), dax::math::NegativeInfinity(), dax::math::Epsilon()
dax::math::IsNan() dax::math::IsInf(), dax::math::IsFinite() dax::math::FMod(), dax::math::Remainder(), dax::math::RemainderQuotient(), dax::math::ModF()
dax::math::Ceil(), dax::math::Floor(), dax::math::Round()
#include <dax/math/Sign.h> dax::math::Abs(), dax::math::IsNegative(), dax::math::CopySign()
Basic Math
#include <dax/math/Exp.h> dax::math::Pow() , dax::math::Sqrt(), dax::math::RSqrt() , dax::math::Cbrt(), dax::math::RCbrt()
dax::math::Exp(), dax::math::Exp2(), dax::math::ExpM1(), dax::math::Exp10()
dax::math::Log(), dax::math::Log2(), dax::math::Log10(), dax::math::Log1P()
#include <dax/math/Trig.h> dax::math::Pi() dax::math::Sin(), dax::math::Cos(), dax::math::Tan() dax::math::ASin(), dax::math::ACos(), dax::math::ATan() , dax::math::ATan2()
dax::math::SinH(), dax::math::CosH(), dax::math::TanH() , dax::math::ASinH(), dax::math::ACosH(), dax::math::ATanH()
Basic Vector Operations
#include <dax/math/VectorAnalysis.h> dax::math::MagnitudeSquared(), dax::math::Magnitude(), dax::math::RMagnitude()
dax::math::Normal(), dax::math::Normalize() dax::math::Cross() dax::math::TriangleNormal()
Basic Small Matrix Operations
#include <dax::math::Matrix.h> class dax::math::Matrix<Type, numRow, numCol>
Access components by matrix(row,col) or matrix[row][col] Specialty types dax::math::Matrix2x2, dax::math::Matrix3x3, dax::math::Matrix4x4
dax::math::MatrixRow(matrix, rowIndex), dax::math::MatrixColumn(matrix, colIndex)
dax::math::MatrixSetRow(matrix,rowIndex,rowValues), dax::math::MatrixSetColumn(matrix,colIndex,colValues)
dax::math::MatrixMultiply(leftFactor, rightFactor) dax::math::MatrixIdentity() dax::math::MatrixTranspose() dax::math::MatrixInverse() dax::math::MatrixDeterminant()
Other Linear and Numeric Algorithms
#include <dax/math/Matrix.h> dax::math::SolveLinearSystem()
#include <dax/math/Numerical.h> dax::math::NewtonsMethod()
SYSTEM OVERVIEW
Execution Environment
Control Environment
Dax Framework
dax::cont dax::exec
Execution Environment
Control Environment
Grid TopologyArray HandleInvoke
Dax Framework
dax::cont dax::exec
Execution Environment
Cell OperationsField Operations
Basic MathMake Cells
Control Environment
Grid TopologyArray HandleInvoke W
orkletDax Framework
dax::cont dax::exec
Execution Environment
Cell OperationsField Operations
Basic MathMake Cells
Control Environment
Grid TopologyArray HandleInvoke W
orkletDax Framework
dax::cont dax::exec
Execution Environment
Cell OperationsField Operations
Basic MathMake Cells
Control Environment
Grid TopologyArray HandleInvoke
Device Adapter
AllocateTransferSchedule
Sort…
Worklet
Dax Framework
dax::cont dax::exec
Export Macros
DAX_CONT_EXPORT Functions/methods for control environment. Think __host__ in CUDA.
DAX_EXEC_EXPORT Functions/methods for execution environment. Think __device__ in CUDA.
DAX_EXEC_CONT_EXPORT Either environment.
CREATING WORKLETS IN THE EXECUTION ENVIRONMENT
Creating Worklets
Worklets are functors with extra syntax sugar.
struct Dot{
dax::Scalar operator()(const dax::Vector3& coord) const {
return dax::dot(coord,coord);}
};
Worklets Base Classes
All Worklets must derive from a dax worklet class. WorkletMapField WorkletMapCell WorkletGenerateTopology
struct Dot : dax::exec::WorkletMapField
WorkletMapField Operate on arbitrary fields. Has no geometric information
WorkletMapCell Operate with access to the cell’s topology and point fields.
WorkletGenerateTopology Operate on input cell’s to create new cell topology
Creating Worklets
struct Dot : dax::exec::WorkletMapField{
dax::Scalar operator()(const dax::Vector3& coord) const {
dax::Scalar dot = dax::dot(coord,coord);}
};
Worklet Control Signature
Control signature defines how we interpret the control parameter Consider it to define the interface that must be met Currently two interface types: Field and Topology
Field converts to a single value passed to the worklet Array Constant value Function ( Under Development )
Topology converts to a single cell passed to the worklet Unstructured Uniform
Worklet Control Signature
Control Signature have modifiers that combined with worklet type determine how we access the argument
Field Context Execution RepresentationIn Read only value
Out Writable value
Point (In,Out) Tuple containing the point values for a field.
Cell (In,Out) Same as In or Out for WorkletMapCell.
Topology Context Execution RepresentationCell (In,Out) Read / Write Cell. Only able to modify cell point ids.
Creating Worklets
struct Dot : dax::exec::WorkletMapField{
typdef void ControlSignature(Field(In),Field(Out));
dax::Scalar operator()(const dax::Vector3& coord) const {
dax::Scalar dot = dax::dot(coord,coord);}
};
Worklet Execution Signature
Execution signature maps control arguments to worklets arguments
typedef void ControlSignature(Field(In))
typedef void ExecutionSignature(_1)
void operator()(const dax::Vector3& v) const
Worklet Execution Signature
Execution signature maps control arguments to worklets arguments
typedef void ControlSignature(Field(In))
typedef void ExecutionSignature(_1)
void operator()(const dax::Vector3& v) const
_1 = First Control Arg
Worklet Execution Signature
Execution signature maps control arguments to worklets arguments
typedef void ControlSignature(Field(In))
typedef void ExecutionSignature(_1)
void operator()(const dax::Vector3& v) const
_1 = First Control Arg
Worklet Execution Signature
Execution Signature Options Effect_1, _2, _3 … _10 Reference argument _1 in control signature
WorkId Fill the argument with the current iteration index
Topology::PointIds( _N ) Convert a topology cell argument to cell’s point ids
Execution signature and Control signature can be different lengths Can use a control argument multiple times Can transform a control side argument
Neighbors Cell Point Ids
Finished Worklet
struct Dot : dax::exec::WorkletMapField {
typedef void ControlSignature(Field(In),Field(Out))typedef _2 ExecutionSignature(_1)
dax::Scalar operator()(const dax::Vector3& coord) const {
dax::Scalar dot = dax::dot(coord,coord);}
};
Execution Cell Types
Some worklets can receive a cell as a parameter Usually the cell type is templated, but can be specified directly
Cell classes defined in dax/exec/Cell*.h No shared superclass, but all implement at a minimum
Constants NUM_POINTS and TOPOLOGICAL_DIMENSIONS GetNumberOfPoints() GetPointIndex(vertexIndex) GetPointIndices()
Returns a Tuple defined by the typedef Cell::PointConnectionsType Currently supported cells: Vertex, Line, Triangle, Quadrilateral,
Voxel, Tetrahedron, Wedge, Hexahedron
Cell Operations
#include <dax/exec/ParametricCoordintes.h> dax::exec::ParametricCoordinates<CellType>::Center() dax::exec::ParametricCoordinates<CellType>::Vertex() dax::exec::ParametricCoordinatesToWorldCoordinates() dax::exec::WorldCoordinatesToParametericCoordinates()
#include <dax/exec/Interpolate.h> dax::exec::CellInterpolate()
#include <dax/exec/Derivative.h> dax::exec::CellDerivative()
Errors in the Execution Environment
All worklet classes have a RaiseError() method this->RaiseError("Precondition failed"); Will cause an exception with that message to be thrown in the control
environment from whence the worklet was invoked But, you cannot catch the error while still in the execution environment In fact, execution might not immediately stop
#include <dax/exec/Assert.h> DAX_ASSERT_EXEC(condition, worklet) Behaves like the POSIX assert except that it throws this error rather than
crashing the program to a halt DAX_ASSERT_EXEC(vertexIndex < 8, this)
INVOKING ALGORITHMS ON DATA IN THE CONTROL ENVIRONMENT
Catching Errors
Dax throws errors in anomalous conditions Thrown class always a subclass of dax::cont::Error If the error originated in control environment, then a subclass of
dax::cont::ErrorControl If the error came from a worklet in the execution environment, then it will be
dax::cont::ErrorExecution
try { ... }catch (dax::cont::Error error) { std::cout << "Dax encountered an error: " << error.GetMessage() << std::endl; }
DeviceAdapter
The DeviceAdapter is an interface between control and execution environments. Adapts to different devices/compilers.
Easiest way to select is to define DAX_DEVICE_ADAPTER Use one of the following (before including any Dax header)
#define DAX_DEVICE_ADAPTER DAX_DEVICE_ADAPTER_SERIAL #define DAX_DEVICE_ADAPTER DAX_DEVICE_ADAPTER_OPENMP #define DAX_DEVICE_ADAPTER DAX_DEVICE_ADAPTER_CUDA
If you select none, a reasonable default will be selected for you There are other ways to select (and create) a DeviceAdapter
Won’t be talking about them today
ArrayHandle
dax::cont::ArrayHandle<type> manages an “array” of data Acts like a reference-counted smart pointer to an array Manages transfer of data between control and execution Can allocate data for output
Relevant methods GetNumberOfValues() CopyInto() ReleaseResources(), ReleaseResourcesExecution()
Functions to create an ArrayHandle dax::cont::make_ArrayHandle(const T *array, dax::Id size)
dax::cont::make_ArrayHandle(const std::vector<T> vector)
Both of these do a shallow (reference) copy. Do not let the original array be deleted or vector to go out of scope!
Other Important ArrayHandle Features We’re Skipping ArrayContainerControl template parameter
Selects array layout for zero-copy semantics Supports implicit arrays Yes, we have a container for vtkDataArray
Generic array interface through an ArrayPortal In principle like an STL iterator, but simpler
UniformGrid
#include <dax/cont/UniformGrid.h> dax::cont::UniformGrid<> (template parameters default)
Get/SetExtent(), Get/SetOrigin(), Get/SetSpacing() GetNumberOfPoints(), GetNumberOfCells() ComputePointIndex(dax::Id3), ComputeCellIndex(dax::Id3)
ComputePointLocation(dax::Id) ComputeCellLocation(dax::Id) ComputePointCoordinates(dax::Id or dax::Id3) GetPointCoordinates()
UnstructuredGrid
#include <dax/cont/UnstructuredGrid.h> dax::cont::UnstructuredGrid<CellType>
Get/SetCellConnections() Stored in ArrayHandle<dax::Id>, one entry per cell vertex
Get/SetPointCoordinates() Stored in ArrayHandle<dax::Vector3>, one entry per point Note that GetPointCoordinates() is match in UniformGrid
GetNumberOfPoints(), GetNumberOfCells()
Invoking Worklets
#include <dax/cont/Schedule.h> dax::cont::Schedule< > (template parameters default)
void operator() (Worklet w, typename… Parameters) Number of parameters must match the worklet’s ControlSignature Determines execution length based on parameters length
Other Important Scheduler Features
#include <dax/cont/ScheduleMapAdapter.h> dax::cont::make_MapAdapter(Keys k, Values v, dax::Id valuesLength) Wraps a parameter to allow many to one access Invisible mapping of workId through the Keys object when executing
#include <dax/cont/ScheduleGenerateTopology.h> Constructs new topology with ability to remove duplicate points Requires an array that represents the classification of each input cell Can also convert point fields Pass to the Schedule class as a worklet!
PUTTING IT ALL TOGETHER
The Functor
struct Normal {
template<typename T>dax::Scalar operator()(const T& coord) const
{dax::Scalar dot = dax::dot(coord,coord);return coord * dax::math::RSqrt(dot);
} };
The Worklet struct Normal: dax::exec::WorkletMapField {
typedef void ControlSignature(Field(In),Field(Out));typedef _2 ExecutionSignature(_1);
template<typename T>T operator()(const T& coord) const
{dax::Scalar dot = dax::dot(coord,coord);return coord * dax::math::RSqrt(dot);
} };
The Control Code int main()
{ using namespace dax::cont;
std::vector<dax::Vector3> coords(10); for(int i=0; i < 10; i++) { const dax::Scalar x(1.0f + i); coords[i] = dax::Vector3(dax::math::Sin(x)/i+1, 1/(x*x), 0); } //make a dax array handle to the coordinates ArrayHandle<dax::Vector3> coordHandle = make_ArrayHandle(coords);
//make a dax array handle to store the results ArrayHandle<dax::Vector3> normals;
Schedule< > scheduler;//note two parameters passed to scheduler like the control signature requests scheduler(Normal(), coordHandle, normals);
std::vector<dax::Vector3> results(normals.GetNumberOfValues()); normals.CopyInto (results.begin());
}
OTHER INFORMATION
Dax VTK Module
https://github.com/robertmaynard/DaxVTKModule Currently exposes Dax threshold as a VTK Filter Uses VTK memory without copying to and from execution