method of MPSCNNConvolution loss in xcode 9.3

After update xcode to 9.3, I can't find the method of MPSCNNConvolution,

public init(device: MTLDevice, convolutionDescriptor: MPSCNNConvolutionDescriptor, kernelWeights: UnsafePointer<Float>, biasTerms: UnsafePointer<Float>?, flags: MPSCNNConvolutionFlags)

and I also can't find some method to instead it in iOS 10.0, can anybody help me ? 😝

Replies

It is gone. :-( I submitted a bug report and Apple responded that this was removed on purpose. The method still exists but it's not part of the API anymore, so you'll have to call it by creating a selector (using the Obj-C runtime).

I'm using swift ~~~ 😕

Hello, could you show some code snippet how to do it. Tried to search for a while but still no idea. Thank you.

The following works. Add this in a .h file to your project:


@import MetalPerformanceShaders;

@interface MPSCNNConvolution (MPSCNNConvolution_iOS10)

-(nonnull instancetype) initWithDevice: (nonnull id <MTLDevice>) device
                 convolutionDescriptor: (const MPSCNNConvolutionDescriptor * __nonnull) convolutionDescriptor
                         kernelWeights: (const float * __nonnull) kernelWeights
                             biasTerms: (const float * __nullable) biasTerms
                                 flags: (MPSCNNConvolutionFlags) flags;

@end


If you're using Swift, also add a bridging header to the project and #include this .h file in the bridging header. Now Xode 9.3 will let you build with the iOS 10 version of MPSCNNConvolution again.

This works when you just want to instanciate directly using that initializer. What however, if your class is derived from MPSCNNConvolution like in the and SlimMPSCNNConvolution class from the apple 2016 example. Then you are reqiured to call a designated initializer ? How to do that ?


class SlimMPSCNNConvolution: MPSCNNConvolution {
...
     init(kernelWidth: UInt, kernelHeight: UInt, inputFeatureChannels: UInt, outputFeatureChannels: UInt, ... and so on...){
          // some code to provide convDesc, w, and b

          // compile time error here !!!!
         super.init(device: device,
               convolutionDescriptor: convDesc,
               kernelWeights: w,
               biasTerms: b,
               flags: MPSCNNConvolutionFlags.none)


          // some code after
    }
...
}


Any solutions for this situation ? Thanks !