Skip to content

Commit

Permalink
Make nn_dot_product function arguments fixed array (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
devfacet authored Apr 12, 2024
1 parent 9269c98 commit 8f902b9
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 9 deletions.
9 changes: 7 additions & 2 deletions include/arch/arm/cmsis-dsp/nn_dot_product.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@

#include <stddef.h>

// nn_dot_product_neon calculates the dot product of two vectors.
float nn_dot_product_cmsis(const float *a, const float *b, size_t length);
// NN_DOT_PRODUCT_MAX_VECTOR_SIZE defines the maximum size of a vector.
#ifndef NN_DOT_PRODUCT_MAX_VECTOR_SIZE
#define NN_DOT_PRODUCT_MAX_VECTOR_SIZE 64
#endif

// nn_dot_product_cmsis calculates the dot product of two vectors.
float nn_dot_product_cmsis(const float a[NN_DOT_PRODUCT_MAX_VECTOR_SIZE], const float b[NN_DOT_PRODUCT_MAX_VECTOR_SIZE], size_t vector_size);

#endif // NN_DOT_PRODUCT_CMSIS_H
7 changes: 6 additions & 1 deletion include/arch/arm/neon/nn_dot_product.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@

#include <stddef.h>

// NN_DOT_PRODUCT_MAX_VECTOR_SIZE defines the maximum size of a vector.
#ifndef NN_DOT_PRODUCT_MAX_VECTOR_SIZE
#define NN_DOT_PRODUCT_MAX_VECTOR_SIZE 64
#endif

// nn_dot_product_neon calculates the dot product of two vectors.
float nn_dot_product_neon(const float *a, const float *b, size_t length);
float nn_dot_product_neon(const float a[NN_DOT_PRODUCT_MAX_VECTOR_SIZE], const float b[NN_DOT_PRODUCT_MAX_VECTOR_SIZE], size_t vector_size);

#endif // NN_DOT_PRODUCT_NEON_H
10 changes: 7 additions & 3 deletions include/nn_dot_product.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
#ifndef NN_DOT_PRODUCT_H
#define NN_DOT_PRODUCT_H

#include "nn_error.h"
#include <stddef.h>

// NN_DOT_PRODUCT_MAX_VECTOR_SIZE defines the maximum size of a vector.
#ifndef NN_DOT_PRODUCT_MAX_VECTOR_SIZE
#define NN_DOT_PRODUCT_MAX_VECTOR_SIZE 64
#endif

// NNDotProductFunction represents a function that calculates the dot product of two vectors.
typedef float (*NNDotProductFunction)(const float *a, const float *b, size_t length);
typedef float (*NNDotProductFunction)(const float a[NN_DOT_PRODUCT_MAX_VECTOR_SIZE], const float b[NN_DOT_PRODUCT_MAX_VECTOR_SIZE], size_t vector_size);

// nn_dot_product calculates the dot product of two vectors.
float nn_dot_product(const float *a, const float *b, size_t length);
float nn_dot_product(const float a[NN_DOT_PRODUCT_MAX_VECTOR_SIZE], const float b[NN_DOT_PRODUCT_MAX_VECTOR_SIZE], size_t vector_size);

#endif // NN_DOT_PRODUCT_H
2 changes: 1 addition & 1 deletion src/arch/arm/cmsis-dsp/nn_dot_product.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <stddef.h>

// nn_dot_product_neon calculates the dot product of two vectors.
float nn_dot_product_cmsis(const float *a, const float *b, size_t vector_size) {
float nn_dot_product_cmsis(const float a[NN_DOT_PRODUCT_MAX_VECTOR_SIZE], const float b[NN_DOT_PRODUCT_MAX_VECTOR_SIZE], size_t vector_size) {
NN_DEBUG_PRINT(5, "function %s called with vector_size = %zu\n", __func__, vector_size);

float result = 0.0f;
Expand Down
2 changes: 1 addition & 1 deletion src/arch/arm/neon/nn_dot_product.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <stddef.h>

// nn_dot_product_neon calculates the dot product of two vectors.
float nn_dot_product_neon(const float *a, const float *b, size_t vector_size) {
float nn_dot_product_neon(const float a[NN_DOT_PRODUCT_MAX_VECTOR_SIZE], const float b[NN_DOT_PRODUCT_MAX_VECTOR_SIZE], size_t vector_size) {
NN_DEBUG_PRINT(5, "function %s called with vector_size = %zu\n", __func__, vector_size);

// Initialize vector sum to 0
Expand Down
3 changes: 2 additions & 1 deletion src/nn_dot_product.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#include "nn_dot_product.h"
#include "nn_debug.h"
#include <stddef.h>

// nn_dot_product_neon calculates the dot product of two vectors.
float nn_dot_product(const float *a, const float *b, size_t vector_size) {
float nn_dot_product(const float a[NN_DOT_PRODUCT_MAX_VECTOR_SIZE], const float b[NN_DOT_PRODUCT_MAX_VECTOR_SIZE], size_t vector_size) {
NN_DEBUG_PRINT(5, "function %s called with vector_size = %zu\n", __func__, vector_size);

// Initialize vector sum to 0
Expand Down

0 comments on commit 8f902b9

Please sign in to comment.