Skip to content

Commit

Permalink
Add const modifier to <acc>_dev_t
Browse files Browse the repository at this point in the history
  • Loading branch information
lukamac committed Feb 28, 2024
1 parent d12a11e commit d78e403
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 46 deletions.
16 changes: 8 additions & 8 deletions inc/pulp_nnx_ne16.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,40 +25,40 @@

/* PULP-NNX interface */

void ne16_nnx_init(ne16_dev_t *dev, ne16_pulp_conf_t *conf);
void ne16_nnx_term(ne16_dev_t *dev);
void ne16_nnx_init(const ne16_dev_t *dev, ne16_pulp_conf_t *conf);
void ne16_nnx_term(const ne16_dev_t *dev);

/** ne16_nnx_dispatch_check
*
* Check whether you can dispatch to the accelerator.
*/
int ne16_nnx_dispatch_check(ne16_dev_t *dev);
int ne16_nnx_dispatch_check(const ne16_dev_t *dev);

/** ne16_nnx_dispatch_wait
*
* Block until you can dispatch to the accelerator.
*/
void ne16_nnx_dispatch_wait(ne16_dev_t *dev);
void ne16_nnx_dispatch_wait(const ne16_dev_t *dev);

/** ne16_nnx_dispatch
*
* Dispatch a task to the accelerator.
* Fails with return code 1 if the task cannot be dispatched. Otherwise returns
* 0.
*/
int ne16_nnx_dispatch(ne16_dev_t *dev, ne16_task_t *task);
int ne16_nnx_dispatch(const ne16_dev_t *dev, ne16_task_t *task);

/** ne16_nnx_resolve_check
*
* Check whether the task has been resolved.
*/
int ne16_nnx_resolve_check(ne16_dev_t *dev, ne16_task_t *task);
int ne16_nnx_resolve_check(const ne16_dev_t *dev, ne16_task_t *task);

/** ne16_nnx_resolve_wait
*
* Block until you can resolve the task.
*/
void ne16_nnx_resolve_wait(ne16_dev_t *dev, ne16_task_t *task);
void ne16_nnx_resolve_wait(const ne16_dev_t *dev, ne16_task_t *task);

/* Additional helper functions */

