|
2 | 2 | #include "matx.h" |
3 | 3 | #include "test_types.h" |
4 | 4 | #include "utilities.h" |
| 5 | +#include "prerun_tester.h" |
5 | 6 |
|
6 | 7 | using namespace matx; |
7 | 8 | using namespace matx::test; |
@@ -256,3 +257,55 @@ TEST(InterpTests, Interp) |
256 | 257 |
|
257 | 258 | MATX_EXIT_HANDLER(); |
258 | 259 | } |
| 260 | + |
| 261 | +// Verify that interp1 forwards PreRun/PostRun to ALL of its operands (sample |
| 262 | +// points, sample values, query points) by wrapping each one in a lifecycle |
| 263 | +// probe. A single invocation covers every forwarded operand. |
| 264 | +template <typename ExecType> |
| 265 | +static void InterpForwardingCheck(ExecType exec) |
| 266 | +{ |
| 267 | + using TestType = float; |
| 268 | + |
| 269 | + auto x = make_tensor<TestType>({5}); |
| 270 | + x.SetVals({0.0, 1.0, 3.0, 3.5, 4.0}); |
| 271 | + auto v = make_tensor<TestType>({5}); |
| 272 | + v.SetVals({0.0, 2.0, 1.0, 3.0, 4.0}); |
| 273 | + auto xq = make_tensor<TestType>({6}); |
| 274 | + xq.SetVals({-1.0, 0.0, 0.25, 1.0, 1.5, 5.0}); |
| 275 | + |
| 276 | + // Reference computed from the raw operands. |
| 277 | + auto out_ref = make_tensor<TestType>({xq.Size(0)}); |
| 278 | + (out_ref = interp1(x, v, xq, InterpMethod::LINEAR)).run(exec); |
| 279 | + |
| 280 | + // Wrap every forwarded operand in a lifecycle probe. |
| 281 | + PreRunLifecycle sx, sv, sxq; |
| 282 | + auto out_test = make_tensor<TestType>({xq.Size(0)}); |
| 283 | + (out_test = interp1(make_prerun_tester(x, sx), make_prerun_tester(v, sv), |
| 284 | + make_prerun_tester(xq, sxq), InterpMethod::LINEAR)) |
| 285 | + .run(exec); |
| 286 | + exec.sync(); |
| 287 | + |
| 288 | + // The forwarding contract is validated by the lifecycle counters: each |
| 289 | + // operand's PreRun/PostRun must have been forwarded exactly once. |
| 290 | + ExpectLifecycleClean(sx, "x"); |
| 291 | + ExpectLifecycleClean(sv, "v"); |
| 292 | + ExpectLifecycleClean(sxq, "xq"); |
| 293 | + |
| 294 | + // The probe forwards to the wrapped operand transparently, so out_test always |
| 295 | + // equals out_ref regardless of forwarding; this only confirms the probe is |
| 296 | + // transparent. The lifecycle counters above are what test the forwarding fix. |
| 297 | + for (index_t i = 0; i < xq.Size(0); i++) { |
| 298 | + ASSERT_NEAR(out_test(i), out_ref(i), 1e-4) << "mismatch at index " << i; |
| 299 | + } |
| 300 | +} |
| 301 | + |
| 302 | +TEST(InterpTests, InterpOperatorInput) |
| 303 | +{ |
| 304 | + MATX_ENTER_HANDLER(); |
| 305 | + // Run on the CUDA executor only: interp1 requires CUDA for the SPLINE method, |
| 306 | + // and the template instantiation for a host executor triggers the SPLINE |
| 307 | + // static_assert even for LINEAR. The host executor is already exercised by the |
| 308 | + // pre-existing InterpTests.Interp test. |
| 309 | + InterpForwardingCheck(cudaExecutor{}); |
| 310 | + MATX_EXIT_HANDLER(); |
| 311 | +} |
0 commit comments