OpenVDB  9.0.1
VolumeComputeGenerator.h
Go to the documentation of this file.
1 // Copyright Contributors to the OpenVDB Project
2 // SPDX-License-Identifier: MPL-2.0
3 
4 /// @file codegen/VolumeComputeGenerator.h
5 ///
6 /// @authors Nick Avramoussis
7 ///
8 /// @brief The visitor framework and function definition for volume grid
9 /// code generation
10 ///
11 
12 #ifndef OPENVDB_AX_VOLUME_COMPUTE_GENERATOR_HAS_BEEN_INCLUDED
13 #define OPENVDB_AX_VOLUME_COMPUTE_GENERATOR_HAS_BEEN_INCLUDED
14 
15 #include "ComputeGenerator.h"
16 #include "FunctionTypes.h"
17 
18 #include "../compiler/AttributeRegistry.h"
19 
20 #include <openvdb/version.h>
21 
22 namespace openvdb {
24 namespace OPENVDB_VERSION_NAME {
25 
26 namespace ax {
27 namespace codegen {
28 
29 /// @brief The primary volume kernel. This function holds the generated body
30 /// of AX programs.
31 /// @details argument structure is as follows:
32 /// 1) - A void pointer to the ax::CustomData
33 /// 2) - A pointer to an array of three ints representing the
34 /// current voxel coord being accessed
35 /// 3) - A void pointer to the current value buffer
36 /// 4) - A bool representing the current values active state
37 /// 5) - The index of the current tile in the parent tile's table
38 /// 6) - A void pointer to a vector of void pointers, representing
39 /// an array of grid accessors
40 /// 7) - A void pointer to a vector of void pointers, representing
41 /// an array of grid transforms
42 /// 8) - The index of currently executing volume in the list of write
43 /// accessible volumes.
45 {
46  // The signature of the generated function
47  using Signature =
48  void(const void* const,
49  const int32_t (*)[3],
50  void*, // value
51  bool, // active
52  int64_t, // index
53  void**, // r accessors
54  const void* const*,
55  int64_t);
56 
58  static const size_t N_ARGS = FunctionTraitsT::N_ARGS;
59 
60  static const std::array<std::string, N_ARGS>& argumentKeys();
61  static const char* getDefaultName();
62 };
63 
64 /// @brief The second volume kernel, responsible for providing the core
65 /// layer of SIMD optimisations by invoking this kernel across a range of
66 /// values.
67 /// @details argument structure is as follows:
68 /// 1) - A void pointer to the ax::CustomData
69 /// 2) - A pointer to an array of three ints representing the
70 /// current voxel coord being accessed
71 /// 3) - A void pointer to the current value buffer
72 /// 4) - A uint64_t pointer to the active word buffer
73 /// 5) - The active state execution mode
74 /// 6) - A void pointer to a vector of void pointers, representing
75 /// an array of grid accessors
76 /// 7) - A void pointer to a vector of void pointers, representing
77 /// an array of grid transforms
78 /// 8) - The index of currently executing volume in the list of write
79 /// accessible volumes.
81 {
82  // The signature of the generated function
83  using Signature =
84  void(const void* const,
85  const int32_t (*)[3],
86  void*, // value buffer
87  uint64_t*, // active buffer
88  int64_t, // buffer size
89  uint64_t, // mode (0 = off, 1 = active, 2 = both)
90  void**, // read accessors
91  const void* const*, // transforms
92  int64_t); // write index
93 
95  static const size_t N_ARGS = FunctionTraitsT::N_ARGS;
96 
97  static const std::array<std::string, N_ARGS>& argumentKeys();
98  static const char* getDefaultName();
99 };
100 
101 /// @brief The third volume kernel, providing an agnostic way to modify
102 /// a single tile value without passing through the buffer states. Note
103 /// that this kernel is mainly utility and one of the value kernels should
104 /// almost always be preferred.
105 /// @details argument structure is as follows:
106 /// 1) - A void pointer to the ax::CustomData
107 /// 2) - A pointer to an array of three ints representing the
108 /// current voxel coord being accessed
109 /// 3) - A void pointer to a vector of void pointers, representing
110 /// an array of grid accessors
111 /// 4) - A void pointer to a vector of void pointers, representing
112 /// an array of grid transforms
113 /// 5) - The index of currently executing volume in the list of write
114 /// accessible volumes.
115 /// 5) - A unique write accessor to the target volume.
117 {
118  // The signature of the generated function
119  using Signature =
120  void(const void* const,
121  const int32_t (*)[3], // index space coord
122  void**, // read accessors
123  const void* const*, // transforms
124  int64_t, // write index
125  void*); // write accessor
126 
128  static const size_t N_ARGS = FunctionTraitsT::N_ARGS;
129 
130  static const std::array<std::string, N_ARGS>& argumentKeys();
131  static const char* getDefaultName();
132 };
133 
134 ///////////////////////////////////////////////////////////////////////////
135 ///////////////////////////////////////////////////////////////////////////
136 
137 namespace codegen_internal {
138 
139 /// @brief Visitor object which will generate llvm IR for a syntax tree which has been generated
140 /// from AX that targets volumes. The IR will represent a single function. It is mainly
141 /// used by the Compiler class.
143 {
144  /// @brief Constructor
145  /// @param module llvm Module for generating IR
146  /// @param options Options for the function registry behaviour
147  /// @param functionRegistry Function registry object which will be used when generating IR
148  /// for function calls
149  /// @param logger Logger for collecting logical errors and warnings
150  VolumeComputeGenerator(llvm::Module& module,
151  const FunctionOptions& options,
152  FunctionRegistry& functionRegistry,
153  Logger& logger);
154 
155  ~VolumeComputeGenerator() override = default;
156 
157  using ComputeGenerator::traverse;
158  using ComputeGenerator::visit;
159 
160  AttributeRegistry::Ptr generate(const ast::Tree& node);
161  bool visit(const ast::Attribute*) override;
162 
163 private:
164  llvm::Value* accessorHandleFromToken(const std::string&);
165  void getAccessorValue(const std::string&, llvm::Value*);
166 
167  void computek2(llvm::Function*, const AttributeRegistry&);
168  void computek3(llvm::Function*, const AttributeRegistry&);
169 };
170 
171 } // namespace codegen_internal
172 
173 } // namespace codegen
174 } // namespace ax
175 } // namespace OPENVDB_VERSION_NAME
176 } // namespace openvdb
177 
178 #endif // OPENVDB_AX_VOLUME_COMPUTE_GENERATOR_HAS_BEEN_INCLUDED
179 
void(const void *const, const int32_t(*)[3], void *, uint64_t *, int64_t, uint64_t, void **, const void *const *, int64_t) Signature
Definition: VolumeComputeGenerator.h:92
The core visitor framework for code generation.
void(const void *const, const int32_t(*)[3], void **, const void *const *, int64_t, void *) Signature
Definition: VolumeComputeGenerator.h:125
Logger for collecting errors and warnings that occur during AX compilation.
Definition: Logger.h:54
Contains frameworks for creating custom AX functions which can be registered within the FunctionRegis...
Visitor object which will generate llvm IR for a syntax tree. This provides the majority of the code ...
Definition: ComputeGenerator.h:86
The function registry which is used for function code generation. Each time a function is visited wit...
Definition: FunctionRegistry.h:36
The third volume kernel, providing an agnostic way to modify a single tile value without passing thro...
Definition: VolumeComputeGenerator.h:116
Templated function traits which provides compile-time index access to the types of the function signa...
Definition: Types.h:259
Definition: Exceptions.h:13
Options that control how functions behave.
Definition: CompilerOptions.h:24
A Tree is the highest concrete (non-abstract) node in the entire AX AST hierarchy. It represents an entire conversion of a valid AX string.
Definition: AST.h:561
This class stores a list of access names, types and their dependency connections. ...
Definition: AttributeRegistry.h:38
void(const void *const, const int32_t(*)[3], void *, bool, int64_t, void **, const void *const *, int64_t) Signature
Definition: VolumeComputeGenerator.h:55
std::shared_ptr< AttributeRegistry > Ptr
Definition: AttributeRegistry.h:41
Attributes represent any access to a primitive value, typically associated with the &#39;@&#39; symbol syntax...
Definition: AST.h:1873
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h.in:116
The primary volume kernel. This function holds the generated body of AX programs. ...
Definition: VolumeComputeGenerator.h:44
Visitor object which will generate llvm IR for a syntax tree which has been generated from AX that ta...
Definition: VolumeComputeGenerator.h:142
The second volume kernel, responsible for providing the core layer of SIMD optimisations by invoking ...
Definition: VolumeComputeGenerator.h:80
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h.in:202