OpenVDB 14.0.0
Loading...
Searching...
No Matches
PointExecutable.h
Go to the documentation of this file.
1// Copyright Contributors to the OpenVDB Project
2// SPDX-License-Identifier: Apache-2.0
3
4/// @file compiler/PointExecutable.h
5///
6/// @authors Nick Avramoussis, Francisco Gochez, Richard Jones
7///
8/// @brief The PointExecutable, produced by the OpenVDB AX Compiler for
9/// execution over OpenVDB Points Grids.
10///
11
12#ifndef OPENVDB_AX_COMPILER_POINT_EXECUTABLE_HAS_BEEN_INCLUDED
13#define OPENVDB_AX_COMPILER_POINT_EXECUTABLE_HAS_BEEN_INCLUDED
14
15#include "CustomData.h"
16#include "AttributeRegistry.h"
17#include "AttributeBindings.h"
18
19#include <openvdb/openvdb.h>
20#include <openvdb/version.h>
22
23
24#include <unordered_map>
25
26struct TestPointExecutableAcc;
27
28/// @cond OPENVDB_DOCS_INTERNAL
29namespace llvm {
30class ExecutionEngine;
31class LLVMContext;
32namespace orc {
33class LLJIT;
34}
35}
36/// @endcond
37
38
39namespace openvdb {
41namespace OPENVDB_VERSION_NAME {
42namespace ax {
43
44class Compiler;
45
46/// @brief Object that encapsulates compiled AX code which can be executed on a
47/// collection of VDB Point Data grids. Executables are created by the
48/// compiler and hold the final immutable JIT compiled function and context.
49/// @details The PointExecutable is returned from the ax::Compiler when
50/// compiling AX code for point execution. The class represents a typical AX
51/// executable object; immutable except for execution settings and implements
52/// 'execute' functions which can be called multiple times for arbitrary sets
53/// of inputs. The intended usage of these executables is to configure their
54/// runtime arguments and then call PointExecutable::execute with your VDBs.
55/// For example:
56/// @code
57/// PointExecutable::Ptr exe = compiler.compile<PointExecutable>("@a += 1");
58/// exe->setCreateMissing(false); // fail on missing attributes
59/// exe->setGroupExecution("group1"); // only process points in group1
60/// exe->execute(vdbs); // run on a set of vdb point data grids
61/// exe->execute(points); // run on a single point data grid
62/// @endcode
63///
64/// The setCreateMissing is initialised with specific configurable settings:
65/// - Create Missing: True
66/// By default, create any missing attributes that were accessed
67/// @sa setCreateMissing
68/// - Group Execution: All
69/// By default, process all points regardless of their group membership
70/// @sa setGroupExecution
71/// - Grain size: 1
72/// The default grain sizes passed to the tbb partitioner for leaf level
73/// processing.
74/// @sa setGrainSize
75///
76/// For more in depth information, see the @ref vdbaxcompilerexe documentation.
78{
79public:
80 using Ptr = std::shared_ptr<PointExecutable>;
82
83 /// @brief Copy constructor. Shares the LLVM constructs but deep copies the
84 /// settings. Multiple copies of an executor can be used at the same time
85 /// safely.
87
88 ////////////////////////////////////////////////////////
89
90 /// @brief Run this point executable binary on a target PointDataGrid.
91 /// @details This method reads from the stored settings on the executable
92 /// to determine certain behaviour and runs the JIT compiled function
93 /// across every valid point. Point attributes may be created, deleted
94 /// collapsed or expanded, and points themselves may be added, deleted
95 /// or moved.
96 ///
97 /// This method is thread safe; it can be run concurrently from the same
98 /// PointExecutable instance on different inputs.
99 ///
100 /// @param grid The PointDataGrid to process
102
103 ////////////////////////////////////////////////////////
104
105 /// @brief Set a specific point group to execute over. The default is none,
106 /// which corresponds to all points. Note that this can also be compiled
107 /// into the AX function using the ingroup("mygroup") method.
108 /// @warning If the group does not exist during execute, a runtime error
109 /// will be thrown.
110 /// @param name The name of the group to execute over
111 void setGroupExecution(const std::string& name);
112 /// @return The points group to be processed. Default is empty, which is
113 /// all points.
114 const std::string& getGroupExecution() const;
115
116 /// @brief Set the behaviour when missing point attributes are accessed.
117 /// Default behaviour is true, which creates them with default initial
118 /// values. If false, a missing attribute runtime error will be thrown
119 /// on missing accesses.
120 /// @param flag Enables or disables the creation of missing attributes
121 void setCreateMissing(const bool flag);
122 /// @return Whether this executable will generate new point attributes.
123 bool getCreateMissing() const;
124
125 /// @brief Set the threading grain size. Default is 1. A value of 0 has the
126 /// effect of disabling multi-threading.
127 /// @param grain The grain size
128 void setGrainSize(const size_t grain);
129 /// @return The current grain size
130 size_t getGrainSize() const;
131
132 /// @brief Set attribute bindings.
133 /// @param bindings A map of attribute bindings to expected names on
134 /// the geometry to be executed over. By default the AX attributes will be
135 /// bound to point attributes of the same name. Supplying bindings
136 /// for a subset of the attributes will leave the others unchanged.
137 /// AX attributes can only bind to a single point attribute and vice versa.
138 /// However, in a single set call these can be swapped e.g. a -> b and b -> a.
139 /// When bindings are overriden through subsequent calls to this function,
140 /// any dangling point attributes will be automatically bound by name.
141 /// To reset these bindings call get function and create a target set of bindings
142 /// for each attribute of name -> name.
144 /// @return The current attribute bindings map
146
147 ////////////////////////////////////////////////////////
148
149 // foward declaration of settings for this executable
150 template <bool> struct Settings;
151
152 /// @brief Command Line Interface handling for the PointExecutable.
153 /// @details This class wraps the logic for converting commands specific
154 /// to the PointExecutable to the internal Settings. Subsequent
155 /// executables can be initialized from the CLI object that gets created
157 {
161 static CLI create(size_t argc, const char* argv[], bool* used=nullptr);
162 static void usage(std::ostream& os, const bool verbose);
163 private:
164 friend class PointExecutable;
165 CLI();
166 std::unique_ptr<Settings<true>> mSettings;
167 };
168
169 /// @brief Intialize the Settings of this executables from the CLI object
170 /// @param cli The CLI object
171 void setSettingsFromCLI(const CLI& cli);
172
173 ////////////////////////////////////////////////////////
174
175private:
176 friend class Compiler;
177 friend struct ::TestPointExecutableAcc;
178
179 /// @brief Private method used in the unit tests
180 bool usesAcceleratedKernel(const points::PointDataTree& tree) const;
181
182 /// @brief Constructor, expected to be invoked by the compiler. Should not
183 /// be invoked directly.
184 /// @param context Shared pointer to an llvm:LLVMContext associated with the
185 /// execution engine
186 /// @param engine Shared pointer to an llvm::ExecutionEngine used to build
187 /// functions. Context should be the associated LLVMContext
188 /// @param attributeRegistry Registry of attributes accessed by AX code
189 /// @param customData Custom data which will be shared by this executable.
190 /// It can be used to retrieve external data from within the AX code
191 /// @param functions A map of function names to physical memory addresses
192 /// which were built by llvm using engine
193 /// @param tree The AST linked to this executable. The AST is not stored
194 /// after compilation, but can be used during construction of the exe to
195 /// infer some pre/post processing optimisations.
197 const std::shared_ptr<const llvm::orc::LLJIT>& mExecutionEngine,
198 const AttributeRegistry::ConstPtr& attributeRegistry,
199 const CustomData::ConstPtr& customData,
200 const std::unordered_map<std::string, uint64_t>& functions,
201 const ast::Tree& tree);
202
203private:
204 const std::shared_ptr<const llvm::orc::LLJIT> mExecutionEngine;
205 const AttributeRegistry::ConstPtr mAttributeRegistry;
206 const CustomData::ConstPtr mCustomData;
207 const std::unordered_map<std::string, uint64_t> mFunctionAddresses;
208 std::unique_ptr<Settings<false>> mSettings;
209};
210
211} // namespace ax
212} // namespace OPENVDB_VERSION_NAME
213} // namespace openvdb
214
215#endif // OPENVDB_AX_COMPILER_POINT_EXECUTABLE_HAS_BEEN_INCLUDED
216
The Attribute Bindings class is used by the compiled Executables to handle the mapping of AX Attribut...
These classes contain lists of expected attributes and volumes which are populated by compiler during...
Access to the CustomData class which can provide custom user user data to the OpenVDB AX Compiler.
#define OPENVDB_AX_API
Definition Platform.h:307
Attribute-owned data structure for points. Point attributes are stored in leaf nodes and ordered by v...
This class wraps an interface for a map of attribute bindings. These map attributes in AX code to con...
Definition AttributeBindings.h:37
std::shared_ptr< const AttributeRegistry > ConstPtr
Definition AttributeRegistry.h:43
std::shared_ptr< const CustomData > ConstPtr
Definition CustomData.h:38
const std::string & getGroupExecution() const
void setCreateMissing(const bool flag)
Set the behaviour when missing point attributes are accessed. Default behaviour is true,...
const AttributeBindings & getAttributeBindings() const
std::shared_ptr< PointExecutable > Ptr
Definition PointExecutable.h:80
void execute(points::PointDataGrid &grid) const
Run this point executable binary on a target PointDataGrid.
PointExecutable(const PointExecutable &other)
Copy constructor. Shares the LLVM constructs but deep copies the settings. Multiple copies of an exec...
friend class Compiler
Definition PointExecutable.h:176
void setGrainSize(const size_t grain)
Set the threading grain size. Default is 1. A value of 0 has the effect of disabling multi-threading.
void setGroupExecution(const std::string &name)
Set a specific point group to execute over. The default is none, which corresponds to all points....
void setSettingsFromCLI(const CLI &cli)
Intialize the Settings of this executables from the CLI object.
void setAttributeBindings(const AttributeBindings &bindings)
Set attribute bindings.
tree::Tree< tree::RootNode< tree::InternalNode< tree::InternalNode< PointDataLeafNode< PointDataIndex32, 3 >, 4 >, 5 > > > PointDataTree
Point index tree configured to match the default VDB configurations.
Definition PointDataGrid.h:68
Grid< PointDataTree > PointDataGrid
Point data grid.
Definition PointDataGrid.h:73
Definition PointDataGrid.h:48
Definition Exceptions.h:13
Command Line Interface handling for the PointExecutable.
Definition PointExecutable.h:157
static void usage(std::ostream &os, const bool verbose)
friend class PointExecutable
Definition PointExecutable.h:164
static CLI create(size_t argc, const char *argv[], bool *used=nullptr)
Definition PointExecutable.h:150
A Tree is the highest concrete (non-abstract) node in the entire AX AST hierarchy....
Definition AST.h:563
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition version.h.in:121
#define OPENVDB_USE_VERSION_NAMESPACE
Definition version.h.in:291