Skip to content

[Bug]: float64 constant output returns incorrect value on GPU devices #33458

@zhihaoxu1325

Description

@zhihaoxu1325

OpenVINO Version

2025.4.0

Operating System

Ubuntu 20.04 (LTS)

Device used for inference

GPU

Framework

None

Model used

No response

Issue description

When a model has a constant output of float64 (double) type, the GPU plugin returns incorrect values instead of the expected constant values. The bug affects only float64 type; float32 works correctly.

Expected Behavior
Constant outputs should return the same values on both CPU and GPU devices.

Actual Behavior

GPU returns incorrect values for float64 constant outputs:

  • Single values often become 0
  • Arrays contain corrupted/garbage values
Constant: [1.0]       -> CPU: [1.], GPU: [0.]
Constant: [3.369349]  -> CPU: [3.369349], GPU: [2.]
Constant: [1. 2. 3.]  -> CPU: [1. 2. 3.], GPU: [0. 1.875 0.]

The bug appears to be related to how the GPU plugin handles constant folding or memory allocation for float64 outputs. The corrupted values suggest a possible issue with memory layout or buffer size calculation for 64-bit floating point data.

Root Cause Hypothesis
The GPU plugin may be:

  1. Allocating buffer with incorrect size (treating f64 as f32)
  2. Reading from uninitialized memory
  3. Incorrectly handling constant nodes in the output during graph compilation

Step-by-step reproduction

Run the minimal reproduction scripts:

#!/usr/bin/env python3
"""
Bug: [GPU] float64 constant output returns incorrect value (zero)

When a model has a constant output of float64 type, GPU returns 0 
instead of the correct constant value.
"""

import numpy as np
import openvino as ov
import openvino.runtime.opset13 as ops
from openvino.runtime import Model

print("=" * 70)
print("[GPU] float64 constant output returns zero")
print("=" * 70)

core = ov.Core()
print(f"OpenVINO version: {ov.__version__}")

# Minimal reproduction
const_value = np.array([3.14159], dtype=np.float64)

const_out = ops.constant(const_value)
param = ops.parameter([1], np.float64)
param_out = ops.add(param, ops.constant(np.array([0.0], dtype=np.float64)))

# Model with two outputs: one constant, one parameter-dependent
model = Model([const_out, param_out], [param])

input_data = np.array([1.0], dtype=np.float64)

cpu_result = np.array(core.compile_model(model, "CPU")([input_data])[0])
gpu_result = np.array(core.compile_model(model, "GPU")([input_data])[0])

print(f"\nConstant value: {const_value}")
print(f"CPU output: {cpu_result}")
print(f"GPU output: {gpu_result}")

if np.allclose(cpu_result, gpu_result):
    print("\nStatus: OK")
else:
    print("\n*** BUG CONFIRMED ***")
    print(f"  Expected: {const_value}")
    print(f"  Got (GPU): {gpu_result}")
    print(f"  GPU returns 0 for float64 constant output")

# Additional test: verify float32 works correctly
print("\n" + "-" * 70)
print("Comparison with float32 (works correctly):")
print("-" * 70)

const_value_f32 = np.array([3.14159], dtype=np.float32)
const_out_f32 = ops.constant(const_value_f32)
param_f32 = ops.parameter([1], np.float32)
param_out_f32 = ops.add(param_f32, ops.constant(np.array([0.0], dtype=np.float32)))
model_f32 = Model([const_out_f32, param_out_f32], [param_f32])

input_data_f32 = np.array([1.0], dtype=np.float32)
cpu_result_f32 = np.array(core.compile_model(model_f32, "CPU")([input_data_f32])[0])
gpu_result_f32 = np.array(core.compile_model(model_f32, "GPU")([input_data_f32])[0])

print(f"  float32 - CPU: {cpu_result_f32}, GPU: {gpu_result_f32}")
print(f"  Match: {'OK' if np.allclose(cpu_result_f32, gpu_result_f32) else 'MISMATCH'}")

# Test various float64 values
print("\n" + "-" * 70)
print("Testing various float64 constant values:")
print("-" * 70)

test_values = [
    np.array([0.0], dtype=np.float64),
    np.array([1.0], dtype=np.float64),
    np.array([-1.0], dtype=np.float64),
    np.array([3.369349], dtype=np.float64),
    np.array([1.0, 2.0, 3.0], dtype=np.float64),
]

for val in test_values:
    const_out = ops.constant(val)
    param = ops.parameter([1], np.float64)
    param_out = ops.add(param, ops.constant(np.array([0.0], dtype=np.float64)))
    model = Model([const_out, param_out], [param])
    
    cpu_r = np.array(core.compile_model(model, "CPU")([input_data])[0])
    gpu_r = np.array(core.compile_model(model, "GPU")([input_data])[0])
    
    match = "OK" if np.allclose(cpu_r, gpu_r) else "MISMATCH"
    print(f"  {val} -> CPU: {cpu_r}, GPU: {gpu_r} [{match}]")

Relevant log output

======================================================================
[GPU] float64 constant output returns incorrect value
======================================================================
OpenVINO version: 2025.4.0-20297-5f5229a2009

Constant value: [3.14159]
CPU output: [3.14159012]
GPU output: [0.]

*** BUG CONFIRMED ***
  Expected: [3.14159]
  Got (GPU): [0.]

----------------------------------------------------------------------
Comparison with float32:
----------------------------------------------------------------------
  CPU: [3.14159], GPU: [3.14159]
  Match: OK

----------------------------------------------------------------------
Various float64 constant values:
----------------------------------------------------------------------
  [0.] -> CPU: [0.], GPU: [0.] [OK]
  [1.] -> CPU: [1.], GPU: [0.] [MISMATCH]
  [-1.] -> CPU: [-1.], GPU: [0.] [MISMATCH]
  [3.369349] -> CPU: [3.369349], GPU: [2.] [MISMATCH]
  [1. 2. 3.] -> CPU: [1. 2. 3.], GPU: [0. 1.875 0.] [MISMATCH]

Issue submission checklist

  • I'm reporting an issue. It's not a question.
  • I checked the problem with the documentation, FAQ, open issues, Stack Overflow, etc., and have not found a solution.
  • There is reproducer code and related data files such as images, videos, models, etc.

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions