From a3f675a0ce4b984a80784d12abe0ff0ee01ebf55 Mon Sep 17 00:00:00 2001 From: Alex Marchioni Date: Thu, 22 Oct 2026 13:00:44 +0000 Subject: [PATCH 01/18] [PULPOpen] add support for idma --- .../PULPClusterTiling.py | 14 +++- Deeploy/Targets/PULPOpen/DMA/MchanDma.py | 2 + Deeploy/Targets/PULPOpen/DMA/iDMA.py | 80 +++++++++++++++++++ Deeploy/Targets/PULPOpen/Platform.py | 61 +++++++++++++- DeeployTest/Platforms/PULPOpen/CMakeLists.txt | 16 +++- .../Platforms/PULPOpen/src/deeploytest.c | 6 ++ DeeployTest/deeployRunner_pulpopen.py | 24 ++++++ DeeployTest/deeployRunner_tiled_pulpopen.py | 24 ++++++ DeeployTest/generateNetwork.py | 11 ++- DeeployTest/testUtils/codeGenerate.py | 6 +- DeeployTest/testUtils/deeployRunner.py | 10 ++- DeeployTest/testUtils/pytestRunner.py | 9 ++- 12 files changed, 250 insertions(+), 13 deletions(-) create mode 100644 Deeploy/Targets/PULPOpen/DMA/iDMA.py create mode 100644 DeeployTest/deeployRunner_pulpopen.py create mode 100644 DeeployTest/deeployRunner_tiled_pulpopen.py diff --git a/Deeploy/Targets/PULPOpen/CodeTransformationPasses/PULPClusterTiling.py b/Deeploy/Targets/PULPOpen/CodeTransformationPasses/PULPClusterTiling.py index 3c0bba3107..393d9d043b 100644 --- a/Deeploy/Targets/PULPOpen/CodeTransformationPasses/PULPClusterTiling.py +++ b/Deeploy/Targets/PULPOpen/CodeTransformationPasses/PULPClusterTiling.py @@ -31,10 +31,16 @@ class ProfilingPULPClusterTilingGenerationDB(DoubleBufferingTilingCodeGeneration class PULPClusterTiling(CodeTransformationPass): def __init__(self, externalMemory: str, localMemory: str, dma: AsyncDma): - self.SB = PULPClusterTilingGenerationSB(externalMemory, localMemory, dma) - self.profilingSB = ProfilingPULPClusterTilingGenerationSB(externalMemory, localMemory, dma) - self.DB = PULPClusterTilingGenerationDB(externalMemory, localMemory, dma) - self.profilingDB = ProfilingPULPClusterTilingGenerationDB(externalMemory, localMemory, dma) + self.externalMemory = externalMemory + self.localMemory = localMemory + self.setDma(dma) + + def setDma(self, dma: AsyncDma) -> None: + self.dma = dma + self.SB = PULPClusterTilingGenerationSB(self.externalMemory, self.localMemory, dma) + self.profilingSB = ProfilingPULPClusterTilingGenerationSB(self.externalMemory, self.localMemory, dma) + self.DB = PULPClusterTilingGenerationDB(self.externalMemory, self.localMemory, dma) + self.profilingDB = ProfilingPULPClusterTilingGenerationDB(self.externalMemory, self.localMemory, dma) def apply(self, ctxt: NetworkContext, diff --git a/Deeploy/Targets/PULPOpen/DMA/MchanDma.py b/Deeploy/Targets/PULPOpen/DMA/MchanDma.py index 93bf699dc6..41b8a368b7 100644 --- a/Deeploy/Targets/PULPOpen/DMA/MchanDma.py +++ b/Deeploy/Targets/PULPOpen/DMA/MchanDma.py @@ -27,6 +27,8 @@ class MchanChannelFuture(Future): class MchanDma(AsyncDma): + includeList = ["mchan_siracusa.h"] + _transferTemplates = { 1: NodeTemplate("mchan_transfer_1d(${cmd}, ${loc}, ${ext});"), 2: NodeTemplate("mchan_transfer_2d_ext_strided(${cmd}, ${loc}, ${ext}, ${size_1d}, ${stride_2d});"), diff --git a/Deeploy/Targets/PULPOpen/DMA/iDMA.py b/Deeploy/Targets/PULPOpen/DMA/iDMA.py new file mode 100644 index 0000000000..cc026cbb17 --- /dev/null +++ b/Deeploy/Targets/PULPOpen/DMA/iDMA.py @@ -0,0 +1,80 @@ +# Copyright (c) 2025 FondazioneChipsIT +# SPDX-License-Identifier: Apache-2.0 + +import math +from typing import Dict, Tuple + +from Deeploy.DeeployTypes import NetworkContext, NodeTemplate, OperatorRepresentation, VariableBuffer +from Deeploy.TilingExtension.AsyncDma import AsyncDma, DirectionWaitingStrategy, DmaDirection, Future + + +class iDMAChannelFuture(Future): + + _initTemplate = NodeTemplate("") + _deinitTemplate = NodeTemplate("") + _waitTemplate = NodeTemplate("") + _allocTemplate = NodeTemplate("") + + +class iDMA(AsyncDma): + + includeList = ["pulp_core.h"] + + _transferTemplates = { + 1: + NodeTemplate("pulp_idma_transfer_1d_and_wait(${direction}, ${ext}, ${loc}, ${length});"), + 2: + NodeTemplate( + "pulp_idma_transfer_2d_and_wait(${direction}, ${ext}, ${loc}, ${length}, ${strideExt}, ${strideLoc}, ${num_reps});" + ) + } + _waitingStrategy = DirectionWaitingStrategy(iDMAChannelFuture, "channel_id") + + def __init__(self, transferTemplates: Dict[int, NodeTemplate] = _transferTemplates) -> None: + super().__init__(transferTemplates) + + def checkTransfer(self, ctxt: NetworkContext, externalBuffer: VariableBuffer, localBuffer: VariableBuffer, + shape: Tuple[int, ...], strideExt: Tuple[int, ...], strideLoc: Tuple[int, ...], + direction: DmaDirection) -> None: + super().checkTransfer(ctxt, externalBuffer, localBuffer, shape, strideExt, strideLoc, direction) + + # Here are some assertions on the iDMA transfer parameters + transferRank = len(shape) + + assert transferRank == 1 or transferRank == 2, "Only 1D and 2D transfers are supported for now" + + if transferRank == 1: + length = shape[0] + elif transferRank == 2: + length = shape[1] + + iDMA_transfer_size = math.prod(shape) + + assert iDMA_transfer_size <= 2**16, ( + "iDMA transfer size should be representable with 16 bits, " + f"current number of bits required is {math.ceil(math.log2(iDMA_transfer_size))}") + + if transferRank == 2: + assert strideExt[0] >= length, "External stride must be at least equal to the length" + assert strideLoc[0] >= length, "Local stride must be at least equal to the length" + + def transferOpRepr(self, externalBuffer: VariableBuffer, localBuffer: VariableBuffer, shape: Tuple[int, ...], + strideExt: Tuple[int, ...], strideLoc: Tuple[int, ...], direction: DmaDirection, + future: Future) -> OperatorRepresentation: + operatorRepresentation = super().transferOpRepr(externalBuffer, localBuffer, shape, strideExt, strideLoc, + direction, future) + + transferRank = len(shape) + operatorRepresentation["direction"] = 1 if direction == "ExternalToLocal" else 0 + + iDMA_transfer_size = math.prod(shape) + + if transferRank == 1: + operatorRepresentation["length"] = shape[0] + elif transferRank == 2: + operatorRepresentation["length"] = shape[1] + operatorRepresentation["strideExt"] = strideExt[0] + operatorRepresentation["strideLoc"] = strideLoc[0] + operatorRepresentation["num_reps"] = iDMA_transfer_size // shape[1] + + return operatorRepresentation diff --git a/Deeploy/Targets/PULPOpen/Platform.py b/Deeploy/Targets/PULPOpen/Platform.py index 0eb5962e2c..92736a61d2 100644 --- a/Deeploy/Targets/PULPOpen/Platform.py +++ b/Deeploy/Targets/PULPOpen/Platform.py @@ -2,13 +2,17 @@ # # SPDX-License-Identifier: Apache-2.0 +import copy +from enum import Enum +from typing import Type, Union + import numpy as np import onnx_graphsurgeon as gs from Deeploy.CommonExtensions.OptimizationPasses.TopologyOptimizationPasses.LoweringOptimizationPasses import \ RemoveEmptyConvBiasPass, RemoveOnlySingletonReduceMeanPass from Deeploy.DeeployTypes import ConstantBuffer, DeploymentEngine, DeploymentPlatform, NetworkContext, NodeMapper, \ - NodeTemplate, StructBuffer, TopologyOptimizer, TransientBuffer, VariableBuffer + NodeTemplate, ONNXLayer, StructBuffer, TopologyOptimizer, TransientBuffer, VariableBuffer from Deeploy.MemoryLevelExtension.MemoryLevels import MemoryHierarchy, MemoryLevel from Deeploy.MemoryLevelExtension.NetworkDeployers.MemoryLevelDeployer import MemoryPlatform, MemoryPlatformWrapper from Deeploy.Targets.Generic.Bindings import BasicGEMMBindings, BasicPad1DBindings, BasicPad2DBindings, \ @@ -31,6 +35,9 @@ SkipEmptyConcatPass, SkipUnityRequantPass, iGELURequantMergePass, iHardswishRequantMergePass from Deeploy.Targets.PULPOpen.Bindings import BasicDequantBindings, BasicQuantBindings, PULPDMASliceBindings, \ PULPDWConv1DBinding +from Deeploy.Targets.PULPOpen.CodeTransformationPasses.PULPClusterTiling import PULPClusterTiling +from Deeploy.Targets.PULPOpen.DMA.iDMA import iDMA +from Deeploy.Targets.PULPOpen.DMA.MchanDma import MchanDma from Deeploy.Targets.PULPOpen.Layers import PULPRQSConvLayer, PULPRQSGEMMLayer from Deeploy.Targets.PULPOpen.Parsers import PULPConv1DParser, PULPConv2DParser, PULPDWConv1DParser, \ PULPDWConv2DParser, PULPFPConv2DParser, PULPFPDWConv2DParser, PULPGEMMParser, PULPMatrixVecParser, \ @@ -52,6 +59,7 @@ PULPTransposeTilingReadyBindings, PULPUniformRQSTilingReadyBindings from Deeploy.Targets.PULPOpen.TopologyOptimizationPasses.Passes import PULPAddRequantMergePass, \ PULPConvRequantMergePass, PULPGEMMRequantMergePass, PULPMatMulRequantMergePass +from Deeploy.TilingExtension.AsyncDma import AsyncDma RQAddMapper = NodeMapper(RQAddParser(), PULPRQAddTilingReadyBindings) AddMapper = NodeMapper(AddParser(), PULPAddTilingReadyBindings) @@ -252,12 +260,46 @@ class PULPStructBuffer(StructBuffer): name = "PULPOptimizer") # SCHEREMO: stdint is included before pulp_nn_kernels.h because it is supposed to be included in there, but isn't... +# DMA-specific headers are appended by PULPClusterEngine.setDma _includeList = [ - "pmsis.h", "stdint.h", "pulp_nn_kernels.h", "DeeployPULPMath.h", "mchan_siracusa.h", "dory_mem.h", "bsp/ram.h", - "perf_utils.h" + "pmsis.h", "stdint.h", "pulp_nn_kernels.h", "DeeployPULPMath.h", "dory_mem.h", "bsp/ram.h", "perf_utils.h" ] +class PULPDma(str, Enum): + """Cluster DMA engine used for L2<->L1 tiling transfers""" + + MCHAN = "mchan" + IDMA = "idma" + + # Keep f-strings and CLI args identical across Python versions + def __str__(self) -> str: + return self.value + + @property + def dmaClass(self) -> Type[AsyncDma]: + return {PULPDma.MCHAN: MchanDma, PULPDma.IDMA: iDMA}[self] + + +# Return a copy of `mapping` whose L2<->L1 cluster tiling uses `dma`. +# The DMA is baked into the module-level code transformers (Bindings.py) shared +# by all bindings, so it is fixed at import time. Hence PULPMapping is built +# with MchanDma, and an engine targeting another DMA deep-copies it and swaps +# the DMA in every PULPClusterTiling pass. The copy keeps the shared PULPMapping +# (also used by Siracusa and Neureka) untouched. +def _remapClusterDma(mapping, dma: AsyncDma): + mapping = copy.deepcopy(mapping) + for layer in mapping.values(): + if not isinstance(layer, ONNXLayer): + continue + for mapper in layer.maps: + for binding in mapper.bindings: + for _pass in binding.codeTransformer.passes: + if isinstance(_pass, PULPClusterTiling): + _pass.setDma(dma) + return mapping + + class PULPClusterEngine(DeploymentEngine): def __init__(self, @@ -265,9 +307,20 @@ def __init__(self, Mapping = PULPMapping, initCode = "", includeList = _includeList, - n_cores: int = 8) -> None: + n_cores: int = 8, + dma: str = "mchan") -> None: super().__init__(name, Mapping, initCode, includeList) self.n_cores = n_cores + self._baseIncludeList = list(includeList) + self.dma = PULPDma.MCHAN # PULPMapping is built with MchanDma + self.setDma(dma) + + def setDma(self, dma: Union[PULPDma, str]) -> None: + dma = PULPDma(dma) + if dma != self.dma: + self.Mapping = _remapClusterDma(self.Mapping, dma.dmaClass()) + self.dma = dma + self.includeList = self._baseIncludeList + dma.dmaClass.includeList class PULPPlatform(DeploymentPlatform): diff --git a/DeeployTest/Platforms/PULPOpen/CMakeLists.txt b/DeeployTest/Platforms/PULPOpen/CMakeLists.txt index 9dfd2f466f..8df0e324eb 100644 --- a/DeeployTest/Platforms/PULPOpen/CMakeLists.txt +++ b/DeeployTest/Platforms/PULPOpen/CMakeLists.txt @@ -4,6 +4,20 @@ set(ProjectId ${TESTNAME}) +set(PULP_DMA MCHAN CACHE STRING "Cluster DMA engine (MCHAN, IDMA)") +set_property(CACHE PULP_DMA PROPERTY STRINGS MCHAN IDMA) +if(NOT PULP_DMA MATCHES "^(MCHAN|IDMA)$") + message(FATAL_ERROR "[Deeploy PULP-OPEN] Unknown PULP_DMA '${PULP_DMA}'. Supported: MCHAN, IDMA") +endif() + +# Generated code and build must agree on the cluster DMA +file(STRINGS ${GENERATED_SOURCE}/Network.h _dmaDefine REGEX "#define DEEPLOY_PULP_DMA_") +if(NOT _dmaDefine MATCHES "DEEPLOY_PULP_DMA_${PULP_DMA}$") + message(FATAL_ERROR "[Deeploy PULP-OPEN] PULP_DMA=${PULP_DMA} but Network.h has '${_dmaDefine}'. " + "Regenerate with --dma or reconfigure with -DPULP_DMA.") +endif() +message(STATUS "[Deeploy PULP-OPEN] Cluster DMA = ${PULP_DMA}") + file(GLOB_RECURSE SOURCES src/CycleCounter.c src/deeploytest.c @@ -13,6 +27,6 @@ add_deeploy_executable(${ProjectId} EXCLUDE_FROM_ALL ${SOURCES}) target_include_directories(${ProjectId} PRIVATE ${CMAKE_CURRENT_LIST_DIR}/inc) target_link_libraries(${ProjectId} PRIVATE network deeploylib) -add_gvsoc_emulation(${ProjectId} "siracusa") +add_gvsoc_emulation(${ProjectId} "pulp-open") link_compile_dump(${TESTNAME}) diff --git a/DeeployTest/Platforms/PULPOpen/src/deeploytest.c b/DeeployTest/Platforms/PULPOpen/src/deeploytest.c index 11d889e48d..a148c09785 100644 --- a/DeeployTest/Platforms/PULPOpen/src/deeploytest.c +++ b/DeeployTest/Platforms/PULPOpen/src/deeploytest.c @@ -98,10 +98,16 @@ int main(void) { pi_cluster_task(&cluster_task, RunNetwork, NULL); cluster_task.stack_size = MAINSTACKSIZE; cluster_task.slave_stack_size = SLAVESTACKSIZE; +#ifdef DEEPLOY_PULP_DMA_IDMA + plp_idma_enable_clk(); +#endif ResetTimer(); StartTimer(); pi_cluster_send_task_to_cl(&cluster_dev, &cluster_task); StopTimer(); +#ifdef DEEPLOY_PULP_DMA_IDMA + plp_idma_disable_clk(); +#endif #ifndef CI printf("Output:\r\n"); diff --git a/DeeployTest/deeployRunner_pulpopen.py b/DeeployTest/deeployRunner_pulpopen.py new file mode 100644 index 0000000000..84b4879c22 --- /dev/null +++ b/DeeployTest/deeployRunner_pulpopen.py @@ -0,0 +1,24 @@ +#!/usr/bin/env python +# SPDX-FileCopyrightText: 2025 ETH Zurich and University of Bologna +# +# SPDX-License-Identifier: Apache-2.0 + +import sys + +from testUtils.deeployRunner import main + +if __name__ == "__main__": + + # Define parser setup callback to add Siracusa-specific arguments + def setup_parser(parser): + parser.add_argument('--cores', type = int, default = 8, help = 'Number of cores (default: 8)\n') + parser.add_argument('--dma', + choices = ['mchan', 'idma'], + default = 'mchan', + help = 'Cluster DMA engine (default: mchan)\n') + + sys.exit( + main(default_platform = "PULPOpen", + default_simulator = "gvsoc", + tiling_enabled = False, + parser_setup_callback = setup_parser)) \ No newline at end of file diff --git a/DeeployTest/deeployRunner_tiled_pulpopen.py b/DeeployTest/deeployRunner_tiled_pulpopen.py new file mode 100644 index 0000000000..fd7f672a79 --- /dev/null +++ b/DeeployTest/deeployRunner_tiled_pulpopen.py @@ -0,0 +1,24 @@ +#!/usr/bin/env python +# SPDX-FileCopyrightText: 2025 ETH Zurich and University of Bologna +# +# SPDX-License-Identifier: Apache-2.0 + +import sys + +from testUtils.deeployRunner import main + +if __name__ == "__main__": + + # Define parser setup callback to add Siracusa-specific arguments + def setup_parser(parser): + parser.add_argument('--cores', type = int, default = 8, help = 'Number of cores (default: 8)\n') + parser.add_argument('--dma', + choices = ['mchan', 'idma'], + default = 'mchan', + help = 'Cluster DMA engine (default: mchan)\n') + + sys.exit( + main(default_platform = "PULPOpen", + default_simulator = "gvsoc", + tiling_enabled = True, + parser_setup_callback = setup_parser)) \ No newline at end of file diff --git a/DeeployTest/generateNetwork.py b/DeeployTest/generateNetwork.py index 159cfd19e9..4bca4dda2a 100644 --- a/DeeployTest/generateNetwork.py +++ b/DeeployTest/generateNetwork.py @@ -20,7 +20,7 @@ from Deeploy.DeeployTypes import _NoVerbosity from Deeploy.Logging import DEFAULT_LOGGER as log from Deeploy.Targets.CortexM.Platform import CMSISPlatform -from Deeploy.Targets.PULPOpen.Platform import PULPClusterEngine, PULPPlatform +from Deeploy.Targets.PULPOpen.Platform import PULPClusterEngine, PULPDma, PULPPlatform def generateNetwork(args): @@ -85,9 +85,13 @@ def generateNetwork(args): platform, signProp = mapPlatform(args.platform) + if args.dma != PULPDma.MCHAN and args.platform != "PULPOpen": + raise ValueError(f"--dma={args.dma} is only supported on PULPOpen, not on {args.platform}") + clusters = [engine for engine in platform.engines if isinstance(engine, PULPClusterEngine)] for cluster in clusters: cluster.n_cores = args.cores + cluster.setDma(args.dma) inputTypes = {} inputOffsets = {} @@ -202,6 +206,11 @@ def generateNetwork(args): help = "Number of cores on which the network is run. Currently, required for im2col buffer sizing on Siracusa. Default: 1.", ) + parser.add_argument("--dma", + type = PULPDma, + choices = list(PULPDma), + default = PULPDma.MCHAN, + help = "Cluster DMA engine (PULPOpen only). Default: mchan.") parser.set_defaults(shouldFail = False) args = parser.parse_args() diff --git a/DeeployTest/testUtils/codeGenerate.py b/DeeployTest/testUtils/codeGenerate.py index ff677a5de6..12597834f8 100644 --- a/DeeployTest/testUtils/codeGenerate.py +++ b/DeeployTest/testUtils/codeGenerate.py @@ -9,7 +9,8 @@ from Deeploy.DeeployTypes import CodeGenVerbosity, ConstantBuffer, NetworkDeployer, VariableBuffer from Deeploy.Targets.MemPool.Platform import MemPoolPlatform -from Deeploy.Targets.PULPOpen.Platform import MemoryPULPPlatform, MemoryPULPPlatformWrapper, PULPPlatform +from Deeploy.Targets.PULPOpen.Platform import MemoryPULPPlatform, MemoryPULPPlatformWrapper, PULPClusterEngine, \ + PULPPlatform from Deeploy.Targets.Snitch.Platform import SnitchPlatform _TEXT_ALIGN = 30 @@ -135,6 +136,9 @@ def generateTestNetworkHeader(deployer: NetworkDeployer) -> str: #include """ retStr += deployer.generateIncludeString() + for engine in deployer.Platform.engines: + if isinstance(engine, PULPClusterEngine): + retStr += f"\n#define DEEPLOY_PULP_DMA_{engine.dma.upper()}\n" if isinstance(deployer.Platform, (PULPPlatform, MemoryPULPPlatform, MemoryPULPPlatformWrapper)): retStr += """ void RunNetwork(); diff --git a/DeeployTest/testUtils/deeployRunner.py b/DeeployTest/testUtils/deeployRunner.py index fde32cdb69..fa0e36b4e1 100644 --- a/DeeployTest/testUtils/deeployRunner.py +++ b/DeeployTest/testUtils/deeployRunner.py @@ -255,6 +255,9 @@ def create_config_from_args(args: argparse.Namespace, if getattr(args, 'profileMicrobenchmark', False): gen_args_list.append("--profileMicrobenchmark") + if getattr(args, 'dma', None): + gen_args_list.append(f"--dma={args.dma}") + config = DeeployTestConfig( test_name = test_name, test_dir = test_dir_abs, @@ -363,13 +366,14 @@ def main(default_platform: Optional[str] = None, "generic": "Generic", "qemu-arm": "QEMU-ARM", "mempool": "MemPool", + "pulpopen": "PULPOpen", "siracusa": "Siracusa", "siracusa_w_neureka": "Siracusa_w_neureka", "snitch": "Snitch", "chimera": "Chimera", "softhier": "SoftHier", "xdna2": "XDNA2", - "xheep": "Xheep" + "xheep": "Xheep", } if args.platform: @@ -410,6 +414,7 @@ def main(default_platform: Optional[str] = None, "Snitch": "gvsoc", "Chimera": "gvsoc", "SoftHier": "gvsoc", + "PULPOpen": "gvsoc", } simulator = simulator_map.get(platform, "host") log.info(f"No simulator specified, using default for {platform}: {simulator}") @@ -423,6 +428,9 @@ def main(default_platform: Optional[str] = None, elif hasattr(args, 'num_cores'): platform_specific_cmake_args.append(f"-DNUM_CORES={args.num_cores}") + if hasattr(args, 'dma'): + platform_specific_cmake_args.append(f"-DPULP_DMA={args.dma.upper()}") + if hasattr(args, 'num_clusters'): platform_specific_cmake_args.append(f"-DNUM_CLUSTERS={args.num_clusters}") diff --git a/DeeployTest/testUtils/pytestRunner.py b/DeeployTest/testUtils/pytestRunner.py index b94ec488b1..6d1893459c 100644 --- a/DeeployTest/testUtils/pytestRunner.py +++ b/DeeployTest/testUtils/pytestRunner.py @@ -50,6 +50,7 @@ def create_test_config( randomized_mem_scheduler: bool = False, profile_untiled: bool = False, gen_args: Optional[List[str]] = None, + dma: Optional[str] = None, ) -> DeeployTestConfig: test_dir = f"Tests/{test_name}" @@ -69,9 +70,15 @@ def create_test_config( gen_args_list = list(gen_args) if gen_args else [] - if cores is not None and platform in ["Siracusa", "Siracusa_w_neureka"]: + if cores is not None and platform in ["Siracusa", "Siracusa_w_neureka", "PULPOpen"]: gen_args_list.append(f"--cores={cores}") + # Always pass the DMA on PULPOpen so a cached PULP_DMA from a previous run cannot leak in + if platform == "PULPOpen": + dma = dma or "mchan" + gen_args_list.append(f"--dma={dma}") + cmake_args_list.append(f"PULP_DMA={dma.upper()}") + if tiling: if l1 is not None: gen_args_list.append(f"--l1={l1}") From dfc08d772093bed368a26679f27f27a8a6778185 Mon Sep 17 00:00:00 2001 From: Alex Marchioni Date: Fri, 23 Oct 2026 13:55:18 +0000 Subject: [PATCH 02/18] WIP adding test for pulpopen and fix llvm --- Container/Dockerfile.deeploy | 7 +- DeeployTest/conftest.py | 2 + DeeployTest/deeployRunner_pulpopen.py | 4 +- DeeployTest/deeployRunner_tiled_pulpopen.py | 4 +- DeeployTest/testMVP.py | 11 +- DeeployTest/test_platforms.py | 188 ++++++++++++++++++ DeeployTest/test_pulpopen_config.py | 80 ++++++++ DeeployTest/test_pulpopen_tiled_config.py | 160 +++++++++++++++ Makefile | 21 +- .../PULPOpen/cmake/pulp-sdk-pulp-open.cmake | 1 + toolchain/gvsoc_pulp_open.patch | 135 +++++++++++++ 11 files changed, 601 insertions(+), 12 deletions(-) create mode 100644 DeeployTest/test_pulpopen_config.py create mode 100644 DeeployTest/test_pulpopen_tiled_config.py create mode 100644 toolchain/gvsoc_pulp_open.patch diff --git a/Container/Dockerfile.deeploy b/Container/Dockerfile.deeploy index 2b717e49ec..437e803e3f 100644 --- a/Container/Dockerfile.deeploy +++ b/Container/Dockerfile.deeploy @@ -34,6 +34,8 @@ RUN --mount=type=cache,target=/ccache \ make gvsoc && \ cp -r toolchain/gvsoc/core/requirements.txt /app/core-requirements.txt && \ cp -r toolchain/gvsoc/gapy/requirements.txt /app/gapy-requirements.txt && \ + cp -r toolchain/gvsoc/gvrun/requirements.txt /app/gvrun-requirements.txt && \ + cp -r toolchain/gvsoc/config_tree/requirements.txt /app/config-tree-requirements.txt && \ rm -rf toolchain/pulp-sdk toolchain/qemu toolchain/mempool toolchain/banshee toolchain/xtensor toolchain/xtl toolchain/xsimd toolchain/gvsoc && \ ccache -s @@ -133,8 +135,11 @@ RUN sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master COPY --from=toolchain /app/core-requirements.txt ./core-requirements.txt COPY --from=toolchain /app/gapy-requirements.txt ./gapy-requirements.txt +COPY --from=toolchain /app/gvrun-requirements.txt ./gvrun-requirements.txt +COPY --from=toolchain /app/config-tree-requirements.txt ./config-tree-requirements.txt COPY requirements-dev.txt ./ -RUN pip install -r requirements-dev.txt -r core-requirements.txt -r gapy-requirements.txt +RUN pip install -r requirements-dev.txt -r core-requirements.txt -r gapy-requirements.txt \ + -r gvrun-requirements.txt -r config-tree-requirements.txt # Copy pre-built toolchains and emulators COPY --from=toolchain /app/install /app/install diff --git a/DeeployTest/conftest.py b/DeeployTest/conftest.py index d400177319..4947af9d99 100644 --- a/DeeployTest/conftest.py +++ b/DeeployTest/conftest.py @@ -66,6 +66,8 @@ def pytest_configure(config: pytest.Config) -> None: config.addinivalue_line("markers", "siracusa_tiled: mark test as a Siracusa platform test (tiled)") config.addinivalue_line("markers", "siracusa_neureka_tiled: mark test as a Siracusa + Neureka platform test (tiled)") + config.addinivalue_line("markers", "pulpopen: mark test as a PULP-Open platform test (untiled)") + config.addinivalue_line("markers", "pulpopen_tiled: mark test as a PULP-Open platform test (tiled)") config.addinivalue_line("markers", "gap9: mark test as a GAP9 platform test") config.addinivalue_line("markers", "gap9_tiled: mark test as a GAP9 platform test (tiled)") config.addinivalue_line("markers", "xdna2: mark test as an XDNA2 (AIE2p) platform test") diff --git a/DeeployTest/deeployRunner_pulpopen.py b/DeeployTest/deeployRunner_pulpopen.py index 84b4879c22..1a961b5ac8 100644 --- a/DeeployTest/deeployRunner_pulpopen.py +++ b/DeeployTest/deeployRunner_pulpopen.py @@ -14,8 +14,8 @@ def setup_parser(parser): parser.add_argument('--cores', type = int, default = 8, help = 'Number of cores (default: 8)\n') parser.add_argument('--dma', choices = ['mchan', 'idma'], - default = 'mchan', - help = 'Cluster DMA engine (default: mchan)\n') + default = 'idma', + help = 'Cluster DMA engine (default: idma)\n') sys.exit( main(default_platform = "PULPOpen", diff --git a/DeeployTest/deeployRunner_tiled_pulpopen.py b/DeeployTest/deeployRunner_tiled_pulpopen.py index fd7f672a79..e44193a48a 100644 --- a/DeeployTest/deeployRunner_tiled_pulpopen.py +++ b/DeeployTest/deeployRunner_tiled_pulpopen.py @@ -14,8 +14,8 @@ def setup_parser(parser): parser.add_argument('--cores', type = int, default = 8, help = 'Number of cores (default: 8)\n') parser.add_argument('--dma', choices = ['mchan', 'idma'], - default = 'mchan', - help = 'Cluster DMA engine (default: mchan)\n') + default = 'idma', + help = 'Cluster DMA engine (default: idma)\n') sys.exit( main(default_platform = "PULPOpen", diff --git a/DeeployTest/testMVP.py b/DeeployTest/testMVP.py index 998412772b..3bec10fdd3 100644 --- a/DeeployTest/testMVP.py +++ b/DeeployTest/testMVP.py @@ -28,7 +28,7 @@ from Deeploy.MemoryLevelExtension.OptimizationPasses.MemoryLevelAnnotationPasses import AnnotateDefaultMemoryLevel, \ AnnotateIOMemoryLevel from Deeploy.Targets.Neureka.OptimizationPasses.MemoryLevelAnnotationPasses import AnnotateNeurekaWeightMemoryLevel -from Deeploy.Targets.PULPOpen.Platform import PULPClusterEngine +from Deeploy.Targets.PULPOpen.Platform import PULPClusterEngine, PULPDma from Deeploy.TilingExtension.TilerExtension import TilerDeployerWrapper @@ -78,9 +78,13 @@ def setupDeployer(graph: gs.Graph, memoryHierarchy: MemoryHierarchy, defaultTarg if args.enableStrides: platform.engines[0].enableStrides = True + if args.dma != PULPDma.MCHAN and args.platform != "PULPOpen": + raise ValueError(f"--dma={args.dma} is only supported on PULPOpen, not on {args.platform}") + clusters = [engine for engine in platform.engines if isinstance(engine, PULPClusterEngine)] for cluster in clusters: cluster.n_cores = args.cores + cluster.setDma(args.dma) for index, num in enumerate(test_inputs): original_dtype = test_input_original_dtypes[index] if index < len(test_input_original_dtypes) else None @@ -211,6 +215,11 @@ def setupDeployer(graph: gs.Graph, memoryHierarchy: MemoryHierarchy, defaultTarg help = "Number of cores on which the network is run. Currently, required for im2col buffer sizing on Siracusa. Default: 1." ) + parser.add_argument("--dma", + type = PULPDma, + choices = list(PULPDma), + default = PULPDma.MCHAN, + help = "Cluster DMA engine (PULPOpen only). Default: mchan.") parser.set_defaults(shouldFail = False) args = parser.parse_args() diff --git a/DeeployTest/test_platforms.py b/DeeployTest/test_platforms.py index dba0acd376..6184fcb0c6 100644 --- a/DeeployTest/test_platforms.py +++ b/DeeployTest/test_platforms.py @@ -23,6 +23,13 @@ from test_mempool_config import DEFAULT_NUM_THREADS as MEMPOOL_DEFAULT_NUM_THREADS from test_mempool_config import KERNEL_TESTS as MEMPOOL_KERNEL_TESTS from test_mempool_config import MODEL_TESTS as MEMPOOL_MODEL_TESTS +from test_pulpopen_config import DEFAULT_CORES as PULPOPEN_DEFAULT_CORES +from test_pulpopen_config import KERNEL_TESTS as PULPOPEN_KERNEL_TESTS +from test_pulpopen_config import MODEL_TESTS as PULPOPEN_MODEL_TESTS +from test_pulpopen_tiled_config import L2_DOUBLEBUFFER_KERNELS as PULPOPEN_L2_DOUBLEBUFFER_KERNELS +from test_pulpopen_tiled_config import L2_DOUBLEBUFFER_MODELS as PULPOPEN_L2_DOUBLEBUFFER_MODELS +from test_pulpopen_tiled_config import L2_SINGLEBUFFER_KERNELS as PULPOPEN_L2_SINGLEBUFFER_KERNELS +from test_pulpopen_tiled_config import L2_SINGLEBUFFER_MODELS as PULPOPEN_L2_SINGLEBUFFER_MODELS from test_siracusa_config import DEFAULT_CORES as SIRACUSA_DEFAULT_CORES from test_siracusa_config import KERNEL_TESTS as SIRACUSA_KERNEL_TESTS from test_siracusa_config import MODEL_TESTS as SIRACUSA_MODEL_TESTS @@ -113,6 +120,13 @@ def param_id(param): "model_tests": SNITCH_MODEL_TESTS, "default_num_cores": SNITCH_DEFAULT_NUM_CORES, }, + "PULPOpen": { + "platform": "PULPOpen", + "simulator": "gvsoc", + "kernel_tests": PULPOPEN_KERNEL_TESTS, + "model_tests": PULPOPEN_MODEL_TESTS, + "default_num_cores": PULPOPEN_DEFAULT_CORES, + }, "gap9": { "platform": "GAP9", "simulator": "gvsoc", @@ -146,6 +160,8 @@ def param_id(param): # siracusa_neureka_tiled: tests from the Siracusa + Neureka platform (tiled) # gap9: tests from the GAP9 platform (untiled) # gap9_tiled: tests from the GAP9 platform (tiled) +# pulpopen: tests from the PULP-Open platform (untiled) +# pulpopen_tiled: tests from the PULP-Open platform (tiled) # Test type markers: # kernels: single kernel (or single layer) tests # models: full model (multiple layer) tests @@ -1085,3 +1101,175 @@ def test_xheep_kernels(test_name, deeploy_test_dir, toolchain, toolchain_dir, cm cmake_args = cmake_args, tiling = False) run_and_assert_test(test_name, config, skipgen, skipsim) + + +@pytest.mark.pulpopen +@pytest.mark.kernels +@pytest.mark.parametrize("test_name", PULPOPEN_KERNEL_TESTS, ids = PULPOPEN_KERNEL_TESTS) +def test_pulpopen_kernels(test_name, deeploy_test_dir, toolchain, toolchain_dir, cmake_args, skipgen, skipsim, + profile_untiled) -> None: + platform_config = PLATFORM_CONFIGS["PULPOpen"] + config = create_test_config( + test_name = test_name, + platform = platform_config["platform"], + simulator = platform_config["simulator"], + deeploy_test_dir = deeploy_test_dir, + toolchain = toolchain, + toolchain_dir = toolchain_dir, + cmake_args = cmake_args, + tiling = False, + cores = PULPOPEN_DEFAULT_CORES, + profile_untiled = profile_untiled, + ) + run_and_assert_test(test_name, config, skipgen, skipsim) + + +@pytest.mark.pulpopen +@pytest.mark.models +@pytest.mark.parametrize("test_name", PULPOPEN_MODEL_TESTS, ids = PULPOPEN_MODEL_TESTS) +def test_pulpopen_models(test_name, deeploy_test_dir, toolchain, toolchain_dir, cmake_args, skipgen, skipsim, + profile_untiled) -> None: + + platform_config = PLATFORM_CONFIGS["PULPOpen"] + + config = create_test_config( + test_name = test_name, + platform = platform_config["platform"], + simulator = platform_config["simulator"], + deeploy_test_dir = deeploy_test_dir, + toolchain = toolchain, + toolchain_dir = toolchain_dir, + cmake_args = cmake_args, + tiling = False, + cores = PULPOPEN_DEFAULT_CORES, + profile_untiled = profile_untiled, + ) + run_and_assert_test(test_name, config, skipgen, skipsim) + + +@pytest.mark.pulpopen_tiled +@pytest.mark.kernels +@pytest.mark.singlebuffer +@pytest.mark.l2 +@pytest.mark.parametrize( + "test_params", + generate_test_params(PULPOPEN_L2_SINGLEBUFFER_KERNELS, "L2-singlebuffer"), + ids = param_id, +) +def test_pulpopen_tiled_kernels_l2_singlebuffer(test_params, deeploy_test_dir, toolchain, toolchain_dir, cmake_args, + skipgen, skipsim) -> None: + + platform_config = PLATFORM_CONFIGS["PULPOpen"] + + test_name, l1, config_name = test_params + config = create_test_config( + test_name = test_name, + platform = platform_config["platform"], + simulator = platform_config["simulator"], + deeploy_test_dir = deeploy_test_dir, + toolchain = toolchain, + toolchain_dir = toolchain_dir, + cmake_args = cmake_args, + tiling = True, + cores = PULPOPEN_DEFAULT_CORES, + l1 = l1, + default_mem_level = "L2", + double_buffer = False, + ) + run_and_assert_test(test_name, config, skipgen, skipsim) + + +@pytest.mark.pulpopen_tiled +@pytest.mark.kernels +@pytest.mark.doublebuffer +@pytest.mark.l2 +@pytest.mark.parametrize( + "test_params", + generate_test_params(PULPOPEN_L2_DOUBLEBUFFER_KERNELS, "L2-doublebuffer"), + ids = param_id, +) +def test_pulpopen_tiled_kernels_l2_doublebuffer(test_params, deeploy_test_dir, toolchain, toolchain_dir, cmake_args, + skipgen, skipsim) -> None: + + platform_config = PLATFORM_CONFIGS["PULPOpen"] + + test_name, l1, config_name = test_params + config = create_test_config( + test_name = test_name, + platform = platform_config["platform"], + simulator = platform_config["simulator"], + deeploy_test_dir = deeploy_test_dir, + toolchain = toolchain, + toolchain_dir = toolchain_dir, + cmake_args = cmake_args, + tiling = True, + cores = PULPOPEN_DEFAULT_CORES, + l1 = l1, + default_mem_level = "L2", + double_buffer = True, + ) + run_and_assert_test(test_name, config, skipgen, skipsim) + + +@pytest.mark.pulpopen_tiled +@pytest.mark.models +@pytest.mark.singlebuffer +@pytest.mark.l2 +@pytest.mark.parametrize( + "test_params", + generate_test_params(PULPOPEN_L2_SINGLEBUFFER_MODELS, "L2-singlebuffer"), + ids = param_id, +) +def test_pulpopen_tiled_models_l2_singlebuffer(test_params, deeploy_test_dir, toolchain, toolchain_dir, cmake_args, + skipgen, skipsim) -> None: + + platform_config = PLATFORM_CONFIGS["PULPOpen"] + + test_name, l1, config_name = test_params + config = create_test_config( + test_name = test_name, + platform = platform_config["platform"], + simulator = platform_config["simulator"], + deeploy_test_dir = deeploy_test_dir, + toolchain = toolchain, + toolchain_dir = toolchain_dir, + cmake_args = cmake_args, + tiling = True, + cores = PULPOPEN_DEFAULT_CORES, + l1 = l1, + default_mem_level = "L2", + double_buffer = False, + ) + run_and_assert_test(test_name, config, skipgen, skipsim) + + +@pytest.mark.pulpopen_tiled +@pytest.mark.models +@pytest.mark.doublebuffer +@pytest.mark.l2 +@pytest.mark.parametrize( + "test_params", + generate_test_params(PULPOPEN_L2_DOUBLEBUFFER_MODELS, "L2-doublebuffer"), + ids = param_id, +) +def test_pulpopen_tiled_models_l2_doublebuffer(test_params, deeploy_test_dir, toolchain, toolchain_dir, cmake_args, + skipgen, skipsim) -> None: + + platform_config = PLATFORM_CONFIGS["PULPOpen"] + + test_name, l1, config_name = test_params + config = create_test_config( + test_name = test_name, + platform = platform_config["platform"], + simulator = platform_config["simulator"], + deeploy_test_dir = deeploy_test_dir, + toolchain = toolchain, + toolchain_dir = toolchain_dir, + cmake_args = cmake_args, + tiling = True, + cores = PULPOPEN_DEFAULT_CORES, + l1 = l1, + default_mem_level = "L2", + double_buffer = True, + ) + run_and_assert_test(test_name, config, skipgen, skipsim) diff --git a/DeeployTest/test_pulpopen_config.py b/DeeployTest/test_pulpopen_config.py new file mode 100644 index 0000000000..6ccf7d2750 --- /dev/null +++ b/DeeployTest/test_pulpopen_config.py @@ -0,0 +1,80 @@ +# SPDX-FileCopyrightText: 2025 ETH Zurich and University of Bologna +# +# SPDX-License-Identifier: Apache-2.0 + +PLATFORM_NAME = "PULPOpen" +SIMULATOR = "gvsoc" +DEFAULT_CORES = 8 + +KERNEL_TESTS = [ + # "Kernels/FP32/ReLU", + # "Kernels/FP32/Softmax/CrossEntropy", + # "Kernels/FP32/Softmax/CrossEntropyGrad", + # "Kernels/FP32/Softmax/Grad", + # "Kernels/FP32/Softmax/Regular", + # "Kernels/FP32/Add/Regular", + # "Kernels/FP32/Conv/DW_2D_Bias", + # "Kernels/FP32/Conv/DW_2D_NoBias", + # "Kernels/FP32/Conv/DW_2D_ZeroValuedBias", + # "Kernels/FP32/Conv/Regular_2D_Bias", + # "Kernels/FP32/Conv/Regular_2D_NoBias", + # "Kernels/FP32/Conv/Regular_2D_ZeroValuedBias", + # "Kernels/FP32/GEMM/Regular", + # "Kernels/FP32/MatMul", + # "Kernels/FP32/MaxPool/Regular_2D", + # "Kernels/FP32/Mul/Regular", + # "Kernels/FP32/LayerNorm", + # "Kernels/FP32/ReduceMean/KeepDims/Add_ReduceMean", + # "Kernels/FP32/ReduceMean/KeepDims/Add_ReduceMean_Add", + # "Kernels/FP32/ReduceMean/KeepDims/AllAxes", + # "Kernels/FP32/ReduceMean/KeepDims/Axes1_2_3", + # "Kernels/FP32/ReduceMean/KeepDims/Axes1_3", + # "Kernels/FP32/ReduceMean/KeepDims/Axes2_1", + # "Kernels/FP32/ReduceMean/KeepDims/Axis0", + # "Kernels/FP32/ReduceMean/KeepDims/Axis2", + # "Kernels/FP32/ReduceMean/KeepDims/ReduceMean_Add", + # "Kernels/FP32/ReduceMean/NoKeepDims/Add_ReduceMean", + # "Kernels/FP32/ReduceMean/NoKeepDims/Add_ReduceMean_Add", + # "Kernels/FP32/ReduceMean/NoKeepDims/AllAxes", + # "Kernels/FP32/ReduceMean/NoKeepDims/Axes1_2_3", + # "Kernels/FP32/ReduceMean/NoKeepDims/Axes1_3", + # "Kernels/FP32/ReduceMean/NoKeepDims/Axes2_1", + # "Kernels/FP32/ReduceMean/NoKeepDims/Axis0", + # "Kernels/FP32/ReduceMean/NoKeepDims/Axis2", + # "Kernels/FP32/ReduceMean/NoKeepDims/ReduceMean_Add", + # "Kernels/FP32/ReduceSum", + # "Kernels/FP32/Reshape/SkipConnection", + # "Kernels/FP32/Transpose", + "Kernels/Integer/Hardswish/Regular", + "Kernels/Integer/Softmax/Regular", + "Kernels/Integer/Add/MultIO", + "Kernels/Integer/Add/Regular", + "Kernels/Integer/Concat", + "Kernels/Integer/MatMul/Add", + "Kernels/Integer/MatMul/Regular", + "Kernels/Integer/Pad/Regular_1D", + "Kernels/Integer/Pad/Regular_2D", + "Kernels/Integer/RMSNorm", + # "Models/TinyViT/5M/Layers/FP32/ReduceMean", + "Others/Backtracking", + # "Kernels/Mixed/Dequant", + # "Kernels/Mixed/Quant", + # "Models/Transformer_DeepQuant", + "Kernels/Integer/Conv/Regular_2D_RQ", + "Kernels/Integer/Conv/DW_2D_RQ", + "Kernels/Integer/Hardswish/Regular_RQ", + "Kernels/Integer/TrueIntegerDiv", +] + +MODEL_TESTS = [ + "Kernels/Integer/Attention", + # "Models/CCT/FP32/CCT_1_16_16_8", + # "Models/CCT/FP32/CCT_2_32_32_128_Opset20", + "Models/miniMobileNet", + "Models/miniMobileNetv2", + "Models/MLPerf/KeywordSpotting", + "Models/MLPerf/ImageClassification", + "Models/MLPerf/AnomalyDetection", + # "Models/TinyViT/Demo", + "Models/CNN_Linear2", +] diff --git a/DeeployTest/test_pulpopen_tiled_config.py b/DeeployTest/test_pulpopen_tiled_config.py new file mode 100644 index 0000000000..06f679ac8e --- /dev/null +++ b/DeeployTest/test_pulpopen_tiled_config.py @@ -0,0 +1,160 @@ +# SPDX-FileCopyrightText: 2025 ETH Zurich and University of Bologna +# +# SPDX-License-Identifier: Apache-2.0 + +PLATFORM_NAME = "PULPOpen" +SIMULATOR = "gvsoc" +DEFAULT_CORES = 8 +DEFAULT_L2 = 1024000 +DEFAULT_MEM_ALLOC_STRATEGY = "MiniMalloc" +DEFAULT_SEARCH_STRATEGY = "random-max" + +L2_SINGLEBUFFER_KERNELS = { + # "Kernels/FP32/ReLU": [2000], + # "Kernels/FP32/Softmax/Regular": [4000], + # "Kernels/FP32/Add/Large": [220000], + # "Kernels/FP32/Conv/DW_2D_Bias": [7200], + # "Kernels/FP32/Conv/DW_2D_NoBias": [7200], + # "Kernels/FP32/Conv/DW_2D_ZeroValuedBias": [7200], + # "Kernels/FP32/Conv/Regular_2D_Bias": [6600], + # "Kernels/FP32/Conv/Regular_2D_NoBias": [1600], + # "Kernels/FP32/Conv/Regular_2D_ZeroValuedBias": [6600], + # "Kernels/FP32/GEMM/Regular": [8000], + # "Kernels/FP32/MatMul": [2000], + # "Kernels/FP32/MaxPool/Regular_2D": [2000], + # "Kernels/FP32/Mul/Regular": [2000], + # "Kernels/FP32/LayerNorm": [2000], + # "Kernels/FP32/ReduceMean/KeepDims/Add_ReduceMean": [8000], + # "Kernels/FP32/ReduceMean/KeepDims/Add_ReduceMean_Add": [8000], + # "Kernels/FP32/ReduceMean/KeepDims/AllAxes": [50000], + # "Kernels/FP32/ReduceMean/KeepDims/Axes1_2_3": [50000], + # "Kernels/FP32/ReduceMean/KeepDims/Axes1_3": [5000, 50000], + # "Kernels/FP32/ReduceMean/KeepDims/Axes2_1": [6200, 50000], + # "Kernels/FP32/ReduceMean/KeepDims/Axis0": [8400, 50000], + # "Kernels/FP32/ReduceMean/KeepDims/Axis2": [8400, 50000], + # "Kernels/FP32/ReduceMean/KeepDims/ReduceMean_Add": [8000], + # "Kernels/FP32/ReduceMean/NoKeepDims/Add_ReduceMean": [8000], + # "Kernels/FP32/ReduceMean/NoKeepDims/Add_ReduceMean_Add": [8000], + # "Kernels/FP32/ReduceMean/NoKeepDims/AllAxes": [50000], + # "Kernels/FP32/ReduceMean/NoKeepDims/Axes1_2_3": [50000], + # "Kernels/FP32/ReduceMean/NoKeepDims/Axes1_3": [5000, 50000], + # "Kernels/FP32/ReduceMean/NoKeepDims/Axes2_1": [6200, 50000], + # "Kernels/FP32/ReduceMean/NoKeepDims/Axis0": [8400, 50000], + # "Kernels/FP32/ReduceMean/NoKeepDims/Axis2": [8400, 50000], + # "Kernels/FP32/ReduceMean/NoKeepDims/ReduceMean_Add": [8000], + # "Kernels/FP32/Reshape/SkipConnection": [1400], + # "Kernels/FP32/Transpose": [2000], + "Kernels/Integer/Hardswish/Regular": [750], + "Kernels/Integer/Softmax/Regular": [800, 500, 300], + "Kernels/Integer/Concat": [32000, 16000, 8000], + "Kernels/Integer/MatMul/Batch": [20000], + "Kernels/Integer/MatMul/Regular": [64000, 32000, 16000], + "Kernels/Integer/RMSNorm": [2048, 1024, 512], + "Kernels/Integer/Conv/Regular_2D_RQ": [8000, 6000, 4000], + "Kernels/Integer/Conv/DW_2D_RQ": [2561], + "Kernels/Integer/Conv/StriddedPadded_2D_RQ": [600], + "Kernels/Integer/GEMM/Batch_RQ": [20000], + "Kernels/Integer/Hardswish/Regular_RQ": [750], +} + +L2_DOUBLEBUFFER_KERNELS = { + # "Kernels/FP32/ReLU": [20], + # "Kernels/FP32/Softmax/Regular": [8000], + # "Kernels/FP32/Conv/DW_2D_Bias": [10000], + # "Kernels/FP32/Conv/DW_2D_NoBias": [9800], + # "Kernels/FP32/Conv/DW_2D_ZeroValuedBias": [9800], + # "Kernels/FP32/Conv/Regular_2D_Bias": [8800], + # "Kernels/FP32/Conv/Regular_2D_NoBias": [2000], + # "Kernels/FP32/Conv/Regular_2D_ZeroValuedBias": [8800], + # "Kernels/FP32/GEMM/Regular": [8000], + # "Kernels/FP32/MatMul": [5000], + # "Kernels/FP32/MaxPool/Regular_2D": [5000], + # "Kernels/FP32/Mul/Regular": [2000], + # "Kernels/FP32/LayerNorm": [2000], + # "Kernels/FP32/ReduceMean/KeepDims/Add_ReduceMean": [8000], + # "Kernels/FP32/ReduceMean/KeepDims/Add_ReduceMean_Add": [8000], + # "Kernels/FP32/ReduceMean/KeepDims/AllAxes": [100000], + # "Kernels/FP32/ReduceMean/KeepDims/Axes1_2_3": [100000], + # "Kernels/FP32/ReduceMean/KeepDims/Axes1_3": [10000, 50000], + # "Kernels/FP32/ReduceMean/KeepDims/Axes2_1": [13000, 50000], + # "Kernels/FP32/ReduceMean/KeepDims/Axis0": [17000, 50000], + # "Kernels/FP32/ReduceMean/KeepDims/Axis2": [17000, 50000], + # "Kernels/FP32/ReduceMean/KeepDims/ReduceMean_Add": [8000], + # "Kernels/FP32/ReduceMean/NoKeepDims/Add_ReduceMean": [8000], + # "Kernels/FP32/ReduceMean/NoKeepDims/Add_ReduceMean_Add": [8000], + # "Kernels/FP32/ReduceMean/NoKeepDims/AllAxes": [100000], + # "Kernels/FP32/ReduceMean/NoKeepDims/Axes1_2_3": [100000], + # "Kernels/FP32/ReduceMean/NoKeepDims/Axes1_3": [10000, 50000], + # "Kernels/FP32/ReduceMean/NoKeepDims/Axes2_1": [13000, 50000], + # "Kernels/FP32/ReduceMean/NoKeepDims/Axis0": [17000, 50000], + # "Kernels/FP32/ReduceMean/NoKeepDims/Axis2": [17000, 50000], + # "Kernels/FP32/ReduceMean/NoKeepDims/ReduceMean_Add": [8000], + # "Kernels/FP32/Reshape/SkipConnection": [2600], + # "Kernels/FP32/Transpose": [2000], + "Kernels/Integer/Hardswish/Regular": [750], + "Kernels/Integer/Softmax/Regular": [1600, 1000, 600], + "Kernels/Integer/Concat": [64000, 32000, 16000], + "Kernels/Integer/MatMul/Regular": [64000, 32000, 16000], + "Kernels/Integer/RMSNorm": [4096, 2048, 1024], + "Kernels/Integer/Conv/Regular_2D_RQ": [8000, 6000, 5000], + "Kernels/Integer/Conv/DW_2D_RQ": [5121], + "Kernels/Integer/Hardswish/Regular_RQ": [800], +} + +L2_SINGLEBUFFER_MODELS = { + "Models/CNN_Linear2": [45000, 30000, 15000], + "Models/miniMobileNet": [60000, 12000, 6000, 3000], + "Models/miniMobileNetv2": [60000, 16000, 12000, 8000], + "Kernels/Integer/Attention": [60000, 10000, 5000], + "Models/microLlama/INT8/microLlama1": [60000, 10000, 5000], + "Models/microLlama/INT8/microLlama8": [60000, 10000, 5000], + "Models/microLlama/INT8/microLlama8_parallel": [60000, 10000, 5000], + "Models/MLPerf/KeywordSpotting": [64000], + "Models/MLPerf/ImageClassification": [64000], + "Models/MLPerf/AnomalyDetection": [64000], + "Models/MLPerf/VisualWakeWords": [64000], + # "Models/CCT/FP32/CCT_1_16_16_8": [64000], + # "Models/TinyViT/Demo": [4000], +} + +L2_DOUBLEBUFFER_MODELS = { + "Models/CNN_Linear2": [60000, 45000, 30000], + "Models/miniMobileNet": [60000, 24000, 12000, 6000], + "Models/miniMobileNetv2": [60000, 32000, 24000, 16000], + "Kernels/Integer/Attention": [60000, 20000, 10000, 5000], + "Models/microLlama/INT8/microLlama1": [60000, 20000, 10000], + "Models/microLlama/INT8/microLlama8": [60000, 20000, 10000], + "Models/microLlama/INT8/microLlama8_parallel": [60000, 20000, 10000], + "Models/MLPerf/KeywordSpotting": [128000], + "Models/MLPerf/ImageClassification": [128000], + "Models/MLPerf/AnomalyDetection": [128000], + "Models/MLPerf/VisualWakeWords": [128000], + # "Models/CCT/FP32/CCT_1_16_16_8": [128000], + # "Models/TinyViT/Demo": [8000], +} + +L3_SINGLEBUFFER_MODELS = { + "Models/CNN_Linear2": [45000, 30000, 16000], + "Models/miniMobileNet": [60000, 12000, 6000], + "Models/miniMobileNetv2": [60000, 16000, 12000, 8000], + "Kernels/Integer/Attention": [60000, 10000, 5000, 2500], + "Models/Transformer": [60000, 30000, 15000], + "Models/microLlama/INT8/microLlama1": [60000, 10000, 5000], + # "Models/CCT/FP32/CCT_2_32_32_128": [128000], + # "Models/CCT_Train/CCT2_FT2": [128000], + # "Models/TinyViT/Demo": [4000], +} + +L3_DOUBLEBUFFER_MODELS = { + "Models/CNN_Linear2": [60000, 45000, 30000], + "Models/miniMobileNet": [60000, 24000, 12000, 6000], + "Models/miniMobileNetv2": [60000, 32000, 24000, 16000], + "Kernels/Integer/Attention": [60000, 20000, 10000, 5000], + "Models/Transformer": [60000, 30000, 15000], + "Models/microLlama/INT8/microLlama1": [60000, 20000, 10000], + "Models/microLlama/INT8/microLlama8": [60000, 20000, 10000], + "Models/microLlama/INT8/microLlama8_parallel": [60000, 20000, 10000], + # "Models/CCT/FP32/CCT_2_32_32_128": [128000], + # "Models/CCT_Train/CCT2_FT2": [128000], + "Models/TinyViT/Demo": [4000], +} diff --git a/Makefile b/Makefile index 0ca5c70263..f2a3e56095 100644 --- a/Makefile +++ b/Makefile @@ -43,13 +43,13 @@ GAP9_SDK_INSTALL_DIR ?= ${DEEPLOY_INSTALL_DIR}/gap9-sdk CMAKE ?= cmake -LLVM_COMMIT_HASH ?= 1ccb97ef1789b8c574e3fcab0de674e11b189b96 +LLVM_COMMIT_HASH ?= 6547028f925c4f27f5ff2ae40c3e901bacf886e4 PICOLIBC_COMMIT_HASH ?= 31ff1b3601b379e4cab63837f253f59729ce1fef -PULP_SDK_COMMIT_HASH ?= 7f4f22516157a1b7c55bcbbc72ca81326180b3b4 +PULP_SDK_COMMIT_HASH ?= 894a13eb62eaa8d00c9f7c39d1d8ff98d9c03211 MEMPOOL_COMMIT_HASH ?= affd45d94e05e375a6966af6a762deeb182a7bd6 SNITCH_COMMIT_HASH ?= e02cc9e3f24b92d4607455d5345caba3eb6273b2 SOFTHIER_COMMIT_HASH ?= 0 # bowwang: to be updated -GVSOC_COMMIT_HASH ?= edfcd8398840ceb1e151711befa06678b05f06a0 +GVSOC_COMMIT_HASH ?= fa24884d164daef0e946cdb8653f28d8af4bb5ab MINIMALLOC_COMMMIT_HASH ?= e9eaf54094025e1c246f9ec231b905f8ef42a29d CHIMERA_SDK_COMMIT_HASH ?= b2392f6efcff75c03f4c65eaf3e12104442b22ea XTL_VERSION ?= 0.7.5 @@ -418,7 +418,9 @@ picolibc-riscv: ${PICOLIBC_RV32IM_INSTALL_DIR} ${PICOLIBC_RV32IMA_INSTALL_DIR} $ ${TOOLCHAIN_DIR}/pulp-sdk: cd ${TOOLCHAIN_DIR} && \ git clone https://github.com/pulp-platform/pulp-sdk.git && \ - cd ${TOOLCHAIN_DIR}/pulp-sdk && git checkout ${PULP_SDK_COMMIT_HASH} && \ + cd ${TOOLCHAIN_DIR}/pulp-sdk && \ + git fetch origin ${PULP_SDK_COMMIT_HASH} && \ + git checkout ${PULP_SDK_COMMIT_HASH} && \ git submodule update --init --recursive ${PULP_SDK_INSTALL_DIR}: ${TOOLCHAIN_DIR}/pulp-sdk @@ -468,11 +470,18 @@ ${TOOLCHAIN_DIR}/gvsoc: git clone https://github.com/gvsoc/gvsoc.git && \ cd ${TOOLCHAIN_DIR}/gvsoc && git checkout ${GVSOC_COMMIT_HASH} && \ git submodule update --init --recursive && \ - pip install -r core/requirements.txt && pip install -r gapy/requirements.txt + cd ${TOOLCHAIN_DIR}/gvsoc/pulp && git apply ${TOOLCHAIN_DIR}/gvsoc_pulp_open.patch && \ + cd ${TOOLCHAIN_DIR}/gvsoc && \ + pip install -r core/requirements.txt && pip install -r gapy/requirements.txt && \ + pip install -r gvrun/requirements.txt && pip install -r config_tree/requirements.txt ${GVSOC_INSTALL_DIR}: ${TOOLCHAIN_DIR}/gvsoc cd ${TOOLCHAIN_DIR}/gvsoc && \ - XTENSOR_INSTALL_DIR=${XTENSOR_INSTALL_DIR}/include XTL_INSTALL_DIR=${XTL_INSTALL_DIR}/include XSIMD_INSTALL_DIR=${XSIMD_INSTALL_DIR}/include make all TARGETS="pulp.snitch.snitch_cluster_single siracusa chimera" build INSTALLDIR=${GVSOC_INSTALL_DIR} + XTENSOR_INSTALL_DIR=${XTENSOR_INSTALL_DIR}/include \ + XTL_INSTALL_DIR=${XTL_INSTALL_DIR}/include \ + XSIMD_INSTALL_DIR=${XSIMD_INSTALL_DIR}/include \ + make all TARGETS="pulp.snitch.snitch_cluster_single siracusa chimera pulp-open" build \ + INSTALLDIR=${GVSOC_INSTALL_DIR} gvsoc: ${GVSOC_INSTALL_DIR} diff --git a/TargetLibraries/PULPOpen/cmake/pulp-sdk-pulp-open.cmake b/TargetLibraries/PULPOpen/cmake/pulp-sdk-pulp-open.cmake index 3ab74d58bc..420c9fba0e 100644 --- a/TargetLibraries/PULPOpen/cmake/pulp-sdk-pulp-open.cmake +++ b/TargetLibraries/PULPOpen/cmake/pulp-sdk-pulp-open.cmake @@ -7,6 +7,7 @@ include(cmake/pulp-sdk-base.cmake) set(PULP_SDK_HOME $ENV{PULP_SDK_HOME}) set(PULP_OPEN_COMPILE_FLAGS + -include ${PULP_SDK_HOME}/rtos/pulpos/pulp/include/pos/chips/pulp/config.h -DCONFIG_PULP -DCONFIG_BOARD_VERSION_PULP -DCONFIG_PROFILE_PULP diff --git a/toolchain/gvsoc_pulp_open.patch b/toolchain/gvsoc_pulp_open.patch new file mode 100644 index 0000000000..be3f385902 --- /dev/null +++ b/toolchain/gvsoc_pulp_open.patch @@ -0,0 +1,135 @@ +diff --git a/pulp/chips/pulp_open/cluster.json b/pulp/chips/pulp_open/cluster.json +index dc157e8..7c8380e 100644 +--- a/pulp/chips/pulp_open/cluster.json ++++ b/pulp/chips/pulp_open/cluster.json +@@ -13,7 +13,7 @@ + "first_external_pcer": 12, + "riscv_dbg_unit": true, + "debug_binaries": [], +- "debug_handler" : "0x1a190800", ++ "debug_handler" : "0x1a110800", + "power_models_file": "pulp/chips/pulp_open/power_models/core/riscy.json" + }, + +@@ -38,12 +38,12 @@ + "l1": { + "mapping": { + "base": "0x10000000", +- "size": "0x00010000", ++ "size": "0x00040000", + "remove_offset": "0x10000000" + }, + "ts_mapping": { + "base": "0x10100000", +- "size": "0x00010000", ++ "size": "0x00040000", + "remove_offset": "0x10100000" + }, + "banking_factor": 2, +@@ -173,7 +173,7 @@ + + "dma": { + "version": 7, +- "kind": "mchan", ++ "kind": "idma", + "nb_tcdm_banks": 2, + "mapping": { + "base": "0x10201800", +@@ -209,4 +209,4 @@ + } + } + } +-} +\ No newline at end of file ++} +diff --git a/pulp/chips/pulp_open/l2_subsystem.py b/pulp/chips/pulp_open/l2_subsystem.py +index ca58304..a03c081 100644 +--- a/pulp/chips/pulp_open/l2_subsystem.py ++++ b/pulp/chips/pulp_open/l2_subsystem.py +@@ -25,14 +25,14 @@ class L2SharedAttr(Tree): + def __init__(self, parent, name): + super().__init__(parent, name) + self.nb_banks = Value(self, 'nb_banks', 4) +- self.nb_regions = Value(self, 'nb_regions', 12) ++ self.nb_regions = Value(self, 'nb_regions', 4) + self.interleaving_bits = Value(self, 'interleaving_bits', 2) +- self.range = Area(self, 'range', 0x1C010000, 0x00180000, description='L2 shared banks') ++ self.range = Area(self, 'range', 0x1C010000, 0x00080000, description='L2 shared banks') + + class L2Attr(Tree): + def __init__(self, parent, name): + super().__init__(parent, name) +- self.range = Area(self, 'range', 0x1C000000, 0x00190000, description='L2 whole address range') ++ self.range = Area(self, 'range', 0x1C000000, 0x00090000, description='L2 whole address range') + self.priv0 = Area(self, 'priv0', 0x1C000000, 0x00008000, description='L2 private bank 0') + self.priv1 = Area(self, 'priv1', 0x1C008000, 0x00008000, description='L2 private bank 1') + self.shared = L2SharedAttr(self, 'shared') +diff --git a/pulp/chips/pulp_open/soc.json b/pulp/chips/pulp_open/soc.json +index 8f7f6e3..68678d5 100644 +--- a/pulp/chips/pulp_open/soc.json ++++ b/pulp/chips/pulp_open/soc.json +@@ -21,7 +21,7 @@ + + "l2": { + "base": "0x1C000000", +- "size": "0x00190000", ++ "size": "0x00090000", + + "priv0": { + "mapping": { +@@ -48,11 +48,11 @@ + + "shared": { + "nb_banks" : 4, +- "nb_regions" : 12, ++ "nb_regions" : 4, + "interleaving_bits" : 2, + "mapping": { + "base" : "0x1C010000", +- "size" : "0x00180000" ++ "size" : "0x00080000" + } + }, + "xip": { +@@ -156,15 +156,15 @@ + }, + + "fc_dbg_unit": { +- "base" : "0x1A190000", ++ "base" : "0x1A110000", + "size" : "0x00000800", +- "remove_offset" : "0x1A190000" ++ "remove_offset" : "0x1A110000" + }, + + "debug_rom": { +- "base" : "0x1A190800", ++ "base" : "0x1A110800", + "size" : "0x00000800", +- "remove_offset" : "0x1A190800" ++ "remove_offset" : "0x1A110800" + } + + } +@@ -198,7 +198,7 @@ + "has_jtag_reg" : true, + "config": { + "nb_harts": 10, +- "nb_l2_shared_banks": 12 ++ "nb_l2_shared_banks": 4 + } + }, + +diff --git a/pulp/cpu/iss/pulp_cores.py b/pulp/cpu/iss/pulp_cores.py +index e83549b..6e7f650 100644 +--- a/pulp/cpu/iss/pulp_cores.py ++++ b/pulp/cpu/iss/pulp_cores.py +@@ -70,7 +70,7 @@ class PulpCore(cpu.iss.riscv.RiscvCommon): + + super().__init__(parent, name, isa=isa, + riscv_dbg_unit=True, fetch_enable=fetch_enable, boot_addr=boot_addr, +- first_external_pcer=12, debug_handler=0x1a190800, misa=0x40000000, core="ri5ky", ++ first_external_pcer=12, debug_handler=0x1a110800, misa=0x40000000, core="ri5ky", + cluster_id=cluster_id, core_id=core_id, wrapper="pulp/cpu/iss/pulp_iss_wrapper.cpp", + scoreboard=True, timed=True, handle_misaligned=True, external_pccr=external_pccr) + From 4862c8a1fcd8d52fe5204fa5d3c8a4e8ae1ebdc4 Mon Sep 17 00:00:00 2001 From: marchioa Date: Mon, 26 Oct 2026 14:06:41 +0000 Subject: [PATCH 03/18] add missing includes --- DeeployTest/Platforms/PULPOpen/src/deeploytest.c | 1 + TargetLibraries/PULPOpen/inc/DeeployPULPMath.h | 2 ++ 2 files changed, 3 insertions(+) diff --git a/DeeployTest/Platforms/PULPOpen/src/deeploytest.c b/DeeployTest/Platforms/PULPOpen/src/deeploytest.c index a148c09785..80614d8846 100644 --- a/DeeployTest/Platforms/PULPOpen/src/deeploytest.c +++ b/DeeployTest/Platforms/PULPOpen/src/deeploytest.c @@ -10,6 +10,7 @@ #include "pmsis.h" #include "testinputs.h" #include "testoutputs.h" +#include #define MAINSTACKSIZE 8000 #define SLAVESTACKSIZE 3800 diff --git a/TargetLibraries/PULPOpen/inc/DeeployPULPMath.h b/TargetLibraries/PULPOpen/inc/DeeployPULPMath.h index 64a5ca24ba..29b7951d08 100644 --- a/TargetLibraries/PULPOpen/inc/DeeployPULPMath.h +++ b/TargetLibraries/PULPOpen/inc/DeeployPULPMath.h @@ -31,10 +31,12 @@ #include "kernel/PULPDWConv3x3.h" #include "kernel/PULPPWConv1x1.h" #include "kernel/PULPStemConv3x3.h" +#include "kernel/Relu.h" #include "kernel/RQiHardswish.h" #include "kernel/RequantShift.h" #include "kernel/Softmax.h" #include "kernel/UniformRequantShift.h" +#include "kernel/gemm.h" #include "kernel/gemv.h" #include "kernel/iRMSnorm.h" From b88d6afe4dac39a872d7e8ab3f146539949cf3b6 Mon Sep 17 00:00:00 2001 From: marchioa Date: Wed, 28 Oct 2026 11:57:48 +0000 Subject: [PATCH 04/18] minor fixes --- Deeploy/Targets/PULPOpen/DMA/iDMA.py | 5 +++-- DeeployTest/testUtils/pytestRunner.py | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/Deeploy/Targets/PULPOpen/DMA/iDMA.py b/Deeploy/Targets/PULPOpen/DMA/iDMA.py index cc026cbb17..1487b30ebe 100644 --- a/Deeploy/Targets/PULPOpen/DMA/iDMA.py +++ b/Deeploy/Targets/PULPOpen/DMA/iDMA.py @@ -22,10 +22,11 @@ class iDMA(AsyncDma): _transferTemplates = { 1: - NodeTemplate("pulp_idma_transfer_1d_and_wait(${direction}, ${ext}, ${loc}, ${length});"), + NodeTemplate( + "pulp_idma_transfer_1d_and_wait(${direction}, (unsigned int)${ext}, (unsigned int)${loc}, ${length});"), 2: NodeTemplate( - "pulp_idma_transfer_2d_and_wait(${direction}, ${ext}, ${loc}, ${length}, ${strideExt}, ${strideLoc}, ${num_reps});" + "pulp_idma_transfer_2d_and_wait(${direction}, (unsigned int)${ext}, (unsigned int)${loc}, ${length}, ${strideExt}, ${strideLoc}, ${num_reps});" ) } _waitingStrategy = DirectionWaitingStrategy(iDMAChannelFuture, "channel_id") diff --git a/DeeployTest/testUtils/pytestRunner.py b/DeeployTest/testUtils/pytestRunner.py index 6d1893459c..79cae7550b 100644 --- a/DeeployTest/testUtils/pytestRunner.py +++ b/DeeployTest/testUtils/pytestRunner.py @@ -75,7 +75,7 @@ def create_test_config( # Always pass the DMA on PULPOpen so a cached PULP_DMA from a previous run cannot leak in if platform == "PULPOpen": - dma = dma or "mchan" + dma = dma or "idma" gen_args_list.append(f"--dma={dma}") cmake_args_list.append(f"PULP_DMA={dma.upper()}") From 423116afe1ce17f259c77868d728e6d928b9ebbe Mon Sep 17 00:00:00 2001 From: marchioa Date: Wed, 28 Oct 2026 11:58:47 +0000 Subject: [PATCH 05/18] enable FP32 tests for pulpopen --- DeeployTest/test_pulpopen_config.py | 64 +++++------ DeeployTest/test_pulpopen_tiled_config.py | 132 +++++++++++----------- 2 files changed, 98 insertions(+), 98 deletions(-) diff --git a/DeeployTest/test_pulpopen_config.py b/DeeployTest/test_pulpopen_config.py index 6ccf7d2750..be462af831 100644 --- a/DeeployTest/test_pulpopen_config.py +++ b/DeeployTest/test_pulpopen_config.py @@ -7,44 +7,44 @@ DEFAULT_CORES = 8 KERNEL_TESTS = [ - # "Kernels/FP32/ReLU", - # "Kernels/FP32/Softmax/CrossEntropy", - # "Kernels/FP32/Softmax/CrossEntropyGrad", - # "Kernels/FP32/Softmax/Grad", - # "Kernels/FP32/Softmax/Regular", - # "Kernels/FP32/Add/Regular", - # "Kernels/FP32/Conv/DW_2D_Bias", - # "Kernels/FP32/Conv/DW_2D_NoBias", - # "Kernels/FP32/Conv/DW_2D_ZeroValuedBias", - # "Kernels/FP32/Conv/Regular_2D_Bias", - # "Kernels/FP32/Conv/Regular_2D_NoBias", - # "Kernels/FP32/Conv/Regular_2D_ZeroValuedBias", - # "Kernels/FP32/GEMM/Regular", - # "Kernels/FP32/MatMul", - # "Kernels/FP32/MaxPool/Regular_2D", - # "Kernels/FP32/Mul/Regular", - # "Kernels/FP32/LayerNorm", + "Kernels/FP32/ReLU", + "Kernels/FP32/Softmax/CrossEntropy", + "Kernels/FP32/Softmax/CrossEntropyGrad", + "Kernels/FP32/Softmax/Grad", + "Kernels/FP32/Softmax/Regular", + "Kernels/FP32/Add/Regular", + "Kernels/FP32/Conv/DW_2D_Bias", + "Kernels/FP32/Conv/DW_2D_NoBias", + "Kernels/FP32/Conv/DW_2D_ZeroValuedBias", + # "Kernels/FP32/Conv/Regular_2D_Bias", # LLVM HW-loop bug + # "Kernels/FP32/Conv/Regular_2D_NoBias", # LLVM HW-loop bug + # "Kernels/FP32/Conv/Regular_2D_ZeroValuedBias", # LLVM HW-loop bug + "Kernels/FP32/GEMM/Regular", + "Kernels/FP32/MatMul", + "Kernels/FP32/MaxPool/Regular_2D", + "Kernels/FP32/Mul/Regular", + "Kernels/FP32/LayerNorm", # "Kernels/FP32/ReduceMean/KeepDims/Add_ReduceMean", # "Kernels/FP32/ReduceMean/KeepDims/Add_ReduceMean_Add", - # "Kernels/FP32/ReduceMean/KeepDims/AllAxes", - # "Kernels/FP32/ReduceMean/KeepDims/Axes1_2_3", - # "Kernels/FP32/ReduceMean/KeepDims/Axes1_3", - # "Kernels/FP32/ReduceMean/KeepDims/Axes2_1", + "Kernels/FP32/ReduceMean/KeepDims/AllAxes", + "Kernels/FP32/ReduceMean/KeepDims/Axes1_2_3", + "Kernels/FP32/ReduceMean/KeepDims/Axes1_3", + "Kernels/FP32/ReduceMean/KeepDims/Axes2_1", # "Kernels/FP32/ReduceMean/KeepDims/Axis0", - # "Kernels/FP32/ReduceMean/KeepDims/Axis2", + "Kernels/FP32/ReduceMean/KeepDims/Axis2", # "Kernels/FP32/ReduceMean/KeepDims/ReduceMean_Add", # "Kernels/FP32/ReduceMean/NoKeepDims/Add_ReduceMean", # "Kernels/FP32/ReduceMean/NoKeepDims/Add_ReduceMean_Add", - # "Kernels/FP32/ReduceMean/NoKeepDims/AllAxes", - # "Kernels/FP32/ReduceMean/NoKeepDims/Axes1_2_3", - # "Kernels/FP32/ReduceMean/NoKeepDims/Axes1_3", - # "Kernels/FP32/ReduceMean/NoKeepDims/Axes2_1", + "Kernels/FP32/ReduceMean/NoKeepDims/AllAxes", + "Kernels/FP32/ReduceMean/NoKeepDims/Axes1_2_3", + "Kernels/FP32/ReduceMean/NoKeepDims/Axes1_3", + "Kernels/FP32/ReduceMean/NoKeepDims/Axes2_1", # "Kernels/FP32/ReduceMean/NoKeepDims/Axis0", - # "Kernels/FP32/ReduceMean/NoKeepDims/Axis2", + "Kernels/FP32/ReduceMean/NoKeepDims/Axis2", # "Kernels/FP32/ReduceMean/NoKeepDims/ReduceMean_Add", - # "Kernels/FP32/ReduceSum", - # "Kernels/FP32/Reshape/SkipConnection", - # "Kernels/FP32/Transpose", + "Kernels/FP32/ReduceSum", + "Kernels/FP32/Reshape/SkipConnection", + "Kernels/FP32/Transpose", "Kernels/Integer/Hardswish/Regular", "Kernels/Integer/Softmax/Regular", "Kernels/Integer/Add/MultIO", @@ -68,13 +68,13 @@ MODEL_TESTS = [ "Kernels/Integer/Attention", - # "Models/CCT/FP32/CCT_1_16_16_8", + # "Models/CCT/FP32/CCT_1_16_16_8", # LLVM HW-loop bug # "Models/CCT/FP32/CCT_2_32_32_128_Opset20", "Models/miniMobileNet", "Models/miniMobileNetv2", "Models/MLPerf/KeywordSpotting", "Models/MLPerf/ImageClassification", "Models/MLPerf/AnomalyDetection", - # "Models/TinyViT/Demo", + "Models/TinyViT/Demo", "Models/CNN_Linear2", ] diff --git a/DeeployTest/test_pulpopen_tiled_config.py b/DeeployTest/test_pulpopen_tiled_config.py index 06f679ac8e..6540b8c9be 100644 --- a/DeeployTest/test_pulpopen_tiled_config.py +++ b/DeeployTest/test_pulpopen_tiled_config.py @@ -10,40 +10,40 @@ DEFAULT_SEARCH_STRATEGY = "random-max" L2_SINGLEBUFFER_KERNELS = { - # "Kernels/FP32/ReLU": [2000], - # "Kernels/FP32/Softmax/Regular": [4000], - # "Kernels/FP32/Add/Large": [220000], - # "Kernels/FP32/Conv/DW_2D_Bias": [7200], - # "Kernels/FP32/Conv/DW_2D_NoBias": [7200], - # "Kernels/FP32/Conv/DW_2D_ZeroValuedBias": [7200], - # "Kernels/FP32/Conv/Regular_2D_Bias": [6600], - # "Kernels/FP32/Conv/Regular_2D_NoBias": [1600], - # "Kernels/FP32/Conv/Regular_2D_ZeroValuedBias": [6600], - # "Kernels/FP32/GEMM/Regular": [8000], - # "Kernels/FP32/MatMul": [2000], - # "Kernels/FP32/MaxPool/Regular_2D": [2000], - # "Kernels/FP32/Mul/Regular": [2000], - # "Kernels/FP32/LayerNorm": [2000], + "Kernels/FP32/ReLU": [2000], + "Kernels/FP32/Softmax/Regular": [4000], + # "Kernels/FP32/Add/Large": [220000], # issue with iDMA 16-bit transfer size + "Kernels/FP32/Conv/DW_2D_Bias": [7200], + "Kernels/FP32/Conv/DW_2D_NoBias": [7200], + "Kernels/FP32/Conv/DW_2D_ZeroValuedBias": [7200], + # "Kernels/FP32/Conv/Regular_2D_Bias": [6600], # LLVM HW-loop bug + # "Kernels/FP32/Conv/Regular_2D_NoBias": [1600], # LLVM HW-loop bug + # "Kernels/FP32/Conv/Regular_2D_ZeroValuedBias": [6600], # LLVM HW-loop bug + "Kernels/FP32/GEMM/Regular": [8000], + "Kernels/FP32/MatMul": [2000], + "Kernels/FP32/MaxPool/Regular_2D": [2000], + "Kernels/FP32/Mul/Regular": [2000], + "Kernels/FP32/LayerNorm": [2000], # "Kernels/FP32/ReduceMean/KeepDims/Add_ReduceMean": [8000], # "Kernels/FP32/ReduceMean/KeepDims/Add_ReduceMean_Add": [8000], - # "Kernels/FP32/ReduceMean/KeepDims/AllAxes": [50000], - # "Kernels/FP32/ReduceMean/KeepDims/Axes1_2_3": [50000], - # "Kernels/FP32/ReduceMean/KeepDims/Axes1_3": [5000, 50000], - # "Kernels/FP32/ReduceMean/KeepDims/Axes2_1": [6200, 50000], + "Kernels/FP32/ReduceMean/KeepDims/AllAxes": [50000], + "Kernels/FP32/ReduceMean/KeepDims/Axes1_2_3": [50000], + "Kernels/FP32/ReduceMean/KeepDims/Axes1_3": [5000, 50000], + "Kernels/FP32/ReduceMean/KeepDims/Axes2_1": [6200, 50000], # "Kernels/FP32/ReduceMean/KeepDims/Axis0": [8400, 50000], - # "Kernels/FP32/ReduceMean/KeepDims/Axis2": [8400, 50000], + "Kernels/FP32/ReduceMean/KeepDims/Axis2": [8400, 50000], # "Kernels/FP32/ReduceMean/KeepDims/ReduceMean_Add": [8000], # "Kernels/FP32/ReduceMean/NoKeepDims/Add_ReduceMean": [8000], # "Kernels/FP32/ReduceMean/NoKeepDims/Add_ReduceMean_Add": [8000], - # "Kernels/FP32/ReduceMean/NoKeepDims/AllAxes": [50000], - # "Kernels/FP32/ReduceMean/NoKeepDims/Axes1_2_3": [50000], - # "Kernels/FP32/ReduceMean/NoKeepDims/Axes1_3": [5000, 50000], - # "Kernels/FP32/ReduceMean/NoKeepDims/Axes2_1": [6200, 50000], + "Kernels/FP32/ReduceMean/NoKeepDims/AllAxes": [50000], + "Kernels/FP32/ReduceMean/NoKeepDims/Axes1_2_3": [50000], + "Kernels/FP32/ReduceMean/NoKeepDims/Axes1_3": [5000, 50000], + "Kernels/FP32/ReduceMean/NoKeepDims/Axes2_1": [6200, 50000], # "Kernels/FP32/ReduceMean/NoKeepDims/Axis0": [8400, 50000], - # "Kernels/FP32/ReduceMean/NoKeepDims/Axis2": [8400, 50000], + "Kernels/FP32/ReduceMean/NoKeepDims/Axis2": [8400, 50000], # "Kernels/FP32/ReduceMean/NoKeepDims/ReduceMean_Add": [8000], - # "Kernels/FP32/Reshape/SkipConnection": [1400], - # "Kernels/FP32/Transpose": [2000], + "Kernels/FP32/Reshape/SkipConnection": [1400], + "Kernels/FP32/Transpose": [2000], "Kernels/Integer/Hardswish/Regular": [750], "Kernels/Integer/Softmax/Regular": [800, 500, 300], "Kernels/Integer/Concat": [32000, 16000, 8000], @@ -58,39 +58,39 @@ } L2_DOUBLEBUFFER_KERNELS = { - # "Kernels/FP32/ReLU": [20], - # "Kernels/FP32/Softmax/Regular": [8000], - # "Kernels/FP32/Conv/DW_2D_Bias": [10000], - # "Kernels/FP32/Conv/DW_2D_NoBias": [9800], - # "Kernels/FP32/Conv/DW_2D_ZeroValuedBias": [9800], - # "Kernels/FP32/Conv/Regular_2D_Bias": [8800], - # "Kernels/FP32/Conv/Regular_2D_NoBias": [2000], - # "Kernels/FP32/Conv/Regular_2D_ZeroValuedBias": [8800], - # "Kernels/FP32/GEMM/Regular": [8000], - # "Kernels/FP32/MatMul": [5000], - # "Kernels/FP32/MaxPool/Regular_2D": [5000], - # "Kernels/FP32/Mul/Regular": [2000], - # "Kernels/FP32/LayerNorm": [2000], + "Kernels/FP32/ReLU": [20], + "Kernels/FP32/Softmax/Regular": [8000], + "Kernels/FP32/Conv/DW_2D_Bias": [10000], + "Kernels/FP32/Conv/DW_2D_NoBias": [9800], + "Kernels/FP32/Conv/DW_2D_ZeroValuedBias": [9800], + # "Kernels/FP32/Conv/Regular_2D_Bias": [8800], # LLVM HW-loop bug + # "Kernels/FP32/Conv/Regular_2D_NoBias": [2000], # LLVM HW-loop bug + # "Kernels/FP32/Conv/Regular_2D_ZeroValuedBias": [8800], # LLVM HW-loop bug + "Kernels/FP32/GEMM/Regular": [8000], + "Kernels/FP32/MatMul": [5000], + "Kernels/FP32/MaxPool/Regular_2D": [5000], + "Kernels/FP32/Mul/Regular": [2000], + "Kernels/FP32/LayerNorm": [2000], # "Kernels/FP32/ReduceMean/KeepDims/Add_ReduceMean": [8000], # "Kernels/FP32/ReduceMean/KeepDims/Add_ReduceMean_Add": [8000], - # "Kernels/FP32/ReduceMean/KeepDims/AllAxes": [100000], - # "Kernels/FP32/ReduceMean/KeepDims/Axes1_2_3": [100000], - # "Kernels/FP32/ReduceMean/KeepDims/Axes1_3": [10000, 50000], - # "Kernels/FP32/ReduceMean/KeepDims/Axes2_1": [13000, 50000], + "Kernels/FP32/ReduceMean/KeepDims/AllAxes": [100000], + "Kernels/FP32/ReduceMean/KeepDims/Axes1_2_3": [100000], + "Kernels/FP32/ReduceMean/KeepDims/Axes1_3": [10000, 50000], + "Kernels/FP32/ReduceMean/KeepDims/Axes2_1": [13000, 50000], # "Kernels/FP32/ReduceMean/KeepDims/Axis0": [17000, 50000], - # "Kernels/FP32/ReduceMean/KeepDims/Axis2": [17000, 50000], + "Kernels/FP32/ReduceMean/KeepDims/Axis2": [17000, 50000], # "Kernels/FP32/ReduceMean/KeepDims/ReduceMean_Add": [8000], # "Kernels/FP32/ReduceMean/NoKeepDims/Add_ReduceMean": [8000], # "Kernels/FP32/ReduceMean/NoKeepDims/Add_ReduceMean_Add": [8000], - # "Kernels/FP32/ReduceMean/NoKeepDims/AllAxes": [100000], - # "Kernels/FP32/ReduceMean/NoKeepDims/Axes1_2_3": [100000], - # "Kernels/FP32/ReduceMean/NoKeepDims/Axes1_3": [10000, 50000], - # "Kernels/FP32/ReduceMean/NoKeepDims/Axes2_1": [13000, 50000], + "Kernels/FP32/ReduceMean/NoKeepDims/AllAxes": [100000], + "Kernels/FP32/ReduceMean/NoKeepDims/Axes1_2_3": [100000], + "Kernels/FP32/ReduceMean/NoKeepDims/Axes1_3": [10000, 50000], + "Kernels/FP32/ReduceMean/NoKeepDims/Axes2_1": [13000, 50000], # "Kernels/FP32/ReduceMean/NoKeepDims/Axis0": [17000, 50000], - # "Kernels/FP32/ReduceMean/NoKeepDims/Axis2": [17000, 50000], + "Kernels/FP32/ReduceMean/NoKeepDims/Axis2": [17000, 50000], # "Kernels/FP32/ReduceMean/NoKeepDims/ReduceMean_Add": [8000], - # "Kernels/FP32/Reshape/SkipConnection": [2600], - # "Kernels/FP32/Transpose": [2000], + "Kernels/FP32/Reshape/SkipConnection": [2600], + "Kernels/FP32/Transpose": [2000], "Kernels/Integer/Hardswish/Regular": [750], "Kernels/Integer/Softmax/Regular": [1600, 1000, 600], "Kernels/Integer/Concat": [64000, 32000, 16000], @@ -106,15 +106,15 @@ "Models/miniMobileNet": [60000, 12000, 6000, 3000], "Models/miniMobileNetv2": [60000, 16000, 12000, 8000], "Kernels/Integer/Attention": [60000, 10000, 5000], - "Models/microLlama/INT8/microLlama1": [60000, 10000, 5000], - "Models/microLlama/INT8/microLlama8": [60000, 10000, 5000], - "Models/microLlama/INT8/microLlama8_parallel": [60000, 10000, 5000], + # "Models/microLlama/INT8/microLlama1": [60000, 10000, 5000], + # "Models/microLlama/INT8/microLlama8": [60000, 10000, 5000], + # "Models/microLlama/INT8/microLlama8_parallel": [60000, 10000, 5000], "Models/MLPerf/KeywordSpotting": [64000], "Models/MLPerf/ImageClassification": [64000], "Models/MLPerf/AnomalyDetection": [64000], "Models/MLPerf/VisualWakeWords": [64000], - # "Models/CCT/FP32/CCT_1_16_16_8": [64000], - # "Models/TinyViT/Demo": [4000], + # "Models/CCT/FP32/CCT_1_16_16_8": [64000], # LLVM HW-loop bug + "Models/TinyViT/Demo": [4000], } L2_DOUBLEBUFFER_MODELS = { @@ -122,15 +122,15 @@ "Models/miniMobileNet": [60000, 24000, 12000, 6000], "Models/miniMobileNetv2": [60000, 32000, 24000, 16000], "Kernels/Integer/Attention": [60000, 20000, 10000, 5000], - "Models/microLlama/INT8/microLlama1": [60000, 20000, 10000], - "Models/microLlama/INT8/microLlama8": [60000, 20000, 10000], - "Models/microLlama/INT8/microLlama8_parallel": [60000, 20000, 10000], + # "Models/microLlama/INT8/microLlama1": [60000, 20000, 10000], + # "Models/microLlama/INT8/microLlama8": [60000, 20000, 10000], + # "Models/microLlama/INT8/microLlama8_parallel": [60000, 20000, 10000], "Models/MLPerf/KeywordSpotting": [128000], "Models/MLPerf/ImageClassification": [128000], "Models/MLPerf/AnomalyDetection": [128000], "Models/MLPerf/VisualWakeWords": [128000], - # "Models/CCT/FP32/CCT_1_16_16_8": [128000], - # "Models/TinyViT/Demo": [8000], + # "Models/CCT/FP32/CCT_1_16_16_8": [128000], # LLVM HW-loop bug + "Models/TinyViT/Demo": [8000], } L3_SINGLEBUFFER_MODELS = { @@ -140,9 +140,9 @@ "Kernels/Integer/Attention": [60000, 10000, 5000, 2500], "Models/Transformer": [60000, 30000, 15000], "Models/microLlama/INT8/microLlama1": [60000, 10000, 5000], - # "Models/CCT/FP32/CCT_2_32_32_128": [128000], - # "Models/CCT_Train/CCT2_FT2": [128000], - # "Models/TinyViT/Demo": [4000], + "Models/CCT/FP32/CCT_2_32_32_128": [128000], + "Models/CCT_Train/CCT2_FT2": [128000], + "Models/TinyViT/Demo": [4000], } L3_DOUBLEBUFFER_MODELS = { @@ -154,7 +154,7 @@ "Models/microLlama/INT8/microLlama1": [60000, 20000, 10000], "Models/microLlama/INT8/microLlama8": [60000, 20000, 10000], "Models/microLlama/INT8/microLlama8_parallel": [60000, 20000, 10000], - # "Models/CCT/FP32/CCT_2_32_32_128": [128000], - # "Models/CCT_Train/CCT2_FT2": [128000], + "Models/CCT/FP32/CCT_2_32_32_128": [128000], + "Models/CCT_Train/CCT2_FT2": [128000], "Models/TinyViT/Demo": [4000], } From 8c302ad6c1dc774f91cd9c8d8e8ef8ea619e0e76 Mon Sep 17 00:00:00 2001 From: marchioa Date: Wed, 28 Oct 2026 11:59:56 +0000 Subject: [PATCH 06/18] add LLVM patch for zfinx --- Makefile | 17 ++- cmake/pulp/toolchain_llvm.cmake | 24 +++- .../meson-build-script-rv32imc_zfinx.txt | 19 +++ toolchain/pulp-llvm-crash-fixes.patch | 119 ++++++++++++++++++ 4 files changed, 171 insertions(+), 8 deletions(-) create mode 100644 toolchain/meson-build-script-rv32imc_zfinx.txt create mode 100644 toolchain/pulp-llvm-crash-fixes.patch diff --git a/Makefile b/Makefile index f2a3e56095..108f969658 100644 --- a/Makefile +++ b/Makefile @@ -23,6 +23,7 @@ PICOLIBC_RV32IMC_INSTALL_DIR ?= ${LLVM_INSTALL_DIR}/picolibc/riscv/rv32imc PICOLIBC_RV32IMA_INSTALL_DIR ?= ${LLVM_INSTALL_DIR}/picolibc/riscv/rv32ima PICOLIBC_RV32IMAFD_INSTALL_DIR ?= ${LLVM_INSTALL_DIR}/picolibc/riscv/rv32imafd PICOLIBC_RV32IMF_INSTALL_DIR ?= ${LLVM_INSTALL_DIR}/picolibc/riscv/rv32imf +PICOLIBC_RV32IMC_ZFINX_INSTALL_DIR ?= ${LLVM_INSTALL_DIR}/picolibc/riscv/rv32imc_zfinx GCC_INSTALL_DIR ?= ${DEEPLOY_INSTALL_DIR}/gcc GAP_RISCV_GCC_INSTALL_DIR ?= ${GCC_INSTALL_DIR}/gap9 @@ -117,7 +118,8 @@ ${TOOLCHAIN_DIR}/llvm-project: git remote add origin https://github.com/pulp-platform/llvm-project.git && \ git fetch --depth=1 origin ${LLVM_COMMIT_HASH} && \ git checkout ${LLVM_COMMIT_HASH} && \ - git submodule update --init --recursive + git submodule update --init --recursive && \ + git apply ${TOOLCHAIN_DIR}/pulp-llvm-crash-fixes.patch ${LLVM_INSTALL_DIR}: ${TOOLCHAIN_DIR}/llvm-project cd ${TOOLCHAIN_DIR}/llvm-project && \ @@ -413,7 +415,18 @@ ${PICOLIBC_RV32IMF_INSTALL_DIR}: ${TOOLCHAIN_DIR}/picolibc --cross-file ../scripts/meson-build-script-rv32imf.txt && \ PATH=${LLVM_INSTALL_DIR}/bin:${PATH} meson install -picolibc-riscv: ${PICOLIBC_RV32IM_INSTALL_DIR} ${PICOLIBC_RV32IMA_INSTALL_DIR} ${PICOLIBC_RV32IMC_INSTALL_DIR} ${PICOLIBC_RV32IMAFD_INSTALL_DIR} ${PICOLIBC_RV32IMF_INSTALL_DIR} +${PICOLIBC_RV32IMC_ZFINX_INSTALL_DIR}: ${TOOLCHAIN_DIR}/picolibc + cd ${TOOLCHAIN_DIR}/picolibc && mkdir -p build-rv32imc_zfinx && cd build-rv32imc_zfinx && \ + cp ${TOOLCHAIN_DIR}/meson-build-script-rv32imc_zfinx.txt ../scripts && \ + PATH=${LLVM_INSTALL_DIR}/bin:${PATH} meson setup --reconfigure -Dincludedir=include \ + -Dlibdir=lib \ + -Dspecsdir=none \ + -Dmultilib=false \ + --prefix ${PICOLIBC_RV32IMC_ZFINX_INSTALL_DIR} \ + --cross-file ../scripts/meson-build-script-rv32imc_zfinx.txt && \ + PATH=${LLVM_INSTALL_DIR}/bin:${PATH} meson install + +picolibc-riscv: ${PICOLIBC_RV32IM_INSTALL_DIR} ${PICOLIBC_RV32IMA_INSTALL_DIR} ${PICOLIBC_RV32IMC_INSTALL_DIR} ${PICOLIBC_RV32IMAFD_INSTALL_DIR} ${PICOLIBC_RV32IMF_INSTALL_DIR} ${PICOLIBC_RV32IMC_ZFINX_INSTALL_DIR} ${TOOLCHAIN_DIR}/pulp-sdk: cd ${TOOLCHAIN_DIR} && \ diff --git a/cmake/pulp/toolchain_llvm.cmake b/cmake/pulp/toolchain_llvm.cmake index cf3fb80d6c..4767648558 100644 --- a/cmake/pulp/toolchain_llvm.cmake +++ b/cmake/pulp/toolchain_llvm.cmake @@ -14,7 +14,19 @@ set(CMAKE_ASM_COMPILER ${TOOLCHAIN_PREFIX}/clang) set(CMAKE_OBJCOPY ${TOOLCHAIN_PREFIX}/${LLVM_TAG}-objcopy) set(CMAKE_OBJDUMP ${TOOLCHAIN_PREFIX}/${LLVM_TAG}-objdump) -set(ISA rv32imf_xpulpv2) +# PULP-Open (GVSoC pulp-open) has no separate FP register file: floats live in the +# integer registers (zfinx). compiler-rt has no zfinx build, rv32imc shares its ilp32 ABI. +if(platform STREQUAL PULPOpen) + set(ISA rv32imc_zfinx_xpulpv2) + set(ABI ilp32) + set(LIBC_ISA rv32imc_zfinx) + set(RT_ISA rv32imc) +else() + set(ISA rv32imf_xpulpv2) + set(ABI ilp32f) + set(LIBC_ISA rv32imf) + set(RT_ISA rv32imf) +endif() set(PE 8) set(FC 1) @@ -23,7 +35,7 @@ set(CMAKE_EXECUTABLE_SUFFIX ".elf") add_compile_options( -target riscv32-unknown-elf -march=${ISA} - -mabi=ilp32f + -mabi=${ABI} -ffunction-sections -fdata-sections -fomit-frame-pointer @@ -31,7 +43,7 @@ add_compile_options( -O3 -DNUM_CORES=${NUM_CORES} -MP - --sysroot=${TOOLCHAIN_INSTALL_DIR}/picolibc/riscv/rv32imf + --sysroot=${TOOLCHAIN_INSTALL_DIR}/picolibc/riscv/${LIBC_ISA} -fno-builtin-memcpy -fno-builtin-memset ) @@ -41,9 +53,9 @@ add_link_options( -MP -nostartfiles -march=${ISA} - -mabi=ilp32f - -L${TOOLCHAIN_INSTALL_DIR}/picolibc/riscv/rv32imf/lib - -L${TOOLCHAIN_INSTALL_DIR}/lib/clang/15.0.0/lib/baremetal/rv32imf/ + -mabi=${ABI} + -L${TOOLCHAIN_INSTALL_DIR}/picolibc/riscv/${LIBC_ISA}/lib + -L${TOOLCHAIN_INSTALL_DIR}/lib/clang/15.0.0/lib/baremetal/${RT_ISA}/ -z norelro -fno-builtin-memcpy -fno-builtin-memset diff --git a/toolchain/meson-build-script-rv32imc_zfinx.txt b/toolchain/meson-build-script-rv32imc_zfinx.txt new file mode 100644 index 0000000000..6347a7346a --- /dev/null +++ b/toolchain/meson-build-script-rv32imc_zfinx.txt @@ -0,0 +1,19 @@ +[binaries] +c = ['clang', '-target', 'riscv32-unknown-elf', '-march=rv32imc_zfinx', '-mabi=ilp32', '-nostdlib'] +ar = 'llvm-ar' +strip = 'llvm-strip' + +[host_machine] +system = 'none' +cpu_family = 'riscv32' +cpu = 'riscv32' +endian = 'little' + +[properties] +c_args = ['-Werror=double-promotion', '-Wno-unsupported-floating-point-opt', '-fshort-enums', '-mno-relax'] +c_link_args = ['-Wl,-z,noexecstack'] +skip_sanity_check = true +default_flash_addr = '0x00000000' +default_flash_size = '0x00400000' +default_ram_addr = '0x20000000' +default_ram_size = '0x00200000' diff --git a/toolchain/pulp-llvm-crash-fixes.patch b/toolchain/pulp-llvm-crash-fixes.patch new file mode 100644 index 0000000000..abe08ef89a --- /dev/null +++ b/toolchain/pulp-llvm-crash-fixes.patch @@ -0,0 +1,119 @@ +diff --git a/llvm/lib/Target/RISCV/PULP/PULPHardwareLoops.cpp b/llvm/lib/Target/RISCV/PULP/PULPHardwareLoops.cpp +index f42031540268..a6923c8b997a 100644 +--- a/llvm/lib/Target/RISCV/PULP/PULPHardwareLoops.cpp ++++ b/llvm/lib/Target/RISCV/PULP/PULPHardwareLoops.cpp +@@ -774,25 +774,29 @@ PULPHardwareLoops::getLoopTripCount(MachineLoop *L, + + if (InitialValue->isReg()) { + llvm::Register R = InitialValue->getReg(); +- MachineBasicBlock *DefBB = MRI->getVRegDef(R)->getParent(); +- if (!MDT->properlyDominates(DefBB, Header)) { ++ // Physical registers (e.g. X0 in a compare against zero) have no SSA ++ // definition, so getVRegDef would return null. ++ MachineInstr *DefMI = R.isVirtual() ? MRI->getVRegDef(R) : nullptr; ++ if (!DefMI || !MDT->properlyDominates(DefMI->getParent(), Header)) { + int64_t V; + if (!checkForImmediate(*InitialValue, V)) { + return nullptr; + } + } +- OldInsts.push_back(MRI->getVRegDef(R)); ++ if (DefMI) ++ OldInsts.push_back(DefMI); + } + if (EndValue->isReg()) { + llvm::Register R = EndValue->getReg(); +- MachineBasicBlock *DefBB = MRI->getVRegDef(R)->getParent(); +- if (!MDT->properlyDominates(DefBB, Header)) { ++ MachineInstr *DefMI = R.isVirtual() ? MRI->getVRegDef(R) : nullptr; ++ if (!DefMI || !MDT->properlyDominates(DefMI->getParent(), Header)) { + int64_t V; + if (!checkForImmediate(*EndValue, V)) { + return nullptr; + } + } +- OldInsts.push_back(MRI->getVRegDef(R)); ++ if (DefMI) ++ OldInsts.push_back(DefMI); + } + + return computeCount(L, InitialValue, EndValue, IVReg, IVBump, Cmp); +@@ -991,8 +995,9 @@ CountValue *PULPHardwareLoops::computeCount(MachineLoop *Loop, + // If the loop has been unrolled, we should use the original loop count + // instead of recalculating the value. This will avoid additional + // 'Add' instruction. +- const MachineInstr *EndValInstr = MRI->getVRegDef(End->getReg()); +- if (EndValInstr->getOpcode() == RISCV::ADDI && ++ const MachineInstr *EndValInstr = ++ End->getReg().isVirtual() ? MRI->getVRegDef(End->getReg()) : nullptr; ++ if (EndValInstr && EndValInstr->getOpcode() == RISCV::ADDI && + EndValInstr->getOperand(1).getSubReg() == 0 && + EndValInstr->getOperand(2).getImm() == StartV) { + DistR = EndValInstr->getOperand(1).getReg(); +@@ -1265,12 +1270,23 @@ bool PULPHardwareLoops::convertToHardwareLoop(MachineLoop *L, bool &RecL0used, + if (TripCount->isReg()) { + // There will be a use of the register inserted into the preheader, + // so make sure that the register is actually defined at that point. +- MachineInstr *TCDef = MRI->getVRegDef(TripCount->getReg()); +- MachineBasicBlock *BBDef = TCDef->getParent(); +- if (!MDT->dominates(BBDef, Preheader)) { +- LLVM_DEBUG(dbgs() << "Cannot convert to hwloop: induction register not " +- "available in preheader\n"); +- return Changed; ++ // Physical registers have no SSA definition; only the constant zero ++ // register X0 is known to be available everywhere. ++ llvm::Register TCReg = TripCount->getReg(); ++ if (!TCReg.isVirtual()) { ++ if (TCReg != RISCV::X0) { ++ LLVM_DEBUG(dbgs() << "Cannot convert to hwloop: trip count in " ++ "physical register\n"); ++ return Changed; ++ } ++ } else { ++ MachineInstr *TCDef = MRI->getVRegDef(TCReg); ++ MachineBasicBlock *BBDef = TCDef->getParent(); ++ if (!MDT->dominates(BBDef, Preheader)) { ++ LLVM_DEBUG(dbgs() << "Cannot convert to hwloop: induction register not " ++ "available in preheader\n"); ++ return Changed; ++ } + } + } + +diff --git a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp +index debc2cffa47b..cc1bf0298060 100644 +--- a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp ++++ b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp +@@ -2796,7 +2796,13 @@ InstructionCost RISCVTargetLowering::getLMULCost(MVT VT) const { + else + Cost = (LMul * DLenFactor); + } else { +- Cost = divideCeil(VT.getSizeInBits(), Subtarget.getRealMinVLen() / DLenFactor); ++ unsigned DLen = Subtarget.getRealMinVLen() / DLenFactor; ++ // Without any V extension getRealMinVLen() is 0. Return a neutral cost ++ // instead of dividing by zero (fixed PULP SIMD vectors are legal without ++ // RVV). ++ if (DLen == 0) ++ return 1; ++ Cost = divideCeil(VT.getSizeInBits(), DLen); + } + return Cost; + } +diff --git a/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp b/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp +index 416c3cb91b6c..f648f77b6a43 100644 +--- a/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp ++++ b/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp +@@ -1052,8 +1052,12 @@ InstructionCost RISCVTTIImpl::getMemoryOpCost(unsigned Opcode, Type *Src, + // Assume memory ops cost scale with the number of vector registers + // possible accessed by the instruction. Note that BasicTTI already + // handles the LT.first term for us. ++ // LMUL scaling only makes sense with RVV. With the PULP extensions small ++ // fixed vectors (v2s/v4s/v2h) are legal without any V extension; in that ++ // case getRealMinVLen() is 0 and getLMULCost would divide by zero. + if (std::pair LT = getTypeLegalizationCost(Src); +- LT.second.isVector() && CostKind != TTI::TCK_CodeSize) ++ LT.second.isVector() && CostKind != TTI::TCK_CodeSize && ++ ST->hasVInstructions()) + BaseCost *= TLI->getLMULCost(LT.second); + return Cost + BaseCost; + From f0808d8cbf53b511192ebcc7161f04825a06adbc Mon Sep 17 00:00:00 2001 From: marchioa Date: Wed, 28 Oct 2026 22:06:55 +0100 Subject: [PATCH 07/18] remove hardcoded clang version from compiler-rt paths The Makefile installed compiler-rt into a hardcoded lib/clang/15.0.0 and the toolchain files linked from the same hardcoded path. With LLVM 18 clang's resource directory is lib/clang/18, so targets relying on it (CortexM) no longer found compiler-rt. - Makefile: install compiler-rt into LLVM_CLANG_RT_DIR (default ${LLVM_INSTALL_DIR}/lib/clang/18), the only place to update on an LLVM bump - cmake/clang_resource_dir.cmake: query the resource directory from the compiler (clang -print-resource-dir) for the RISC-V toolchain files --- Makefile | 43 ++++++++++++++++-------------- cmake/chimera/toolchain_llvm.cmake | 3 ++- cmake/clang_resource_dir.cmake | 22 +++++++++++++++ cmake/mempool/toolchain_llvm.cmake | 3 ++- cmake/pulp/toolchain_llvm.cmake | 3 ++- cmake/snitch/toolchain_llvm.cmake | 3 ++- 6 files changed, 53 insertions(+), 24 deletions(-) create mode 100644 cmake/clang_resource_dir.cmake diff --git a/Makefile b/Makefile index 108f969658..d3eb9e9e5d 100644 --- a/Makefile +++ b/Makefile @@ -10,20 +10,23 @@ INSTALL_PREFIX ?= install DEEPLOY_INSTALL_DIR ?= ${ROOT_DIR}/${INSTALL_PREFIX} TOOLCHAIN_DIR := ${ROOT_DIR}/toolchain -LLVM_INSTALL_DIR ?= ${DEEPLOY_INSTALL_DIR}/llvm -LLVM_CLANG_RT_ARM ?= ${LLVM_INSTALL_DIR}/lib/clang/15.0.0/lib/baremetal/libclang_rt.builtins-armv7m.a -LLVM_CLANG_RT_RISCV_RV32IMAFD ?= ${LLVM_INSTALL_DIR}/lib/clang/15.0.0/lib/baremetal/rv32imafd/libclang_rt.builtins-riscv32.a -LLVM_CLANG_RT_RISCV_RV32IMC ?= ${LLVM_INSTALL_DIR}/lib/clang/15.0.0/lib/baremetal/rv32imc/libclang_rt.builtins-riscv32.a -LLVM_CLANG_RT_RISCV_RV32IMA ?= ${LLVM_INSTALL_DIR}/lib/clang/15.0.0/lib/baremetal/rv32ima/libclang_rt.builtins-riscv32.a -LLVM_CLANG_RT_RISCV_RV32IM ?= ${LLVM_INSTALL_DIR}/lib/clang/15.0.0/lib/baremetal/rv32im/libclang_rt.builtins-riscv32.a -LLVM_CLANG_RT_RISCV_RV32IMF ?= ${LLVM_INSTALL_DIR}/lib/clang/15.0.0/lib/baremetal/rv32imf/libclang_rt.builtins-riscv32.a -PICOLIBC_ARM_INSTALL_DIR ?= ${LLVM_INSTALL_DIR}/picolibc/arm -PICOLIBC_RV32IM_INSTALL_DIR ?= ${LLVM_INSTALL_DIR}/picolibc/riscv/rv32im -PICOLIBC_RV32IMC_INSTALL_DIR ?= ${LLVM_INSTALL_DIR}/picolibc/riscv/rv32imc -PICOLIBC_RV32IMA_INSTALL_DIR ?= ${LLVM_INSTALL_DIR}/picolibc/riscv/rv32ima -PICOLIBC_RV32IMAFD_INSTALL_DIR ?= ${LLVM_INSTALL_DIR}/picolibc/riscv/rv32imafd -PICOLIBC_RV32IMF_INSTALL_DIR ?= ${LLVM_INSTALL_DIR}/picolibc/riscv/rv32imf -PICOLIBC_RV32IMC_ZFINX_INSTALL_DIR ?= ${LLVM_INSTALL_DIR}/picolibc/riscv/rv32imc_zfinx +LLVM_INSTALL_DIR ?= ${DEEPLOY_INSTALL_DIR}/llvm +# clang resource directory, where compiler-rt is installed. Must match +# `clang -print-resource-dir` of the LLVM version above (clang >= 16: major only). +LLVM_CLANG_RT_DIR ?= ${LLVM_INSTALL_DIR}/lib/clang/18 +LLVM_CLANG_RT_ARM ?= ${LLVM_CLANG_RT_DIR}/lib/baremetal/libclang_rt.builtins-armv7m.a +LLVM_CLANG_RT_RISCV_RV32IMAFD ?= ${LLVM_CLANG_RT_DIR}/lib/baremetal/rv32imafd/libclang_rt.builtins-riscv32.a +LLVM_CLANG_RT_RISCV_RV32IMC ?= ${LLVM_CLANG_RT_DIR}/lib/baremetal/rv32imc/libclang_rt.builtins-riscv32.a +LLVM_CLANG_RT_RISCV_RV32IMA ?= ${LLVM_CLANG_RT_DIR}/lib/baremetal/rv32ima/libclang_rt.builtins-riscv32.a +LLVM_CLANG_RT_RISCV_RV32IM ?= ${LLVM_CLANG_RT_DIR}/lib/baremetal/rv32im/libclang_rt.builtins-riscv32.a +LLVM_CLANG_RT_RISCV_RV32IMF ?= ${LLVM_CLANG_RT_DIR}/lib/baremetal/rv32imf/libclang_rt.builtins-riscv32.a +PICOLIBC_ARM_INSTALL_DIR ?= ${LLVM_INSTALL_DIR}/picolibc/arm +PICOLIBC_RV32IM_INSTALL_DIR ?= ${LLVM_INSTALL_DIR}/picolibc/riscv/rv32im +PICOLIBC_RV32IMC_INSTALL_DIR ?= ${LLVM_INSTALL_DIR}/picolibc/riscv/rv32imc +PICOLIBC_RV32IMA_INSTALL_DIR ?= ${LLVM_INSTALL_DIR}/picolibc/riscv/rv32ima +PICOLIBC_RV32IMAFD_INSTALL_DIR ?= ${LLVM_INSTALL_DIR}/picolibc/riscv/rv32imafd +PICOLIBC_RV32IMF_INSTALL_DIR ?= ${LLVM_INSTALL_DIR}/picolibc/riscv/rv32imf +PICOLIBC_RV32IMC_ZFINX_INSTALL_DIR ?= ${LLVM_INSTALL_DIR}/picolibc/riscv/rv32imc_zfinx GCC_INSTALL_DIR ?= ${DEEPLOY_INSTALL_DIR}/gcc GAP_RISCV_GCC_INSTALL_DIR ?= ${GCC_INSTALL_DIR}/gap9 @@ -150,7 +153,7 @@ ${LLVM_CLANG_RT_RISCV_RV32IM}: ${TOOLCHAIN_DIR}/llvm-project -DCMAKE_C_COMPILER_WORKS=1 \ -DCMAKE_CXX_COMPILER_WORKS=1 \ -DCMAKE_AR=${LLVM_INSTALL_DIR}/bin/llvm-ar \ - -DCMAKE_INSTALL_PREFIX=${LLVM_INSTALL_DIR}/lib/clang/15.0.0 \ + -DCMAKE_INSTALL_PREFIX=${LLVM_CLANG_RT_DIR} \ -DCMAKE_ASM_COMPILER_TARGET="riscv32-unknown-elf" \ -DCMAKE_C_COMPILER=${LLVM_INSTALL_DIR}/bin/clang \ -DCMAKE_ASM_COMPILER=${LLVM_INSTALL_DIR}/bin/clang \ @@ -182,7 +185,7 @@ ${LLVM_CLANG_RT_RISCV_RV32IMA}: ${TOOLCHAIN_DIR}/llvm-project -DCMAKE_C_COMPILER_WORKS=1 \ -DCMAKE_CXX_COMPILER_WORKS=1 \ -DCMAKE_AR=${LLVM_INSTALL_DIR}/bin/llvm-ar \ - -DCMAKE_INSTALL_PREFIX=${LLVM_INSTALL_DIR}/lib/clang/15.0.0 \ + -DCMAKE_INSTALL_PREFIX=${LLVM_CLANG_RT_DIR} \ -DCMAKE_ASM_COMPILER_TARGET="riscv32-unknown-elf" \ -DCMAKE_C_COMPILER=${LLVM_INSTALL_DIR}/bin/clang \ -DCMAKE_ASM_COMPILER=${LLVM_INSTALL_DIR}/bin/clang \ @@ -214,7 +217,7 @@ ${LLVM_CLANG_RT_RISCV_RV32IMC}: ${TOOLCHAIN_DIR}/llvm-project -DCMAKE_C_COMPILER_WORKS=1 \ -DCMAKE_CXX_COMPILER_WORKS=1 \ -DCMAKE_AR=${LLVM_INSTALL_DIR}/bin/llvm-ar \ - -DCMAKE_INSTALL_PREFIX=${LLVM_INSTALL_DIR}/lib/clang/15.0.0 \ + -DCMAKE_INSTALL_PREFIX=${LLVM_CLANG_RT_DIR} \ -DCMAKE_ASM_COMPILER_TARGET="riscv32-unknown-elf" \ -DCMAKE_C_COMPILER=${LLVM_INSTALL_DIR}/bin/clang \ -DCMAKE_ASM_COMPILER=${LLVM_INSTALL_DIR}/bin/clang \ @@ -246,7 +249,7 @@ ${LLVM_CLANG_RT_RISCV_RV32IMAFD}: ${TOOLCHAIN_DIR}/llvm-project -DCMAKE_C_COMPILER_WORKS=1 \ -DCMAKE_CXX_COMPILER_WORKS=1 \ -DCMAKE_AR=${LLVM_INSTALL_DIR}/bin/llvm-ar \ - -DCMAKE_INSTALL_PREFIX=${LLVM_INSTALL_DIR}/lib/clang/15.0.0 \ + -DCMAKE_INSTALL_PREFIX=${LLVM_CLANG_RT_DIR} \ -DCMAKE_ASM_COMPILER_TARGET="riscv32-unknown-elf" \ -DCMAKE_C_COMPILER=${LLVM_INSTALL_DIR}/bin/clang \ -DCMAKE_ASM_COMPILER=${LLVM_INSTALL_DIR}/bin/clang \ @@ -279,7 +282,7 @@ ${LLVM_CLANG_RT_RISCV_RV32IMF}: ${TOOLCHAIN_DIR}/llvm-project -DCMAKE_C_COMPILER_WORKS=1 \ -DCMAKE_CXX_COMPILER_WORKS=1 \ -DCMAKE_AR=${LLVM_INSTALL_DIR}/bin/llvm-ar \ - -DCMAKE_INSTALL_PREFIX=${LLVM_INSTALL_DIR}/lib/clang/15.0.0 \ + -DCMAKE_INSTALL_PREFIX=${LLVM_CLANG_RT_DIR} \ -DCMAKE_ASM_COMPILER_TARGET="riscv32-unknown-elf" \ -DCMAKE_C_COMPILER=${LLVM_INSTALL_DIR}/bin/clang \ -DCMAKE_ASM_COMPILER=${LLVM_INSTALL_DIR}/bin/clang \ @@ -314,7 +317,7 @@ ${LLVM_CLANG_RT_ARM}: ${TOOLCHAIN_DIR}/llvm-project -DCMAKE_C_COMPILER_WORKS=1 \ -DCMAKE_CXX_COMPILER_WORKS=1 \ -DCMAKE_AR=${LLVM_INSTALL_DIR}/bin/llvm-ar \ - -DCMAKE_INSTALL_PREFIX=${LLVM_INSTALL_DIR}/lib/clang/15.0.0 \ + -DCMAKE_INSTALL_PREFIX=${LLVM_CLANG_RT_DIR} \ -DCMAKE_ASM_COMPILER_TARGET="armv7m-none-eabi" \ -DCMAKE_C_COMPILER=${LLVM_INSTALL_DIR}/bin/clang \ -DCMAKE_ASM_COMPILER=${LLVM_INSTALL_DIR}/bin/clang \ diff --git a/cmake/chimera/toolchain_llvm.cmake b/cmake/chimera/toolchain_llvm.cmake index 6e613c0cb9..318bc913f4 100644 --- a/cmake/chimera/toolchain_llvm.cmake +++ b/cmake/chimera/toolchain_llvm.cmake @@ -9,6 +9,7 @@ set(CMAKE_SYSTEM_NAME Generic) set(LLVM_TAG llvm) set(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}/clang) +include(${CMAKE_CURRENT_LIST_DIR}/../clang_resource_dir.cmake) set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PREFIX}/clang++) set(CMAKE_ASM_COMPILER ${TOOLCHAIN_PREFIX}/clang) set(CMAKE_OBJCOPY ${TOOLCHAIN_PREFIX}/${LLVM_TAG}-objcopy) @@ -50,7 +51,7 @@ add_link_options( -nostartfiles -nostdlib -L${TOOLCHAIN_INSTALL_DIR}/picolibc/riscv/${ISA}/lib - -L${TOOLCHAIN_INSTALL_DIR}/lib/clang/15.0.0/lib/baremetal/${ISA} + -L${CLANG_RESOURCE_DIR}/lib/baremetal/${ISA} ) link_libraries( diff --git a/cmake/clang_resource_dir.cmake b/cmake/clang_resource_dir.cmake new file mode 100644 index 0000000000..2625b06a5a --- /dev/null +++ b/cmake/clang_resource_dir.cmake @@ -0,0 +1,22 @@ +# SPDX-FileCopyrightText: 2026 ETH Zurich and University of Bologna +# +# SPDX-License-Identifier: Apache-2.0 + +# Sets CLANG_RESOURCE_DIR to the resource directory of CMAKE_C_COMPILER +# (e.g. /lib/clang/18), where the Makefile installs compiler-rt. +# Asking the compiler keeps toolchain files independent of the LLVM version. +# +# CMake also re-reads toolchain files for its internal try_compile projects, +# where TOOLCHAIN_INSTALL_DIR is not set; the query is skipped there. + +if(EXISTS ${CMAKE_C_COMPILER}) + execute_process( + COMMAND ${CMAKE_C_COMPILER} -print-resource-dir + OUTPUT_VARIABLE CLANG_RESOURCE_DIR + OUTPUT_STRIP_TRAILING_WHITESPACE + RESULT_VARIABLE _clang_resource_dir_result + ) + if(NOT _clang_resource_dir_result EQUAL 0 OR NOT CLANG_RESOURCE_DIR) + message(FATAL_ERROR "Could not query the resource directory of ${CMAKE_C_COMPILER}") + endif() +endif() diff --git a/cmake/mempool/toolchain_llvm.cmake b/cmake/mempool/toolchain_llvm.cmake index 3340daf460..9f8356f032 100644 --- a/cmake/mempool/toolchain_llvm.cmake +++ b/cmake/mempool/toolchain_llvm.cmake @@ -8,6 +8,7 @@ set(CMAKE_SYSTEM_NAME Generic) set(CMAKE_OBJCOPY ${TOOLCHAIN_PREFIX}/llvm-objcopy) set(CMAKE_OBJDUMP ${TOOLCHAIN_PREFIX}/llvm-objdump) set(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}/clang) +include(${CMAKE_CURRENT_LIST_DIR}/../clang_resource_dir.cmake) set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PREFIX}/clang++) set(CMAKE_AR ${TOOLCHAIN_PREFIX}/llvm-ar) set(SIZE ${TOOLCHAIN_PREFIX}/llvm-size) @@ -76,7 +77,7 @@ add_link_options( -static -L${TOOLCHAIN_INSTALL_DIR}/picolibc/riscv/rv32ima/lib - -L${TOOLCHAIN_INSTALL_DIR}/lib/clang/15.0.0/lib/baremetal/rv32ima/ + -L${CLANG_RESOURCE_DIR}/lib/baremetal/rv32ima/ ) link_libraries( diff --git a/cmake/pulp/toolchain_llvm.cmake b/cmake/pulp/toolchain_llvm.cmake index 4767648558..05252a6325 100644 --- a/cmake/pulp/toolchain_llvm.cmake +++ b/cmake/pulp/toolchain_llvm.cmake @@ -9,6 +9,7 @@ set(CMAKE_SYSTEM_NAME Generic) set(LLVM_TAG llvm) set(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}/clang) +include(${CMAKE_CURRENT_LIST_DIR}/../clang_resource_dir.cmake) set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PREFIX}/clang++) set(CMAKE_ASM_COMPILER ${TOOLCHAIN_PREFIX}/clang) set(CMAKE_OBJCOPY ${TOOLCHAIN_PREFIX}/${LLVM_TAG}-objcopy) @@ -55,7 +56,7 @@ add_link_options( -march=${ISA} -mabi=${ABI} -L${TOOLCHAIN_INSTALL_DIR}/picolibc/riscv/${LIBC_ISA}/lib - -L${TOOLCHAIN_INSTALL_DIR}/lib/clang/15.0.0/lib/baremetal/${RT_ISA}/ + -L${CLANG_RESOURCE_DIR}/lib/baremetal/${RT_ISA}/ -z norelro -fno-builtin-memcpy -fno-builtin-memset diff --git a/cmake/snitch/toolchain_llvm.cmake b/cmake/snitch/toolchain_llvm.cmake index 09f64b9817..d752b69304 100644 --- a/cmake/snitch/toolchain_llvm.cmake +++ b/cmake/snitch/toolchain_llvm.cmake @@ -9,6 +9,7 @@ set(CMAKE_SYSTEM_NAME Generic) set(LLVM_TAG llvm) set(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}/clang) +include(${CMAKE_CURRENT_LIST_DIR}/../clang_resource_dir.cmake) set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PREFIX}/clang++) set(CMAKE_ASM_COMPILER ${TOOLCHAIN_PREFIX}/clang) set(CMAKE_OBJCOPY ${TOOLCHAIN_PREFIX}/${LLVM_TAG}-objcopy) @@ -39,7 +40,7 @@ add_link_options( -nostartfiles -nostdlib -L${TOOLCHAIN_INSTALL_DIR}/picolibc/riscv/rv32imafd/lib - -L${TOOLCHAIN_INSTALL_DIR}/lib/clang/15.0.0/lib/baremetal/rv32imafd + -L${CLANG_RESOURCE_DIR}/lib/baremetal/rv32imafd ) link_libraries( From fd5f7e5d7bd41974e1ae0a5fad619c2f485b9c7b Mon Sep 17 00:00:00 2001 From: marchioa Date: Wed, 28 Oct 2026 22:19:40 +0100 Subject: [PATCH 08/18] minor fixes due to the clang update from version 15 to 18 - pulp-open/siracusa L3: address cast - siracusa: missing include in deeploytest.c - snitch: fpu barrier in SnitchCoreFilter.py, missing include in DeeploySnitchMath.h, missing func prototypes in Add.h, iSoftmax.h - mempool: missing volatile in main.c, update flags in /mempool/toolchain_llvm.cmake - chimera: missing func prototypes in sdk so added in DeeployChimeraMath.h, update flags in /chimera/toolchain_llvm.cmake --- Deeploy/Targets/PULPOpen/DMA/L3Dma.py | 2 +- .../CodeTransformationPasses/SnitchCoreFilter.py | 8 +++++++- DeeployTest/Platforms/MemPool/main.c | 2 +- DeeployTest/Platforms/Siracusa/src/deeploytest.c | 1 + TargetLibraries/Chimera/inc/DeeployChimeraMath.h | 5 +++++ TargetLibraries/Snitch/inc/DeeploySnitchMath.h | 1 + TargetLibraries/Snitch/inc/kernel/Add.h | 12 ++++++++++++ TargetLibraries/Snitch/inc/kernel/iSoftmax.h | 2 +- cmake/chimera/toolchain_llvm.cmake | 3 +++ cmake/mempool/toolchain_llvm.cmake | 4 ++-- 10 files changed, 34 insertions(+), 6 deletions(-) diff --git a/Deeploy/Targets/PULPOpen/DMA/L3Dma.py b/Deeploy/Targets/PULPOpen/DMA/L3Dma.py index 6c2aa30811..b9d57cf489 100644 --- a/Deeploy/Targets/PULPOpen/DMA/L3Dma.py +++ b/Deeploy/Targets/PULPOpen/DMA/L3Dma.py @@ -29,7 +29,7 @@ class L3Dma(AsyncDma): _transferTemplates = { 2: NodeTemplate( - "pi_cl_ram_copy_2d(get_ram_ptr(), ${ext}, ${loc}, ${transfer_size}, ${stride}, ${length}, ${ext2loc}, &${future});" + "pi_cl_ram_copy_2d(get_ram_ptr(), (uint32_t)${ext}, ${loc}, ${transfer_size}, ${stride}, ${length}, ${ext2loc}, &${future});" ) } _waitingStrategy = PerTensorWaitingStrategy(L3DmaFuture) diff --git a/Deeploy/Targets/Snitch/CodeTransformationPasses/SnitchCoreFilter.py b/Deeploy/Targets/Snitch/CodeTransformationPasses/SnitchCoreFilter.py index a864c5db8f..08e4f4aa62 100644 --- a/Deeploy/Targets/Snitch/CodeTransformationPasses/SnitchCoreFilter.py +++ b/Deeploy/Targets/Snitch/CodeTransformationPasses/SnitchCoreFilter.py @@ -20,5 +20,11 @@ def apply(self, name: str, verbose: CodeGenVerbosity = _NoVerbosity) -> Tuple[NetworkContext, ExecutionBlock]: executionBlock.addLeft(NodeTemplate(f"if (snrt_is_{self.coreType}_core()) {{\n"), {}) - executionBlock.addRight(NodeTemplate("}\n"), {}) + if self.coreType == "compute": + # The FPU is decoupled from the integer core: wait until all issued + # FP instructions (e.g. a trailing fdiv + store) have completed, so + # the following barrier / DMA transfer sees the final results. + executionBlock.addRight(NodeTemplate("snrt_fpu_fence();\n}\n"), {}) + else: + executionBlock.addRight(NodeTemplate("}\n"), {}) return ctxt, executionBlock diff --git a/DeeployTest/Platforms/MemPool/main.c b/DeeployTest/Platforms/MemPool/main.c index a0eda86c83..2c22699563 100644 --- a/DeeployTest/Platforms/MemPool/main.c +++ b/DeeployTest/Platforms/MemPool/main.c @@ -31,7 +31,7 @@ dump(input1, 7); #define NUM_THREADS 1 #endif -static int8_t inference_done __attribute__((section(".l1"))) = 0; +static volatile int8_t inference_done __attribute__((section(".l1"))) = 0; int main() { uint32_t const core_id = mempool_get_core_id(); diff --git a/DeeployTest/Platforms/Siracusa/src/deeploytest.c b/DeeployTest/Platforms/Siracusa/src/deeploytest.c index 11d889e48d..4ebcc810fe 100644 --- a/DeeployTest/Platforms/Siracusa/src/deeploytest.c +++ b/DeeployTest/Platforms/Siracusa/src/deeploytest.c @@ -10,6 +10,7 @@ #include "pmsis.h" #include "testinputs.h" #include "testoutputs.h" +#include #define MAINSTACKSIZE 8000 #define SLAVESTACKSIZE 3800 diff --git a/TargetLibraries/Chimera/inc/DeeployChimeraMath.h b/TargetLibraries/Chimera/inc/DeeployChimeraMath.h index 756b532850..32ec3303ab 100644 --- a/TargetLibraries/Chimera/inc/DeeployChimeraMath.h +++ b/TargetLibraries/Chimera/inc/DeeployChimeraMath.h @@ -27,4 +27,9 @@ #include #include +// Memory island allocator, defined in chimera-sdk generic_runtime/src/alloc.c +// (the SDK provides no header for it). +void *memory_island_malloc(size_t size); +void memory_island_free(void *ptr); + #endif //__DEEPLOY_CHIMERA_MATH_HEADER_ diff --git a/TargetLibraries/Snitch/inc/DeeploySnitchMath.h b/TargetLibraries/Snitch/inc/DeeploySnitchMath.h index f686e597ca..8513170afb 100644 --- a/TargetLibraries/Snitch/inc/DeeploySnitchMath.h +++ b/TargetLibraries/Snitch/inc/DeeploySnitchMath.h @@ -40,6 +40,7 @@ typedef float v2f32 __attribute__((vector_size(8))); #include "kernel/Softmax.h" #include "kernel/UniformRequantShift.h" #include "kernel/iNoNorm.h" +#include "kernel/iSoftmax.h" #include "dmaStruct.h" diff --git a/TargetLibraries/Snitch/inc/kernel/Add.h b/TargetLibraries/Snitch/inc/kernel/Add.h index dc08482021..3a1ea21e6c 100644 --- a/TargetLibraries/Snitch/inc/kernel/Add.h +++ b/TargetLibraries/Snitch/inc/kernel/Add.h @@ -12,4 +12,16 @@ void Add_fp32(float32_t *input1, float32_t *input2, float32_t *output, uint32_t size, uint32_t is_scalar); +void SnitchAdd(int8_t *pIn1, int8_t *pIn2, int32_t *pOut, uint32_t size, + int32_t offset); + +void snitch_nn_add_i8_i8_i8(int8_t *pIn1, int8_t *pIn2, int8_t *pOut, + int32_t in1_mul, int32_t in1_add, + uint16_t in1_shift, int32_t in2_mul, + int32_t in2_add, uint16_t in2_shift, + int32_t out_mul, int32_t out_add, + uint16_t out_shift, uint16_t dim_im_in_x, + uint16_t dim_im_in_y, uint16_t ch_im_in, + int out_requant_flag); + #endif // __DEEPLOY_MATH_ADD_KERNEL_HEADER_ diff --git a/TargetLibraries/Snitch/inc/kernel/iSoftmax.h b/TargetLibraries/Snitch/inc/kernel/iSoftmax.h index fb68d04adf..f07895126e 100644 --- a/TargetLibraries/Snitch/inc/kernel/iSoftmax.h +++ b/TargetLibraries/Snitch/inc/kernel/iSoftmax.h @@ -13,7 +13,7 @@ void SnitchSoftmax_u8_u8(uint8_t *data_in, uint8_t *data_out, uint32_t *lastDimBuffer, uint32_t size, uint32_t lastDimLength, int32_t coeffB, int32_t coeffC, int32_t log2); -void StnichSoftmax_i8_u8(int8_t *data_in, uint8_t *data_out, +void SnitchSoftmax_i8_u8(int8_t *data_in, uint8_t *data_out, uint32_t *lastDimBuffer, uint32_t size, uint32_t lastDimLength, int32_t coeffB, int32_t coeffC, int32_t log2); diff --git a/cmake/chimera/toolchain_llvm.cmake b/cmake/chimera/toolchain_llvm.cmake index 318bc913f4..881eb12c89 100644 --- a/cmake/chimera/toolchain_llvm.cmake +++ b/cmake/chimera/toolchain_llvm.cmake @@ -40,6 +40,9 @@ add_compile_options( -fno-common -fopenmp -ftls-model=local-exec + # chimera-sdk generic_runtime/src/stdio.c passes a char-returning putc to + # FDEV_SETUP_STREAM; an error since clang 16, keep it a warning until fixed + -Wno-error=incompatible-function-pointer-types -DNUM_CORES=${NUM_CORES} -isystem ${TOOLCHAIN_INSTALL_DIR}/picolibc/riscv/${ISA}/include ) diff --git a/cmake/mempool/toolchain_llvm.cmake b/cmake/mempool/toolchain_llvm.cmake index 9f8356f032..e38db9c7d0 100644 --- a/cmake/mempool/toolchain_llvm.cmake +++ b/cmake/mempool/toolchain_llvm.cmake @@ -19,10 +19,10 @@ if(xpulpimg) message(FATAL_ERROR "Xpulpimg extension is not supported for this compiler!") else() add_compile_options( - -march=rv32ima + -march=rv32ima_xmempool ) add_link_options( - -march=rv32ima + -march=rv32ima_xmempool ) endif() From b86fa39b97cebb7b589d2765e5099d7b93d4c5c0 Mon Sep 17 00:00:00 2001 From: marchioa Date: Fri, 30 Oct 2026 12:03:49 +0100 Subject: [PATCH 09/18] move the PULP LLVM toolchain to clang 20 Switch to the albsposito/llvm-project port/20 branch (clang 20.1.8). Toolchain adaptations for clang >= 19/20 (clang 15 still builds): - pulp, mempool: clang links compiler-rt by an absolute per-target path that ignores -L. Use -nodefaultlibs and link -lc and -lclang_rt.builtins-riscv32 explicitly. - mempool, cmsis: add -nostartfiles, since clang 20 adds crt0.o on bare-metal targets. - mempool: disable GlobalMerge. It reorders the static .l2 constants, and Banshee corrupts the trailing bytes of an ELF load segment whose size is not a multiple of 4 (e.g. Kernels/Integer/Conv/DW_2D_RQ). Fixes for bugs exposed by the new compiler: - Snitch CycleCounter: drop the .l1 section attribute. - ReshapeTemplate: run the alias assignment on every core. Under SINGLE_CORE, a RunNetwork-local output pointer was left uninitialized on the other cores. --- .../Generic/Templates/ReshapeTemplate.py | 4 +- DeeployTest/test_pulpopen_config.py | 8 +- DeeployTest/test_pulpopen_tiled_config.py | 16 +-- Makefile | 10 +- TargetLibraries/Snitch/src/CycleCounter.c | 12 +- cmake/cmsis/toolchain_llvm.cmake | 2 + cmake/mempool/toolchain_llvm.cmake | 16 ++- cmake/pulp/toolchain_llvm.cmake | 5 + toolchain/pulp-llvm-crash-fixes.patch | 119 ------------------ 9 files changed, 48 insertions(+), 144 deletions(-) delete mode 100644 toolchain/pulp-llvm-crash-fixes.patch diff --git a/Deeploy/Targets/Generic/Templates/ReshapeTemplate.py b/Deeploy/Targets/Generic/Templates/ReshapeTemplate.py index e4cb01381c..dc933e6fba 100644 --- a/Deeploy/Targets/Generic/Templates/ReshapeTemplate.py +++ b/Deeploy/Targets/Generic/Templates/ReshapeTemplate.py @@ -43,7 +43,9 @@ def alignToContext(self, ctxt: NetworkContext, return ctxt, operatorRepresentation, [] +# Executed by every core: ${data_out} can be a local of the per-core RunNetwork, +# so a SINGLE_CORE assignment would leave it uninitialized on the other cores. referenceTemplate = _ReshapeTemplate(""" // Reshape (Name: ${nodeName}, Op: ${nodeOp}) -SINGLE_CORE ${data_out} = ${data_in}; +${data_out} = ${data_in}; """) diff --git a/DeeployTest/test_pulpopen_config.py b/DeeployTest/test_pulpopen_config.py index be462af831..7162308997 100644 --- a/DeeployTest/test_pulpopen_config.py +++ b/DeeployTest/test_pulpopen_config.py @@ -16,9 +16,9 @@ "Kernels/FP32/Conv/DW_2D_Bias", "Kernels/FP32/Conv/DW_2D_NoBias", "Kernels/FP32/Conv/DW_2D_ZeroValuedBias", - # "Kernels/FP32/Conv/Regular_2D_Bias", # LLVM HW-loop bug - # "Kernels/FP32/Conv/Regular_2D_NoBias", # LLVM HW-loop bug - # "Kernels/FP32/Conv/Regular_2D_ZeroValuedBias", # LLVM HW-loop bug + "Kernels/FP32/Conv/Regular_2D_Bias", + "Kernels/FP32/Conv/Regular_2D_NoBias", + "Kernels/FP32/Conv/Regular_2D_ZeroValuedBias", "Kernels/FP32/GEMM/Regular", "Kernels/FP32/MatMul", "Kernels/FP32/MaxPool/Regular_2D", @@ -68,7 +68,7 @@ MODEL_TESTS = [ "Kernels/Integer/Attention", - # "Models/CCT/FP32/CCT_1_16_16_8", # LLVM HW-loop bug + "Models/CCT/FP32/CCT_1_16_16_8", # "Models/CCT/FP32/CCT_2_32_32_128_Opset20", "Models/miniMobileNet", "Models/miniMobileNetv2", diff --git a/DeeployTest/test_pulpopen_tiled_config.py b/DeeployTest/test_pulpopen_tiled_config.py index 6540b8c9be..67418205fc 100644 --- a/DeeployTest/test_pulpopen_tiled_config.py +++ b/DeeployTest/test_pulpopen_tiled_config.py @@ -16,9 +16,9 @@ "Kernels/FP32/Conv/DW_2D_Bias": [7200], "Kernels/FP32/Conv/DW_2D_NoBias": [7200], "Kernels/FP32/Conv/DW_2D_ZeroValuedBias": [7200], - # "Kernels/FP32/Conv/Regular_2D_Bias": [6600], # LLVM HW-loop bug - # "Kernels/FP32/Conv/Regular_2D_NoBias": [1600], # LLVM HW-loop bug - # "Kernels/FP32/Conv/Regular_2D_ZeroValuedBias": [6600], # LLVM HW-loop bug + "Kernels/FP32/Conv/Regular_2D_Bias": [6600], + "Kernels/FP32/Conv/Regular_2D_NoBias": [1600], + "Kernels/FP32/Conv/Regular_2D_ZeroValuedBias": [6600], "Kernels/FP32/GEMM/Regular": [8000], "Kernels/FP32/MatMul": [2000], "Kernels/FP32/MaxPool/Regular_2D": [2000], @@ -63,9 +63,9 @@ "Kernels/FP32/Conv/DW_2D_Bias": [10000], "Kernels/FP32/Conv/DW_2D_NoBias": [9800], "Kernels/FP32/Conv/DW_2D_ZeroValuedBias": [9800], - # "Kernels/FP32/Conv/Regular_2D_Bias": [8800], # LLVM HW-loop bug - # "Kernels/FP32/Conv/Regular_2D_NoBias": [2000], # LLVM HW-loop bug - # "Kernels/FP32/Conv/Regular_2D_ZeroValuedBias": [8800], # LLVM HW-loop bug + "Kernels/FP32/Conv/Regular_2D_Bias": [8800], + "Kernels/FP32/Conv/Regular_2D_NoBias": [2000], + "Kernels/FP32/Conv/Regular_2D_ZeroValuedBias": [8800], "Kernels/FP32/GEMM/Regular": [8000], "Kernels/FP32/MatMul": [5000], "Kernels/FP32/MaxPool/Regular_2D": [5000], @@ -113,7 +113,7 @@ "Models/MLPerf/ImageClassification": [64000], "Models/MLPerf/AnomalyDetection": [64000], "Models/MLPerf/VisualWakeWords": [64000], - # "Models/CCT/FP32/CCT_1_16_16_8": [64000], # LLVM HW-loop bug + "Models/CCT/FP32/CCT_1_16_16_8": [64000], "Models/TinyViT/Demo": [4000], } @@ -129,7 +129,7 @@ "Models/MLPerf/ImageClassification": [128000], "Models/MLPerf/AnomalyDetection": [128000], "Models/MLPerf/VisualWakeWords": [128000], - # "Models/CCT/FP32/CCT_1_16_16_8": [128000], # LLVM HW-loop bug + "Models/CCT/FP32/CCT_1_16_16_8": [128000], "Models/TinyViT/Demo": [8000], } diff --git a/Makefile b/Makefile index d3eb9e9e5d..5d83d89b8d 100644 --- a/Makefile +++ b/Makefile @@ -13,7 +13,7 @@ TOOLCHAIN_DIR := ${ROOT_DIR}/toolchain LLVM_INSTALL_DIR ?= ${DEEPLOY_INSTALL_DIR}/llvm # clang resource directory, where compiler-rt is installed. Must match # `clang -print-resource-dir` of the LLVM version above (clang >= 16: major only). -LLVM_CLANG_RT_DIR ?= ${LLVM_INSTALL_DIR}/lib/clang/18 +LLVM_CLANG_RT_DIR ?= ${LLVM_INSTALL_DIR}/lib/clang/20 LLVM_CLANG_RT_ARM ?= ${LLVM_CLANG_RT_DIR}/lib/baremetal/libclang_rt.builtins-armv7m.a LLVM_CLANG_RT_RISCV_RV32IMAFD ?= ${LLVM_CLANG_RT_DIR}/lib/baremetal/rv32imafd/libclang_rt.builtins-riscv32.a LLVM_CLANG_RT_RISCV_RV32IMC ?= ${LLVM_CLANG_RT_DIR}/lib/baremetal/rv32imc/libclang_rt.builtins-riscv32.a @@ -47,7 +47,8 @@ GAP9_SDK_INSTALL_DIR ?= ${DEEPLOY_INSTALL_DIR}/gap9-sdk CMAKE ?= cmake -LLVM_COMMIT_HASH ?= 6547028f925c4f27f5ff2ae40c3e901bacf886e4 +LLVM_REPO ?= https://github.com/albsposito/llvm-project.git +LLVM_COMMIT_HASH ?= 2dcfd2de54d93d239bde88dd0a57fce15396810e PICOLIBC_COMMIT_HASH ?= 31ff1b3601b379e4cab63837f253f59729ce1fef PULP_SDK_COMMIT_HASH ?= 894a13eb62eaa8d00c9f7c39d1d8ff98d9c03211 MEMPOOL_COMMIT_HASH ?= affd45d94e05e375a6966af6a762deeb182a7bd6 @@ -118,11 +119,10 @@ ${TOOLCHAIN_DIR}/llvm-project: cd ${TOOLCHAIN_DIR} && \ git init llvm-project && \ cd ${TOOLCHAIN_DIR}/llvm-project && \ - git remote add origin https://github.com/pulp-platform/llvm-project.git && \ + git remote add origin ${LLVM_REPO} && \ git fetch --depth=1 origin ${LLVM_COMMIT_HASH} && \ git checkout ${LLVM_COMMIT_HASH} && \ - git submodule update --init --recursive && \ - git apply ${TOOLCHAIN_DIR}/pulp-llvm-crash-fixes.patch + git submodule update --init --recursive ${LLVM_INSTALL_DIR}: ${TOOLCHAIN_DIR}/llvm-project cd ${TOOLCHAIN_DIR}/llvm-project && \ diff --git a/TargetLibraries/Snitch/src/CycleCounter.c b/TargetLibraries/Snitch/src/CycleCounter.c index 3861c421c1..572c88a2f1 100644 --- a/TargetLibraries/Snitch/src/CycleCounter.c +++ b/TargetLibraries/Snitch/src/CycleCounter.c @@ -6,12 +6,14 @@ #include "DeeploySnitchMath.h" -static uint32_t timer_init[NUM_CORES] __attribute__((section(".l1"))); -static uint32_t timer_end[NUM_CORES] __attribute__((section(".l1"))); -static uint32_t instr_init[NUM_CORES] __attribute__((section(".l1"))); -static uint32_t instr_end[NUM_CORES] __attribute__((section(".l1"))); +// No section attribute: the Snitch linker script has no .l1 output section, so +// the linker would place these as an orphan section, possibly on the L3 heap. +static uint32_t timer_init[NUM_CORES]; +static uint32_t timer_end[NUM_CORES]; +static uint32_t instr_init[NUM_CORES]; +static uint32_t instr_end[NUM_CORES]; -static uint32_t running[NUM_CORES] __attribute__((section(".l1"))); +static uint32_t running[NUM_CORES]; void ResetTimer() { snrt_reset_perf_counter(SNRT_PERF_CNT0); diff --git a/cmake/cmsis/toolchain_llvm.cmake b/cmake/cmsis/toolchain_llvm.cmake index 6c747b1d9d..2789605746 100644 --- a/cmake/cmsis/toolchain_llvm.cmake +++ b/cmake/cmsis/toolchain_llvm.cmake @@ -40,6 +40,8 @@ add_link_options( -target armv7m-none-eabi -MP -mcpu=${ISA} + # startup code comes from -lcrt0-semihost; clang >= 20 would add crt0.o + -nostartfiles -L${TOOLCHAIN_INSTALL_DIR}/picolibc/arm/lib -Tpicolibc.ld -v diff --git a/cmake/mempool/toolchain_llvm.cmake b/cmake/mempool/toolchain_llvm.cmake index e38db9c7d0..db736e7217 100644 --- a/cmake/mempool/toolchain_llvm.cmake +++ b/cmake/mempool/toolchain_llvm.cmake @@ -32,8 +32,13 @@ add_compile_options( -mabi=ilp32 -mcmodel=medany -mcpu=mempool-rv32 - -mllvm - -misched-topdown + # LLVM 19 replaced -misched-topdown with -misched-prera-direction=topdown + "SHELL:-mllvm $,19>,-misched-topdown,-misched-prera-direction=topdown>" + # Banshee corrupts the trailing bytes of an ELF load segment whose size is not + # a multiple of 4. GlobalMerge (on for RISC-V in recent LLVM) reorders the + # static .l2 constants, which can leave an odd-sized int8 tensor at the end of + # the last segment (e.g. Kernels/Integer/Conv/DW_2D_RQ). Keep source order. + "SHELL:-mllvm -enable-global-merge=false" -std=gnu99 @@ -76,12 +81,19 @@ add_link_options( -Wextra -static + # startup code comes from the MemPool runtime; clang >= 20 would add crt0.o + -nostartfiles + -nodefaultlibs -L${TOOLCHAIN_INSTALL_DIR}/picolibc/riscv/rv32ima/lib -L${CLANG_RESOURCE_DIR}/lib/baremetal/rv32ima/ ) +# clang >= 19 links compiler-rt by an absolute per-target path that ignores -L, +# so link it explicitly to select the ISA-specific build. link_libraries( -lm + -lc + -lclang_rt.builtins-riscv32 ) add_compile_definitions(__LINK_LD) diff --git a/cmake/pulp/toolchain_llvm.cmake b/cmake/pulp/toolchain_llvm.cmake index 05252a6325..233f56e7a6 100644 --- a/cmake/pulp/toolchain_llvm.cmake +++ b/cmake/pulp/toolchain_llvm.cmake @@ -53,6 +53,7 @@ add_link_options( -target riscv32-unknown-elf -MP -nostartfiles + -nodefaultlibs -march=${ISA} -mabi=${ABI} -L${TOOLCHAIN_INSTALL_DIR}/picolibc/riscv/${LIBC_ISA}/lib @@ -62,8 +63,12 @@ add_link_options( -fno-builtin-memset ) +# clang >= 19 links compiler-rt by an absolute per-target path that ignores -L, +# so link it explicitly to select the ISA-specific build. link_libraries( -lm + -lc + -lclang_rt.builtins-riscv32 ) add_compile_definitions(__LINK_LD) diff --git a/toolchain/pulp-llvm-crash-fixes.patch b/toolchain/pulp-llvm-crash-fixes.patch deleted file mode 100644 index abe08ef89a..0000000000 --- a/toolchain/pulp-llvm-crash-fixes.patch +++ /dev/null @@ -1,119 +0,0 @@ -diff --git a/llvm/lib/Target/RISCV/PULP/PULPHardwareLoops.cpp b/llvm/lib/Target/RISCV/PULP/PULPHardwareLoops.cpp -index f42031540268..a6923c8b997a 100644 ---- a/llvm/lib/Target/RISCV/PULP/PULPHardwareLoops.cpp -+++ b/llvm/lib/Target/RISCV/PULP/PULPHardwareLoops.cpp -@@ -774,25 +774,29 @@ PULPHardwareLoops::getLoopTripCount(MachineLoop *L, - - if (InitialValue->isReg()) { - llvm::Register R = InitialValue->getReg(); -- MachineBasicBlock *DefBB = MRI->getVRegDef(R)->getParent(); -- if (!MDT->properlyDominates(DefBB, Header)) { -+ // Physical registers (e.g. X0 in a compare against zero) have no SSA -+ // definition, so getVRegDef would return null. -+ MachineInstr *DefMI = R.isVirtual() ? MRI->getVRegDef(R) : nullptr; -+ if (!DefMI || !MDT->properlyDominates(DefMI->getParent(), Header)) { - int64_t V; - if (!checkForImmediate(*InitialValue, V)) { - return nullptr; - } - } -- OldInsts.push_back(MRI->getVRegDef(R)); -+ if (DefMI) -+ OldInsts.push_back(DefMI); - } - if (EndValue->isReg()) { - llvm::Register R = EndValue->getReg(); -- MachineBasicBlock *DefBB = MRI->getVRegDef(R)->getParent(); -- if (!MDT->properlyDominates(DefBB, Header)) { -+ MachineInstr *DefMI = R.isVirtual() ? MRI->getVRegDef(R) : nullptr; -+ if (!DefMI || !MDT->properlyDominates(DefMI->getParent(), Header)) { - int64_t V; - if (!checkForImmediate(*EndValue, V)) { - return nullptr; - } - } -- OldInsts.push_back(MRI->getVRegDef(R)); -+ if (DefMI) -+ OldInsts.push_back(DefMI); - } - - return computeCount(L, InitialValue, EndValue, IVReg, IVBump, Cmp); -@@ -991,8 +995,9 @@ CountValue *PULPHardwareLoops::computeCount(MachineLoop *Loop, - // If the loop has been unrolled, we should use the original loop count - // instead of recalculating the value. This will avoid additional - // 'Add' instruction. -- const MachineInstr *EndValInstr = MRI->getVRegDef(End->getReg()); -- if (EndValInstr->getOpcode() == RISCV::ADDI && -+ const MachineInstr *EndValInstr = -+ End->getReg().isVirtual() ? MRI->getVRegDef(End->getReg()) : nullptr; -+ if (EndValInstr && EndValInstr->getOpcode() == RISCV::ADDI && - EndValInstr->getOperand(1).getSubReg() == 0 && - EndValInstr->getOperand(2).getImm() == StartV) { - DistR = EndValInstr->getOperand(1).getReg(); -@@ -1265,12 +1270,23 @@ bool PULPHardwareLoops::convertToHardwareLoop(MachineLoop *L, bool &RecL0used, - if (TripCount->isReg()) { - // There will be a use of the register inserted into the preheader, - // so make sure that the register is actually defined at that point. -- MachineInstr *TCDef = MRI->getVRegDef(TripCount->getReg()); -- MachineBasicBlock *BBDef = TCDef->getParent(); -- if (!MDT->dominates(BBDef, Preheader)) { -- LLVM_DEBUG(dbgs() << "Cannot convert to hwloop: induction register not " -- "available in preheader\n"); -- return Changed; -+ // Physical registers have no SSA definition; only the constant zero -+ // register X0 is known to be available everywhere. -+ llvm::Register TCReg = TripCount->getReg(); -+ if (!TCReg.isVirtual()) { -+ if (TCReg != RISCV::X0) { -+ LLVM_DEBUG(dbgs() << "Cannot convert to hwloop: trip count in " -+ "physical register\n"); -+ return Changed; -+ } -+ } else { -+ MachineInstr *TCDef = MRI->getVRegDef(TCReg); -+ MachineBasicBlock *BBDef = TCDef->getParent(); -+ if (!MDT->dominates(BBDef, Preheader)) { -+ LLVM_DEBUG(dbgs() << "Cannot convert to hwloop: induction register not " -+ "available in preheader\n"); -+ return Changed; -+ } - } - } - -diff --git a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp -index debc2cffa47b..cc1bf0298060 100644 ---- a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp -+++ b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp -@@ -2796,7 +2796,13 @@ InstructionCost RISCVTargetLowering::getLMULCost(MVT VT) const { - else - Cost = (LMul * DLenFactor); - } else { -- Cost = divideCeil(VT.getSizeInBits(), Subtarget.getRealMinVLen() / DLenFactor); -+ unsigned DLen = Subtarget.getRealMinVLen() / DLenFactor; -+ // Without any V extension getRealMinVLen() is 0. Return a neutral cost -+ // instead of dividing by zero (fixed PULP SIMD vectors are legal without -+ // RVV). -+ if (DLen == 0) -+ return 1; -+ Cost = divideCeil(VT.getSizeInBits(), DLen); - } - return Cost; - } -diff --git a/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp b/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp -index 416c3cb91b6c..f648f77b6a43 100644 ---- a/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp -+++ b/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp -@@ -1052,8 +1052,12 @@ InstructionCost RISCVTTIImpl::getMemoryOpCost(unsigned Opcode, Type *Src, - // Assume memory ops cost scale with the number of vector registers - // possible accessed by the instruction. Note that BasicTTI already - // handles the LT.first term for us. -+ // LMUL scaling only makes sense with RVV. With the PULP extensions small -+ // fixed vectors (v2s/v4s/v2h) are legal without any V extension; in that -+ // case getRealMinVLen() is 0 and getLMULCost would divide by zero. - if (std::pair LT = getTypeLegalizationCost(Src); -- LT.second.isVector() && CostKind != TTI::TCK_CodeSize) -+ LT.second.isVector() && CostKind != TTI::TCK_CodeSize && -+ ST->hasVInstructions()) - BaseCost *= TLI->getLMULCost(LT.second); - return Cost + BaseCost; - From 356236ed473df5d3a4e80fb06735a1564fb5e7e2 Mon Sep 17 00:00:00 2001 From: marchioa Date: Fri, 30 Oct 2026 16:45:22 +0100 Subject: [PATCH 10/18] disable LLVM assembly files in the toolchain build --- Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/Makefile b/Makefile index 5d83d89b8d..127f98296b 100644 --- a/Makefile +++ b/Makefile @@ -136,6 +136,7 @@ ${LLVM_INSTALL_DIR}: ${TOOLCHAIN_DIR}/llvm-project -DLLVM_ENABLE_TERMINFO="0" \ -DLLVM_OPTIMIZED_TABLEGEN=ON \ -DLLVM_PARALLEL_LINK_JOBS=2 \ + -DLLVM_DISABLE_ASSEMBLY_FILES=ON \ -DCMAKE_BUILD_TYPE=Release \ -DCMAKE_C_COMPILER_LAUNCHER=ccache \ -DCMAKE_CXX_COMPILER_LAUNCHER=ccache \ From 878608b783f6223e859596e274ebf3b9e1bd5a8f Mon Sep 17 00:00:00 2001 From: marchioa Date: Mon, 2 Nov 2026 11:08:02 +0100 Subject: [PATCH 11/18] relax GVSoC markdown-it-py pin to stay compatible with myst-parser --- Container/Dockerfile.deeploy | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Container/Dockerfile.deeploy b/Container/Dockerfile.deeploy index 437e803e3f..78d6b9d932 100644 --- a/Container/Dockerfile.deeploy +++ b/Container/Dockerfile.deeploy @@ -28,6 +28,7 @@ COPY Makefile ./ # Compile emulators # WIESEP: We need to already clean up some space, otherwise the GitHub runners run out of disk space +# GVSoC pins markdown-it-py>=4, but no myst-parser for Python 3.10 (docs) supports it; 3.x works for GVSoC RUN --mount=type=cache,target=/ccache \ ccache -z && \ make pulp-sdk chimera-sdk qemu mempool banshee xtensor && \ @@ -36,6 +37,7 @@ RUN --mount=type=cache,target=/ccache \ cp -r toolchain/gvsoc/gapy/requirements.txt /app/gapy-requirements.txt && \ cp -r toolchain/gvsoc/gvrun/requirements.txt /app/gvrun-requirements.txt && \ cp -r toolchain/gvsoc/config_tree/requirements.txt /app/config-tree-requirements.txt && \ + sed -i 's/^markdown-it-py.*/markdown-it-py>=3.0/' /app/config-tree-requirements.txt && \ rm -rf toolchain/pulp-sdk toolchain/qemu toolchain/mempool toolchain/banshee toolchain/xtensor toolchain/xtl toolchain/xsimd toolchain/gvsoc && \ ccache -s From c01f20a090e64e6ecd266ac0287737adcbfe219d Mon Sep 17 00:00:00 2001 From: marchioa Date: Tue, 3 Nov 2026 11:56:58 +0100 Subject: [PATCH 12/18] minor changes for linting --- TargetLibraries/PULPOpen/inc/DeeployPULPMath.h | 2 +- TargetLibraries/Snitch/inc/kernel/Add.h | 13 +++++-------- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/TargetLibraries/PULPOpen/inc/DeeployPULPMath.h b/TargetLibraries/PULPOpen/inc/DeeployPULPMath.h index 29b7951d08..31dcb8637b 100644 --- a/TargetLibraries/PULPOpen/inc/DeeployPULPMath.h +++ b/TargetLibraries/PULPOpen/inc/DeeployPULPMath.h @@ -31,8 +31,8 @@ #include "kernel/PULPDWConv3x3.h" #include "kernel/PULPPWConv1x1.h" #include "kernel/PULPStemConv3x3.h" -#include "kernel/Relu.h" #include "kernel/RQiHardswish.h" +#include "kernel/Relu.h" #include "kernel/RequantShift.h" #include "kernel/Softmax.h" #include "kernel/UniformRequantShift.h" diff --git a/TargetLibraries/Snitch/inc/kernel/Add.h b/TargetLibraries/Snitch/inc/kernel/Add.h index 3a1ea21e6c..e6cc131a4d 100644 --- a/TargetLibraries/Snitch/inc/kernel/Add.h +++ b/TargetLibraries/Snitch/inc/kernel/Add.h @@ -15,13 +15,10 @@ void Add_fp32(float32_t *input1, float32_t *input2, float32_t *output, void SnitchAdd(int8_t *pIn1, int8_t *pIn2, int32_t *pOut, uint32_t size, int32_t offset); -void snitch_nn_add_i8_i8_i8(int8_t *pIn1, int8_t *pIn2, int8_t *pOut, - int32_t in1_mul, int32_t in1_add, - uint16_t in1_shift, int32_t in2_mul, - int32_t in2_add, uint16_t in2_shift, - int32_t out_mul, int32_t out_add, - uint16_t out_shift, uint16_t dim_im_in_x, - uint16_t dim_im_in_y, uint16_t ch_im_in, - int out_requant_flag); +void snitch_nn_add_i8_i8_i8( + int8_t *pIn1, int8_t *pIn2, int8_t *pOut, int32_t in1_mul, int32_t in1_add, + uint16_t in1_shift, int32_t in2_mul, int32_t in2_add, uint16_t in2_shift, + int32_t out_mul, int32_t out_add, uint16_t out_shift, uint16_t dim_im_in_x, + uint16_t dim_im_in_y, uint16_t ch_im_in, int out_requant_flag); #endif // __DEEPLOY_MATH_ADD_KERNEL_HEADER_ From 28290d1012d7d1bc1fe439a9e6055ec949d16c70 Mon Sep 17 00:00:00 2001 From: marchioa Date: Tue, 3 Nov 2026 15:21:58 +0100 Subject: [PATCH 13/18] update CHANGELOG --- CHANGELOG.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b95e052f40..7eba7f9e9f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,7 @@ This file contains the changelog for the Deeploy project. The changelog is divid - Add SoCDAML Part III: hands-on lab for adding a new int8 operator [#194](https://github.com/pulp-platform/Deeploy/pull/194) - Match GAP9 SDK MLPerf Tiny Performance with Specialised Depthwise and Pointwise Kernels [#206](https://github.com/pulp-platform/Deeploy/pull/206) - Add support for the X-HEEP platform [#200](https://github.com/pulp-platform/Deeploy/pull/200) +- PULP-Open iDMA Support and Tests, and LLVM Update to Clang 20 [#216](https://github.com/pulp-platform/Deeploy/pull/216) ### Added - tests for Regular and DW Conv2D with 3x3 kernel @@ -48,6 +49,10 @@ This file contains the changelog for the Deeploy project. The changelog is divid - Specialised PULPOpen kernels for 3x3 depthwise (`PULPDWConv3x3.c`), 1x1 pointwise (`PULPPWConv1x1.c`) and a three-channel 3x3 stem (`PULPStemConv3x3.c`), with bindings and tile constraints for PULPOpen and GAP9 - Lowering passes `PULPNCHWtoNHWCPwConvPass` and `PULPNCHWtoNHWCConvPass`, keeping a 1x1 convolution's output and a depthwise-feeding stem channels-first so the transposes at depthwise boundaries cancel - X-HEEP platform support, including compilation for FPGA targets and simulation with Verilator. +- iDMA support for PULP-Open (`--dma {mchan,idma}`, default `idma`), with a CMake `PULP_DMA` check +- PULP-Open test suite (`pulpopen` and `pulpopen_tiled` markers), including FP32 tests now that the toolchain supports `zfinx` +- `cmake/clang_resource_dir.cmake` to locate compiler-rt without a hardcoded clang version +- picolibc build for `rv32imc_zfinx` ### Changed - Refactor the topology optimization pass `NeurekaReshapePointwiseConvolutionPass` and Neureka's Tile constraints @@ -67,6 +72,12 @@ This file contains the changelog for the Deeploy project. The changelog is divid - Aligned CLI commands across the project - Added @runwangdl as a code owner - Skip emitting duplicate `testInputVector` data for inputs placed in L3 (loaded at runtime from the readfs hex instead), reducing test binary size +- Move the PULP LLVM toolchain to clang 20.1.8 (`albsposito/llvm-project`, `port/20`), dropping the local crash-fix patch +- Update GVSoC (with the `pulp-open` target) and the PULP SDK +- LLVM toolchains link with `-nostartfiles -nodefaultlibs` and explicit `-lc -lclang_rt.builtins-riscv32`, as clang 20 adds `crt0.o` and links compiler-rt by absolute path +- MemPool toolchain picks `-misched-topdown` or `-misched-prera-direction=topdown` depending on the LLVM version, and disables GlobalMerge to avoid Banshee corrupting unaligned ELF segment tails +- PULP-Open compiles for `rv32imc_zfinx_xpulpv2` (hardware FP32 instead of soft-float) +- Build LLVM with `-DLLVM_DISABLE_ASSEMBLY_FILES=ON` so ccache does not break the BLAKE3 assembly sources ### Fixed - Fix Neureka's output-channels subtile size (in ConvTemplate) and Dense/DW/PW tile constraints @@ -86,6 +97,9 @@ This file contains the changelog for the Deeploy project. The changelog is divid - Fix invalid escape sequence python error in DeeployTypes.py: appearing when using pytest to launch regressions - Fix GAP9 board tests with `--defaultMemLevel L3` reading garbage inputs: place all gapy `--flash-property` options before the positional subcommand and use `image flash run` so the readfs partition (input hex files) is flashed to the device - Fix Deeploy 101 tutorial errors: `--profileTiling` usage and the moved intrinsics inventory path +- Snitch `CycleCounter` no longer places its state in a `.l1` section, which lld put on top of the L3 heap +- `ReshapeTemplate` alias assignment now runs on all cores instead of only under `SINGLE_CORE`, fixing undefined behaviour on the other cores +- Relax GVSoC's `markdown-it-py>=4` pin to `>=3.0` in the container so it can be installed alongside `myst-parser` on Python 3.10 ### Removed - removed experimental `enable3x3` flag, from Neureka Engine. Now, 3x3 mode is enabled by default. From ea7a346a4c2acc000a6962779b026a4f79082ea9 Mon Sep 17 00:00:00 2001 From: marchioa Date: Wed, 4 Nov 2026 18:01:41 +0100 Subject: [PATCH 14/18] [iDMA] split long 1D transfers at runtime, async transfers @petreiuss 1D transfers over 64 KiB are split in pulp_idma_utils.h, so only the 2D row length is limited to 16 bits. Transfers are now non-blocking, with per-direction waits where the data is needed. --- Deeploy/Targets/PULPOpen/DMA/iDMA.py | 109 ++++++++++-------- .../PULPOpen/inc/pulp_idma_utils.h | 70 +++++++++++ 2 files changed, 129 insertions(+), 50 deletions(-) create mode 100644 TargetLibraries/PULPOpen/inc/pulp_idma_utils.h diff --git a/Deeploy/Targets/PULPOpen/DMA/iDMA.py b/Deeploy/Targets/PULPOpen/DMA/iDMA.py index 1487b30ebe..ca00ad2e89 100644 --- a/Deeploy/Targets/PULPOpen/DMA/iDMA.py +++ b/Deeploy/Targets/PULPOpen/DMA/iDMA.py @@ -1,81 +1,90 @@ # Copyright (c) 2025 FondazioneChipsIT # SPDX-License-Identifier: Apache-2.0 -import math -from typing import Dict, Tuple +from typing import Dict, Optional, Tuple from Deeploy.DeeployTypes import NetworkContext, NodeTemplate, OperatorRepresentation, VariableBuffer from Deeploy.TilingExtension.AsyncDma import AsyncDma, DirectionWaitingStrategy, DmaDirection, Future +# HAL pulp_cl_idma_* calls take the (row) length as unsigned short; +# 1D goes through deeploy_idma_transfer_1d (pulp_idma_utils.h), split at runtime +_MAX_LEN = 2**16 - 1 + +# Direction encoding expected by the deeploy_idma_transfer_* helpers in +# pulp_idma_utils.h (`direction == 1` means L2 -> L1): keep the two in sync +_DIR_EXT_TO_LOC = 1 +_DIR_LOC_TO_EXT = 0 + class iDMAChannelFuture(Future): _initTemplate = NodeTemplate("") _deinitTemplate = NodeTemplate("") - _waitTemplate = NodeTemplate("") + _waitTemplate = NodeTemplate("deeploy_idma_wait_${name}();") _allocTemplate = NodeTemplate("") class iDMA(AsyncDma): - includeList = ["pulp_core.h"] + includeList = ["pulp_core.h", "pulp_idma_utils.h"] _transferTemplates = { 1: - NodeTemplate( - "pulp_idma_transfer_1d_and_wait(${direction}, (unsigned int)${ext}, (unsigned int)${loc}, ${length});"), + NodeTemplate("deeploy_idma_transfer_1d(${direction}, " + "(unsigned int)${ext}, (unsigned int)${loc}, ${length});"), 2: - NodeTemplate( - "pulp_idma_transfer_2d_and_wait(${direction}, (unsigned int)${ext}, (unsigned int)${loc}, ${length}, ${strideExt}, ${strideLoc}, ${num_reps});" - ) + NodeTemplate("deeploy_idma_transfer_2d(${direction}, (unsigned int)${ext}, " + "(unsigned int)${loc}, ${length}, ${strideExt}, ${strideLoc}, " + "${num_reps});") } _waitingStrategy = DirectionWaitingStrategy(iDMAChannelFuture, "channel_id") - def __init__(self, transferTemplates: Dict[int, NodeTemplate] = _transferTemplates) -> None: + def __init__( + self, + transferTemplates: Optional[Dict[int, NodeTemplate]] = None, + ) -> None: + if transferTemplates is None: + transferTemplates = dict(type(self)._transferTemplates) super().__init__(transferTemplates) - def checkTransfer(self, ctxt: NetworkContext, externalBuffer: VariableBuffer, localBuffer: VariableBuffer, - shape: Tuple[int, ...], strideExt: Tuple[int, ...], strideLoc: Tuple[int, ...], - direction: DmaDirection) -> None: - super().checkTransfer(ctxt, externalBuffer, localBuffer, shape, strideExt, strideLoc, direction) - - # Here are some assertions on the iDMA transfer parameters - transferRank = len(shape) + def checkTransfer( + self, + ctxt: NetworkContext, + externalBuffer: VariableBuffer, + localBuffer: VariableBuffer, + shape: Tuple[int, ...], + strideExt: Tuple[int, ...], + strideLoc: Tuple[int, ...], + direction: DmaDirection, + ) -> None: - assert transferRank == 1 or transferRank == 2, "Only 1D and 2D transfers are supported for now" - - if transferRank == 1: - length = shape[0] - elif transferRank == 2: + super().checkTransfer(ctxt, externalBuffer, localBuffer, shape, strideExt, strideLoc, direction) + assert len(shape) in (1, 2), "Only 1D and 2D transfers are supported for now" + # 1D is split at runtime; in 2D the row length is 16-bit: + if len(shape) == 2: length = shape[1] - - iDMA_transfer_size = math.prod(shape) - - assert iDMA_transfer_size <= 2**16, ( - "iDMA transfer size should be representable with 16 bits, " - f"current number of bits required is {math.ceil(math.log2(iDMA_transfer_size))}") - - if transferRank == 2: + assert length <= _MAX_LEN, (f"iDMA row length {length} exceeds the HAL's 16-bit limit ({_MAX_LEN})") assert strideExt[0] >= length, "External stride must be at least equal to the length" assert strideLoc[0] >= length, "Local stride must be at least equal to the length" - def transferOpRepr(self, externalBuffer: VariableBuffer, localBuffer: VariableBuffer, shape: Tuple[int, ...], - strideExt: Tuple[int, ...], strideLoc: Tuple[int, ...], direction: DmaDirection, - future: Future) -> OperatorRepresentation: - operatorRepresentation = super().transferOpRepr(externalBuffer, localBuffer, shape, strideExt, strideLoc, - direction, future) - - transferRank = len(shape) - operatorRepresentation["direction"] = 1 if direction == "ExternalToLocal" else 0 - - iDMA_transfer_size = math.prod(shape) - - if transferRank == 1: - operatorRepresentation["length"] = shape[0] - elif transferRank == 2: - operatorRepresentation["length"] = shape[1] - operatorRepresentation["strideExt"] = strideExt[0] - operatorRepresentation["strideLoc"] = strideLoc[0] - operatorRepresentation["num_reps"] = iDMA_transfer_size // shape[1] - - return operatorRepresentation + def transferOpRepr( + self, + externalBuffer: VariableBuffer, + localBuffer: VariableBuffer, + shape: Tuple[int, ...], + strideExt: Tuple[int, ...], + strideLoc: Tuple[int, ...], + direction: DmaDirection, + future: Future, + ) -> OperatorRepresentation: + + opRepr = super().transferOpRepr(externalBuffer, localBuffer, shape, strideExt, strideLoc, direction, future) + + opRepr["direction"] = _DIR_EXT_TO_LOC if direction == "ExternalToLocal" else _DIR_LOC_TO_EXT + opRepr["length"] = shape[-1] + if len(shape) == 2: + opRepr["strideExt"] = strideExt[0] + opRepr["strideLoc"] = strideLoc[0] + opRepr["num_reps"] = shape[0] + + return opRepr diff --git a/TargetLibraries/PULPOpen/inc/pulp_idma_utils.h b/TargetLibraries/PULPOpen/inc/pulp_idma_utils.h new file mode 100644 index 0000000000..673cec8489 --- /dev/null +++ b/TargetLibraries/PULPOpen/inc/pulp_idma_utils.h @@ -0,0 +1,70 @@ +/* + * SPDX-FileCopyrightText: 2026 ETH Zurich, University of Bologna and + * Fondazione Chips-IT + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef __PULP_IDMA_UTILS_H__ +#define __PULP_IDMA_UTILS_H__ + +#include "pmsis.h" + +// HAL length is unsigned short: split long 1D transfers at runtime, so every +// tile shares one call shape. Word-aligned chunks keep the offsets aligned. +#define DEEPLOY_IDMA_CHUNK (0xFFFFu & ~3u) + +static inline void deeploy_idma_transfer_1d_and_wait(unsigned int direction, + unsigned int ext, + unsigned int loc, + unsigned int size) { + while (size > 0xFFFFu) { + pulp_idma_transfer_1d_and_wait(direction, ext, loc, DEEPLOY_IDMA_CHUNK); + ext += DEEPLOY_IDMA_CHUNK; + loc += DEEPLOY_IDMA_CHUNK; + size -= DEEPLOY_IDMA_CHUNK; + } + pulp_idma_transfer_1d_and_wait(direction, ext, loc, (unsigned short)size); +} + +// Asynchronous variants: start the transfer and return. Completion is awaited +// per direction (the iDMA keeps one transfer ID counter per direction), with +// deeploy_idma_wait_channel_id_input/output, where the data is needed. +static inline void deeploy_idma_transfer_1d(unsigned int direction, + unsigned int ext, unsigned int loc, + unsigned int size) { + while (size > 0) { + unsigned int len = size > 0xFFFFu ? DEEPLOY_IDMA_CHUNK : size; + if (direction == 1) { + pulp_cl_idma_L2ToL1(ext, loc, (unsigned short)len); + } else { + pulp_cl_idma_L1ToL2(loc, ext, (unsigned short)len); + } + ext += len; + loc += len; + size -= len; + } +} + +static inline void deeploy_idma_transfer_2d(unsigned int direction, + unsigned int ext, unsigned int loc, + unsigned short size, + unsigned int stride_ext, + unsigned int stride_loc, + unsigned int num_reps) { + if (direction == 1) { + pulp_cl_idma_L2ToL1_2d(ext, loc, size, stride_ext, stride_loc, num_reps); + } else { + pulp_cl_idma_L1ToL2_2d(loc, ext, size, stride_loc, stride_ext, num_reps); + } +} + +static inline void deeploy_idma_wait_channel_id_input(void) { + plp_cl_dma_barrier_toL1(); +} + +static inline void deeploy_idma_wait_channel_id_output(void) { + plp_cl_dma_barrier_toL2(); +} + +#endif // __PULP_IDMA_UTILS_H__ From a33d7e268a767330a557721ad4ebba67ba8ed95c Mon Sep 17 00:00:00 2001 From: marchioa Date: Wed, 4 Nov 2026 19:18:42 +0100 Subject: [PATCH 15/18] [iDMA] add support for 3D transfers --- Deeploy/Targets/PULPOpen/DMA/iDMA.py | 31 ++++++++++++------- .../PULPOpen/inc/pulp_idma_utils.h | 22 +++++++++++++ 2 files changed, 42 insertions(+), 11 deletions(-) diff --git a/Deeploy/Targets/PULPOpen/DMA/iDMA.py b/Deeploy/Targets/PULPOpen/DMA/iDMA.py index ca00ad2e89..8d6954d9f1 100644 --- a/Deeploy/Targets/PULPOpen/DMA/iDMA.py +++ b/Deeploy/Targets/PULPOpen/DMA/iDMA.py @@ -35,7 +35,11 @@ class iDMA(AsyncDma): 2: NodeTemplate("deeploy_idma_transfer_2d(${direction}, (unsigned int)${ext}, " "(unsigned int)${loc}, ${length}, ${strideExt}, ${strideLoc}, " - "${num_reps});") + "${num_reps});"), + 3: + NodeTemplate("deeploy_idma_transfer_3d(${direction}, (unsigned int)${ext}, " + "(unsigned int)${loc}, ${length}, ${strideExt}, ${strideLoc}, " + "${num_reps}, ${strideExt_3d}, ${strideLoc_3d}, ${num_reps_3d});") } _waitingStrategy = DirectionWaitingStrategy(iDMAChannelFuture, "channel_id") @@ -59,13 +63,12 @@ def checkTransfer( ) -> None: super().checkTransfer(ctxt, externalBuffer, localBuffer, shape, strideExt, strideLoc, direction) - assert len(shape) in (1, 2), "Only 1D and 2D transfers are supported for now" - # 1D is split at runtime; in 2D the row length is 16-bit: - if len(shape) == 2: - length = shape[1] + # 1D is split at runtime; in 2D/3D the row length is 16-bit (strides and reps are 32-bit) + if len(shape) >= 2: + length = shape[-1] assert length <= _MAX_LEN, (f"iDMA row length {length} exceeds the HAL's 16-bit limit ({_MAX_LEN})") - assert strideExt[0] >= length, "External stride must be at least equal to the length" - assert strideLoc[0] >= length, "Local stride must be at least equal to the length" + assert strideExt[-2] >= length, "External stride must be at least equal to the length" + assert strideLoc[-2] >= length, "Local stride must be at least equal to the length" def transferOpRepr( self, @@ -82,9 +85,15 @@ def transferOpRepr( opRepr["direction"] = _DIR_EXT_TO_LOC if direction == "ExternalToLocal" else _DIR_LOC_TO_EXT opRepr["length"] = shape[-1] - if len(shape) == 2: - opRepr["strideExt"] = strideExt[0] - opRepr["strideLoc"] = strideLoc[0] - opRepr["num_reps"] = shape[0] + # 2nd dimension (rows): stride between rows and number of rows + if len(shape) >= 2: + opRepr["strideExt"] = strideExt[-2] + opRepr["strideLoc"] = strideLoc[-2] + opRepr["num_reps"] = shape[-2] + # 3rd dimension (planes): stride between planes and number of planes + if len(shape) == 3: + opRepr["strideExt_3d"] = strideExt[-3] + opRepr["strideLoc_3d"] = strideLoc[-3] + opRepr["num_reps_3d"] = shape[-3] return opRepr diff --git a/TargetLibraries/PULPOpen/inc/pulp_idma_utils.h b/TargetLibraries/PULPOpen/inc/pulp_idma_utils.h index 673cec8489..d3820136fb 100644 --- a/TargetLibraries/PULPOpen/inc/pulp_idma_utils.h +++ b/TargetLibraries/PULPOpen/inc/pulp_idma_utils.h @@ -59,6 +59,28 @@ static inline void deeploy_idma_transfer_2d(unsigned int direction, } } +// Rows of `size` bytes, `num_reps` rows per plane, `num_reps_3d` planes. +// stride_*_3d are plane-to-plane strides, but the iDMA (idma_nd_midend) adds +// the 3D stride to the address of the last row of a plane, not to its start: +// convert them. Unsigned wrap-around handles negative results. +static inline void +deeploy_idma_transfer_3d(unsigned int direction, unsigned int ext, + unsigned int loc, unsigned short size, + unsigned int stride_ext, unsigned int stride_loc, + unsigned int num_reps, unsigned int stride_ext_3d, + unsigned int stride_loc_3d, unsigned int num_reps_3d) { + unsigned int last_row = num_reps - 1; + stride_ext_3d -= last_row * stride_ext; + stride_loc_3d -= last_row * stride_loc; + if (direction == 1) { + pulp_cl_idma_L2ToL1_3d(ext, loc, size, stride_ext, stride_loc, num_reps, + stride_ext_3d, stride_loc_3d, num_reps_3d); + } else { + pulp_cl_idma_L1ToL2_3d(loc, ext, size, stride_loc, stride_ext, num_reps, + stride_loc_3d, stride_ext_3d, num_reps_3d); + } +} + static inline void deeploy_idma_wait_channel_id_input(void) { plp_cl_dma_barrier_toL1(); } From 301b01c9c9e2ca3049785f4bef6903dea8245dfc Mon Sep 17 00:00:00 2001 From: marchioa Date: Thu, 5 Nov 2026 09:40:40 +0100 Subject: [PATCH 16/18] [MCHAN] split transfers longer than the 17-bit length - @petreiuss Transfers over 2^17 - 1 bytes are issued as several commands on the same channel (mchan_transfer_*_split), so one channel wait still covers them. --- CHANGELOG.md | 1 + Deeploy/Targets/PULPOpen/DMA/MchanDma.py | 22 +++++++++----- TargetLibraries/PULPOpen/inc/mchan_v7.h | 38 ++++++++++++++++++++++++ 3 files changed, 54 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7eba7f9e9f..bfac2c16b0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -100,6 +100,7 @@ This file contains the changelog for the Deeploy project. The changelog is divid - Snitch `CycleCounter` no longer places its state in a `.l1` section, which lld put on top of the L3 heap - `ReshapeTemplate` alias assignment now runs on all cores instead of only under `SINGLE_CORE`, fixing undefined behaviour on the other cores - Relax GVSoC's `markdown-it-py>=4` pin to `>=3.0` in the container so it can be installed alongside `myst-parser` on Python 3.10 +- `MchanDma` splits transfers longer than the 17-bit mchan length into several commands instead of asserting ### Removed - removed experimental `enable3x3` flag, from Neureka Engine. Now, 3x3 mode is enabled by default. diff --git a/Deeploy/Targets/PULPOpen/DMA/MchanDma.py b/Deeploy/Targets/PULPOpen/DMA/MchanDma.py index 41b8a368b7..ec85e72b26 100644 --- a/Deeploy/Targets/PULPOpen/DMA/MchanDma.py +++ b/Deeploy/Targets/PULPOpen/DMA/MchanDma.py @@ -29,9 +29,16 @@ class MchanDma(AsyncDma): includeList = ["mchan_siracusa.h"] + # The *_split helpers (mchan_v7.h) issue one command per 2^17 - 1 bytes on + # the same channel, so transfers longer than the 17-bit mchan length work + # too. The size can differ per tile, so the split is decided at runtime: a + # transfer that fits is still a single command. _transferTemplates = { - 1: NodeTemplate("mchan_transfer_1d(${cmd}, ${loc}, ${ext});"), - 2: NodeTemplate("mchan_transfer_2d_ext_strided(${cmd}, ${loc}, ${ext}, ${size_1d}, ${stride_2d});"), + 1: + NodeTemplate("mchan_transfer_1d_split(${flags}, ${size}, ${loc}, ${ext});"), + 2: + NodeTemplate( + "mchan_transfer_2d_ext_strided_split(${flags}, ${size}, ${loc}, ${ext}, ${size_1d}, ${stride_2d});"), } _waitingStrategy = DirectionWaitingStrategy(MchanChannelFuture, "channel") @@ -67,12 +74,13 @@ def transferOpRepr(self, externalBuffer: VariableBuffer, localBuffer: VariableBu mchanFlags += (1 << 3) # event enable mchanTransferSize = math.prod(shape) - mchanTransferSizeBits = math.ceil(math.log2(mchanTransferSize)) - assert mchanTransferSizeBits <= 17, ( - "The transfer size is not representable with 17 bits. " - f"Received transfer size {mchanTransferSize} that requires {mchanTransferSizeBits}") + mchanMaxLen = (1 << 17) - 1 + if transferRank == 2: + assert shape[1] <= mchanMaxLen, ( + f"A 2D mchan row of {shape[1]} bytes does not fit in one command (max {mchanMaxLen})") - operatorRepresentation["cmd"] = (mchanFlags << 17) + mchanTransferSize + operatorRepresentation["flags"] = mchanFlags + operatorRepresentation["size"] = mchanTransferSize if transferRank == 2: operatorRepresentation["size_1d"] = shape[1] diff --git a/TargetLibraries/PULPOpen/inc/mchan_v7.h b/TargetLibraries/PULPOpen/inc/mchan_v7.h index 32ef836f34..5753e7b1cd 100644 --- a/TargetLibraries/PULPOpen/inc/mchan_v7.h +++ b/TargetLibraries/PULPOpen/inc/mchan_v7.h @@ -94,6 +94,44 @@ static void mchan_transfer_2d_loc_strided_ext_strided( *cmd_ptr = (uint32_t)loc_stride_2d; } +// One mchan command moves at most 2^17 - 1 bytes (17-bit length field). Longer +// transfers are split into several commands: they all count on the channel +// allocated last, whose byte counter covers them all, so a single +// mchan_channel_wait() still waits for the whole transfer. noinline: one copy +// serves all transfer sites (inlining them costs about 16 KB of L2 code). +#define MCHAN_CMD_MAX_LEN ((1u << 17) - 1) +#define MCHAN_CMD_CHUNK_1D (MCHAN_CMD_MAX_LEN & ~3u) + +static __attribute__((noinline)) void +mchan_transfer_1d_split(uint32_t flags, uint32_t size, void *loc, void *ext) { + while (size > MCHAN_CMD_MAX_LEN) { + mchan_transfer_1d((flags << 17) | MCHAN_CMD_CHUNK_1D, loc, ext); + loc = (char *)loc + MCHAN_CMD_CHUNK_1D; + ext = (char *)ext + MCHAN_CMD_CHUNK_1D; + size -= MCHAN_CMD_CHUNK_1D; + } + mchan_transfer_1d((flags << 17) | size, loc, ext); +} + +// Whole rows per command: local memory is contiguous, external rows are strided +static __attribute__((noinline)) void +mchan_transfer_2d_ext_strided_split(uint32_t flags, uint32_t size, void *loc, + void *ext, uint32_t ext_size_1d, + uint32_t ext_stride_2d) { + uint32_t rows = size / ext_size_1d; + uint32_t rows_per_cmd = MCHAN_CMD_MAX_LEN / ext_size_1d; + while (rows > rows_per_cmd) { + uint32_t chunk = rows_per_cmd * ext_size_1d; + mchan_transfer_2d_ext_strided((flags << 17) | chunk, loc, ext, ext_size_1d, + ext_stride_2d); + loc = (char *)loc + chunk; + ext = (char *)ext + rows_per_cmd * ext_stride_2d; + rows -= rows_per_cmd; + } + mchan_transfer_2d_ext_strided((flags << 17) | (rows * ext_size_1d), loc, ext, + ext_size_1d, ext_stride_2d); +} + static uint32_t mchan_channel_alloc() { return *cmd_ptr; } static void mchan_channel_free(uint32_t channel_id) { From 7140376a651e1d0e7cdf274d39304beb061e1a9f Mon Sep 17 00:00:00 2001 From: marchioa Date: Thu, 5 Nov 2026 10:20:57 +0100 Subject: [PATCH 17/18] [CI] pin Python 3.11 in the documentation workflow --- .github/workflows/infra-generate-documentation.yml | 2 ++ CHANGELOG.md | 1 + 2 files changed, 3 insertions(+) diff --git a/.github/workflows/infra-generate-documentation.yml b/.github/workflows/infra-generate-documentation.yml index de42648f63..36a48be5d2 100644 --- a/.github/workflows/infra-generate-documentation.yml +++ b/.github/workflows/infra-generate-documentation.yml @@ -23,6 +23,8 @@ jobs: steps: - uses: actions/checkout@v4 - uses: actions/setup-python@v5 + with: + python-version: "3.11" - name: Install dependencies run: | pip install . diff --git a/CHANGELOG.md b/CHANGELOG.md index bfac2c16b0..35a897ee3e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -101,6 +101,7 @@ This file contains the changelog for the Deeploy project. The changelog is divid - `ReshapeTemplate` alias assignment now runs on all cores instead of only under `SINGLE_CORE`, fixing undefined behaviour on the other cores - Relax GVSoC's `markdown-it-py>=4` pin to `>=3.0` in the container so it can be installed alongside `myst-parser` on Python 3.10 - `MchanDma` splits transfers longer than the 17-bit mchan length into several commands instead of asserting +- Pin Python 3.11 in the documentation workflow, as the unpinned `setup-python` picked the runner's Python 3.14, which `numpy<2.0.0` does not support ### Removed - removed experimental `enable3x3` flag, from Neureka Engine. Now, 3x3 mode is enabled by default. From df212191ab1ca0ab7d1b0f7a92e2f57139b2ae26 Mon Sep 17 00:00:00 2001 From: marchioa Date: Fri, 13 Nov 2026 17:44:03 +0100 Subject: [PATCH 18/18] [FIX] minor fixes to deeployRunners for pulpopen --- DeeployTest/deeployRunner_pulpopen.py | 1 + DeeployTest/deeployRunner_tiled_pulpopen.py | 1 + DeeployTest/testUtils/deeployRunner.py | 4 ++++ 3 files changed, 6 insertions(+) diff --git a/DeeployTest/deeployRunner_pulpopen.py b/DeeployTest/deeployRunner_pulpopen.py index 1a961b5ac8..7a5bdeee72 100644 --- a/DeeployTest/deeployRunner_pulpopen.py +++ b/DeeployTest/deeployRunner_pulpopen.py @@ -13,6 +13,7 @@ def setup_parser(parser): parser.add_argument('--cores', type = int, default = 8, help = 'Number of cores (default: 8)\n') parser.add_argument('--dma', + type = str, choices = ['mchan', 'idma'], default = 'idma', help = 'Cluster DMA engine (default: idma)\n') diff --git a/DeeployTest/deeployRunner_tiled_pulpopen.py b/DeeployTest/deeployRunner_tiled_pulpopen.py index e44193a48a..59e858951f 100644 --- a/DeeployTest/deeployRunner_tiled_pulpopen.py +++ b/DeeployTest/deeployRunner_tiled_pulpopen.py @@ -13,6 +13,7 @@ def setup_parser(parser): parser.add_argument('--cores', type = int, default = 8, help = 'Number of cores (default: 8)\n') parser.add_argument('--dma', + type = str, choices = ['mchan', 'idma'], default = 'idma', help = 'Cluster DMA engine (default: idma)\n') diff --git a/DeeployTest/testUtils/deeployRunner.py b/DeeployTest/testUtils/deeployRunner.py index fa0e36b4e1..bd3dfbaa43 100644 --- a/DeeployTest/testUtils/deeployRunner.py +++ b/DeeployTest/testUtils/deeployRunner.py @@ -61,6 +61,7 @@ def __init__(self, default = None, help = 'Target platform (e.g., Generic, QEMU-ARM, Siracusa, Snitch)\n') self.add_argument('-s', + '--simulator', metavar = '', dest = 'simulator', type = str, @@ -258,6 +259,9 @@ def create_config_from_args(args: argparse.Namespace, if getattr(args, 'dma', None): gen_args_list.append(f"--dma={args.dma}") + if getattr(args, 'cores', None): + gen_args_list.append(f"--cores={args.cores}") + config = DeeployTestConfig( test_name = test_name, test_dir = test_dir_abs,