#if defined(CUFFT) || defined(CUFFTW)
#include "cuda_runtime.h"
#ifdef CUFFT
-#include "cuda/cuda_error_check.cuh"
+#include "cuda_error_check.hpp"
#endif
#endif
#ifdef CUFFT
T *ptr_d = nullptr;
#endif
- size_t num_elem;
public:
- typedef T type;
+ typedef T value_type;
+ const size_t num_elem;
+
DynMem_(size_t num_elem) : num_elem(num_elem)
{
#ifdef CUFFT
ptr_h = new T[num_elem];
#endif
}
- DynMem_(DynMem_&& other) {
+ DynMem_(const DynMem_ &other) : DynMem_(other.num_elem)
+ {
+ memcpy(ptr_h, other.ptr_h, num_elem * sizeof(T));
+ }
+ DynMem_(DynMem_ &&other) : num_elem(other.num_elem)
+ {
ptr_h = other.ptr_h;
other.ptr_h = nullptr;
#ifdef CUFFT
}
~DynMem_()
{
-#ifdef CUFFT
- CudaSafeCall(cudaFreeHost(ptr_h));
-#else
- delete[] ptr_h;
-#endif
+ release();
}
T *hostMem() { return ptr_h; }
+ const T *hostMem() const { return ptr_h; }
#ifdef CUFFT
T *deviceMem() { return ptr_d; }
+ const T *deviceMem() const { return ptr_d; }
#endif
void operator=(DynMem_ &rhs) {
+ assert(num_elem == rhs.num_elem);
memcpy(ptr_h, rhs.ptr_h, num_elem * sizeof(T));
}
void operator=(DynMem_ &&rhs)
{
+ assert(num_elem == rhs.num_elem);
+ release();
ptr_h = rhs.ptr_h;
rhs.ptr_h = nullptr;
#ifdef CUFFT
#endif
}
T operator[](uint i) const { return ptr_h[i]; }
+private:
+ void release()
+ {
+#ifdef CUFFT
+ CudaSafeCall(cudaFreeHost(ptr_h));
+#else
+ delete[] ptr_h;
+#endif
+ }
};
typedef DynMem_<float> DynMem;
assert(int(idx) < size[0]);
return cv::Mat(size[1], size[2], cv::Mat::type(), ptr(idx));
}
+ const cv::Mat plane(uint idx) const {
+ assert(dims == 3);
+ assert(int(idx) < size[0]);
+ return cv::Mat(size[1], size[2], cv::Mat::type(), const_cast<uchar*>(ptr(idx)));
+ }
+
};
class MatFeats : public Mat3d
assert(int(feature) < size[1]);
return cv::Mat(size[2], size[3], cv::Mat::type(), ptr(scale, feature));
}
+ cv::Mat scale(uint scale) {
+ assert(dims == 4);
+ assert(int(scale) < size[0]);
+ return cv::Mat(3, std::vector<int>({size[1], size[2], size[3]}).data(), cv::Mat::type(), ptr(scale));
+ }
};
#endif // DYNMEM_HPP