Skip to content

Commit fd6c99d

Browse files
committed
Add Redmule Platform, Engline, Tiler, and Deployer
1 parent ac56ca2 commit fd6c99d

File tree

16 files changed

+670
-10
lines changed

16 files changed

+670
-10
lines changed

CMakeLists.txt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ if(TOOLCHAIN STREQUAL GCC)
1515
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
1616
endif()
1717

18-
set(platform MemPool CACHE STRING "Platform (MemPool, QEMU, Siracusa, Siracusa_w_neureka, PULP-Open, Generic, Snitch)")
19-
set_property(CACHE platform PROPERTY STRINGS MemPool QEMU Siracusa Siracusa_w_neureka PULP-Open Generic Snitch)
18+
set(platform MemPool CACHE STRING "Platform (MemPool, QEMU, Siracusa, Siracusa_w_neureka, Siracusa_w_redmule, PULP-Open, Generic, Snitch)")
19+
set_property(CACHE platform PROPERTY STRINGS MemPool QEMU Siracusa Siracusa_w_neureka Siracusa_w_redmule PULP-Open Generic Snitch)
2020

2121
if(platform STREQUAL MemPool)
2222
message(STATUS "Building for platform 'MemPool'")
@@ -26,6 +26,8 @@ elseif(platform STREQUAL Siracusa)
2626
message(STATUS "Building for platform 'Siracusa'")
2727
elseif(platform STREQUAL Siracusa_w_neureka)
2828
message(STATUS "Building for platform 'Siracusa_w_neureka'")
29+
elseif(platform STREQUAL Siracusa_w_redmule)
30+
message(STATUS "Building for platform 'Siracusa_w_redmule'")
2931
elseif(platform STREQUAL PULPOpen)
3032
message(STATUS "Building for platform 'PULP-Open'")
3133
elseif(platform STREQUAL Generic)
@@ -148,7 +150,7 @@ if(platform STREQUAL QEMU-ARM)
148150

149151
endif()
150152

151-
if(platform STREQUAL Siracusa OR platform STREQUAL Siracusa_w_neureka OR platform STREQUAL PULPOpen)
153+
if(platform STREQUAL Siracusa OR platform STREQUAL Siracusa_w_neureka OR platform STREQUAL Siracusa_w_redmule OR platform STREQUAL PULPOpen)
152154

