/home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-roccv/checkouts/latest/include/kernels/device/bnd_box_device.hpp Source File

/home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-roccv/checkouts/latest/include/kernels/device/bnd_box_device.hpp Source File#

3 min read time

Applies to Linux

rocCV: /home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-roccv/checkouts/latest/include/kernels/device/bnd_box_device.hpp Source File
bnd_box_device.hpp
Go to the documentation of this file.
1 
23 #pragma once
24 
25 #include <hip/hip_runtime.h>
28 #include "operator_types.h"
29 
30 using namespace roccv;
31 
32 namespace Kernels {
33 namespace Device {
34 template <bool has_alpha, typename T, typename SrcWrapper, typename DstWrapper, typename BT = detail::BaseType<T>>
35 __global__ void bndbox_kernel(SrcWrapper input, DstWrapper output, Rect_t *rects,
36  size_t n_rects, int64_t batch, int64_t height,
37  int64_t width) {
38  // Working type for internal pixel format, which has 4 channels.
39  using WorkType = detail::MakeType<BT, 4>;
40 
41  const auto x_idx = threadIdx.x + blockIdx.x * blockDim.x;
42  const auto y_idx = threadIdx.y + blockIdx.y * blockDim.y;
43  const auto b_idx = threadIdx.z + blockIdx.z * blockDim.z;
44 
45  if (x_idx >= width || y_idx >= height || b_idx >= batch) {
46  return;
47  }
48 
49  WorkType shaded_pixel{0, 0, 0, 0};
50 
51  for (size_t i = 0; i < n_rects; i++) {
52  Rect_t curr_rect = rects[i];
53  if (curr_rect.batch <= b_idx)
54  shade_rectangle<WorkType>(curr_rect, x_idx, y_idx, &shaded_pixel);
55  }
56 
57  WorkType out_color =
58  MathVector::fill(input.at(b_idx, y_idx, x_idx, 0));
59  out_color.w = has_alpha ? out_color.w : (std::numeric_limits<BT>::max());
60 
61  if (shaded_pixel.w != 0) blend_single_color<WorkType>(out_color, shaded_pixel);
62 
63  MathVector::trunc(out_color,
64  &output.at(b_idx, y_idx, x_idx, 0));
65 }
66 }; // namespace Device
67 }; // namespace Kernels
__host__ static __device__ HIP_vector_type< T, 4 > fill(HIP_vector_type< T, rank > vec)
Definition: math_vector.hpp:107
__host__ static __device__ void trunc(HIP_vector_type< T, 4 > vec, HIP_vector_type< T, rank > *dst)
Definition: math_vector.hpp:136
__global__ void bndbox_kernel(SrcWrapper input, DstWrapper output, Rect_t *rects, size_t n_rects, int64_t batch, int64_t height, int64_t width)
Definition: bnd_box_device.hpp:35
Definition: non_max_suppression_helpers.hpp:26
MakeType_t< T, C >::type MakeType
Definition: type_traits.hpp:97
Definition: strided_data_wrap.hpp:33
Definition: operator_types.h:115
int64_t batch
Definition: operator_types.h:116