1 // This file is part of OpenCV project.
2 // It is subject to the license terms in the LICENSE file found in the top-level directory
3 // of this distribution and at http://opencv.org/license.html.
5 #ifndef OPENCV_DNN_SRC_CUDA_ARRAY_HPP
6 #define OPENCV_DNN_SRC_CUDA_ARRAY_HPP
8 #include <cuda_runtime.h>
13 #include <type_traits>
16 namespace cv { namespace dnn { namespace cuda4dnn { namespace csl { namespace device {
18 template <class T, std::size_t N>
21 using size_type = device::size_type;
22 using difference_type = std::ptrdiff_t;
23 using reference = typename std::add_lvalue_reference<value_type>::type;
24 using const_reference = typename std::add_lvalue_reference<typename std::add_const<value_type>::type>::type;
25 using pointer = typename std::add_pointer<value_type>::type;
26 using const_pointer = typename std::add_pointer<typename std::add_const<value_type>::type>::type;
27 using iterator = pointer;
28 using const_iterator = const_pointer;
29 using reverse_iterator = std::reverse_iterator<iterator>;
30 using const_reverse_iterator = std::reverse_iterator<const_iterator>;
32 __host__ __device__ bool empty() const noexcept { return N == 0; }
33 __host__ __device__ size_type size() const noexcept { return N; }
35 __host__ __device__ iterator begin() noexcept { return ptr; }
36 __host__ __device__ iterator end() noexcept { return ptr + N; }
37 __host__ __device__ const_iterator begin() const noexcept { return ptr; }
38 __host__ __device__ const_iterator end() const noexcept { return ptr + N; }
40 __host__ __device__ const_iterator cbegin() const noexcept { return ptr; }
41 __host__ __device__ const_iterator cend() const noexcept { return ptr + N; }
43 __host__ __device__ reverse_iterator rbegin() noexcept { return ptr + N; }
44 __host__ __device__ reverse_iterator rend() noexcept { return ptr; }
45 __host__ __device__ const_reverse_iterator rbegin() const noexcept { return ptr + N; }
46 __host__ __device__ const_reverse_iterator rend() const noexcept { return ptr; }
48 __host__ __device__ const_reverse_iterator crbegin() const noexcept { return ptr + N; }
49 __host__ __device__ const_reverse_iterator crend() const noexcept { return ptr; }
51 template <class InputItr>
52 __host__ void assign(InputItr first, InputItr last) {
53 std::copy(first, last, std::begin(ptr));
56 __host__ __device__ reference operator[](int idx) { return ptr[idx]; }
57 __host__ __device__ const_reference operator[](int idx) const { return ptr[idx]; }
59 __host__ __device__ reference front() { return ptr[0]; }
60 __host__ __device__ const_reference front() const { return ptr[0]; }
62 __host__ __device__ reference back() { return ptr[N - 1]; }
63 __host__ __device__ const_reference back() const { return ptr[N - 1]; }
65 __host__ __device__ pointer data() noexcept { return ptr; }
66 __host__ __device__ const_pointer data() const noexcept { return ptr; }
71 }}}}} /* namespace cv::dnn::cuda4dnn::csl::device */
73 #endif /* OPENCV_DNN_SRC_CUDA_ARRAY_HPP */