153155
if(TOOLCHAIN STREQUAL LLVM)
154156
set(CMAKE_TOOLCHAIN_FILE ${CMAKE_CURRENT_LIST_DIR}/cmake/pulp/toolchain_llvm.cmake)
@@ -158,7 +160,7 @@ if(platform STREQUAL Siracusa OR platform STREQUAL Siracusa_w_neureka OR platfor
158160

159161
include(${CMAKE_CURRENT_LIST_DIR}/cmake/pulp/pulp.cmake)
160162

161-
if(platform STREQUAL Siracusa OR platform STREQUAL Siracusa_w_neureka)
163+
if(platform STREQUAL Siracusa OR platform STREQUAL Siracusa_w_neureka OR platform STREQUAL Siracusa_w_redmule)
162164
include(${CMAKE_CURRENT_LIST_DIR}/cmake/pulp/siracusa/siracusa.cmake)
163165
elseif(platform STREQUAL PULPOpen)
164166
include(${CMAKE_CURRENT_LIST_DIR}/cmake/pulp/pulp-open/pulp-open.cmake)

Deeploy/Targets/Generic/Templates/FloatMatMulTemplate.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
${data_out_type.typeName} ref_${data_out}_${data_out} = ${data_out};
3333
3434
for(uint32_t i=0; i<${batch}; i++){
35-
MatMul_fp${A_type.referencedType.typeWidth}_fp${B_type.referencedType.typeWidth}_fp${data_out_type.referencedType.typeWidth}_Redmule(
35+
MatMul_fp${A_type.referencedType.typeWidth}_fp${B_type.referencedType.typeWidth}_fp${data_out_type.referencedType.typeWidth}(
3636
ref_${data_out}_${A},
3737
ref_${data_out}_${B},
3838
ref_${data_out}_${data_out},
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# ----------------------------------------------------------------------
2+
#
3+
# File: NeurekaBindings.py
4+
#
5+
# Last edited: 10.07.2024
6+
#
7+
# Copyright (C) 2024, ETH Zurich and University of Bologna.
8+
#
9+
# Author:
10+
# Luka Macan, University of Bologna
11+
# Moritz Scherer, ETH Zurich
12+
#
13+
# ----------------------------------------------------------------------
14+
# SPDX-License-Identifier: Apache-2.0
15+
#
16+
# Licensed under the Apache License, Version 2.0 (the License); you may
17+
# not use this file except in compliance with the License.
18+
# You may obtain a copy of the License at
19+
#
20+
# www.apache.org/licenses/LICENSE-2.0
21+
#
22+
# Unless required by applicable law or agreed to in writing, software
23+
# distributed under the License is distributed on an AS IS BASIS, WITHOUT
24+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
25+
# See the License for the specific language governing permissions and
26+
# limitations under the License.
27+
28+
from Deeploy.AbstractDataTypes import PointerClass
29+
from Deeploy.CommonExtensions.DataTypes import float32_t
30+
from Deeploy.DeeployTypes import NodeBinding
31+
from Deeploy.Targets.Generic.TypeCheckers import MatMulChecker
32+
from Deeploy.Targets.Redmule.Templates import MatmulTemplate
33+
from Deeploy.Targets.PULPOpen.Bindings import ClusterTransformer
34+
from Deeploy.Targets.PULPOpen.TypeCheckers import PULPConvChecker
35+
36+
RedmuleMatmulBindings = [
37+
NodeBinding(MatMulChecker([PointerClass(float32_t), PointerClass(float32_t)], [PointerClass(float32_t)]),
38+
MatmulTemplate.referenceTemplate, ClusterTransformer)
39+
]
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# ----------------------------------------------------------------------
2+
#
3+
# File: Deployer.py
4+
#
5+
# Last edited: 08.05.2025
6+
#
7+
# Copyright (C) 2024, ETH Zurich and University of Bologna.
8+
#
9+
# Author: Run Wang, ETH Zurich
10+
#
11+
# ----------------------------------------------------------------------
12+
# SPDX-License-Identifier: Apache-2.0
13+
#
14+
# Licensed under the Apache License, Version 2.0 (the License); you may
15+
# not use this file except in compliance with the License.
16+
# You may obtain a copy of the License at
17+
#
18+
# www.apache.org/licenses/LICENSE-2.0
19+
#
20+
# Unless required by applicable law or agreed to in writing, software
21+
# distributed under the License is distributed on an AS IS BASIS, WITHOUT
22+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
23+
# See the License for the specific language governing permissions and
24+
# limitations under the License.
25+
26+
from typing import Callable, Dict, Type
27+
28+
import onnx_graphsurgeon as gs
29+
30+
from Deeploy.AbstractDataTypes import Pointer
31+
from Deeploy.DeeployTypes import DeploymentPlatform, TopologyOptimizer
32+
from Deeploy.Targets.PULPOpen.Deployer import PULPDeployer
33+
34+
35+
class RedmuleDeployer(PULPDeployer):
36+
37+
def __init__(self,
38+
graph: gs.Graph,
39+
deploymentPlatform: DeploymentPlatform,
40+
inputTypes: Dict[str, Type[Pointer]],
41+
loweringOptimizer: TopologyOptimizer,
42+
scheduler: Callable = lambda graph: list(graph.nodes),
43+
name: str = 'DeeployNetwork',
44+
default_channels_first = False,
45+
deeployStateDir: str = "DeeployStateDir",
46+
inputOffsets = {}):
47+
super().__init__(graph, deploymentPlatform, inputTypes, loweringOptimizer, scheduler, name,
48+
default_channels_first, deeployStateDir, inputOffsets)

Deeploy/Targets/Redmule/Engine.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# ----------------------------------------------------------------------
2+
#
3+
# File: Engine.py
4+
#
5+
# Last edited: 26.07.2024
6+
#
7+
# Copyright (C) 2024, ETH Zurich and University of Bologna.
8+
#
9+
# Author: Moritz Scherer, ETH Zurich
10+
#
11+
# ----------------------------------------------------------------------
12+
# SPDX-License-Identifier: Apache-2.0
13+
#
14+
# Licensed under the Apache License, Version 2.0 (the License); you may
15+
# not use this file except in compliance with the License.
16+
# You may obtain a copy of the License at
17+
#
18+
# www.apache.org/licenses/LICENSE-2.0
19+
#
20+
# Unless required by applicable law or agreed to in writing, software
21+
# distributed under the License is distributed on an AS IS BASIS, WITHOUT
22+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
23+
# See the License for the specific language governing permissions and
24+
# limitations under the License.
25+
26+
from typing import List
27+
28+
import onnx_graphsurgeon as gs
29+
30+
from Deeploy.DeeployTypes import DeploymentEngine, NodeMapper
31+
from Deeploy.Targets.Generic.Layers import MatMulLayer
32+
from Deeploy.Targets.Generic.Parsers import MatMulParser
33+
from Deeploy.Targets.Redmule.Tiler import RedmuleMatMulTilingReadyBindings
34+
35+
MatMulRedmuleMapper = NodeMapper(
36+
MatMulParser(), RedmuleMatMulTilingReadyBindings)
37+
38+
RedmuleMapping = {
39+
'MatMul': MatMulLayer([MatMulRedmuleMapper]),
40+
}
41+
42+
_includeList = []
43+
44+
_redmuleInitCode = r"""
45+
// Redmule engine initialization
46+
"""
47+
48+
49+
class RedmuleEngine(DeploymentEngine):
50+
51+
def __init__(self,
52+
name: str,
53+
Mapping = RedmuleMapping,
54+
initCode: str = _redmuleInitCode,
55+
includeList: List[str] = _includeList) -> None:
56+
super().__init__(name, Mapping, initCode, includeList)
57+
58+
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# ----------------------------------------------------------------------
2+
#
3+
# File: Platform.py
4+
#
5+
# Last edited: 08.05.2025
6+
#
7+
# Copyright (C) 2024, ETH Zurich and University of Bologna.
8+
#
9+
# Author: Run Wang, ETH Zurich
10+
#
11+
# ----------------------------------------------------------------------
12+
# SPDX-License-Identifier: Apache-2.0
13+
#
14+
# Licensed under the Apache License, Version 2.0 (the License); you may
15+
# not use this file except in compliance with the License.
16+
# You may obtain a copy of the License at
17+
#
18+
# www.apache.org/licenses/LICENSE-2.0
19+
#
20+
# Unless required by applicable law or agreed to in writing, software
21+
# distributed under the License is distributed on an AS IS BASIS, WITHOUT
22+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
23+
# See the License for the specific language governing permissions and
24+
# limitations under the License.
25+
26+
from Deeploy.DeeployTypes import TopologyOptimizer
27+
from Deeploy.Targets.Redmule.Engine import RedmuleEngine
28+
from Deeploy.Targets.PULPOpen.Platform import PULPClusterEngine, \
29+
PULPOptimizer, PULPPlatform, PULPStructBuffer, PULPTransientBuffer, PULPVariableBuffer, PULPConstantBuffer
30+
31+
RedmuleOptimizer = TopologyOptimizer([
32+
*PULPOptimizer.passes
33+
])
34+
35+
class RedmulePlatform(PULPPlatform):
36+
37+
def __init__(self,
38+
engines = [RedmuleEngine("Redmule"), PULPClusterEngine("PULPCluster")],
39+
variableBuffer = PULPVariableBuffer,
40+
constantBuffer = PULPConstantBuffer,
41+
structBuffer = PULPStructBuffer,
42+
transientBuffer = PULPTransientBuffer) -> None:
43+
super().__init__(engines, variableBuffer, constantBuffer, structBuffer, transientBuffer)
44+
45+
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# ----------------------------------------------------------------------
2+
#
3+
# File: MatMul.py.py
4+
#
5+
# Last edited: 27.01.2025
6+
#
7+
# Copyright (C) 2023, ETH Zurich and University of Bologna.
8+
#
9+
# Author: Run Wang, ETH Zurich
10+
#
11+
# ----------------------------------------------------------------------
12+
# SPDX-License-Identifier: Apache-2.0
13+
#
14+
# Licensed under the Apache License, Version 2.0 (the License); you may
15+
# not use this file except in compliance with the License.
16+
# You may obtain a copy of the License at
17+
#
18+
# www.apache.org/licenses/LICENSE-2.0
19+
#
20+
# Unless required by applicable law or agreed to in writing, software
21+
# distributed under the License is distributed on an AS IS BASIS, WITHOUT
22+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
23+
# See the License for the specific language governing permissions and
24+
# limitations under the Licens
25+
from Deeploy.DeeployTypes import NodeTemplate
26+
27+
referenceTemplate = NodeTemplate("""
28+
// Matmul using RedMule hardware accelerator (Name: ${nodeName}, Op: ${nodeOp})
29+
30+
int8_t ${nodeName}_core_id = pi_core_id();
31+
int8_t ${nodeName}_num_cores = NUM_CORES;
32+
33+
if (${nodeName}_core_id == 0) {
34+
for(uint32_t b=0; b<${batch}; b++) {
35+
${A_type.typeName} batch_A = ${A} + b * ${M} * ${N};
36+
${B_type.typeName} batch_B = ${B} + b * ${N} * ${O};
37+
${data_out_type.typeName} batch_out = ${data_out} + b * ${M} * ${O};
38+
39+
MatMul_fp32_fp32_fp32_Redmule(
40+
(const float32_t *) batch_A,
41+
(const float32_t *) batch_B,
42+
(float32_t *) batch_out,
43+
${M},
44+
${N},
45+
${O}
46+
);
47+
}
48+
}
49+
""")
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# ----------------------------------------------------------------------
2+
#
3+
# File: __init__.py
4+
#
5+
# Last edited: 08.05.2025
6+
#
7+
# Copyright (C) 2024, ETH Zurich and University of Bologna.
8+
#
9+
# Author: Run Wang, ETH Zurich
10+
#
11+
# ----------------------------------------------------------------------
12+
# SPDX-License-Identifier: Apache-2.0
13+
#
14+
# Licensed under the Apache License, Version 2.0 (the License); you may
15+
# not use this file except in compliance with the License.
16+
# You may obtain a copy of the License at
17+
#
18+
# www.apache.org/licenses/LICENSE-2.0
19+
#
20+
# Unless required by applicable law or agreed to in writing, software
21+
# distributed under the License is distributed on an AS IS BASIS, WITHOUT
22+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
23+
# See the License for the specific language governing permissions and
24+
# limitations under the License.
25+
26+
from . import *

0 commit comments

Comments
 (0)