Adding CoreML codegen with the BYOC feature enables us to offload subgraphs to 
Apple’s Neural Engine on iOS devices. There are some approaches how to build a 
CoreML model in TVM.

- A0: Build with coremltools

  I think this is the most intuitive way to construct CoreML models.  
coremltools provides good 
[APIs](https://apple.github.io/coremltools/generated/coremltools.models.neural_network.builder.html)
 and they are well documented. My concern is that we need to implement codegen 
with Python to use coremltools.  I wonder if there is any limitation to 
implement external codegen with Python.

- A1: Generate protobuf from Core ML specification

  Core ML model format is protobuf and its specification is available 
[here](https://github.com/apple/coremltools/tree/master/mlmodel/format), so we 
can create Core ML model with generated .pb.h and .pb.cc files. TFLite also 
takes this approach to implement Core ML Delegate. We can implement CoreML 
codegen flexibly, but it looks a harder way to go than A0.

- A2: Convert ONNX models

  We can use [onnx-coreml](https://github.com/onnx/onnx-coreml) to convert 
generated ONNX models by [this 
feature](https://discuss.tvm.ai/t/rfc-relay-to-onnx/6101).  We don't need to 
maintenance codes to build CoreML models, but I'm not sure how the 
implementation would be.  The flexibility of the output CoreML model might be 
limited by the intermediate ONNX model.

I've implemented [a prototype of 
A0](https://github.com/kazum/tvm/tree/coreml_codegen), which supports only add 
and multiply, on top of [CoreML 
runtime](https://github.com/apache/incubator-tvm/pull/5283). It looks working 
well at this point.

Any comments are welcome :)

@tqchen @ziheng @FrozenGene @thierry





---
[Visit Topic](https://discuss.tvm.ai/t/rfc-coreml-codegen/6415/1) to respond.

You are receiving this because you enabled mailing list mode.

To unsubscribe from these emails, [click 
here](https://discuss.tvm.ai/email/unsubscribe/2b410852728a40c0875cffb4eee2f8c9901e12dcb1b5171c3e0440001fdca33a).

Reply via email to