Skip to content

fix(ffs-depth-tensorrt): depth_alloc_pixels_ not reset (+2 more) - #68

Draft
andrewwhitecdw wants to merge 1 commit into
NVlabs:masterfrom
andrewwhitecdw:bugfix/ffs-depth-tensorrt-assorted-a0e1e7e0
Draft

fix(ffs-depth-tensorrt): depth_alloc_pixels_ not reset (+2 more)#68
andrewwhitecdw wants to merge 1 commit into
NVlabs:masterfrom
andrewwhitecdw:bugfix/ffs-depth-tensorrt-assorted-a0e1e7e0

Conversation

@andrewwhitecdw

@andrewwhitecdw andrewwhitecdw commented Jul 27, 2026

Copy link
Copy Markdown

Small fixes in cpp/src/ffs_depth_tensorrt.cpp:

fix: depth_alloc_pixels_ not reset before realloc

Fix: Replace:

    if (static_cast<int64_t>(num_pixels) > depth_alloc_pixels_) {
        // cudaFree is implicitly stream-ordered: it waits for prior work on the
        // device before reclaiming the allocation, so this is safe to call here
        // even though earlier inferDepth() calls may still be in flight.
        if (d_disp_for_depth_) {
            cudaFree(d_disp_for_depth_);
            d_disp_for_depth_ = nullptr;
        }
        cudaMallocChecked(reinterpret_cast<void**>(&d_disp_for_depth_),
                          num_pixels * sizeof(float), "d_disp_for_depth_");
        depth_alloc_pixels_ = static_cast<int64_t>(num_pixels);
    }

with:

    if (static_cast<int64_t>(num_pixels) > depth_alloc_pixels_) {
        // cudaFree is implicitly stream-ordered: it waits for prior work on the
        // device before reclaiming the allocation, so this is safe to call here
        // even though earlier inferDepth() calls may still be in flight.
        if (d_disp_for_depth_) {
            cudaFree(d_disp_for_depth_);
            d_disp_for_depth_ = nullptr;
        }
        depth_alloc_pixels_ = 0;
        cudaMallocChecked(reinterpret_cast<void**>(&d_disp_for_depth_),
                          num_pixels * sizeof(float), "d_disp_for_depth_");
        depth_alloc_pixels_ = static_cast<int64_t>(num_pixels);
    }

fix: inferDepth does not validate output pointer

Fix: Replace:

void FFSDepthInference::inferDepth(
    const uint8_t* d_left_rgb, const uint8_t* d_right_rgb,
    int input_h, int input_w,
    float fx, float baseline_m,
    float* d_depth_out)
{
    if (input_h <= 0 || input_w <= 0) {
        throw std::runtime_error("[FFS] inferDepth: input dimensions must be positive");
    }

with:

void FFSDepthInference::inferDepth(
    const uint8_t* d_left_rgb, const uint8_t* d_right_rgb,
    int input_h, int input_w,
    float fx, float baseline_m,
    float* d_depth_out)
{
    if (!d_left_rgb || !d_right_rgb || !d_depth_out) {
        throw std::runtime_error("[FFS] inferDepth: null device pointer");
    }
    if (input_h <= 0 || input_w <= 0) {
        throw std::runtime_error("[FFS] inferDepth: input dimensions must be positive");
    }

fix: disp buffer logic assumes FP32 regardless of dtype

Fix: Replace:

    const auto disp_dt = post_engine_->getTensorDataType("disp");
    const size_t disp_bytes = H * W * elementSize(disp_dt);
    cudaMallocChecked(reinterpret_cast<void**>(&d_disp_), disp_bytes, "d_disp_");

with:

    const auto disp_dt = post_engine_->getTensorDataType("disp");
    if (disp_dt != nvinfer1::DataType::kFLOAT) {
        throw std::runtime_error("[FFS] post_runner disp tensor must be FP32");
    }
    const size_t disp_bytes = H * W * elementSize(disp_dt);
    cudaMallocChecked(reinterpret_cast<void**>(&d_disp_), disp_bytes, "d_disp_");

Files changed

  • cpp/src/ffs_depth_tensorrt.cpp

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant