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"
21namespace fixed_radius_search_opkernel {
24template <
class T,
class TIndex>
25class 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;
54class 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");
89 OP_REQUIRES(
context, TensorShapeUtils::IsScalar(radius.shape()),
90 absl::InvalidArgumentError(
91 std::string(
"radius must be scalar, got shape ") +
92 radius.shape().DebugString()));
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:232
ImGuiContext * context
Definition Window.cpp:99
Class for dimensions for which the value should be inferred.
Definition ShapeChecking.h:50
Shared types and SYCL nearest-neighbor search tuning defaults.
Definition FixedRadiusIndex.cpp:18
Metric
Supported metrics.
Definition NeighborSearchCommon.h:22
@ Linf
Definition NeighborSearchCommon.h:22
@ L1
Definition NeighborSearchCommon.h:22
@ L2
Definition NeighborSearchCommon.h:22
Definition ShapeChecking.h:16