9 #include <tbb/parallel_for.h>
19 template <
class TFeat,
26 const std::vector<int>& filter_dims,
29 const TFeat* out_importance,
31 const TFeat* inp_features,
32 const TFeat* inp_neighbors_importance_sum,
33 const int64_t* inp_neighbors_row_splits,
34 const TIndex* neighbor_index,
35 const TKernelIndex* neighbors_kernel_index,
36 const TFeat* neighbor_importance,
37 const int64_t* neighbors_row_splits) {
38 const bool NEIGHBOR_IMPORTANCE = inp_neighbors_importance_sum;
40 const int in_channels = filter_dims[filter_dims.size() - 2];
41 const int out_channels = filter_dims[filter_dims.size() - 1];
43 int num_kernel_elements = 1;
44 for (
int i = 0; i < filter_dims.size() - 2; ++i)
45 num_kernel_elements *= filter_dims[i];
47 memset(out_features, 0,
sizeof(TOut) * num_out * out_channels);
50 tbb::blocked_range<size_t>(0, num_out, 32),
51 [&](
const tbb::blocked_range<size_t>& r) {
52 int range_length = r.end() - r.begin();
54 Eigen::Map<Eigen::Matrix<TOut, Eigen::Dynamic, Eigen::Dynamic>>
55 C(out_features + (r.begin() * out_channels),
56 out_channels, range_length);
58 for (
size_t out_idx = r.begin(); out_idx != r.end();
60 const int out_col = out_idx - r.begin();
61 const size_t neighbor_start = neighbors_row_splits[out_idx];
62 const size_t neighbor_end =
63 neighbors_row_splits[out_idx + 1];
65 for (size_t n = neighbor_start; n < neighbor_end; ++n) {
66 const size_t inp_idx = neighbor_index[n];
67 const int kernel_idx = neighbors_kernel_index[n];
69 TFeat n_importance = NEIGHBOR_IMPORTANCE
70 ? neighbor_importance[n]
75 if (NEIGHBOR_IMPORTANCE) {
76 if (inp_neighbors_importance_sum[inp_idx] !=
78 normalizer /= inp_neighbors_importance_sum
81 size_t num_inp_neighbors;
82 const size_t inp_neighbor_start =
83 inp_neighbors_row_splits[inp_idx];
84 const size_t inp_neighbor_end =
85 inp_neighbors_row_splits[inp_idx + 1];
87 inp_neighbor_end - inp_neighbor_start;
88 if (num_inp_neighbors > 0)
89 normalizer /= TFeat(num_inp_neighbors);
93 Eigen::Map<const Eigen::Matrix<TFeat, Eigen::Dynamic,
95 A(filter + kernel_idx * out_channels *
97 out_channels, in_channels);
99 Eigen::Map<const Eigen::Matrix<TFeat, Eigen::Dynamic,
101 B(inp_features + inp_idx * in_channels,
103 TFeat scale = normalizer * n_importance;
105 (A * (scale * B)).template cast<TOut>();
110 if (out_importance) {
111 for (
int i = 0; i < range_length; ++i)
112 C.col(i) *= TOut(out_importance[r.begin() + i]);
163 template <
class TFeat,
class TOut,
class TIndex,
class TKernelIndex>
166 const std::vector<int>& filter_dims,
169 const TFeat* out_importance,
171 const TFeat* inp_features,
172 const TFeat* inp_neighbors_importance_sum,
173 const int64_t* inp_neighbors_row_splits,
174 const TIndex* neighbor_index,
175 const TKernelIndex* neighbors_kernel_index,
176 const TFeat* neighbor_importance,
177 const int64_t* neighbors_row_splits,
179 #define FN_PARAMETERS \
180 out_features, filter_dims, filter, num_out, out_importance, num_inp, \
181 inp_features, inp_neighbors_importance_sum, \
182 inp_neighbors_row_splits, neighbor_index, neighbors_kernel_index, \
183 neighbor_importance, neighbors_row_splits
185 #define CALL_TEMPLATE(NORMALIZE) \
186 if (NORMALIZE == normalize) \
187 _SparseConvTransposeComputeFeaturesCPU<TFeat, TOut, TIndex, \
188 TKernelIndex, NORMALIZE>( \
191 #define CALL_TEMPLATE2 \
192 CALL_TEMPLATE(true) \
198 #undef CALL_TEMPLATE2
void _SparseConvTransposeComputeFeaturesCPU(TOut *out_features, const std::vector< int > &filter_dims, const TFeat *filter, size_t num_out, const TFeat *out_importance, size_t num_inp, const TFeat *inp_features, const TFeat *inp_neighbors_importance_sum, const int64_t *inp_neighbors_row_splits, const TIndex *neighbor_index, const TKernelIndex *neighbors_kernel_index, const TFeat *neighbor_importance, const int64_t *neighbors_row_splits)
Definition: SparseConvTranspose.h:24
void SparseConvTransposeComputeFeaturesCPU(TOut *out_features, const std::vector< int > &filter_dims, const TFeat *filter, size_t num_out, const TFeat *out_importance, size_t num_inp, const TFeat *inp_features, const TFeat *inp_neighbors_importance_sum, const int64_t *inp_neighbors_row_splits, const TIndex *neighbor_index, const TKernelIndex *neighbors_kernel_index, const TFeat *neighbor_importance, const int64_t *neighbors_row_splits, bool normalize)
Definition: SparseConvTranspose.h:164
Definition: PinholeCameraIntrinsic.cpp:16