12 #include "../TensorFlowHelper.h"
15 #include "tensorflow/core/framework/op.h"
16 #include "tensorflow/core/framework/op_kernel.h"
17 #include "tensorflow/core/lib/core/errors.h"
21 namespace fixed_radius_search_opkernel {
24 template <
class T,
class TIndex>
25 class OutputAllocator {
29 void AllocIndices(TIndex** ptr,
size_t num) {
30 using namespace tensorflow;
33 TensorShape shape({int64_t(num)});
34 OP_REQUIRES_OK(
context,
context->allocate_output(0, shape, &tensor));
36 auto flat_tensor = tensor->flat<TIndex>();
37 *ptr = (TIndex*)flat_tensor.data();
40 void AllocDistances(T** ptr,
size_t num) {
41 using namespace tensorflow;
44 TensorShape shape({int64_t(num)});
45 OP_REQUIRES_OK(
context,
context->allocate_output(2, shape, &tensor));
46 auto flat_tensor = tensor->flat<T>();
47 *ptr = flat_tensor.data();
51 tensorflow::OpKernelContext*
context;
54 class FixedRadiusSearchOpKernel :
public tensorflow::OpKernel {
56 explicit FixedRadiusSearchOpKernel(
57 tensorflow::OpKernelConstruction* construction)
58 : OpKernel(construction) {
59 using namespace tensorflow;
62 std::string metric_str;
63 OP_REQUIRES_OK(construction,
64 construction->GetAttr(
"metric", &metric_str));
65 if (metric_str ==
"L1")
67 else if (metric_str ==
"L2")
72 OP_REQUIRES_OK(construction,
73 construction->GetAttr(
"ignore_query_point",
74 &ignore_query_point));
76 OP_REQUIRES_OK(construction, construction->GetAttr(
"return_distances",
80 void Compute(tensorflow::OpKernelContext*
context)
override {
81 using namespace tensorflow;
82 static_assert(
sizeof(int64_t) ==
sizeof(int64_t),
83 "int64_t type is not compatible");
86 const Tensor& queries =
context->input(1);
88 const Tensor& radius =
context->input(2);
89 OP_REQUIRES(
context, TensorShapeUtils::IsScalar(radius.shape()),
90 absl::InvalidArgumentError(
91 std::string(
"radius must be scalar, got shape ") +
92 radius.shape().DebugString()));
94 const Tensor& points_row_splits =
context->input(3);
95 const Tensor& queries_row_splits =
context->input(4);
97 const Tensor& hash_table_splits =
context->input(5);
98 const Tensor& hash_table_index =
context->input(6);
99 const Tensor& hash_table_cell_splits =
context->input(7);
104 Dim num_points(
"num_points");
105 Dim num_queries(
"num_queries");
106 Dim batch_size(
"batch_size");
107 Dim num_cells(
"num_cells");
116 Tensor* query_neighbors_row_splits = 0;
117 TensorShape query_neighbors_row_splits_shape(
118 {queries.shape().dim_size(0) + 1});
120 1, query_neighbors_row_splits_shape,
121 &query_neighbors_row_splits));
124 queries_row_splits, hash_table_splits, hash_table_index,
125 hash_table_cell_splits, *query_neighbors_row_splits);
128 virtual void Kernel(tensorflow::OpKernelContext*
context,
129 const tensorflow::Tensor&
points,
130 const tensorflow::Tensor& queries,
131 const tensorflow::Tensor& radius,
132 const tensorflow::Tensor& points_row_splits,
133 const tensorflow::Tensor& queries_row_splits,
134 const tensorflow::Tensor& hash_table_splits,
135 const tensorflow::Tensor& hash_table_index,
136 const tensorflow::Tensor& hash_table_cell_splits,
137 tensorflow::Tensor& query_neighbors_row_splits) = 0;
141 bool ignore_query_point;
142 bool return_distances;
#define CHECK_SHAPE(tensor,...)
Definition: TorchHelper.h:190
ImGuiContext * context
Definition: Window.cpp:76
Class for dimensions for which the value should be inferred.
Definition: ShapeChecking.h:50
Definition: FixedRadiusIndex.cpp:16
Metric
Supported metrics.
Definition: NeighborSearchCommon.h:19
@ Linf
Definition: NeighborSearchCommon.h:19
@ L1
Definition: NeighborSearchCommon.h:19
@ L2
Definition: NeighborSearchCommon.h:19
Definition: ShapeChecking.h:16