Skip to content

Commit 450f9ff

Browse files
committed
Migrate memory apis to helper class, added additional conformance flags, and minor cleanup
1 parent f53a77f commit 450f9ff

37 files changed

+409
-316
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# CoreVX Project
2-
This project is an implementation of the OpenVX specification version 1.3.1, with various extensions and features enabled.
2+
This project is an implementation of the OpenVX specification version 1.3.1, with various extensions and features enabled.
33
The project is built using Google's Bazel build system and is validated by unit tests, integration tests, and the OpenVX conformance tests.
44

55
## Project Structure
@@ -52,6 +52,7 @@ The following extensions and features are enabled in the CoreVX project, as defi
5252
- **OPENVX_USE_S16**: Enables support for 16-bit signed integer data types.
5353
- **OPENVX_USE_OPENCL_INTEROP**: Enables interoperability with OpenCL, allowing OpenVX to leverage OpenCL for acceleration.
5454
- **OPENVX_USE_NN**: Enables the neural network extension, providing support for neural network operations within OpenVX.
55+
- **OPENVX_USE_NN_16**: Enables half float (float16) support for the neural network extension.
5556

5657
### Conditional Extensions for ARM Architectures
5758
The following extensions are conditionally enabled for ARM and ARM64 architectures:

framework/include/vx_debug.h

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -171,18 +171,6 @@ vx_bool vx_get_debug_zone(vx_enum zone);
171171
*/
172172
void vx_set_debug_zone_from_env(void);
173173

174-
/*!
175-
* \brief Prints the value of an addressing structure.
176-
* \param [in] addr
177-
* \ingroup group_int_image
178-
*/
179-
void ownPrintImageAddressing(const vx_imagepatch_addressing_t *addr);
180-
181-
/*! \brief Prints the name of an object type.
182-
* \ingroup group_int_debug
183-
*/
184-
const char *ownGetObjectTypeName(vx_enum type);
185-
186174
#ifdef __cplusplus
187175
}
188176
#endif /* __cplusplus */

framework/include/vx_image.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,12 @@ class Image : public Reference
180180
*/
181181
static void printImage(vx_image image);
182182

183+
/*! \brief Prints the addressing information of an image patch.
184+
* \param [in] addr The addressing structure.
185+
* \ingroup group_int_image
186+
*/
187+
static void printImageAddressing(const vx_imagepatch_addressing_t *addr);
188+
183189
/*! \brief Used to free an image object.
184190
* Only the data is freed, not the
185191
* meta-data structure.

framework/include/vx_inlines.h

Lines changed: 101 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,26 +19,21 @@
1919

2020
#include "vx_internal.h"
2121

22-
static VX_INLINE void *ownFormatMemoryPtr(vx_memory_t *memory,
23-
vx_uint32 c,
24-
vx_uint32 x,
25-
vx_uint32 y,
26-
vx_uint32 p)
27-
{
28-
intmax_t offset = (memory->strides[p][VX_DIM_Y] * y) +
29-
(memory->strides[p][VX_DIM_X] * x) +
30-
(memory->strides[p][VX_DIM_C] * c);
31-
void *ptr = (void *)&memory->ptrs[p][offset];
32-
//ownPrintMemory(memory);
33-
//VX_PRINT(VX_ZONE_INFO, "&(%p[%zu]) = %p\n", memory->ptrs[p], offset, ptr);
34-
return ptr;
35-
}
36-
37-
static VX_INLINE int isodd(size_t a)
38-
{
39-
return (int)(a & 1);
40-
}
22+
/*!
23+
* \file
24+
* \brief A set of internal utility functions.
25+
*
26+
* \defgroup group_int_inlines Internal Utility Functions
27+
* \ingroup group_internal
28+
* \brief Static internal utility functions
29+
*/
4130

31+
/**
32+
* @brief Is the number odd?
33+
* @ingroup group_int_inlines
34+
* @param a The number to check
35+
* @return vx_true_e if odd, else vx_false_e
36+
*/
4237
static VX_INLINE vx_bool vxIsOdd(vx_uint32 a)
4338
{
4439
if (a & 0x1)
@@ -47,6 +42,12 @@ static VX_INLINE vx_bool vxIsOdd(vx_uint32 a)
4742
return vx_false_e;
4843
}
4944

