Skip to content

Commit

Permalink
mldev: add scale and zero point to I/O info struct
Browse files Browse the repository at this point in the history
Added scale and zero point to I/O information structure.
This would provision sharing the recommended scale factor
and zero point to the user for quantization process.

Signed-off-by: Srikanth Yalavarthi <syalavarthi@marvell.com>
  • Loading branch information
syalavarthi authored and tmonjalo committed Oct 17, 2024
1 parent 65282e9 commit fe8eba6
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 2 deletions.
4 changes: 4 additions & 0 deletions drivers/ml/cnxk/cn10k_ml_model.c
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,8 @@ cn10k_ml_model_info_set(struct cnxk_ml_dev *cnxk_mldev, struct cnxk_ml_model *mo
input[i].nb_elements = io_info->input[i].nb_elements;
input[i].size = io_info->input[i].nb_elements *
rte_ml_io_type_size_get(io_info->input[i].qtype);
input[i].scale = 1.0 / io_info->input[i].scale;
input[i].zero_point = 0;
}

/* Set output info */
Expand All @@ -597,6 +599,8 @@ cn10k_ml_model_info_set(struct cnxk_ml_dev *cnxk_mldev, struct cnxk_ml_model *mo
output[i].nb_elements = io_info->output[i].nb_elements;
output[i].size = io_info->output[i].nb_elements *
rte_ml_io_type_size_get(io_info->output[i].qtype);
output[i].scale = io_info->output[i].scale;
output[i].zero_point = 0;
}
}

Expand Down
3 changes: 3 additions & 0 deletions drivers/ml/cnxk/cnxk_ml_io.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ struct cnxk_ml_io {

/* Scale */
float scale;

/* Zero point */
int64_t zero_point;
};

/* Model / Layer IO structure */
Expand Down
4 changes: 4 additions & 0 deletions drivers/ml/cnxk/mvtvm_ml_model.c
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,8 @@ mvtvm_ml_model_info_set(struct cnxk_ml_dev *cnxk_mldev, struct cnxk_ml_model *mo
input[i].nb_elements = model->mvtvm.info.input[i].nb_elements;
input[i].size = model->mvtvm.info.input[i].nb_elements *
rte_ml_io_type_size_get(model->mvtvm.info.input[i].qtype);
input[i].scale = model->mvtvm.info.input[i].scale;
input[i].zero_point = 0;
}

/* Set output info */
Expand All @@ -345,6 +347,8 @@ mvtvm_ml_model_info_set(struct cnxk_ml_dev *cnxk_mldev, struct cnxk_ml_model *mo
output[i].nb_elements = model->mvtvm.info.output[i].nb_elements;
output[i].size = model->mvtvm.info.output[i].nb_elements *
rte_ml_io_type_size_get(model->mvtvm.info.output[i].qtype);
input[i].scale = model->mvtvm.info.output[i].scale;
input[i].zero_point = 0;
}

return;
Expand Down
8 changes: 6 additions & 2 deletions lib/mldev/rte_mldev.h
Original file line number Diff line number Diff line change
Expand Up @@ -947,9 +947,13 @@ struct rte_ml_io_info {
* @see enum rte_ml_io_type
*/
uint64_t nb_elements;
/** Number of elements in tensor */
/**< Number of elements in tensor */
uint64_t size;
/** Size of tensor in bytes */
/**< Size of tensor in bytes */
float scale;
/**< Scale factor */
int64_t zero_point;
/**< Zero point */
};

/** Model information structure */
Expand Down

0 comments on commit fe8eba6

Please sign in to comment.