1 /* Copyright 2024 Advanced Micro Devices, Inc. 2 * 3 * Permission is hereby granted, free of charge, to any person obtaining a 4 * copy of this software and associated documentation files (the "Software"), 5 * to deal in the Software without restriction, including without limitation 6 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 7 * and/or sell copies of the Software, and to permit persons to whom the 8 * Software is furnished to do so, subject to the following conditions: 9 * 10 * The above copyright notice and this permission notice shall be included in 11 * all copies or substantial portions of the Software. 12 * 13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 16 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR 17 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 18 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 19 * OTHER DEALINGS IN THE SOFTWARE. 20 * 21 * Authors: AMD 22 * 23 */ 24 25 #pragma once 26 27 #include "vpe_types.h" 28 #include "resource.h" 29 30 #ifdef __cplusplus 31 extern "C" { 32 #endif 33 34 struct vpe_priv; 35 36 struct vpe_vector { 37 struct vpe_priv *vpe_priv; /*< store the vpe_priv for alloc/free memory */ 38 39 void *element; /*< the internal vector memory storage */ 40 size_t num_elements; /*< number of stored elements */ 41 size_t capacity; 42 /*< size of the storage space currently allocated for the vector */ 43 size_t element_size; /*< size of elements in bytes */ 44 }; 45 46 /** 47 * Create the vector. 48 * @param[in] vpe_priv vpe instance created by vpe_create() 49 * @param[in] element_size size of each element of this vector. 50 * @param[in] initial_capacity initial capacity of the vector. 51 */ 52 struct vpe_vector *vpe_vector_create( 53 struct vpe_priv *vpe_priv, size_t element_size, size_t initial_capacity); 54 55 /** 56 * Get the specific element from vector by index. 57 * @param[in] vector vector that we want to get the element from. 58 * @param[in] idx index 59 */ 60 void *vpe_vector_get(struct vpe_vector *vector, size_t idx); 61 62 /** 63 * Push the element to end of the vector. 64 * @param[in] vector vector that we want to push to the end. 65 * @param[in] p_element pointer of the element 66 */ 67 void vpe_vector_push(struct vpe_vector *vector, void *p_element); 68 69 /** 70 * Clear the vector. 71 * @param[in] vector vector that we want to clear. 72 */ 73 void vpe_vector_clear(struct vpe_vector *vector); 74 75 /** 76 * Free the vector. 77 * @param[in] vector vector that we want to free. 78 */ 79 void vpe_vector_free(struct vpe_vector *vpe_vector); 80 81 #ifdef __cplusplus 82 } 83 #endif 84