45+
/**
46+
* @brief Is the number a power of two?
47+
* @ingroup group_int_inlines
48+
* @param a The number to check
49+
* @return vx_true_e if even, else vx_false_e
50+
*/
5051
static VX_INLINE vx_bool vxIsPowerOfTwo(vx_uint32 a)
5152
{
5253
if (a == 0)
@@ -57,6 +58,14 @@ static VX_INLINE vx_bool vxIsPowerOfTwo(vx_uint32 a)
5758
return vx_false_e;
5859
}
5960

61+
/**
62+
* @brief Count the number of occurrences of a character in a string.
63+
* @ingroup group_int_inlines
64+
* @param string The string to search
65+
* @param size The size of the string
66+
* @param c The character to count
67+
* @return The number of occurrences of the character in the string.
68+
*/
6069
static VX_INLINE vx_size strncount(const vx_char string[], vx_size size, vx_char c)
6170
{
6271
vx_size i = 0ul, count = 0ul;
@@ -66,6 +75,14 @@ static VX_INLINE vx_size strncount(const vx_char string[], vx_size size, vx_char
6675
return count;
6776
}
6877

78+
/**
79+
* @brief Find the index of a character in a string.
80+
* @ingroup group_int_inlines
81+
* @param str The string to search
82+
* @param c The character to find
83+
* @param limit The maximum number of characters to search
84+
* @return The index of the character in the string.
85+
*/
6986
static VX_INLINE vx_size strnindex(const vx_char *str, vx_char c, vx_size limit)
7087
{
7188
vx_size index = 0;
@@ -82,6 +99,13 @@ static VX_INLINE vx_size strnindex(const vx_char *str, vx_char c, vx_size limit)
8299
return index;
83100
}
84101

102+
/**
103+
* @brief Is valid format?
104+
* @ingroup group_int_inlines
105+
* @param data_type data type
106+
* @param fixed_point_pos fixed point position
107+
* @return vx_true_e if valid, else vx_false_e
108+
*/
85109
static VX_INLINE int validFormat(vx_enum data_type, vx_uint8 fixed_point_pos)
86110
{
87111
return
@@ -96,4 +120,62 @@ static VX_INLINE int validFormat(vx_enum data_type, vx_uint8 fixed_point_pos)
96120
(data_type == VX_TYPE_UINT8 && fixed_point_pos == 0);
97121
}
98122

123+
/*! \brief Prints the name of an object type.
124+
* \ingroup group_int_inlines
125+
*/
126+
static VX_INLINE const char* vxGetObjectTypeName(vx_enum type)
127+
{
128+
const char *name = "";
129+
130+
switch(type)
131+
{
132+
case VX_TYPE_CONTEXT:
133+
name = "CONTEXT"; break;
134+
case VX_TYPE_GRAPH:
135+
name = "GRAPH"; break;
136+
case VX_TYPE_NODE:
137+
name = "NODE"; break;
138+
case VX_TYPE_KERNEL:
139+
name = "KERNEL"; break;
140+
case VX_TYPE_TARGET:
141+
name = "TARGET"; break;
142+
case VX_TYPE_PARAMETER:
143+
name = "PARAMETER"; break;
144+
case VX_TYPE_DELAY:
145+
name = "DELAY"; break;
146+
case VX_TYPE_LUT:
147+
name = "LUT"; break;
148+
case VX_TYPE_DISTRIBUTION:
149+
name = "DISTRIBUTION"; break;
150+
case VX_TYPE_PYRAMID:
151+
name = "PYRAMID"; break;
152+
case VX_TYPE_THRESHOLD:
153+
name = "THRESHOLD"; break;
154+
case VX_TYPE_MATRIX:
155+
name = "MATRIX"; break;
156+
case VX_TYPE_CONVOLUTION:
157+
name = "CONVOLUTION"; break;
158+
case VX_TYPE_SCALAR:
159+
name = "SCALAR"; break;
160+
case VX_TYPE_ARRAY:
161+
name = "ARRAY"; break;
162+
case VX_TYPE_IMAGE:
163+
name = "IMAGE"; break;
164+
case VX_TYPE_REMAP:
165+
name = "REMAP"; break;
166+
case VX_TYPE_ERROR:
167+
name = "<ERROR OBJECT>"; break;
168+
case VX_TYPE_META_FORMAT:
169+
name = "META_FORMAT"; break;
170+
case VX_TYPE_OBJECT_ARRAY:
171+
name = "OBJECT_ARRAY"; break;
172+
case VX_TYPE_TENSOR:
173+
name = "TENSOR"; break;
174+
default:
175+
name = "<UNKNOWN TYPE>";
176+
}
177+
178+
return name;
179+
}
180+
99181
#endif /* VX_INLINES_H */

framework/include/vx_memory.h

Lines changed: 47 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2012-2017 The Khronos Group Inc. *
2+
* Copyright (c) 2012-2017 The Khronos Group Inc.
33
* Licensed under the Apache License, Version 2.0 (the "License");
44
* you may not use this file except in compliance with the License.
55
* You may obtain a copy of the License at
@@ -26,24 +26,56 @@
2626
* \brief The Internal Memory API.
2727
*/
2828

29-
/*! \brief Frees a memory block.
29+
/*! \brief The internal representation of a \ref vx_memory
3030
* \ingroup group_int_memory
3131
*/
32-
vx_bool ownFreeMemory(vx_context context, vx_memory_t *memory);
32+
class Memory
33+
{
34+
public:
35+
/*! \brief Frees a memory block.
36+
* \ingroup group_int_memory
37+
* \param [in] context The reference to the overall context.
38+
* \param [in] memory The memory block.
39+
* \return vx_true_e if successful.
40+
*/
41+
static vx_bool freeMemory(vx_context context, vx_memory_t *memory);
3342

34-
/*! \brief Allocates a memory block.
35-
* \ingroup group_int_memory
36-
*/
37-
vx_bool ownAllocateMemory(vx_context context, vx_memory_t *memory);
43+
/*! \brief Allocates a memory block.
44+
* \ingroup group_int_memory
45+
* \param [in] context The reference to the overall context.
46+
* \param [in] memory The memory block.
47+
* \return vx_true_e if successful.
48+
*/
49+
static vx_bool allocateMemory(vx_context context, vx_memory_t *memory);
3850

39-
/*! \brief Print info of memory block.
40-
* \ingroup group_int_memory
41-
*/
42-
void ownPrintMemory(vx_memory_t *mem);
51+
/*! \brief Print info of memory block.
52+
* \ingroup group_int_memory
53+
* \param [in] mem The memory block.
54+
*/
55+
static void printMemory(vx_memory_t *mem);
4356

44-
/*! \brief Compute size of memory block.
45-
* \ingroup group_int_memory
46-
*/
47-
vx_size ownComputeMemorySize(vx_memory_t *memory, vx_uint32 p);
57+
/*! \brief Compute size of memory block.
58+
* \ingroup group_int_memory
59+
* \param [in] memory The memory block.
60+
* \param [in] p The plane index.
61+
* \return Size of memory block.
62+
*/
63+
static vx_size computeMemorySize(vx_memory_t *memory, vx_uint32 p);
64+
65+
/*! \brief Get pointer to memory block.
66+
* \ingroup group_int_memory
67+
* \param memory The memory block.
68+
* \param c The channel index.
69+
* \param x The stride in x-dim.
70+
* \param y The stride in y-dim.
71+
* \param p The plane index.
72+
* \return Pointer to memory block.
73+
*/
74+
static void* formatMemoryPtr(vx_memory_t *memory,
75+
vx_uint32 c,
76+
vx_uint32 x,
77+
vx_uint32 y,
78+
vx_uint32 p);
79+
};
4880

4981
#endif /* VX_MEMORY_H */

framework/include/vx_scalar.h

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,30 @@ class Scalar : public Reference
5858
*/
5959
void* allocateScalarMemory(vx_size size);
6060

61+
/**
62+
* @brief Get host memory from scalar obj
63+
*
64+
* @param scalar scalar obj
65+
* @param user_ptr pointer to user memory
66+
* @return vx_status VX_SUCCESS on success
67+
* @ingroup group_int_scalar
68+
*/
69+
static vx_status scalarToHostMem(vx_scalar scalar, void* user_ptr);
70+
71+
/**
72+
* @brief Get scalar from host memory
73+
*
74+
* @param scalar scalar obj
75+
* @param user_ptr pointer to user memory
76+
* @return vx_status VX_SUCCESS on success
77+
* @ingroup group_int_scalar
78+
*/
79+
static vx_status hostMemToScalar(vx_scalar scalar, void* user_ptr);
80+
6181
/**
6282
* @brief Print scalar object
6383
*
64-
* @param scalar
84+
* @param scalar scalar obj
6585
* @ingroup group_int_scalar
6686
*/
6787
static void printScalarValue(vx_scalar scalar);

framework/src/vx_array.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ vx_array Array::createArray(vx_context context, vx_enum item_type, vx_size capac
6262

6363
void Array::destruct()
6464
{
65-
ownFreeMemory(context, &memory);
65+
Memory::freeMemory(context, &memory);
6666
}
6767

6868
vx_bool Array::initVirtualArray(vx_enum item_type, vx_size capacity)
@@ -106,7 +106,7 @@ vx_bool Array::allocateArray()
106106
vx_bool res = vx_false_e;
107107
if (capacity > 0)
108108
{
109-
res = ownAllocateMemory(context, &memory);
109+
res = Memory::allocateMemory(context, &memory);
110110
}
111111
return res;
112112
}

framework/src/vx_context.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -909,7 +909,7 @@ VX_API_ENTRY vx_status VX_API_CALL vxReleaseContext(vx_context* c)
909909
if (ref && ref->external_count > 0)
910910
{
911911
VX_PRINT(VX_ZONE_WARNING,"Stale reference " VX_FMT_REF " of type %s at external count %u, internal count %u\n",
912-
ref, ownGetObjectTypeName(ref->type), ref->external_count, ref->internal_count);
912+
ref, vxGetObjectTypeName(ref->type), ref->external_count, ref->internal_count);
913913
}
914914

