Skip to content

Commit ee4998b

Browse files
jungkyoJungGitHub Enterprise
authored andcommitted
Merge pull request #11 from isce-3/develop
rebase develop
2 parents e6fc3ba + f8b915d commit ee4998b

File tree

112 files changed

+7261
-1526
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

112 files changed

+7261
-1526
lines changed

cxx/isce3/core/Attitude.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ class Attitude {
5959
/** Time of last measurement relative to reference epoch (s) */
6060
double endTime() const { return _time[size() - 1]; }
6161

62+
/** Check if time falls in the valid interpolation domain. */
63+
bool contains(double time) const {
64+
return (startTime() <= time) && (time <= endTime());
65+
}
66+
6267
/** UTC time of first measurement */
6368
DateTime startDateTime() const
6469
{

cxx/isce3/core/Orbit.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,12 @@ class Orbit {
7676
/** Reference epoch (UTC) */
7777
const DateTime & referenceEpoch() const { return _reference_epoch; }
7878

79-
/** Set reference epoch (UTC) */
79+
/** Set reference epoch (UTC)
80+
*
81+
* Also updates relative time tags so that
82+
* referenceEpoch() + TimeDelta(time()[i])
83+
* results in the same absolute time tags before and after this call.
84+
*/
8085
void referenceEpoch(const DateTime &);
8186

8287
/** Interpolation method */
@@ -103,6 +108,11 @@ class Orbit {
103108
/** UTC time of last state vector */
104109
DateTime endDateTime() const { return _reference_epoch + TimeDelta(endTime()); }
105110

111+
/** Check if time falls in the valid interpolation domain. */
112+
bool contains(double time) const {
113+
return (startTime() <= time) && (time <= endTime());
114+
}
115+
106116
/** Time interval between state vectors (s) */
107117
double spacing() const { return _time.spacing(); }
108118

cxx/isce3/cuda/core/InterpolatorHandle.cu

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -16,28 +16,23 @@ namespace isce3::cuda::core {
1616

1717
template<class T>
1818
__global__ void init_interp(DeviceInterp<T>** interp,
19-
isce3::core::dataInterpMethod interp_method, bool* unsupported_interp)
19+
isce3::core::dataInterpMethod interp_method)
2020
{
2121
if (threadIdx.x == 0 && blockIdx.x == 0) {
2222
// Choose interpolator
23-
switch(interp_method) {
24-
case isce3::core::BILINEAR_METHOD:
25-
(*interp) = new isce3::cuda::core::gpuBilinearInterpolator<T>();
26-
break;
27-
case isce3::core::BICUBIC_METHOD:
28-
(*interp) = new isce3::cuda::core::gpuBicubicInterpolator<T>();
29-
break;
30-
case isce3::core::BIQUINTIC_METHOD:
31-
size_t order = 6;
32-
(*interp) = new isce3::cuda::core::gpuSpline2dInterpolator<T>(order);
33-
break;
34-
case isce3::core::NEAREST_METHOD:
35-
(*interp) = new isce3::cuda::core::gpuNearestNeighborInterpolator<T>();
36-
break;
37-
default:
38-
*unsupported_interp = true;
39-
break;
23+
if (interp_method == isce3::core::BILINEAR_METHOD)
24+
(*interp) = new isce3::cuda::core::gpuBilinearInterpolator<T>();
25+
26+
if (interp_method == isce3::core::BICUBIC_METHOD)
27+
(*interp) = new isce3::cuda::core::gpuBicubicInterpolator<T>();
28+
29+
if (interp_method == isce3::core::BIQUINTIC_METHOD) {
30+
size_t order = 6;
31+
(*interp) = new isce3::cuda::core::gpuSpline2dInterpolator<T>(order);
4032
}
33+
34+
if (interp_method == isce3::core::NEAREST_METHOD)
35+
(*interp) = new isce3::cuda::core::gpuNearestNeighborInterpolator<T>();
4136
}
4237
}
4338

@@ -55,21 +50,23 @@ InterpolatorHandle<T>::InterpolatorHandle(
5550
{
5651
checkCudaErrors(cudaMalloc(&_interp, sizeof(DeviceInterp<T>**)));
5752

58-
thrust::device_vector<bool> d_unsupported_interp(1, false);
59-
init_interp<<<1, 1>>>(
60-
_interp, interp_method, d_unsupported_interp.data().get());
61-
checkCudaErrors(cudaPeekAtLastError());
62-
checkCudaErrors(cudaDeviceSynchronize());
63-
64-
bool unsupported_interp = d_unsupported_interp[0];
65-
if (unsupported_interp) {
53+
if (interp_method != isce3::core::BILINEAR_METHOD
54+
&& interp_method != isce3::core::BICUBIC_METHOD
55+
&& interp_method != isce3::core::BIQUINTIC_METHOD
56+
&& interp_method != isce3::core::NEAREST_METHOD)
57+
{
6658
pyre::journal::error_t error(
67-
"isce.cuda.core.InterpolatorHandle.InterpolatorHandle");
59+
"isce3.cuda.core.InterpolatorHandle.InterpolatorHandle");
6860
error << "Unsupported interpolator method provided."
6961
<< pyre::journal::endl;
7062
throw isce3::except::InvalidArgument(
7163
ISCE_SRCINFO(), "Unsupported interpolator method provided.");
7264
}
65+
66+
thrust::device_vector<bool> d_unsupported_interp(1, false);
67+
init_interp<<<1, 1>>>(_interp, interp_method);
68+
checkCudaErrors(cudaPeekAtLastError());
69+
checkCudaErrors(cudaDeviceSynchronize());
7370
}
7471

7572
template<class T>
@@ -86,4 +83,5 @@ template class InterpolatorHandle<thrust::complex<float>>;
8683
template class InterpolatorHandle<double>;
8784
template class InterpolatorHandle<thrust::complex<double>>;
8885
template class InterpolatorHandle<unsigned char>;
86+
template class InterpolatorHandle<unsigned int>;
8987
} // namespace isce3::cuda::core

cxx/isce3/cuda/core/gpuBicubicInterpolator.cu

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ template class gpuBicubicInterpolator<thrust::complex<double>>;
179179
template class gpuBicubicInterpolator<float>;
180180
template class gpuBicubicInterpolator<thrust::complex<float>>;
181181
template class gpuBicubicInterpolator<unsigned char>;
182+
template class gpuBicubicInterpolator<unsigned int>;
182183

183184
template __global__ void gpuInterpolator_g<double>(
184185
gpuBicubicInterpolator<double> interp, double* x, double* y,

cxx/isce3/cuda/core/gpuBilinearInterpolator.cu

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ template class gpuBilinearInterpolator<thrust::complex<double>>;
115115
template class gpuBilinearInterpolator<float>;
116116
template class gpuBilinearInterpolator<thrust::complex<float>>;
117117
template class gpuBilinearInterpolator<unsigned char>;
118+
template class gpuBilinearInterpolator<unsigned int>;
118119

119120
template __global__ void gpuInterpolator_g<double>(
120121
gpuBilinearInterpolator<double> interp, double* x, double* y,

cxx/isce3/cuda/core/gpuNearestNeighborInterpolator.cu

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@ template class gpuNearestNeighborInterpolator<thrust::complex<double>>;
1919
template class gpuNearestNeighborInterpolator<float>;
2020
template class gpuNearestNeighborInterpolator<thrust::complex<float>>;
2121
template class gpuNearestNeighborInterpolator<unsigned char>;
22+
template class gpuNearestNeighborInterpolator<unsigned int>;

cxx/isce3/cuda/core/gpuSpline2dInterpolator.cu

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ template class gpuSpline2dInterpolator<thrust::complex<double>>;
154154
template class gpuSpline2dInterpolator<float>;
155155
template class gpuSpline2dInterpolator<thrust::complex<float>>;
156156
template class gpuSpline2dInterpolator<unsigned char>;
157+
template class gpuSpline2dInterpolator<unsigned int>;
157158

158159
template __global__ void gpuInterpolator_g<double>(
159160
gpuSpline2dInterpolator<double> interp, double* x, double* y,

cxx/isce3/cuda/geocode/Geocode.cu

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,10 @@ Geocode::Geocode(const isce3::product::GeoGridParameters & geogrid,
201201
_interp_double_handle(data_interp_method),
202202
_interp_cdouble_handle(data_interp_method),
203203
_interp_unsigned_char_handle(data_interp_method),
204+
_interp_unsigned_int_handle(data_interp_method),
204205
_proj_handle(geogrid.epsg()),
205-
_dem_interp_method(dem_interp_method)
206+
_dem_interp_method(dem_interp_method),
207+
_data_interp_method(data_interp_method)
206208
{
207209
// init light weight radar grid
208210
_radar_grid.sensing_start = _rdr_geom.radarGrid().sensingStart();
@@ -231,10 +233,12 @@ Geocode::Geocode(const isce3::product::GeoGridParameters & geogrid,
231233
_invalid_float = std::numeric_limits<float>::quiet_NaN();
232234
_invalid_double = std::numeric_limits<double>::quiet_NaN();
233235
_invalid_unsigned_char = 255;
236+
_invalid_unsigned_int = 4294967295;
234237
} else {
235238
_invalid_float = invalid_value;
236239
_invalid_double = static_cast<double>(invalid_value);
237240
_invalid_unsigned_char = static_cast<unsigned char>(invalid_value);
241+
_invalid_unsigned_int = static_cast<unsigned int>(invalid_value);
238242
}
239243
}
240244

@@ -337,9 +341,21 @@ void Geocode::setBlockRdrCoordGrid(const size_t block_number)
337341
}
338342
}
339343

344+
void Geocode::rasterDtypeInterpCheck(const int dtype) const
345+
{
346+
if ((dtype == GDT_Byte || dtype == GDT_UInt32) &&
347+
_data_interp_method != isce3::core::NEAREST_METHOD)
348+
{
349+
std::string err_str {"int type of raster can only use nearest neighbor interp"};
350+
throw isce3::except::InvalidArgument(ISCE_SRCINFO(), err_str);
351+
}
352+
}
353+
340354
template<class T>
341355
void Geocode::geocodeRasterBlock(Raster& output_raster, Raster& input_raster)
342356
{
357+
rasterDtypeInterpCheck(input_raster.dtype());
358+
343359
// determine number of elements in output vector
344360
const auto n_elem_out = _geo_block_length * _geogrid.width();
345361

@@ -362,6 +378,9 @@ void Geocode::geocodeRasterBlock(Raster& output_raster, Raster& input_raster)
362378
} else if constexpr (std::is_same_v<T, unsigned char>) {
363379
interp = _interp_unsigned_char_handle.getInterp();
364380
invalid_value = _invalid_unsigned_char;
381+
} else if constexpr (std::is_same_v<T, unsigned int>) {
382+
interp = _interp_unsigned_int_handle.getInterp();
383+
invalid_value = _invalid_unsigned_int;
365384
}
366385

367386
// 0 width indicates current block is out of bounds
@@ -427,6 +446,10 @@ void Geocode::geocodeRasters(
427446

428447
const auto n_raster_pairs = output_rasters.size();
429448

449+
// check if raster types consistent with data interp method
450+
for (size_t i_raster = 0; i_raster < n_raster_pairs; ++i_raster)
451+
rasterDtypeInterpCheck(input_rasters[i_raster].get().dtype());
452+
430453
// iterate over blocks
431454
for (size_t i_block = 0; i_block < _n_blocks; ++i_block) {
432455

@@ -457,6 +480,10 @@ void Geocode::geocodeRasters(
457480
geocodeRasterBlock<unsigned char>(
458481
output_rasters[i_raster], input_rasters[i_raster]);
459482
break;}
483+
case GDT_UInt32: {
484+
geocodeRasterBlock<unsigned int>(
485+
output_rasters[i_raster], input_rasters[i_raster]);
486+
break;}
460487
default: {
461488
throw isce3::except::RuntimeError(ISCE_SRCINFO(),
462489
"unsupported datatype");
@@ -474,4 +501,5 @@ EXPLICIT_INSTATIATION(thrust::complex<float>);
474501
EXPLICIT_INSTATIATION(double);
475502
EXPLICIT_INSTATIATION(thrust::complex<double>);
476503
EXPLICIT_INSTATIATION(unsigned char);
504+
EXPLICIT_INSTATIATION(unsigned int);
477505
} // namespace isce3::cuda::geocode

cxx/isce3/cuda/geocode/Geocode.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,12 +178,18 @@ class Geocode {
178178
_interp_cdouble_handle;
179179
isce3::cuda::core::InterpolatorHandle<unsigned char>
180180
_interp_unsigned_char_handle;
181+
isce3::cuda::core::InterpolatorHandle<unsigned int>
182+
_interp_unsigned_int_handle;
181183

182184
// value applied to invalid geogrid pixels
183185
float _invalid_float;
184186
double _invalid_double;
185187
unsigned char _invalid_unsigned_char;
188+
unsigned int _invalid_unsigned_int;
186189

187190
isce3::core::dataInterpMethod _dem_interp_method;
191+
isce3::core::dataInterpMethod _data_interp_method;
192+
193+
void rasterDtypeInterpCheck(const int dtype) const;
188194
};
189195
} // namespace isce3::cuda::geocode

cxx/isce3/cuda/geometry/Geo2rdr.cpp

Lines changed: 4 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,9 @@ geo2rdr(isce3::io::Raster & topoRaster,
102102
// Interpolate orbit to middle of the scene as a test
103103
_checkOrbitInterpolation(tmid);
104104

105-
// Compute number of lines per block
106-
computeLinesPerBlock();
107-
108105
// Compute number of DEM blocks needed to process image
109-
size_t nBlocks = demLength / _linesPerBlock;
110-
if ((demLength % _linesPerBlock) != 0)
106+
size_t nBlocks = demLength / linesPerBlock();
107+
if ((demLength % linesPerBlock()) != 0)
111108
nBlocks += 1;
112109

113110
// Cache near, mid, far ranges for diagnostics on Doppler
@@ -121,11 +118,11 @@ geo2rdr(isce3::io::Raster & topoRaster,
121118

122119
// Get block extents
123120
size_t lineStart, blockLength;
124-
lineStart = block * _linesPerBlock;
121+
lineStart = block * linesPerBlock();
125122
if (block == (nBlocks - 1)) {
126123
blockLength = demLength - lineStart;
127124
} else {
128-
blockLength = _linesPerBlock;
125+
blockLength = linesPerBlock();
129126
}
130127
size_t blockSize = blockLength * demWidth;
131128

@@ -194,33 +191,3 @@ _checkOrbitInterpolation(double aztime) {
194191
isce3::core::cartesian_t satxyz, satvel;
195192
this->orbit().interpolate(&satxyz, &satvel, aztime);
196193
}
197-
198-
// Compute number of lines per block dynamically from GPU memory
199-
void isce3::cuda::geometry::Geo2rdr::
200-
computeLinesPerBlock() {
201-
202-
// Compute GPU memory
203-
const size_t nGPUBytes = getDeviceMem();
204-
205-
// 2 GB buffer for safeguard for large enough devices (> 6 GB)
206-
size_t gpuBuffer;
207-
if (nGPUBytes > 6e9) {
208-
gpuBuffer = 2e9;
209-
} else {
210-
// Else use 500 MB buffer
211-
gpuBuffer = 500e6;
212-
}
213-
214-
// Compute pixels per Block (3 double input layers and 2 float output layers)
215-
size_t pixelsPerBlock = (nGPUBytes - gpuBuffer) /
216-
(3 * sizeof(double) + 2 * sizeof(float));
217-
// Round down to nearest 10 million pixels
218-
pixelsPerBlock = (pixelsPerBlock / 10000000) * 10000000;
219-
220-
// Compute number of lines per block
221-
_linesPerBlock = pixelsPerBlock / this->radarGridParameters().width();
222-
// Round down to nearest 500 lines
223-
_linesPerBlock = (_linesPerBlock / 500) * 500;
224-
}
225-
226-
// end of file

0 commit comments

Comments
 (0)