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 b95e052f40..35a897ee3e 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,11 @@ 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 +- `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. diff --git a/Container/Dockerfile.deeploy b/Container/Dockerfile.deeploy index 2b717e49ec..78d6b9d932 100644 --- a/Container/Dockerfile.deeploy +++ b/Container/Dockerfile.deeploy @@ -28,12 +28,16 @@ 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 && \ 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 && \ + 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 @@ -133,8 +137,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/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/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/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/PULPOpen/DMA/MchanDma.py b/Deeploy/Targets/PULPOpen/DMA/MchanDma.py index 93bf699dc6..ec85e72b26 100644 --- a/Deeploy/Targets/PULPOpen/DMA/MchanDma.py +++ b/Deeploy/Targets/PULPOpen/DMA/MchanDma.py @@ -27,9 +27,18 @@ class MchanChannelFuture(Future): 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") @@ -65,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/Deeploy/Targets/PULPOpen/DMA/iDMA.py b/Deeploy/Targets/PULPOpen/DMA/iDMA.py new file mode 100644 index 0000000000..8d6954d9f1 --- /dev/null +++ b/Deeploy/Targets/PULPOpen/DMA/iDMA.py @@ -0,0 +1,99 @@ +# Copyright (c) 2025 FondazioneChipsIT +# SPDX-License-Identifier: Apache-2.0 + +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("deeploy_idma_wait_${name}();") + _allocTemplate = NodeTemplate("") + + +class iDMA(AsyncDma): + + includeList = ["pulp_core.h", "pulp_idma_utils.h"] + + _transferTemplates = { + 1: + NodeTemplate("deeploy_idma_transfer_1d(${direction}, " + "(unsigned int)${ext}, (unsigned int)${loc}, ${length});"), + 2: + NodeTemplate("deeploy_idma_transfer_2d(${direction}, (unsigned int)${ext}, " + "(unsigned int)${loc}, ${length}, ${strideExt}, ${strideLoc}, " + "${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") + + 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) + # 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[-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, + 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] + # 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/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/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/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..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 @@ -98,10 +99,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/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/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 new file mode 100644 index 0000000000..7a5bdeee72 --- /dev/null +++ b/DeeployTest/deeployRunner_pulpopen.py @@ -0,0 +1,25 @@ +#!/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', + type = str, + choices = ['mchan', 'idma'], + default = 'idma', + help = 'Cluster DMA engine (default: idma)\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..59e858951f --- /dev/null +++ b/DeeployTest/deeployRunner_tiled_pulpopen.py @@ -0,0 +1,25 @@ +#!/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', + type = str, + choices = ['mchan', 'idma'], + default = 'idma', + help = 'Cluster DMA engine (default: idma)\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/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/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..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, @@ -255,6 +256,12 @@ 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}") + + if getattr(args, 'cores', None): + gen_args_list.append(f"--cores={args.cores}") + config = DeeployTestConfig( test_name = test_name, test_dir = test_dir_abs, @@ -363,13 +370,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 +418,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 +432,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..79cae7550b 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 "idma" + 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}") 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..7162308997 --- /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..67418205fc --- /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], # 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], + "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..127f98296b 100644 --- a/Makefile +++ b/Makefile @@ -10,19 +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 +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/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 +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 @@ -43,13 +47,14 @@ GAP9_SDK_INSTALL_DIR ?= ${DEEPLOY_INSTALL_DIR}/gap9-sdk CMAKE ?= cmake -LLVM_COMMIT_HASH ?= 1ccb97ef1789b8c574e3fcab0de674e11b189b96 +LLVM_REPO ?= https://github.com/albsposito/llvm-project.git +LLVM_COMMIT_HASH ?= 2dcfd2de54d93d239bde88dd0a57fce15396810e 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 @@ -114,7 +119,7 @@ ${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 @@ -131,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 \ @@ -148,7 +154,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 \ @@ -180,7 +186,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 \ @@ -212,7 +218,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 \ @@ -244,7 +250,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 \ @@ -277,7 +283,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 \ @@ -312,7 +318,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 \ @@ -413,12 +419,25 @@ ${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} && \ 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 +487,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/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/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/TargetLibraries/PULPOpen/inc/DeeployPULPMath.h b/TargetLibraries/PULPOpen/inc/DeeployPULPMath.h index 64a5ca24ba..31dcb8637b 100644 --- a/TargetLibraries/PULPOpen/inc/DeeployPULPMath.h +++ b/TargetLibraries/PULPOpen/inc/DeeployPULPMath.h @@ -32,9 +32,11 @@ #include "kernel/PULPPWConv1x1.h" #include "kernel/PULPStemConv3x3.h" #include "kernel/RQiHardswish.h" +#include "kernel/Relu.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" 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) { diff --git a/TargetLibraries/PULPOpen/inc/pulp_idma_utils.h b/TargetLibraries/PULPOpen/inc/pulp_idma_utils.h new file mode 100644 index 0000000000..d3820136fb --- /dev/null +++ b/TargetLibraries/PULPOpen/inc/pulp_idma_utils.h @@ -0,0 +1,92 @@ +/* + * 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); + } +} + +// 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(); +} + +static inline void deeploy_idma_wait_channel_id_output(void) { + plp_cl_dma_barrier_toL2(); +} + +#endif // __PULP_IDMA_UTILS_H__ 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..e6cc131a4d 100644 --- a/TargetLibraries/Snitch/inc/kernel/Add.h +++ b/TargetLibraries/Snitch/inc/kernel/Add.h @@ -12,4 +12,13 @@ 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/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/chimera/toolchain_llvm.cmake b/cmake/chimera/toolchain_llvm.cmake index 6e613c0cb9..881eb12c89 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) @@ -39,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 ) @@ -50,7 +54,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/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 3340daf460..db736e7217 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) @@ -18,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() @@ -31,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 @@ -75,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${TOOLCHAIN_INSTALL_DIR}/lib/clang/15.0.0/lib/baremetal/rv32ima/ + -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 cf3fb80d6c..233f56e7a6 100644 --- a/cmake/pulp/toolchain_llvm.cmake +++ b/cmake/pulp/toolchain_llvm.cmake @@ -9,12 +9,25 @@ 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) 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 +36,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 +44,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 ) @@ -40,17 +53,22 @@ add_link_options( -target riscv32-unknown-elf -MP -nostartfiles + -nodefaultlibs -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${CLANG_RESOURCE_DIR}/lib/baremetal/${RT_ISA}/ -z norelro -fno-builtin-memcpy -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/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( 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) + 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'