nms.h 875 Bytes
Newer Older
1
#pragma once
2
#include "cpu/vision_cpu.h"
3
4

#ifdef WITH_CUDA
5
#include "cuda/vision_cuda.h"
6
#endif
7
8
9
#ifdef WITH_HIP
#include "hip/vision_cuda.h"
#endif
10
11
12
13

at::Tensor nms(
    const at::Tensor& dets,
    const at::Tensor& scores,
14
    const double iou_threshold) {
15
  if (dets.is_cuda()) {
16
#if defined(WITH_CUDA)
17
18
19
20
    if (dets.numel() == 0) {
      at::cuda::CUDAGuard device_guard(dets.device());
      return at::empty({0}, dets.options().dtype(at::kLong));
    }
21
    return nms_cuda(dets, scores, iou_threshold);
22
23
24
25
26
27
#elif defined(WITH_HIP)
    if (dets.numel() == 0) {
      at::cuda::HIPGuard device_guard(dets.device());
      return at::empty({0}, dets.options().dtype(at::kLong));
    }
    return nms_cuda(dets, scores, iou_threshold);
28
29
30
31
32
#else
    AT_ERROR("Not compiled with GPU support");
#endif
  }

33
  at::Tensor result = nms_cpu(dets, scores, iou_threshold);
34
35
  return result;
}