nvfuser-cu121-torch25 0.2.25.dev20250201__cp310-cp310-manylinux_2_28_x86_64.whl
Sign up to get free protection for your applications and to get access to all the features.
- nvfuser/_C.cpython-310-x86_64-linux-gnu.so +0 -0
- nvfuser/__init__.py +618 -0
- nvfuser/__init__.pyi +4 -0
- nvfuser/contrib/__init__.py +9 -0
- nvfuser/contrib/nn/__init__.py +13 -0
- nvfuser/contrib/nn/normalization.py +725 -0
- nvfuser/include/nvfuser/alias_analysis.h +116 -0
- nvfuser/include/nvfuser/bfs.h +929 -0
- nvfuser/include/nvfuser/codegen.h +26 -0
- nvfuser/include/nvfuser/compute_at.h +28 -0
- nvfuser/include/nvfuser/compute_at_map.h +394 -0
- nvfuser/include/nvfuser/contiguity.h +351 -0
- nvfuser/include/nvfuser/cuda_utils.h +50 -0
- nvfuser/include/nvfuser/debug.h +50 -0
- nvfuser/include/nvfuser/device_lower/analysis/bank_conflict.h +53 -0
- nvfuser/include/nvfuser/device_lower/analysis/circular_buffer.h +109 -0
- nvfuser/include/nvfuser/device_lower/analysis/device_version.h +65 -0
- nvfuser/include/nvfuser/device_lower/analysis/divisible_split.h +28 -0
- nvfuser/include/nvfuser/device_lower/analysis/fused_reduction.h +36 -0
- nvfuser/include/nvfuser/device_lower/analysis/index_compute.h +322 -0
- nvfuser/include/nvfuser/device_lower/analysis/predicate_elimination.h +71 -0
- nvfuser/include/nvfuser/device_lower/analysis/sync_information.h +47 -0
- nvfuser/include/nvfuser/device_lower/analysis/tensor_memory.h +65 -0
- nvfuser/include/nvfuser/device_lower/analysis/thread_predicate.h +158 -0
- nvfuser/include/nvfuser/device_lower/analysis/tma.h +93 -0
- nvfuser/include/nvfuser/device_lower/analysis/trivial_broadcast.h +75 -0
- nvfuser/include/nvfuser/device_lower/id_model_options.h +135 -0
- nvfuser/include/nvfuser/device_lower/lower2device.h +391 -0
- nvfuser/include/nvfuser/device_lower/pass/alias_memory.h +37 -0
- nvfuser/include/nvfuser/device_lower/pass/allocation.h +32 -0
- nvfuser/include/nvfuser/device_lower/pass/circular_buffer.h +191 -0
- nvfuser/include/nvfuser/device_lower/pass/expr_sort.h +17 -0
- nvfuser/include/nvfuser/device_lower/pass/fusion_simplifier.h +21 -0
- nvfuser/include/nvfuser/device_lower/pass/grid_serialization.h +26 -0
- nvfuser/include/nvfuser/device_lower/pass/index.h +200 -0
- nvfuser/include/nvfuser/device_lower/pass/inline_ptx.h +16 -0
- nvfuser/include/nvfuser/device_lower/pass/insert_syncs.h +39 -0
- nvfuser/include/nvfuser/device_lower/pass/instrument.h +24 -0
- nvfuser/include/nvfuser/device_lower/pass/loop_rotation.h +150 -0
- nvfuser/include/nvfuser/device_lower/pass/loops.h +68 -0
- nvfuser/include/nvfuser/device_lower/pass/magic_zero.h +86 -0
- nvfuser/include/nvfuser/device_lower/pass/misaligned_vectorization.h +118 -0
- nvfuser/include/nvfuser/device_lower/pass/predicate.h +23 -0
- nvfuser/include/nvfuser/device_lower/pass/replace_size.h +24 -0
- nvfuser/include/nvfuser/device_lower/pass/scalar_hoist.h +115 -0
- nvfuser/include/nvfuser/device_lower/pass/unroll.h +98 -0
- nvfuser/include/nvfuser/device_lower/pass/vectorize_welford.h +45 -0
- nvfuser/include/nvfuser/device_lower/pass/warp_reduce.h +23 -0
- nvfuser/include/nvfuser/device_lower/utils.h +382 -0
- nvfuser/include/nvfuser/device_lower/validation.h +74 -0
- nvfuser/include/nvfuser/disjoint_set.h +556 -0
- nvfuser/include/nvfuser/dispatch.h +334 -0
- nvfuser/include/nvfuser/driver_api.h +49 -0
- nvfuser/include/nvfuser/dynamic_transform.h +316 -0
- nvfuser/include/nvfuser/dynamic_type/C++20/type_traits +37 -0
- nvfuser/include/nvfuser/dynamic_type/dynamic_type.h +969 -0
- nvfuser/include/nvfuser/dynamic_type/error.h +24 -0
- nvfuser/include/nvfuser/dynamic_type/type_traits.h +703 -0
- nvfuser/include/nvfuser/evaluator_common.h +295 -0
- nvfuser/include/nvfuser/exceptions.h +283 -0
- nvfuser/include/nvfuser/expr_evaluator.h +125 -0
- nvfuser/include/nvfuser/expr_simplifier.h +218 -0
- nvfuser/include/nvfuser/flatbuffers/allocator.h +68 -0
- nvfuser/include/nvfuser/flatbuffers/array.h +253 -0
- nvfuser/include/nvfuser/flatbuffers/base.h +486 -0
- nvfuser/include/nvfuser/flatbuffers/buffer.h +154 -0
- nvfuser/include/nvfuser/flatbuffers/buffer_ref.h +53 -0
- nvfuser/include/nvfuser/flatbuffers/code_generator.h +80 -0
- nvfuser/include/nvfuser/flatbuffers/code_generators.h +234 -0
- nvfuser/include/nvfuser/flatbuffers/default_allocator.h +64 -0
- nvfuser/include/nvfuser/flatbuffers/detached_buffer.h +114 -0
- nvfuser/include/nvfuser/flatbuffers/flatbuffer_builder.h +1225 -0
- nvfuser/include/nvfuser/flatbuffers/flatbuffers.h +272 -0
- nvfuser/include/nvfuser/flatbuffers/flatc.h +130 -0
- nvfuser/include/nvfuser/flatbuffers/flex_flat_util.h +36 -0
- nvfuser/include/nvfuser/flatbuffers/flexbuffers.h +1889 -0
- nvfuser/include/nvfuser/flatbuffers/grpc.h +300 -0
- nvfuser/include/nvfuser/flatbuffers/hash.h +127 -0
- nvfuser/include/nvfuser/flatbuffers/idl.h +1359 -0
- nvfuser/include/nvfuser/flatbuffers/minireflect.h +420 -0
- nvfuser/include/nvfuser/flatbuffers/reflection.h +522 -0
- nvfuser/include/nvfuser/flatbuffers/reflection_generated.h +1471 -0
- nvfuser/include/nvfuser/flatbuffers/registry.h +128 -0
- nvfuser/include/nvfuser/flatbuffers/stl_emulation.h +513 -0
- nvfuser/include/nvfuser/flatbuffers/string.h +64 -0
- nvfuser/include/nvfuser/flatbuffers/struct.h +53 -0
- nvfuser/include/nvfuser/flatbuffers/table.h +168 -0
- nvfuser/include/nvfuser/flatbuffers/util.h +731 -0
- nvfuser/include/nvfuser/flatbuffers/vector.h +393 -0
- nvfuser/include/nvfuser/flatbuffers/vector_downward.h +273 -0
- nvfuser/include/nvfuser/flatbuffers/verifier.h +317 -0
- nvfuser/include/nvfuser/fusion.h +511 -0
- nvfuser/include/nvfuser/fusion_guard.h +37 -0
- nvfuser/include/nvfuser/fusion_profiler.h +311 -0
- nvfuser/include/nvfuser/fusion_segmenter.h +751 -0
- nvfuser/include/nvfuser/global_allocator.h +27 -0
- nvfuser/include/nvfuser/grouped_reduction.h +47 -0
- nvfuser/include/nvfuser/host_ir/container.h +60 -0
- nvfuser/include/nvfuser/host_ir/executor.h +152 -0
- nvfuser/include/nvfuser/host_ir/host_ir.h +320 -0
- nvfuser/include/nvfuser/host_ir/lower.h +35 -0
- nvfuser/include/nvfuser/id_model/circular_buffer_indexing.h +56 -0
- nvfuser/include/nvfuser/id_model/contiguity.h +166 -0
- nvfuser/include/nvfuser/id_model/id_model.h +359 -0
- nvfuser/include/nvfuser/id_model/id_model_index_compute.h +81 -0
- nvfuser/include/nvfuser/id_model/indexing.h +208 -0
- nvfuser/include/nvfuser/id_model/indexing_traversal.h +72 -0
- nvfuser/include/nvfuser/id_model/indexing_utils.h +62 -0
- nvfuser/include/nvfuser/id_model/loop_promotion.h +180 -0
- nvfuser/include/nvfuser/id_model/predicate_indexing.h +104 -0
- nvfuser/include/nvfuser/id_model/schedule.h +54 -0
- nvfuser/include/nvfuser/id_model/to_string.h +87 -0
- nvfuser/include/nvfuser/id_model/transform_replay.h +58 -0
- nvfuser/include/nvfuser/id_model/utils.h +176 -0
- nvfuser/include/nvfuser/id_model/validation_utils.h +55 -0
- nvfuser/include/nvfuser/index_compute.h +651 -0
- nvfuser/include/nvfuser/instrumentation.h +107 -0
- nvfuser/include/nvfuser/ir/all_nodes.h +14 -0
- nvfuser/include/nvfuser/ir/base_nodes.h +687 -0
- nvfuser/include/nvfuser/ir/builder.h +215 -0
- nvfuser/include/nvfuser/ir/builder_passkey.h +29 -0
- nvfuser/include/nvfuser/ir/cloner.h +185 -0
- nvfuser/include/nvfuser/ir/container.h +226 -0
- nvfuser/include/nvfuser/ir/graphviz.h +119 -0
- nvfuser/include/nvfuser/ir/interface_nodes.h +957 -0
- nvfuser/include/nvfuser/ir/internal_base_nodes.h +744 -0
- nvfuser/include/nvfuser/ir/internal_nodes.h +2792 -0
- nvfuser/include/nvfuser/ir/iostream.h +98 -0
- nvfuser/include/nvfuser/ir/printer.h +57 -0
- nvfuser/include/nvfuser/ir/utils.h +801 -0
- nvfuser/include/nvfuser/iter_visitor.h +661 -0
- nvfuser/include/nvfuser/kernel.h +299 -0
- nvfuser/include/nvfuser/kernel_db/kernel_db.h +109 -0
- nvfuser/include/nvfuser/kernel_db/utils.h +37 -0
- nvfuser/include/nvfuser/kernel_ir.h +1457 -0
- nvfuser/include/nvfuser/kernel_ir_dispatch.h +147 -0
- nvfuser/include/nvfuser/linked_hash_map.h +97 -0
- nvfuser/include/nvfuser/logical_domain_map.h +577 -0
- nvfuser/include/nvfuser/macros.h +23 -0
- nvfuser/include/nvfuser/mma_type.h +257 -0
- nvfuser/include/nvfuser/multidevice/c10d_mock.h +175 -0
- nvfuser/include/nvfuser/multidevice/communication.h +232 -0
- nvfuser/include/nvfuser/multidevice/communicator.h +179 -0
- nvfuser/include/nvfuser/multidevice/device_mesh.h +95 -0
- nvfuser/include/nvfuser/multidevice/executor.h +107 -0
- nvfuser/include/nvfuser/multidevice/multidevice.h +18 -0
- nvfuser/include/nvfuser/multidevice/utils.h +187 -0
- nvfuser/include/nvfuser/non_divisible_split.h +86 -0
- nvfuser/include/nvfuser/opaque_type.h +129 -0
- nvfuser/include/nvfuser/ops/alias.h +192 -0
- nvfuser/include/nvfuser/ops/all_ops.h +13 -0
- nvfuser/include/nvfuser/ops/arith.h +712 -0
- nvfuser/include/nvfuser/ops/composite.h +130 -0
- nvfuser/include/nvfuser/ops/indexing.h +55 -0
- nvfuser/include/nvfuser/ops/normalization.h +263 -0
- nvfuser/include/nvfuser/ops/utils.h +127 -0
- nvfuser/include/nvfuser/options.h +313 -0
- nvfuser/include/nvfuser/parallel_dimension_map.h +95 -0
- nvfuser/include/nvfuser/parallel_type_bitmap.h +365 -0
- nvfuser/include/nvfuser/polymorphic_value.h +432 -0
- nvfuser/include/nvfuser/predicate_compute.h +213 -0
- nvfuser/include/nvfuser/python_frontend/distributed_tensor.h +50 -0
- nvfuser/include/nvfuser/python_frontend/fusion_cache.h +298 -0
- nvfuser/include/nvfuser/python_frontend/fusion_definition.h +372 -0
- nvfuser/include/nvfuser/python_frontend/fusion_record.h +3124 -0
- nvfuser/include/nvfuser/python_frontend/fusion_state.h +143 -0
- nvfuser/include/nvfuser/python_frontend/python_bindings.h +27 -0
- nvfuser/include/nvfuser/python_frontend/segmentation.h +246 -0
- nvfuser/include/nvfuser/python_frontend/translation.h +20 -0
- nvfuser/include/nvfuser/python_frontend/translation_utils.h +308 -0
- nvfuser/include/nvfuser/scheduler/all_schedulers.h +17 -0
- nvfuser/include/nvfuser/scheduler/ampere_multi_matmul.h +206 -0
- nvfuser/include/nvfuser/scheduler/cache_policy_refiner.h +19 -0
- nvfuser/include/nvfuser/scheduler/compile_time_info.h +322 -0
- nvfuser/include/nvfuser/scheduler/debug_utils.h +68 -0
- nvfuser/include/nvfuser/scheduler/expr_eval_sched.h +45 -0
- nvfuser/include/nvfuser/scheduler/heuristic.h +113 -0
- nvfuser/include/nvfuser/scheduler/hopper_multi_matmul.h +204 -0
- nvfuser/include/nvfuser/scheduler/mark_aliases.h +19 -0
- nvfuser/include/nvfuser/scheduler/matmul.h +40 -0
- nvfuser/include/nvfuser/scheduler/matmul_heuristic.h +293 -0
- nvfuser/include/nvfuser/scheduler/matmul_heuristic_plugin.h +65 -0
- nvfuser/include/nvfuser/scheduler/matmul_heuristic_plugin_api.h +99 -0
- nvfuser/include/nvfuser/scheduler/matmul_utils.h +54 -0
- nvfuser/include/nvfuser/scheduler/mma_utils.h +500 -0
- nvfuser/include/nvfuser/scheduler/multi_matmul.h +74 -0
- nvfuser/include/nvfuser/scheduler/no_op.h +48 -0
- nvfuser/include/nvfuser/scheduler/normalization_inner.h +49 -0
- nvfuser/include/nvfuser/scheduler/normalization_inner_outer.h +51 -0
- nvfuser/include/nvfuser/scheduler/normalization_outer.h +48 -0
- nvfuser/include/nvfuser/scheduler/normalization_utils.h +379 -0
- nvfuser/include/nvfuser/scheduler/pointwise.h +183 -0
- nvfuser/include/nvfuser/scheduler/pointwise_heuristic.h +118 -0
- nvfuser/include/nvfuser/scheduler/pointwise_utils.h +24 -0
- nvfuser/include/nvfuser/scheduler/reduction.h +43 -0
- nvfuser/include/nvfuser/scheduler/reduction_heuristic.h +339 -0
- nvfuser/include/nvfuser/scheduler/reduction_utils.h +159 -0
- nvfuser/include/nvfuser/scheduler/registry.h +97 -0
- nvfuser/include/nvfuser/scheduler/registry_utils.h +111 -0
- nvfuser/include/nvfuser/scheduler/resize.h +41 -0
- nvfuser/include/nvfuser/scheduler/resize_heuristic.h +67 -0
- nvfuser/include/nvfuser/scheduler/runtime_info.h +166 -0
- nvfuser/include/nvfuser/scheduler/scheduler_types.h +80 -0
- nvfuser/include/nvfuser/scheduler/transpose.h +114 -0
- nvfuser/include/nvfuser/scheduler/transpose_heuristic.h +164 -0
- nvfuser/include/nvfuser/scheduler/utils.h +771 -0
- nvfuser/include/nvfuser/scheduler/vectorize_helper.h +349 -0
- nvfuser/include/nvfuser/serde/factory.h +55 -0
- nvfuser/include/nvfuser/serde/fusion_cache_generated.h +4319 -0
- nvfuser/include/nvfuser/serde/fusion_record.h +124 -0
- nvfuser/include/nvfuser/serde/polymorphic_value.h +52 -0
- nvfuser/include/nvfuser/serde/utils.h +34 -0
- nvfuser/include/nvfuser/struct.inl +127 -0
- nvfuser/include/nvfuser/swizzle.h +54 -0
- nvfuser/include/nvfuser/sys_utils.h +40 -0
- nvfuser/include/nvfuser/tensor_metadata.h +118 -0
- nvfuser/include/nvfuser/tma.h +124 -0
- nvfuser/include/nvfuser/transform_iter.h +522 -0
- nvfuser/include/nvfuser/transform_replay.h +297 -0
- nvfuser/include/nvfuser/transform_rfactor.h +33 -0
- nvfuser/include/nvfuser/transform_view.h +136 -0
- nvfuser/include/nvfuser/type.h +1125 -0
- nvfuser/include/nvfuser/type_promotion.h +61 -0
- nvfuser/include/nvfuser/utils.h +619 -0
- nvfuser/include/nvfuser/val_graph.h +446 -0
- nvfuser/include/nvfuser/val_graph_visitor.h +259 -0
- nvfuser/include/nvfuser/validator_utils.h +92 -0
- nvfuser/include/nvfuser/vectorization_info.h +31 -0
- nvfuser/include/nvfuser/visibility.h +21 -0
- nvfuser/lib/libnvfuser_codegen.so +0 -0
- nvfuser/nvfuser_version.py +69 -0
- nvfuser/pytorch_utils.py +184 -0
- nvfuser/share/cmake/nvfuser/NvfuserConfig-release.cmake +20 -0
- nvfuser/share/cmake/nvfuser/NvfuserConfig.cmake +106 -0
- nvfuser/utils.py +18 -0
- nvfuser/version.py +1 -0
- nvfuser_cu121_torch25-0.2.25.dev20250201.dist-info/LICENSE +976 -0
- nvfuser_cu121_torch25-0.2.25.dev20250201.dist-info/METADATA +20 -0
- nvfuser_cu121_torch25-0.2.25.dev20250201.dist-info/RECORD +242 -0
- nvfuser_cu121_torch25-0.2.25.dev20250201.dist-info/WHEEL +5 -0
- nvfuser_cu121_torch25-0.2.25.dev20250201.dist-info/top_level.txt +1 -0
- nvfuser_cu121_torch25.libs/libnvToolsExt-847d78f2.so.1.0.0 +0 -0
@@ -0,0 +1,64 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright 2021 Google Inc. All rights reserved.
|
3
|
+
*
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
* you may not use this file except in compliance with the License.
|
6
|
+
* You may obtain a copy of the License at
|
7
|
+
*
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
*
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
* See the License for the specific language governing permissions and
|
14
|
+
* limitations under the License.
|
15
|
+
*/
|
16
|
+
|
17
|
+
#ifndef FLATBUFFERS_STRING_H_
|
18
|
+
#define FLATBUFFERS_STRING_H_
|
19
|
+
|
20
|
+
#include "flatbuffers/base.h"
|
21
|
+
#include "flatbuffers/vector.h"
|
22
|
+
|
23
|
+
namespace flatbuffers {
|
24
|
+
|
25
|
+
struct String : public Vector<char> {
|
26
|
+
const char *c_str() const { return reinterpret_cast<const char *>(Data()); }
|
27
|
+
std::string str() const { return std::string(c_str(), size()); }
|
28
|
+
|
29
|
+
// clang-format off
|
30
|
+
#ifdef FLATBUFFERS_HAS_STRING_VIEW
|
31
|
+
flatbuffers::string_view string_view() const {
|
32
|
+
return flatbuffers::string_view(c_str(), size());
|
33
|
+
}
|
34
|
+
#endif // FLATBUFFERS_HAS_STRING_VIEW
|
35
|
+
// clang-format on
|
36
|
+
|
37
|
+
bool operator<(const String &o) const {
|
38
|
+
return StringLessThan(this->data(), this->size(), o.data(), o.size());
|
39
|
+
}
|
40
|
+
};
|
41
|
+
|
42
|
+
// Convenience function to get std::string from a String returning an empty
|
43
|
+
// string on null pointer.
|
44
|
+
static inline std::string GetString(const String *str) {
|
45
|
+
return str ? str->str() : "";
|
46
|
+
}
|
47
|
+
|
48
|
+
// Convenience function to get char* from a String returning an empty string on
|
49
|
+
// null pointer.
|
50
|
+
static inline const char *GetCstring(const String *str) {
|
51
|
+
return str ? str->c_str() : "";
|
52
|
+
}
|
53
|
+
|
54
|
+
#ifdef FLATBUFFERS_HAS_STRING_VIEW
|
55
|
+
// Convenience function to get string_view from a String returning an empty
|
56
|
+
// string_view on null pointer.
|
57
|
+
static inline flatbuffers::string_view GetStringView(const String *str) {
|
58
|
+
return str ? str->string_view() : flatbuffers::string_view();
|
59
|
+
}
|
60
|
+
#endif // FLATBUFFERS_HAS_STRING_VIEW
|
61
|
+
|
62
|
+
} // namespace flatbuffers
|
63
|
+
|
64
|
+
#endif // FLATBUFFERS_STRING_H_
|
@@ -0,0 +1,53 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright 2021 Google Inc. All rights reserved.
|
3
|
+
*
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
* you may not use this file except in compliance with the License.
|
6
|
+
* You may obtain a copy of the License at
|
7
|
+
*
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
*
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
* See the License for the specific language governing permissions and
|
14
|
+
* limitations under the License.
|
15
|
+
*/
|
16
|
+
|
17
|
+
#ifndef FLATBUFFERS_STRUCT_H_
|
18
|
+
#define FLATBUFFERS_STRUCT_H_
|
19
|
+
|
20
|
+
#include "flatbuffers/base.h"
|
21
|
+
|
22
|
+
namespace flatbuffers {
|
23
|
+
|
24
|
+
// "structs" are flat structures that do not have an offset table, thus
|
25
|
+
// always have all members present and do not support forwards/backwards
|
26
|
+
// compatible extensions.
|
27
|
+
|
28
|
+
class Struct FLATBUFFERS_FINAL_CLASS {
|
29
|
+
public:
|
30
|
+
template<typename T> T GetField(uoffset_t o) const {
|
31
|
+
return ReadScalar<T>(&data_[o]);
|
32
|
+
}
|
33
|
+
|
34
|
+
template<typename T> T GetStruct(uoffset_t o) const {
|
35
|
+
return reinterpret_cast<T>(&data_[o]);
|
36
|
+
}
|
37
|
+
|
38
|
+
const uint8_t *GetAddressOf(uoffset_t o) const { return &data_[o]; }
|
39
|
+
uint8_t *GetAddressOf(uoffset_t o) { return &data_[o]; }
|
40
|
+
|
41
|
+
private:
|
42
|
+
// private constructor & copy constructor: you obtain instances of this
|
43
|
+
// class by pointing to existing data only
|
44
|
+
Struct();
|
45
|
+
Struct(const Struct &);
|
46
|
+
Struct &operator=(const Struct &);
|
47
|
+
|
48
|
+
uint8_t data_[1];
|
49
|
+
};
|
50
|
+
|
51
|
+
} // namespace flatbuffers
|
52
|
+
|
53
|
+
#endif // FLATBUFFERS_STRUCT_H_
|
@@ -0,0 +1,168 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright 2021 Google Inc. All rights reserved.
|
3
|
+
*
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
* you may not use this file except in compliance with the License.
|
6
|
+
* You may obtain a copy of the License at
|
7
|
+
*
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
*
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
* See the License for the specific language governing permissions and
|
14
|
+
* limitations under the License.
|
15
|
+
*/
|
16
|
+
|
17
|
+
#ifndef FLATBUFFERS_TABLE_H_
|
18
|
+
#define FLATBUFFERS_TABLE_H_
|
19
|
+
|
20
|
+
#include "flatbuffers/base.h"
|
21
|
+
#include "flatbuffers/verifier.h"
|
22
|
+
|
23
|
+
namespace flatbuffers {
|
24
|
+
|
25
|
+
// "tables" use an offset table (possibly shared) that allows fields to be
|
26
|
+
// omitted and added at will, but uses an extra indirection to read.
|
27
|
+
class Table {
|
28
|
+
public:
|
29
|
+
const uint8_t *GetVTable() const {
|
30
|
+
return data_ - ReadScalar<soffset_t>(data_);
|
31
|
+
}
|
32
|
+
|
33
|
+
// This gets the field offset for any of the functions below it, or 0
|
34
|
+
// if the field was not present.
|
35
|
+
voffset_t GetOptionalFieldOffset(voffset_t field) const {
|
36
|
+
// The vtable offset is always at the start.
|
37
|
+
auto vtable = GetVTable();
|
38
|
+
// The first element is the size of the vtable (fields + type id + itself).
|
39
|
+
auto vtsize = ReadScalar<voffset_t>(vtable);
|
40
|
+
// If the field we're accessing is outside the vtable, we're reading older
|
41
|
+
// data, so it's the same as if the offset was 0 (not present).
|
42
|
+
return field < vtsize ? ReadScalar<voffset_t>(vtable + field) : 0;
|
43
|
+
}
|
44
|
+
|
45
|
+
template<typename T> T GetField(voffset_t field, T defaultval) const {
|
46
|
+
auto field_offset = GetOptionalFieldOffset(field);
|
47
|
+
return field_offset ? ReadScalar<T>(data_ + field_offset) : defaultval;
|
48
|
+
}
|
49
|
+
|
50
|
+
template<typename P> P GetPointer(voffset_t field) {
|
51
|
+
auto field_offset = GetOptionalFieldOffset(field);
|
52
|
+
auto p = data_ + field_offset;
|
53
|
+
return field_offset ? reinterpret_cast<P>(p + ReadScalar<uoffset_t>(p))
|
54
|
+
: nullptr;
|
55
|
+
}
|
56
|
+
template<typename P> P GetPointer(voffset_t field) const {
|
57
|
+
return const_cast<Table *>(this)->GetPointer<P>(field);
|
58
|
+
}
|
59
|
+
|
60
|
+
template<typename P> P GetStruct(voffset_t field) const {
|
61
|
+
auto field_offset = GetOptionalFieldOffset(field);
|
62
|
+
auto p = const_cast<uint8_t *>(data_ + field_offset);
|
63
|
+
return field_offset ? reinterpret_cast<P>(p) : nullptr;
|
64
|
+
}
|
65
|
+
|
66
|
+
template<typename Raw, typename Face>
|
67
|
+
flatbuffers::Optional<Face> GetOptional(voffset_t field) const {
|
68
|
+
auto field_offset = GetOptionalFieldOffset(field);
|
69
|
+
auto p = data_ + field_offset;
|
70
|
+
return field_offset ? Optional<Face>(static_cast<Face>(ReadScalar<Raw>(p)))
|
71
|
+
: Optional<Face>();
|
72
|
+
}
|
73
|
+
|
74
|
+
template<typename T> bool SetField(voffset_t field, T val, T def) {
|
75
|
+
auto field_offset = GetOptionalFieldOffset(field);
|
76
|
+
if (!field_offset) return IsTheSameAs(val, def);
|
77
|
+
WriteScalar(data_ + field_offset, val);
|
78
|
+
return true;
|
79
|
+
}
|
80
|
+
template<typename T> bool SetField(voffset_t field, T val) {
|
81
|
+
auto field_offset = GetOptionalFieldOffset(field);
|
82
|
+
if (!field_offset) return false;
|
83
|
+
WriteScalar(data_ + field_offset, val);
|
84
|
+
return true;
|
85
|
+
}
|
86
|
+
|
87
|
+
bool SetPointer(voffset_t field, const uint8_t *val) {
|
88
|
+
auto field_offset = GetOptionalFieldOffset(field);
|
89
|
+
if (!field_offset) return false;
|
90
|
+
WriteScalar(data_ + field_offset,
|
91
|
+
static_cast<uoffset_t>(val - (data_ + field_offset)));
|
92
|
+
return true;
|
93
|
+
}
|
94
|
+
|
95
|
+
uint8_t *GetAddressOf(voffset_t field) {
|
96
|
+
auto field_offset = GetOptionalFieldOffset(field);
|
97
|
+
return field_offset ? data_ + field_offset : nullptr;
|
98
|
+
}
|
99
|
+
const uint8_t *GetAddressOf(voffset_t field) const {
|
100
|
+
return const_cast<Table *>(this)->GetAddressOf(field);
|
101
|
+
}
|
102
|
+
|
103
|
+
bool CheckField(voffset_t field) const {
|
104
|
+
return GetOptionalFieldOffset(field) != 0;
|
105
|
+
}
|
106
|
+
|
107
|
+
// Verify the vtable of this table.
|
108
|
+
// Call this once per table, followed by VerifyField once per field.
|
109
|
+
bool VerifyTableStart(Verifier &verifier) const {
|
110
|
+
return verifier.VerifyTableStart(data_);
|
111
|
+
}
|
112
|
+
|
113
|
+
// Verify a particular field.
|
114
|
+
template<typename T>
|
115
|
+
bool VerifyField(const Verifier &verifier, voffset_t field,
|
116
|
+
size_t align) const {
|
117
|
+
// Calling GetOptionalFieldOffset should be safe now thanks to
|
118
|
+
// VerifyTable().
|
119
|
+
auto field_offset = GetOptionalFieldOffset(field);
|
120
|
+
// Check the actual field.
|
121
|
+
return !field_offset || verifier.VerifyField<T>(data_, field_offset, align);
|
122
|
+
}
|
123
|
+
|
124
|
+
// VerifyField for required fields.
|
125
|
+
template<typename T>
|
126
|
+
bool VerifyFieldRequired(const Verifier &verifier, voffset_t field,
|
127
|
+
size_t align) const {
|
128
|
+
auto field_offset = GetOptionalFieldOffset(field);
|
129
|
+
return verifier.Check(field_offset != 0) &&
|
130
|
+
verifier.VerifyField<T>(data_, field_offset, align);
|
131
|
+
}
|
132
|
+
|
133
|
+
// Versions for offsets.
|
134
|
+
bool VerifyOffset(const Verifier &verifier, voffset_t field) const {
|
135
|
+
auto field_offset = GetOptionalFieldOffset(field);
|
136
|
+
return !field_offset || verifier.VerifyOffset(data_, field_offset);
|
137
|
+
}
|
138
|
+
|
139
|
+
bool VerifyOffsetRequired(const Verifier &verifier, voffset_t field) const {
|
140
|
+
auto field_offset = GetOptionalFieldOffset(field);
|
141
|
+
return verifier.Check(field_offset != 0) &&
|
142
|
+
verifier.VerifyOffset(data_, field_offset);
|
143
|
+
}
|
144
|
+
|
145
|
+
private:
|
146
|
+
// private constructor & copy constructor: you obtain instances of this
|
147
|
+
// class by pointing to existing data only
|
148
|
+
Table();
|
149
|
+
Table(const Table &other);
|
150
|
+
Table &operator=(const Table &);
|
151
|
+
|
152
|
+
uint8_t data_[1];
|
153
|
+
};
|
154
|
+
|
155
|
+
// This specialization allows avoiding warnings like:
|
156
|
+
// MSVC C4800: type: forcing value to bool 'true' or 'false'.
|
157
|
+
template<>
|
158
|
+
inline flatbuffers::Optional<bool> Table::GetOptional<uint8_t, bool>(
|
159
|
+
voffset_t field) const {
|
160
|
+
auto field_offset = GetOptionalFieldOffset(field);
|
161
|
+
auto p = data_ + field_offset;
|
162
|
+
return field_offset ? Optional<bool>(ReadScalar<uint8_t>(p) != 0)
|
163
|
+
: Optional<bool>();
|
164
|
+
}
|
165
|
+
|
166
|
+
} // namespace flatbuffers
|
167
|
+
|
168
|
+
#endif // FLATBUFFERS_TABLE_H_
|