Skip to content

Commit

Permalink
increment_version for inplace ops
Browse files Browse the repository at this point in the history
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
  • Loading branch information
bottler authored and facebook-github-bot committed Mar 23, 2023
1 parent 9437768 commit 7d8b029
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 0 deletions.
3 changes: 3 additions & 0 deletions pytorch3d/csrc/points_to_volumes/points_to_volumes.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/

#pragma once
#include <torch/csrc/autograd/VariableTypeUtils.h>
#include <torch/extension.h>
#include <cstdio>
#include <tuple>
Expand Down Expand Up @@ -96,6 +97,8 @@ inline void PointsToVolumesForward(
point_weight,
align_corners,
splat);
torch::autograd::increment_version(volume_features);
torch::autograd::increment_version(volume_densities);
return;
#else
AT_ERROR("Not compiled with GPU support.");
Expand Down
3 changes: 3 additions & 0 deletions pytorch3d/csrc/points_to_volumes/points_to_volumes_cpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* LICENSE file in the root directory of this source tree.
*/

#include <torch/csrc/autograd/VariableTypeUtils.h>
#include <torch/extension.h>
#include <algorithm>
#include <cmath>
Expand Down Expand Up @@ -148,6 +149,8 @@ void PointsToVolumesForwardCpu(
}
}
}
torch::autograd::increment_version(volume_features);
torch::autograd::increment_version(volume_densities);
}

// With nearest, the only smooth dependence is that volume features
Expand Down
2 changes: 2 additions & 0 deletions pytorch3d/csrc/sample_pdf/sample_pdf.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/

#pragma once
#include <torch/csrc/autograd/VariableTypeUtils.h>
#include <torch/extension.h>
#include <cstdio>
#include <tuple>
Expand Down Expand Up @@ -63,6 +64,7 @@ inline void SamplePdf(
#ifdef WITH_CUDA
CHECK_CUDA(weights);
CHECK_CONTIGUOUS_CUDA(outputs);
torch::autograd::increment_version(outputs);
SamplePdfCuda(bins, weights, outputs, eps);
return;
#else
Expand Down
2 changes: 2 additions & 0 deletions pytorch3d/csrc/sample_pdf/sample_pdf_cpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* LICENSE file in the root directory of this source tree.
*/

#include <torch/csrc/autograd/VariableTypeUtils.h>
#include <torch/extension.h>
#include <algorithm>
#include <thread>
Expand Down Expand Up @@ -137,4 +138,5 @@ void SamplePdfCpu(
for (auto&& thread : threads) {
thread.join();
}
torch::autograd::increment_version(outputs);
}

0 comments on commit 7d8b029

Please sign in to comment.