-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Decouple pulp-sdk and add hwpe device structure (#1)
* Add hwpe interface and decouple pulp-sdk from hal * Fixes and changes to test Fixed/ignored some pyright bugs. Made generated data files external which additionally required touching of the nnx_layer.c file before compiling to have correct compilation but still without `make clean`. Added `-flto` flag to compilation. Some formatting fixes.
- Loading branch information
Showing
25 changed files
with
1,044 additions
and
759 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* | ||
* Luka Macan <[email protected]> | ||
* | ||
* Copyright 2023 ETH Zurich and University of Bologna | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#include "ne16.h" | ||
#include "ne16_pulp_bsp.h" | ||
#include "ne16_task.h" | ||
#include <stdint.h> | ||
|
||
/* PULP-NNX interface */ | ||
|
||
void ne16_nnx_init(ne16_dev_t *dev, ne16_pulp_conf_t *conf); | ||
void ne16_nnx_term(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); | ||
|
||
/** ne16_nnx_dispatch_wait | ||
* | ||
* Block until you can dispatch to the accelerator. | ||
*/ | ||
void ne16_nnx_dispatch_wait(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); | ||
|
||
/** ne16_nnx_resolve_check | ||
* | ||
* Check whether the task has been resolved. | ||
*/ | ||
int ne16_nnx_resolve_check(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); | ||
|
||
|
||
/* Additional helper functions */ | ||
|
||
/** ne16_nnx_dispatch_stride2x2 | ||
* | ||
* It uses NE16's 2x2 strided mode which reduces the number of writes NE16 does. | ||
* This mode doesn't stride the NE16's subtile input pointer, so we have to | ||
* 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, const uint32_t w_in, const uint32_t k_in, | ||
const uint32_t w_in_stride, const uint32_t k_in_stride, | ||
const uint32_t h_out, const uint32_t w_out, const uint32_t k_out, | ||
const uint32_t w_out_stride, const uint32_t k_out_stride, | ||
const uint8_t h_ker, const uint8_t w_ker); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/* | ||
* Luka Macan <[email protected]> | ||
* | ||
* Copyright 2023 ETH Zurich and University of Bologna | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#include "ne16_pulp_bsp.h" | ||
#include <pmsis.h> | ||
|
||
#define NE16_PULP_CLUSTER_CTRL_ADDR_BASE (0x00200000) | ||
#define NE16_PULP_CLUSTER_CTRL_HWPE_OFFS 0x18 | ||
#define NE16_PULP_CLUSTER_CTRL_HWPE_ADDR \ | ||
(NE16_PULP_CLUSTER_CTRL_ADDR_BASE + NE16_PULP_CLUSTER_CTRL_HWPE_OFFS) | ||
#define NE16_PULP_CLUSTER_CTRL_HWPE_MASK_CG_EN 0x800 | ||
#define NE16_PULP_CLUSTER_CTRL_HWPE_MASK_HCI_PRIO 0x100 | ||
#define NE16_PULP_CLUSTER_CTRL_HWPE_MASK_HCI_MAXSTALL 0xff | ||
#define NE16_PULP_MAX_STALL (8) | ||
#define NE16_PULP_EVENT (1 << 12) | ||
#define NE16_PULP_BASE_ADDR (0x00201000) | ||
|
||
void ne16_pulp_cg_enable() { | ||
*(volatile uint32_t *)NE16_PULP_CLUSTER_CTRL_HWPE_ADDR |= | ||
NE16_PULP_CLUSTER_CTRL_HWPE_MASK_CG_EN; | ||
} | ||
|
||
void ne16_pulp_cg_disable() { | ||
*(volatile uint32_t *)NE16_PULP_CLUSTER_CTRL_HWPE_ADDR &= | ||
~NE16_PULP_CLUSTER_CTRL_HWPE_MASK_CG_EN; | ||
} | ||
|
||
void ne16_pulp_hci_setpriority_ne16() { | ||
*(volatile uint32_t *)NE16_PULP_CLUSTER_CTRL_HWPE_ADDR |= | ||
NE16_PULP_CLUSTER_CTRL_HWPE_MASK_HCI_PRIO; | ||
} | ||
|
||
void ne16_pulp_hci_setpriority_core() { | ||
*(volatile uint32_t *)NE16_PULP_CLUSTER_CTRL_HWPE_ADDR &= | ||
~NE16_PULP_CLUSTER_CTRL_HWPE_MASK_HCI_PRIO; | ||
} | ||
|
||
void ne16_pulp_hci_reset_max_stall() { | ||
*(volatile uint32_t *)NE16_PULP_CLUSTER_CTRL_HWPE_ADDR &= | ||
~NE16_PULP_CLUSTER_CTRL_HWPE_MASK_HCI_MAXSTALL; | ||
} | ||
|
||
void ne16_pulp_hci_set_max_stall(uint32_t max_stall) { | ||
*(volatile uint32_t *)NE16_PULP_CLUSTER_CTRL_HWPE_ADDR |= | ||
max_stall & NE16_PULP_CLUSTER_CTRL_HWPE_MASK_HCI_MAXSTALL; | ||
} | ||
|
||
void ne16_pulp_open(ne16_pulp_conf_t *conf) { | ||
ne16_pulp_cg_enable(); | ||
ne16_pulp_hci_setpriority_ne16(); | ||
ne16_pulp_hci_set_max_stall(conf->max_stall); | ||
} | ||
|
||
void ne16_pulp_close() { | ||
ne16_pulp_hci_reset_max_stall(); | ||
ne16_pulp_hci_setpriority_core(); | ||
ne16_pulp_cg_disable(); | ||
} | ||
|
||
void ne16_pulp_event_wait_and_clear() { | ||
eu_evt_maskWaitAndClr(NE16_PULP_EVENT); | ||
} | ||
|
||
static const ne16_dev_t ne16_pulp_dev = { | ||
.hwpe_dev = (struct hwpe_dev_t){ | ||
.base_addr = (volatile uint32_t *)NE16_PULP_BASE_ADDR}}; | ||
|
||
const ne16_dev_t *ne16_pulp_get_dev() { return &ne16_pulp_dev; } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* | ||
* Luka Macan <[email protected]> | ||
* | ||
* Copyright 2023 ETH Zurich and University of Bologna | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#ifndef __NE16_PULP_BSP_H__ | ||
#define __NE16_PULP_BSP_H__ | ||
|
||
#include "ne16.h" | ||
#include <stdint.h> | ||
|
||
/** | ||
* ne16_pulp_cg_enable | ||
* | ||
* Enable clock gating of the NE16. | ||
*/ | ||
void ne16_pulp_cg_enable(); | ||
|
||
/** | ||
* ne16_pulp_cg_enable | ||
* | ||
* Disable clock gating of the NE16. | ||
*/ | ||
void ne16_pulp_cg_disable(); | ||
|
||
/** | ||
* ne16_pulp_setpriority_ne16 | ||
* | ||
* Set HCI interconnect bus priority to prioritize NE16. | ||
*/ | ||
void ne16_pulp_hci_setpriority_ne16(); | ||
|
||
/** | ||
* ne16_pulp_setpriority_core | ||
* | ||
* Set HCI bus priority to prioritize cores. | ||
*/ | ||
void ne16_pulp_hci_setpriority_core(); | ||
|
||
/** | ||
* ne16_pulp_hci_reset_maxstall | ||
* | ||
* Reset the HCI bus maxstall parameter. | ||
* TODO: Check if it disables it also or just resets? | ||
*/ | ||
void ne16_pulp_hci_reset_max_stall(); | ||
|
||
/** | ||
* ne16_pulp_hci_set_maxstall | ||
* | ||
* Set the HCI bus maxstall. Maxstall defines how many cycles | ||
* will the HCI bus stall the lower priority master, i.e. ne16 or core, | ||
* before letting it do a transaction. | ||
*/ | ||
void ne16_pulp_hci_set_max_stall(uint32_t max_stall); | ||
|
||
typedef struct ne16_pulp_conf_t { | ||
int max_stall; | ||
} ne16_pulp_conf_t; | ||
|
||
void ne16_pulp_open(ne16_pulp_conf_t *conf); | ||
void ne16_pulp_close(); | ||
void ne16_pulp_event_wait_and_clear(); | ||
const ne16_dev_t *ne16_pulp_get_dev(); | ||
|
||
#endif // !__NE16_PULP_BSP_H__ |
Oops, something went wrong.