Expand All @@ -69,7 +69,7 @@ void ne16_nnx_resolve_wait(ne16_dev_t *dev, ne16_task_t *task);
* tile the tile to the subtile's spatial dimensions (in this case 3x3 output).
* Works only if the k_out is divisible by 2.
*/
void ne16_nnx_dispatch_stride2x2(ne16_dev_t *dev, ne16_task_t *task,
void ne16_nnx_dispatch_stride2x2(const ne16_dev_t *dev, ne16_task_t *task,
const uint32_t w_in, const uint32_t k_in,
const uint32_t h_out, const uint32_t w_out,
const uint32_t k_out, const uint8_t h_ker,
Expand Down
14 changes: 7 additions & 7 deletions inc/pulp_nnx_neureka.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,37 +25,37 @@

/* PULP-NNX interface */

void neureka_nnx_init(neureka_dev_t *dev, neureka_siracusa_conf_t *conf);
void neureka_nnx_term(neureka_dev_t *dev);
void neureka_nnx_init(const neureka_dev_t *dev, neureka_siracusa_conf_t *conf);
void neureka_nnx_term(const neureka_dev_t *dev);

/** neureka_nnx_dispatch_check
*
* Check whether you can dispatch to the accelerator.
*/
int neureka_nnx_dispatch_check(neureka_dev_t *dev);
int neureka_nnx_dispatch_check(const neureka_dev_t *dev);

/** neureka_nnx_dispatch_wait
*
* Block until you can dispatch to the accelerator.
*/
void neureka_nnx_dispatch_wait(neureka_dev_t *dev);
void neureka_nnx_dispatch_wait(const neureka_dev_t *dev);

/** neureka_nnx_dispatch
*
* Dispatch a task to the accelerator.
* Fails with return code 1 if the task cannot be dispatched. Otherwise returns
* 0.
*/
int neureka_nnx_dispatch(neureka_dev_t *dev, neureka_task_t *task);
int neureka_nnx_dispatch(const neureka_dev_t *dev, neureka_task_t *task);

/** neureka_nnx_resolve_check
*
* Check whether the task has been resolved.
*/
int neureka_nnx_resolve_check(neureka_dev_t *dev, neureka_task_t *task);
int neureka_nnx_resolve_check(const neureka_dev_t *dev, neureka_task_t *task);

/** neureka_nnx_resolve_wait
*
* Block until you can resolve the task.
*/
void neureka_nnx_resolve_wait(neureka_dev_t *dev, neureka_task_t *task);
void neureka_nnx_resolve_wait(const neureka_dev_t *dev, neureka_task_t *task);
4 changes: 2 additions & 2 deletions ne16/gvsoc/ne16_gvsoc.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ typedef enum ne16_gvsoc_log_level_e {
NE16_GVSOC_LOG_LEVEL_ALL = 3
} ne16_gvsoc_log_level_e;

static void ne16_gvsoc_log_activate(ne16_dev_t *dev,
static void ne16_gvsoc_log_activate(const ne16_dev_t *dev,
ne16_gvsoc_log_level_e log_level,
ne16_gvsoc_log_format_e format) {
hwpe_task_reg_write(&dev->hwpe_dev, NE16_REG_GVSOC_LOG_LEVEL, log_level);
hwpe_task_reg_write(&dev->hwpe_dev, NE16_REG_GVSOC_LOG_FORMAT, format);
}

static void ne16_gvsoc_log_deactivate(ne16_dev_t *dev) {
static void ne16_gvsoc_log_deactivate(const ne16_dev_t *dev) {
hwpe_task_reg_write(&dev->hwpe_dev, NE16_REG_GVSOC_LOG_LEVEL,
NE16_GVSOC_LOG_LEVEL_CONFIG);
}
Expand Down
6 changes: 3 additions & 3 deletions ne16/hal/ne16.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@
#define NE16_STATUS_EMPTY (0x000)
#define NE16_STATUS_FULL (0x101)

inline int ne16_task_queue_tasks_in_flight(ne16_dev_t *dev) {
inline int ne16_task_queue_tasks_in_flight(const ne16_dev_t *dev) {
uint32_t status = hwpe_task_queue_status(&dev->hwpe_dev);
return (status & 0x1) + ((status >> 8) & 0x1);
}

inline int ne16_task_queue_empty(ne16_dev_t *dev) {
inline int ne16_task_queue_empty(const ne16_dev_t *dev) {
return hwpe_task_queue_status(&dev->hwpe_dev) == NE16_STATUS_EMPTY;
}

inline int ne16_task_queue_full(ne16_dev_t *dev) {
inline int ne16_task_queue_full(const ne16_dev_t *dev) {
return hwpe_task_queue_status(&dev->hwpe_dev) == NE16_STATUS_FULL;
}
6 changes: 3 additions & 3 deletions ne16/hal/ne16.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ typedef struct ne16_dev_t {
hwpe_dev_t hwpe_dev; /* Implements the HWPE device interface */
} ne16_dev_t;

int ne16_task_queue_tasks_in_flight(ne16_dev_t *dev);
int ne16_task_queue_empty(ne16_dev_t *dev);
int ne16_task_queue_full(ne16_dev_t *dev);
int ne16_task_queue_tasks_in_flight(const ne16_dev_t *dev);
int ne16_task_queue_empty(const ne16_dev_t *dev);
int ne16_task_queue_full(const ne16_dev_t *dev);

#endif // __NE16_H__
4 changes: 2 additions & 2 deletions neureka/gvsoc/neureka_gvsoc.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ typedef enum neureka_gvsoc_log_level_e {
NEUREKA_GVSOC_LOG_LEVEL_ALL = 3
} neureka_gvsoc_log_level_e;

static void neureka_gvsoc_log_activate(neureka_dev_t *dev,
static void neureka_gvsoc_log_activate(const neureka_dev_t *dev,
neureka_gvsoc_log_level_e log_level,
neureka_gvsoc_log_format_e format) {
hwpe_task_reg_write(&dev->hwpe_dev, NEUREKA_REG_GVSOC_LOG_LEVEL, log_level);
hwpe_task_reg_write(&dev->hwpe_dev, NEUREKA_REG_GVSOC_LOG_FORMAT, format);
}

static void neureka_gvsoc_log_deactivate(neureka_dev_t *dev) {
static void neureka_gvsoc_log_deactivate(const neureka_dev_t *dev) {
hwpe_task_reg_write(&dev->hwpe_dev, NEUREKA_REG_GVSOC_LOG_LEVEL,
NEUREKA_GVSOC_LOG_LEVEL_JOB_START_END);
}
Expand Down
6 changes: 3 additions & 3 deletions neureka/hal/neureka.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@
#define NEUREKA_STATUS_EMPTY (0x000)
#define NEUREKA_STATUS_FULL (0x101)

inline int neureka_task_queue_tasks_in_flight(neureka_dev_t *dev) {
inline int neureka_task_queue_tasks_in_flight(const neureka_dev_t *dev) {
uint32_t status = hwpe_task_queue_status(&dev->hwpe_dev);
return (status & 0x1) + ((status >> 8) & 0x1);
}

inline int neureka_task_queue_empty(neureka_dev_t *dev) {
inline int neureka_task_queue_empty(const neureka_dev_t *dev) {
return hwpe_task_queue_status(&dev->hwpe_dev) == NEUREKA_STATUS_EMPTY;
}

inline int neureka_task_queue_full(neureka_dev_t *dev) {
inline int neureka_task_queue_full(const neureka_dev_t *dev) {
return hwpe_task_queue_status(&dev->hwpe_dev) == NEUREKA_STATUS_FULL;
}
6 changes: 3 additions & 3 deletions neureka/hal/neureka.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ typedef struct neureka_dev_t {
hwpe_dev_t hwpe_dev; /* Implements the HWPE device interface */
} neureka_dev_t;

int neureka_task_queue_tasks_in_flight(neureka_dev_t *dev);
int neureka_task_queue_empty(neureka_dev_t *dev);
int neureka_task_queue_full(neureka_dev_t *dev);
int neureka_task_queue_tasks_in_flight(const neureka_dev_t *dev);
int neureka_task_queue_empty(const neureka_dev_t *dev);
int neureka_task_queue_full(const neureka_dev_t *dev);

#endif // __NEUREKA_H__
16 changes: 8 additions & 8 deletions src/pulp_nnx_ne16.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,27 +25,27 @@
#include <pmsis.h>
#include <stdint.h>

void ne16_nnx_init(ne16_dev_t *dev, ne16_pulp_conf_t *conf) {
void ne16_nnx_init(const ne16_dev_t *dev, ne16_pulp_conf_t *conf) {
ne16_pulp_open(conf);
hwpe_soft_clear(&dev->hwpe_dev);
}

void ne16_nnx_term(ne16_dev_t *dev) {
void ne16_nnx_term(const ne16_dev_t *dev) {
hwpe_soft_clear(&dev->hwpe_dev);
ne16_pulp_close();
}

int ne16_nnx_dispatch_check(ne16_dev_t *dev) {
int ne16_nnx_dispatch_check(const ne16_dev_t *dev) {
return !ne16_task_queue_full(dev);
}

void ne16_nnx_dispatch_wait(ne16_dev_t *dev) {
void ne16_nnx_dispatch_wait(const ne16_dev_t *dev) {
while (!ne16_nnx_dispatch_check(dev)) {
ne16_pulp_event_wait_and_clear();
}
}

int ne16_nnx_dispatch(ne16_dev_t *dev, ne16_task_t *task) {
int ne16_nnx_dispatch(const ne16_dev_t *dev, ne16_task_t *task) {
if (hwpe_task_queue_acquire_task(&dev->hwpe_dev, &task->id)) {
return 1;
}
Expand All @@ -55,7 +55,7 @@ int ne16_nnx_dispatch(ne16_dev_t *dev, ne16_task_t *task) {
return 0;
}

int ne16_nnx_resolve_check(ne16_dev_t *dev, ne16_task_t *task) {
int ne16_nnx_resolve_check(const ne16_dev_t *dev, ne16_task_t *task) {
#if __PLATFORM__ == ARCHI_PLATFORM_GVSOC
// GVSOC model has a broken running_id so resolve_check
// conservativly looks if the task queue is empty.
Expand All @@ -68,7 +68,7 @@ int ne16_nnx_resolve_check(ne16_dev_t *dev, ne16_task_t *task) {
#endif
}

void ne16_nnx_resolve_wait(ne16_dev_t *dev, ne16_task_t *task) {
void ne16_nnx_resolve_wait(const ne16_dev_t *dev, ne16_task_t *task) {
while (!ne16_nnx_resolve_check(dev, task)) {
ne16_pulp_event_wait_and_clear();
}
Expand All @@ -83,7 +83,7 @@ static inline uint32_t _get_tile_ptr(uint32_t ptr, int i, int j, int size_i,
(j * (size_j - overlap_j) - offset_j) * stride_k;
}

void ne16_nnx_dispatch_stride2x2(ne16_dev_t *dev, ne16_task_t *task,
void ne16_nnx_dispatch_stride2x2(const ne16_dev_t *dev, ne16_task_t *task,
const uint32_t w_in, const uint32_t k_in,
const uint32_t h_out, const uint32_t w_out,
const uint32_t k_out, const uint8_t h_ker,
Expand Down
14 changes: 7 additions & 7 deletions src/pulp_nnx_neureka.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,27 +26,27 @@
#include <stdint.h>
#include <sys/types.h>

void neureka_nnx_init(neureka_dev_t *dev, neureka_siracusa_conf_t *conf) {
void neureka_nnx_init(const neureka_dev_t *dev, neureka_siracusa_conf_t *conf) {
neureka_siracusa_open(conf);
hwpe_soft_clear(&dev->hwpe_dev);
}

void neureka_nnx_term(neureka_dev_t *dev) {
void neureka_nnx_term(const neureka_dev_t *dev) {
hwpe_soft_clear(&dev->hwpe_dev);
neureka_siracusa_close();
}

int neureka_nnx_dispatch_check(neureka_dev_t *dev) {
int neureka_nnx_dispatch_check(const neureka_dev_t *dev) {
return !neureka_task_queue_full(dev);
}

void neureka_nnx_dispatch_wait(neureka_dev_t *dev) {
void neureka_nnx_dispatch_wait(const neureka_dev_t *dev) {
while (!neureka_nnx_dispatch_check(dev)) {
neureka_siracusa_event_wait_and_clear();
}
}

int neureka_nnx_dispatch(neureka_dev_t *dev, neureka_task_t *task) {
int neureka_nnx_dispatch(const neureka_dev_t *dev, neureka_task_t *task) {
if (hwpe_task_queue_acquire_task(&dev->hwpe_dev, &task->id)) {
return 1;
}
Expand All @@ -56,7 +56,7 @@ int neureka_nnx_dispatch(neureka_dev_t *dev, neureka_task_t *task) {
return 0;
}

int neureka_nnx_resolve_check(neureka_dev_t *dev, neureka_task_t *task) {
int neureka_nnx_resolve_check(const neureka_dev_t *dev, neureka_task_t *task) {
#if __PLATFORM__ == ARCHI_PLATFORM_GVSOC
// GVSOC model has a broken running_id so resolve_check
// conservativly looks if the task queue is empty.
Expand All @@ -69,7 +69,7 @@ int neureka_nnx_resolve_check(neureka_dev_t *dev, neureka_task_t *task) {
#endif
}

void neureka_nnx_resolve_wait(neureka_dev_t *dev, neureka_task_t *task) {
void neureka_nnx_resolve_wait(const neureka_dev_t *dev, neureka_task_t *task) {
while (!neureka_nnx_resolve_check(dev, task)) {
neureka_siracusa_event_wait_and_clear();
}
Expand Down

0 comments on commit d78e403

Please sign in to comment.