nvfuser-cu121-torch25 0.2.25.dev20250201__cp312-cp312-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-312-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 +16 -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,300 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright 2014 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_GRPC_H_
|
18
|
+
#define FLATBUFFERS_GRPC_H_
|
19
|
+
|
20
|
+
// Helper functionality to glue FlatBuffers and GRPC.
|
21
|
+
|
22
|
+
#include "flatbuffers/flatbuffers.h"
|
23
|
+
#include "grpc/byte_buffer_reader.h"
|
24
|
+
#include "grpcpp/support/byte_buffer.h"
|
25
|
+
#include "grpcpp/support/slice.h"
|
26
|
+
|
27
|
+
namespace flatbuffers {
|
28
|
+
namespace grpc {
|
29
|
+
|
30
|
+
// Message is a typed wrapper around a buffer that manages the underlying
|
31
|
+
// `grpc_slice` and also provides flatbuffers-specific helpers such as `Verify`
|
32
|
+
// and `GetRoot`. Since it is backed by a `grpc_slice`, the underlying buffer
|
33
|
+
// is refcounted and ownership is be managed automatically.
|
34
|
+
template<class T> class Message {
|
35
|
+
public:
|
36
|
+
Message() {}
|
37
|
+
|
38
|
+
Message(::grpc::Slice slice) : slice_(slice) {}
|
39
|
+
|
40
|
+
Message &operator=(const Message &other) = delete;
|
41
|
+
|
42
|
+
Message(Message &&other) = default;
|
43
|
+
|
44
|
+
Message(const Message &other) = delete;
|
45
|
+
|
46
|
+
Message &operator=(Message &&other) = default;
|
47
|
+
|
48
|
+
const uint8_t *mutable_data() const { return slice_.begin(); }
|
49
|
+
|
50
|
+
const uint8_t *data() const { return slice_.begin(); }
|
51
|
+
|
52
|
+
size_t size() const { return slice_.size(); }
|
53
|
+
|
54
|
+
bool Verify() const {
|
55
|
+
Verifier verifier(data(), size());
|
56
|
+
return verifier.VerifyBuffer<T>(nullptr);
|
57
|
+
}
|
58
|
+
|
59
|
+
T *GetMutableRoot() { return flatbuffers::GetMutableRoot<T>(mutable_data()); }
|
60
|
+
|
61
|
+
const T *GetRoot() const { return flatbuffers::GetRoot<T>(data()); }
|
62
|
+
|
63
|
+
// This is only intended for serializer use, or if you know what you're doing
|
64
|
+
const ::grpc::Slice &BorrowSlice() const { return slice_; }
|
65
|
+
|
66
|
+
private:
|
67
|
+
::grpc::Slice slice_;
|
68
|
+
};
|
69
|
+
|
70
|
+
class MessageBuilder;
|
71
|
+
|
72
|
+
// SliceAllocator is a gRPC-specific allocator that uses the `grpc_slice`
|
73
|
+
// refcounted slices to manage memory ownership. This makes it easy and
|
74
|
+
// efficient to transfer buffers to gRPC.
|
75
|
+
class SliceAllocator : public Allocator {
|
76
|
+
public:
|
77
|
+
SliceAllocator() {}
|
78
|
+
|
79
|
+
SliceAllocator(const SliceAllocator &other) = delete;
|
80
|
+
SliceAllocator &operator=(const SliceAllocator &other) = delete;
|
81
|
+
|
82
|
+
SliceAllocator(SliceAllocator &&other) {
|
83
|
+
// default-construct and swap idiom
|
84
|
+
swap(other);
|
85
|
+
}
|
86
|
+
|
87
|
+
SliceAllocator &operator=(SliceAllocator &&other) {
|
88
|
+
// move-construct and swap idiom
|
89
|
+
SliceAllocator temp(std::move(other));
|
90
|
+
swap(temp);
|
91
|
+
return *this;
|
92
|
+
}
|
93
|
+
|
94
|
+
void swap(SliceAllocator &other) {
|
95
|
+
using std::swap;
|
96
|
+
swap(slice_, other.slice_);
|
97
|
+
}
|
98
|
+
|
99
|
+
virtual ~SliceAllocator() {}
|
100
|
+
|
101
|
+
virtual uint8_t *allocate(size_t size) override {
|
102
|
+
FLATBUFFERS_ASSERT(slice_.size() == 0);
|
103
|
+
slice_ = ::grpc::Slice(size);
|
104
|
+
return const_cast<uint8_t *>(slice_.begin());
|
105
|
+
}
|
106
|
+
|
107
|
+
virtual void deallocate(uint8_t *p, size_t size) override {
|
108
|
+
FLATBUFFERS_ASSERT(p == slice_.begin());
|
109
|
+
FLATBUFFERS_ASSERT(size == slice_.size());
|
110
|
+
slice_ = ::grpc::Slice();
|
111
|
+
}
|
112
|
+
|
113
|
+
virtual uint8_t *reallocate_downward(uint8_t *old_p, size_t old_size,
|
114
|
+
size_t new_size, size_t in_use_back,
|
115
|
+
size_t in_use_front) override {
|
116
|
+
FLATBUFFERS_ASSERT(old_p == slice_.begin());
|
117
|
+
FLATBUFFERS_ASSERT(old_size == slice_.size());
|
118
|
+
FLATBUFFERS_ASSERT(new_size > old_size);
|
119
|
+
::grpc::Slice old_slice = slice_;
|
120
|
+
::grpc::Slice new_slice = ::grpc::Slice(new_size);
|
121
|
+
uint8_t *new_p = const_cast<uint8_t *>(new_slice.begin());
|
122
|
+
memcpy_downward(old_p, old_size, new_p, new_size, in_use_back,
|
123
|
+
in_use_front);
|
124
|
+
slice_ = new_slice;
|
125
|
+
return new_p;
|
126
|
+
}
|
127
|
+
|
128
|
+
private:
|
129
|
+
::grpc::Slice &get_slice(uint8_t *p, size_t size) {
|
130
|
+
FLATBUFFERS_ASSERT(p == slice_.begin());
|
131
|
+
FLATBUFFERS_ASSERT(size == slice_.size());
|
132
|
+
return slice_;
|
133
|
+
}
|
134
|
+
|
135
|
+
::grpc::Slice slice_;
|
136
|
+
|
137
|
+
friend class MessageBuilder;
|
138
|
+
};
|
139
|
+
|
140
|
+
// SliceAllocatorMember is a hack to ensure that the MessageBuilder's
|
141
|
+
// slice_allocator_ member is constructed before the FlatBufferBuilder, since
|
142
|
+
// the allocator is used in the FlatBufferBuilder ctor.
|
143
|
+
namespace detail {
|
144
|
+
struct SliceAllocatorMember {
|
145
|
+
SliceAllocator slice_allocator_;
|
146
|
+
};
|
147
|
+
} // namespace detail
|
148
|
+
|
149
|
+
// MessageBuilder is a gRPC-specific FlatBufferBuilder that uses SliceAllocator
|
150
|
+
// to allocate gRPC buffers.
|
151
|
+
class MessageBuilder : private detail::SliceAllocatorMember,
|
152
|
+
public FlatBufferBuilder {
|
153
|
+
public:
|
154
|
+
explicit MessageBuilder(uoffset_t initial_size = 1024)
|
155
|
+
: FlatBufferBuilder(initial_size, &slice_allocator_, false) {}
|
156
|
+
|
157
|
+
MessageBuilder(const MessageBuilder &other) = delete;
|
158
|
+
MessageBuilder &operator=(const MessageBuilder &other) = delete;
|
159
|
+
|
160
|
+
MessageBuilder(MessageBuilder &&other)
|
161
|
+
: FlatBufferBuilder(1024, &slice_allocator_, false) {
|
162
|
+
// Default construct and swap idiom.
|
163
|
+
Swap(other);
|
164
|
+
}
|
165
|
+
|
166
|
+
/// Create a MessageBuilder from a FlatBufferBuilder.
|
167
|
+
explicit MessageBuilder(FlatBufferBuilder &&src,
|
168
|
+
void (*dealloc)(void *,
|
169
|
+
size_t) = &DefaultAllocator::dealloc)
|
170
|
+
: FlatBufferBuilder(1024, &slice_allocator_, false) {
|
171
|
+
src.Swap(*this);
|
172
|
+
src.SwapBufAllocator(*this);
|
173
|
+
if (buf_.capacity()) {
|
174
|
+
uint8_t *buf = buf_.scratch_data(); // pointer to memory
|
175
|
+
size_t capacity = buf_.capacity(); // size of memory
|
176
|
+
slice_allocator_.slice_ = ::grpc::Slice(buf, capacity, dealloc);
|
177
|
+
} else {
|
178
|
+
slice_allocator_.slice_ = ::grpc::Slice();
|
179
|
+
}
|
180
|
+
}
|
181
|
+
|
182
|
+
/// Move-assign a FlatBufferBuilder to a MessageBuilder.
|
183
|
+
/// Only FlatBufferBuilder with default allocator (basically, nullptr) is
|
184
|
+
/// supported.
|
185
|
+
MessageBuilder &operator=(FlatBufferBuilder &&src) {
|
186
|
+
// Move construct a temporary and swap
|
187
|
+
MessageBuilder temp(std::move(src));
|
188
|
+
Swap(temp);
|
189
|
+
return *this;
|
190
|
+
}
|
191
|
+
|
192
|
+
MessageBuilder &operator=(MessageBuilder &&other) {
|
193
|
+
// Move construct a temporary and swap
|
194
|
+
MessageBuilder temp(std::move(other));
|
195
|
+
Swap(temp);
|
196
|
+
return *this;
|
197
|
+
}
|
198
|
+
|
199
|
+
void Swap(MessageBuilder &other) {
|
200
|
+
slice_allocator_.swap(other.slice_allocator_);
|
201
|
+
FlatBufferBuilder::Swap(other);
|
202
|
+
// After swapping the FlatBufferBuilder, we swap back the allocator, which
|
203
|
+
// restores the original allocator back in place. This is necessary because
|
204
|
+
// MessageBuilder's allocator is its own member (SliceAllocatorMember). The
|
205
|
+
// allocator passed to FlatBufferBuilder::vector_downward must point to this
|
206
|
+
// member.
|
207
|
+
buf_.swap_allocator(other.buf_);
|
208
|
+
}
|
209
|
+
|
210
|
+
// Releases the ownership of the buffer pointer.
|
211
|
+
// Returns the size, offset, and the original grpc_slice that
|
212
|
+
// allocated the buffer. Also see grpc_slice_unref().
|
213
|
+
uint8_t *ReleaseRaw(size_t &size, size_t &offset, ::grpc::Slice &slice) {
|
214
|
+
uint8_t *buf = FlatBufferBuilder::ReleaseRaw(size, offset);
|
215
|
+
slice = slice_allocator_.slice_;
|
216
|
+
slice_allocator_.slice_ = ::grpc::Slice();
|
217
|
+
return buf;
|
218
|
+
}
|
219
|
+
|
220
|
+
~MessageBuilder() {}
|
221
|
+
|
222
|
+
// GetMessage extracts the subslice of the buffer corresponding to the
|
223
|
+
// flatbuffers-encoded region and wraps it in a `Message<T>` to handle buffer
|
224
|
+
// ownership.
|
225
|
+
template<class T> Message<T> GetMessage() {
|
226
|
+
auto buf_data = buf_.scratch_data(); // pointer to memory
|
227
|
+
auto buf_size = buf_.capacity(); // size of memory
|
228
|
+
auto msg_data = buf_.data(); // pointer to msg
|
229
|
+
auto msg_size = buf_.size(); // size of msg
|
230
|
+
// Do some sanity checks on data/size
|
231
|
+
FLATBUFFERS_ASSERT(msg_data);
|
232
|
+
FLATBUFFERS_ASSERT(msg_size);
|
233
|
+
FLATBUFFERS_ASSERT(msg_data >= buf_data);
|
234
|
+
FLATBUFFERS_ASSERT(msg_data + msg_size <= buf_data + buf_size);
|
235
|
+
// Calculate offsets from the buffer start
|
236
|
+
auto begin = msg_data - buf_data;
|
237
|
+
auto end = begin + msg_size;
|
238
|
+
// Get the slice we are working with (no refcount change)
|
239
|
+
::grpc::Slice slice = slice_allocator_.get_slice(buf_data, buf_size);
|
240
|
+
// Extract a subslice of the existing slice (increment refcount)
|
241
|
+
::grpc::Slice subslice = slice.sub(begin, end);
|
242
|
+
// Wrap the subslice in a `Message<T>`, but don't increment refcount
|
243
|
+
Message<T> msg(subslice);
|
244
|
+
return msg;
|
245
|
+
}
|
246
|
+
|
247
|
+
template<class T> Message<T> ReleaseMessage() {
|
248
|
+
Message<T> msg = GetMessage<T>();
|
249
|
+
Reset();
|
250
|
+
return msg;
|
251
|
+
}
|
252
|
+
|
253
|
+
private:
|
254
|
+
// SliceAllocator slice_allocator_; // part of SliceAllocatorMember
|
255
|
+
};
|
256
|
+
|
257
|
+
} // namespace grpc
|
258
|
+
} // namespace flatbuffers
|
259
|
+
|
260
|
+
namespace grpc {
|
261
|
+
|
262
|
+
template<class T> class SerializationTraits<flatbuffers::grpc::Message<T>> {
|
263
|
+
public:
|
264
|
+
static grpc::Status Serialize(const flatbuffers::grpc::Message<T> &msg,
|
265
|
+
ByteBuffer *buffer, bool *own_buffer) {
|
266
|
+
// Package the single slice into a `ByteBuffer`,
|
267
|
+
// incrementing the refcount in the process.
|
268
|
+
*buffer = ByteBuffer(&msg.BorrowSlice(), 1);
|
269
|
+
*own_buffer = true;
|
270
|
+
return grpc::Status::OK;
|
271
|
+
}
|
272
|
+
|
273
|
+
// Deserialize by pulling the
|
274
|
+
static grpc::Status Deserialize(ByteBuffer *buf,
|
275
|
+
flatbuffers::grpc::Message<T> *msg) {
|
276
|
+
Slice slice;
|
277
|
+
if (!buf->TrySingleSlice(&slice).ok()) {
|
278
|
+
if (!buf->DumpToSingleSlice(&slice).ok()) {
|
279
|
+
buf->Clear();
|
280
|
+
return ::grpc::Status(::grpc::StatusCode::INTERNAL, "No payload");
|
281
|
+
}
|
282
|
+
}
|
283
|
+
*msg = flatbuffers::grpc::Message<T>(slice);
|
284
|
+
buf->Clear();
|
285
|
+
#if FLATBUFFERS_GRPC_DISABLE_AUTO_VERIFICATION
|
286
|
+
return ::grpc::Status::OK;
|
287
|
+
#else
|
288
|
+
if (msg->Verify()) {
|
289
|
+
return ::grpc::Status::OK;
|
290
|
+
} else {
|
291
|
+
return ::grpc::Status(::grpc::StatusCode::INTERNAL,
|
292
|
+
"Message verification failed");
|
293
|
+
}
|
294
|
+
#endif
|
295
|
+
}
|
296
|
+
};
|
297
|
+
|
298
|
+
} // namespace grpc
|
299
|
+
|
300
|
+
#endif // FLATBUFFERS_GRPC_H_
|
@@ -0,0 +1,127 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright 2015 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_HASH_H_
|
18
|
+
#define FLATBUFFERS_HASH_H_
|
19
|
+
|
20
|
+
#include <cstdint>
|
21
|
+
#include <cstring>
|
22
|
+
|
23
|
+
#include "flatbuffers/flatbuffers.h"
|
24
|
+
|
25
|
+
namespace flatbuffers {
|
26
|
+
|
27
|
+
template<typename T> struct FnvTraits {
|
28
|
+
static const T kFnvPrime;
|
29
|
+
static const T kOffsetBasis;
|
30
|
+
};
|
31
|
+
|
32
|
+
template<> struct FnvTraits<uint32_t> {
|
33
|
+
static const uint32_t kFnvPrime = 0x01000193;
|
34
|
+
static const uint32_t kOffsetBasis = 0x811C9DC5;
|
35
|
+
};
|
36
|
+
|
37
|
+
template<> struct FnvTraits<uint64_t> {
|
38
|
+
static const uint64_t kFnvPrime = 0x00000100000001b3ULL;
|
39
|
+
static const uint64_t kOffsetBasis = 0xcbf29ce484222645ULL;
|
40
|
+
};
|
41
|
+
|
42
|
+
template<typename T> T HashFnv1(const char *input) {
|
43
|
+
T hash = FnvTraits<T>::kOffsetBasis;
|
44
|
+
for (const char *c = input; *c; ++c) {
|
45
|
+
hash *= FnvTraits<T>::kFnvPrime;
|
46
|
+
hash ^= static_cast<unsigned char>(*c);
|
47
|
+
}
|
48
|
+
return hash;
|
49
|
+
}
|
50
|
+
|
51
|
+
template<typename T> T HashFnv1a(const char *input) {
|
52
|
+
T hash = FnvTraits<T>::kOffsetBasis;
|
53
|
+
for (const char *c = input; *c; ++c) {
|
54
|
+
hash ^= static_cast<unsigned char>(*c);
|
55
|
+
hash *= FnvTraits<T>::kFnvPrime;
|
56
|
+
}
|
57
|
+
return hash;
|
58
|
+
}
|
59
|
+
|
60
|
+
template<> inline uint16_t HashFnv1<uint16_t>(const char *input) {
|
61
|
+
uint32_t hash = HashFnv1<uint32_t>(input);
|
62
|
+
return (hash >> 16) ^ (hash & 0xffff);
|
63
|
+
}
|
64
|
+
|
65
|
+
template<> inline uint16_t HashFnv1a<uint16_t>(const char *input) {
|
66
|
+
uint32_t hash = HashFnv1a<uint32_t>(input);
|
67
|
+
return (hash >> 16) ^ (hash & 0xffff);
|
68
|
+
}
|
69
|
+
|
70
|
+
template<typename T> struct NamedHashFunction {
|
71
|
+
const char *name;
|
72
|
+
|
73
|
+
typedef T (*HashFunction)(const char *);
|
74
|
+
HashFunction function;
|
75
|
+
};
|
76
|
+
|
77
|
+
const NamedHashFunction<uint16_t> kHashFunctions16[] = {
|
78
|
+
{ "fnv1_16", HashFnv1<uint16_t> },
|
79
|
+
{ "fnv1a_16", HashFnv1a<uint16_t> },
|
80
|
+
};
|
81
|
+
|
82
|
+
const NamedHashFunction<uint32_t> kHashFunctions32[] = {
|
83
|
+
{ "fnv1_32", HashFnv1<uint32_t> },
|
84
|
+
{ "fnv1a_32", HashFnv1a<uint32_t> },
|
85
|
+
};
|
86
|
+
|
87
|
+
const NamedHashFunction<uint64_t> kHashFunctions64[] = {
|
88
|
+
{ "fnv1_64", HashFnv1<uint64_t> },
|
89
|
+
{ "fnv1a_64", HashFnv1a<uint64_t> },
|
90
|
+
};
|
91
|
+
|
92
|
+
inline NamedHashFunction<uint16_t>::HashFunction FindHashFunction16(
|
93
|
+
const char *name) {
|
94
|
+
std::size_t size = sizeof(kHashFunctions16) / sizeof(kHashFunctions16[0]);
|
95
|
+
for (std::size_t i = 0; i < size; ++i) {
|
96
|
+
if (std::strcmp(name, kHashFunctions16[i].name) == 0) {
|
97
|
+
return kHashFunctions16[i].function;
|
98
|
+
}
|
99
|
+
}
|
100
|
+
return nullptr;
|
101
|
+
}
|
102
|
+
|
103
|
+
inline NamedHashFunction<uint32_t>::HashFunction FindHashFunction32(
|
104
|
+
const char *name) {
|
105
|
+
std::size_t size = sizeof(kHashFunctions32) / sizeof(kHashFunctions32[0]);
|
106
|
+
for (std::size_t i = 0; i < size; ++i) {
|
107
|
+
if (std::strcmp(name, kHashFunctions32[i].name) == 0) {
|
108
|
+
return kHashFunctions32[i].function;
|
109
|
+
}
|
110
|
+
}
|
111
|
+
return nullptr;
|
112
|
+
}
|
113
|
+
|
114
|
+
inline NamedHashFunction<uint64_t>::HashFunction FindHashFunction64(
|
115
|
+
const char *name) {
|
116
|
+
std::size_t size = sizeof(kHashFunctions64) / sizeof(kHashFunctions64[0]);
|
117
|
+
for (std::size_t i = 0; i < size; ++i) {
|
118
|
+
if (std::strcmp(name, kHashFunctions64[i].name) == 0) {
|
119
|
+
return kHashFunctions64[i].function;
|
120
|
+
}
|
121
|
+
}
|
122
|
+
return nullptr;
|
123
|
+
}
|
124
|
+
|
125
|
+
} // namespace flatbuffers
|
126
|
+
|
127
|
+
#endif // FLATBUFFERS_HASH_H_
|