Skip to content

Commit 7d8b029

Browse files
bottlerfacebook-github-bot
authored andcommitted
increment_version for inplace ops
Summary: For safety checks, make inplace forward operations in cuda and c++ call increment_version. Reviewed By: davidsonic Differential Revision: D44302504 fbshipit-source-id: 6ff62251e352d6778cb54399e2e11459e16e77ba
1 parent 9437768 commit 7d8b029

File tree

4 files changed

+10
-0
lines changed

4 files changed

+10
-0
lines changed

pytorch3d/csrc/points_to_volumes/points_to_volumes.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
*/
88

99
#pragma once
10+
#include <torch/csrc/autograd/VariableTypeUtils.h>
1011
#include <torch/extension.h>
1112
#include <cstdio>
1213
#include <tuple>
@@ -96,6 +97,8 @@ inline void PointsToVolumesForward(
9697
point_weight,
9798
align_corners,
9899
splat);
100+
torch::autograd::increment_version(volume_features);
101+
torch::autograd::increment_version(volume_densities);
99102
return;
100103
#else
101104
AT_ERROR("Not compiled with GPU support.");

pytorch3d/csrc/points_to_volumes/points_to_volumes_cpu.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* LICENSE file in the root directory of this source tree.
77
*/
88

9+
#include <torch/csrc/autograd/VariableTypeUtils.h>
910
#include <torch/extension.h>
1011
#include <algorithm>
1112
#include <cmath>
@@ -148,6 +149,8 @@ void PointsToVolumesForwardCpu(
148149
}
149150
}
150151
}
152+
torch::autograd::increment_version(volume_features);
153+
torch::autograd::increment_version(volume_densities);
151154
}
152155

153156
// With nearest, the only smooth dependence is that volume features

pytorch3d/csrc/sample_pdf/sample_pdf.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
*/
88

99
#pragma once
10+
#include <torch/csrc/autograd/VariableTypeUtils.h>
1011
#include <torch/extension.h>
1112
#include <cstdio>
1213
#include <tuple>
@@ -63,6 +64,7 @@ inline void SamplePdf(
6364
#ifdef WITH_CUDA
6465
CHECK_CUDA(weights);
6566
CHECK_CONTIGUOUS_CUDA(outputs);
67+
torch::autograd::increment_version(outputs);
6668
SamplePdfCuda(bins, weights, outputs, eps);
6769
return;
6870
#else

pytorch3d/csrc/sample_pdf/sample_pdf_cpu.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* LICENSE file in the root directory of this source tree.
77
*/
88

9+
#include <torch/csrc/autograd/VariableTypeUtils.h>
910
#include <torch/extension.h>
1011
#include <algorithm>
1112
#include <thread>
@@ -137,4 +138,5 @@ void SamplePdfCpu(
137138
for (auto&& thread : threads) {
138139
thread.join();
139140
}
141+
torch::autograd::increment_version(outputs);
140142
}

0 commit comments

Comments
 (0)