Skip to content

Commit a098e99

Browse files
authored
Add sar_bp PixelZIsZero and PixelZIsFixed properties (#1196)
* Add sar_bp PixelZIsZero and PixelZIsFixed properties The PixelZIsZero and PixelZIsFixed sar_bp properties assert that the image z locations are either identically zero or all uniformally the same value, respectively. These properties are asserted by the user and are not verified at run-time by the operator. Adding these properties enables additional optimizations in the sar_bp operator by eliding computations involving the z location or hoisting such computations out of the inner loop. The performance benefits vary by compute type. On RTX PRO 6000, TaylorFast and FloatFloat benefit by 3% and 10%, respectively, with PixelZIsZero. Signed-off-by: Thomas Benson <tbenson@nvidia.com>
1 parent ae52583 commit a098e99

6 files changed

Lines changed: 613 additions & 73 deletions

File tree

docs_input/api/signalimage/radar/sar_bp.rst

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ namespace as its API is subject to change.
1111
.. doxygenfunction:: sar_bp(const ImageType &initial_image, const RangeProfilesType &range_profiles, const PlatPosType &platform_positions, const VoxLocType &voxel_locations, const RangeToMcpType &range_to_mcp, const SarBpParams &params)
1212
.. doxygenenum:: matx::SarBpComputeType
1313
.. doxygenenum:: matx::SarBpFeature
14+
.. doxygenenum:: matx::SarBpPixelZMode
1415
.. doxygenstruct:: matx::PropSarBpTaylorFastAddThirdOrder
16+
.. doxygenstruct:: matx::PropSarBpPixelZIsZero
17+
.. doxygenstruct:: matx::PropSarBpPixelZIsFixed
1518
.. doxygenstruct:: matx::SarBpParams
1619
:members:
1720

@@ -366,6 +369,35 @@ a thread block, the third-order term becomes more important. The third-order
366369
property uses a separate kernel instantiation, which avoids a run-time order
367370
dispatch inside the backprojection kernel.
368371

372+
Pixel Height (Z) Assumptions
373+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
374+
375+
SAR images are frequently formed on a flat focal plane, so every output pixel
376+
shares the same height (z) coordinate -- very often ``z = 0`` (a ground plane at
377+
the reference height). When that holds, the per-pulse, per-pixel range
378+
computation carries a redundant pixel-z term that can be elided. MatX exposes
379+
this as two opt-in, compile-time properties:
380+
381+
- ``PropSarBpPixelZIsZero`` asserts that every pixel has ``z = 0``. The kernel
382+
drops the pixel-z term from the per-pulse range computation.
383+
- ``PropSarBpPixelZIsFixed`` asserts that every pixel shares one (arbitrary,
384+
possibly non-zero) z value. On the shared-cache compute paths the uniform
385+
per-pulse z contribution is hoisted out of the per-pixel inner loop.
386+
387+
Both are *compile-time assumptions that are not validated at run time*; set one
388+
only when it actually holds for the supplied ``voxel_locations``. With neither
389+
property set (the default), each pixel may have a distinct z coordinate, which is
390+
the correct choice for terrain- or DEM-based focusing. If both are set,
391+
``PropSarBpPixelZIsZero`` (the stronger assumption) takes precedence. Callers who
392+
set neither are unaffected: the default kernel is unchanged, and only the
393+
variants you opt into are additionally instantiated.
394+
395+
Whether ``z`` is literally ``0``/constant depends on the coordinate frame of
396+
``voxel_locations``. A flat focal plane expressed in a scene-local East-North-Up
397+
frame (height along z) satisfies these assumptions, whereas a grid expressed in
398+
ECEF generally does not, since even a flat plane then has all three coordinates
399+
varying per pixel.
400+
369401
Examples
370402
~~~~~~~~
371403

@@ -387,3 +419,19 @@ third-order term to a ``TaylorFast`` launch:
387419

388420
The property only affects ``SarBpComputeType::TaylorFast``. Other compute types
389421
continue to use their ordinary kernel instantiations.
422+
423+
When the image is formed on the ``z = 0`` plane, the ``PropSarBpPixelZIsZero``
424+
property lets the kernel skip the pixel-z term in the per-pulse range
425+
computation. Like ``PropSarBpTaylorFastAddThirdOrder``, it is a compile-time
426+
property applied to the operator, independent of the compute type selected
427+
through ``SarBpParams``:
428+
429+
.. literalinclude:: ../../../../test/00_transform/SarBp.cu
430+
:language: cpp
431+
:start-after: example-begin sar-bp-3
432+
:end-before: example-end sar-bp-3
433+
:dedent:
434+
435+
``PropSarBpPixelZIsFixed`` is the analogous property for a constant, non-zero
436+
focal-plane height. These assumptions are not validated at run time, so set them
437+
only when the supplied voxel z coordinates actually satisfy them.

examples/sarbp/sarbp.cu

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ struct BpRunCtx {
227227
bool is_int16_mode;
228228
bool apply_window;
229229
bool taylor_fast_add_third_order;
230+
SarBpPixelZMode pixel_z_mode; // compile-time pixel-z assumption to apply
230231
int sgn;
231232
bool do_warmup;
232233
std::string output_file;
@@ -319,10 +320,25 @@ static int run_bp_device(PosTensor blk_positions, RtmTensor blk_rtm,
319320
auto cur_voxel_locations = matx::slice(voxel_locations, {y0, x0}, {y1, x1});
320321
auto bp = matx::experimental::sar_bp(
321322
cur_image, cur_profiles, cur_positions, cur_voxel_locations, cur_rtm, ctx.params);
323+
// Cross product of the optional TaylorFast third-order term and the
324+
// compile-time pixel-z assumption (variable / zero / fixed).
325+
auto run_with_z = [&](auto bp_props) {
326+
switch (ctx.pixel_z_mode) {
327+
case SarBpPixelZMode::Zero:
328+
(cur_image = bp_props.template props<matx::PropSarBpPixelZIsZero>()).run(ctx.exec);
329+
break;
330+
case SarBpPixelZMode::Fixed:
331+
(cur_image = bp_props.template props<matx::PropSarBpPixelZIsFixed>()).run(ctx.exec);
332+
break;
333+
case SarBpPixelZMode::Variable:
334+
(cur_image = bp_props).run(ctx.exec);
335+
break;
336+
}
337+
};
322338
if (ctx.taylor_fast_add_third_order) {
323-
(cur_image = bp.template props<matx::PropSarBpTaylorFastAddThirdOrder>()).run(ctx.exec);
339+
run_with_z(bp.template props<matx::PropSarBpTaylorFastAddThirdOrder>());
324340
} else {
325-
(cur_image = bp).run(ctx.exec);
341+
run_with_z(bp);
326342
}
327343
}
328344
}
@@ -684,6 +700,7 @@ int main(int argc, char **argv) {
684700
<< " Add the third-order term for --precision taylor_fast\n"
685701
<< " --warmup Warmup GPU kernels and FFT plans before timed run\n"
686702
<< " --precision <type> Compute precision: double, float, fltflt, mixed, taylor_fast (default: mixed)\n"
703+
<< " --pixel-z <mode> Compile-time pixel-z assumption: variable, zero, fixed (default: variable)\n"
687704
<< " -h, --help Print this help message and exit\n";
688705
};
689706

@@ -701,6 +718,8 @@ int main(int argc, char **argv) {
701718
bool do_warmup = false;
702719
bool taylor_fast_add_third_order = false;
703720
std::string precision_type = "mixed";
721+
std::string pixel_z_arg = "variable";
722+
SarBpPixelZMode pixel_z_mode = SarBpPixelZMode::Variable;
704723

705724
auto needs_value = [&](int i) -> bool {
706725
if (i + 1 >= argc) {
@@ -742,6 +761,9 @@ int main(int argc, char **argv) {
742761
} else if (std::strcmp(argv[i], "--precision") == 0) {
743762
if (!needs_value(i)) return 1;
744763
precision_type = argv[++i];
764+
} else if (std::strcmp(argv[i], "--pixel-z") == 0) {
765+
if (!needs_value(i)) return 1;
766+
pixel_z_arg = argv[++i];
745767
} else if (argv[i][0] == '-') {
746768
std::cerr << "ERROR: unknown option '" << argv[i] << "'" << std::endl;
747769
print_usage();
@@ -782,6 +804,19 @@ int main(int argc, char **argv) {
782804
return 1;
783805
}
784806

807+
if (pixel_z_arg == "variable") {
808+
pixel_z_mode = SarBpPixelZMode::Variable;
809+
} else if (pixel_z_arg == "zero") {
810+
pixel_z_mode = SarBpPixelZMode::Zero;
811+
} else if (pixel_z_arg == "fixed") {
812+
pixel_z_mode = SarBpPixelZMode::Fixed;
813+
} else {
814+
std::cerr << "ERROR: invalid --pixel-z '" << pixel_z_arg
815+
<< "' (use variable, zero, or fixed)" << std::endl;
816+
print_usage();
817+
return 1;
818+
}
819+
785820
// -------------------------------------------------------------------
786821
// Read .sarbp file header
787822
// -------------------------------------------------------------------
@@ -1110,6 +1145,7 @@ int main(int argc, char **argv) {
11101145
.is_int16_mode = is_int16_mode,
11111146
.apply_window = apply_window,
11121147
.taylor_fast_add_third_order = taylor_fast_add_third_order,
1148+
.pixel_z_mode = pixel_z_mode,
11131149
.sgn = sgn,
11141150
.do_warmup = do_warmup,
11151151
.output_file = output_file,

0 commit comments

Comments
 (0)