/**
 * Copyright 2019 Huawei Technologies Co., Ltd
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

include "ops.fbs";

namespace mindspore.schema;

// This corresponds to the version.
file_identifier "MSL2";
// File extension of any written files.
file_extension "ms";

table QuantParam {
    scale: double = 1;
    zeroPoint: int = 0;
    min: double = 0;
    max: double = 0;
    narrowRange: bool = true;
    numBits: int = 8;
    inited: bool = false;
    varCorr: float = 1;
    meanCorr: float = 0;
    dstDtype: int = 32;
    roundType: int = 1;
    multiplier: int = 1; // calculate fixed point multiplier method
}

enum WeightQuantCompressType: int {
    NONE,
    INDEXING,
    SPARSE,
    FSE,
    BITPACKING,
    FSE_INT,
    FSE_INFER,
}

table ExternalData {
    checkSum: string;
    location: string;
    offset: int64 = 0;
    length: int64 = -1;
}

table Tensor {
    nodeType: int;
    // data type
    dataType: int;
    // shape
    dims: [int];
    format: Format;
    refCount: int;
    offset: int;
    data: [ubyte];
    quantParams: [QuantParam];
    quantClusters: [float];
    name: string;
    enableHuffmanCode: bool = false;
    weightQuantCompressType: WeightQuantCompressType = NONE;
    externalData: [ExternalData];
}

enum QuantType: int {
    QUANT_NONE,
    AwareTraining, // deprecated, use QUANT_ALL instead
    WeightQuant,  // deprecated, use QUANT_WEIGHT instead
    PostTraining, // deprecated, use QUANT_ALL instead
    QUANT_WEIGHT,
    QUANT_ALL,
    QUANT_DYNAMIC,
}

table Primitive {
    value: PrimitiveType;
}

table CNode {
    name: string;
    nodeType: int (deprecated);
    primitive: Primitive;
    inputIndex: [uint];
    outputIndex: [uint];
    quantType: QuantType = QUANT_NONE;
    deviceType: int = -1; // 1 = CPU, 2 = GPU, 3 = NPU, -1 = UNKNOWN
}

table SubGraph {
    name:string;
    inputIndices: [uint];
    outputIndices: [uint];
    nodeIndices: [uint];
    tensorIndices: [uint];
}

table MetaGraph {
    name: string;
    version: string;
    fmkType: int; // 0:tf,1:caffe
    inputIndex: [uint];
    outputIndex: [uint];
    mempoolSize: uint;
    nodes: [CNode];
    allTensors: [Tensor]; // weight + input + output
    subGraph : [SubGraph];
    obfuscate: bool = false;
    encrypt : bool = false;
    obfMetaData: [ubyte];
    decryptTable: [ubyte];
}

root_type MetaGraph;