915915
/* These were internally opened during creation, so should internally close ERRORs */

framework/src/vx_convolution.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ Convolution::~Convolution()
3232

3333
void Convolution::destruct()
3434
{
35-
ownFreeMemory(context, &memory);
35+
Memory::freeMemory(context, &memory);
3636
}
3737

3838
/******************************************************************************/
@@ -60,7 +60,7 @@ VX_API_ENTRY vx_convolution VX_API_CALL vxCreateConvolution(vx_context context,
6060

6161
if (Context::isValidContext(context) == vx_true_e)
6262
{
63-
if (isodd(columns) && columns >= 3 && isodd(rows) && rows >= 3)
63+
if (vxIsOdd(columns) && columns >= 3 && vxIsOdd(rows) && rows >= 3)
6464
{
6565
convolution = (vx_convolution)Reference::createReference(context, VX_TYPE_CONVOLUTION, VX_EXTERNAL, context);
6666
if (vxGetStatus((vx_reference)convolution) == VX_SUCCESS && convolution->type == VX_TYPE_CONVOLUTION)
@@ -184,7 +184,7 @@ VX_API_ENTRY vx_status VX_API_CALL vxReadConvolutionCoefficients(vx_convolution
184184
{
185185
vx_status status = VX_ERROR_INVALID_REFERENCE;
186186
if ((Reference::isValidReference(convolution, VX_TYPE_CONVOLUTION) == vx_true_e) &&
187-
(ownAllocateMemory(convolution->context, &convolution->memory) == vx_true_e))
187+
(Memory::allocateMemory(convolution->context, &convolution->memory) == vx_true_e))
188188
{
189189
Osal::semWait(&convolution->lock);
190190
if (array)
@@ -204,7 +204,7 @@ VX_API_ENTRY vx_status VX_API_CALL vxWriteConvolutionCoefficients(vx_convolution
204204
{
205205
vx_status status = VX_ERROR_INVALID_REFERENCE;
206206
if ((Reference::isValidReference(convolution, VX_TYPE_CONVOLUTION) == vx_true_e) &&
207-
(ownAllocateMemory(convolution->context, &convolution->memory) == vx_true_e))
207+
(Memory::allocateMemory(convolution->context, &convolution->memory) == vx_true_e))
208208
{
209209
Osal::semWait(&convolution->lock);
210210
if (array)
@@ -228,7 +228,7 @@ vx_status VX_API_CALL vxCopyConvolutionCoefficients(vx_convolution convolution,
228228

229229
if (Reference::isValidReference(convolution, VX_TYPE_CONVOLUTION) == vx_true_e)
230230
{
231-
if (ownAllocateMemory(convolution->context, &convolution->memory) == vx_true_e)
231+
if (Memory::allocateMemory(convolution->context, &convolution->memory) == vx_true_e)
232232
{
233233
#ifdef OPENVX_USE_OPENCL_INTEROP
234234
void * ptr_given = ptr;

0 commit comments

Comments
 (0)