hollance / Forge

A neural network toolkit for Metal
MIT License
1.27k stars 172 forks source link

EXC_BAD_ACCESS on release executions #27

Closed LightMan closed 6 years ago

LightMan commented 6 years ago

I tried to run this project using the release version and they all crash at:

mpscnn = MPSCNNFullyConnected(device: device, convolutionDescriptor: desc, kernelWeights: weights.pointer, biasTerms: biasTerms, flags: .none)

In createCompute of layers.swift

Only MNIST project, which does not use Forge, seems to work.

This means that an app using this library cannot be compiled to be sent to the app store, ad hoc or enterprise distribution.

hollance commented 6 years ago

What version of iOS are you trying this on? I think I know why this happens but didn't see it on my devices yet.

LightMan commented 6 years ago

Hi @hollance I am using an iPhone 6 64gb running iOS 11.1 (15B93)

hollance commented 6 years ago

This is actually an issue I ran into before and thought I had fixed but apparently not. With optimizations enabled, Swift deallocates the object containing the bias terms for the layer before the layer gets constructed. This seems like a compiler error since there are still (optional) objects with a reference to this object and so it gets deallocated too soon. It also doesn't happen with optimizations disabled. I'll see if I can find a workaround.

hollance commented 6 years ago

This should be fixed in https://github.com/hollance/Forge/commit/14a6d7229c8e8c14c0d18f429c91fd628d694067

Let me know if it works! 😄