Dax Tutorial

of 56/56
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 Tutorial Many-Core Code Sprint September 19, 2012
  • date post

    23-Feb-2016
  • Category

    Documents

  • view

    105
  • 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

Transcript of Dax Tutorial

Slide 1

Dax TutorialMany-Core Code SprintSeptember 19, 2012Sandia 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 Energys National Nuclear Security Administration under contract DE-AC04-94AL85000.SAND NO. 2012-7796PDax: A Toolkit for Accelerated VisualizationMapping on FieldsTopology GenerationConnectivity ReconstructionThe 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 estimationGetting StartedPrerequisitesgitCMake (2.8.8 or newer recommended)Boost 1.48.0CUDA Toolkit 4+ (for CUDA backend)Thrust 1.4 or 1.5 (comes with CUDA)Getting DaxClone from one of the git repositorieshttp://public.kitware.com/DaxToolkit.githttps://github.com/Kitware/DaxToolkit.gitgit clone http://public.kitware.com/DaxToolkit.gitConfiguring DaxCreate a build directoryRun ccmake (or cmake-gui) pointing back to source directorygit clone http://public.kitware.com/DaxToolkit.gitmkdir daxBuildcd daxBuildccmake ../DaxToolkitImportant Configuration ParametersVariableDescriptionDAX_ENABLE_CUDATurn this ON to enable CUDA backend. Requires CUDA Toolkit and Thrust.DAX_ENABLE_OPENMPTurn this ON to enable OpenMP backend. Requires Thrust and OpenMP compiler support (not Clang). DAX_ENABLE_TESTINGTurn on header, unit, and benchmark tests.DAX_USE_64BIT_IDSEnable 64bit index support. Using this with CUDA backend generally requires a Tesla card.DAX_USE_DOUBLE_PRECISIONEnable using double as the representation type for dax::Scalar. Using this with CUDA backend generally requires a Tesla card.CMAKE_BUILD_TYPEDebug, RelWithDebInfo, or ReleaseCMAKE_INSTALL_PREFIXLocation to install headersBuilding 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 ../DaxToolkitmakectestInstalling Dax(Optional but good if your project doesnt use CMake)make install targetgit clone http://public.kitware.com/DaxToolkit.gitmkdir daxBuildcd daxBuildccmake ../DaxToolkitmakectestmake installMore InformationWe know, documentation is sparsehttp://daxtoolkit.orgClick down to Using DaxDoxygen: http://daxtoolkit.org/Doc/classes.html

Basic Common Support Types and FunctionsBasic Types#include dax::IdInteger/index typedax::ScalarFloating pointUse of core C types (int, float, double, etc.) discouraged.Basic Tuples#include dax::Id3, dax::Vector2, dax::Vector3, dax::Vector4Operator [] overloaded for component accessOperators +, -, *, / overloaded for component-wise arithmeticmake_Id3(), make_Vector2(), make_Vector3(), etc.dax::dot()Generic dax::Tuple

Vector Traits#includetemplate struct VectorTraitsNUM_COMPONENTSGetComponent()SetComponent()

Basic Math#include dax::math::Min(x,y), dax::math::Max(x,y)#include 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::Abs(), dax::math::IsNegative(), dax::math::CopySign()Basic Math#include 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::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::MagnitudeSquared(), dax::math::Magnitude(), dax::math::RMagnitude()dax::math::Normal(), dax::math::Normalize()dax::math::Cross()dax::math::TriangleNormal()

Basic Small Matrix Operations#include class dax::math::MatrixAccess components by matrix(row,col) or matrix[row][col]Specialty types dax::math::Matrix2x2, dax::math::Matrix3x3, dax::math::Matrix4x4dax::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::SolveLinearSystem()#include dax::math::NewtonsMethod()

System OverviewExecution Environment

Control Environment

Dax Frameworkdax::contdax::execThe Dax framework is divided into two distinct environments each with their own API.The control environment a serial environment that is used to establish data and set up parallel jobs.This is the interface used to connect Dax to applications and other code.The API for the control environment is located in the namespace dax::cont.The execution environment is the parallel environment where the actual data processing is done.Internally, the control environment spawns parallel jobs in the execution environment.The API for the execution environment is located in the namespace dax::exec.These two environments mirror the typical hardware configuration of general purpose CPU and accelerator coprocessor.But also work fine when both are integrated.Execution Environment

Control Environment

Grid TopologyArray HandleInvoke

Dax Frameworkdax::contdax::execWhen processing data in Dax, you first establish the data topology through the control environment.This is done through very basic grid topology structures and adaptable array handles.Execution Environment

