mirror of
https://github.com/facebookresearch/pytorch3d.git
synced 2026-09-07 15:55:52 +08:00
Check CUDA device calls in Pulsar renderer
Summary: Wrap Pulsar renderer `cudaGetDevice` and `cudaSetDevice` calls in `C10_CUDA_CHECK` so HIPified AMD builds do not fail on ignored `hipError_t` return values. Reviewed By: yiminglin-ai, bottler Differential Revision: D118286930 fbshipit-source-id: 796993ada47734bba0427572ddcde51c19fb47ba
This commit is contained in:
committed by
meta-codesync[bot]
parent
e73a7e7bfc
commit
0a7d4c1a17
@@ -11,6 +11,7 @@
|
|||||||
#include "./util.h"
|
#include "./util.h"
|
||||||
|
|
||||||
#ifdef WITH_CUDA
|
#ifdef WITH_CUDA
|
||||||
|
#include <c10/cuda/CUDAException.h>
|
||||||
#include <c10/cuda/CUDAGuard.h>
|
#include <c10/cuda/CUDAGuard.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -106,10 +107,10 @@ void Renderer::ensure_on_device(torch::Device device, bool /*non_blocking*/) {
|
|||||||
LOG_IF(INFO, PULSAR_LOG_INIT)
|
LOG_IF(INFO, PULSAR_LOG_INIT)
|
||||||
<< "Transferring render buffers between devices.";
|
<< "Transferring render buffers between devices.";
|
||||||
int prev_active;
|
int prev_active;
|
||||||
cudaGetDevice(&prev_active);
|
C10_CUDA_CHECK(cudaGetDevice(&prev_active));
|
||||||
if (this->device_type == c10::DeviceType::CUDA) {
|
if (this->device_type == c10::DeviceType::CUDA) {
|
||||||
LOG_IF(INFO, PULSAR_LOG_INIT) << " Destructing on CUDA.";
|
LOG_IF(INFO, PULSAR_LOG_INIT) << " Destructing on CUDA.";
|
||||||
cudaSetDevice(this->device_index);
|
C10_CUDA_CHECK(cudaSetDevice(this->device_index));
|
||||||
for (auto& nrend : this->renderer_vec) {
|
for (auto& nrend : this->renderer_vec) {
|
||||||
PRE::destruct<true>(&nrend);
|
PRE::destruct<true>(&nrend);
|
||||||
}
|
}
|
||||||
@@ -121,7 +122,7 @@ void Renderer::ensure_on_device(torch::Device device, bool /*non_blocking*/) {
|
|||||||
}
|
}
|
||||||
if (device.type() == c10::DeviceType::CUDA) {
|
if (device.type() == c10::DeviceType::CUDA) {
|
||||||
LOG_IF(INFO, PULSAR_LOG_INIT) << " Constructing on CUDA.";
|
LOG_IF(INFO, PULSAR_LOG_INIT) << " Constructing on CUDA.";
|
||||||
cudaSetDevice(device.index());
|
C10_CUDA_CHECK(cudaSetDevice(device.index()));
|
||||||
for (auto& nrend : this->renderer_vec) {
|
for (auto& nrend : this->renderer_vec) {
|
||||||
PRE::construct<true>(
|
PRE::construct<true>(
|
||||||
&nrend,
|
&nrend,
|
||||||
@@ -149,7 +150,7 @@ void Renderer::ensure_on_device(torch::Device device, bool /*non_blocking*/) {
|
|||||||
this->n_track());
|
this->n_track());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
cudaSetDevice(prev_active);
|
C10_CUDA_CHECK(cudaSetDevice(prev_active));
|
||||||
this->device_type = device.type();
|
this->device_type = device.type();
|
||||||
this->device_index = device.index();
|
this->device_index = device.index();
|
||||||
#else
|
#else
|
||||||
@@ -743,8 +744,8 @@ std::tuple<torch::Tensor, torch::Tensor> Renderer::forward(
|
|||||||
// moved to a CUDA device).
|
// moved to a CUDA device).
|
||||||
#ifdef WITH_CUDA
|
#ifdef WITH_CUDA
|
||||||
int prev_active;
|
int prev_active;
|
||||||
cudaGetDevice(&prev_active);
|
C10_CUDA_CHECK(cudaGetDevice(&prev_active));
|
||||||
cudaSetDevice(this->device_index);
|
C10_CUDA_CHECK(cudaSetDevice(this->device_index));
|
||||||
#ifdef PULSAR_TIMINGS_BATCHED_ENABLED
|
#ifdef PULSAR_TIMINGS_BATCHED_ENABLED
|
||||||
START_TIME_CU(batch_forward);
|
START_TIME_CU(batch_forward);
|
||||||
#endif
|
#endif
|
||||||
@@ -789,7 +790,7 @@ std::tuple<torch::Tensor, torch::Tensor> Renderer::forward(
|
|||||||
std::cout << "Forward render batched time per example: "
|
std::cout << "Forward render batched time per example: "
|
||||||
<< time_ms / static_cast<float>(batch_size) << "ms" << std::endl;
|
<< time_ms / static_cast<float>(batch_size) << "ms" << std::endl;
|
||||||
#endif
|
#endif
|
||||||
cudaSetDevice(prev_active);
|
C10_CUDA_CHECK(cudaSetDevice(prev_active));
|
||||||
#endif
|
#endif
|
||||||
} else {
|
} else {
|
||||||
#ifdef PULSAR_TIMINGS_BATCHED_ENABLED
|
#ifdef PULSAR_TIMINGS_BATCHED_ENABLED
|
||||||
@@ -1100,8 +1101,8 @@ Renderer::backward(
|
|||||||
// the renderer to a CUDA device if not built with CUDA.
|
// the renderer to a CUDA device if not built with CUDA.
|
||||||
#ifdef WITH_CUDA
|
#ifdef WITH_CUDA
|
||||||
int prev_active;
|
int prev_active;
|
||||||
cudaGetDevice(&prev_active);
|
C10_CUDA_CHECK(cudaGetDevice(&prev_active));
|
||||||
cudaSetDevice(this->device_index);
|
C10_CUDA_CHECK(cudaSetDevice(this->device_index));
|
||||||
#ifdef PULSAR_TIMINGS_BATCHED_ENABLED
|
#ifdef PULSAR_TIMINGS_BATCHED_ENABLED
|
||||||
START_TIME_CU(batch_backward);
|
START_TIME_CU(batch_backward);
|
||||||
#endif
|
#endif
|
||||||
@@ -1205,7 +1206,7 @@ Renderer::backward(
|
|||||||
at::cuda::getCurrentCUDAStream());
|
at::cuda::getCurrentCUDAStream());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
cudaSetDevice(prev_active);
|
C10_CUDA_CHECK(cudaSetDevice(prev_active));
|
||||||
#ifdef PULSAR_TIMINGS_BATCHED_ENABLED
|
#ifdef PULSAR_TIMINGS_BATCHED_ENABLED
|
||||||
STOP_TIME_CU(batch_backward);
|
STOP_TIME_CU(batch_backward);
|
||||||
float time_ms;
|
float time_ms;
|
||||||
|
|||||||
Reference in New Issue
Block a user