Skip to content

[SR-13210] Forward mode differentiation SIL verification crash #55650

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
swift-ci opened this issue Jul 13, 2020 · 0 comments
Open

[SR-13210] Forward mode differentiation SIL verification crash #55650

swift-ci opened this issue Jul 13, 2020 · 0 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior.

Comments

@swift-ci
Copy link
Contributor

Previous ID SR-13210
Radar None
Original Reporter aefr (JIRA User)
Type Bug
Additional Detail from JIRA
Votes 0
Component/s
Labels Bug
Assignee None
Priority Medium

md5: cb81b52c0a39a78b5112773d78acdf10

Issue Description:

Verification crashes on the following test:

Test in forward_mode.swift:

ForwardModeTests.test("Generics") {
  let a = SIMD3<Double>(1, 2, 3)
  let g = SIMD3<Double>(1, 1, 1)

  func testInit<Scalar, SIMDType: SIMD>(x: Scalar) -> SIMDType
    where SIMDType.Scalar == Scalar,
          SIMDType : Differentiable,
          Scalar : BinaryFloatingPoint & Differentiable,
          SIMDType.TangentVector == SIMDType,
          Scalar.TangentVector == Scalar {
    return SIMDType.init(repeating: x)
  }
  func simd3Init(x: Double) -> SIMD3<Double> { testInit(x: x) }
  let (val1, df1) = valueWithDifferential(at: 10, in: simd3Init)
  expectEqual(SIMD3<Double>(10, 10, 10), val1)
  expectEqual(SIMD3<Double>(5, 5, 5), df1(5))

  // SIMDType + SIMDType
  func testAddition<Scalar, SIMDType: SIMD>(lhs: SIMDType, rhs: SIMDType)
    -> SIMDType
    where SIMDType.Scalar == Scalar,
          SIMDType : Differentiable,
          SIMDType.TangentVector : SIMD,
          Scalar : BinaryFloatingPoint,
          SIMDType.TangentVector.Scalar : BinaryFloatingPoint {
    return lhs + rhs
  }
  func simd3Add(lhs: SIMD3<Double>, rhs: SIMD3<Double>) -> SIMD3<Double> {
    return testAddition(lhs: lhs, rhs: rhs)
  }
  let (val2, df2) = valueWithDifferential(at: a, a, in: simd3Add)
  expectEqual(SIMD3<Double>(2, 4, 6), val2)
  expectEqual(g + a, df2(g, a))

  // Scalar - SIMDType
  func testSubtraction<Scalar, SIMDType: SIMD>(lhs: Scalar, rhs: SIMDType)
    -> SIMDType
    where SIMDType.Scalar == Scalar,
          SIMDType : Differentiable,
          Scalar : BinaryFloatingPoint & Differentiable,
          SIMDType.TangentVector == SIMDType,
          Scalar.TangentVector == Scalar {
    return lhs - rhs
  }
  func simd3Subtract(lhs: Double, rhs: SIMD3<Double>) -> SIMD3<Double> {
    return testSubtraction(lhs: lhs, rhs: rhs)
  }
  let (val3, df3) = valueWithDifferential(at: 5, a, in: simd3Subtract)
  expectEqual(SIMD3<Double>(4, 3, 2), val3)
  expectEqual(2 - g, df3(2, g))

  // SIMDType * Scalar
  func testMultipication<Scalar, SIMDType: SIMD>(lhs: SIMDType, rhs: Scalar)
    -> SIMDType
    where SIMDType.Scalar == Scalar,
      SIMDType : Differentiable,
      Scalar : BinaryFloatingPoint & Differentiable,
      SIMDType.TangentVector == SIMDType,
      Scalar.TangentVector == Scalar {
    return lhs * rhs
  }
  func simd3Multiply(lhs: SIMD3<Double>, rhs: Double) -> SIMD3<Double> {
    return testMultipication(lhs: lhs, rhs: rhs)
  }
  let (val4, df4) = valueWithDifferential(at: a, 5, in: simd3Multiply)
  expectEqual(SIMD3<Double>(5, 10, 15), val4)
  expectEqual(a * 3 + g * 5 , df4(g, 3))
}

Running the test:

llvm-project/llvm/utils/lit/lit.py -vvv build/Ninja-ReleaseAssert/swift-linux-x86_64/test-linux-x86_64/AutoDiff/ --filter forward_mode

Relevant part of the output:

SIL verification failed: Found mutating or consuming use of an in_guaranteed parameter?!: !ImmutableAddressUseVerifier().isMutatingOrConsuming(fArg)
Verifying argument:
-> %1 = argument of bb0 : $*τ_0_0                // user: %3
     %3 = apply %2(%0, %1) : $@callee_guaranteed (@in τ_0_0) -> @out τ_0_1
In function:
// thunk for @escaping @callee_guaranteed (@in A) -> (@out B)
sil shared [serialized] [reabstraction_thunk] @$sxq_Iegir_xq_Iegnr_SBRz16_Differentiation14DifferentiableRz13TangentVectorAaBPQzRszs4SIMDR_AaBR_AcDQy_Rs_6Scalars11SIMDStoragePQy_AERSr0_lTR : $@convention(thin) <τ_0_0, τ_0_1 where τ_0_0 : BinaryFloatingPoint, τ_0_0 : Differentiable, τ_0_0 == τ_0_0.TangentVector, τ_0_1 : SIMD, τ_0_1 : Differentiable, τ_0_1 == τ_0_1.TangentVector, τ_0_0.TangentVector == τ_0_1.Scalar> (@in_guaranteed τ_0_0, @guaranteed @callee_guaranteed (@in τ_0_0) -> @out τ_0_1) -> @out τ_0_1 {
// %0                                             // user: %3
// %1                                             // user: %3
// %2                                             // user: %3
bb0(%0 : $*τ_0_1, %1 : $*τ_0_0, %2 : $@callee_guaranteed (@in τ_0_0) -> @out τ_0_1):
  %3 = apply %2(%0, %1) : $@callee_guaranteed (@in τ_0_0) -> @out τ_0_1
  %4 = tuple ()                                   // user: %5
  return %4 : $()                                 // id: %5
} // end sil function '$sxq_Iegir_xq_Iegnr_SBRz16_Differentiation14DifferentiableRz13TangentVectorAaBPQzRszs4SIMDR_AaBR_AcDQy_Rs_6Scalars11SIMDStoragePQy_AERSr0_lTR'
@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior.
Projects
None yet
Development

No branches or pull requests

1 participant