Cell OperationsField OperationsBasic MathMake CellsControl Environment

Grid TopologyArray HandleInvokeWorklet

Dax Framework

dax::contdax::execThen from the control environment you can invoke an algorithm on your data.Internally, this will decompose the data into constitute pieces, transfer data as necessary, and invoke a parallel algorithm.Algorithms in the execution environment are built using worklets.Worklets are serial functors that operate on one constituent element.The execution API provides the basic operations for cells, interpolations, derivatives, and other math.Worklets come in different types with different abilities.Execution Environment

Cell OperationsField OperationsBasic MathMake CellsControl Environment

Grid TopologyArray HandleInvokeWorklet

Dax Framework

dax::contdax::execAnd eventually the results are passed back to the control environment.Execution Environment

Cell OperationsField OperationsBasic MathMake CellsControl Environment

Grid TopologyArray HandleInvokeDevice AdapterAllocateTransferScheduleSortWorklet

Dax Framework

dax::contdax::execThese two environments, particularly the execution environment, are meant to work on a variety of architectures.To manage this portability, we have a unit called a device adapter that sits between these two environments.The device adapter provides the basic memory management, scheduling, and algorithms needed to run on a parallel device.Export MacrosDAX_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 EnvironmentCreating 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.WorkletMapFieldWorkletMapCellWorkletGenerateTopology

struct Dot : dax::exec::WorkletMapFieldWorkletMapFieldOperate on arbitrary fields. Has no geometric informationWorkletMapCellOperate with access to the cells topology and point fields.WorkletGenerateTopologyOperate on input cells 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 parameterConsider it to define the interface that must be metCurrently two interface types: Field and TopologyField converts to a single value passed to the workletArrayConstant valueFunction ( Under Development )

Topology converts to a single cell passed to the workletUnstructuredUniformWe currently have support for constant value field and Array Handle that represent fields.Topology maps to the topology of unstructured / uniform gridsPoint coordinates are not implicit with topology interfaceWorklet Control SignatureControl Signature have modifiers that combined with worklet type determine how we access the argument

Field ContextExecution RepresentationInRead only valueOutWritable valuePoint (In,Out)Tuple containing the point values for a field. Cell (In,Out)Same as In or Out for WorkletMapCell.Topology ContextExecution 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_1 means we are using the first argument in the control signatureWorklet 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 ArgThe position in the Execution Signature defines the position in the operator() signatureWorklet Execution SignatureExecution Signature OptionsEffect_1, _2, _3 _10Reference argument _1 in control signatureWorkIdFill the argument with the current iteration indexTopology::PointIds( _N )Convert a topology cell argument to cells point idsExecution signature and Control signature can be different lengthsCan use a control argument multiple timesCan transform a control side argumentNeighborsCell 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 TypesSome worklets can receive a cell as a parameterUsually the cell type is templated, but can be specified directlyCell classes defined in dax/exec/Cell*.hNo shared superclass, but all implement at a minimumConstants NUM_POINTS and TOPOLOGICAL_DIMENSIONSGetNumberOfPoints()GetPointIndex(vertexIndex)GetPointIndices()Returns a Tuple defined by the typedef Cell::PointConnectionsTypeCurrently supported cells: Vertex, Line, Triangle, Quadrilateral, Voxel, Tetrahedron, Wedge, HexahedronCell Operations#include dax::exec::ParametricCoordinates::Center()dax::exec::ParametricCoordinates::Vertex()dax::exec::ParametricCoordinatesToWorldCoordinates()dax::exec::WorldCoordinatesToParametericCoordinates()#include dax::exec::CellInterpolate()#include dax::exec::CellDerivative()Errors in the Execution EnvironmentAll worklet classes have a RaiseError() methodthis->RaiseError("Precondition failed");Will cause an exception with that message to be thrown in the control environment from whence the worklet was invokedBut, you cannot catch the error while still in the execution environmentIn fact, execution might not immediately stop#include DAX_ASSERT_EXEC(condition, worklet)Behaves like the POSIX assert except that it throws this error rather than crashing the program to a haltDAX_ASSERT_EXEC(vertexIndex < 8, this)Invoking Algorithms on Data in the Control EnvironmentCatching ErrorsDax throws errors in anomalous conditionsThrown class always a subclass of dax::cont::ErrorIf the error originated in control environment, then a subclass of dax::cont::ErrorControlIf the error came from a worklet in the execution environment, then it will be dax::cont::ErrorExecutiontry { ... }catch (dax::cont::Error error) { std::cout