Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add optional cuda guard for different device usage #175

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <ATen/cuda/CUDAContext.h>
#include <cuda.h>
#include <cuda_runtime.h>
#include <c10/cuda/CUDAGuard.h>


at::Tensor ms_deform_attn_cuda_forward(
Expand Down Expand Up @@ -55,6 +56,8 @@ at::Tensor ms_deform_attn_cuda_forward(
const int im2col_step_ = std::min(batch, im2col_step);

AT_ASSERTM(batch % im2col_step_ == 0, "batch(%d) must divide im2col_step(%d)", batch, im2col_step_);

const at::cuda::OptionalCUDAGuard device_guard(device_of(value));

auto output = at::zeros({batch, num_query, num_heads, channels}, value.options());

Expand All @@ -63,6 +66,7 @@ at::Tensor ms_deform_attn_cuda_forward(
auto per_value_size = spatial_size * num_heads * channels;
auto per_sample_loc_size = num_query * num_heads * num_levels * num_point * 2;
auto per_attn_weight_size = num_query * num_heads * num_levels * num_point;

for (int n = 0; n < batch/im2col_step_; ++n)
{
auto columns = output_n.select(0, n);
Expand Down Expand Up @@ -123,6 +127,8 @@ std::vector<at::Tensor> ms_deform_attn_cuda_backward(

AT_ASSERTM(batch % im2col_step_ == 0, "batch(%d) must divide im2col_step(%d)", batch, im2col_step_);

const at::cuda::OptionalCUDAGuard device_guard(device_of(value));

auto grad_value = at::zeros_like(value);
auto grad_sampling_loc = at::zeros_like(sampling_loc);
auto grad_attn_weight = at::zeros_like(attn_weight);
Expand Down