/**
 * Copyright (c) 2025 Huawei Technologies Co., Ltd.
 * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
 * CANN Open Software License Agreement Version 2.0 (the "License").
 * Please refer to the License for details. You may not use this file except in compliance with the License.
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
 * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
 * See LICENSE in the root of the software repository for the full text of the License.
 */

syntax = "proto3";
package toolkit.dump;

enum OutputDataType {
    DT_UNDEFINED = 0;
    DT_FLOAT = 1;
    DT_FLOAT16 = 2;
    DT_INT8 = 3;
    DT_UINT8 = 4;
    DT_INT16 = 5;
    DT_UINT16 = 6;
    DT_INT32 = 7;
    DT_INT64 = 8;
    DT_UINT32 = 9;
    DT_UINT64 = 10;
    DT_BOOL = 11;
    DT_DOUBLE = 12;
    DT_STRING = 13;
    DT_DUAL_SUB_INT8 = 14;
    DT_DUAL_SUB_UINT8 = 15;
    DT_COMPLEX64 = 16;
    DT_COMPLEX128 = 17;
    DT_QINT8 = 18;
    DT_QINT16 = 19;
    DT_QINT32 = 20;
    DT_QUINT8 = 21;
    DT_QUINT16 = 22;
    DT_RESOURCE = 23;
    DT_STRING_REF = 24;
    DT_DUAL = 25;
    DT_VARIANT = 26;
    DT_BF16 = 27;              // bf16 type
    DT_INT4 = 28;              // int4 type
    DT_UINT1 = 29;             // uint1 type
    DT_INT2 = 30;              // int2 type
    DT_UINT2 = 31;             // uint2 type
    DT_COMPLEX32 = 32;         // complex32 type
    DT_HIFLOAT8 = 33;
    DT_FLOAT8_E5M2 = 34;
    DT_FLOAT8_E4M3FN = 35;
    DT_FLOAT8_E8M0 = 36;       // float8_e8m0 type
    DT_FLOAT6_E3M2 = 37;       // float6_e3m2 type
    DT_FLOAT6_E2M3 = 38;       // float6_e2m3 type
    DT_FLOAT4_E2M1 = 39;       // float4_e2m1 type
    DT_FLOAT4_E1M2 = 40;       // float4_e1m2 type
    DT_HIFLOAT4 = 41;
}

enum OutputFormat {
    FORMAT_NCHW = 0;
    FORMAT_NHWC = 1;
    FORMAT_ND = 2;
    FORMAT_NC1HWC0 = 3;
    FORMAT_FRACTAL_Z = 4;
    FORMAT_NC1C0HWPAD = 5;
    FORMAT_NHWC1C0 = 6;
    FORMAT_FSR_NCHW = 7;
    FORMAT_FRACTAL_DECONV = 8;
    FORMAT_C1HWNC0 = 9;
    FORMAT_FRACTAL_DECONV_TRANSPOSE = 10;
    FORMAT_FRACTAL_DECONV_SP_STRIDE_TRANS = 11;
    FORMAT_NC1HWC0_C04 = 12;
    FORMAT_FRACTAL_Z_C04 = 13;
    FORMAT_CHWN = 14;
    FORMAT_FRACTAL_DECONV_SP_STRIDE8_TRANS = 15;
    FORMAT_HWCN = 16;
    FORMAT_NC1KHKWHWC0 = 17;
    FORMAT_BN_WEIGHT = 18;
    FORMAT_FILTER_HWCK = 19;
    FORMAT_HASHTABLE_LOOKUP_LOOKUPS=20;
    FORMAT_HASHTABLE_LOOKUP_KEYS = 21;
    FORMAT_HASHTABLE_LOOKUP_VALUE = 22;
    FORMAT_HASHTABLE_LOOKUP_OUTPUT = 23;
    FORMAT_HASHTABLE_LOOKUP_HITS=24;
    FORMAT_C1HWNCoC0 = 25;
    FORMAT_MD = 26;
    FORMAT_NDHWC = 27;
    FORMAT_FRACTAL_ZZ = 28;
    FORMAT_FRACTAL_NZ = 29;
    FORMAT_NCDHW = 30;
    FORMAT_DHWCH = 31;
    FORMAT_NDC1HWC0 = 32;
    FORMAT_FRACTAL_Z_3D = 33;
    FORMAT_CN = 34;
    FORMAT_NC = 35;
    FORMAT_DHWNC = 36;
    FORMAT_FRACTAL_Z_3D_TRANSPOSE = 37;
    FORMAT_FRACTAL_ZN_LSTM = 38;
    FORMAT_FRACTAL_Z_G = 39;
    FORMAT_RESERVED = 40;
    FORMAT_ALL = 41;
    FORMAT_NULL = 42;
    FORMAT_ND_RNN_BIAS = 43;
    FORMAT_FRACTAL_ZN_RNN = 44;
    FORMAT_NYUV = 45;
    FORMAT_NYUV_A = 46;
    FORMAT_NCL = 47;
    FORMAT_FRACTAL_Z_WINO = 48;
    FORMAT_C1HWC0 = 49;
    FORMAT_MAX = 0xff;
}

message OriginalOp {
    string name = 1;
    uint32 output_index = 2;
    OutputDataType data_type = 3;
    OutputFormat format = 4;
}

message Shape {
    repeated uint64 dim = 1;
}

message DimRange {
    uint64 dim_start = 1;
    uint64 dim_end = 2;
}

message OpOutput {
    OutputDataType data_type = 1;
    OutputFormat format = 2;
    Shape shape = 3;
    OriginalOp original_op = 4;  // the original op corresponding to the output
    bytes data = 5;
    uint64 size = 6;
    Shape original_shape = 7;
    int32 sub_format = 8;
    uint64 address = 9;
    repeated DimRange dim_range = 10;
    uint32 arg_index = 11;
}

message OpInput {
    OutputDataType data_type = 1;
    OutputFormat format = 2;
    Shape shape = 3;
    bytes data = 4;
    uint64 size = 5;
    Shape original_shape = 6;
    int32 sub_format = 7;
    uint64 address = 8;
    uint64 offset = 9;
    uint32 arg_index = 10;
    uint32 input_type = 11;
}

enum BufferType {
    L1 = 0;
}

message OpBuffer {
    BufferType buffer_type = 1;
    bytes data = 2;
    uint64 size = 3;
}

message OpAttr {
    string name = 1;
    string value = 2;
}

message Workspace {
    enum SpaceType {
        LOG = 0;
    }
    SpaceType type = 1;
    bytes data = 2;
    uint64 size = 3;
    uint32 arg_index = 4;
}

message DumpData{
    string version = 1;
    uint64 dump_time = 2;
    repeated OpOutput output = 3;
    repeated OpInput input = 4;
    repeated OpBuffer buffer = 5;
    string op_name = 6;
    repeated OpAttr attr = 7;
    repeated Workspace space = 8;
    string dfx_message = 9;
}