2019-01-16 19:40:08 +00:00
|
|
|
#include "cuAmpcorChunk.h"
|
|
|
|
#include "cuAmpcorUtil.h"
|
|
|
|
|
|
|
|
/**
|
2019-11-20 00:59:49 +00:00
|
|
|
* Run ampcor process for a batch of images (a chunk)
|
2019-01-16 19:40:08 +00:00
|
|
|
* @param[in] idxDown_ index oIDIVUP(i,j) ((i+j-1)/j)f the chunk along Down/Azimuth direction
|
|
|
|
* @param[in] idxAcross_ index of the chunk along Across/Range direction
|
2019-11-20 00:59:49 +00:00
|
|
|
*/
|
2019-01-16 19:40:08 +00:00
|
|
|
void cuAmpcorChunk::run(int idxDown_, int idxAcross_)
|
|
|
|
{
|
|
|
|
// set chunk index
|
|
|
|
setIndex(idxDown_, idxAcross_);
|
2019-11-20 00:59:49 +00:00
|
|
|
|
|
|
|
// load master image chunk
|
|
|
|
loadMasterChunk();
|
|
|
|
|
2019-01-16 19:40:08 +00:00
|
|
|
//std::cout << "load master chunk ok\n";
|
2019-11-20 00:59:49 +00:00
|
|
|
|
2019-01-16 19:40:08 +00:00
|
|
|
cuArraysAbs(c_masterBatchRaw, r_masterBatchRaw, stream);
|
|
|
|
cuArraysSubtractMean(r_masterBatchRaw, stream);
|
|
|
|
// load slave image chunk
|
|
|
|
loadSlaveChunk();
|
|
|
|
cuArraysAbs(c_slaveBatchRaw, r_slaveBatchRaw, stream);
|
2019-11-20 00:59:49 +00:00
|
|
|
|
2019-01-16 19:40:08 +00:00
|
|
|
//std::cout << "load slave chunk ok\n";
|
2019-11-20 00:59:49 +00:00
|
|
|
|
|
|
|
|
2019-01-16 19:40:08 +00:00
|
|
|
//cross correlation for none-oversampled data
|
|
|
|
if(param->algorithm == 0) {
|
|
|
|
cuCorrFreqDomain->execute(r_masterBatchRaw, r_slaveBatchRaw, r_corrBatchRaw);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
cuCorrTimeDomain(r_masterBatchRaw, r_slaveBatchRaw, r_corrBatchRaw, stream); //time domain cross correlation
|
2019-11-20 00:59:49 +00:00
|
|
|
}
|
2019-01-16 19:40:08 +00:00
|
|
|
cuCorrNormalize(r_masterBatchRaw, r_slaveBatchRaw, r_corrBatchRaw, stream);
|
|
|
|
|
|
|
|
|
2019-11-20 00:59:49 +00:00
|
|
|
// find the maximum location of none-oversampled correlation
|
|
|
|
// 41 x 41, if halfsearchrange=20
|
|
|
|
//cuArraysMaxloc2D(r_corrBatchRaw, offsetInit, stream);
|
|
|
|
cuArraysMaxloc2D(r_corrBatchRaw, offsetInit, r_maxval, stream);
|
2019-01-16 19:40:08 +00:00
|
|
|
|
2019-11-20 00:59:49 +00:00
|
|
|
offsetInit->outputToFile("offsetInit1", stream);
|
2019-01-16 19:40:08 +00:00
|
|
|
|
2019-11-20 00:59:49 +00:00
|
|
|
// Estimation of statistics
|
|
|
|
// Author: Minyan Zhong
|
|
|
|
// Extraction of correlation surface around the peak
|
|
|
|
cuArraysCopyExtractCorr(r_corrBatchRaw, r_corrBatchRawZoomIn, i_corrBatchZoomInValid, offsetInit, stream);
|
2019-01-16 19:40:08 +00:00
|
|
|
|
2019-11-20 00:59:49 +00:00
|
|
|
cudaDeviceSynchronize();
|
|
|
|
|
|
|
|
// debug: output the intermediate results
|
|
|
|
r_maxval->outputToFile("r_maxval",stream);
|
|
|
|
r_corrBatchRaw->outputToFile("r_corrBatchRaw",stream);
|
|
|
|
r_corrBatchRawZoomIn->outputToFile("r_corrBatchRawZoomIn",stream);
|
|
|
|
i_corrBatchZoomInValid->outputToFile("i_corrBatchZoomInValid",stream);
|
|
|
|
|
|
|
|
// Summation of correlation and data point values
|
|
|
|
cuArraysSumCorr(r_corrBatchRawZoomIn, i_corrBatchZoomInValid, r_corrBatchSum, i_corrBatchValidCount, stream);
|
|
|
|
|
|
|
|
// SNR
|
|
|
|
cuEstimateSnr(r_corrBatchSum, i_corrBatchValidCount, r_maxval, r_snrValue, stream);
|
|
|
|
|
|
|
|
// Variance
|
|
|
|
// cuEstimateVariance(r_corrBatchRaw, offsetInit, r_maxval, r_covValue, stream);
|
|
|
|
|
|
|
|
// Using the approximate estimation to adjust slave image (half search window size becomes only 4 pixels)
|
2019-01-16 19:40:08 +00:00
|
|
|
//offsetInit->debuginfo(stream);
|
|
|
|
// determine the starting pixel to extract slave images around the max location
|
2019-11-20 00:59:49 +00:00
|
|
|
cuDetermineSlaveExtractOffset(offsetInit,
|
2019-01-16 19:40:08 +00:00
|
|
|
param->halfSearchRangeDownRaw, // old range
|
2019-11-20 00:59:49 +00:00
|
|
|
param->halfSearchRangeAcrossRaw,
|
2019-01-16 19:40:08 +00:00
|
|
|
param->halfZoomWindowSizeRaw, // new range
|
|
|
|
param->halfZoomWindowSizeRaw,
|
|
|
|
stream);
|
|
|
|
//offsetInit->debuginfo(stream);
|
|
|
|
// oversample master
|
|
|
|
// (deramping now included in oversampler)
|
|
|
|
masterBatchOverSampler->execute(c_masterBatchRaw, c_masterBatchOverSampled, param->derampMethod);
|
|
|
|
cuArraysAbs(c_masterBatchOverSampled, r_masterBatchOverSampled, stream);
|
|
|
|
cuArraysSubtractMean(r_masterBatchOverSampled, stream);
|
2019-11-20 00:59:49 +00:00
|
|
|
|
2019-01-16 19:40:08 +00:00
|
|
|
// extract slave and oversample
|
|
|
|
cuArraysCopyExtract(c_slaveBatchRaw, c_slaveBatchZoomIn, offsetInit, stream);
|
|
|
|
slaveBatchOverSampler->execute(c_slaveBatchZoomIn, c_slaveBatchOverSampled, param->derampMethod);
|
|
|
|
cuArraysAbs(c_slaveBatchOverSampled, r_slaveBatchOverSampled, stream);
|
2019-11-20 00:59:49 +00:00
|
|
|
|
2019-01-16 19:40:08 +00:00
|
|
|
// correlate oversampled images
|
|
|
|
if(param->algorithm == 0) {
|
|
|
|
cuCorrFreqDomain_OverSampled->execute(r_masterBatchOverSampled, r_slaveBatchOverSampled, r_corrBatchZoomIn);
|
|
|
|
}
|
|
|
|
else {
|
2019-11-20 00:59:49 +00:00
|
|
|
cuCorrTimeDomain(r_masterBatchOverSampled, r_slaveBatchOverSampled, r_corrBatchZoomIn, stream);
|
|
|
|
}
|
2019-01-16 19:40:08 +00:00
|
|
|
cuCorrNormalize(r_masterBatchOverSampled, r_slaveBatchOverSampled, r_corrBatchZoomIn, stream);
|
2019-11-20 00:59:49 +00:00
|
|
|
|
2019-01-16 19:40:08 +00:00
|
|
|
//std::cout << "debug correlation oversample\n";
|
|
|
|
//std::cout << r_masterBatchOverSampled->height << " " << r_masterBatchOverSampled->width << "\n";
|
|
|
|
//std::cout << r_slaveBatchOverSampled->height << " " << r_slaveBatchOverSampled->width << "\n";
|
|
|
|
//std::cout << r_corrBatchZoomIn->height << " " << r_corrBatchZoomIn->width << "\n";
|
2019-11-20 00:59:49 +00:00
|
|
|
|
|
|
|
// oversample the correlation surface
|
2019-01-16 19:40:08 +00:00
|
|
|
cuArraysCopyExtract(r_corrBatchZoomIn, r_corrBatchZoomInAdjust, make_int2(0,0), stream);
|
2019-11-20 00:59:49 +00:00
|
|
|
|
2019-01-16 19:40:08 +00:00
|
|
|
//std::cout << "debug oversampling " << r_corrBatchZoomInAdjust << " " << r_corrBatchZoomInOverSampled << "\n";
|
2019-11-20 00:59:49 +00:00
|
|
|
|
2019-01-16 19:40:08 +00:00
|
|
|
if(param->oversamplingMethod) {
|
|
|
|
corrSincOverSampler->execute(r_corrBatchZoomInAdjust, r_corrBatchZoomInOverSampled);
|
|
|
|
}
|
|
|
|
else {
|
2019-11-20 00:59:49 +00:00
|
|
|
corrOverSampler->execute(r_corrBatchZoomInAdjust, r_corrBatchZoomInOverSampled);
|
2019-01-16 19:40:08 +00:00
|
|
|
}
|
2019-11-20 00:59:49 +00:00
|
|
|
|
2019-01-16 19:40:08 +00:00
|
|
|
//find the max again
|
2019-11-20 00:59:49 +00:00
|
|
|
|
2019-01-16 19:40:08 +00:00
|
|
|
cuArraysMaxloc2D(r_corrBatchZoomInOverSampled, offsetZoomIn, corrMaxValue, stream);
|
2019-11-20 00:59:49 +00:00
|
|
|
|
|
|
|
// determine the final offset from non-oversampled (pixel) and oversampled (sub-pixel)
|
|
|
|
cuSubPixelOffset(offsetInit, offsetZoomIn, offsetFinal,
|
|
|
|
param->oversamplingFactor, param->rawDataOversamplingFactor,
|
2019-01-16 19:40:08 +00:00
|
|
|
param->halfSearchRangeDownRaw, param->halfSearchRangeAcrossRaw,
|
|
|
|
param->halfZoomWindowSizeRaw, param->halfZoomWindowSizeRaw,
|
|
|
|
stream);
|
|
|
|
//offsetInit->debuginfo(stream);
|
|
|
|
//offsetZoomIn->debuginfo(stream);
|
2019-11-20 00:59:49 +00:00
|
|
|
//offsetFinal->debuginfo(stream);
|
|
|
|
|
|
|
|
// Do insertion.
|
|
|
|
// Offsetfields.
|
2019-01-16 19:40:08 +00:00
|
|
|
cuArraysCopyInsert(offsetFinal, offsetImage, idxDown_*param->numberWindowDownInChunk, idxAcross_*param->numberWindowAcrossInChunk,stream);
|
|
|
|
|
2019-11-20 00:59:49 +00:00
|
|
|
// Debugging matrix.
|
|
|
|
cuArraysCopyInsert(r_corrBatchSum, floatImage1, idxDown_*param->numberWindowDownInChunk, idxAcross_*param->numberWindowAcrossInChunk,stream);
|
|
|
|
cuArraysCopyInsert(i_corrBatchValidCount, intImage1, idxDown_*param->numberWindowDownInChunk, idxAcross_*param->numberWindowAcrossInChunk,stream);
|
2019-01-16 19:40:08 +00:00
|
|
|
|
2019-11-20 00:59:49 +00:00
|
|
|
// Old: save max correlation coefficients.
|
|
|
|
//cuArraysCopyInsert(corrMaxValue, snrImage, idxDown_*param->numberWindowDownInChunk, idxAcross_*param->numberWindowAcrossInChunk,stream);
|
|
|
|
// New: save SNR
|
|
|
|
cuArraysCopyInsert(r_snrValue, snrImage, idxDown_*param->numberWindowDownInChunk, idxAcross_*param->numberWindowAcrossInChunk,stream);
|
|
|
|
|
|
|
|
// Variance.
|
|
|
|
cuArraysCopyInsert(r_covValue, covImage, idxDown_*param->numberWindowDownInChunk, idxAcross_*param->numberWindowAcrossInChunk,stream);
|
2019-01-16 19:40:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void cuAmpcorChunk::setIndex(int idxDown_, int idxAcross_)
|
|
|
|
{
|
|
|
|
idxChunkDown = idxDown_;
|
|
|
|
idxChunkAcross = idxAcross_;
|
|
|
|
idxChunk = idxChunkAcross + idxChunkDown*param->numberChunkAcross;
|
2019-11-20 00:59:49 +00:00
|
|
|
|
2019-01-16 19:40:08 +00:00
|
|
|
if(idxChunkDown == param->numberChunkDown -1) {
|
|
|
|
nWindowsDown = param->numberWindowDown - param->numberWindowDownInChunk*(param->numberChunkDown -1);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
nWindowsDown = param->numberWindowDownInChunk;
|
|
|
|
}
|
2019-11-20 00:59:49 +00:00
|
|
|
|
2019-01-16 19:40:08 +00:00
|
|
|
if(idxChunkAcross == param->numberChunkAcross -1) {
|
|
|
|
nWindowsAcross = param->numberWindowAcross - param->numberWindowAcrossInChunk*(param->numberChunkAcross -1);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
nWindowsAcross = param->numberWindowAcrossInChunk;
|
|
|
|
}
|
|
|
|
//std::cout << "DEBUG setIndex" << idxChunk << " " << nWindowsDown << " " << nWindowsAcross << "\n";
|
2019-11-20 00:59:49 +00:00
|
|
|
|
2019-01-16 19:40:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// obtain the starting pixels for each chip
|
2019-11-20 00:59:49 +00:00
|
|
|
/// @param[in] oStartPixel
|
2019-01-16 19:40:08 +00:00
|
|
|
///
|
|
|
|
void cuAmpcorChunk::getRelativeOffset(int *rStartPixel, const int *oStartPixel, int diff)
|
|
|
|
{
|
|
|
|
for(int i=0; i<param->numberWindowDownInChunk; ++i) {
|
|
|
|
int iDown = i;
|
2019-11-20 00:59:49 +00:00
|
|
|
if(i>=nWindowsDown) iDown = nWindowsDown-1;
|
2019-01-16 19:40:08 +00:00
|
|
|
for(int j=0; j<param->numberWindowAcrossInChunk; ++j){
|
|
|
|
int iAcross = j;
|
2019-11-20 00:59:49 +00:00
|
|
|
if(j>=nWindowsAcross) iAcross = nWindowsAcross-1;
|
2019-01-16 19:40:08 +00:00
|
|
|
int idxInChunk = iDown*param->numberWindowAcrossInChunk+iAcross;
|
|
|
|
int idxInAll = (iDown+idxChunkDown*param->numberWindowDownInChunk)*param->numberWindowAcross
|
|
|
|
+ idxChunkAcross*param->numberWindowAcrossInChunk+iAcross;
|
|
|
|
rStartPixel[idxInChunk] = oStartPixel[idxInAll] - diff;
|
|
|
|
//fprintf(stderr, "relative offset %d %d %d %d\n", i, j, rStartPixel[idxInChunk], diff);
|
|
|
|
}
|
|
|
|
}
|
2019-11-20 00:59:49 +00:00
|
|
|
}
|
2019-01-16 19:40:08 +00:00
|
|
|
|
|
|
|
void cuAmpcorChunk::loadMasterChunk()
|
|
|
|
{
|
2019-11-20 00:59:49 +00:00
|
|
|
|
|
|
|
// we first load the whole chunk of image from cpu to a gpu buffer c(r)_masterChunkRaw
|
|
|
|
// then copy to a batch of windows with (nImages, height, width) (leading dimension on the right)
|
|
|
|
|
|
|
|
// get the chunk size to be loaded to gpu
|
|
|
|
int startD = param->masterChunkStartPixelDown[idxChunk]; //start pixel down (along height)
|
|
|
|
int startA = param->masterChunkStartPixelAcross[idxChunk]; // start pixel across (along width)
|
|
|
|
int height = param->masterChunkHeight[idxChunk]; // number of pixels along height
|
|
|
|
int width = param->masterChunkWidth[idxChunk]; // number of pixels along width
|
|
|
|
|
|
|
|
//use cpu to compute the starting positions for each window
|
2019-01-16 19:40:08 +00:00
|
|
|
getRelativeOffset(ChunkOffsetDown->hostData, param->masterStartPixelDown, param->masterChunkStartPixelDown[idxChunk]);
|
2019-11-20 00:59:49 +00:00
|
|
|
// copy the positions to gpu
|
2019-01-16 19:40:08 +00:00
|
|
|
ChunkOffsetDown->copyToDevice(stream);
|
2019-11-20 00:59:49 +00:00
|
|
|
// same for the across direction
|
2019-01-16 19:40:08 +00:00
|
|
|
getRelativeOffset(ChunkOffsetAcross->hostData, param->masterStartPixelAcross, param->masterChunkStartPixelAcross[idxChunk]);
|
|
|
|
ChunkOffsetAcross->copyToDevice(stream);
|
2019-11-20 00:59:49 +00:00
|
|
|
|
|
|
|
// check whether the image is complex (e.g., SLC) or real( e.g. TIFF)
|
|
|
|
if(masterImage->isComplex())
|
|
|
|
{
|
|
|
|
// allocate a gpu buffer to load data from cpu/file
|
|
|
|
// try allocate/deallocate the buffer on the fly to save gpu memory 07/09/19
|
|
|
|
c_masterChunkRaw = new cuArrays<float2> (param->maxMasterChunkHeight, param->maxMasterChunkWidth);
|
|
|
|
c_masterChunkRaw->allocate();
|
|
|
|
|
|
|
|
// load the data from cpu
|
|
|
|
masterImage->loadToDevice((void *)c_masterChunkRaw->devData, startD, startA, height, width, stream);
|
|
|
|
//std::cout << "debug load master: " << startD << " " << startA << " " << height << " " << width << "\n";
|
|
|
|
|
|
|
|
//copy the chunk to a batch format (nImages, height, width)
|
|
|
|
// if derampMethod = 0 (no deramp), take amplitudes; otherwise, copy complex data
|
|
|
|
if(param->derampMethod == 0) {
|
|
|
|
cuArraysCopyToBatchAbsWithOffset(c_masterChunkRaw, param->masterChunkWidth[idxChunk],
|
|
|
|
c_masterBatchRaw, ChunkOffsetDown->devData, ChunkOffsetAcross->devData, stream);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
cuArraysCopyToBatchWithOffset(c_masterChunkRaw, param->masterChunkWidth[idxChunk],
|
|
|
|
c_masterBatchRaw, ChunkOffsetDown->devData, ChunkOffsetAcross->devData, stream);
|
|
|
|
}
|
|
|
|
// deallocate the gpu buffer
|
|
|
|
delete c_masterChunkRaw;
|
2019-01-16 19:40:08 +00:00
|
|
|
}
|
2019-11-20 00:59:49 +00:00
|
|
|
// if the image is real
|
2019-01-16 19:40:08 +00:00
|
|
|
else {
|
2019-11-20 00:59:49 +00:00
|
|
|
r_masterChunkRaw = new cuArrays<float> (param->maxMasterChunkHeight, param->maxMasterChunkWidth);
|
|
|
|
r_masterChunkRaw->allocate();
|
|
|
|
|
|
|
|
// load the data from cpu
|
|
|
|
masterImage->loadToDevice((void *)r_masterChunkRaw->devData, startD, startA, height, width, stream);
|
|
|
|
|
|
|
|
// copy the chunk (real) to a batch format (complex)
|
|
|
|
cuArraysCopyToBatchWithOffsetR2C(r_masterChunkRaw, param->masterChunkWidth[idxChunk],
|
|
|
|
c_masterBatchRaw, ChunkOffsetDown->devData, ChunkOffsetAcross->devData, stream);
|
|
|
|
// deallocate the gpu buffer
|
|
|
|
delete r_masterChunkRaw;
|
2019-01-16 19:40:08 +00:00
|
|
|
}
|
2019-11-20 00:59:49 +00:00
|
|
|
|
|
|
|
|
2019-01-16 19:40:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void cuAmpcorChunk::loadSlaveChunk()
|
|
|
|
{
|
2019-11-20 00:59:49 +00:00
|
|
|
|
2019-01-16 19:40:08 +00:00
|
|
|
//copy to a batch format (nImages, height, width)
|
|
|
|
getRelativeOffset(ChunkOffsetDown->hostData, param->slaveStartPixelDown, param->slaveChunkStartPixelDown[idxChunk]);
|
|
|
|
ChunkOffsetDown->copyToDevice(stream);
|
|
|
|
getRelativeOffset(ChunkOffsetAcross->hostData, param->slaveStartPixelAcross, param->slaveChunkStartPixelAcross[idxChunk]);
|
|
|
|
ChunkOffsetAcross->copyToDevice(stream);
|
2019-11-20 00:59:49 +00:00
|
|
|
|
|
|
|
if(slaveImage->isComplex())
|
2019-01-16 19:40:08 +00:00
|
|
|
{
|
2019-11-20 00:59:49 +00:00
|
|
|
c_slaveChunkRaw = new cuArrays<float2> (param->maxSlaveChunkHeight, param->maxSlaveChunkWidth);
|
|
|
|
c_slaveChunkRaw->allocate();
|
|
|
|
|
|
|
|
//load a chunk from mmap to gpu
|
|
|
|
slaveImage->loadToDevice(c_slaveChunkRaw->devData,
|
|
|
|
param->slaveChunkStartPixelDown[idxChunk],
|
|
|
|
param->slaveChunkStartPixelAcross[idxChunk],
|
|
|
|
param->slaveChunkHeight[idxChunk],
|
|
|
|
param->slaveChunkWidth[idxChunk],
|
|
|
|
stream);
|
|
|
|
|
|
|
|
if(param->derampMethod == 0) {
|
|
|
|
cuArraysCopyToBatchAbsWithOffset(c_slaveChunkRaw, param->slaveChunkWidth[idxChunk],
|
|
|
|
c_slaveBatchRaw, ChunkOffsetDown->devData, ChunkOffsetAcross->devData, stream);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
cuArraysCopyToBatchWithOffset(c_slaveChunkRaw, param->slaveChunkWidth[idxChunk],
|
|
|
|
c_slaveBatchRaw, ChunkOffsetDown->devData, ChunkOffsetAcross->devData, stream);
|
|
|
|
}
|
|
|
|
delete c_slaveChunkRaw;
|
|
|
|
}
|
|
|
|
else { //real image
|
|
|
|
//allocate the gpu buffer
|
|
|
|
r_slaveChunkRaw = new cuArrays<float> (param->maxSlaveChunkHeight, param->maxSlaveChunkWidth);
|
|
|
|
r_slaveChunkRaw->allocate();
|
|
|
|
|
|
|
|
//load a chunk from mmap to gpu
|
|
|
|
slaveImage->loadToDevice(r_slaveChunkRaw->devData,
|
|
|
|
param->slaveChunkStartPixelDown[idxChunk],
|
|
|
|
param->slaveChunkStartPixelAcross[idxChunk],
|
|
|
|
param->slaveChunkHeight[idxChunk],
|
|
|
|
param->slaveChunkWidth[idxChunk],
|
|
|
|
stream);
|
|
|
|
|
|
|
|
// convert to the batch format
|
|
|
|
cuArraysCopyToBatchWithOffsetR2C(r_slaveChunkRaw, param->slaveChunkWidth[idxChunk],
|
|
|
|
c_slaveBatchRaw, ChunkOffsetDown->devData, ChunkOffsetAcross->devData, stream);
|
|
|
|
delete r_slaveChunkRaw;
|
|
|
|
}
|
2019-01-16 19:40:08 +00:00
|
|
|
}
|
|
|
|
|
2019-11-20 00:59:49 +00:00
|
|
|
cuAmpcorChunk::cuAmpcorChunk(cuAmpcorParameter *param_, GDALImage *master_, GDALImage *slave_,
|
|
|
|
cuArrays<float2> *offsetImage_, cuArrays<float> *snrImage_, cuArrays<float3> *covImage_, cuArrays<int> *intImage1_, cuArrays<float> *floatImage1_, cudaStream_t stream_)
|
|
|
|
|
2019-01-16 19:40:08 +00:00
|
|
|
{
|
|
|
|
param = param_;
|
|
|
|
masterImage = master_;
|
2019-11-20 00:59:49 +00:00
|
|
|
slaveImage = slave_;
|
2019-01-16 19:40:08 +00:00
|
|
|
offsetImage = offsetImage_;
|
|
|
|
snrImage = snrImage_;
|
2019-11-20 00:59:49 +00:00
|
|
|
covImage = covImage_;
|
|
|
|
|
|
|
|
intImage1 = intImage1_;
|
|
|
|
floatImage1 = floatImage1_;
|
|
|
|
|
2019-01-16 19:40:08 +00:00
|
|
|
stream = stream_;
|
2019-11-20 00:59:49 +00:00
|
|
|
|
|
|
|
// std::cout << "debug Chunk creator " << param->maxMasterChunkHeight << " " << param->maxMasterChunkWidth << "\n";
|
|
|
|
// try allocate/deallocate on the fly to save gpu memory 07/09/19
|
|
|
|
// c_masterChunkRaw = new cuArrays<float2> (param->maxMasterChunkHeight, param->maxMasterChunkWidth);
|
|
|
|
// c_masterChunkRaw->allocate();
|
|
|
|
|
|
|
|
// c_slaveChunkRaw = new cuArrays<float2> (param->maxSlaveChunkHeight, param->maxSlaveChunkWidth);
|
|
|
|
// c_slaveChunkRaw->allocate();
|
|
|
|
|
2019-01-16 19:40:08 +00:00
|
|
|
ChunkOffsetDown = new cuArrays<int> (param->numberWindowDownInChunk, param->numberWindowAcrossInChunk);
|
|
|
|
ChunkOffsetDown->allocate();
|
|
|
|
ChunkOffsetDown->allocateHost();
|
|
|
|
ChunkOffsetAcross = new cuArrays<int> (param->numberWindowDownInChunk, param->numberWindowAcrossInChunk);
|
|
|
|
ChunkOffsetAcross->allocate();
|
|
|
|
ChunkOffsetAcross->allocateHost();
|
2019-11-20 00:59:49 +00:00
|
|
|
|
2019-01-16 19:40:08 +00:00
|
|
|
c_masterBatchRaw = new cuArrays<float2> (
|
|
|
|
param->windowSizeHeightRaw, param->windowSizeWidthRaw,
|
|
|
|
param->numberWindowDownInChunk, param->numberWindowAcrossInChunk);
|
|
|
|
c_masterBatchRaw->allocate();
|
2019-11-20 00:59:49 +00:00
|
|
|
|
2019-01-16 19:40:08 +00:00
|
|
|
c_slaveBatchRaw = new cuArrays<float2> (
|
|
|
|
param->searchWindowSizeHeightRaw, param->searchWindowSizeWidthRaw,
|
|
|
|
param->numberWindowDownInChunk, param->numberWindowAcrossInChunk);
|
|
|
|
c_slaveBatchRaw->allocate();
|
2019-11-20 00:59:49 +00:00
|
|
|
|
2019-01-16 19:40:08 +00:00
|
|
|
r_masterBatchRaw = new cuArrays<float> (
|
|
|
|
param->windowSizeHeightRaw, param->windowSizeWidthRaw,
|
|
|
|
param->numberWindowDownInChunk, param->numberWindowAcrossInChunk);
|
|
|
|
r_masterBatchRaw->allocate();
|
2019-11-20 00:59:49 +00:00
|
|
|
|
2019-01-16 19:40:08 +00:00
|
|
|
r_slaveBatchRaw = new cuArrays<float> (
|
|
|
|
param->searchWindowSizeHeightRaw, param->searchWindowSizeWidthRaw,
|
|
|
|
param->numberWindowDownInChunk, param->numberWindowAcrossInChunk);
|
|
|
|
r_slaveBatchRaw->allocate();
|
2019-11-20 00:59:49 +00:00
|
|
|
|
2019-01-16 19:40:08 +00:00
|
|
|
c_slaveBatchZoomIn = new cuArrays<float2> (
|
|
|
|
param->searchWindowSizeHeightRawZoomIn, param->searchWindowSizeWidthRawZoomIn,
|
|
|
|
param->numberWindowDownInChunk, param->numberWindowAcrossInChunk);
|
|
|
|
c_slaveBatchZoomIn->allocate();
|
2019-11-20 00:59:49 +00:00
|
|
|
|
2019-01-16 19:40:08 +00:00
|
|
|
c_masterBatchOverSampled = new cuArrays<float2> (
|
|
|
|
param->windowSizeHeight, param->windowSizeWidth,
|
|
|
|
param->numberWindowDownInChunk, param->numberWindowAcrossInChunk);
|
|
|
|
c_masterBatchOverSampled->allocate();
|
|
|
|
|
|
|
|
c_slaveBatchOverSampled = new cuArrays<float2> (
|
|
|
|
param->searchWindowSizeHeight, param->searchWindowSizeWidth,
|
|
|
|
param->numberWindowDownInChunk, param->numberWindowAcrossInChunk);
|
|
|
|
c_slaveBatchOverSampled->allocate();
|
2019-11-20 00:59:49 +00:00
|
|
|
|
2019-01-16 19:40:08 +00:00
|
|
|
r_masterBatchOverSampled = new cuArrays<float> (
|
|
|
|
param->windowSizeHeight, param->windowSizeWidth,
|
|
|
|
param->numberWindowDownInChunk, param->numberWindowAcrossInChunk);
|
|
|
|
r_masterBatchOverSampled->allocate();
|
|
|
|
|
|
|
|
r_slaveBatchOverSampled = new cuArrays<float> (
|
|
|
|
param->searchWindowSizeHeight, param->searchWindowSizeWidth,
|
|
|
|
param->numberWindowDownInChunk, param->numberWindowAcrossInChunk);
|
|
|
|
r_slaveBatchOverSampled->allocate();
|
2019-11-20 00:59:49 +00:00
|
|
|
|
2019-01-16 19:40:08 +00:00
|
|
|
masterBatchOverSampler = new cuOverSamplerC2C(
|
|
|
|
c_masterBatchRaw->height, c_masterBatchRaw->width, //orignal size
|
2019-11-20 00:59:49 +00:00
|
|
|
c_masterBatchOverSampled->height, c_masterBatchOverSampled->width, //oversampled size
|
2019-01-16 19:40:08 +00:00
|
|
|
c_masterBatchRaw->count, stream);
|
2019-11-20 00:59:49 +00:00
|
|
|
|
|
|
|
slaveBatchOverSampler = new cuOverSamplerC2C(c_slaveBatchZoomIn->height, c_slaveBatchZoomIn->width,
|
2019-01-16 19:40:08 +00:00
|
|
|
c_slaveBatchOverSampled->height, c_slaveBatchOverSampled->width, c_slaveBatchRaw->count, stream);
|
2019-11-20 00:59:49 +00:00
|
|
|
|
2019-01-16 19:40:08 +00:00
|
|
|
r_corrBatchRaw = new cuArrays<float> (
|
2019-11-20 00:59:49 +00:00
|
|
|
param->searchWindowSizeHeightRaw-param->windowSizeHeightRaw+1,
|
|
|
|
param->searchWindowSizeWidthRaw-param->windowSizeWidthRaw+1,
|
|
|
|
param->numberWindowDownInChunk,
|
2019-01-16 19:40:08 +00:00
|
|
|
param->numberWindowAcrossInChunk);
|
|
|
|
r_corrBatchRaw->allocate();
|
2019-11-20 00:59:49 +00:00
|
|
|
|
2019-01-16 19:40:08 +00:00
|
|
|
r_corrBatchZoomIn = new cuArrays<float> (
|
2019-11-20 00:59:49 +00:00
|
|
|
param->searchWindowSizeHeight - param->windowSizeHeight+1,
|
|
|
|
param->searchWindowSizeWidth - param->windowSizeWidth+1,
|
|
|
|
param->numberWindowDownInChunk,
|
2019-01-16 19:40:08 +00:00
|
|
|
param->numberWindowAcrossInChunk);
|
|
|
|
r_corrBatchZoomIn->allocate();
|
2019-11-20 00:59:49 +00:00
|
|
|
|
2019-01-16 19:40:08 +00:00
|
|
|
r_corrBatchZoomInAdjust = new cuArrays<float> (
|
2019-11-20 00:59:49 +00:00
|
|
|
param->searchWindowSizeHeight - param->windowSizeHeight,
|
|
|
|
param->searchWindowSizeWidth - param->windowSizeWidth,
|
|
|
|
param->numberWindowDownInChunk,
|
2019-01-16 19:40:08 +00:00
|
|
|
param->numberWindowAcrossInChunk);
|
|
|
|
r_corrBatchZoomInAdjust->allocate();
|
2019-11-20 00:59:49 +00:00
|
|
|
|
|
|
|
|
2019-01-16 19:40:08 +00:00
|
|
|
r_corrBatchZoomInOverSampled = new cuArrays<float> (
|
|
|
|
param->zoomWindowSize * param->oversamplingFactor,
|
2019-11-20 00:59:49 +00:00
|
|
|
param->zoomWindowSize * param->oversamplingFactor,
|
|
|
|
param->numberWindowDownInChunk,
|
2019-01-16 19:40:08 +00:00
|
|
|
param->numberWindowAcrossInChunk);
|
|
|
|
r_corrBatchZoomInOverSampled->allocate();
|
2019-11-20 00:59:49 +00:00
|
|
|
|
2019-01-16 19:40:08 +00:00
|
|
|
offsetInit = new cuArrays<int2> (param->numberWindowDownInChunk, param->numberWindowAcrossInChunk);
|
|
|
|
offsetInit->allocate();
|
2019-11-20 00:59:49 +00:00
|
|
|
|
2019-01-16 19:40:08 +00:00
|
|
|
offsetZoomIn = new cuArrays<int2> (param->numberWindowDownInChunk, param->numberWindowAcrossInChunk);
|
|
|
|
offsetZoomIn->allocate();
|
2019-11-20 00:59:49 +00:00
|
|
|
|
2019-01-16 19:40:08 +00:00
|
|
|
offsetFinal = new cuArrays<float2> (param->numberWindowDownInChunk, param->numberWindowAcrossInChunk);
|
|
|
|
offsetFinal->allocate();
|
2019-11-20 00:59:49 +00:00
|
|
|
|
2019-01-16 19:40:08 +00:00
|
|
|
corrMaxValue = new cuArrays<float> (param->numberWindowDownInChunk, param->numberWindowAcrossInChunk);
|
|
|
|
corrMaxValue->allocate();
|
2019-11-20 00:59:49 +00:00
|
|
|
|
|
|
|
|
|
|
|
// new arrays due to snr estimation
|
|
|
|
std::cout<< "corrRawZoomInHeight: " << param->corrRawZoomInHeight << "\n";
|
|
|
|
std::cout<< "corrRawZoomInWidth: " << param->corrRawZoomInWidth << "\n";
|
|
|
|
|
|
|
|
r_corrBatchRawZoomIn = new cuArrays<float> (
|
|
|
|
param->corrRawZoomInHeight,
|
|
|
|
param->corrRawZoomInWidth,
|
|
|
|
param->numberWindowDownInChunk,
|
|
|
|
param->numberWindowAcrossInChunk);
|
|
|
|
r_corrBatchRawZoomIn->allocate();
|
|
|
|
|
|
|
|
i_corrBatchZoomInValid = new cuArrays<int> (
|
|
|
|
param->corrRawZoomInHeight,
|
|
|
|
param->corrRawZoomInWidth,
|
|
|
|
param->numberWindowDownInChunk,
|
|
|
|
param->numberWindowAcrossInChunk);
|
|
|
|
i_corrBatchZoomInValid->allocate();
|
|
|
|
|
|
|
|
|
|
|
|
r_corrBatchSum = new cuArrays<float> (
|
|
|
|
param->numberWindowDownInChunk,
|
|
|
|
param->numberWindowAcrossInChunk);
|
|
|
|
r_corrBatchSum->allocate();
|
|
|
|
|
|
|
|
i_corrBatchValidCount = new cuArrays<int> (
|
|
|
|
param->numberWindowDownInChunk,
|
|
|
|
param->numberWindowAcrossInChunk);
|
|
|
|
i_corrBatchValidCount->allocate();
|
|
|
|
|
|
|
|
i_maxloc = new cuArrays<int2> (param->numberWindowDownInChunk, param->numberWindowAcrossInChunk);
|
|
|
|
|
|
|
|
i_maxloc->allocate();
|
|
|
|
|
|
|
|
r_maxval = new cuArrays<float> (param->numberWindowDownInChunk, param->numberWindowAcrossInChunk);
|
|
|
|
|
|
|
|
r_maxval->allocate();
|
|
|
|
|
|
|
|
r_snrValue = new cuArrays<float> (param->numberWindowDownInChunk, param->numberWindowAcrossInChunk);
|
|
|
|
|
|
|
|
r_snrValue->allocate();
|
|
|
|
|
|
|
|
r_covValue = new cuArrays<float3> (param->numberWindowDownInChunk, param->numberWindowAcrossInChunk);
|
|
|
|
|
|
|
|
r_covValue->allocate();
|
|
|
|
|
|
|
|
// end of new arrays
|
|
|
|
|
2019-01-16 19:40:08 +00:00
|
|
|
if(param->oversamplingMethod) {
|
|
|
|
corrSincOverSampler = new cuSincOverSamplerR2R(param->zoomWindowSize, param->oversamplingFactor, stream);
|
|
|
|
}
|
2019-11-20 00:59:49 +00:00
|
|
|
else {
|
2019-01-16 19:40:08 +00:00
|
|
|
corrOverSampler= new cuOverSamplerR2R(param->zoomWindowSize, param->zoomWindowSize,
|
2019-11-20 00:59:49 +00:00
|
|
|
(param->zoomWindowSize)*param->oversamplingFactor,
|
2019-01-16 19:40:08 +00:00
|
|
|
(param->zoomWindowSize)*param->oversamplingFactor,
|
2019-11-20 00:59:49 +00:00
|
|
|
param->numberWindowDownInChunk*param->numberWindowAcrossInChunk,
|
|
|
|
stream);
|
|
|
|
}
|
2019-01-16 19:40:08 +00:00
|
|
|
if(param->algorithm == 0) {
|
|
|
|
cuCorrFreqDomain = new cuFreqCorrelator(
|
|
|
|
param->searchWindowSizeHeightRaw, param->searchWindowSizeWidthRaw,
|
|
|
|
param->numberWindowDownInChunk*param->numberWindowAcrossInChunk,
|
|
|
|
stream);
|
|
|
|
cuCorrFreqDomain_OverSampled = new cuFreqCorrelator(
|
|
|
|
param->searchWindowSizeHeight, param->searchWindowSizeWidth,
|
|
|
|
param->numberWindowDownInChunk*param->numberWindowAcrossInChunk,
|
2019-11-20 00:59:49 +00:00
|
|
|
stream);
|
2019-01-16 19:40:08 +00:00
|
|
|
}
|
|
|
|
|
2019-11-20 00:59:49 +00:00
|
|
|
|
2019-01-16 19:40:08 +00:00
|
|
|
|
|
|
|
debugmsg("all objects in chunk are created ...\n");
|
|
|
|
|
|
|
|
}
|
|
|
|
cuAmpcorChunk::~cuAmpcorChunk()
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
delete masterChunkRaw;
|
|
|
|
delete slaveChunkRaw;
|
|
|
|
delete ChunkOffsetDown;
|
|
|
|
delete ChunkOffsetAcross;
|
|
|
|
delete masterBatchRaw;
|
|
|
|
delete slaveBatchRaw;
|
|
|
|
delete masterChunkOverSampled;
|
|
|
|
delete slaveChunkOverSampled;
|
|
|
|
delete masterChunkOverSampler;
|
|
|
|
delete slaveChunkOverSampler;
|
|
|
|
delete masterChunk;
|
|
|
|
delete slaveChunk;
|
|
|
|
delete corrChunk;
|
|
|
|
delete offsetInit;
|
|
|
|
delete zoomInOffset;
|
|
|
|
delete offsetFinal;
|
|
|
|
delete corrChunkZoomIn;
|
|
|
|
delete corrChunkZoomInOverSampled;
|
|
|
|
delete corrOverSampler;
|
|
|
|
delete corrSincOverSampler;
|
|
|
|
delete corrMaxValue;
|
|
|
|
if(param->algorithm == 0)
|
|
|
|
delete cuCorrFreqDomain;
|
|
|
|
*/
|
|
|
|
}
|