GCC Code Coverage Report


Directory: ./
File: openvdb_ax/openvdb_ax/codegen/VolumeComputeGenerator.h
Date: 2022-07-25 17:40:05
Exec Total Coverage
Lines: 1 1 100.0%
Functions: 0 1 0.0%
Branches: 0 0 -%

Line Branch Exec Source
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 {
23 OPENVDB_USE_VERSION_NAMESPACE
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.
44 struct VolumeKernelValue
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
57 using FunctionTraitsT = codegen::FunctionTraits<Signature>;
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.
80 struct VolumeKernelBuffer
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
94 using FunctionTraitsT = codegen::FunctionTraits<Signature>;
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.
116 struct VolumeKernelNode
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
127 using FunctionTraitsT = codegen::FunctionTraits<Signature>;
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.
142 struct VolumeComputeGenerator : public ComputeGenerator
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 763 ~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
180