#include "cuda_runtime.h"
#include "cufft.h"
-#include "cuda/cuda_error_check.cuh"
+#include "cuda_error_check.hpp"
class ComplexMat {
public:
uint rows;
uint n_channels;
uint n_scales = 1;
- bool foreign_data = false;
- cudaStream_t stream = nullptr;
ComplexMat() : cols(0), rows(0), n_channels(0) {}
- ComplexMat(uint _rows, uint _cols, uint _n_channels, cudaStream_t _stream)
- : cols(_cols), rows(_rows), n_channels(_n_channels), stream(_stream)
+
+ ComplexMat(uint _rows, uint _cols, uint _n_channels, uint _n_scales = 1)
+ : cols(_cols), rows(_rows), n_channels(_n_channels * _n_scales), n_scales(_n_scales)
{
CudaSafeCall(cudaMalloc(&p_data, n_channels * cols * rows * sizeof(cufftComplex)));
}
- ComplexMat(uint _rows, uint _cols, uint _n_channels, uint _n_scales, cudaStream_t _stream)
- : cols(_cols), rows(_rows), n_channels(_n_channels), n_scales(_n_scales), stream(_stream)
+ ComplexMat(cv::Size size, uint _n_channels, uint _n_scales = 1)
+ : cols(size.width), rows(size.height), n_channels(_n_channels * _n_channels), n_scales(_n_scales)
{
CudaSafeCall(cudaMalloc(&p_data, n_channels * cols * rows * sizeof(cufftComplex)));
}
n_channels = other.n_channels;
n_scales = other.n_scales;
p_data = other.p_data;
- stream = other.stream;
other.p_data = nullptr;
}
~ComplexMat()
{
- if (p_data != nullptr && !foreign_data) {
+ if (p_data != nullptr) {
CudaSafeCall(cudaFree(p_data));
p_data = nullptr;
}
}
- void create(uint _rows, uint _cols, uint _n_channels, cudaStream_t _stream = nullptr)
+ void create(uint _rows, uint _cols, uint _n_channels)
{
rows = _rows;
cols = _cols;
n_channels = _n_channels;
- stream = _stream;
CudaSafeCall(cudaMalloc(&p_data, n_channels * cols * rows * sizeof(cufftComplex)));
}
- void create(uint _rows, uint _cols, uint _n_channels, uint _n_scales, cudaStream_t _stream = nullptr)
+ void create(uint _rows, uint _cols, uint _n_channels, uint _n_scales)
{
rows = _rows;
cols = _cols;
n_channels = _n_channels;
n_scales = _n_scales;
- stream = _stream;
CudaSafeCall(cudaMalloc(&p_data, n_channels * cols * rows * sizeof(cufftComplex)));
}
// cv::Mat API compatibility
- cv::Size size() { return cv::Size(cols, rows); }
- int channels() { return n_channels; }
- int channels() const { return n_channels; }
-
- void set_stream(cudaStream_t _stream)
- {
- stream = _stream;
- return;
- }
+ cv::Size size() const { return cv::Size(cols, rows); }
+ uint channels() const { return n_channels; }
void sqr_norm(DynMem &result) const;