28 #include <tbb/parallel_for.h> 38 template <
class TFeat,
42 bool POINT_IMPORTANCE>
44 const std::vector<int>& filter_dims,
48 const TFeat* inp_features,
49 const TFeat* inp_importance,
50 size_t neighbors_index_size,
51 const TIndex* neighbors_index,
52 const TKernelIndex* neighbors_kernel_index,
53 const TFeat* neighbors_importance,
54 const int64_t* neighbors_row_splits,
56 const bool NEIGHBOR_IMPORTANCE = neighbors_importance !=
nullptr;
58 const int in_channels = filter_dims[filter_dims.size() - 2];
59 const int out_channels = filter_dims[filter_dims.size() - 1];
61 int num_kernel_elements = 1;
62 for (
int i = 0; i < filter_dims.size() - 2; ++i)
63 num_kernel_elements *= filter_dims[i];
65 memset(out_features, 0,
sizeof(TOut) * num_out * out_channels);
68 tbb::blocked_range<size_t>(0, num_out, 32),
69 [&](
const tbb::blocked_range<size_t>& r) {
70 int range_length = r.end() - r.begin();
72 Eigen::Matrix<TOut, Eigen::Dynamic, 1> normalizers(range_length,
74 normalizers.setZero();
76 Eigen::Map<Eigen::Matrix<TOut, Eigen::Dynamic, Eigen::Dynamic>>
77 C(out_features + (r.begin() * out_channels),
78 out_channels, range_length);
80 for (
size_t out_idx = r.begin(); out_idx != r.end();
82 const int out_col = out_idx - r.begin();
83 const size_t neighbor_start = neighbors_row_splits[out_idx];
84 const size_t neighbor_end =
85 neighbors_row_splits[out_idx + 1];
87 for (
size_t n = neighbor_start; n < neighbor_end; ++n) {
88 const size_t inp_idx = neighbors_index[n];
89 const int kernel_idx = neighbors_kernel_index[n];
91 const TFeat n_importance =
92 (NEIGHBOR_IMPORTANCE ? neighbors_importance[n]
94 normalizers(out_col) += TOut(n_importance);
96 TFeat importance(1.0);
98 importance = inp_importance[inp_idx];
99 if (NEIGHBOR_IMPORTANCE) importance *= n_importance;
101 Eigen::Map<
const Eigen::Matrix<TFeat, Eigen::Dynamic,
103 A(filter + kernel_idx * out_channels *
105 out_channels, in_channels);
107 Eigen::Map<
const Eigen::Matrix<TFeat, Eigen::Dynamic,
109 B(inp_features + inp_idx * in_channels,
113 (A * (importance * B)).template cast<TOut>();
119 for (
int i = 0; i < range_length; ++i) {
120 if (normalizers(i) != TOut(0))
121 C.col(i) /= normalizers(i);
172 template <
class TFeat,
class TOut,
class TIndex,
class TKernelIndex>
174 const std::vector<int>& filter_dims,
178 const TFeat* inp_features,
179 const TFeat* inp_importance,
180 size_t neighbors_index_size,
181 const TIndex* neighbors_index,
182 const TKernelIndex* neighbors_kernel_index,
183 const TFeat* neighbors_importance,
184 const int64_t* neighbors_row_splits,
187 bool has_importance = inp_importance;
189 #define FN_PARAMETERS \ 190 out_features, filter_dims, filter, num_out, num_inp, inp_features, \ 191 inp_importance, neighbors_index_size, neighbors_index, \ 192 neighbors_kernel_index, neighbors_importance, \ 193 neighbors_row_splits, normalize 195 #define CALL_TEMPLATE(HAS_IMPORTANCE) \ 196 if (HAS_IMPORTANCE == has_importance) \ 197 _SparseConvComputeFeaturesCPU<TFeat, TOut, TIndex, TKernelIndex, \ 198 HAS_IMPORTANCE>(FN_PARAMETERS); 200 #define CALL_TEMPLATE2 \ 201 CALL_TEMPLATE(true) \ 207 #undef CALL_TEMPLATE2
void SparseConvComputeFeaturesCPU(TOut *out_features, const std::vector< int > &filter_dims, const TFeat *filter, size_t num_out, size_t num_inp, const TFeat *inp_features, const TFeat *inp_importance, size_t neighbors_index_size, const TIndex *neighbors_index, const TKernelIndex *neighbors_kernel_index, const TFeat *neighbors_importance, const int64_t *neighbors_row_splits, bool normalize)
Definition: SparseConv.h:173
Definition: PinholeCameraIntrinsic.cpp:35
void _SparseConvComputeFeaturesCPU(TOut *out_features, const std::vector< int > &filter_dims, const TFeat *filter, size_t num_out, size_t num_inp, const TFeat *inp_features, const TFeat *inp_importance, size_t neighbors_index_size, const TIndex *neighbors_index, const TKernelIndex *neighbors_kernel_index, const TFeat *neighbors_importance, const int64_t *neighbors_row_splits, bool normalize)
Definition: SparseConv.h:43