From 9343b8292380dbe968e07bbce540c5b4b1ddc220 Mon Sep 17 00:00:00 2001 From: Andrew Mikhail Date: Fri, 8 Aug 2025 11:32:16 -0700 Subject: [PATCH 1/9] Added corevx namespace --- framework/include/vx_array.h | 3 +-- framework/include/vx_context.h | 3 +-- framework/include/vx_convolution.h | 3 +-- framework/include/vx_distribution.h | 3 +-- framework/include/vx_error.h | 3 +-- framework/include/vx_event_queue.hpp | 1 - framework/include/vx_graph.h | 3 +-- framework/include/vx_image.h | 3 +-- framework/include/vx_import.h | 3 +-- framework/include/vx_kernel.h | 3 +-- framework/include/vx_log.h | 3 +-- framework/include/vx_matrix.h | 3 +-- framework/include/vx_memory.h | 3 +-- framework/include/vx_meta_format.h | 3 +-- framework/include/vx_node.h | 3 +-- framework/include/vx_object_array.h | 3 +-- framework/include/vx_parameter.h | 3 +-- framework/include/vx_pyramid.h | 3 +-- framework/include/vx_reference.h | 3 +-- framework/include/vx_remap.h | 3 +-- framework/include/vx_scalar.h | 3 +-- framework/include/vx_target.h | 3 +-- framework/include/vx_tensor.h | 3 +-- framework/include/vx_threshold.h | 3 +-- framework/include/vx_user_data_object.h | 1 - 25 files changed, 23 insertions(+), 48 deletions(-) diff --git a/framework/include/vx_array.h b/framework/include/vx_array.h index 1ff9ab6..36a4458 100644 --- a/framework/include/vx_array.h +++ b/framework/include/vx_array.h @@ -300,5 +300,4 @@ class Array : public Reference } // namespace corevx - -#endif /* VX_ARRAY_H */ +#endif /* VX_ARRAY_H */ \ No newline at end of file diff --git a/framework/include/vx_context.h b/framework/include/vx_context.h index 8846516..cc39d4d 100644 --- a/framework/include/vx_context.h +++ b/framework/include/vx_context.h @@ -509,5 +509,4 @@ class Context : public Reference } // namespace corevx - -#endif /* VX_CONTEXT_H */ +#endif /* VX_CONTEXT_H */ \ No newline at end of file diff --git a/framework/include/vx_convolution.h b/framework/include/vx_convolution.h index 71f260b..e623eac 100644 --- a/framework/include/vx_convolution.h +++ b/framework/include/vx_convolution.h @@ -118,5 +118,4 @@ class Convolution : public Matrix } // namespace corevx - -#endif /* VX_CONVOLUTION_H */ +#endif /* VX_CONVOLUTION_H */ \ No newline at end of file diff --git a/framework/include/vx_distribution.h b/framework/include/vx_distribution.h index bc8b2e1..53f4e46 100644 --- a/framework/include/vx_distribution.h +++ b/framework/include/vx_distribution.h @@ -171,5 +171,4 @@ class Distribution : public Reference } // namespace corevx - -#endif /* VX_DISTRIBUTION_H */ +#endif /* VX_DISTRIBUTION_H */ \ No newline at end of file diff --git a/framework/include/vx_error.h b/framework/include/vx_error.h index c03e1cd..3c62551 100644 --- a/framework/include/vx_error.h +++ b/framework/include/vx_error.h @@ -89,7 +89,6 @@ class Error : public Reference } // namespace corevx - /*! \brief Matches the status code against all known error objects in the * context. * \param [in] context The pointer to the overall context. @@ -98,4 +97,4 @@ class Error : public Reference */ vx_error vxGetErrorObject(vx_context context, vx_status status); -#endif /* VX_ERROR_H */ +#endif /* VX_ERROR_H */ \ No newline at end of file diff --git a/framework/include/vx_event_queue.hpp b/framework/include/vx_event_queue.hpp index a12595b..a14ee4a 100644 --- a/framework/include/vx_event_queue.hpp +++ b/framework/include/vx_event_queue.hpp @@ -260,4 +260,3 @@ private : bool enabled_; }; } // namespace corevx - diff --git a/framework/include/vx_graph.h b/framework/include/vx_graph.h index 760aafb..48ee751 100644 --- a/framework/include/vx_graph.h +++ b/framework/include/vx_graph.h @@ -410,5 +410,4 @@ class Graph : public Reference } // namespace corevx - -#endif /* VX_GRAPH_H */ +#endif /* VX_GRAPH_H */ \ No newline at end of file diff --git a/framework/include/vx_image.h b/framework/include/vx_image.h index 6bf6732..9a4c202 100644 --- a/framework/include/vx_image.h +++ b/framework/include/vx_image.h @@ -421,5 +421,4 @@ class Image : public Reference } // namespace corevx - -#endif /* VX_IMAGE_H */ +#endif /* VX_IMAGE_H */ \ No newline at end of file diff --git a/framework/include/vx_import.h b/framework/include/vx_import.h index 993f8ae..773a9c5 100644 --- a/framework/include/vx_import.h +++ b/framework/include/vx_import.h @@ -136,5 +136,4 @@ class Import : public Reference } // namespace corevx - -#endif /* VX_IMPORT_H */ +#endif /* VX_IMPORT_H */ \ No newline at end of file diff --git a/framework/include/vx_kernel.h b/framework/include/vx_kernel.h index 15e712a..2cab53c 100644 --- a/framework/include/vx_kernel.h +++ b/framework/include/vx_kernel.h @@ -462,5 +462,4 @@ class Kernel : public Reference } // namespace corevx - -#endif /* VX_KERNEL_H */ +#endif /* VX_KERNEL_H */ \ No newline at end of file diff --git a/framework/include/vx_log.h b/framework/include/vx_log.h index 5bc61ae..88a802c 100644 --- a/framework/include/vx_log.h +++ b/framework/include/vx_log.h @@ -65,5 +65,4 @@ class Logger } // namespace corevx - -#endif /* VX_LOG_H */ +#endif /* VX_LOG_H */ \ No newline at end of file diff --git a/framework/include/vx_matrix.h b/framework/include/vx_matrix.h index 81c2461..f388961 100644 --- a/framework/include/vx_matrix.h +++ b/framework/include/vx_matrix.h @@ -150,5 +150,4 @@ class Matrix : public Reference } // namespace corevx - -#endif /* VX_MATRIX_H */ +#endif /* VX_MATRIX_H */ \ No newline at end of file diff --git a/framework/include/vx_memory.h b/framework/include/vx_memory.h index df420ba..2aa452e 100644 --- a/framework/include/vx_memory.h +++ b/framework/include/vx_memory.h @@ -82,5 +82,4 @@ class Memory } // namespace corevx - -#endif /* VX_MEMORY_H */ +#endif /* VX_MEMORY_H */ \ No newline at end of file diff --git a/framework/include/vx_meta_format.h b/framework/include/vx_meta_format.h index 2cc3e36..2ce38b4 100644 --- a/framework/include/vx_meta_format.h +++ b/framework/include/vx_meta_format.h @@ -250,7 +250,6 @@ class MetaFormat : public Reference } // namespace corevx - /*! \brief Creates a metaformat object. * \param [in] context The overall context object. * \ingroup group_int_meta_format @@ -263,4 +262,4 @@ vx_meta_format vxCreateMetaFormat(vx_context context); */ vx_status vxReleaseMetaFormat(vx_meta_format *pmeta); -#endif /* VX_META_FORMAT_H */ +#endif /* VX_META_FORMAT_H */ \ No newline at end of file diff --git a/framework/include/vx_node.h b/framework/include/vx_node.h index dece9df..f5daf5a 100644 --- a/framework/include/vx_node.h +++ b/framework/include/vx_node.h @@ -300,5 +300,4 @@ class Node : public Reference } // namespace corevx - -#endif /* VX_NODE_H */ +#endif /* VX_NODE_H */ \ No newline at end of file diff --git a/framework/include/vx_object_array.h b/framework/include/vx_object_array.h index 94bb660..8676bce 100644 --- a/framework/include/vx_object_array.h +++ b/framework/include/vx_object_array.h @@ -144,5 +144,4 @@ class ObjectArray : public Reference } // namespace corevx - -#endif /* VX_OBJECT_ARRAY_H */ +#endif /* VX_OBJECT_ARRAY_H */ \ No newline at end of file diff --git a/framework/include/vx_parameter.h b/framework/include/vx_parameter.h index 2612fab..b857d6f 100644 --- a/framework/include/vx_parameter.h +++ b/framework/include/vx_parameter.h @@ -175,5 +175,4 @@ class Parameter : public Reference } // namespace corevx - -#endif /* VX_PARAMETER_H */ +#endif /* VX_PARAMETER_H */ \ No newline at end of file diff --git a/framework/include/vx_pyramid.h b/framework/include/vx_pyramid.h index effbe0d..a42845e 100644 --- a/framework/include/vx_pyramid.h +++ b/framework/include/vx_pyramid.h @@ -151,5 +151,4 @@ class Pyramid : public Reference } // namespace corevx - -#endif /* VX_PYRAMID_H */ +#endif /* VX_PYRAMID_H */ \ No newline at end of file diff --git a/framework/include/vx_reference.h b/framework/include/vx_reference.h index 74f30f6..c1f55cf 100644 --- a/framework/include/vx_reference.h +++ b/framework/include/vx_reference.h @@ -219,5 +219,4 @@ class Reference { } // namespace corevx - -#endif /* VX_REFERENCE_H */ +#endif /* VX_REFERENCE_H */ \ No newline at end of file diff --git a/framework/include/vx_remap.h b/framework/include/vx_remap.h index 6d53020..0f9877f 100644 --- a/framework/include/vx_remap.h +++ b/framework/include/vx_remap.h @@ -197,5 +197,4 @@ class Remap : public Reference } // namespace corevx - -#endif /* VX_REMAP_H */ +#endif /* VX_REMAP_H */ \ No newline at end of file diff --git a/framework/include/vx_scalar.h b/framework/include/vx_scalar.h index 5ff3f99..f7dafeb 100644 --- a/framework/include/vx_scalar.h +++ b/framework/include/vx_scalar.h @@ -189,5 +189,4 @@ class Scalar : public Reference } // namespace corevx - -#endif /* VX_SCALAR_H */ +#endif /* VX_SCALAR_H */ \ No newline at end of file diff --git a/framework/include/vx_target.h b/framework/include/vx_target.h index aa23d94..0695605 100644 --- a/framework/include/vx_target.h +++ b/framework/include/vx_target.h @@ -123,5 +123,4 @@ class Target : public Reference } // namespace corevx - -#endif /* VX_TARGET_H */ +#endif /* VX_TARGET_H */ \ No newline at end of file diff --git a/framework/include/vx_tensor.h b/framework/include/vx_tensor.h index 8f754cd..03aaf96 100644 --- a/framework/include/vx_tensor.h +++ b/framework/include/vx_tensor.h @@ -225,5 +225,4 @@ class Tensor : public Reference } // namespace corevx - -#endif +#endif /* VX_TENSOR_H */ \ No newline at end of file diff --git a/framework/include/vx_threshold.h b/framework/include/vx_threshold.h index e0ccfd4..ea1e8a7 100644 --- a/framework/include/vx_threshold.h +++ b/framework/include/vx_threshold.h @@ -331,5 +331,4 @@ class Threshold : public Reference } // namespace corevx - -#endif /* VX_THRESHOLD_H */ +#endif /* VX_THRESHOLD_H */ \ No newline at end of file diff --git a/framework/include/vx_user_data_object.h b/framework/include/vx_user_data_object.h index e467163..a6109a3 100644 --- a/framework/include/vx_user_data_object.h +++ b/framework/include/vx_user_data_object.h @@ -118,5 +118,4 @@ class UserDataObject : public Reference } // namespace corevx - #endif /* VX_USER_DATA_OBJECT_H */ \ No newline at end of file From 69602e6170e71493f6e925bf43fa5e2984baf06b Mon Sep 17 00:00:00 2001 From: Andrew Mikhail Date: Sat, 9 Aug 2025 14:54:10 -0700 Subject: [PATCH 2/9] Reworked objects --- framework/include/vx_context.h | 6 + framework/include/vx_convolution.h | 11 ++ framework/include/vx_distribution.h | 12 ++ framework/include/vx_graph.h | 14 +- framework/include/vx_image.h | 2 +- framework/include/vx_matrix.h | 12 ++ framework/include/vx_meta_format.h | 9 + framework/include/vx_node.h | 10 + framework/include/vx_object_array.h | 10 + framework/include/vx_remap.h | 13 ++ framework/include/vx_scalar.h | 11 ++ framework/include/vx_tensor.h | 14 ++ framework/include/vx_threshold.h | 11 ++ framework/include/vx_user_data_object.h | 12 ++ framework/src/vx_array.cpp | 44 +++-- framework/src/vx_context.cpp | 252 ++++++++++++------------ framework/src/vx_convolution.cpp | 61 +++--- framework/src/vx_distribution.cpp | 65 +++--- framework/src/vx_graph.cpp | 42 ++-- framework/src/vx_image.cpp | 17 +- framework/src/vx_matrix.cpp | 104 +++++----- framework/src/vx_meta_format.cpp | 35 +++- framework/src/vx_node.cpp | 125 ++++++------ framework/src/vx_object_array.cpp | 99 +++++----- framework/src/vx_pyramid.cpp | 54 +++-- framework/src/vx_remap.cpp | 63 +++--- framework/src/vx_scalar.cpp | 46 +++-- framework/src/vx_tensor.cpp | 67 ++++--- framework/src/vx_threshold.cpp | 133 +++++++------ framework/src/vx_user_data_object.cpp | 119 +++++------ 30 files changed, 870 insertions(+), 603 deletions(-) diff --git a/framework/include/vx_context.h b/framework/include/vx_context.h index cc39d4d..8aee37a 100644 --- a/framework/include/vx_context.h +++ b/framework/include/vx_context.h @@ -55,6 +55,12 @@ class Context : public Reference */ ~Context(); + /** + * @brief Create a new context + * @ingroup group_int_context + */ + static vx_context createContext(); + /** * @brief Get vendor id * diff --git a/framework/include/vx_convolution.h b/framework/include/vx_convolution.h index e623eac..f2c34ed 100644 --- a/framework/include/vx_convolution.h +++ b/framework/include/vx_convolution.h @@ -46,6 +46,17 @@ class Convolution : public Matrix */ Convolution(vx_context context, vx_reference scope); + /** + * @brief Create a new convolution + * + * @param context The context associated with this convolution + * @param columns The number of columns in the convolution + * @param rows The number of rows in the convolution + * @return vx_convolution The convolution object + * @ingroup group_int_convolution + */ + static vx_convolution createConvolution(vx_context context, vx_size columns, vx_size rows); + /** * @brief Get the scale factor of the convolution * diff --git a/framework/include/vx_distribution.h b/framework/include/vx_distribution.h index 53f4e46..c969be5 100644 --- a/framework/include/vx_distribution.h +++ b/framework/include/vx_distribution.h @@ -45,6 +45,18 @@ class Distribution : public Reference */ Distribution(vx_context context, vx_reference scope); + /** + * @brief Create a new distribution + * + * @param context The context associated with this distribution + * @param numBins The number of bins in the distribution + * @param offset The offset of the distribution + * @param range The range of the distribution + * @return vx_distribution The distribution object + * @ingroup group_int_distribution + */ + static vx_distribution createDistribution(vx_context context, vx_size numBins, vx_int32 offset, vx_uint32 range); + /** * @brief Get the number of dimensions in the distribution * diff --git a/framework/include/vx_graph.h b/framework/include/vx_graph.h index 48ee751..b230933 100644 --- a/framework/include/vx_graph.h +++ b/framework/include/vx_graph.h @@ -39,7 +39,6 @@ namespace corevx { class Graph : public Reference { private: - /** * @brief Get the next node index given current node index * @@ -89,6 +88,12 @@ class Graph : public Reference * @ingroup group_int_graph */ static void contaminateGraphs(vx_reference ref); + + /** + * @brief Destroy the Graph object + * @ingroup group_int_graph + */ + ~Graph(); public: /** * @brief Construct a new Graph object @@ -100,10 +105,13 @@ class Graph : public Reference Graph(vx_context context, vx_reference scope); /** - * @brief Destroy the Graph object + * @brief Create a graph + * + * @param context The context associated with this graph + * @return vx_graph The graph object * @ingroup group_int_graph */ - ~Graph(); + static vx_graph createGraph(vx_context context); /** * @brief Do a topological in-place sort of the nodes in list, with current diff --git a/framework/include/vx_image.h b/framework/include/vx_image.h index 9a4c202..d7b1308 100644 --- a/framework/include/vx_image.h +++ b/framework/include/vx_image.h @@ -72,7 +72,7 @@ class Image : public Reference vx_uint32 width, vx_uint32 height, vx_df_image color, - vx_bool is_virtual); + vx_bool is_virtual = vx_false_e); /*! \brief Used to initialize a single plane in an image object. * \param [in] index The index to the plane. diff --git a/framework/include/vx_matrix.h b/framework/include/vx_matrix.h index f388961..3bc4af7 100644 --- a/framework/include/vx_matrix.h +++ b/framework/include/vx_matrix.h @@ -54,6 +54,18 @@ class Matrix : public Reference */ Matrix(vx_context context, vx_type_e type, vx_reference scope); + /** + * @brief Create a matrix object + * + * @param context The context associated with this obj + * @param data_type The data type of the matrix + * @param columns The number of columns in the matrix + * @param rows The number of rows in the matrix + * @return vx_matrix The matrix object + * @ingroup group_int_matrix + */ + static vx_matrix createMatrix(vx_context context, vx_enum data_type, vx_size columns, vx_size rows); + /** * @brief Get the data type of the matrix * diff --git a/framework/include/vx_meta_format.h b/framework/include/vx_meta_format.h index 2ce38b4..8eb6a10 100644 --- a/framework/include/vx_meta_format.h +++ b/framework/include/vx_meta_format.h @@ -55,6 +55,15 @@ class MetaFormat : public Reference */ ~MetaFormat() = default; + /** + * @brief Create a new meta format + * + * @param context The context associated with this meta format + * @return vx_meta_format The meta format object + * @ingroup group_int_meta_format + */ + static vx_meta_format createMetaFormat(vx_context context); + /** * @brief Check if two meta formats are valid * diff --git a/framework/include/vx_node.h b/framework/include/vx_node.h index f5daf5a..6bd8c2b 100644 --- a/framework/include/vx_node.h +++ b/framework/include/vx_node.h @@ -75,6 +75,16 @@ class Node : public Reference */ ~Node(); + /** + * @brief Create a new node + * + * @param graph The graph associated with this node + * @param kernel The kernel associated with this node + * @return vx_node The node object + * @ingroup group_int_node + */ + static vx_node createNode(vx_graph graph, vx_kernel kernel); + /*! \brief Node parameter setter, no check. * \ingroup group_int_node */ diff --git a/framework/include/vx_object_array.h b/framework/include/vx_object_array.h index 8676bce..fbd5639 100644 --- a/framework/include/vx_object_array.h +++ b/framework/include/vx_object_array.h @@ -51,6 +51,16 @@ class ObjectArray : public Reference */ ~ObjectArray(); + /** + * @brief Create a Object Array object + * + * @param context The context associated with this obj + * @param type The type of the object array + * @return vx_object_array The object array object + * @ingroup group_int_object_array + */ + static vx_object_array createObjectArray(vx_context context, vx_enum type); + /** * @brief Create a Object Array object * diff --git a/framework/include/vx_remap.h b/framework/include/vx_remap.h index 0f9877f..4ae63b9 100644 --- a/framework/include/vx_remap.h +++ b/framework/include/vx_remap.h @@ -50,6 +50,19 @@ class Remap : public Reference */ ~Remap(); + /** + * @brief Create a remap object + * + * @param context The context associated with this obj + * @param src_width The width of the source image + * @param src_height The height of the source image + * @param dst_width The width of the destination image + * @param dst_height The height of the destination image + * @return vx_remap The remap object + * @ingroup group_int_remap + */ + static vx_remap createRemap(vx_context context, vx_uint32 src_width, vx_uint32 src_height, vx_uint32 dst_width, vx_uint32 dst_height); + /** * @brief Validate remap object * diff --git a/framework/include/vx_scalar.h b/framework/include/vx_scalar.h index f7dafeb..53d2745 100644 --- a/framework/include/vx_scalar.h +++ b/framework/include/vx_scalar.h @@ -50,6 +50,17 @@ class Scalar : public Reference */ ~Scalar(); + /** + * @brief Create a scalar object + * + * @param context The context associated with this obj + * @param data_type The data type of the scalar + * @param ptr The pointer to the scalar value + * @return vx_scalar The scalar object + * @ingroup group_int_scalar + */ + static vx_scalar createScalar(vx_context context, vx_enum data_type, const void* ptr); + /** * @brief Allocate memory for scalar obj * diff --git a/framework/include/vx_tensor.h b/framework/include/vx_tensor.h index 03aaf96..eddab50 100644 --- a/framework/include/vx_tensor.h +++ b/framework/include/vx_tensor.h @@ -50,6 +50,20 @@ class Tensor : public Reference */ ~Tensor(); + /** + * @brief Create a tensor object + * + * @param context The context associated with this obj + * @param number_of_dims The number of dimensions of the tensor + * @param dims The dimensions of the tensor + * @param data_type The data type of the tensor + * @param fixed_point_position The fixed point position of the tensor + * @return vx_tensor The tensor object + * @ingroup group_int_tensor + */ + static vx_tensor createTensor( + vx_context context, vx_size number_of_dims, const vx_size *dims, vx_enum data_type, vx_int8 fixed_point_position); + /*! \brief Used to validate the vx_tensor types. * \param [in] tensor The vx_tensor to validate. * \ingroup group_int_tensor diff --git a/framework/include/vx_threshold.h b/framework/include/vx_threshold.h index ea1e8a7..4580013 100644 --- a/framework/include/vx_threshold.h +++ b/framework/include/vx_threshold.h @@ -55,6 +55,17 @@ class Threshold : public Reference */ ~Threshold(); + /** + * @brief Create a threshold object + * + * @param context The context associated with this obj + * @param thresh_type The threshold type + * @param data_type The data type + * @return vx_threshold The threshold object + * @ingroup group_int_threshold + */ + static vx_threshold createThreshold(vx_context context, vx_enum thresh_type, vx_enum data_type); + /** * @brief Set the binary threshold value * diff --git a/framework/include/vx_user_data_object.h b/framework/include/vx_user_data_object.h index a6109a3..50e7a6b 100644 --- a/framework/include/vx_user_data_object.h +++ b/framework/include/vx_user_data_object.h @@ -45,6 +45,18 @@ class UserDataObject : public Reference */ ~UserDataObject(); + /** + * @brief Create a user data object + * + * @param context The context associated with this obj + * @param type_name The type name of the user data object + * @param size The size of the user data object + * @param ptr The pointer to the user data object + * @return vx_user_data_object The user data object + * @ingroup group_int_user_data_object + */ + static vx_user_data_object createUserDataObject(vx_context context, const vx_char *type_name, vx_size size, const void *ptr); + /** * @brief Get the type name of the user data object * diff --git a/framework/src/vx_array.cpp b/framework/src/vx_array.cpp index 4665ff5..265b828 100644 --- a/framework/src/vx_array.cpp +++ b/framework/src/vx_array.cpp @@ -51,15 +51,30 @@ Array::~Array() vx_array Array::createArray(vx_context context, vx_enum item_type, vx_size capacity, vx_bool is_virtual, vx_enum type) { - vx_array arr = (vx_array)Reference::createReference(context, type, VX_EXTERNAL, context); - if (vxGetStatus((vx_reference)arr) == VX_SUCCESS && arr->type == type) + vx_array arr = nullptr; + + if (Context::isValidContext(context) == vx_true_e) { - arr->item_type = item_type; - arr->item_size = Array::itemSize(context, item_type); - arr->capacity = capacity; - arr->is_virtual = is_virtual; - arr->initArrayMemory(); + if ((Array::isValidArrayItemType(context, item_type) == vx_true_e) && (capacity > 0)) + { + arr = (vx_array)Reference::createReference(context, type, VX_EXTERNAL, context); + if (Error::getStatus((vx_reference)arr) == VX_SUCCESS && arr->type == type) + { + arr->item_type = item_type; + arr->item_size = Array::itemSize(context, item_type); + arr->capacity = capacity; + arr->is_virtual = is_virtual; + arr->initArrayMemory(); + } + + if (arr == nullptr) arr = (vx_array)Error::getError(context, VX_ERROR_NO_MEMORY); + } + else + { + arr = (vx_array)Error::getError(context, VX_ERROR_INVALID_PARAMETERS); + } } + return arr; } @@ -899,20 +914,7 @@ VX_API_ENTRY vx_array VX_API_CALL vxCreateArray(vx_context context, vx_enum item { vx_array arr = nullptr; - if (Context::isValidContext(context) == vx_true_e && - (Array::isValidArrayItemType(context, item_type) == vx_true_e) && (capacity > 0)) - { - arr = (vx_array)Array::createArray(context, item_type, capacity, vx_false_e, VX_TYPE_ARRAY); - - if (arr == nullptr) - { - arr = (vx_array)vxGetErrorObject(context, VX_ERROR_NO_MEMORY); - } - } - else - { - arr = (vx_array)vxGetErrorObject(context, VX_ERROR_INVALID_PARAMETERS); - } + arr = (vx_array)Array::createArray(context, item_type, capacity, vx_false_e, VX_TYPE_ARRAY); return arr; } diff --git a/framework/src/vx_context.cpp b/framework/src/vx_context.cpp index e688357..62cb93f 100644 --- a/framework/src/vx_context.cpp +++ b/framework/src/vx_context.cpp @@ -125,6 +125,134 @@ Context::~Context() } } +vx_context Context::createContext() +{ + vx_context context = nullptr; + + if (single_context == nullptr) + { + Osal::createSem(&context_lock, 1); + Osal::createSem(&global_lock, 1); + } + + Osal::semWait(&context_lock); + if (single_context == nullptr) + { + /* read the variables for debugging flags */ + vx_set_debug_zone_from_env(); + + single_context = std::make_shared(); + context = single_context.get(); + + if (context) + { + vx_uint32 p = 0u, p2 = 0u, t = 0u, m = 0u; +#if !DISABLE_ICD_COMPATIBILITY + context->platform = platform; +#endif + context->incrementReference(VX_EXTERNAL); + context->workers = Osal::createThreadpool(VX_INT_HOST_CORES, + VX_INT_MAX_REF, /* very deep queues! */ + sizeof(vx_work_t), + Context::workerNode, + context); + Error::createConstErrors(context); + + /* initialize modules */ + for (m = 0u; m < VX_INT_MAX_MODULES; m++) + { + Osal::createSem(&context->modules[m].lock, 1); + } + + /* load all targets */ + for (t = 0u; t < dimof(targetModules); t++) + { + if (context->loadTarget(targetModules[t]) == VX_SUCCESS) + { + context->num_targets++; + } + } + + if (context->num_targets == 0) + { + VX_PRINT(VX_ZONE_ERROR, "No targets loaded!\n"); + Osal::semPost(&context_lock); + single_context.reset(); + return nullptr; + } + + /* initialize all targets */ + for (t = 0u; t < context->num_targets; t++) + { + if (context->targets[t]->module.handle && + context->targets[t]->funcs.init) + { + /* call the init function */ + if (context->targets[t]->funcs.init(context->targets[t]) != VX_SUCCESS) + { + VX_PRINT(VX_ZONE_WARNING, "Target %s failed to initialize!\n", context->targets[t]->name); + /* unload this module */ + /* @TODO: unload target now or on context release? */ + /* + * context->unloadTarget(t, vx_true_e); + * break; + */ + } + else + { + context->targets[t]->enabled = vx_true_e; + VX_PRINT(VX_ZONE_INFO, "Target %s enabled!\n", context->targets[t]->name); + } + } + } + + /* assign the targets by priority into the list */ + p2 = 0u; + for (p = 0u; p < VX_TARGET_PRIORITY_MAX; p++) + { + for (t = 0u; t < context->num_targets; t++) + { + vx_target target = context->targets[t]; + if (p == target->priority) + { + context->priority_targets[p2] = t; + p2++; + } + } + } + /* print out the priority list */ + for (t = 0u; t < context->num_targets; t++) + { + vx_target target = context->targets[context->priority_targets[t]]; + if (target->enabled == vx_true_e) + { + VX_PRINT(VX_ZONE_TARGET, "target[%u]: %s\n", + target->priority, + target->name); + } + } + + /* create the internal thread which processes graphs for asynchronous mode. */ + Osal::initQueue(&context->proc.input); + Osal::initQueue(&context->proc.output); + context->proc.running = vx_true_e; + context->proc.thread = Osal::createThread(Context::workerGraph, &context->proc); + context->imm_target_enum = VX_TARGET_ANY; + memset(context->imm_target_string, 0, sizeof(context->imm_target_string)); + + /* memory maps table lock */ + Osal::createSem(&context->memory_maps_lock, 1); + } + } + else + { + context = single_context.get(); + context->incrementReference(VX_EXTERNAL); + } + Osal::semPost(&context_lock); + return context; +} + vx_uint16 Context::vendorId() const { return vendor_id; @@ -1063,129 +1191,7 @@ VX_API_ENTRY vx_context VX_API_CALL vxCreateContextFromPlatform(struct _vx_platf VX_API_ENTRY vx_context VX_API_CALL vxCreateContext(void) #endif { - vx_context context; - - if (single_context == nullptr) - { - Osal::createSem(&context_lock, 1); - Osal::createSem(&global_lock, 1); - } - - Osal::semWait(&context_lock); - if (single_context == nullptr) - { - /* read the variables for debugging flags */ - vx_set_debug_zone_from_env(); - - single_context = std::make_shared(); - context = single_context.get(); - - if (context) - { - vx_uint32 p = 0u, p2 = 0u, t = 0u, m = 0u; -#if !DISABLE_ICD_COMPATIBILITY - context->platform = platform; -#endif - context->incrementReference(VX_EXTERNAL); - context->workers = Osal::createThreadpool(VX_INT_HOST_CORES, - VX_INT_MAX_REF, /* very deep queues! */ - sizeof(vx_work_t), - Context::workerNode, - context); - Error::createConstErrors(context); - - /* initialize modules */ - for (m = 0u; m < VX_INT_MAX_MODULES; m++) - { - Osal::createSem(&context->modules[m].lock, 1); - } - - /* load all targets */ - for (t = 0u; t < dimof(targetModules); t++) - { - if (context->loadTarget(targetModules[t]) == VX_SUCCESS) - { - context->num_targets++; - } - } - - if (context->num_targets == 0) - { - VX_PRINT(VX_ZONE_ERROR, "No targets loaded!\n"); - Osal::semPost(&context_lock); - single_context.reset(); - return nullptr; - } - - /* initialize all targets */ - for (t = 0u; t < context->num_targets; t++) - { - if (context->targets[t]->module.handle && - context->targets[t]->funcs.init) - { - /* call the init function */ - if (context->targets[t]->funcs.init(context->targets[t]) != VX_SUCCESS) - { - VX_PRINT(VX_ZONE_WARNING, "Target %s failed to initialize!\n", context->targets[t]->name); - /* unload this module */ - /* @TODO: unload target now or on context release? */ - /* - * context->unloadTarget(t, vx_true_e); - * break; - */ - } - else - { - context->targets[t]->enabled = vx_true_e; - VX_PRINT(VX_ZONE_INFO, "Target %s enabled!\n", context->targets[t]->name); - } - } - } - - /* assign the targets by priority into the list */ - p2 = 0u; - for (p = 0u; p < VX_TARGET_PRIORITY_MAX; p++) - { - for (t = 0u; t < context->num_targets; t++) - { - vx_target target = context->targets[t]; - if (p == target->priority) - { - context->priority_targets[p2] = t; - p2++; - } - } - } - /* print out the priority list */ - for (t = 0u; t < context->num_targets; t++) - { - vx_target target = context->targets[context->priority_targets[t]]; - if (target->enabled == vx_true_e) - { - VX_PRINT(VX_ZONE_TARGET, "target[%u]: %s\n", - target->priority, - target->name); - } - } - - /* create the internal thread which processes graphs for asynchronous mode. */ - Osal::initQueue(&context->proc.input); - Osal::initQueue(&context->proc.output); - context->proc.running = vx_true_e; - context->proc.thread = Osal::createThread(Context::workerGraph, &context->proc); - context->imm_target_enum = VX_TARGET_ANY; - memset(context->imm_target_string, 0, sizeof(context->imm_target_string)); - - /* memory maps table lock */ - Osal::createSem(&context->memory_maps_lock, 1); - } - } - else - { - context = single_context.get(); - context->incrementReference(VX_EXTERNAL); - } - Osal::semPost(&context_lock); + vx_context context = Context::createContext(); return context; } diff --git a/framework/src/vx_convolution.cpp b/framework/src/vx_convolution.cpp index 2e17d05..9bfa4b4 100644 --- a/framework/src/vx_convolution.cpp +++ b/framework/src/vx_convolution.cpp @@ -32,6 +32,41 @@ Convolution::~Convolution() { } +vx_convolution Convolution::createConvolution(vx_context context, vx_size columns, vx_size rows) +{ + vx_convolution convolution = nullptr; + + if (Context::isValidContext(context) == vx_true_e) + { + if (vxIsOdd(columns) && columns >= 3 && vxIsOdd(rows) && rows >= 3) + { + convolution = (vx_convolution)Reference::createReference(context, VX_TYPE_CONVOLUTION, + VX_EXTERNAL, context); + if (Error::getStatus((vx_reference)convolution) == VX_SUCCESS && + convolution->type == VX_TYPE_CONVOLUTION) + { + convolution->data_type = VX_TYPE_INT16; + convolution->columns = columns; + convolution->rows = rows; + convolution->memory.ndims = 2; + convolution->memory.nptrs = 1; + convolution->memory.dims[0][0] = sizeof(vx_int16); + convolution->memory.dims[0][1] = (vx_uint32)(columns * rows); + convolution->scale = 1; + } + } + else + { + VX_PRINT(VX_ZONE_ERROR, "Failed to create convolution, invalid dimensions\n"); + vxAddLogEntry((vx_reference)context, VX_ERROR_INVALID_DIMENSION, + "Invalid dimensions to convolution\n"); + convolution = (vx_convolution)Error::getError(context, VX_ERROR_INVALID_DIMENSION); + } + } + + return convolution; +} + vx_uint32 Convolution::scaleFactor() const { return scale; @@ -196,30 +231,8 @@ VX_API_ENTRY vx_convolution VX_API_CALL vxCreateConvolution(vx_context context, { vx_convolution convolution = nullptr; - if (Context::isValidContext(context) == vx_true_e) - { - if (vxIsOdd(columns) && columns >= 3 && vxIsOdd(rows) && rows >= 3) - { - convolution = (vx_convolution)Reference::createReference(context, VX_TYPE_CONVOLUTION, VX_EXTERNAL, context); - if (vxGetStatus((vx_reference)convolution) == VX_SUCCESS && convolution->type == VX_TYPE_CONVOLUTION) - { - convolution->data_type = VX_TYPE_INT16; - convolution->columns = columns; - convolution->rows = rows; - convolution->memory.ndims = 2; - convolution->memory.nptrs = 1; - convolution->memory.dims[0][0] = sizeof(vx_int16); - convolution->memory.dims[0][1] = (vx_uint32)(columns*rows); - convolution->scale = 1; - } - } - else - { - VX_PRINT(VX_ZONE_ERROR, "Failed to create convolution, invalid dimensions\n"); - vxAddLogEntry((vx_reference)context, VX_ERROR_INVALID_DIMENSION, "Invalid dimensions to convolution\n"); - convolution = (vx_convolution)vxGetErrorObject(context, VX_ERROR_INVALID_DIMENSION); - } - } + convolution = Convolution::createConvolution(context, columns, rows); + return convolution; } diff --git a/framework/src/vx_distribution.cpp b/framework/src/vx_distribution.cpp index 4d5fb90..84f6353 100644 --- a/framework/src/vx_distribution.cpp +++ b/framework/src/vx_distribution.cpp @@ -31,6 +31,43 @@ offset_y(0) { } +vx_distribution Distribution::createDistribution(vx_context context, vx_size numBins, vx_int32 offset, vx_uint32 range) +{ + vx_distribution distribution = nullptr; + + if (Context::isValidContext(context) == vx_true_e) + { + if ((numBins != 0) && (range != 0)) + { + distribution = (vx_distribution)Reference::createReference( + context, VX_TYPE_DISTRIBUTION, VX_EXTERNAL, context); + if (Error::getStatus((vx_reference)distribution) == VX_SUCCESS && + distribution->type == VX_TYPE_DISTRIBUTION) + { + distribution->memory.ndims = 2; + distribution->memory.nptrs = 1; + distribution->memory.strides[0][VX_DIM_C] = sizeof(vx_int32); + distribution->memory.dims[0][VX_DIM_C] = 1; + distribution->memory.dims[0][VX_DIM_X] = (vx_uint32)numBins; + distribution->memory.dims[0][VX_DIM_Y] = 1; + distribution->range_x = (vx_uint32)range; + distribution->range_y = 1; + distribution->offset_x = offset; + distribution->offset_y = 0; + } + } + else + { + VX_PRINT(VX_ZONE_ERROR, "Invalid parameters to distribution\n"); + vxAddLogEntry(context, VX_ERROR_INVALID_PARAMETERS, + "Invalid parameters to distribution\n"); + distribution = (vx_distribution)Error::getError(context, VX_ERROR_INVALID_PARAMETERS); + } + } + + return distribution; +} + vx_size Distribution::dims() const { return (vx_size)(memory.ndims - 1); @@ -388,33 +425,7 @@ VX_API_ENTRY vx_distribution VX_API_CALL vxCreateDistribution(vx_context context { vx_distribution distribution = nullptr; - if (Context::isValidContext(context) == vx_true_e) - { - if ((numBins != 0) && (range != 0)) - { - distribution = (vx_distribution)Reference::createReference(context, VX_TYPE_DISTRIBUTION, VX_EXTERNAL, context); - if ( vxGetStatus((vx_reference)distribution) == VX_SUCCESS && - distribution->type == VX_TYPE_DISTRIBUTION) - { - distribution->memory.ndims = 2; - distribution->memory.nptrs = 1; - distribution->memory.strides[0][VX_DIM_C] = sizeof(vx_int32); - distribution->memory.dims[0][VX_DIM_C] = 1; - distribution->memory.dims[0][VX_DIM_X] = (vx_uint32)numBins; - distribution->memory.dims[0][VX_DIM_Y] = 1; - distribution->range_x = (vx_uint32)range; - distribution->range_y = 1; - distribution->offset_x = offset; - distribution->offset_y = 0; - } - } - else - { - VX_PRINT(VX_ZONE_ERROR, "Invalid parameters to distribution\n"); - vxAddLogEntry(context, VX_ERROR_INVALID_PARAMETERS, "Invalid parameters to distribution\n"); - distribution = (vx_distribution)vxGetErrorObject(context, VX_ERROR_INVALID_PARAMETERS); - } - } + distribution = Distribution::createDistribution(context, numBins, offset, range); return distribution; } diff --git a/framework/src/vx_graph.cpp b/framework/src/vx_graph.cpp index 53b9faa..e703cc8 100644 --- a/framework/src/vx_graph.cpp +++ b/framework/src/vx_graph.cpp @@ -57,6 +57,33 @@ Graph::Graph(vx_context context, vx_reference scope) Graph::~Graph() {} +vx_graph Graph::createGraph(vx_context context) +{ + vx_graph graph = nullptr; + + if (Context::isValidContext(context) == vx_true_e) + { + graph = (vx_graph)Reference::createReference(context, VX_TYPE_GRAPH, VX_EXTERNAL, context); + if (Error::getStatus((vx_reference)graph) == VX_SUCCESS && graph->type == VX_TYPE_GRAPH) + { + Osal::initPerf(&graph->perf); + Osal::createSem(&graph->lock, 1); + VX_PRINT(VX_ZONE_GRAPH, "Created Graph %p\n", graph); + Reference::printReference((vx_reference)graph); + graph->reverify = graph->verified; + graph->verified = vx_false_e; + graph->state = VX_GRAPH_STATE_UNVERIFIED; + } + + if (graph == nullptr) + { + graph = (vx_graph)Error::getError(context, VX_ERROR_NO_MEMORY); + } + } + + return graph; +} + vx_uint32 Graph::nextNode(vx_uint32 index) { return ((index + 1) % numNodes); @@ -3096,20 +3123,7 @@ VX_API_ENTRY vx_graph VX_API_CALL vxCreateGraph(vx_context context) { vx_graph graph = nullptr; - if (Context::isValidContext(context) == vx_true_e) - { - graph = (vx_graph)Reference::createReference(context, VX_TYPE_GRAPH, VX_EXTERNAL, context); - if (vxGetStatus((vx_reference)graph) == VX_SUCCESS && graph->type == VX_TYPE_GRAPH) - { - Osal::initPerf(&graph->perf); - Osal::createSem(&graph->lock, 1); - VX_PRINT(VX_ZONE_GRAPH,"Created Graph %p\n", graph); - Reference::printReference((vx_reference)graph); - graph->reverify = graph->verified; - graph->verified = vx_false_e; - graph->state = VX_GRAPH_STATE_UNVERIFIED; - } - } + graph = Graph::createGraph(context); return (vx_graph)graph; } diff --git a/framework/src/vx_image.cpp b/framework/src/vx_image.cpp index 799f65e..f8364c4 100644 --- a/framework/src/vx_image.cpp +++ b/framework/src/vx_image.cpp @@ -244,6 +244,12 @@ vx_image Image::createImage(vx_context context, { vx_image image = nullptr; + if ((width == 0) || (height == 0) || (Image::isSupportedFourcc(color) == vx_false_e) || + (color == VX_DF_IMAGE_VIRT)) + { + return (vx_image)Error::getError(context, VX_ERROR_INVALID_PARAMETERS); + } + if (Context::isValidContext(context) == vx_true_e) { if (Image::isSupportedFourcc(color) == vx_true_e) @@ -251,7 +257,7 @@ vx_image Image::createImage(vx_context context, if (Image::isValidDimensions(width, height, color) == vx_true_e) { image = (vx_image)Reference::createReference(context, VX_TYPE_IMAGE, VX_EXTERNAL, context); - if (vxGetStatus((vx_reference)image) == VX_SUCCESS && image->type == VX_TYPE_IMAGE) + if (Error::getStatus((vx_reference)image) == VX_SUCCESS && image->type == VX_TYPE_IMAGE) { image->is_virtual = is_virtual; image->initImage(width, height, color); @@ -261,14 +267,14 @@ vx_image Image::createImage(vx_context context, { VX_PRINT(VX_ZONE_ERROR, "Requested Image Dimensions are invalid!\n"); vxAddLogEntry((vx_reference)image, VX_ERROR_INVALID_DIMENSION, "Requested Image Dimensions was invalid!\n"); - image = (vx_image)vxGetErrorObject(context, VX_ERROR_INVALID_DIMENSION); + image = (vx_image)Error::getError(context, VX_ERROR_INVALID_DIMENSION); } } else { VX_PRINT(VX_ZONE_ERROR, "Requested Image Format was invalid!\n"); vxAddLogEntry((vx_reference)context, VX_ERROR_INVALID_FORMAT, "Requested Image Format was invalid!\n"); - image = (vx_image)vxGetErrorObject(context, VX_ERROR_INVALID_FORMAT); + image = (vx_image)Error::getError(context, VX_ERROR_INVALID_FORMAT); } } @@ -2237,11 +2243,6 @@ void Image::destruct() VX_API_ENTRY vx_image VX_API_CALL vxCreateImage(vx_context context, vx_uint32 width, vx_uint32 height, vx_df_image format) { - if ((width == 0) || (height == 0) || - (Image::isSupportedFourcc(format) == vx_false_e) || (format == VX_DF_IMAGE_VIRT)) - { - return (vx_image)vxGetErrorObject(context, VX_ERROR_INVALID_PARAMETERS); - } return (vx_image)Image::createImage(context, width, height, format, vx_false_e); } diff --git a/framework/src/vx_matrix.cpp b/framework/src/vx_matrix.cpp index f68045e..03e5a2f 100644 --- a/framework/src/vx_matrix.cpp +++ b/framework/src/vx_matrix.cpp @@ -44,6 +44,64 @@ pattern() } +vx_matrix Matrix::createMatrix(vx_context context, vx_enum data_type, vx_size columns, vx_size rows) +{ + vx_matrix matrix = nullptr; + + vx_size dim = 0ul; + + if (Context::isValidContext(context) == vx_false_e) + return 0; + + if ((data_type == VX_TYPE_INT8) || (data_type == VX_TYPE_UINT8)) + { + dim = sizeof(vx_uint8); + } + else if ((data_type == VX_TYPE_INT16) || (data_type == VX_TYPE_UINT16)) + { + dim = sizeof(vx_uint16); + } + else if ((data_type == VX_TYPE_INT32) || (data_type == VX_TYPE_UINT32) || (data_type == VX_TYPE_FLOAT32)) + { + dim = sizeof(vx_uint32); + } + else if ((data_type == VX_TYPE_INT64) || (data_type == VX_TYPE_UINT64) || (data_type == VX_TYPE_FLOAT64)) + { + dim = sizeof(vx_uint64); + } + + if (dim == 0ul) + { + VX_PRINT(VX_ZONE_ERROR, "Invalid data type\n"); + vxAddLogEntry(context, VX_ERROR_INVALID_TYPE, "Invalid data type\n"); + return (vx_matrix)Error::getError(context, VX_ERROR_INVALID_TYPE); + } + + if ((columns == 0ul) || (rows == 0ul)) + { + VX_PRINT(VX_ZONE_ERROR, "Invalid dimensions to matrix\n"); + vxAddLogEntry(context, VX_ERROR_INVALID_DIMENSION, "Invalid dimensions to matrix\n"); + return (vx_matrix)Error::getError(context, VX_ERROR_INVALID_DIMENSION); + } + + matrix = (vx_matrix)Reference::createReference(context, VX_TYPE_MATRIX, VX_EXTERNAL, context); + if (Error::getStatus((vx_reference)matrix) == VX_SUCCESS && matrix->type == VX_TYPE_MATRIX) + { + matrix->data_type = data_type; + matrix->columns = columns; + matrix->rows = rows; + matrix->memory.ndims = 2; + matrix->memory.nptrs = 1; + matrix->memory.dims[0][0] = (vx_uint32)dim; + matrix->memory.dims[0][1] = (vx_uint32)(columns*rows); + matrix->origin.x = (vx_uint32)(columns / 2); + matrix->origin.y = (vx_uint32)(rows / 2); + matrix->pattern = VX_PATTERN_OTHER; + } + + return matrix; +} + vx_enum Matrix::dataType() const { return data_type; @@ -218,53 +276,9 @@ void Matrix::destruct() VX_API_ENTRY vx_matrix VX_API_CALL vxCreateMatrix(vx_context context, vx_enum data_type, vx_size columns, vx_size rows) { vx_matrix matrix = nullptr; - vx_size dim = 0ul; - if (Context::isValidContext(context) == vx_false_e) - return 0; + matrix = Matrix::createMatrix(context, data_type, columns, rows); - if ((data_type == VX_TYPE_INT8) || (data_type == VX_TYPE_UINT8)) - { - dim = sizeof(vx_uint8); - } - else if ((data_type == VX_TYPE_INT16) || (data_type == VX_TYPE_UINT16)) - { - dim = sizeof(vx_uint16); - } - else if ((data_type == VX_TYPE_INT32) || (data_type == VX_TYPE_UINT32) || (data_type == VX_TYPE_FLOAT32)) - { - dim = sizeof(vx_uint32); - } - else if ((data_type == VX_TYPE_INT64) || (data_type == VX_TYPE_UINT64) || (data_type == VX_TYPE_FLOAT64)) - { - dim = sizeof(vx_uint64); - } - if (dim == 0ul) - { - VX_PRINT(VX_ZONE_ERROR, "Invalid data type\n"); - vxAddLogEntry(context, VX_ERROR_INVALID_TYPE, "Invalid data type\n"); - return (vx_matrix)vxGetErrorObject(context, VX_ERROR_INVALID_TYPE); - } - if ((columns == 0ul) || (rows == 0ul)) - { - VX_PRINT(VX_ZONE_ERROR, "Invalid dimensions to matrix\n"); - vxAddLogEntry(context, VX_ERROR_INVALID_DIMENSION, "Invalid dimensions to matrix\n"); - return (vx_matrix)vxGetErrorObject(context, VX_ERROR_INVALID_DIMENSION); - } - matrix = (vx_matrix)Reference::createReference(context, VX_TYPE_MATRIX, VX_EXTERNAL, context); - if (vxGetStatus((vx_reference)matrix) == VX_SUCCESS && matrix->type == VX_TYPE_MATRIX) - { - matrix->data_type = data_type; - matrix->columns = columns; - matrix->rows = rows; - matrix->memory.ndims = 2; - matrix->memory.nptrs = 1; - matrix->memory.dims[0][0] = (vx_uint32)dim; - matrix->memory.dims[0][1] = (vx_uint32)(columns*rows); - matrix->origin.x = (vx_uint32)(columns / 2); - matrix->origin.y = (vx_uint32)(rows / 2); - matrix->pattern = VX_PATTERN_OTHER; - } return (vx_matrix)matrix; } diff --git a/framework/src/vx_meta_format.cpp b/framework/src/vx_meta_format.cpp index 25165a8..0530917 100644 --- a/framework/src/vx_meta_format.cpp +++ b/framework/src/vx_meta_format.cpp @@ -30,6 +30,31 @@ set_valid_rectangle_callback(nullptr) } +vx_meta_format MetaFormat::createMetaFormat(vx_context context) +{ + vx_meta_format meta = nullptr; + + if (Context::isValidContext(context) == vx_true_e) + { + meta = (vx_meta_format)Reference::createReference(context, VX_TYPE_META_FORMAT, VX_EXTERNAL, context); + if (Error::getStatus((vx_reference)meta) == VX_SUCCESS) + { + meta->size = sizeof(vx_meta_format); + meta->type = VX_TYPE_INVALID; + } + else + { + meta = (vx_meta_format)Error::getError(context, VX_ERROR_NO_MEMORY); + } + } + else + { + meta = (vx_meta_format)Error::getError(context, VX_ERROR_INVALID_PARAMETERS); + } + + return meta; +} + vx_bool MetaFormat::isValidMetaFormat(vx_meta_format meta1, vx_meta_format meta2) { vx_bool isValid = vx_false_e; @@ -424,15 +449,7 @@ vx_meta_format vxCreateMetaFormat(vx_context context) { vx_meta_format meta = nullptr; - if (Context::isValidContext(context) == vx_true_e) - { - meta = (vx_meta_format)Reference::createReference(context, VX_TYPE_META_FORMAT, VX_EXTERNAL, context); - if (vxGetStatus((vx_reference)meta) == VX_SUCCESS) - { - meta->size = sizeof(vx_meta_format); - meta->type = VX_TYPE_INVALID; - } - } + meta = MetaFormat::createMetaFormat(context); return meta; } diff --git a/framework/src/vx_node.cpp b/framework/src/vx_node.cpp index 2290318..9ac117c 100644 --- a/framework/src/vx_node.cpp +++ b/framework/src/vx_node.cpp @@ -49,6 +49,72 @@ Node::~Node() { } +vx_node Node::createNode(vx_graph graph, vx_kernel kernel) +{ + vx_node node = nullptr; + + if (Reference::isValidReference(reinterpret_cast(graph), VX_TYPE_GRAPH) == vx_true_e) + { + if (Reference::isValidReference(reinterpret_cast(kernel), VX_TYPE_KERNEL) == vx_true_e) + { + vx_uint32 n = 0; + Osal::semWait(&graph->lock); + for (n = 0; n < VX_INT_MAX_REF; n++) + { + if (graph->nodes[n] == nullptr) + { + node = (vx_node)Reference::createReference(graph->context, VX_TYPE_NODE, VX_EXTERNAL, reinterpret_cast(graph)); + if (Error::getStatus((vx_reference)node) == VX_SUCCESS && node->type == VX_TYPE_NODE) + { + /* reference the abstract kernel. */ + node->kernel = kernel; + node->affinity = kernel->affinity; + + /* show that there are potentially multiple nodes using this kernel. */ + kernel->incrementReference(VX_INTERNAL); + + /* copy the attributes over */ + memcpy(&node->attributes, &kernel->attributes, sizeof(vx_kernel_attr_t)); + + /* setup our forward and back references to the node/graph */ + graph->nodes[n] = node; + node->graph = graph; + node->incrementReference(VX_INTERNAL); /* one for the graph */ + + /* increase the count of nodes in the graph. */ + graph->numNodes++; + + Osal::initPerf(&graph->nodes[n]->perf); + + /* force a re-verify */ + graph->reverify = graph->verified; + graph->verified = vx_false_e; + graph->state = VX_GRAPH_STATE_UNVERIFIED; + + VX_PRINT(VX_ZONE_NODE, "Created Node %p %s affinity:%s\n", node, node->kernel->name, node->context->targets[node->affinity]->name); + } + break; /* succeed or fail, break. */ + } + } + Osal::semPost(&graph->lock); + Reference::printReference((vx_reference )node); + } + else + { + VX_PRINT(VX_ZONE_ERROR, "Kernel %p was invalid!\n", kernel); + vxAddLogEntry((vx_reference)graph, VX_ERROR_INVALID_REFERENCE, "Kernel %p was invalid!\n", kernel); + node = (vx_node)Error::getError(graph->context, VX_ERROR_INVALID_REFERENCE); + } + } + else + { + VX_PRINT(VX_ZONE_ERROR, "Graph %p was invalid!\n", graph); + vxAddLogEntry((vx_reference)graph, VX_ERROR_INVALID_REFERENCE, "Graph %p as invalid!\n", graph); + } + + return node; +} + void Node::setParameter(vx_uint32 index, vx_reference value) { if (parameters[index]) @@ -550,64 +616,7 @@ VX_API_ENTRY vx_node VX_API_CALL vxCreateGenericNode(vx_graph graph, vx_kernel k { vx_node node = nullptr; - if (Reference::isValidReference(reinterpret_cast(graph), VX_TYPE_GRAPH) == vx_true_e) - { - if (Reference::isValidReference(reinterpret_cast(kernel), VX_TYPE_KERNEL) == vx_true_e) - { - vx_uint32 n = 0; - Osal::semWait(&graph->lock); - for (n = 0; n < VX_INT_MAX_REF; n++) - { - if (graph->nodes[n] == nullptr) - { - node = (vx_node)Reference::createReference(graph->context, VX_TYPE_NODE, VX_EXTERNAL, reinterpret_cast(graph)); - if (vxGetStatus((vx_reference)node) == VX_SUCCESS && node->type == VX_TYPE_NODE) - { - /* reference the abstract kernel. */ - node->kernel = kernel; - node->affinity = kernel->affinity; - - /* show that there are potentially multiple nodes using this kernel. */ - kernel->incrementReference(VX_INTERNAL); - - /* copy the attributes over */ - memcpy(&node->attributes, &kernel->attributes, sizeof(vx_kernel_attr_t)); - - /* setup our forward and back references to the node/graph */ - graph->nodes[n] = node; - node->graph = graph; - node->incrementReference(VX_INTERNAL); /* one for the graph */ - - /* increase the count of nodes in the graph. */ - graph->numNodes++; - - Osal::initPerf(&graph->nodes[n]->perf); - - /* force a re-verify */ - graph->reverify = graph->verified; - graph->verified = vx_false_e; - graph->state = VX_GRAPH_STATE_UNVERIFIED; - - VX_PRINT(VX_ZONE_NODE, "Created Node %p %s affinity:%s\n", node, node->kernel->name, node->context->targets[node->affinity]->name); - } - break; /* succeed or fail, break. */ - } - } - Osal::semPost(&graph->lock); - Reference::printReference((vx_reference )node); - } - else - { - VX_PRINT(VX_ZONE_ERROR, "Kernel %p was invalid!\n", kernel); - vxAddLogEntry((vx_reference)graph, VX_ERROR_INVALID_REFERENCE, "Kernel %p was invalid!\n", kernel); - node = (vx_node)vxGetErrorObject(graph->context, VX_ERROR_INVALID_REFERENCE); - } - } - else - { - VX_PRINT(VX_ZONE_ERROR, "Graph %p was invalid!\n", graph); - vxAddLogEntry((vx_reference)graph, VX_ERROR_INVALID_REFERENCE, "Graph %p as invalid!\n", graph); - } + node = Node::createNode(graph, kernel); return (vx_node)node; } diff --git a/framework/src/vx_object_array.cpp b/framework/src/vx_object_array.cpp index 3a69216..ceb8595 100644 --- a/framework/src/vx_object_array.cpp +++ b/framework/src/vx_object_array.cpp @@ -349,23 +349,63 @@ vx_size ObjectArray::numItems() const return num_items; } +vx_object_array ObjectArray::createObjectArray(vx_context context, vx_enum type) +{ + vx_object_array arr = nullptr; + + if (Context::isValidContext(context) == vx_true_e) + { + if ((type != VX_TYPE_CONTEXT) && (type != VX_TYPE_DELAY) && (type != VX_TYPE_OBJECT_ARRAY)) + { + arr = (vx_object_array)Reference::createReference(context, VX_TYPE_OBJECT_ARRAY, + VX_EXTERNAL, context); + if (Error::getStatus((vx_reference)arr) == VX_SUCCESS && arr->type == VX_TYPE_OBJECT_ARRAY) + { + arr->scope = context; + arr->is_virtual = vx_false_e; + arr->item_type = type; + } + else + { + arr = (vx_object_array)Error::getError(context, VX_ERROR_NO_MEMORY); + } + } + else + { + arr = (vx_object_array)Error::getError(context, VX_ERROR_INVALID_PARAMETERS); + } + } + + return arr; +} + vx_object_array ObjectArray::createObjectArray(vx_reference scope, vx_reference exemplar, vx_size count, vx_bool is_virtual) { vx_context context = scope->context ? scope->context : (vx_context)scope; vx_object_array arr = nullptr; - arr = (vx_object_array)Reference::createReference(context, VX_TYPE_OBJECT_ARRAY, VX_EXTERNAL, scope); - if (vxGetStatus((vx_reference)arr) == VX_SUCCESS && arr->type == VX_TYPE_OBJECT_ARRAY) + if (Context::isValidContext(context) == vx_true_e && + Reference::isValidReference(exemplar) && + (exemplar->type != VX_TYPE_DELAY) && + (exemplar->type != VX_TYPE_OBJECT_ARRAY)) { - arr->scope = scope; - arr->is_virtual = is_virtual; - - if (arr->initObjectArray(exemplar, count) != VX_SUCCESS) + arr = (vx_object_array)Reference::createReference(context, VX_TYPE_OBJECT_ARRAY, VX_EXTERNAL, scope); + if (Error::getStatus((vx_reference)arr) == VX_SUCCESS && arr->type == VX_TYPE_OBJECT_ARRAY) { - Reference::releaseReference((vx_reference*)&arr, VX_TYPE_OBJECT_ARRAY, VX_EXTERNAL, nullptr); - arr = (vx_object_array)vxGetErrorObject(context, VX_ERROR_NO_MEMORY); + arr->scope = scope; + arr->is_virtual = is_virtual; + + if (arr->initObjectArray(exemplar, count) != VX_SUCCESS) + { + Reference::releaseReference((vx_reference*)&arr, VX_TYPE_OBJECT_ARRAY, VX_EXTERNAL, nullptr); + arr = (vx_object_array)Error::getError(context, VX_ERROR_NO_MEMORY); + } } } + else + { + arr = (vx_object_array)Error::getError(context, VX_ERROR_INVALID_PARAMETERS); + } return arr; } @@ -410,24 +450,7 @@ VX_API_ENTRY vx_object_array VX_API_CALL vxCreateObjectArray(vx_context context, { vx_object_array arr = nullptr; - if (Context::isValidContext(context) == vx_true_e) - { - if (Reference::isValidReference(exemplar) && - (exemplar->type != VX_TYPE_DELAY) && - (exemplar->type != VX_TYPE_OBJECT_ARRAY)) - { - arr = ObjectArray::createObjectArray((vx_reference)context, exemplar, count, vx_false_e); - - if (arr == nullptr) - { - arr = (vx_object_array)vxGetErrorObject(context, VX_ERROR_NO_MEMORY); - } - } - else - { - arr = (vx_object_array)vxGetErrorObject(context, VX_ERROR_INVALID_PARAMETERS); - } - } + arr = ObjectArray::createObjectArray((vx_reference)context, exemplar, count, vx_false_e); return arr; } @@ -436,29 +459,7 @@ VX_API_ENTRY vx_object_array VX_API_CALL vxCreateObjectArrayWithType(vx_context { vx_object_array arr = nullptr; - if (Context::isValidContext(context) == vx_true_e) - { - if ((type != VX_TYPE_CONTEXT) && - (type != VX_TYPE_DELAY) && - (type != VX_TYPE_OBJECT_ARRAY)) - { - arr = (vx_object_array)Reference::createReference(context, VX_TYPE_OBJECT_ARRAY, VX_EXTERNAL, context); - if (vxGetStatus((vx_reference)arr) == VX_SUCCESS && arr->type == VX_TYPE_OBJECT_ARRAY) - { - arr->scope = context; - arr->is_virtual = vx_false_e; - arr->item_type = type; - } - else - { - arr = (vx_object_array)vxGetErrorObject(context, VX_ERROR_NO_MEMORY); - } - } - else - { - arr = (vx_object_array)vxGetErrorObject(context, VX_ERROR_INVALID_PARAMETERS); - } - } + arr = ObjectArray::createObjectArray(context, type); return arr; } diff --git a/framework/src/vx_pyramid.cpp b/framework/src/vx_pyramid.cpp index 124f194..2eeae5a 100644 --- a/framework/src/vx_pyramid.cpp +++ b/framework/src/vx_pyramid.cpp @@ -190,9 +190,15 @@ vx_pyramid Pyramid::createPyramid(vx_context context, if (Context::isValidContext(context) == vx_false_e) { /* Context is invalid, we can't get any error object, - * we then simply return nullptr as it is handled by vxGetStatus - */ - return nullptr; + * we then simply return nullptr as it is handled by vxGetStatus + */ + return nullptr; + + } + + if ((width == 0) || (height == 0) || (format == VX_DF_IMAGE_VIRT)) + { + pyramid = (vx_pyramid)Error::getError(context, VX_ERROR_INVALID_PARAMETERS); } if ((scale != VX_SCALE_PYRAMID_HALF) && @@ -200,18 +206,18 @@ vx_pyramid Pyramid::createPyramid(vx_context context, { VX_PRINT(VX_ZONE_ERROR, "Invalid scale %lf for pyramid!\n",scale); vxAddLogEntry((vx_reference)context, VX_ERROR_INVALID_PARAMETERS, "Invalid scale %lf for pyramid!\n",scale); - pyramid = (vx_pyramid)vxGetErrorObject(context, VX_ERROR_INVALID_PARAMETERS); + pyramid = (vx_pyramid)Error::getError(context, VX_ERROR_INVALID_PARAMETERS); } else if (levels == 0 || levels > 8) { VX_PRINT(VX_ZONE_ERROR, "Invalid number of levels for pyramid!\n", levels); vxAddLogEntry((vx_reference)context, VX_ERROR_INVALID_PARAMETERS, "Invalid number of levels for pyramid!\n", levels); - pyramid = (vx_pyramid)vxGetErrorObject(context, VX_ERROR_INVALID_PARAMETERS); + pyramid = (vx_pyramid)Error::getError(context, VX_ERROR_INVALID_PARAMETERS); } else { pyramid = (vx_pyramid)Reference::createReference(context, VX_TYPE_PYRAMID, VX_EXTERNAL, context); - if (vxGetStatus((vx_reference)pyramid) == VX_SUCCESS && pyramid->type == VX_TYPE_PYRAMID) + if (Error::getStatus((vx_reference)pyramid) == VX_SUCCESS && pyramid->type == VX_TYPE_PYRAMID) { vx_status status; pyramid->is_virtual = is_virtual; @@ -220,14 +226,14 @@ vx_pyramid Pyramid::createPyramid(vx_context context, { vxAddLogEntry((vx_reference)pyramid, status, "Failed to initialize pyramid\n"); vxReleasePyramid((vx_pyramid *)&pyramid); - pyramid = (vx_pyramid)vxGetErrorObject(context, status); + pyramid = (vx_pyramid)Error::getError(context, status); } } else { VX_PRINT(VX_ZONE_ERROR, "Failed to allocate memory\n"); vxAddLogEntry((vx_reference)context, VX_ERROR_NO_MEMORY, "Failed to allocate memory\n"); - pyramid = (vx_pyramid)vxGetErrorObject(context, VX_ERROR_NO_MEMORY); + pyramid = (vx_pyramid)Error::getError(context, VX_ERROR_NO_MEMORY); } } @@ -238,6 +244,17 @@ vx_pyramid Pyramid::createPyramid(vx_context context, /* PUBLIC INTERFACE */ /******************************************************************************/ +VX_API_ENTRY vx_pyramid VX_API_CALL vxCreatePyramid(vx_context context, vx_size levels, vx_float32 scale, vx_uint32 width, vx_uint32 height, vx_df_image format) +{ + vx_pyramid pyr = nullptr; + + pyr = (vx_pyramid)Pyramid::createPyramid(context, + levels, scale, width, height, format, + vx_false_e); + + return pyr; +} + VX_API_ENTRY vx_pyramid VX_API_CALL vxCreateVirtualPyramid(vx_graph graph, vx_size levels, vx_float32 scale, @@ -263,27 +280,6 @@ VX_API_ENTRY vx_pyramid VX_API_CALL vxCreateVirtualPyramid(vx_graph graph, return pyramid; } -VX_API_ENTRY vx_pyramid VX_API_CALL vxCreatePyramid(vx_context context, vx_size levels, vx_float32 scale, vx_uint32 width, vx_uint32 height, vx_df_image format) -{ - vx_pyramid pyr = nullptr; - - if (Context::isValidContext(context) == vx_true_e) - { - if ((width == 0) || (height == 0) || (format == VX_DF_IMAGE_VIRT)) - { - pyr = (vx_pyramid)vxGetErrorObject(context, VX_ERROR_INVALID_PARAMETERS); - } - else - { - pyr = (vx_pyramid)Pyramid::createPyramid(context, - levels, scale, width, height, format, - vx_false_e); - } - } - - return pyr; -} - VX_API_ENTRY vx_status VX_API_CALL vxQueryPyramid(vx_pyramid pyramid, vx_enum attribute, void *ptr, vx_size size) { vx_status status = VX_SUCCESS; diff --git a/framework/src/vx_remap.cpp b/framework/src/vx_remap.cpp index be8e013..b3451fa 100644 --- a/framework/src/vx_remap.cpp +++ b/framework/src/vx_remap.cpp @@ -36,6 +36,41 @@ Remap::~Remap() { } +vx_remap Remap::createRemap(vx_context context, vx_uint32 src_width, vx_uint32 src_height, vx_uint32 dst_width, vx_uint32 dst_height) +{ + vx_remap remap = nullptr; + + if (Context::isValidContext(context) == vx_true_e) + { + if (src_width != 0 && src_height != 0 && dst_width != 0 && dst_height != 0) + { + remap = + (vx_remap)Reference::createReference(context, VX_TYPE_REMAP, VX_EXTERNAL, context); + if (Error::getStatus((vx_reference)remap) == VX_SUCCESS && remap->type == VX_TYPE_REMAP) + { + remap->src_width = src_width; + remap->src_height = src_height; + remap->dst_width = dst_width; + remap->dst_height = dst_height; + remap->memory.ndims = 3; + remap->memory.nptrs = 1; + remap->memory.dims[0][VX_DIM_C] = 2; // 2 "channels" of f32 + remap->memory.dims[0][VX_DIM_X] = dst_width; + remap->memory.dims[0][VX_DIM_Y] = dst_height; + remap->memory.strides[0][VX_DIM_C] = sizeof(vx_float32); + } + } + else + { + VX_PRINT(VX_ZONE_ERROR, "Invalid parameters to remap\n"); + vxAddLogEntry(context, VX_ERROR_INVALID_PARAMETERS, "Invalid parameters to remap\n"); + remap = (vx_remap)Error::getError(context, VX_ERROR_INVALID_PARAMETERS); + } + } + + return remap; +} + vx_bool Remap::isValidRemap(vx_remap remap) { if (Reference::isValidReference(remap, VX_TYPE_REMAP) == vx_true_e) @@ -549,33 +584,7 @@ VX_API_ENTRY vx_remap VX_API_CALL vxCreateRemap(vx_context context, vx_uint32 sr { vx_remap remap = nullptr; - if (Context::isValidContext(context) == vx_true_e) - { - if (src_width != 0 && src_height != 0 && dst_width != 0 && dst_height != 0) - { - remap = - (vx_remap)Reference::createReference(context, VX_TYPE_REMAP, VX_EXTERNAL, context); - if (vxGetStatus((vx_reference)remap) == VX_SUCCESS && remap->type == VX_TYPE_REMAP) - { - remap->src_width = src_width; - remap->src_height = src_height; - remap->dst_width = dst_width; - remap->dst_height = dst_height; - remap->memory.ndims = 3; - remap->memory.nptrs = 1; - remap->memory.dims[0][VX_DIM_C] = 2; // 2 "channels" of f32 - remap->memory.dims[0][VX_DIM_X] = dst_width; - remap->memory.dims[0][VX_DIM_Y] = dst_height; - remap->memory.strides[0][VX_DIM_C] = sizeof(vx_float32); - } - } - else - { - VX_PRINT(VX_ZONE_ERROR, "Invalid parameters to remap\n"); - vxAddLogEntry(context, VX_ERROR_INVALID_PARAMETERS, "Invalid parameters to remap\n"); - remap = (vx_remap)vxGetErrorObject(context, VX_ERROR_INVALID_PARAMETERS); - } - } + remap = (vx_remap)Remap::createRemap(context, src_width, src_height, dst_width, dst_height); return remap; } diff --git a/framework/src/vx_scalar.cpp b/framework/src/vx_scalar.cpp index b851c9a..d37b08a 100644 --- a/framework/src/vx_scalar.cpp +++ b/framework/src/vx_scalar.cpp @@ -35,6 +35,33 @@ Scalar::~Scalar() { } +vx_scalar Scalar::createScalar(vx_context context, vx_enum data_type, const void* ptr) +{ + vx_scalar scalar = nullptr; + + if (Context::isValidContext(context) == vx_false_e) return nullptr; + + if (!VX_TYPE_IS_SCALAR(data_type)) + { + VX_PRINT(VX_ZONE_ERROR, "Invalid type to scalar\n"); + vxAddLogEntry(reinterpret_cast(context), VX_ERROR_INVALID_TYPE, + "Invalid type to scalar\n"); + scalar = (vx_scalar)Error::getError(context, VX_ERROR_INVALID_TYPE); + } + else + { + scalar = + (vx_scalar)Reference::createReference(context, VX_TYPE_SCALAR, VX_EXTERNAL, context); + if (Error::getStatus((vx_reference)scalar) == VX_SUCCESS && scalar->type == VX_TYPE_SCALAR) + { + scalar->data_type = data_type; + vxCopyScalar(scalar, (void *)ptr, VX_WRITE_ONLY, VX_MEMORY_TYPE_HOST); + } + } + + return scalar; +} + void* Scalar::allocateScalarMemory(vx_size size) { if (data_addr == nullptr) @@ -489,24 +516,7 @@ VX_API_ENTRY vx_scalar VX_API_CALL vxCreateScalar(vx_context context, vx_enum da { vx_scalar scalar = nullptr; - if (Context::isValidContext(context) == vx_false_e) - return nullptr; - - if (!VX_TYPE_IS_SCALAR(data_type)) - { - VX_PRINT(VX_ZONE_ERROR, "Invalid type to scalar\n"); - vxAddLogEntry(reinterpret_cast(context), VX_ERROR_INVALID_TYPE, "Invalid type to scalar\n"); - scalar = (vx_scalar)vxGetErrorObject(context, VX_ERROR_INVALID_TYPE); - } - else - { - scalar = (vx_scalar)Reference::createReference(context, VX_TYPE_SCALAR, VX_EXTERNAL, context); - if (vxGetStatus((vx_reference)scalar) == VX_SUCCESS && scalar->type == VX_TYPE_SCALAR) - { - scalar->data_type = data_type; - vxCopyScalar(scalar, (void*)ptr, VX_WRITE_ONLY, VX_MEMORY_TYPE_HOST); - } - } + scalar = (vx_scalar)Scalar::createScalar(context, data_type, ptr); return (vx_scalar)scalar; } /* vxCreateScalar() */ diff --git a/framework/src/vx_tensor.cpp b/framework/src/vx_tensor.cpp index d60c098..da2061c 100644 --- a/framework/src/vx_tensor.cpp +++ b/framework/src/vx_tensor.cpp @@ -41,6 +41,42 @@ Tensor::~Tensor() { } +vx_tensor Tensor::createTensor(vx_context context, vx_size number_of_dims, const vx_size *dims, vx_enum data_type, vx_int8 fixed_point_position) +{ + vx_tensor tensor = nullptr; + + if (Context::isValidContext(context) == vx_false_e) + { + return tensor; + } + + if (number_of_dims < 1) + { + VX_PRINT(VX_ZONE_ERROR, "Invalid dimensions for the tensor.\n"); + return (vx_tensor)Error::getError(context, VX_ERROR_INVALID_DIMENSION); + } + + if (!validFormat(data_type, fixed_point_position)) + { + VX_PRINT(VX_ZONE_ERROR, "Invalid format for the tensor.\n"); + return (vx_tensor)Error::getError(context, VX_ERROR_INVALID_TYPE); + } + + tensor = (vx_tensor)Reference::createReference(context, VX_TYPE_TENSOR, VX_EXTERNAL, context); + + if (Error::getStatus((vx_reference)tensor) != VX_SUCCESS || tensor->type != VX_TYPE_TENSOR) + { + VX_PRINT(VX_ZONE_ERROR, "Failed to create reference for tensor.\n"); + return tensor; + } + + tensor->initTensor(dims, number_of_dims, data_type, fixed_point_position); + tensor->parent = nullptr; + tensor->scope = (vx_reference)context; + + return tensor; +} + vx_bool Tensor::isValidTensor(vx_tensor tensor) { if (Reference::isValidReference(reinterpret_cast(tensor), VX_TYPE_TENSOR) == vx_true_e) @@ -469,36 +505,7 @@ VX_API_ENTRY vx_tensor VX_API_CALL vxCreateTensor( { vx_tensor tensor = nullptr; - //TODO: add unlikely() for err checks - - if (Context::isValidContext(context) == vx_false_e) - { - //TODO: check, do we not need to set the err here - return tensor; - } - - if (number_of_dims < 1) - { - VX_PRINT(VX_ZONE_ERROR, "Invalid dimensions for the tensor.\n"); - return (vx_tensor)vxGetErrorObject(context, VX_ERROR_INVALID_DIMENSION); - } - - if (!validFormat(data_type, fixed_point_position)) - { - VX_PRINT(VX_ZONE_ERROR, "Invalid format for the tensor.\n"); - return (vx_tensor)vxGetErrorObject(context, VX_ERROR_INVALID_TYPE); - } - - tensor = (vx_tensor)Reference::createReference(context, VX_TYPE_TENSOR, VX_EXTERNAL, context); - if (vxGetStatus((vx_reference)tensor) != VX_SUCCESS || tensor->type != VX_TYPE_TENSOR) - { - VX_PRINT(VX_ZONE_ERROR, "Failed to create reference for tensor.\n"); - //TODO: check, do we not need to set the err here - return tensor; - } - tensor->initTensor(dims, number_of_dims, data_type, fixed_point_position); - tensor->parent = nullptr; - tensor->scope = (vx_reference)context; + tensor = Tensor::createTensor(context, number_of_dims, dims, data_type, fixed_point_position); return tensor; } diff --git a/framework/src/vx_threshold.cpp b/framework/src/vx_threshold.cpp index 2523fca..addd82d 100644 --- a/framework/src/vx_threshold.cpp +++ b/framework/src/vx_threshold.cpp @@ -41,6 +41,76 @@ Threshold::~Threshold() } +vx_threshold Threshold::createThreshold(vx_context context, vx_enum thresh_type, vx_enum data_type) +{ + vx_threshold threshold = nullptr; + + if (Context::isValidContext(context) == vx_true_e) + { + if (Threshold::isValidThresholdDataType(data_type) == vx_true_e) + { + if (Threshold::isValidThresholdType(thresh_type) == vx_true_e) + { + threshold = (vx_threshold)Reference::createReference(context, VX_TYPE_THRESHOLD, + VX_EXTERNAL, context); + if (Error::getStatus((vx_reference)threshold) == VX_SUCCESS && + threshold->type == VX_TYPE_THRESHOLD) + { + threshold->thresh_type = thresh_type; + threshold->data_type = data_type; + switch (data_type) + { + case VX_TYPE_BOOL: + threshold->true_value.U1 = VX_U1_THRESHOLD_TRUE_VALUE; + threshold->false_value.U1 = VX_U1_THRESHOLD_FALSE_VALUE; + break; + case VX_TYPE_INT8: + threshold->true_value.U8 = VX_DEFAULT_THRESHOLD_TRUE_VALUE; + threshold->false_value.U8 = VX_DEFAULT_THRESHOLD_FALSE_VALUE; + break; + case VX_TYPE_UINT8: + threshold->true_value.U8 = VX_DEFAULT_THRESHOLD_TRUE_VALUE; + threshold->false_value.U8 = VX_DEFAULT_THRESHOLD_FALSE_VALUE; + break; + case VX_TYPE_UINT16: + threshold->true_value.U16 = VX_DEFAULT_THRESHOLD_TRUE_VALUE; + threshold->false_value.U16 = VX_DEFAULT_THRESHOLD_FALSE_VALUE; + break; + case VX_TYPE_INT16: + threshold->true_value.S16 = VX_DEFAULT_THRESHOLD_TRUE_VALUE; + threshold->false_value.S16 = VX_DEFAULT_THRESHOLD_FALSE_VALUE; + break; + case VX_TYPE_INT32: + threshold->true_value.S32 = VX_DEFAULT_THRESHOLD_TRUE_VALUE; + threshold->false_value.S32 = VX_DEFAULT_THRESHOLD_FALSE_VALUE; + break; + case VX_TYPE_UINT32: + threshold->true_value.U32 = VX_DEFAULT_THRESHOLD_TRUE_VALUE; + threshold->false_value.U32 = VX_DEFAULT_THRESHOLD_FALSE_VALUE; + break; + default: + break; + } + } + } + else + { + VX_PRINT(VX_ZONE_ERROR, "Invalid threshold type\n"); + vxAddLogEntry(context, VX_ERROR_INVALID_TYPE, "Invalid threshold type\n"); + threshold = (vx_threshold)Error::getError(context, VX_ERROR_INVALID_TYPE); + } + } + else + { + VX_PRINT(VX_ZONE_ERROR, "Invalid data type\n"); + vxAddLogEntry(context, VX_ERROR_INVALID_TYPE, "Invalid data type\n"); + threshold = (vx_threshold)Error::getError(context, VX_ERROR_INVALID_TYPE); + } + } + + return threshold; +} + void Threshold::setBinaryValue(vx_int32 value) { this->value.S32 = value; @@ -586,68 +656,7 @@ VX_API_ENTRY vx_threshold VX_API_CALL vxCreateThreshold(vx_context context, vx_e { vx_threshold threshold = nullptr; - if (Context::isValidContext(context) == vx_true_e) - { - if (Threshold::isValidThresholdDataType(data_type) == vx_true_e) - { - if (Threshold::isValidThresholdType(thresh_type) == vx_true_e) - { - threshold = (vx_threshold)Reference::createReference(context, VX_TYPE_THRESHOLD, - VX_EXTERNAL, context); - if (vxGetStatus((vx_reference)threshold) == VX_SUCCESS && - threshold->type == VX_TYPE_THRESHOLD) - { - threshold->thresh_type = thresh_type; - threshold->data_type = data_type; - switch (data_type) - { - case VX_TYPE_BOOL: - threshold->true_value.U1 = VX_U1_THRESHOLD_TRUE_VALUE; - threshold->false_value.U1 = VX_U1_THRESHOLD_FALSE_VALUE; - break; - case VX_TYPE_INT8: - threshold->true_value.U8 = VX_DEFAULT_THRESHOLD_TRUE_VALUE; - threshold->false_value.U8 = VX_DEFAULT_THRESHOLD_FALSE_VALUE; - break; - case VX_TYPE_UINT8: - threshold->true_value.U8 = VX_DEFAULT_THRESHOLD_TRUE_VALUE; - threshold->false_value.U8 = VX_DEFAULT_THRESHOLD_FALSE_VALUE; - break; - case VX_TYPE_UINT16: - threshold->true_value.U16 = VX_DEFAULT_THRESHOLD_TRUE_VALUE; - threshold->false_value.U16 = VX_DEFAULT_THRESHOLD_FALSE_VALUE; - break; - case VX_TYPE_INT16: - threshold->true_value.S16 = VX_DEFAULT_THRESHOLD_TRUE_VALUE; - threshold->false_value.S16 = VX_DEFAULT_THRESHOLD_FALSE_VALUE; - break; - case VX_TYPE_INT32: - threshold->true_value.S32 = VX_DEFAULT_THRESHOLD_TRUE_VALUE; - threshold->false_value.S32 = VX_DEFAULT_THRESHOLD_FALSE_VALUE; - break; - case VX_TYPE_UINT32: - threshold->true_value.U32 = VX_DEFAULT_THRESHOLD_TRUE_VALUE; - threshold->false_value.U32 = VX_DEFAULT_THRESHOLD_FALSE_VALUE; - break; - default: - break; - } - } - } - else - { - VX_PRINT(VX_ZONE_ERROR, "Invalid threshold type\n"); - vxAddLogEntry(context, VX_ERROR_INVALID_TYPE, "Invalid threshold type\n"); - threshold = (vx_threshold)vxGetErrorObject(context, VX_ERROR_INVALID_TYPE); - } - } - else - { - VX_PRINT(VX_ZONE_ERROR, "Invalid data type\n"); - vxAddLogEntry(context, VX_ERROR_INVALID_TYPE, "Invalid data type\n"); - threshold = (vx_threshold)vxGetErrorObject(context, VX_ERROR_INVALID_TYPE); - } - } + threshold = Threshold::createThreshold(context, thresh_type, data_type); return threshold; } diff --git a/framework/src/vx_user_data_object.cpp b/framework/src/vx_user_data_object.cpp index 094676f..2f29812 100644 --- a/framework/src/vx_user_data_object.cpp +++ b/framework/src/vx_user_data_object.cpp @@ -42,6 +42,69 @@ UserDataObject::~UserDataObject() Memory::freeMemory(context, &memory); } +vx_user_data_object UserDataObject::createUserDataObject(vx_context context, const vx_char *type_name, vx_size size, const void *ptr) +{ + vx_user_data_object user_data_object = nullptr; + vx_status status = VX_SUCCESS; + + if(Context::isValidContext(context) == (vx_bool)vx_true_e) + { + if (size < 1U) + { + VX_PRINT(VX_ZONE_ERROR, "Invalid size for the user data object.\n"); + user_data_object = (vx_user_data_object)Error::getError(context, VX_ERROR_INVALID_PARAMETERS); + } + + if( nullptr == user_data_object ) + { + user_data_object = (vx_user_data_object)Reference::createReference(context, VX_TYPE_USER_DATA_OBJECT, VX_EXTERNAL, context); + + if ((Error::getStatus((vx_reference)user_data_object) == (vx_status)VX_SUCCESS) && + (user_data_object->type == VX_TYPE_USER_DATA_OBJECT)) + { + user_data_object->size = size; + + /* Initialize string with zeros, which safely fills with nullptr terminators */ + user_data_object->type_name[0] = (char)0; + + if (type_name != nullptr) + { + strncpy(user_data_object->type_name, type_name, VX_MAX_REFERENCE_NAME); + } + + user_data_object->memory.nptrs = 1; + user_data_object->memory.ndims = 1; + user_data_object->memory.dims[0][0] = (vx_uint32)size; + + if (nullptr != ptr) + { + status = vxCopyUserDataObject(user_data_object, 0, size, (void*)ptr, (vx_enum)VX_WRITE_ONLY, (vx_enum)VX_MEMORY_TYPE_HOST); + } + else + { + status = VX_BOOL_TO_STATUS(user_data_object->allocateUserDataObject()); + + if (status == (vx_status)VX_SUCCESS) + { + vx_uint8 *start_ptr = (vx_uint8 *)&user_data_object->memory.ptrs[0][0]; + memset(start_ptr, 0, size); + } + } + } + + if(status != (vx_status)VX_SUCCESS) + { + user_data_object = nullptr; + VX_PRINT(VX_ZONE_ERROR, "Failed to create user data object with error: %d\n", status); + user_data_object = (vx_user_data_object)Error::getError( + context, (vx_status)VX_ERROR_INVALID_PARAMETERS); + } + } + } + + return user_data_object; +} + const vx_char *UserDataObject::typeName() const { return type_name; @@ -259,62 +322,8 @@ VX_API_ENTRY vx_user_data_object VX_API_CALL vxCreateUserDataObject( const void *ptr) { vx_user_data_object user_data_object = nullptr; - vx_status status = (vx_status)VX_SUCCESS; - - if(Context::isValidContext(context) == (vx_bool)vx_true_e) - { - if (size < 1U) - { - VX_PRINT(VX_ZONE_ERROR, "Invalid size for the user data object.\n"); - user_data_object = (vx_user_data_object)vxGetErrorObject((vx_context)context, (vx_status)VX_ERROR_INVALID_PARAMETERS); - } - - if( nullptr == user_data_object ) - { - user_data_object = (vx_user_data_object)Reference::createReference(context, VX_TYPE_USER_DATA_OBJECT, VX_EXTERNAL, context); - - if ((vxGetStatus((vx_reference)user_data_object) == (vx_status)VX_SUCCESS) && - (user_data_object->type == VX_TYPE_USER_DATA_OBJECT)) - { - user_data_object->size = size; - - /* Initialize string with zeros, which safely fills with nullptr terminators */ - user_data_object->type_name[0] = (char)0; - - if (type_name != nullptr) - { - strncpy(user_data_object->type_name, type_name, VX_MAX_REFERENCE_NAME); - } - - user_data_object->memory.nptrs = 1; - user_data_object->memory.ndims = 1; - user_data_object->memory.dims[0][0] = (vx_uint32)size; - - if (nullptr != ptr) - { - status = vxCopyUserDataObject(user_data_object, 0, size, (void*)ptr, (vx_enum)VX_WRITE_ONLY, (vx_enum)VX_MEMORY_TYPE_HOST); - } - else - { - status = VX_BOOL_TO_STATUS(user_data_object->allocateUserDataObject()); - if (status == (vx_status)VX_SUCCESS) - { - vx_uint8 *start_ptr = (vx_uint8 *)&user_data_object->memory.ptrs[0][0]; - memset(start_ptr, 0, size); - } - } - } - - if(status != (vx_status)VX_SUCCESS) - { - user_data_object = nullptr; - VX_PRINT(VX_ZONE_ERROR, "Failed to create user data object with error: %d\n", status); - user_data_object = (vx_user_data_object)vxGetErrorObject( - context, (vx_status)VX_ERROR_INVALID_PARAMETERS); - } - } - } + user_data_object = UserDataObject::createUserDataObject(context, type_name, size, ptr); return (user_data_object); } From a482516b6c0b5cfa8ab4cedd5f5d85f6e91b91df Mon Sep 17 00:00:00 2001 From: Andrew Mikhail Date: Sat, 9 Aug 2025 18:17:06 -0700 Subject: [PATCH 3/9] More updates to delay and lut --- framework/include/vx_array.h | 82 +++--- framework/include/vx_delay.h | 11 + framework/include/vx_object_array.h | 3 +- framework/include/vx_pyramid.h | 2 +- framework/src/vx_delay.cpp | 408 +++++++++++++++------------- framework/src/vx_lut.cpp | 38 ++- 6 files changed, 300 insertions(+), 244 deletions(-) diff --git a/framework/include/vx_array.h b/framework/include/vx_array.h index 36a4458..70726ee 100644 --- a/framework/include/vx_array.h +++ b/framework/include/vx_array.h @@ -69,17 +69,29 @@ class Array : public Reference * @param capacity capacity of array * @param is_virtual is array virtual * @param type array or lut - * @return vx_array + * @return vx_array array object * @ingroup group_int_array */ - static vx_array createArray(vx_context context, vx_enum item_type, vx_size capacity, vx_bool is_virtual, vx_enum type); + static vx_array createArray( + vx_context context, vx_enum item_type, vx_size capacity, vx_bool is_virtual = vx_false_e, vx_enum type = VX_TYPE_ARRAY); + + /** + * @brief Create a LUT object + * + * @param context context object + * @param data_type array object type + * @param count count of array + * @return vx_lut_t LUT object + * @ingroup group_int_array + */ + static vx_lut_t createLUT(vx_context context, vx_enum data_type, vx_size count); /** * @brief Validate array object * * @param item_type array object type * @param capacity capacity of array - * @return vx_bool + * @return vx_bool true if valid, false otherwise * @ingroup group_int_array */ vx_bool validateArray(vx_enum item_type, vx_size capacity); @@ -87,7 +99,7 @@ class Array : public Reference /** * @brief Allocate memory for array object * - * @return vx_bool + * @return vx_bool true if successful, false otherwise * @ingroup group_int_array */ vx_bool allocateArray(); @@ -97,7 +109,7 @@ class Array : public Reference * * @param context global context * @param item_type item type - * @return vx_size + * @return vx_size size of item * @ingroup group_int_array */ static vx_size itemSize(vx_context context, vx_enum item_type); @@ -107,7 +119,7 @@ class Array : public Reference * * @param context global context * @param item_type item type - * @return vx_bool + * @return vx_bool true if valid, false otherwise * @ingroup group_int_array */ static vx_bool isValidArrayItemType(vx_context context, vx_enum item_type); @@ -116,7 +128,7 @@ class Array : public Reference * @brief Validate array object * * @param arr array object to check - * @return vx_bool + * @return vx_bool true if valid, false otherwise * @ingroup group_int_array */ static vx_bool isValidArray(vx_array arr); @@ -133,7 +145,7 @@ class Array : public Reference * * @param item_type array object type * @param capacity capacity of array - * @return vx_bool + * @return vx_bool true if successful, false otherwise * @ingroup group_int_array */ vx_bool initVirtualArray(vx_enum item_type, vx_size capacity); @@ -209,12 +221,12 @@ class Array : public Reference /** * @brief Access array range in object * - * @param start start index - * @param end end index - * @param pStride pointer of stride - * @param ptr pointer to data - * @param usage ro | rw | wo - * @return vx_status + * @param start start index + * @param end end index + * @param pStride pointer of stride + * @param ptr pointer to data + * @param usage ro | rw | wo + * @return vx_status VX_SUCCESS if successful, any other value indicates failure. * @ingroup group_int_array */ vx_status accessArrayRange(vx_size start, vx_size end, vx_size *pStride, void **ptr, vx_enum usage); @@ -222,10 +234,10 @@ class Array : public Reference /** * @brief Commit array range * - * @param start start index - * @param end end index - * @param ptr pointer to data - * @return vx_status + * @param start start index + * @param end end index + * @param ptr pointer to data + * @return vx_status VX_SUCCESS if successful, any other value indicates failure. * @ingroup group_int_array */ vx_status commitArrayRange(vx_size start, vx_size end, const void *ptr); @@ -233,13 +245,13 @@ class Array : public Reference /** * @brief Copy array range * - * @param start start index - * @param end end index - * @param stride size of stride - * @param ptr pointer to data - * @param usage ro | rw | wo - * @param mem_type host | device - * @return vx_status + * @param start start index + * @param end end index + * @param stride size of stride + * @param ptr pointer to data + * @param usage ro | rw | wo + * @param mem_type host | device + * @return vx_status VX_SUCCESS if successful, any other value indicates failure. * @ingroup group_int_array */ vx_status copyArrayRange(vx_size start, vx_size end, vx_size stride, void *ptr, vx_enum usage, vx_enum mem_type); @@ -247,15 +259,15 @@ class Array : public Reference /** * @brief Map array range * - * @param start start index - * @param end end index - * @param map_id memory map id - * @param stride size of stride - * @param ptr pointer to data - * @param usage ro | rw | wo - * @param mem_type host | device - * @param flags additional flags - * @return vx_status + * @param start start index + * @param end end index + * @param map_id memory map id + * @param stride size of stride + * @param ptr pointer to data + * @param usage ro | rw | wo + * @param mem_type host | device + * @param flags additional flags + * @return vx_status VX_SUCCESS if successful, any other value indicates failure. * @ingroup group_int_array */ vx_status mapArrayRange(vx_size start, vx_size end, vx_map_id *map_id, vx_size *stride, @@ -265,7 +277,7 @@ class Array : public Reference * @brief Unmap array range * * @param map_id memory map id - * @return vx_status + * @return vx_status VX_SUCCESS if successful, any other value indicates failure. * @ingroup group_int_array */ vx_status unmapArrayRange(vx_map_id map_id); diff --git a/framework/include/vx_delay.h b/framework/include/vx_delay.h index a390100..d7834db 100644 --- a/framework/include/vx_delay.h +++ b/framework/include/vx_delay.h @@ -46,6 +46,17 @@ class Delay : public Reference */ ~Delay(); + /** + * @brief Create a delay object + * + * @param context + * @param exemplar + * @param count + * @return vx_delay + * @ingroup group_int_delay + */ + static vx_delay createDelay(vx_context context, vx_reference exemplar, vx_size count); + /** * @brief Get data type of references associated with this delay object * diff --git a/framework/include/vx_object_array.h b/framework/include/vx_object_array.h index fbd5639..bb9452c 100644 --- a/framework/include/vx_object_array.h +++ b/framework/include/vx_object_array.h @@ -71,7 +71,8 @@ class ObjectArray : public Reference * @return vx_object_array Object array created * @ingroup group_int_object_array */ - static vx_object_array createObjectArray(vx_reference scope, vx_reference exemplar, vx_size count, vx_bool is_virtual); + static vx_object_array createObjectArray( + vx_reference scope, vx_reference exemplar, vx_size count, vx_bool is_virtual = vx_false_e); /** * @brief Initialize object array diff --git a/framework/include/vx_pyramid.h b/framework/include/vx_pyramid.h index a42845e..1923848 100644 --- a/framework/include/vx_pyramid.h +++ b/framework/include/vx_pyramid.h @@ -70,7 +70,7 @@ class Pyramid : public Reference vx_uint32 width, vx_uint32 height, vx_df_image format, - vx_bool is_virtual); + vx_bool is_virtual = vx_false_e); /** * @brief Get the number of levels in the pyramid diff --git a/framework/src/vx_delay.cpp b/framework/src/vx_delay.cpp index 5af6ee9..e2f07e6 100644 --- a/framework/src/vx_delay.cpp +++ b/framework/src/vx_delay.cpp @@ -38,6 +38,216 @@ Delay::~Delay() { } +vx_delay Delay::createDelay(vx_context context, vx_reference exemplar, vx_size count) +{ + vx_delay delay = nullptr; + vx_uint32 t = 0u; + vx_enum invalid_types[] = { + VX_TYPE_CONTEXT, + VX_TYPE_GRAPH, + VX_TYPE_NODE, + VX_TYPE_KERNEL, + VX_TYPE_TARGET, + VX_TYPE_PARAMETER, + VX_TYPE_REFERENCE, + VX_TYPE_DELAY, /* no delays of delays */ +#ifdef OPENVX_KHR_XML + VX_TYPE_IMPORT, +#endif + }; + + if (Context::isValidContext(context) == vx_false_e) + { + return delay; + } + + if (Reference::isValidReference(exemplar) == vx_false_e) + { + return (vx_delay)Error::getError(context, VX_ERROR_INVALID_REFERENCE); + } + + for (t = 0u; t < dimof(invalid_types); t++) + { + if (exemplar->type == invalid_types[t]) + { + VX_PRINT(VX_ZONE_ERROR, "Attempted to create delay of invalid object type!\n"); + vxAddLogEntry((vx_reference)context, VX_ERROR_INVALID_REFERENCE, "Attempted to create delay of invalid object type!\n"); + return (vx_delay)Error::getError(context, VX_ERROR_INVALID_REFERENCE); + } + } + + delay = (vx_delay)Reference::createReference(context, VX_TYPE_DELAY, VX_EXTERNAL, context); + if (Error::getStatus((vx_reference)delay) == VX_SUCCESS && + delay->type == VX_TYPE_DELAY) + { + vx_size i = 0; + delay->pyr = nullptr; + delay->set = new vx_delay_param_t[count](); + delay->refs = new vx_reference[count](); + delay->type = exemplar->type; + delay->count = count; + VX_PRINT(VX_ZONE_DELAY, "Creating Delay of %u objects of type %x!\n", count, exemplar->type); + for (i = 0; i < count; i++) + { + vx_bool ref_bool = vx_true_e; + switch (exemplar->type) + { + case VX_TYPE_IMAGE: + { + vx_image image = (vx_image )exemplar; + delay->refs[i] = (vx_reference)Image::createImage(context, image->width, image->height, image->format); + VX_PRINT(VX_ZONE_DELAY, "Creating image with width %d height %d format %d", image->width, image->height, image->format); + break; + } + case VX_TYPE_ARRAY: + { + vx_array arr = (vx_array )exemplar; + delay->refs[i] = (vx_reference)Array::createArray(context, arr->item_type, arr->capacity); + break; + } + case VX_TYPE_MATRIX: + { + vx_matrix mat = (vx_matrix)exemplar; + delay->refs[i] = (vx_reference)Matrix::createMatrix(context, mat->data_type, mat->columns, mat->rows); + break; + } + case VX_TYPE_CONVOLUTION: + { + vx_convolution conv = (vx_convolution)exemplar; + vx_convolution conv2 = Convolution::createConvolution(context, conv->columns, conv->rows); + conv2->scale = conv->scale; + delay->refs[i] = (vx_reference)conv2; + break; + } + case VX_TYPE_DISTRIBUTION: + { + vx_distribution dist = (vx_distribution)exemplar; + delay->refs[i] = (vx_reference)Distribution::createDistribution( + context, dist->memory.dims[0][VX_DIM_X], dist->offset_x, dist->range_x); + break; + } + case VX_TYPE_REMAP: + { + vx_remap remap = (vx_remap)exemplar; + delay->refs[i] = (vx_reference)Remap::createRemap( + context, remap->src_width, remap->src_height, remap->dst_width, remap->dst_height); + break; + } + case VX_TYPE_LUT: + { + vx_lut_t lut = (vx_lut_t)exemplar; + delay->refs[i] = (vx_reference)vxCreateLUT(context, lut->item_type, lut->capacity); + break; + } + case VX_TYPE_PYRAMID: + { + vx_pyramid pyramid = (vx_pyramid )exemplar; + delay->refs[i] = (vx_reference)Pyramid::createPyramid( + context, pyramid->numLevels, pyramid->scale, pyramid->width, pyramid->height, pyramid->format); + break; + } + case VX_TYPE_THRESHOLD: + { + vx_threshold thresh = (vx_threshold )exemplar; + delay->refs[i] = (vx_reference)Threshold::createThreshold(context, thresh->thresh_type, VX_TYPE_UINT8); + break; + } + case VX_TYPE_SCALAR: + { + vx_scalar scalar = (vx_scalar )exemplar; + delay->refs[i] = (vx_reference)Scalar::createScalar(context, scalar->data_type, nullptr); + break; + } + case VX_TYPE_TENSOR: + { + vx_tensor tensor = (vx_tensor )exemplar; + delay->refs[i] = (vx_reference)Tensor::createTensor( + context, tensor->number_of_dimensions, tensor->dimensions, tensor->data_type, tensor->fixed_point_position); + break; + } + default: + ref_bool = vx_false_e; + break; + } + if (ref_bool) + { + /* set the object as a delay element */ + delay->refs[i]->initReferenceForDelay(delay, (vx_int32)i); + /* change the counting from external to internal */ + delay->refs[i]->incrementReference(VX_INTERNAL); + delay->refs[i]->decrementReference(VX_EXTERNAL); + /* set the scope to the delay */ + ((vx_reference)delay->refs[i])->scope = (vx_reference)delay; + } + } + + if (exemplar->type == VX_TYPE_PYRAMID) + { + /* create internal delays for each pyramid level */ + vx_size j = 0; + vx_size numLevels = ((vx_pyramid)exemplar)->numLevels; + delay->pyr = new vx_delay[numLevels](); + vx_delay pyrdelay = nullptr; + for (j = 0; j < numLevels; ++j) + { + pyrdelay = (vx_delay)Reference::createReference(context, VX_TYPE_DELAY, VX_INTERNAL, (vx_reference)delay); + delay->pyr[j] = pyrdelay; + if (Error::getStatus((vx_reference)pyrdelay) == VX_SUCCESS && pyrdelay->type == VX_TYPE_DELAY) + { + pyrdelay->set = new vx_delay_param_t[count](); + pyrdelay->refs = new vx_reference[count](); + pyrdelay->type = VX_TYPE_IMAGE; + pyrdelay->count = count; + for (i = 0; i < count; i++) + { + if (Reference::isValidReference((vx_pyramid)delay->refs[i], + VX_TYPE_PYRAMID) == vx_true_e) + { + pyrdelay->refs[i] = ((vx_pyramid)delay->refs[i])->getAtLevel((vx_uint32)j); + } + /* set the object as a delay element */ + pyrdelay->refs[i]->initReferenceForDelay(pyrdelay, (vx_int32)i); + /* change the counting from external to internal */ + pyrdelay->refs[i]->incrementReference(VX_INTERNAL); + pyrdelay->refs[i]->decrementReference(VX_EXTERNAL); + } + } + } + } + + if (exemplar->type == VX_TYPE_OBJECT_ARRAY) + { + vx_object_array objarray = (vx_object_array )exemplar; + if (objarray->num_items != 0) + { + for (i = 0; i < count; i++) + { + delay->refs[i] = (vx_reference)ObjectArray::createObjectArray(context, + objarray->items[0], + objarray->num_items); + /* set the object as a delay element */ + delay->refs[i]->initReferenceForDelay(delay, (vx_int32)i); + /* change the counting from external to internal */ + delay->refs[i]->incrementReference(VX_INTERNAL); + delay->refs[i]->decrementReference(VX_EXTERNAL); + /* set the scope to the delay */ + ((vx_reference)delay->refs[i])->scope = (vx_reference)delay; + } + } + else + { + vxReleaseDelay(&delay); + } + } + } + else + { + VX_PRINT(VX_ZONE_ERROR, "Delay created is invalid!\n"); + } + + return delay; +} + vx_enum Delay::dataType() const { return type; @@ -63,7 +273,7 @@ vx_reference Delay::getReference(vx_int32 index) { vxAddLogEntry((vx_reference)this, VX_ERROR_INVALID_PARAMETERS, "Failed to retrieve reference from delay by index %d\n", index); - ref = (vx_reference)vxGetErrorObject(this->context, VX_ERROR_INVALID_PARAMETERS); + ref = (vx_reference)Error::getError(this->context, VX_ERROR_INVALID_PARAMETERS); } return ref; @@ -294,202 +504,8 @@ VX_API_ENTRY vx_delay VX_API_CALL vxCreateDelay(vx_context context, vx_size count) { vx_delay delay = nullptr; - vx_uint32 t = 0u; - vx_enum invalid_types[] = { - VX_TYPE_CONTEXT, - VX_TYPE_GRAPH, - VX_TYPE_NODE, - VX_TYPE_KERNEL, - VX_TYPE_TARGET, - VX_TYPE_PARAMETER, - VX_TYPE_REFERENCE, - VX_TYPE_DELAY, /* no delays of delays */ -#ifdef OPENVX_KHR_XML - VX_TYPE_IMPORT, -#endif - }; - - if (Context::isValidContext(context) == vx_false_e) - { - return delay; - } - - if (Reference::isValidReference(exemplar) == vx_false_e) - { - return (vx_delay)vxGetErrorObject(context, VX_ERROR_INVALID_REFERENCE); - } - - for (t = 0u; t < dimof(invalid_types); t++) - { - if (exemplar->type == invalid_types[t]) - { - VX_PRINT(VX_ZONE_ERROR, "Attempted to create delay of invalid object type!\n"); - vxAddLogEntry((vx_reference)context, VX_ERROR_INVALID_REFERENCE, "Attempted to create delay of invalid object type!\n"); - return (vx_delay)vxGetErrorObject(context, VX_ERROR_INVALID_REFERENCE); - } - } - delay = (vx_delay)Reference::createReference(context, VX_TYPE_DELAY, VX_EXTERNAL, context); - if (vxGetStatus((vx_reference)delay) == VX_SUCCESS && - delay->type == VX_TYPE_DELAY) - { - vx_size i = 0; - delay->pyr = nullptr; - delay->set = new vx_delay_param_t[count](); - delay->refs = new vx_reference[count](); - delay->type = exemplar->type; - delay->count = count; - VX_PRINT(VX_ZONE_DELAY, "Creating Delay of %u objects of type %x!\n", count, exemplar->type); - for (i = 0; i < count; i++) - { - vx_bool ref_bool = vx_true_e; - switch (exemplar->type) - { - case VX_TYPE_IMAGE: - { - vx_image image = (vx_image )exemplar; - delay->refs[i] = (vx_reference)vxCreateImage(context, image->width, image->height, image->format); - VX_PRINT(VX_ZONE_DELAY, "Creating image with width %d height %d format %d", image->width, image->height, image->format); - break; - } - case VX_TYPE_ARRAY: - { - vx_array arr = (vx_array )exemplar; - delay->refs[i] = (vx_reference)vxCreateArray(context, arr->item_type, arr->capacity); - break; - } - case VX_TYPE_MATRIX: - { - vx_matrix mat = (vx_matrix)exemplar; - delay->refs[i] = (vx_reference)vxCreateMatrix(context, mat->data_type, mat->columns, mat->rows); - break; - } - case VX_TYPE_CONVOLUTION: - { - vx_convolution conv = (vx_convolution)exemplar; - vx_convolution conv2 = vxCreateConvolution(context, conv->columns, conv->rows); - conv2->scale = conv->scale; - delay->refs[i] = (vx_reference)conv2; - break; - } - case VX_TYPE_DISTRIBUTION: - { - vx_distribution dist = (vx_distribution)exemplar; - delay->refs[i] = (vx_reference)vxCreateDistribution(context, dist->memory.dims[0][VX_DIM_X], dist->offset_x, dist->range_x); - break; - } - case VX_TYPE_REMAP: - { - vx_remap remap = (vx_remap)exemplar; - delay->refs[i] = (vx_reference)vxCreateRemap(context, remap->src_width, remap->src_height, remap->dst_width, remap->dst_height); - break; - } - case VX_TYPE_LUT: - { - vx_lut_t lut = (vx_lut_t)exemplar; - delay->refs[i] = (vx_reference)vxCreateLUT(context, lut->item_type, lut->capacity); - break; - } - case VX_TYPE_PYRAMID: - { - vx_pyramid pyramid = (vx_pyramid )exemplar; - delay->refs[i] = (vx_reference)vxCreatePyramid(context, pyramid->numLevels, pyramid->scale, pyramid->width, pyramid->height, pyramid->format); - break; - } - case VX_TYPE_THRESHOLD: - { - vx_threshold thresh = (vx_threshold )exemplar; - delay->refs[i] = (vx_reference)vxCreateThreshold(context, thresh->thresh_type, VX_TYPE_UINT8); - break; - } - case VX_TYPE_SCALAR: - { - vx_scalar scalar = (vx_scalar )exemplar; - delay->refs[i] = (vx_reference)vxCreateScalar(context, scalar->data_type, nullptr); - break; - } - case VX_TYPE_TENSOR: - { - vx_tensor tensor = (vx_tensor )exemplar; - delay->refs[i] = (vx_reference)vxCreateTensor(context, tensor->number_of_dimensions, tensor->dimensions, tensor->data_type, - tensor->fixed_point_position); - break; - } - default: - ref_bool = vx_false_e; - break; - } - if (ref_bool) - { - /* set the object as a delay element */ - delay->refs[i]->initReferenceForDelay(delay, (vx_int32)i); - /* change the counting from external to internal */ - delay->refs[i]->incrementReference(VX_INTERNAL); - delay->refs[i]->decrementReference(VX_EXTERNAL); - /* set the scope to the delay */ - ((vx_reference)delay->refs[i])->scope = (vx_reference)delay; - } - } - - if (exemplar->type == VX_TYPE_PYRAMID) - { - /* create internal delays for each pyramid level */ - vx_size j = 0; - vx_size numLevels = ((vx_pyramid)exemplar)->numLevels; - delay->pyr = new vx_delay[numLevels](); - vx_delay pyrdelay = nullptr; - for (j = 0; j < numLevels; ++j) - { - pyrdelay = (vx_delay)Reference::createReference(context, VX_TYPE_DELAY, VX_INTERNAL, (vx_reference)delay); - delay->pyr[j] = pyrdelay; - if (vxGetStatus((vx_reference)pyrdelay) == VX_SUCCESS && pyrdelay->type == VX_TYPE_DELAY) - { - pyrdelay->set = new vx_delay_param_t[count](); - pyrdelay->refs = new vx_reference[count](); - pyrdelay->type = VX_TYPE_IMAGE; - pyrdelay->count = count; - for (i = 0; i < count; i++) - { - pyrdelay->refs[i] = (vx_reference)vxGetPyramidLevel((vx_pyramid)delay->refs[i], (vx_uint32)j); - /* set the object as a delay element */ - pyrdelay->refs[i]->initReferenceForDelay(pyrdelay, (vx_int32)i); - /* change the counting from external to internal */ - pyrdelay->refs[i]->incrementReference(VX_INTERNAL); - pyrdelay->refs[i]->decrementReference(VX_EXTERNAL); - } - } - } - } - - if (exemplar->type == VX_TYPE_OBJECT_ARRAY) - { - vx_object_array objarray = (vx_object_array )exemplar; - if (objarray->num_items != 0) - { - for (i = 0; i < count; i++) - { - delay->refs[i] = (vx_reference)vxCreateObjectArray(context, - objarray->items[0], - objarray->num_items); - /* set the object as a delay element */ - delay->refs[i]->initReferenceForDelay(delay, (vx_int32)i); - /* change the counting from external to internal */ - delay->refs[i]->incrementReference(VX_INTERNAL); - delay->refs[i]->decrementReference(VX_EXTERNAL); - /* set the scope to the delay */ - ((vx_reference)delay->refs[i])->scope = (vx_reference)delay; - } - } - else - { - vxReleaseDelay(&delay); - } - } - } - else - { - VX_PRINT(VX_ZONE_ERROR, "Delay created is invalid!\n"); - } + delay = Delay::createDelay(context, exemplar, count); return (vx_delay)delay; } diff --git a/framework/src/vx_lut.cpp b/framework/src/vx_lut.cpp index 67a3b27..bf1e154 100644 --- a/framework/src/vx_lut.cpp +++ b/framework/src/vx_lut.cpp @@ -19,7 +19,7 @@ using namespace corevx; -VX_API_ENTRY vx_lut VX_API_CALL vxCreateLUT(vx_context context, vx_enum data_type, vx_size count) +vx_lut_t Lut::createLUT(vx_context context, vx_enum data_type, vx_size count) { vx_lut_t lut = nullptr; @@ -32,13 +32,14 @@ VX_API_ENTRY vx_lut VX_API_CALL vxCreateLUT(vx_context context, vx_enum data_typ { VX_PRINT(VX_ZONE_ERROR, "Invalid parameter to LUT\n"); vxAddLogEntry(context, VX_ERROR_INVALID_PARAMETERS, "Invalid parameter to LUT\n"); - lut = (vx_lut_t)vxGetErrorObject(context, VX_ERROR_INVALID_PARAMETERS); + lut = (vx_lut_t)Error::getError(context, VX_ERROR_INVALID_PARAMETERS); } else #endif { - lut = (vx_lut_t)Array::createArray(context, VX_TYPE_UINT8, count, vx_false_e, VX_TYPE_LUT); - if (vxGetStatus((vx_reference)lut) == VX_SUCCESS && lut->type == VX_TYPE_LUT) + lut = (vx_lut_t)Array::createArray(context, VX_TYPE_UINT8, count, vx_false_e, + VX_TYPE_LUT); + if (Error::getStatus((vx_reference)lut) == VX_SUCCESS && lut->type == VX_TYPE_LUT) { lut->num_items = count; lut->offset = 0; @@ -52,15 +53,16 @@ VX_API_ENTRY vx_lut VX_API_CALL vxCreateLUT(vx_context context, vx_enum data_typ { VX_PRINT(VX_ZONE_ERROR, "Invalid parameter to LUT\n"); vxAddLogEntry(context, VX_ERROR_INVALID_PARAMETERS, "Invalid parameter to LUT\n"); - lut = (vx_lut_t)vxGetErrorObject(context, VX_ERROR_INVALID_PARAMETERS); + lut = (vx_lut_t)Error::getError(context, VX_ERROR_INVALID_PARAMETERS); } else { - lut = (vx_lut_t)Array::createArray(context, VX_TYPE_INT16, count, vx_false_e, VX_TYPE_LUT); - if (vxGetStatus((vx_reference)lut) == VX_SUCCESS && lut->type == VX_TYPE_LUT) + lut = (vx_lut_t)Array::createArray(context, VX_TYPE_INT16, count, vx_false_e, + VX_TYPE_LUT); + if (Error::getStatus((vx_reference)lut) == VX_SUCCESS && lut->type == VX_TYPE_LUT) { lut->num_items = count; - lut->offset = (vx_uint32)(count/2); + lut->offset = (vx_uint32)(count / 2); Array::printArray(lut); } } @@ -68,8 +70,9 @@ VX_API_ENTRY vx_lut VX_API_CALL vxCreateLUT(vx_context context, vx_enum data_typ #if !defined(OPENVX_STRICT_1_0) else if (data_type == VX_TYPE_UINT16) { - lut = (vx_lut_t)Array::createArray(context, VX_TYPE_UINT16, count, vx_false_e, VX_TYPE_LUT); - if (vxGetStatus((vx_reference)lut) == VX_SUCCESS && lut->type == VX_TYPE_LUT) + lut = (vx_lut_t)Array::createArray(context, VX_TYPE_UINT16, count, vx_false_e, + VX_TYPE_LUT); + if (Error::getStatus((vx_reference)lut) == VX_SUCCESS && lut->type == VX_TYPE_LUT) { lut->num_items = count; lut->offset = 0; @@ -81,10 +84,23 @@ VX_API_ENTRY vx_lut VX_API_CALL vxCreateLUT(vx_context context, vx_enum data_typ { VX_PRINT(VX_ZONE_ERROR, "Invalid data type\n"); vxAddLogEntry(context, VX_ERROR_INVALID_TYPE, "Invalid data type\n"); - lut = (vx_lut_t)vxGetErrorObject(context, VX_ERROR_INVALID_TYPE); + lut = (vx_lut_t)Error::getError(context, VX_ERROR_INVALID_TYPE); } } + return lut; +} + +/******************************************************************************/ +/* PUBLIC INTERFACE */ +/******************************************************************************/ + +VX_API_ENTRY vx_lut VX_API_CALL vxCreateLUT(vx_context context, vx_enum data_type, vx_size count) +{ + vx_lut_t lut = nullptr; + + lut = Lut::createLUT(context, data_type, count); + return (vx_lut)lut; } From c1cafd34482ef4c8d5c1e4d8835969b51aec8f47 Mon Sep 17 00:00:00 2001 From: Andrew Mikhail Date: Sun, 10 Aug 2025 12:40:24 -0700 Subject: [PATCH 4/9] Cleanup to context --- framework/include/vx_context.h | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/framework/include/vx_context.h b/framework/include/vx_context.h index 8aee37a..50ed2e8 100644 --- a/framework/include/vx_context.h +++ b/framework/include/vx_context.h @@ -32,9 +32,6 @@ * \brief The Internal Context API */ -/*! \brief The implementation string which is of the format "." */ -extern const vx_char implementation[]; - /*! \brief The top level context data for the entire OpenVX instance * \ingroup group_int_context */ @@ -49,6 +46,13 @@ class Context : public Reference */ Context(); + /** + * @brief Delete copy constructor and assignment operator to prevent copying + * @ingroup group_int_context + */ + Context(const Context&) = delete; + Context& operator=(const Context&) = delete; + /** * @brief Destroy the Context object * @ingroup group_int_context @@ -507,7 +511,7 @@ class Context : public Reference const vx_uint16 vendor_id; /*! \brief The version number this implements */ const vx_uint16 version_number; - /*! \brief The name of this impleemntation */ + /*! \brief The implementation string which is of the format "." */ const vx_char implementation[VX_MAX_IMPLEMENTATION_NAME]; /*! \brief The name of additional extensions in this impleemntation */ const vx_char* extension; From 12ddd845854a1b12283efa612427dcf97a21dea9 Mon Sep 17 00:00:00 2001 From: Andrew Mikhail Date: Sun, 10 Aug 2025 13:11:21 -0700 Subject: [PATCH 5/9] Moving sensitive members to private --- framework/include/vx_context.h | 41 ++++---- framework/include/vx_graph.h | 161 +++++++++++++++---------------- framework/include/vx_reference.h | 3 +- framework/include/vx_target.h | 4 +- framework/src/vx_context.cpp | 2 + framework/src/vx_graph.cpp | 4 +- framework/src/vx_target.cpp | 8 +- 7 files changed, 113 insertions(+), 110 deletions(-) diff --git a/framework/include/vx_context.h b/framework/include/vx_context.h index 50ed2e8..a83eebd 100644 --- a/framework/include/vx_context.h +++ b/framework/include/vx_context.h @@ -37,8 +37,27 @@ */ namespace corevx { -class Context : public Reference +class Context final : public Reference { +private: + /** + * @brief Launch worker graph thread + * + * @param arg Optional argument to pass as parameter. + * @return vx_value_t Thread return value. + * @ingroup group_int_context + */ + static vx_value_t workerGraph(void* arg); + + /** + * @brief Launch worker node + * + * @param worker The threadpool of the worker. + * @return vx_bool vx_true_e if ran successful, vx_false_e otherwise + * @ingroup group_int_context + */ + static vx_bool workerNode(vx_threadpool_worker_t* worker); + public: /** * @brief Construct a new Context object @@ -177,6 +196,7 @@ class Context : public Reference */ std::vector uniqueKernelTable(); +#ifdef OPENVX_USE_OPENCL_INTEROP /** * @brief Get the OpenCL context * @@ -192,6 +212,7 @@ class Context : public Reference * @ingroup group_int_context */ cl_command_queue clCommandQueue() const; +#endif /** OPENVX_USE_OPENCL_INTEROP */ /** * @brief Set the logging enabled state @@ -323,24 +344,6 @@ class Context : public Reference */ static vx_bool isValidBorderMode(vx_enum mode); - /** - * @brief Launch worker graph thread - * - * @param arg Optional argument to pass as parameter. - * @return vx_value_t Thread return value. - * @ingroup group_int_context - */ - static vx_value_t workerGraph(void *arg); - - /** - * @brief Launch worker node - * - * @param worker The threadpool of the worker. - * @return vx_bool vx_true_e if ran successful, vx_false_e otherwise - * @ingroup group_int_context - */ - static vx_bool workerNode(vx_threadpool_worker_t *worker); - /** * @brief Register a user struct with a certain number of bytes * diff --git a/framework/include/vx_graph.h b/framework/include/vx_graph.h index b230933..773b6ef 100644 --- a/framework/include/vx_graph.h +++ b/framework/include/vx_graph.h @@ -89,40 +89,6 @@ class Graph : public Reference */ static void contaminateGraphs(vx_reference ref); - /** - * @brief Destroy the Graph object - * @ingroup group_int_graph - */ - ~Graph(); -public: - /** - * @brief Construct a new Graph object - * - * @param context The context associated with this graph - * @param scope Parent reference of this graph - * @ingroup group_int_graph - */ - Graph(vx_context context, vx_reference scope); - - /** - * @brief Create a graph - * - * @param context The context associated with this graph - * @return vx_graph The graph object - * @ingroup group_int_graph - */ - static vx_graph createGraph(vx_context context); - - /** - * @brief Do a topological in-place sort of the nodes in list, with current - * order maintained between independent nodes. - * - * @param list list of nodes - * @param nnodes number of nodes - * @ingroup group_int_graph - */ - void topologicalSort(vx_node *list, vx_uint32 nnodes); - /** * @brief Setup output * @@ -169,58 +135,59 @@ class Graph : public Reference vx_bool postprocessOutput(vx_uint32 n, vx_uint32 p, vx_reference* vref, vx_meta_format meta, vx_status* status, vx_uint32* num_errors); - /*! \brief Clears visited flag. - * \ingroup group_int_graph + /** + * @brief Traverse graph + * + * @param parentIndex + * @param childIndex + * @return vx_status + * @ingroup group_int_graph */ - void clearVisitation(); + vx_status traverseGraph(vx_uint32 parentIndex, + vx_uint32 childIndex); - /*! \brief Clears execution flag. - * \ingroup group_int_graph + /** + * @brief Do a topological in-place sort of the nodes in list, with current + * order maintained between independent nodes. + * + * @param list list of nodes + * @param nnodes number of nodes + * @ingroup group_int_graph */ - void clearExecution(); + void topologicalSort(vx_node* list, vx_uint32 nnodes); /** - * @brief Find nodes using this reference as input or output parameter. - * This function starts on the next node in the list and loops until we - * hit the original node again. Parse over the nodes in circular fashion. - * @param ref The reference to search for - * @param refnodes The nodes to search within - * @param count Count of nodes found using ref - * @param reftype The reference type - * @return vx_status + * @brief Execute the graph + * + * @param depth Optional count of executions + * @return vx_status VX_SUCCESS if successful, otherwise return status with error code. * @ingroup group_int_graph */ - vx_status findNodesWithReference( - vx_reference ref, - vx_uint32 refnodes[], - vx_uint32 *count, - vx_enum reftype); + vx_status executeGraph(vx_uint32 depth); - /*! \brief Given a set of last nodes, this function will determine the next - * set of nodes which are capable of being run. Nodes which are encountered but - * can't be run will be placed in the left nodes list. - * \param [in] last_nodes The last list of nodes executed. - * \param [in] numLast The number of nodes in the last_nodes list which are valid. - * \param [out] next_nodes The list of nodes next to be executed. - * \param [in] numNext The number of nodes in the next_nodes list which are valid. - * \param [out] left_nodes The list of nodes which are next, but can't be executed. - * \param [in] numLeft The number of nodes in the left_nodes list which are valid. - * \ingroup group_int_graph + /** + * @brief Destroy the Graph object + * @ingroup group_int_graph */ - void findNextNodes(vx_uint32 last_nodes[VX_INT_MAX_REF], vx_uint32 numLast, - vx_uint32 next_nodes[VX_INT_MAX_REF], vx_uint32 *numNext, - vx_uint32 left_nodes[VX_INT_MAX_REF], vx_uint32 *numLeft); + ~Graph(); +public: + /** + * @brief Construct a new Graph object + * + * @param context The context associated with this graph + * @param scope Parent reference of this graph + * @ingroup group_int_graph + */ + Graph(vx_context context, vx_reference scope); /** - * @brief Traverse graph + * @brief Create a graph * - * @param parentIndex - * @param childIndex - * @return vx_status + * @param context The context associated with this graph + * @return vx_graph The graph object * @ingroup group_int_graph */ - vx_status traverseGraph(vx_uint32 parentIndex, - vx_uint32 childIndex); + static vx_graph createGraph(vx_context context); /** * @brief Get the graph performance @@ -270,15 +237,6 @@ class Graph : public Reference */ vx_status verify(); - /** - * @brief Execute the graph - * - * @param depth Optional count of executions - * @return vx_status VX_SUCCESS if successful, otherwise return status with error code. - * @ingroup group_int_graph - */ - vx_status executeGraph(vx_uint32 depth); - /** * @brief Schedule the graph * @@ -301,7 +259,7 @@ class Graph : public Reference * @return vx_status VX_SUCCESS if successful, otherwise return status with error code. * @ingroup group_int_graph */ - vx_status processGraph(); + vx_status process(); /** * @brief Add a graph paramter @@ -341,6 +299,45 @@ class Graph : public Reference vx_status pipelineValidateRefsList( const vx_graph_parameter_queue_params_t graph_parameters_queue_param); + /*! \brief Clears visited flag. + * \ingroup group_int_graph + */ + void clearVisitation(); + + /*! \brief Clears execution flag. + * \ingroup group_int_graph + */ + void clearExecution(); + + /** + * @brief Find nodes using this reference as input or output parameter. + * This function starts on the next node in the list and loops until we + * hit the original node again. Parse over the nodes in circular fashion. + * @param ref The reference to search for + * @param refnodes The nodes to search within + * @param count Count of nodes found using ref + * @param reftype The reference type + * @return vx_status + * @ingroup group_int_graph + */ + vx_status findNodesWithReference(vx_reference ref, vx_uint32 refnodes[], vx_uint32* count, + vx_enum reftype); + + /*! \brief Given a set of last nodes, this function will determine the next + * set of nodes which are capable of being run. Nodes which are encountered but + * can't be run will be placed in the left nodes list. + * \param [in] last_nodes The last list of nodes executed. + * \param [in] numLast The number of nodes in the last_nodes list which are valid. + * \param [out] next_nodes The list of nodes next to be executed. + * \param [in] numNext The number of nodes in the next_nodes list which are valid. + * \param [out] left_nodes The list of nodes which are next, but can't be executed. + * \param [in] numLeft The number of nodes in the left_nodes list which are valid. + * \ingroup group_int_graph + */ + void findNextNodes(vx_uint32 last_nodes[VX_INT_MAX_REF], vx_uint32 numLast, + vx_uint32 next_nodes[VX_INT_MAX_REF], vx_uint32* numNext, + vx_uint32 left_nodes[VX_INT_MAX_REF], vx_uint32* numLeft); + /** * @brief Streaming loop function * diff --git a/framework/include/vx_reference.h b/framework/include/vx_reference.h index c1f55cf..df20149 100644 --- a/framework/include/vx_reference.h +++ b/framework/include/vx_reference.h @@ -38,7 +38,7 @@ namespace corevx { class Reference { -public: +protected: /** * @brief Construct a new Reference object * @@ -55,6 +55,7 @@ class Reference { */ virtual ~Reference(); +public: /** * @brief Returns the reference count of the object * @return vx_uint32 The reference count diff --git a/framework/include/vx_target.h b/framework/include/vx_target.h index 0695605..928c101 100644 --- a/framework/include/vx_target.h +++ b/framework/include/vx_target.h @@ -61,7 +61,7 @@ class Target : public Reference * \ingroup group_int_target * \retval vx_true_e If string matches, vx_false_e if not. */ - static vx_bool matchTargetNameWithString(const char* target_name, const char* target_string); + static vx_bool matchTargetNameWithString(const vx_char* target_name, const vx_char* target_string); /** * @brief Find the last occurrence of a substring in a string. @@ -71,7 +71,7 @@ class Target : public Reference * @return const char* Pointer to the last occurrence of the substring, or nullptr if not found. * @ingroup group_int_target */ - static const char* reverse_strstr(const char* string, const char* substr); + static const vx_char* reverse_strstr(const vx_char* string, const vx_char* substr); /*! \brief Initializes a target's kernels list. * \param [in] kernels The array of kernels that the target supports. diff --git a/framework/src/vx_context.cpp b/framework/src/vx_context.cpp index 62cb93f..a4e6610 100644 --- a/framework/src/vx_context.cpp +++ b/framework/src/vx_context.cpp @@ -359,6 +359,7 @@ std::vector Context::uniqueKernelTable() return table; } +#ifdef OPENVX_USE_OPENCL_INTEROP cl_context Context::clContext() const { return opencl_context; @@ -368,6 +369,7 @@ cl_command_queue Context::clCommandQueue() const { return opencl_command_queue; } +#endif /** OPENVX_USE_OPENCL_INTEROP */ void Context::setLoggingEnabled(vx_bool flag) { diff --git a/framework/src/vx_graph.cpp b/framework/src/vx_graph.cpp index e703cc8..cd58ba4 100644 --- a/framework/src/vx_graph.cpp +++ b/framework/src/vx_graph.cpp @@ -1516,7 +1516,7 @@ vx_status Graph::wait() return status; } -vx_status Graph::processGraph() +vx_status Graph::process() { vx_status status = VX_SUCCESS; @@ -3260,7 +3260,7 @@ VX_API_ENTRY vx_status VX_API_CALL vxProcessGraph(vx_graph graph) if (VX_SUCCESS == status) { - status = graph->processGraph(); + status = graph->process(); } VX_PRINT(VX_ZONE_GRAPH, "%s returned %d\n", __func__, status ); diff --git a/framework/src/vx_target.cpp b/framework/src/vx_target.cpp index 060e988..0cc8e07 100644 --- a/framework/src/vx_target.cpp +++ b/framework/src/vx_target.cpp @@ -109,7 +109,7 @@ vx_status Target::deinitializeTarget() return status; } -vx_bool Target::matchTargetNameWithString(const char* target_name, const char* target_string) +vx_bool Target::matchTargetNameWithString(const vx_char* target_name, const vx_char* target_string) { /* 1. find latest occurrence of target_string in target_name; 2. match only the cases: target_name == "[smth.][.smth]" @@ -132,10 +132,10 @@ vx_bool Target::matchTargetNameWithString(const char* target_name, const char* t return match; } -const char* Target::reverse_strstr(const char* string, const char* substr) +const vx_char* Target::reverse_strstr(const vx_char* string, const vx_char* substr) { - const char* last = nullptr; - const char* cur = string; + const vx_char* last = nullptr; + const vx_char* cur = string; do { cur = (const char*) strstr(cur, substr); if (cur != nullptr) From 65d207d0280d124148007eeeb0193b0c3d216a6e Mon Sep 17 00:00:00 2001 From: Andrew Mikhail Date: Sun, 10 Aug 2025 15:13:27 -0700 Subject: [PATCH 6/9] Added C++ helpers for node kernel --- framework/include/vx_kernel.h | 34 +++++++++++++++++++++++ framework/include/vx_node.h | 11 ++++++++ framework/src/vx_kernel.cpp | 51 +++++++++++++++++++++++++++++++++++ framework/src/vx_node.cpp | 8 ++++++ framework/src/vx_scalar.cpp | 2 +- 5 files changed, 105 insertions(+), 1 deletion(-) diff --git a/framework/include/vx_kernel.h b/framework/include/vx_kernel.h index 2cab53c..eb50a03 100644 --- a/framework/include/vx_kernel.h +++ b/framework/include/vx_kernel.h @@ -40,6 +40,18 @@ namespace corevx { class Kernel : public Reference { public: + /** + * @brief The parameter of the kernel + * + * @ingroup group_int_kernel + */ + struct Param + { + vx_enum direction; // VX_INPUT, VX_OUTPUT, etc. + vx_enum type; // VX_TYPE_SCALAR, VX_TYPE_IMAGE, etc. + vx_enum state; // VX_PARAMETER_STATE_REQUIRED, VX_PARAMETER_STATE_OPTIONAL, etc. + }; + /** * @brief Construct a new Kernel object * @@ -75,6 +87,28 @@ class Kernel : public Reference */ ~Kernel() = default; + /** + * @brief Register a custom kernel + * + * @param context The context + * @param name The name of the kernel + * @param params The parameters of the kernel + * @param function The function of the kernel + * @param validate The validate function of the kernel + * @param initialize The initialize function of the kernel + * @param deinitialize The deinitialize function of the kernel + * @return vx_kernel The kernel + * @ingroup group_int_kernel + */ + static vx_kernel registerCustomKernel( + vx_context context, + std::string name, + const std::vector ¶ms, + vx_kernel_f function, + vx_kernel_validate_f validate = nullptr, + vx_kernel_initialize_f initialize = nullptr, + vx_kernel_deinitialize_f deinitialize = nullptr); + /** * @brief Get the number of kernel parameters * diff --git a/framework/include/vx_node.h b/framework/include/vx_node.h index 6bd8c2b..f94ae09 100644 --- a/framework/include/vx_node.h +++ b/framework/include/vx_node.h @@ -85,6 +85,17 @@ class Node : public Reference */ static vx_node createNode(vx_graph graph, vx_kernel kernel); + /** + * @brief Create a new node with parameters + * + * @param graph The graph associated with this node + * @param kernel The kernel associated with this node + * @param params The parameters associated with this node + * @return vx_node The node object + * @ingroup group_int_node + */ + static vx_node createNode(vx_graph graph, vx_kernel kernel, std::initializer_list params); + /*! \brief Node parameter setter, no check. * \ingroup group_int_node */ diff --git a/framework/src/vx_kernel.cpp b/framework/src/vx_kernel.cpp index acc83ff..dce57fd 100644 --- a/framework/src/vx_kernel.cpp +++ b/framework/src/vx_kernel.cpp @@ -82,6 +82,57 @@ Kernel::Kernel(vx_context context, } } +vx_kernel Kernel::registerCustomKernel( + vx_context context, + std::string name, + const std::vector ¶ms, + vx_kernel_f function, + vx_kernel_validate_f validate, + vx_kernel_initialize_f initialize, + vx_kernel_deinitialize_f deinitialize) +{ + vx_enum kernel_enum = 0; + + if (context->allocateKernelId(&kernel_enum) != VX_SUCCESS) + { + VX_PRINT(VX_ZONE_ERROR, "Failed to allocate user kernel ID\n"); + return nullptr; + } + + // 2. Add the user kernel + vx_kernel kernel = addkernel(context, name.c_str(), kernel_enum, function, + static_cast(params.size()), validate, + nullptr, nullptr, initialize, deinitialize, vx_true_e); + if (!kernel) + { + VX_PRINT(VX_ZONE_ERROR, "Failed to add user kernel\n"); + return nullptr; + } + + // 3. Add parameters + for (vx_uint32 i = 0; i < params.size(); ++i) + { + const auto &p = params[i]; + if (kernel->addParameter(i, p.direction, p.type, p.state) != VX_SUCCESS) + { + VX_PRINT(VX_ZONE_ERROR, "Failed to add parameter %u to kernel\n", i); + // vxReleaseKernel(&kernel); + return nullptr; + } + } + + // 4. Finalize the kernel + if (kernel->finalize() != VX_SUCCESS) + { + VX_PRINT(VX_ZONE_ERROR, "Failed to finalize kernel\n"); + // vxReleaseKernel(&kernel); + return nullptr; + } + + // 5. Return the kernel handle + return kernel; +} + void Kernel::printKernel(vx_kernel kernel) { VX_PRINT(VX_ZONE_KERNEL, "kernel[%u] enabled?=%s %s \n", diff --git a/framework/src/vx_node.cpp b/framework/src/vx_node.cpp index 9ac117c..f052859 100644 --- a/framework/src/vx_node.cpp +++ b/framework/src/vx_node.cpp @@ -115,6 +115,14 @@ vx_node Node::createNode(vx_graph graph, vx_kernel kernel) return node; } +vx_node Node::createNode(vx_graph graph, vx_kernel kernel, std::initializer_list params) +{ + vx_node node = createNode(graph, kernel); + vx_uint32 idx = 0; + for (const auto& obj : params) node->setParameter(idx++, obj); + return node; +} + void Node::setParameter(vx_uint32 index, vx_reference value) { if (parameters[index]) diff --git a/framework/src/vx_scalar.cpp b/framework/src/vx_scalar.cpp index d37b08a..154601f 100644 --- a/framework/src/vx_scalar.cpp +++ b/framework/src/vx_scalar.cpp @@ -55,7 +55,7 @@ vx_scalar Scalar::createScalar(vx_context context, vx_enum data_type, const void if (Error::getStatus((vx_reference)scalar) == VX_SUCCESS && scalar->type == VX_TYPE_SCALAR) { scalar->data_type = data_type; - vxCopyScalar(scalar, (void *)ptr, VX_WRITE_ONLY, VX_MEMORY_TYPE_HOST); + scalar->copy(const_cast(ptr), VX_WRITE_ONLY, VX_MEMORY_TYPE_HOST); } } From f55a9f8df7cde15ad3162c63a4fda30eb19ad4f7 Mon Sep 17 00:00:00 2001 From: Andrew Mikhail Date: Sun, 10 Aug 2025 20:03:33 -0700 Subject: [PATCH 7/9] Added some cpp samples --- framework/include/vx_xml.h | 128 +++++++++++++++++++++++++++ include/COREVX/all.hpp | 2 + samples/corevx_cpp/BUILD | 50 +++++++++++ samples/corevx_cpp/blur_pipeline.cpp | 54 +++++++++++ samples/corevx_cpp/custom_code.cpp | 95 ++++++++++++++++++++ samples/corevx_cpp/hello_world.cpp | 53 +++++++++++ 6 files changed, 382 insertions(+) create mode 100644 framework/include/vx_xml.h create mode 100644 samples/corevx_cpp/BUILD create mode 100644 samples/corevx_cpp/blur_pipeline.cpp create mode 100644 samples/corevx_cpp/custom_code.cpp create mode 100644 samples/corevx_cpp/hello_world.cpp diff --git a/framework/include/vx_xml.h b/framework/include/vx_xml.h new file mode 100644 index 0000000..5f3fe45 --- /dev/null +++ b/framework/include/vx_xml.h @@ -0,0 +1,128 @@ +/** + * @file vx_xml.h + * @brief XML import/export API + * @version 0.1 + * @date 2025-08-10 + * + * @copyright Copyright (c) 2025 Edge AI, LLC. All rights reserved. + * + */ +#ifndef VX_XML_H +#define VX_XML_H + +#include "vx_internal.h" + +/*! + * @defgroup group_int_xml XML Import/Export API + * @ingroup group_internal + * @brief The XML import/export API + */ +namespace corevx +{ +namespace xml +{ +class Import +{ +public: + Import() = delete; + Import(const Import &) = delete; + Import(Import &&) = delete; + Import &operator=(const Import &) = delete; + Import &operator=(Import &&) = delete; + ~Import() = delete; + + /** + * @brief Import from XML + * + * @param context The context + * @param filepath The path to the XML file + * @return std::vector The imported references + * @ingroup group_int_xml + */ + static std::vector importFromXML(vx_context context, std::string filepath) + { + std::vector graphs; + vx_status status = VX_SUCCESS; + vx_size num_refs = 0; + vx_size num_kernels = 0; + vx_size num_refs_added = 0; + vx_size num_kernels_added = 0; + vx_size num_nonkern_added = 0; + vx_size count = 0; + vx_size num_refs_orig = context->numReferences(); + vx_size num_kernels_orig = context->numUniqueKernels(); + + auto import = vxImportFromXML(context, const_cast(filepath.c_str())); + if (import && (status = Error::getStatus(import)) == VX_SUCCESS) + { + num_refs = context->numReferences(); + num_kernels = context->numUniqueKernels(); + num_refs_added = num_refs - num_refs_orig; + num_kernels_added = num_kernels - num_kernels_orig; + num_nonkern_added = num_refs_added - num_kernels_added; + + if ((status == VX_SUCCESS) && (count = import->numRefs()) > 0) + { + /* Count returns the number of references explicitly found in the xml file and + * returned in the refs array. num_nonkern_added can be greater than count because + * of the following 2 reasons: + * 1. if there are any non-unique kernels added from a library, this will + * increase the num_refs count, but not the count of the number of unique kernels + * 2. if there are any virtual pyramids which do not have image references in the + * xml file, there will be added references for each level of the pyramid, but these + * will not be listed in the refs array + */ + if (num_nonkern_added < count) + { + printf("ODD? Num nonkernel Refs Added = %u and Count = %u\n", num_nonkern_added, + count); + status = VX_FAILURE; + } + } + + /* Now that the objects are imported, add all graphs to return list */ + if (status == VX_SUCCESS) + { + for (vx_uint32 i = 0; i < count; i++) + { + auto ref = import->getReferenceByIndex(i); + if (ref->dataType() == VX_TYPE_GRAPH) + { + graphs.push_back(static_cast(ref)); + } + } + } + } + + return graphs; + } +}; + +class Export +{ +public: + Export() = delete; + Export(const Export &) = delete; + Export(Export &&) = delete; + Export &operator=(const Export &) = delete; + Export &operator=(Export &&) = delete; + ~Export() = delete; + + /** + * @brief Export to XML + * + * @param context The context + * @param filepath The path to the XML file + * @return vx_status The status of the export + * @ingroup group_int_xml + */ + static vx_status exportToXML(vx_context context, std::string filepath) + { + return vxExportToXML(context, const_cast(filepath.c_str())); + } +}; + +} // namespace xml +} // namespace corevx + +#endif /* VX_XML_H */ \ No newline at end of file diff --git a/include/COREVX/all.hpp b/include/COREVX/all.hpp index 8f238b2..d83bd13 100644 --- a/include/COREVX/all.hpp +++ b/include/COREVX/all.hpp @@ -33,3 +33,5 @@ #include "framework/include/vx_error.h" #include "framework/include/vx_delay.h" #include "framework/include/vx_event_queue.hpp" +#include "framework/include/vx_user_data_object.h" +#include "framework/include/vx_xml.h" diff --git a/samples/corevx_cpp/BUILD b/samples/corevx_cpp/BUILD new file mode 100644 index 0000000..d288d03 --- /dev/null +++ b/samples/corevx_cpp/BUILD @@ -0,0 +1,50 @@ + +package(default_visibility = ["//visibility:public"]) + +cc_binary( + name = "hello_world", + srcs = ["hello_world.cpp"], + deps = [ + "//:corevx", + "//targets/ai_server:imported_openvx_ai_server", + "//targets/c_model:imported_openvx_c_model", + "//targets/debug:imported_openvx_debug", + "//targets/extras:imported_openvx_extras", + "//targets/liteRT:imported_openvx_liteRT", + "//targets/opencl:imported_openvx_opencl", + "//targets/onnxRT:imported_openvx_onnxRT", + "//targets/executorch:imported_openvx_torch", + ], +) + +cc_binary( + name = "blur_pipeline", + srcs = ["blur_pipeline.cpp"], + deps = [ + "//:corevx", + "//targets/ai_server:imported_openvx_ai_server", + "//targets/c_model:imported_openvx_c_model", + "//targets/debug:imported_openvx_debug", + "//targets/extras:imported_openvx_extras", + "//targets/liteRT:imported_openvx_liteRT", + "//targets/opencl:imported_openvx_opencl", + "//targets/onnxRT:imported_openvx_onnxRT", + "//targets/executorch:imported_openvx_torch", + ], +) + +cc_binary( + name = "custom_code", + srcs = ["custom_code.cpp"], + deps = [ + "//:corevx", + "//targets/ai_server:imported_openvx_ai_server", + "//targets/c_model:imported_openvx_c_model", + "//targets/debug:imported_openvx_debug", + "//targets/extras:imported_openvx_extras", + "//targets/liteRT:imported_openvx_liteRT", + "//targets/opencl:imported_openvx_opencl", + "//targets/onnxRT:imported_openvx_onnxRT", + "//targets/executorch:imported_openvx_torch", + ], +) diff --git a/samples/corevx_cpp/blur_pipeline.cpp b/samples/corevx_cpp/blur_pipeline.cpp new file mode 100644 index 0000000..845d69f --- /dev/null +++ b/samples/corevx_cpp/blur_pipeline.cpp @@ -0,0 +1,54 @@ +#include + +#include + +using namespace corevx; + +int main(int argc, char* argv[]) +{ + (void)argc; + (void)argv; + + // Create context + vx_context context = Context::createContext(); + if (Error::getStatus(context) != VX_SUCCESS) + { + std::cerr << "Failed to create Context" << std::endl; + return EXIT_FAILURE; + } + + // Create graph + vx_graph graph = Graph::createGraph(context); + if (Error::getStatus(graph) != VX_SUCCESS) + { + std::cerr << "Failed to create Graph" << std::endl; + return EXIT_FAILURE; + } + + // Create data objects + const vx_uint32 width = 256, height = 256; + vx_image rgb = Image::createImage(context, width, height, VX_DF_IMAGE_RGB); + vx_image yuv = Image::createImage(context, width, height, VX_DF_IMAGE_YUV4); + vx_image gray = Image::createImage(context, width, height, VX_DF_IMAGE_U8); + vx_image blur = Image::createImage(context, width, height, VX_DF_IMAGE_U8); + + // Color convert (RGB -> YUV) + vx_node ncc = vxColorConvertNode(graph, rgb, yuv); + // Extract Y plane to gray + vx_node nce = vxChannelExtractNode(graph, yuv, VX_CHANNEL_Y, gray); + // Box filter 3x3 + vx_node nbox = vxBox3x3Node(graph, gray, blur); + (void)ncc; (void)nce; (void)nbox; + + // Process graph + if (graph->process() != VX_SUCCESS) + { + std::cerr << "Graph process failed" << std::endl; + return EXIT_FAILURE; + } + + std::cout << "Blur pipeline ran successfully" << std::endl; + return EXIT_SUCCESS; +} + + diff --git a/samples/corevx_cpp/custom_code.cpp b/samples/corevx_cpp/custom_code.cpp new file mode 100644 index 0000000..20ac8ea --- /dev/null +++ b/samples/corevx_cpp/custom_code.cpp @@ -0,0 +1,95 @@ +/** + * @file custom_code.cpp + * @brief Custom kernel example + * @version 0.1 + * @date 2025-08-10 + * + * @copyright Copyright (c) 2025 + * + */ +#include + +#include +#include + +using namespace corevx; + +int main() +{ + // 1. Create context + vx_context context = Context::createContext(); + if (Error::getStatus(context) != VX_SUCCESS) + { + std::cerr << "Failed to create context\n"; + return EXIT_FAILURE; + } + + // 2. Create a graph + vx_graph graph = Graph::createGraph(context); + if (Error::getStatus(graph) != VX_SUCCESS) + { + std::cerr << "Failed to create graph\n"; + return EXIT_FAILURE; + } + + // 3. Create input and output data objects -- in this case, scalars + vx_int32 a = 7, b = 5; + vx_scalar scalar_a = Scalar::createScalar(context, VX_TYPE_INT32, &a); + vx_scalar scalar_b = Scalar::createScalar(context, VX_TYPE_INT32, &b); + vx_scalar scalar_out = Scalar::createScalar(context, VX_TYPE_INT32, nullptr); + + // 4. Register the custom kernel + vx_kernel add_kernel = Kernel::registerCustomKernel( + context, + "example.scalar_add", + { + // direction, type, state + {VX_INPUT, VX_TYPE_INT32, VX_PARAMETER_STATE_REQUIRED}, + {VX_INPUT, VX_TYPE_INT32, VX_PARAMETER_STATE_REQUIRED}, + {VX_OUTPUT, VX_TYPE_INT32, VX_PARAMETER_STATE_REQUIRED} + }, + // Custom kernel function via lambda + [](vx_node node, const vx_reference parameters[], vx_uint32 num) -> vx_status { + (void)node; + (void)num; + vx_int32 a = 0, b = 0, c = 0; + vx_scalar scalar_a = (vx_scalar)parameters[0]; + vx_scalar scalar_b = (vx_scalar)parameters[1]; + vx_scalar scalar_out = (vx_scalar)parameters[2]; + + scalar_a->readValue(&a); + scalar_b->readValue(&b); + c = a + b; + scalar_out->writeValue(&c); + + return VX_SUCCESS; + }); + if (Error::getStatus(add_kernel) != VX_SUCCESS) + { + std::cerr << "Custom kernel not registered!\n"; + return EXIT_FAILURE; + } + + // 5. Add node to the graph + vx_node add_node = Node::createNode(graph, add_kernel, {scalar_a, scalar_b, scalar_out}); + if (Error::getStatus(add_node) != VX_SUCCESS) + { + std::cerr << "Failed to create node\n"; + return EXIT_FAILURE; + } + + // 6. Process the graph + if (graph->process() != VX_SUCCESS) + { + std::cerr << "Graph processing failed\n"; + return EXIT_FAILURE; + } + + // 7. Read back the result + vx_int32 result = 0; + scalar_out->readValue(&result); + std::cout << "Result: " << a << " + " << b << " = " << result << std::endl; + + // 8. cleanup automatically done when program exits + return EXIT_SUCCESS; +} \ No newline at end of file diff --git a/samples/corevx_cpp/hello_world.cpp b/samples/corevx_cpp/hello_world.cpp new file mode 100644 index 0000000..34713f4 --- /dev/null +++ b/samples/corevx_cpp/hello_world.cpp @@ -0,0 +1,53 @@ +#include +#include + +#include + +using namespace corevx; + +int main(int argc, char* argv[]) +{ + if (argc != 2) + { + std::cerr << "Usage: " << argv[0] << " " << std::endl; + return EXIT_FAILURE; + } + + // Create context + vx_context context = Context::createContext(); + if (Error::getStatus(context) != VX_SUCCESS) + { + std::cerr << "Failed to create Context" << std::endl; + return EXIT_FAILURE; + } + + // Import graph(s) from XML + auto graphs = xml::Import::importFromXML(context, argv[1]); + if (graphs.empty()) + { + std::cerr << "Failed to import graph from XML" << std::endl; + return EXIT_FAILURE; + } + + // Process graph + for (auto graph : graphs) + { + if (Error::getStatus(graph) == VX_SUCCESS) + { + if (graph->process() == VX_SUCCESS) + { + std::cout << "Graph processed successfully" << std::endl; + } + else + { + std::cerr << "Failed to process graph" << std::endl; + } + } + } + + // Automatically cleanup when program exits + std::cout << "completed successfully" << std::endl; + return EXIT_SUCCESS; +} + + From b1fa83fa9ead6a4b3208289941bc1f5f51f26b97 Mon Sep 17 00:00:00 2001 From: Andrew Mikhail Date: Mon, 11 Aug 2025 12:47:15 -0700 Subject: [PATCH 8/9] Fixed build issue --- framework/src/vx_image.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/framework/src/vx_image.cpp b/framework/src/vx_image.cpp index f8364c4..88833ba 100644 --- a/framework/src/vx_image.cpp +++ b/framework/src/vx_image.cpp @@ -244,10 +244,13 @@ vx_image Image::createImage(vx_context context, { vx_image image = nullptr; - if ((width == 0) || (height == 0) || (Image::isSupportedFourcc(color) == vx_false_e) || - (color == VX_DF_IMAGE_VIRT)) + if (vx_false_e == is_virtual) { - return (vx_image)Error::getError(context, VX_ERROR_INVALID_PARAMETERS); + if ((width == 0) || (height == 0) || (Image::isSupportedFourcc(color) == vx_false_e) || + (color == VX_DF_IMAGE_VIRT)) + { + return (vx_image)Error::getError(context, VX_ERROR_INVALID_PARAMETERS); + } } if (Context::isValidContext(context) == vx_true_e) From 6878dde6e6cc84e0a11ee425b0ffa880acc09b14 Mon Sep 17 00:00:00 2001 From: Andrew Mikhail Date: Mon, 11 Aug 2025 14:07:59 -0700 Subject: [PATCH 9/9] Documentation updates --- docs/Doxyfile | 2 +- framework/include/vx_context.h | 2 +- framework/include/vx_debug.h | 1 + framework/include/vx_event_queue.hpp | 2 +- framework/include/vx_image.h | 1 - framework/include/vx_kernel.h | 8 ++++---- framework/include/vx_parameter.h | 5 ++--- framework/src/vx_lut.cpp | 1 + include/COREVX/all.hpp | 13 +++++++++---- include/COREVX/execution_queue.hpp | 2 +- targets/c_model/vx_bilateral_filter.cpp | 5 +++++ targets/c_model/vx_controlflow.cpp | 5 +++++ targets/c_model/vx_copy.cpp | 5 +++++ targets/c_model/vx_hog.cpp | 5 +++++ targets/c_model/vx_interface.h | 5 +++++ targets/c_model/vx_khr_nn.cpp | 5 +++++ targets/c_model/vx_multiply_matrix.cpp | 5 +++++ targets/c_model/vx_nonlinearfilter.cpp | 5 +++++ targets/c_model/vx_tensor_lut.cpp | 5 +++++ targets/c_model/vx_tensor_op.cpp | 6 ++++++ targets/c_model/vx_tensor_transpose.cpp | 6 ++++++ targets/executorch/vx_torch_inf.cpp | 4 ++-- targets/extras/vx_harris_score.cpp | 5 +++++ targets/extras/vx_norm.cpp | 1 + targets/liteRT/vx_interface.h | 5 +++++ targets/liteRT/vx_litert_inf.cpp | 2 +- targets/opencl/vx_interface.cpp | 2 +- targets/opencl/vx_interface.h | 5 +++++ targets/opencl/vx_nonlinearfilter.cpp | 5 +++++ targets/opencl/vx_support.cpp | 5 +++++ targets/opencl/vx_support.h | 5 +++++ targets/tiling/vx_hog.cpp | 4 ++++ targets/tiling/vx_interface.cpp | 2 +- targets/tiling/vx_interface.h | 5 +++++ targets/tiling/vx_nonlinearfilter.cpp | 5 +++++ targets/venum/vx_bilateral_filter.cpp | 5 +++++ targets/venum/vx_copy.cpp | 5 +++++ targets/venum/vx_hog.cpp | 5 +++++ targets/venum/vx_interface.cpp | 2 +- targets/venum/vx_interface.h | 5 +++++ targets/venum/vx_laplacianpyramid.cpp | 5 +++++ targets/venum/vx_multiply_matrix.cpp | 5 +++++ targets/venum/vx_nonlinearfilter.cpp | 5 +++++ targets/venum/vx_tensor_lut.cpp | 5 +++++ targets/venum/vx_tensor_op.cpp | 7 +++++-- targets/venum/vx_tensor_transpose.cpp | 6 ++++-- tools/run_xml_graph.cpp | 9 +++++++++ 47 files changed, 187 insertions(+), 26 deletions(-) diff --git a/docs/Doxyfile b/docs/Doxyfile index 620cd0a..cee5282 100644 --- a/docs/Doxyfile +++ b/docs/Doxyfile @@ -1120,7 +1120,7 @@ EXCLUDE_PATTERNS = */bazel-*/* \ */build/* \ */cts/* \ */external/* \ - */kernels/NNEF-Tools/* \ + */kernels/nnef/NNEF-Tools/* \ */kernels/utils/half/* \ *.md \ /private/var/tmp/_bazel* \ diff --git a/framework/include/vx_context.h b/framework/include/vx_context.h index a83eebd..7ef491a 100644 --- a/framework/include/vx_context.h +++ b/framework/include/vx_context.h @@ -25,7 +25,7 @@ /*! * \file - * \brief + * \brief The internal context implementation. * * \defgroup group_int_context Internal Context API * \ingroup group_internal diff --git a/framework/include/vx_debug.h b/framework/include/vx_debug.h index ab55c2e..9fe5d95 100644 --- a/framework/include/vx_debug.h +++ b/framework/include/vx_debug.h @@ -29,6 +29,7 @@ /*! * \file + * \brief The internal debugging implementation. * * \defgroup group_int_debug Internal Debugging API * \ingroup group_internal diff --git a/framework/include/vx_event_queue.hpp b/framework/include/vx_event_queue.hpp index a14ee4a..d6a5b55 100644 --- a/framework/include/vx_event_queue.hpp +++ b/framework/include/vx_event_queue.hpp @@ -1,6 +1,6 @@ /** * @file vx_event_queue.hpp - * @brief + * @brief Internal Event Queue Object * @version 0.1 * @date 2025-05-09 * diff --git a/framework/include/vx_image.h b/framework/include/vx_image.h index d7b1308..975da07 100644 --- a/framework/include/vx_image.h +++ b/framework/include/vx_image.h @@ -302,7 +302,6 @@ class Image : public Reference * @param plane_index The plane index to access * @param addr The addressing information for the patch * @param ptr The pointer to the user memory - * @param mem_type The type of memory (host, opencl, etc.) * @param usage The usage of the memory (read/write) * @return vx_status VX_SUCCESS on success, error code otherwise * @ingroup group_int_image diff --git a/framework/include/vx_kernel.h b/framework/include/vx_kernel.h index eb50a03..35d364f 100644 --- a/framework/include/vx_kernel.h +++ b/framework/include/vx_kernel.h @@ -103,7 +103,7 @@ class Kernel : public Reference static vx_kernel registerCustomKernel( vx_context context, std::string name, - const std::vector ¶ms, + const std::vector ¶ms, vx_kernel_f function, vx_kernel_validate_f validate = nullptr, vx_kernel_initialize_f initialize = nullptr, @@ -373,7 +373,7 @@ class Kernel : public Reference * @brief Removes a custom kernel from its context and releases it. * * @param [in] kernel The reference to the kernel to remove. Returned from \ref - * addKernel. + * addkernel. * @note Any kernel enumerated in the base standard * cannot be removed; only kernels added through \ref vxAddUserKernel can * be removed. @@ -389,7 +389,7 @@ class Kernel : public Reference * @note When all references to loaded kernels are released, the module * may be automatically unloaded. * @param [in] context The reference to the context the kernels must be added to. - * @param [in] module The short name of the module to load. On systems where + * @param [in] name The short name of the module to load. On systems where * there are specific naming conventions for modules, the name passed * should ignore such conventions. For example: \c libxyz.so should be * passed as just \c xyz and the implementation will do the right thing that @@ -405,7 +405,7 @@ class Kernel : public Reference * the module using the \ref loadKernels function. * * @param [in] context The reference to the context the kernels must be removed from. - * @param [in] module The short name of the module to unload. On systems where + * @param [in] name The short name of the module to unload. On systems where * there are specific naming conventions for modules, the name passed * should ignore such conventions. For example: \c libxyz.so should be * passed as just \c xyz and the implementation will do the right thing diff --git a/framework/include/vx_parameter.h b/framework/include/vx_parameter.h index b857d6f..244a68f 100644 --- a/framework/include/vx_parameter.h +++ b/framework/include/vx_parameter.h @@ -156,9 +156,8 @@ class Parameter : public Reference /** * @brief Get a parameter by index from a node * - * @param node The node to get the parameter from - * @param index The index of the parameter - * @return vx_parameter The parameter object, or nullptr if not found + * @param value The reference to set as the parameter value + * @return vx_status VX_SUCCESS on success, error code otherwise * @ingroup group_int_parameter */ vx_status setParameterByReference(vx_reference value); diff --git a/framework/src/vx_lut.cpp b/framework/src/vx_lut.cpp index bf1e154..07a2b75 100644 --- a/framework/src/vx_lut.cpp +++ b/framework/src/vx_lut.cpp @@ -18,6 +18,7 @@ #include "vx_lut.h" using namespace corevx; +using Lut = Array; vx_lut_t Lut::createLUT(vx_context context, vx_enum data_type, vx_size count) { diff --git a/include/COREVX/all.hpp b/include/COREVX/all.hpp index d83bd13..65c9ff2 100644 --- a/include/COREVX/all.hpp +++ b/include/COREVX/all.hpp @@ -1,7 +1,12 @@ -// CoreVX single-include header for C++ development -// Exposes the existing C++ classes under the corevx namespace without refactoring -// and re-exports the stable OpenVX C API for convenience. - +/** + * @file all.hpp + * @brief CoreVX single-include header for C++ development + * @version 0.1 + * @date 2025-08-11 + * + * @copyright Copyright (c) 2025 EdgeAI, LLC. All rights reserved. + * @ingroup group_corevx_ext + */ #pragma once // Public OpenVX C API (stable surface) diff --git a/include/COREVX/execution_queue.hpp b/include/COREVX/execution_queue.hpp index 73f59db..843fcc6 100644 --- a/include/COREVX/execution_queue.hpp +++ b/include/COREVX/execution_queue.hpp @@ -4,7 +4,7 @@ * @version 0.1 * @date 2025-05-16 * - * @copyright Copyright (c) 2025 + * @copyright Copyright (c) 2025 EdgeAI, LLC. All rights reserved. * @ingroup group_corevx_ext */ #include diff --git a/targets/c_model/vx_bilateral_filter.cpp b/targets/c_model/vx_bilateral_filter.cpp index 343a75f..b4fedab 100644 --- a/targets/c_model/vx_bilateral_filter.cpp +++ b/targets/c_model/vx_bilateral_filter.cpp @@ -14,6 +14,11 @@ * limitations under the License. */ +/*! + * \file + * \brief The Bilateral Filter Kernel. + */ + #include #include diff --git a/targets/c_model/vx_controlflow.cpp b/targets/c_model/vx_controlflow.cpp index 1d5c293..d01ef57 100644 --- a/targets/c_model/vx_controlflow.cpp +++ b/targets/c_model/vx_controlflow.cpp @@ -14,6 +14,11 @@ * limitations under the License. */ +/*! + * \file + * \brief The Control Flow Kernel. + */ + #include #include diff --git a/targets/c_model/vx_copy.cpp b/targets/c_model/vx_copy.cpp index 27bc0e5..57dc8e2 100644 --- a/targets/c_model/vx_copy.cpp +++ b/targets/c_model/vx_copy.cpp @@ -15,6 +15,11 @@ * limitations under the License. */ +/*! + * \file + * \brief The Copy Kernel. + */ + #include #include diff --git a/targets/c_model/vx_hog.cpp b/targets/c_model/vx_hog.cpp index 8f62f55..21e76b9 100644 --- a/targets/c_model/vx_hog.cpp +++ b/targets/c_model/vx_hog.cpp @@ -26,6 +26,11 @@ * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. */ +/*! + * \file + * \brief The HOG Cells Kernel. + */ + #include #include diff --git a/targets/c_model/vx_interface.h b/targets/c_model/vx_interface.h index 5fb0b64..c6ab531 100644 --- a/targets/c_model/vx_interface.h +++ b/targets/c_model/vx_interface.h @@ -17,6 +17,11 @@ #ifndef _OPENVX_INTERFACE_H_ #define _OPENVX_INTERFACE_H_ +/*! + * \file + * \brief The C-Model Kernel Interface Header. + */ + #include #include diff --git a/targets/c_model/vx_khr_nn.cpp b/targets/c_model/vx_khr_nn.cpp index b91db4c..623a8e3 100644 --- a/targets/c_model/vx_khr_nn.cpp +++ b/targets/c_model/vx_khr_nn.cpp @@ -14,6 +14,11 @@ * limitations under the License. */ +/*! + * \file + * \brief The Neural Network Kernel. + */ + #include #include #include diff --git a/targets/c_model/vx_multiply_matrix.cpp b/targets/c_model/vx_multiply_matrix.cpp index 1100e97..fda911f 100644 --- a/targets/c_model/vx_multiply_matrix.cpp +++ b/targets/c_model/vx_multiply_matrix.cpp @@ -15,6 +15,11 @@ * limitations under the License. */ +/*! + * \file + * \brief The Matrix Multiply Kernel. + */ + #include #include diff --git a/targets/c_model/vx_nonlinearfilter.cpp b/targets/c_model/vx_nonlinearfilter.cpp index c50c277..daef519 100644 --- a/targets/c_model/vx_nonlinearfilter.cpp +++ b/targets/c_model/vx_nonlinearfilter.cpp @@ -14,6 +14,11 @@ * limitations under the License. */ +/*! + * \file + * \brief The Non-Linear Filter Kernel. + */ + #include #include diff --git a/targets/c_model/vx_tensor_lut.cpp b/targets/c_model/vx_tensor_lut.cpp index 6c0dcd3..8d61f15 100644 --- a/targets/c_model/vx_tensor_lut.cpp +++ b/targets/c_model/vx_tensor_lut.cpp @@ -15,6 +15,11 @@ * limitations under the License. */ +/*! + * \file + * \brief The Tensor LUT Kernel. + */ + #include #include diff --git a/targets/c_model/vx_tensor_op.cpp b/targets/c_model/vx_tensor_op.cpp index 684dbe3..089c6f3 100644 --- a/targets/c_model/vx_tensor_op.cpp +++ b/targets/c_model/vx_tensor_op.cpp @@ -13,6 +13,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + +/*! + * \file + * \brief The Tensor Op Kernel. + */ + #include #include #include "vx_internal.h" diff --git a/targets/c_model/vx_tensor_transpose.cpp b/targets/c_model/vx_tensor_transpose.cpp index dd9db88..a36fea8 100644 --- a/targets/c_model/vx_tensor_transpose.cpp +++ b/targets/c_model/vx_tensor_transpose.cpp @@ -13,6 +13,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + +/*! + * \file + * \brief The Tensor Transpose Kernel. + */ + #include #include #include "vx_internal.h" diff --git a/targets/executorch/vx_torch_inf.cpp b/targets/executorch/vx_torch_inf.cpp index 2d57dc1..1563fcf 100644 --- a/targets/executorch/vx_torch_inf.cpp +++ b/targets/executorch/vx_torch_inf.cpp @@ -1,10 +1,10 @@ /** - * @file vx_ort_inf.cpp + * @file vx_torch_inf.cpp * @brief OpenVX Interface Into Executorch * @version 0.1 * @date 2025-01-20 * - * @copyright Copyright (c) 2025 + * @copyright Copyright (c) 2025 EdgeAI, LLC. All rights reserved. * */ #include diff --git a/targets/extras/vx_harris_score.cpp b/targets/extras/vx_harris_score.cpp index 3b7e8ff..a292d7d 100644 --- a/targets/extras/vx_harris_score.cpp +++ b/targets/extras/vx_harris_score.cpp @@ -14,6 +14,11 @@ * limitations under the License. */ +/*! + * \file + * \brief The Harris Score Kernel. + */ + #include #include #include diff --git a/targets/extras/vx_norm.cpp b/targets/extras/vx_norm.cpp index ca8b5ea..7950cdd 100644 --- a/targets/extras/vx_norm.cpp +++ b/targets/extras/vx_norm.cpp @@ -15,6 +15,7 @@ */ /*! + * \file * \brief Elementwise binary norm kernel (Extras) */ diff --git a/targets/liteRT/vx_interface.h b/targets/liteRT/vx_interface.h index ec0e7d4..0cd9e5c 100644 --- a/targets/liteRT/vx_interface.h +++ b/targets/liteRT/vx_interface.h @@ -10,6 +10,11 @@ #ifndef OPENVX_INTERFACE_H #define OPENVX_INTERFACE_H +/*! + * \file + * \brief The TFLITE Runtime Kernel Interface Header. + */ + #include extern vx_kernel_description_t tflite_cpu_inf_kernel; diff --git a/targets/liteRT/vx_litert_inf.cpp b/targets/liteRT/vx_litert_inf.cpp index e50ebed..d9fc1ad 100644 --- a/targets/liteRT/vx_litert_inf.cpp +++ b/targets/liteRT/vx_litert_inf.cpp @@ -1,5 +1,5 @@ /** - * @file vx_ort_inf.cpp + * @file vx_litert_inf.cpp * @brief OpenVX Interface Into LiteRT * @version 0.1 * @date 2025-01-20 diff --git a/targets/opencl/vx_interface.cpp b/targets/opencl/vx_interface.cpp index 6c825a0..049222e 100644 --- a/targets/opencl/vx_interface.cpp +++ b/targets/opencl/vx_interface.cpp @@ -16,7 +16,7 @@ /*! * \file - * \brief The C-Model Target Interface + * \brief The OpenCL Target Interface * \author Erik Rainey */ #include diff --git a/targets/opencl/vx_interface.h b/targets/opencl/vx_interface.h index d5c2f82..94425a3 100644 --- a/targets/opencl/vx_interface.h +++ b/targets/opencl/vx_interface.h @@ -18,6 +18,11 @@ #include "vx_internal.h" +/*! + * \file + * \brief The OpenCL Kernel Interface Header. + */ + #if defined(DARWIN) || defined(__APPLE__) #include #else diff --git a/targets/opencl/vx_nonlinearfilter.cpp b/targets/opencl/vx_nonlinearfilter.cpp index 15c18f0..1253b76 100644 --- a/targets/opencl/vx_nonlinearfilter.cpp +++ b/targets/opencl/vx_nonlinearfilter.cpp @@ -14,6 +14,11 @@ * limitations under the License. */ +/*! + * \file + * \brief The Non-Linear Filter Kernel. + */ + #include #include #include diff --git a/targets/opencl/vx_support.cpp b/targets/opencl/vx_support.cpp index 8bc46cc..225b091 100644 --- a/targets/opencl/vx_support.cpp +++ b/targets/opencl/vx_support.cpp @@ -14,6 +14,11 @@ * limitations under the License. */ +/*! + * \file + * \brief The OpenCL Support Functions. + */ + #include #define CASE_STRINGERIZE(err, label, function, file, line) \ diff --git a/targets/opencl/vx_support.h b/targets/opencl/vx_support.h index 6eb6b44..7b2e75a 100644 --- a/targets/opencl/vx_support.h +++ b/targets/opencl/vx_support.h @@ -14,6 +14,11 @@ * limitations under the License. */ +/*! + * \file + * \brief The OpenCL Support Functions Header. + */ + #include "vx_interface.h" #include "vx_internal.h" diff --git a/targets/tiling/vx_hog.cpp b/targets/tiling/vx_hog.cpp index 4d7e744..1163a3f 100644 --- a/targets/tiling/vx_hog.cpp +++ b/targets/tiling/vx_hog.cpp @@ -30,6 +30,10 @@ #include "vx_internal.h" #include "tiling.h" +/*! + * \file + * \brief The HOG Cells Kernel. + */ static vx_status VX_CALLBACK vxHogCellsInputValidator(vx_node node, vx_uint32 index) { diff --git a/targets/tiling/vx_interface.cpp b/targets/tiling/vx_interface.cpp index 1959510..88e020a 100644 --- a/targets/tiling/vx_interface.cpp +++ b/targets/tiling/vx_interface.cpp @@ -16,7 +16,7 @@ /*! * \file - * \brief The C-Model Target Interface + * \brief The Tiling Target Interface. * \author Erik Rainey */ diff --git a/targets/tiling/vx_interface.h b/targets/tiling/vx_interface.h index 054dd6d..fb90340 100644 --- a/targets/tiling/vx_interface.h +++ b/targets/tiling/vx_interface.h @@ -14,6 +14,11 @@ * limitations under the License. */ +/*! + * \file + * \brief The Tiling Kernel Interface Header. + */ + #ifndef _OPENVX_INTERFACE_H_ #define _OPENVX_INTERFACE_H_ diff --git a/targets/tiling/vx_nonlinearfilter.cpp b/targets/tiling/vx_nonlinearfilter.cpp index d7642e3..8a675b1 100644 --- a/targets/tiling/vx_nonlinearfilter.cpp +++ b/targets/tiling/vx_nonlinearfilter.cpp @@ -18,6 +18,11 @@ #include "tiling.h" +/*! + * \file + * \brief The Non-Linear Filter Kernel. + */ + static vx_status VX_CALLBACK vxNonLinearFilterInputValidator(vx_node node, vx_uint32 index) { vx_status status = VX_ERROR_INVALID_PARAMETERS; diff --git a/targets/venum/vx_bilateral_filter.cpp b/targets/venum/vx_bilateral_filter.cpp index 2a18b0f..f1ade61 100644 --- a/targets/venum/vx_bilateral_filter.cpp +++ b/targets/venum/vx_bilateral_filter.cpp @@ -23,6 +23,11 @@ #include #include "tensor_utils.h" +/*! + * \file + * \brief The Bilateral Filter Kernel. + */ + typedef enum _bilateral_filter_params_e { BILATERAL_FILTER_PARAM_SRC = 0, BILATERAL_FILTER_PARAM_DIAMETER, diff --git a/targets/venum/vx_copy.cpp b/targets/venum/vx_copy.cpp index 9658f00..1564583 100644 --- a/targets/venum/vx_copy.cpp +++ b/targets/venum/vx_copy.cpp @@ -15,6 +15,11 @@ * limitations under the License. */ +/*! + * \file + * \brief The Copy Kernel. + */ + #include #include diff --git a/targets/venum/vx_hog.cpp b/targets/venum/vx_hog.cpp index f7a0d8b..83a9783 100644 --- a/targets/venum/vx_hog.cpp +++ b/targets/venum/vx_hog.cpp @@ -26,6 +26,11 @@ * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. */ +/*! + * \file + * \brief The HOG Cells Kernel. + */ + #include #include diff --git a/targets/venum/vx_interface.cpp b/targets/venum/vx_interface.cpp index ebe597b..cf677c3 100644 --- a/targets/venum/vx_interface.cpp +++ b/targets/venum/vx_interface.cpp @@ -16,7 +16,7 @@ /*! * \file - * \brief The C-Model Target Interface + * \brief The Venum Target Interface * \author Erik Rainey */ diff --git a/targets/venum/vx_interface.h b/targets/venum/vx_interface.h index 4a08b3d..01a4977 100644 --- a/targets/venum/vx_interface.h +++ b/targets/venum/vx_interface.h @@ -20,6 +20,11 @@ #include #include +/*! + * \file + * \brief The Venum Kernel Interface Header. + */ + extern vx_kernel_description_t absdiff_kernel; extern vx_kernel_description_t not_kernel; extern vx_kernel_description_t median3x3_kernel; diff --git a/targets/venum/vx_laplacianpyramid.cpp b/targets/venum/vx_laplacianpyramid.cpp index ef320ca..7cbd4a0 100644 --- a/targets/venum/vx_laplacianpyramid.cpp +++ b/targets/venum/vx_laplacianpyramid.cpp @@ -22,6 +22,11 @@ #include #include "vx_internal.h" +/*! + * \file + * \brief The Laplacian Pyramid Kernel. + */ + static const vx_uint32 gaussian5x5scale = 256; static const vx_int16 gaussian5x5[5][5] = { diff --git a/targets/venum/vx_multiply_matrix.cpp b/targets/venum/vx_multiply_matrix.cpp index 3ef5945..8980fa1 100644 --- a/targets/venum/vx_multiply_matrix.cpp +++ b/targets/venum/vx_multiply_matrix.cpp @@ -24,6 +24,11 @@ #include #include "tensor_utils.h" +/*! + * \file + * \brief The Matrix Multiply Kernel. + */ + typedef enum _matrix_multiply_params_e { MATRIX_MULTIPLY_PARAM_TENSOR_IN1 = 0, MATRIX_MULTIPLY_PARAM_TENSOR_IN2, diff --git a/targets/venum/vx_nonlinearfilter.cpp b/targets/venum/vx_nonlinearfilter.cpp index f15cc3c..07adc6e 100644 --- a/targets/venum/vx_nonlinearfilter.cpp +++ b/targets/venum/vx_nonlinearfilter.cpp @@ -21,6 +21,11 @@ #include +/*! + * \file + * \brief The Non-Linear Filter Kernel. + */ + static vx_status VX_CALLBACK vxNonLinearFilterKernel(vx_node node, const vx_reference *parameters, vx_uint32 num) { vx_status status = VX_ERROR_INVALID_PARAMETERS; diff --git a/targets/venum/vx_tensor_lut.cpp b/targets/venum/vx_tensor_lut.cpp index f28ca3c..5523151 100644 --- a/targets/venum/vx_tensor_lut.cpp +++ b/targets/venum/vx_tensor_lut.cpp @@ -24,6 +24,11 @@ #include #include "tensor_utils.h" +/*! + * \file + * \brief The Tensor LUT Kernel. + */ + typedef enum _lut_params_e { LUT_PARAM_TENSOR_IN = 0, LUT_PARAM_LUT, diff --git a/targets/venum/vx_tensor_op.cpp b/targets/venum/vx_tensor_op.cpp index 199e0d1..d1926f7 100644 --- a/targets/venum/vx_tensor_op.cpp +++ b/targets/venum/vx_tensor_op.cpp @@ -20,6 +20,10 @@ #include +/*! + * \file + * \brief The Tensor Op Kernel. + */ #define Q78_FIXED_POINT_POSITION 8 @@ -29,8 +33,7 @@ if (status_ != VX_SUCCESS) return status_; \ } while(0) - -static enum TensorCFmt getTensorCFmt(vx_tensor tensor) + static enum TensorCFmt getTensorCFmt(vx_tensor tensor) { if (tensor->data_type == VX_TYPE_INT16 && tensor->fixed_point_position == Q78_FIXED_POINT_POSITION) return TENSOR_C_FMT_Q78; diff --git a/targets/venum/vx_tensor_transpose.cpp b/targets/venum/vx_tensor_transpose.cpp index 93c29fa..e1532fe 100644 --- a/targets/venum/vx_tensor_transpose.cpp +++ b/targets/venum/vx_tensor_transpose.cpp @@ -18,8 +18,10 @@ #include "vx_internal.h" #include - - +/*! + * \file + * \brief The Tensor Transpose Kernel. + */ /*============================================================================== ============================================================================== diff --git a/tools/run_xml_graph.cpp b/tools/run_xml_graph.cpp index d96c6a5..ce534c0 100644 --- a/tools/run_xml_graph.cpp +++ b/tools/run_xml_graph.cpp @@ -1,3 +1,12 @@ +/** + * @file run_xml_graph.cpp + * @brief CoreVX Graph Runner + * @version 0.1 + * @date 2025-08-11 + * + * @copyright Copyright (c) 2025 EdgeAI, LLC. All rights reserved. + * @ingroup group_corevx_ext + */ #include #include #include