From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id ABED8A0093; Thu, 8 Dec 2022 21:03:21 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id AF13E42D55; Thu, 8 Dec 2022 21:02:36 +0100 (CET) Received: from mx0b-0016f401.pphosted.com (mx0b-0016f401.pphosted.com [67.231.156.173]) by mails.dpdk.org (Postfix) with ESMTP id 7C4DC42D24 for ; Thu, 8 Dec 2022 21:02:29 +0100 (CET) Received: from pps.filterd (m0045851.ppops.net [127.0.0.1]) by mx0b-0016f401.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 2B8JjesG004916 for ; Thu, 8 Dec 2022 12:02:28 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=pfpt0220; bh=8a12XVrzV4TOO6eBz39aPqWKwjxx05pE+GA+fFwqFwM=; b=TrdR1eQyDsZqqaGVAqPTUteckdFYXBLQ0PNMrIJCaRT0TNUlw4kaS3eVbJpBabzyJhf5 TIBuoSb98spvdkyE/q7n1I2TaiFwlucgAaKYrbfeGdUBxkew0svEapjZe1pRiCH+EfpY NiwyHkAADn8nGejgPjpvQhM24zoTuXYlOF0gMbLAHU6wDlzvw1069K+bHXQs4wqSO5// 53tfKCHU3OxKr2zCHXkt0bDLMgFXQrn7/e5shcW1nI/OZTEFQJm0jcSD5hZMMV26IzHh ZefmTt6Vx7amFs9meyYlXzG7DdOXzzK1/jSMv/wAaC6Aap6ruF+Z31xcfQkp7uZNeq+A JA== Received: from dc5-exch02.marvell.com ([199.233.59.182]) by mx0b-0016f401.pphosted.com (PPS) with ESMTPS id 3m86usnfsu-3 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Thu, 08 Dec 2022 12:02:28 -0800 Received: from DC5-EXCH01.marvell.com (10.69.176.38) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Thu, 8 Dec 2022 12:02:26 -0800 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Thu, 8 Dec 2022 12:02:26 -0800 Received: from ml-host-33.caveonetworks.com (unknown [10.110.143.233]) by maili.marvell.com (Postfix) with ESMTP id 5DE133F7059; Thu, 8 Dec 2022 12:02:26 -0800 (PST) From: Srikanth Yalavarthi To: Srikanth Yalavarthi CC: , , , Subject: [PATCH v1 12/37] ml/cnxk: add internal structures for derived info Date: Thu, 8 Dec 2022 12:01:55 -0800 Message-ID: <20221208200220.20267-13-syalavarthi@marvell.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20221208200220.20267-1-syalavarthi@marvell.com> References: <20221208200220.20267-1-syalavarthi@marvell.com> MIME-Version: 1.0 Content-Type: text/plain X-Proofpoint-GUID: Ujoi_416AJaWrEY-T0YjoTgvIf4W9W8D X-Proofpoint-ORIG-GUID: Ujoi_416AJaWrEY-T0YjoTgvIf4W9W8D X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.923,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2022-12-08_11,2022-12-08_01,2022-06-22_01 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Added internal structures to handle derived address fields and enabled support to compute DMA addresses for model start. Enabled updating internal model fields. Signed-off-by: Srikanth Yalavarthi --- drivers/ml/cnxk/cn10k_ml_model.c | 88 ++++++++++++++++++++++++++++++++ drivers/ml/cnxk/cn10k_ml_model.h | 80 +++++++++++++++++++++++++++++ drivers/ml/cnxk/cn10k_ml_ops.c | 18 ++++++- 3 files changed, 185 insertions(+), 1 deletion(-) diff --git a/drivers/ml/cnxk/cn10k_ml_model.c b/drivers/ml/cnxk/cn10k_ml_model.c index 6f803ce6a5..72b52fce8d 100644 --- a/drivers/ml/cnxk/cn10k_ml_model.c +++ b/drivers/ml/cnxk/cn10k_ml_model.c @@ -199,3 +199,91 @@ cn10k_ml_model_metadata_update(struct cn10k_ml_model_metadata *metadata) cn10k_ml_io_type_map(metadata->output[i].model_output_type); } } + +void +cn10k_ml_model_addr_update(struct cn10k_ml_model *model, uint8_t *buffer, uint8_t *base_dma_addr) +{ + struct cn10k_ml_model_metadata *metadata; + struct cn10k_ml_model_addr *addr; + size_t model_data_size; + uint8_t *dma_addr_load; + uint8_t *dma_addr_run; + uint8_t i; + int fpos; + + metadata = &model->metadata; + addr = &model->addr; + model_data_size = metadata->init_model.file_size + metadata->main_model.file_size + + metadata->finish_model.file_size + metadata->weights_bias.file_size; + + /* Base address */ + addr->base_dma_addr_load = base_dma_addr; + addr->base_dma_addr_run = PLT_PTR_ADD(addr->base_dma_addr_load, model_data_size); + + /* Init Section */ + dma_addr_load = addr->base_dma_addr_load; + dma_addr_run = addr->base_dma_addr_run; + fpos = sizeof(struct cn10k_ml_model_metadata); + addr->init_load_addr = dma_addr_load; + addr->init_run_addr = dma_addr_run; + memcpy(dma_addr_load, PLT_PTR_ADD(buffer, fpos), metadata->init_model.file_size); + + /* Main Section */ + dma_addr_load += metadata->init_model.file_size; + dma_addr_run += metadata->init_model.file_size; + fpos += metadata->init_model.file_size; + addr->main_load_addr = dma_addr_load; + addr->main_run_addr = dma_addr_run; + memcpy(dma_addr_load, PLT_PTR_ADD(buffer, fpos), metadata->main_model.file_size); + + /* Finish Section */ + dma_addr_load += metadata->main_model.file_size; + dma_addr_run += metadata->main_model.file_size; + fpos += metadata->main_model.file_size; + addr->finish_load_addr = dma_addr_load; + addr->finish_run_addr = dma_addr_run; + memcpy(dma_addr_load, PLT_PTR_ADD(buffer, fpos), metadata->finish_model.file_size); + + /* Weights & Bias Section*/ + dma_addr_load += metadata->finish_model.file_size; + fpos += metadata->finish_model.file_size; + addr->wb_base_addr = PLT_PTR_SUB(dma_addr_load, metadata->weights_bias.mem_offset); + addr->wb_load_addr = PLT_PTR_ADD(addr->wb_base_addr, metadata->weights_bias.mem_offset); + memcpy(addr->wb_load_addr, PLT_PTR_ADD(buffer, fpos), metadata->weights_bias.file_size); + + /* Inputs */ + addr->total_input_sz_d = 0; + addr->total_input_sz_q = 0; + for (i = 0; i < metadata->model.num_input; i++) { + addr->input[i].nb_elements = + model->metadata.input[i].shape.w * model->metadata.input[i].shape.x * + model->metadata.input[i].shape.y * model->metadata.input[i].shape.z; + addr->input[i].sz_d = addr->input[i].nb_elements * + ml_io_type_size_get(metadata->input[i].input_type); + addr->input[i].sz_q = addr->input[i].nb_elements * + ml_io_type_size_get(metadata->input[i].model_input_type); + addr->total_input_sz_d += addr->input[i].sz_d; + addr->total_input_sz_q += addr->input[i].sz_q; + + plt_ml_dbg("model_id = %d, input[%u] - w:%u x:%u y:%u z:%u, sz_d = %u sz_q = %u", + model->model_id, i, metadata->input[i].shape.w, + metadata->input[i].shape.x, metadata->input[i].shape.y, + metadata->input[i].shape.z, addr->input[i].sz_d, addr->input[i].sz_q); + } + + /* Outputs */ + addr->total_output_sz_q = 0; + addr->total_output_sz_d = 0; + for (i = 0; i < metadata->model.num_output; i++) { + addr->output[i].nb_elements = metadata->output[i].size; + addr->output[i].sz_d = addr->output[i].nb_elements * + ml_io_type_size_get(metadata->output[i].output_type); + addr->output[i].sz_q = addr->output[i].nb_elements * + ml_io_type_size_get(metadata->output[i].model_output_type); + addr->total_output_sz_q += addr->output[i].sz_q; + addr->total_output_sz_d += addr->output[i].sz_d; + + plt_ml_dbg("model_id = %d, output[%u] - sz_d = %u, sz_q = %u", model->model_id, i, + addr->output[i].sz_d, addr->output[i].sz_q); + } +} diff --git a/drivers/ml/cnxk/cn10k_ml_model.h b/drivers/ml/cnxk/cn10k_ml_model.h index eb031c6fb2..02a119cdd8 100644 --- a/drivers/ml/cnxk/cn10k_ml_model.h +++ b/drivers/ml/cnxk/cn10k_ml_model.h @@ -325,6 +325,81 @@ struct cn10k_ml_model_metadata { uint8_t reserved3[16]; }; +/* Model address structure */ +struct cn10k_ml_model_addr { + /* Base DMA address for load */ + void *base_dma_addr_load; + + /* Base DMA address for run */ + void *base_dma_addr_run; + + /* Init section load address */ + void *init_load_addr; + + /* Init section run address */ + void *init_run_addr; + + /* Main section load address */ + void *main_load_addr; + + /* Main section run address */ + void *main_run_addr; + + /* Finish section load address */ + void *finish_load_addr; + + /* Finish section run address */ + void *finish_run_addr; + + /* Weights and Bias base address */ + void *wb_base_addr; + + /* Weights and bias load address */ + void *wb_load_addr; + + /* Start tile */ + uint8_t tile_start; + + /* End tile */ + uint8_t tile_end; + + /* Input address and size */ + struct { + /* Number of elements */ + uint32_t nb_elements; + + /* Dequantized input size */ + uint32_t sz_d; + + /* Quantized input size */ + uint32_t sz_q; + } input[MRVL_ML_INPUT_OUTPUT_SIZE]; + + /* Output address and size */ + struct { + /* Number of elements */ + uint32_t nb_elements; + + /* Dequantize output size */ + uint32_t sz_d; + + /* Quantized output size */ + uint32_t sz_q; + } output[MRVL_ML_INPUT_OUTPUT_SIZE]; + + /* Total size of quantized input */ + uint32_t total_input_sz_q; + + /* Total size of dequantized input */ + uint32_t total_input_sz_d; + + /* Total size of quantized output */ + uint32_t total_output_sz_q; + + /* Total size of dequantized output */ + uint32_t total_output_sz_d; +}; + /* ML Model Object */ struct cn10k_ml_model { /* Device reference */ @@ -342,6 +417,9 @@ struct cn10k_ml_model { /* Model metadata */ struct cn10k_ml_model_metadata metadata; + /* Model address structure */ + struct cn10k_ml_model_addr addr; + /* Model lock, used to update model state */ plt_spinlock_t lock; @@ -351,5 +429,7 @@ struct cn10k_ml_model { int cn10k_ml_model_metadata_check(uint8_t *buffer, uint64_t size); void cn10k_ml_model_metadata_update(struct cn10k_ml_model_metadata *metadata); +void cn10k_ml_model_addr_update(struct cn10k_ml_model *model, uint8_t *buffer, + uint8_t *base_dma_addr); #endif /* _CN10K_ML_MODEL_H_ */ diff --git a/drivers/ml/cnxk/cn10k_ml_ops.c b/drivers/ml/cnxk/cn10k_ml_ops.c index 171428794e..6bf365d185 100644 --- a/drivers/ml/cnxk/cn10k_ml_ops.c +++ b/drivers/ml/cnxk/cn10k_ml_ops.c @@ -408,11 +408,14 @@ cn10k_ml_dev_queue_pair_setup(struct rte_ml_dev *dev, uint16_t queue_pair_id, int cn10k_ml_model_load(struct rte_ml_dev *dev, struct rte_ml_model_params *params, int16_t *model_id) { + struct cn10k_ml_model_metadata *metadata; struct cn10k_ml_model *model; struct cn10k_ml_dev *mldev; char str[RTE_MEMZONE_NAMESIZE]; const struct plt_memzone *mz; + size_t model_data_size; + uint8_t *base_dma_addr; uint64_t mz_size; uint16_t idx; bool found; @@ -439,7 +442,12 @@ cn10k_ml_model_load(struct rte_ml_dev *dev, struct rte_ml_model_params *params, } /* Get MZ size */ - mz_size = PLT_ALIGN_CEIL(sizeof(struct cn10k_ml_model), ML_CN10K_ALIGN_SIZE); + metadata = (struct cn10k_ml_model_metadata *)params->addr; + model_data_size = metadata->init_model.file_size + metadata->main_model.file_size + + metadata->finish_model.file_size + metadata->weights_bias.file_size; + model_data_size = PLT_ALIGN_CEIL(model_data_size, ML_CN10K_ALIGN_SIZE); + mz_size = PLT_ALIGN_CEIL(sizeof(struct cn10k_ml_model), ML_CN10K_ALIGN_SIZE) + + 2 * model_data_size; /* Allocate memzone for model object and model data */ snprintf(str, RTE_MEMZONE_NAMESIZE, "%s_%u", CN10K_ML_MODEL_MEMZONE_NAME, idx); @@ -462,6 +470,14 @@ cn10k_ml_model_load(struct rte_ml_dev *dev, struct rte_ml_model_params *params, else model->batch_size = model->metadata.model.batch_size; + /* Set DMA base address */ + base_dma_addr = PLT_PTR_ADD( + mz->addr, PLT_ALIGN_CEIL(sizeof(struct cn10k_ml_model), ML_CN10K_ALIGN_SIZE)); + cn10k_ml_model_addr_update(model, params->addr, base_dma_addr); + + /* Copy data from load to run. run address to be used by MLIP */ + memcpy(model->addr.base_dma_addr_run, model->addr.base_dma_addr_load, model_data_size); + plt_spinlock_init(&model->lock); model->state = ML_CN10K_MODEL_STATE_LOADED; dev->data->models[idx] = model; -- 2.17.1