1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright (c) 2022 Marvell. 3 */ 4 5 #ifndef _CN10K_ML_OCM_H_ 6 #define _CN10K_ML_OCM_H_ 7 8 #include <rte_mldev.h> 9 #include <rte_mldev_pmd.h> 10 11 struct cnxk_ml_dev; 12 13 /* Number of OCM tiles. */ 14 #define ML_CN10K_OCM_NUMTILES 0x8 15 16 /* OCM in bytes, per tile. */ 17 #define ML_CN10K_OCM_TILESIZE 0x100000 18 19 /* OCM and Tile information structure */ 20 struct cn10k_ml_ocm_tile_info { 21 /* Mask of used / allotted pages on tile's OCM */ 22 uint8_t *ocm_mask; 23 24 /* Last pages in the tile's OCM used for weights and bias, default = -1 */ 25 int last_wb_page; 26 27 /* Number pages used for scratch memory on the tile's OCM */ 28 uint16_t scratch_pages; 29 }; 30 31 /* Model OCM map structure */ 32 struct cn10k_ml_ocm_layer_map { 33 /* Status of OCM reservation */ 34 bool ocm_reserved; 35 36 /* Mask of OCM tiles for the model */ 37 uint64_t tilemask; 38 39 /* Start page for the model load, default = -1 */ 40 int wb_page_start; 41 42 /* Number of pages required for weights and bias */ 43 uint16_t wb_pages; 44 45 /* Number of pages required for scratch memory */ 46 uint16_t scratch_pages; 47 }; 48 49 /* OCM state structure */ 50 struct cn10k_ml_ocm { 51 /* OCM spinlock, used to update OCM state */ 52 rte_spinlock_t lock; 53 54 /* OCM allocation mode */ 55 const char *alloc_mode; 56 57 /* Number of OCM tiles */ 58 uint8_t num_tiles; 59 60 /* OCM size per each tile */ 61 uint64_t size_per_tile; 62 63 /* Size of OCM page */ 64 uint64_t page_size; 65 66 /* Number of OCM pages */ 67 uint16_t num_pages; 68 69 /* Words per OCM mask */ 70 uint16_t mask_words; 71 72 /* OCM memory info and status*/ 73 struct cn10k_ml_ocm_tile_info tile_ocm_info[ML_CN10K_OCM_NUMTILES]; 74 75 /* Memory for ocm_mask */ 76 uint8_t *ocm_mask; 77 }; 78 79 int cn10k_ml_ocm_tilecount(uint64_t tilemask, int *start, int *end); 80 int cn10k_ml_ocm_tilemask_find(struct cnxk_ml_dev *cnxk_mldev, uint8_t num_tiles, uint16_t wb_pages, 81 uint16_t scratch_pages, uint64_t *tilemask); 82 void cn10k_ml_ocm_reserve_pages(struct cnxk_ml_dev *cnxk_mldev, uint16_t model_id, 83 uint16_t layer_id, uint64_t tilemask, int wb_page_start, 84 uint16_t wb_pages, uint16_t scratch_pages); 85 void cn10k_ml_ocm_free_pages(struct cnxk_ml_dev *cnxk_mldev, uint16_t model_id, uint16_t layer_id); 86 void cn10k_ml_ocm_print(struct cnxk_ml_dev *cnxk_mldev, FILE *fp); 87 88 #endif /* _CN10K_ML_OCM_H_ */ 89