Skip to content

Fix segmentation fault with complex Variable operations and assign_add (#105367)#9

Open
CodersAcademy006 wants to merge 9 commits intomasterfrom
fix-complex-variable-conj-segfault
Open

Fix segmentation fault with complex Variable operations and assign_add (#105367)#9
CodersAcademy006 wants to merge 9 commits intomasterfrom
fix-complex-variable-conj-segfault

Conversation

@CodersAcademy006
Copy link
Copy Markdown
Owner

Description

This PR fixes issue tensorflow#105367 - a segmentation fault that occurs when performing complex number operations involving:

  • Complex64/complex128 variables
  • tf.raw_ops.Conj operation
  • Variable.assign_add() method

Root Cause

The segmentation fault was caused by missing complex type support in:

  1. GPU DenseUpdate functor template instantiations for ADD/SUB operations in dense_update_functor_gpu.cu.cc
  2. GPU kernel registrations for AssignAddVariableOp and AssignSubVariableOp in resource_variable_ops.cc

When users tried to use assign_add on complex variables (especially after tf.raw_ops.Conj), the kernel was not properly instantiated for complex types on GPU, leading to undefined behavior and segfaults.

Changes

  1. tensorflow/core/kernels/dense_update_functor_gpu.cu.cc

    • Added TF_CALL_COMPLEX_TYPES(DEFINE_GPU_KERNELS) to instantiate DenseUpdate functors for complex64 and complex128 types
  2. tensorflow/core/kernels/resource_variable_ops.cc

    • Added TF_CALL_COMPLEX_TYPES(REGISTER_GPU_KERNELS) to register GPU kernels for AssignAddVariableOp and AssignSubVariableOp with complex types
  3. tensorflow/python/kernel_tests/variables/resource_variable_ops_test.py

    • Added comprehensive test cases for complex variable assign_add operations:
      • testComplexVariableAssignAddWithConj: Tests GPU execution with Conj operation (the original issue)
      • testComplexVariableAssignAddCPU: Tests CPU execution with complex types

Testing

The fix has been validated with:

Fixes

Closes tensorflow#105367

Co-authored-by: CodersAcademy006 <104912634+CodersAcademy006@users.noreply.github.com>
Co-authored-by: CodersAcademy006 <104912634+CodersAcademy006@users.noreply.github.com>
…ents and edge case handling

Co-authored-by: CodersAcademy006 <104912634+CodersAcademy006@users.noreply.github.com>
Fixes tensorflow#105367

The issue was that complex types (complex64, complex128) were missing from:
1. GPU DenseUpdate functor template instantiations for ADD/SUB operations
2. GPU kernel registrations for AssignAddVariableOp and AssignSubVariableOp

This caused a segmentation fault when using assign_add on complex Variables,
particularly when combined with tf.raw_ops.Conj operations.

Changes:
- Added TF_CALL_COMPLEX_TYPES to dense_update_functor_gpu.cu.cc for ADD/SUB
- Added TF_CALL_COMPLEX_TYPES to GPU kernel registrations in resource_variable_ops.cc
- Added comprehensive test cases for complex variable assign_add operations
@CodersAcademy006 CodersAcademy006 force-pushed the fix-complex-variable-conj-segfault branch from 633e17d to 8bb30b1 Compare December 1, 2025 13:17
Address code review feedback: limit changes only to the complex variable
conj segfault fix. The cuDNN batch splitting code was unrelated to the
initializers issue and has been removed to keep the PR focused.
…ble fix

The complex variable conj segfault fix only requires changes to:
- dense_update_functor_gpu.cu.cc (GPU kernel instantiation)
- resource_variable_ops.cc (GPU kernel registration)
- resource_variable_ops_test.py (test cases)

The conv_ops_impl.h file is unrelated to this fix and should not be modified.
@CodersAcademy006 CodersAcademy006 force-pushed the fix-complex-variable-conj-segfault branch from 24d000a to a7b6d38 Compare December 1, 2025 19:25
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.

Segmentation fault when combining complex Variable operations with tf.raw_ops.Conj and assign_add

1 participant