Spaces:
Running
Running
File size: 5,753 Bytes
b7eedf7 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 |
#include <torch/extension.h>
#include <vector>
// CUDA forward declarations
std::vector<torch::Tensor> projective_transform_cuda(
torch::Tensor poses,
torch::Tensor disps,
torch::Tensor intrinsics,
torch::Tensor ii,
torch::Tensor jj);
torch::Tensor depth_filter_cuda(
torch::Tensor poses,
torch::Tensor disps,
torch::Tensor intrinsics,
torch::Tensor ix,
torch::Tensor thresh);
torch::Tensor frame_distance_cuda(
torch::Tensor poses,
torch::Tensor disps,
torch::Tensor intrinsics,
torch::Tensor ii,
torch::Tensor jj,
const float beta);
std::vector<torch::Tensor> projmap_cuda(
torch::Tensor poses,
torch::Tensor disps,
torch::Tensor intrinsics,
torch::Tensor ii,
torch::Tensor jj);
torch::Tensor iproj_cuda(
torch::Tensor poses,
torch::Tensor disps,
torch::Tensor intrinsics);
std::vector<torch::Tensor> ba_cuda(
torch::Tensor poses,
torch::Tensor disps,
torch::Tensor intrinsics,
torch::Tensor disps_sens,
torch::Tensor targets,
torch::Tensor weights,
torch::Tensor eta,
torch::Tensor ii,
torch::Tensor jj,
const int t0,
const int t1,
const int iterations,
const float lm,
const float ep,
const bool motion_only);
std::vector<torch::Tensor> corr_index_cuda_forward(
torch::Tensor volume,
torch::Tensor coords,
int radius);
std::vector<torch::Tensor> corr_index_cuda_backward(
torch::Tensor volume,
torch::Tensor coords,
torch::Tensor corr_grad,
int radius);
std::vector<torch::Tensor> altcorr_cuda_forward(
torch::Tensor fmap1,
torch::Tensor fmap2,
torch::Tensor coords,
int radius);
std::vector<torch::Tensor> altcorr_cuda_backward(
torch::Tensor fmap1,
torch::Tensor fmap2,
torch::Tensor coords,
torch::Tensor corr_grad,
int radius);
#define CHECK_CONTIGUOUS(x) TORCH_CHECK(x.is_contiguous(), #x " must be contiguous")
#define CHECK_INPUT(x) CHECK_CONTIGUOUS(x)
std::vector<torch::Tensor> ba(
torch::Tensor poses,
torch::Tensor disps,
torch::Tensor intrinsics,
torch::Tensor disps_sens,
torch::Tensor targets,
torch::Tensor weights,
torch::Tensor eta,
torch::Tensor ii,
torch::Tensor jj,
const int t0,
const int t1,
const int iterations,
const float lm,
const float ep,
const bool motion_only) {
CHECK_INPUT(targets);
CHECK_INPUT(weights);
CHECK_INPUT(poses);
CHECK_INPUT(disps);
CHECK_INPUT(intrinsics);
CHECK_INPUT(disps_sens);
CHECK_INPUT(ii);
CHECK_INPUT(jj);
return ba_cuda(poses, disps, intrinsics, disps_sens, targets, weights,
eta, ii, jj, t0, t1, iterations, lm, ep, motion_only);
}
torch::Tensor frame_distance(
torch::Tensor poses,
torch::Tensor disps,
torch::Tensor intrinsics,
torch::Tensor ii,
torch::Tensor jj,
const float beta) {
CHECK_INPUT(poses);
CHECK_INPUT(disps);
CHECK_INPUT(intrinsics);
CHECK_INPUT(ii);
CHECK_INPUT(jj);
return frame_distance_cuda(poses, disps, intrinsics, ii, jj, beta);
}
std::vector<torch::Tensor> projmap(
torch::Tensor poses,
torch::Tensor disps,
torch::Tensor intrinsics,
torch::Tensor ii,
torch::Tensor jj) {
CHECK_INPUT(poses);
CHECK_INPUT(disps);
CHECK_INPUT(intrinsics);
CHECK_INPUT(ii);
CHECK_INPUT(jj);
return projmap_cuda(poses, disps, intrinsics, ii, jj);
}
torch::Tensor iproj(
torch::Tensor poses,
torch::Tensor disps,
torch::Tensor intrinsics) {
CHECK_INPUT(poses);
CHECK_INPUT(disps);
CHECK_INPUT(intrinsics);
return iproj_cuda(poses, disps, intrinsics);
}
// c++ python binding
std::vector<torch::Tensor> corr_index_forward(
torch::Tensor volume,
torch::Tensor coords,
int radius) {
CHECK_INPUT(volume);
CHECK_INPUT(coords);
return corr_index_cuda_forward(volume, coords, radius);
}
std::vector<torch::Tensor> corr_index_backward(
torch::Tensor volume,
torch::Tensor coords,
torch::Tensor corr_grad,
int radius) {
CHECK_INPUT(volume);
CHECK_INPUT(coords);
CHECK_INPUT(corr_grad);
auto volume_grad = corr_index_cuda_backward(volume, coords, corr_grad, radius);
return {volume_grad};
}
std::vector<torch::Tensor> altcorr_forward(
torch::Tensor fmap1,
torch::Tensor fmap2,
torch::Tensor coords,
int radius) {
CHECK_INPUT(fmap1);
CHECK_INPUT(fmap2);
CHECK_INPUT(coords);
return altcorr_cuda_forward(fmap1, fmap2, coords, radius);
}
std::vector<torch::Tensor> altcorr_backward(
torch::Tensor fmap1,
torch::Tensor fmap2,
torch::Tensor coords,
torch::Tensor corr_grad,
int radius) {
CHECK_INPUT(fmap1);
CHECK_INPUT(fmap2);
CHECK_INPUT(coords);
CHECK_INPUT(corr_grad);
return altcorr_cuda_backward(fmap1, fmap2, coords, corr_grad, radius);
}
torch::Tensor depth_filter(
torch::Tensor poses,
torch::Tensor disps,
torch::Tensor intrinsics,
torch::Tensor ix,
torch::Tensor thresh) {
CHECK_INPUT(poses);
CHECK_INPUT(disps);
CHECK_INPUT(intrinsics);
CHECK_INPUT(ix);
CHECK_INPUT(thresh);
return depth_filter_cuda(poses, disps, intrinsics, ix, thresh);
}
PYBIND11_MODULE(TORCH_EXTENSION_NAME, m) {
// bundle adjustment kernels
m.def("ba", &ba, "bundle adjustment");
m.def("frame_distance", &frame_distance, "frame_distance");
m.def("projmap", &projmap, "projmap");
m.def("depth_filter", &depth_filter, "depth_filter");
m.def("iproj", &iproj, "back projection");
// correlation volume kernels
m.def("altcorr_forward", &altcorr_forward, "ALTCORR forward");
m.def("altcorr_backward", &altcorr_backward, "ALTCORR backward");
m.def("corr_index_forward", &corr_index_forward, "INDEX forward");
m.def("corr_index_backward", &corr_index_backward, "INDEX backward");
} |