Skip to content

Commit b65ea63

Browse files
gshiromaGitHub Enterprise
authored andcommitted
Add read progress to GeocodeCov (#761)
* add read progress in % to GeocodeCov * improve getNBlocks() function name to getBlocksNumberAndLength() to be more descriptive and update associated dosctrings * update getBlocksNumberAndLength() max_block_size type from int to long long * update areaProjGetNBlocks() parameter max_block_size type from int to long long * simplify declaration of variables in getBlocksNumberAndLength() * remove unnecessary line * add comments to the GeocodeCov function that reads the RSLC rasters * substitute c-type cast by static_cast in the GeocodeCov module * substitute c-type cast by static_cast in the RTC module
1 parent 4522534 commit b65ea63

File tree

4 files changed

+166
-13
lines changed

4 files changed

+166
-13
lines changed

cxx/isce3/geocode/GeocodeCov.cpp

Lines changed: 137 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,57 @@ void Geocode<T>::geoGrid(double geoGridStartX, double geoGridStartY,
8686
_epsgOut = epsgcode;
8787
}
8888

89+
90+
void getBlocksNumberAndLength(const int array_length, const int array_width,
91+
const int nbands, const size_t type_size,
92+
pyre::journal::info_t* channel,
93+
int* block_length, int* nblocks_y,
94+
const long long max_block_size) {
95+
96+
const int max_block_length = max_block_size /
97+
(nbands * array_width * type_size);
98+
99+
int _block_length = std::min(array_length, max_block_length);
100+
101+
// update nblocks
102+
int _nblocks_y = std::ceil((static_cast<float>(array_length)) / _block_length);
103+
104+
if (nblocks_y != nullptr)
105+
*nblocks_y = _nblocks_y;
106+
107+
if (channel != nullptr) {
108+
*channel << "array length: " << array_length << pyre::journal::newline;
109+
*channel << "array width: " << array_width << pyre::journal::newline;
110+
*channel << "number of block(s): " << _nblocks_y
111+
<< pyre::journal::newline;
112+
}
113+
114+
if (block_length != nullptr) {
115+
*block_length = _block_length;
116+
if (channel != nullptr) {
117+
*channel << "block length: " << *block_length
118+
<< pyre::journal::newline;
119+
*channel << "block width: " << array_width
120+
<< pyre::journal::newline;
121+
}
122+
}
123+
124+
if (channel != nullptr) {
125+
126+
long long block_size_bytes =
127+
((static_cast<long long>(_block_length)) *
128+
array_width * nbands * type_size);
129+
130+
std::string block_size_bytes_str = geometry::getNbytesStr(block_size_bytes);
131+
if (nbands > 1)
132+
block_size_bytes_str += " (" + std::to_string(nbands) + " bands)";
133+
134+
*channel << "block size: " << block_size_bytes_str
135+
<< pyre::journal::endl;
136+
}
137+
}
138+
139+
89140
template<class T>
90141
void Geocode<T>::geocode(
91142
const isce3::product::RadarGridParameters& radar_grid,
@@ -597,23 +648,91 @@ void _getUpsampledBlock(
597648
{
598649
int nbands = input_raster.numBands();
599650
rdrData.reserve(nbands);
651+
bool flag_parallel_radargrid_read = geocode_memory_mode ==
652+
geocodeMemoryMode::BLOCKS_GEOGRID_AND_RADARGRID;
600653
for (int band = 0; band < nbands; ++band) {
601-
if (geocode_memory_mode !=
602-
geocodeMemoryMode::BLOCKS_GEOGRID_AND_RADARGRID) {
654+
if (!flag_parallel_radargrid_read) {
603655
info << "reading input raster band: " << band + 1
604656
<< pyre::journal::endl;
605657
}
658+
606659
rdrData.emplace_back(
607660
std::make_unique<isce3::core::Matrix<T_out>>(size_y, size_x));
608-
if (!flag_upsample_radar_grid && std::is_same<T, T_out>::value) {
609-
#pragma omp critical
661+
662+
if (!flag_upsample_radar_grid && std::is_same<T, T_out>::value &&
663+
!flag_parallel_radargrid_read) {
664+
/*
665+
Enter here if:
666+
1. No upsampling is required;
667+
2. No type convertion is required (input and output have same
668+
types);
669+
3. Not parallel (which allows messages to be printed to stdout).
670+
*/
671+
672+
int radargrid_nblocks, radar_block_length;
673+
const int max_block_size = 1 << 28; // 256MB
674+
isce3::geocode::getBlocksNumberAndLength(size_y, size_x, 1, sizeof(T),
675+
nullptr, &radar_block_length, &radargrid_nblocks,
676+
max_block_size);
677+
678+
for (size_t block = 0; block < (size_t) radargrid_nblocks;
679+
++block) {
680+
681+
int this_radar_block_length = radar_block_length;
682+
if ((block + 1) * radar_block_length > size_y) {
683+
this_radar_block_length = size_y % radar_block_length;
684+
}
685+
if (radargrid_nblocks > 1) {
686+
std::cout << "reading band " << band + 1 << " progress: "
687+
<< static_cast<int>((100.0 * block) / radargrid_nblocks)
688+
<< "% \r";
689+
std::cout.flush();
690+
}
691+
auto ptr = rdrData[band]->data();
692+
input_raster.getBlock(ptr +
693+
block * radar_block_length * size_x,
694+
xidx, block * radar_block_length + yidx, size_x,
695+
this_radar_block_length, band + 1);
696+
}
697+
698+
if (radargrid_nblocks > 1) {
699+
std::cout << "reading band " << band + 1
700+
<< " progress: 100%" << std::endl;
701+
}
702+
}
703+
else if (!flag_upsample_radar_grid && std::is_same<T, T_out>::value) {
704+
/*
705+
Enter here if:
706+
1. No upsampling is required;
707+
2. No type convertion is required (input and output have same
708+
types);
709+
3. Is parallel (which does not allow messages to be printed to
710+
stdout).
711+
*/
712+
_Pragma("omp critical")
713+
{
610714
input_raster.getBlock(rdrData[band]->data(), xidx, yidx, size_x,
611715
size_y, band + 1);
612-
} else if (!flag_upsample_radar_grid) {
716+
}
717+
}
718+
else if (!flag_upsample_radar_grid) {
719+
/*
720+
Enter here if:
721+
1. No upsampling is required;
722+
2. Type convertion is required (input and output have different
723+
types).
724+
*/
613725
isce3::core::Matrix<T> radar_data_in(size_y, size_x);
614-
#pragma omp critical
615-
input_raster.getBlock(radar_data_in.data(), xidx, yidx, size_x,
616-
size_y, band + 1);
726+
if (flag_parallel_radargrid_read) {
727+
_Pragma("omp critical")
728+
{
729+
input_raster.getBlock(radar_data_in.data(), xidx, yidx, size_x,
730+
size_y, band + 1);
731+
}
732+
} else {
733+
input_raster.getBlock(radar_data_in.data(), xidx, yidx, size_x,
734+
size_y, band + 1);
735+
}
617736

618737
/*
619738
Iteratively converts input pixel (ptr_1) to output pixel (ptr_2).
@@ -630,10 +749,20 @@ void _getUpsampledBlock(
630749
_convertToOutputType(*ptr_1++, *ptr_2++);
631750
}
632751
} else if (flag_upsample_radar_grid && !isce3::is_complex<T>()) {
752+
/*
753+
Enter here if:
754+
1. Upsampling is required;
755+
2. Input is not complex.
756+
*/
633757
std::string error_msg = "radar-grid upsampling is only available";
634758
error_msg += " for complex inputs";
635759
throw isce3::except::InvalidArgument(ISCE_SRCINFO(), error_msg);
636760
} else {
761+
/*
762+
Enter here if:
763+
1. Upsampling is required;
764+
2. Input is complex.
765+
*/
637766
int radargrid_nblocks, radar_block_size;
638767
if (geocode_memory_mode == geocodeMemoryMode::SINGLE_BLOCK ||
639768
geocode_memory_mode ==

cxx/isce3/geocode/GeocodeCov.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,29 @@ class Geocode {
241241
void updateGeoGrid(const isce3::product::RadarGridParameters& radar_grid,
242242
isce3::io::Raster& dem_raster);
243243

244+
constexpr static long long DEFAULT_MAX_BLOCK_SIZE = 1 << 29; // 512MB
245+
/** Compute the number of blocks and their length for block processing
246+
* in the length direction
247+
*
248+
* @param[in] array_length Length of the data to be processed
249+
* @param[in] array_width Width of the data to be processed
250+
* @param[in] nbands Number of the bands to be processed
251+
* @param[in] type_size Type size of the data to be processed
252+
* @param[in] channel Pyre info channel
253+
* @param[out] block_length Block length
254+
* @param[out] nblock_y Number of blocks in the Y direction
255+
* @param[in] max_block_size Maximum block size in Bytes (per thread)
256+
*/
257+
void getBlocksNumberAndLength(const int array_length,
258+
const int array_width,
259+
const int nbands = 1,
260+
const size_t type_size = 4, // Float32
261+
pyre::journal::info_t* channel = nullptr,
262+
int* block_length = nullptr,
263+
int* nblock_y = nullptr,
264+
const long long max_block_size =
265+
DEFAULT_MAX_BLOCK_SIZE);
266+
244267
// Get/set data interpolator
245268
isce3::core::dataInterpMethod dataInterpolator() const
246269
{

cxx/isce3/geometry/RTC.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,8 @@ void areaProjGetNBlocks(const int array_length, const int array_width,
426426
int* block_length_with_upsampling, int* block_length,
427427
int* nblocks_y, int* block_width_with_upsampling,
428428
int* block_width, int* nblocks_x,
429-
const int min_block_size, const int max_block_size,
429+
const int min_block_size,
430+
const long long max_block_size,
430431
const int nblocks_per_thread)
431432
{
432433

@@ -458,7 +459,7 @@ void areaProjGetNBlocks(const int array_length, const int array_width,
458459
// set nblocks and block size (Y-axis)
459460
_nblocks_y = std::max(_nblocks_y, 1);
460461
_block_length_with_upsampling =
461-
std::ceil(((float) array_length) / _nblocks_y);
462+
std::ceil((static_cast<float>(array_length)) / _nblocks_y);
462463
_block_length_with_upsampling =
463464
std::max(_block_length_with_upsampling, min_block_length);
464465
_block_length_with_upsampling =
@@ -470,7 +471,7 @@ void areaProjGetNBlocks(const int array_length, const int array_width,
470471
if (flag_2d) {
471472
_nblocks_x = std::max(_nblocks_x, 1);
472473
_block_width_with_upsampling =
473-
std::ceil(((float) array_width) / _nblocks_x);
474+
std::ceil((static_cast<float>(array_width)) / _nblocks_x);
474475
_block_width_with_upsampling =
475476
std::max(_block_width_with_upsampling, min_block_width);
476477
_block_width_with_upsampling =

cxx/isce3/geometry/RTC.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ enum rtcMemoryMode {
3838
};
3939

4040
constexpr static int AP_DEFAULT_MIN_BLOCK_SIZE = 1 << 22; // 4MB
41-
constexpr static int AP_DEFAULT_MAX_BLOCK_SIZE = 1 << 30; // 1GB
41+
constexpr static long long AP_DEFAULT_MAX_BLOCK_SIZE = 1 << 30; // 1GB
4242

4343
/**Enumeration type to indicate RTC area mode (AREA or AREA_FACTOR) */
4444
enum rtcAreaMode { AREA = 0, AREA_FACTOR = 1 };
@@ -378,7 +378,7 @@ void areaProjGetNBlocks(const int array_length, const int array_width,
378378
int* block_width_with_upsampling = nullptr, int* block_width = nullptr,
379379
int* nblock_x = nullptr,
380380
const int min_block_size = AP_DEFAULT_MIN_BLOCK_SIZE,
381-
const int max_block_size = AP_DEFAULT_MAX_BLOCK_SIZE,
381+
const long long max_block_size = AP_DEFAULT_MAX_BLOCK_SIZE,
382382
const int nblocks_per_thread = 4);
383383

384384
double

0 commit comments

Comments
 (0)