[PATCH v1 30/34] ml/cnxk: implement I/O alloc and free callbacks
Srikanth Yalavarthi
syalavarthi at marvell.com
Wed Aug 30 17:59:20 CEST 2023
Implemented callback functions for IO allocation and free
for Glow layers.
Signed-off-by: Srikanth Yalavarthi <syalavarthi at marvell.com>
---
drivers/ml/cnxk/cn10k_ml_ops.c | 123 +++++++++++++++++++++++++++++++++
drivers/ml/cnxk/cn10k_ml_ops.h | 3 +
drivers/ml/cnxk/mvtvm_ml_ops.c | 2 +
3 files changed, 128 insertions(+)
diff --git a/drivers/ml/cnxk/cn10k_ml_ops.c b/drivers/ml/cnxk/cn10k_ml_ops.c
index f70383b1281..23e98b96c59 100644
--- a/drivers/ml/cnxk/cn10k_ml_ops.c
+++ b/drivers/ml/cnxk/cn10k_ml_ops.c
@@ -1399,3 +1399,126 @@ cn10k_ml_inference_sync(void *device, uint16_t index, void *input, void *output,
error_enqueue:
return ret;
}
+
+int
+cn10k_ml_io_alloc(void *device, uint16_t model_id, const char *layer_name, uint64_t **input_qbuffer,
+ uint64_t **output_qbuffer)
+{
+ struct cnxk_ml_dev *cnxk_mldev;
+ struct cnxk_ml_model *model;
+ struct cnxk_ml_layer *layer;
+
+ char str[RTE_MEMZONE_NAMESIZE];
+ const struct plt_memzone *mz;
+ uint16_t layer_id = 0;
+ uint64_t output_size;
+ uint64_t input_size;
+
+#ifndef RTE_MLDEV_CNXK_ENABLE_MVTVM
+ PLT_SET_USED(layer_name);
+#endif
+
+ cnxk_mldev = (struct cnxk_ml_dev *)device;
+ if (cnxk_mldev == NULL) {
+ plt_err("Invalid device = %p", cnxk_mldev);
+ return -EINVAL;
+ }
+
+ model = cnxk_mldev->mldev->data->models[model_id];
+ if (model == NULL) {
+ plt_err("Invalid model_id = %u", model_id);
+ return -EINVAL;
+ }
+
+#ifdef RTE_MLDEV_CNXK_ENABLE_MVTVM
+ if (model->type == ML_CNXK_MODEL_TYPE_TVM) {
+ for (layer_id = 0; layer_id < model->mvtvm.metadata.model.nb_layers; layer_id++) {
+ if (strcmp(model->layer[layer_id].name, layer_name) == 0)
+ break;
+ }
+
+ if (layer_id == model->mvtvm.metadata.model.nb_layers) {
+ plt_err("Invalid layer name: %s", layer_name);
+ return -EINVAL;
+ }
+
+ if (model->layer[layer_id].type != ML_CNXK_LAYER_TYPE_MRVL) {
+ plt_err("Invalid layer name / type: %s", layer_name);
+ return -EINVAL;
+ }
+ }
+#endif
+
+ layer = &model->layer[layer_id];
+ input_size = PLT_ALIGN_CEIL(layer->info.total_input_sz_q, ML_CN10K_ALIGN_SIZE);
+ output_size = PLT_ALIGN_CEIL(layer->info.total_output_sz_q, ML_CN10K_ALIGN_SIZE);
+
+ sprintf(str, "cn10k_ml_io_mz_%u_%u", model_id, layer_id);
+ mz = plt_memzone_reserve_aligned(str, input_size + output_size, 0, ML_CN10K_ALIGN_SIZE);
+ if (mz == NULL) {
+ plt_err("io_alloc failed: Unable to allocate memory: model_id = %u, layer_name = %s",
+ model_id, layer_name);
+ return -ENOMEM;
+ }
+
+ *input_qbuffer = mz->addr;
+ *output_qbuffer = PLT_PTR_ADD(mz->addr, input_size);
+
+ return 0;
+}
+
+int
+cn10k_ml_io_free(void *device, uint16_t model_id, const char *layer_name)
+{
+ struct cnxk_ml_dev *cnxk_mldev;
+ struct cnxk_ml_model *model;
+
+ char str[RTE_MEMZONE_NAMESIZE];
+ const struct plt_memzone *mz;
+ uint16_t layer_id = 0;
+
+#ifndef RTE_MLDEV_CNXK_ENABLE_MVTVM
+ PLT_SET_USED(layer_name);
+#endif
+
+ cnxk_mldev = (struct cnxk_ml_dev *)device;
+ if (cnxk_mldev == NULL) {
+ plt_err("Invalid device = %p", cnxk_mldev);
+ return -EINVAL;
+ }
+
+ model = cnxk_mldev->mldev->data->models[model_id];
+ if (model == NULL) {
+ plt_err("Invalid model_id = %u", model_id);
+ return -EINVAL;
+ }
+
+#ifdef RTE_MLDEV_CNXK_ENABLE_MVTVM
+ if (model->type == ML_CNXK_MODEL_TYPE_TVM) {
+ for (layer_id = 0; layer_id < model->mvtvm.metadata.model.nb_layers; layer_id++) {
+ if (strcmp(model->layer[layer_id].name, layer_name) == 0)
+ break;
+ }
+
+ if (layer_id == model->mvtvm.metadata.model.nb_layers) {
+ plt_err("Invalid layer name: %s", layer_name);
+ return -EINVAL;
+ }
+
+ if (model->layer[layer_id].type != ML_CNXK_LAYER_TYPE_MRVL) {
+ plt_err("Invalid layer name / type: %s", layer_name);
+ return -EINVAL;
+ }
+ }
+#endif
+
+ sprintf(str, "cn10k_ml_io_mz_%u_%u", model_id, layer_id);
+ mz = plt_memzone_lookup(str);
+ if (mz == NULL) {
+ plt_err("io_free failed: Memzone not found: model_id = %u, layer_name = %s",
+ model_id, layer_name);
+ return -EINVAL;
+ }
+
+ return plt_memzone_free(mz);
+}
diff --git a/drivers/ml/cnxk/cn10k_ml_ops.h b/drivers/ml/cnxk/cn10k_ml_ops.h
index 3e75cae65a3..055651eaa24 100644
--- a/drivers/ml/cnxk/cn10k_ml_ops.h
+++ b/drivers/ml/cnxk/cn10k_ml_ops.h
@@ -328,5 +328,8 @@ int cn10k_ml_layer_load(void *device, uint16_t model_id, const char *layer_name,
int cn10k_ml_layer_unload(void *device, uint16_t model_id, const char *layer_name);
int cn10k_ml_layer_start(void *device, uint16_t model_id, const char *layer_name);
int cn10k_ml_layer_stop(void *device, uint16_t model_id, const char *layer_name);
+int cn10k_ml_io_alloc(void *device, uint16_t model_id, const char *layer_name,
+ uint64_t **input_qbuffer, uint64_t **output_qbuffer);
+int cn10k_ml_io_free(void *device, uint16_t model_id, const char *layer_name);
#endif /* _CN10K_ML_OPS_H_ */
diff --git a/drivers/ml/cnxk/mvtvm_ml_ops.c b/drivers/ml/cnxk/mvtvm_ml_ops.c
index c251579668c..821b3e8f3c9 100644
--- a/drivers/ml/cnxk/mvtvm_ml_ops.c
+++ b/drivers/ml/cnxk/mvtvm_ml_ops.c
@@ -166,6 +166,8 @@ mvtvm_ml_model_load(struct cnxk_ml_dev *cnxk_mldev, struct rte_ml_model_params *
callback = &model->mvtvm.cb;
callback->tvmrt_glow_layer_load = cn10k_ml_layer_load;
callback->tvmrt_glow_layer_unload = cn10k_ml_layer_unload;
+ callback->tvmrt_io_alloc = cn10k_ml_io_alloc;
+ callback->tvmrt_io_free = cn10k_ml_io_free;
} else {
callback = NULL;
}
--
2.41.0
More information about the dev
mailing list