diff --git a/source/mlir.js b/source/mlir.js new file mode 100644 index 0000000000..5bddc20481 --- /dev/null +++ b/source/mlir.js @@ -0,0 +1,72 @@ + +var mlir = {}; +var text = require('./text'); + +mlir.ModelFactory = class { + + match(context) { + const stream = context.stream; + if (stream) { + const reader = text.Reader.open(stream, 2048); + for (;;) { + const line = reader.read(); + if (line === undefined) { + break; + } + if (line.indexOf('module ') !== -1) { + return 'mlir'; + } + } + } + return null; + } + + open(context) { + const stream = context.stream; + const decoder = text.Decoder.open(stream); + new mlir.Parser(decoder); + throw new mlir.Error('MLIR support is not implemented.'); + } +}; + +mlir.Model = class { + + constructor() { + this._format = 'MLIR'; + this._graphs = []; + } + + get format() { + return this._format; + } + + get graphs() { + return this._graphs; + } +}; + +mlir.Tokenizer = class { + + constructor(decoder) { + this._decoder = decoder; + } +}; + +mlir.Parser = class { + + constructor(decoder) { + this._tokenizer = new mlir.Tokenizer(decoder); + } +}; + +mlir.Error = class extends Error { + + constructor(message) { + super(message); + this.name = 'Error loading MLIR model.'; + } +}; + +if (typeof module !== 'undefined' && typeof module.exports === 'object') { + module.exports.ModelFactory = mlir.ModelFactory; +} diff --git a/source/view.js b/source/view.js index 7f0a804ba8..41785e1398 100644 --- a/source/view.js +++ b/source/view.js @@ -4533,6 +4533,7 @@ view.ModelFactoryService = class { this.register('./nnef', [ '.nnef', '.dat' ]); this.register('./cambricon', [ '.cambricon' ]); this.register('./onednn', [ '.json']); + this.register('./mlir', [ '.mlir']); } register(id, factories, containers) { diff --git a/test/models.json b/test/models.json index 612cc34fd1..2f5bd6613f 100644 --- a/test/models.json +++ b/test/models.json @@ -2772,6 +2772,20 @@ "source": "https://raw.githubusercontent.com/dotnet/machinelearning-samples/61b428c746f39069a9d1d92f9e0f819e6beb30f3/samples/csharp/end-to-end-apps/DeepLearning_ObjectDetection_Onnx/OnnxObjectDetectionE2EAPP/ML/MLNETModel/TinyYoloModel.zip", "format": "ML.NET v1.0.27701.1" }, + { + "type": "mlir", + "target": "examples.mnist_xla.mlir", + "source": "https://github.com/lutzroeder/netron/files/10672271/examples.mnist_xla.mlir.zip[examples.mnist_xla.mlir]", + "error": "MLIR support is not implemented.", + "link": "https://github.com/lutzroeder/netron/issues/1044" + }, + { + "type": "mlir", + "target": "issue_1043.mlir", + "source": "https://github.com/lutzroeder/netron/files/10672270/issue_1043.mlir.zip[issue_1043.mlir]", + "error": "MLIR support is not implemented.", + "link": "https://github.com/lutzroeder/netron/issues/1044" + }, { "type": "mnn", "target": "blazeface.mnn",