Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ name: test
# smoke - correctness: dotnet test + corpus smoke on every platform / ISA tier (+ Metal)
# bench - performance: corpus benchmark (.github/scripts/bench.ps1), several replicas per platform
# report - merges every result into the run summary (tests/Sdcb.SimdGcdrNet.TestReport)
# Job budget: 35 jobs (40 concurrent); macOS: 2 smoke + 3 bench (5 concurrent).
# Job budget: 36 jobs (40 concurrent); macOS: 2 smoke + 3 bench (5 concurrent).

on:
push:
Expand Down Expand Up @@ -33,6 +33,9 @@ concurrency:

env:
DOTNET_NOLOGO: 1
# jobs build against the pinned Sdcb.SimdOnnx package (what ships); the engine-head smoke builds
# sdcb/SimdOnnx main from source next to this checkout (MSBuild reads env vars as properties)
SimdOnnxProject: ${{ github.workspace }}/_simdonnx/src/Sdcb.SimdOnnx/Sdcb.SimdOnnx.csproj
DOTNET_CLI_TELEMETRY_OPTOUT: 1
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1

Expand All @@ -57,11 +60,15 @@ jobs:
name: smoke ${{ matrix.name }}
runs-on: ${{ matrix.os }}
timeout-minutes: 30
env:
UseLocalSimdOnnx: ${{ matrix.enginehead && 'true' || 'false' }}
strategy:
fail-fast: false
matrix:
include:
- { name: win-x64, os: windows-2025, count: 5 }
# the same tests against sdcb/SimdOnnx main from source: engine changes that break this library
- { name: linux-x64-engine-head, os: ubuntu-24.04, count: 2, enginehead: true }
- { name: win-arm64, os: windows-11-arm, count: 5 }
- { name: linux-x64, os: ubuntu-24.04, count: 5, pack: true }
- { name: linux-arm64, os: ubuntu-24.04-arm, count: 5 }
Expand All @@ -77,6 +84,9 @@ jobs:
- { name: linux-arm64-scalar, os: ubuntu-24.04-arm, count: 2, maxmp: 1, isa: DOTNET_EnableHWIntrinsic=0 }
steps:
- uses: actions/checkout@v7
- uses: actions/checkout@v7
if: matrix.enginehead
with: { repository: sdcb/SimdOnnx, path: _simdonnx }
- uses: actions/download-artifact@v8
with: { name: realdae, path: tests/testdata/realdae }
- name: Build
Expand Down
11 changes: 9 additions & 2 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,15 @@
never force a models release). Edit here and keep build/00-common.linq in sync.
-->
<PropertyGroup>
<SdcbSimdGcdrNetVersion Condition="'$(SdcbSimdGcdrNetVersion)' == ''">1.0.0</SdcbSimdGcdrNetVersion>
<SdcbSimdGcdrNetVersion Condition="'$(SdcbSimdGcdrNetVersion)' == ''">2.0.0</SdcbSimdGcdrNetVersion>
<SdcbSimdGcdrNetModelsVersion Condition="'$(SdcbSimdGcdrNetModelsVersion)' == ''">1.0.0</SdcbSimdGcdrNetModelsVersion>
<!-- Engine package (exact pin: the library builds against engine internals). UseLocalSimdOnnx=true
switches to ../Sdcb.SimdOnnx as a project reference for side-by-side development. -->
<SdcbSimdOnnxVersion Condition="'$(SdcbSimdOnnxVersion)' == ''">0.1.0-preview.4</SdcbSimdOnnxVersion>
<SimdOnnxProject Condition="'$(SimdOnnxProject)' == ''">$(MSBuildThisFileDirectory)..\Sdcb.SimdOnnx\src\Sdcb.SimdOnnx\Sdcb.SimdOnnx.csproj</SimdOnnxProject>
<!-- a stable package pinned to an engine preview (NU5104): accepted while the engine is a preview on
the ProGet test feed; a nuget.org release of this package needs the engine released first -->
<NoWarn Condition="$(SdcbSimdOnnxVersion.Contains('-'))">$(NoWarn);NU5104</NoWarn>
</PropertyGroup>

<PropertyGroup>
Expand Down Expand Up @@ -39,7 +46,7 @@
<PackageId>Sdcb.SimdGcdrNet</PackageId>
<Version>$(SdcbSimdGcdrNetVersion)</Version>
<IsPackable>true</IsPackable>
<Description>Pure C# GCDRNet inference: document image shadow removal / appearance enhancement. Self-contained ONNX graph engine with CPU SIMD (AVX-512/AVX2/NEON/Vector) and GPU (Vulkan, Metal) backends; no onnxruntime dependency. Accepts interleaved BGR24 / RGB24 / BGRA32 / RGBA32. Models ship separately in Sdcb.SimdGcdrNet.Models.</Description>
<Description>Pure C# GCDRNet inference: document image shadow removal / appearance enhancement. Runs on the pure C# Sdcb.SimdOnnx engine (CPU SIMD AVX-512/AVX2/NEON/Vector, GPU Vulkan/Metal) with GCDRNet-specific fused kernels; no onnxruntime dependency. Accepts interleaved BGR24 / RGB24 / BGRA32 / RGBA32. Models ship separately in Sdcb.SimdGcdrNet.Models.</Description>
<PackageTags>Sdcb;GCDRNet;document;document-enhancement;shadow-removal;image-enhancement;onnx;inference;deep-learning;SIMD;AVX512;NEON;wasm;AOT;Vulkan;Metal;linqpad-samples</PackageTags>
</PropertyGroup>
<PropertyGroup Condition="'$(MSBuildProjectName)' == 'Sdcb.SimdGcdrNet.Models'">
Expand Down
41 changes: 22 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
**Sdcb.SimdGcdrNet** is a pure C# implementation of [GCDRNet](https://github.com/ZZZHANG-jx/GCDRNet)
(*Appearance Enhancement for Camera-captured Document Images in the Wild*, IEEE TAI 2023) —
document-image shadow removal and appearance enhancement **without onnxruntime or any other
third-party inference engine**. It ships its own compiled-model inference engine, inspired by
`Sdcb.SimdPaddleOCR`.
third-party inference engine**. Inference runs on [Sdcb.SimdOnnx](https://github.com/sdcb/SimdOnnx),
a pure C# engine shared with `Sdcb.SimdPaddleOCR` (it grew out of this repository's own engine).

The model is a two-stage pipeline:

Expand Down Expand Up @@ -110,19 +110,20 @@ dotnet run --project examples/PaddleOCR.Console -- [image] [output.jpg]

### Layout

- `src/Sdcb.SimdGcdrNet/Onnx` — minimal protobuf reader + ONNX model/graph objects
- `src/Sdcb.SimdGcdrNet/Engine` — `GraphCompiler` (specialize → fold → fuse → arena-plan),
`InferenceSession`
- `src/Sdcb.SimdGcdrNet/Kernels` — Scalar / `Vector<float>` / AVX2 / AVX-512 kernels (`Ops`, `Avx2Kernels`, `Nhwc`,
`PixelOps`, `SimdMath`)
- `src/Sdcb.SimdGcdrNet/Backends/Vulkan` — `Vk` P/Invoke layer, `VkDevice`, `VkShaders` (embedded
SPIR-V), `VkGraph` dispatch lowering, `VkSession`, `VkPipeline2` (fused pipeline), `VkBackend`
- `src/Sdcb.SimdGcdrNet/Backends/Vulkan/Shaders` — GLSL sources; `tools/build-shaders.bat`
recompiles `.comp` → `.spv` (committed; dev-time only, not part of `dotnet build`)
- `src/Sdcb.SimdGcdrNet/Backends/Metal` — `ObjC`/`Metal` P/Invoke layer, `MtlGraph` dispatch
lowering, `MtlSession`, `MtlPipeline` (fused pipeline), `MetalBackend`
- `src/Sdcb.SimdGcdrNet/Backends/Metal/Shaders` — MSL sources (`.metal`, embedded resources,
compiled to PSOs at run time — no pre-build step)
The ONNX engine (protobuf reader, graph compiler, CPU SIMD kernels, Vulkan / Metal backends) is
[Sdcb.SimdOnnx](https://github.com/sdcb/SimdOnnx); this library holds the GCDRNet-specific parts:

- `src/Sdcb.SimdGcdrNet/GcdrEnhancer.cs` — public API: backend selection, per-size session pools,
gc → dr stitching, arena stacking
- `src/Sdcb.SimdGcdrNet/Extensions` — engine extensions (`GcdrExtensions`): fused operators
(`UpHeadOp`, `ChannelShiftOp`) with their CPU kernels (Vector / AVX-512 / NEON / WASM SIMD) and
graph passes
- `src/Sdcb.SimdGcdrNet/Kernels` — `PixelOps` (interleaved pixels ↔ tensors, padding)
- `src/Sdcb.SimdGcdrNet/Backends/Vulkan` — `VkPipeline2` (fused gc + dr pipeline on SimdOnnx's
Vulkan backend); `Shaders` holds the GCDRNet GLSL kernels, `tools/build-shaders.bat` recompiles
`.comp` → `.spv` (committed; dev-time only, not part of `dotnet build`)
- `src/Sdcb.SimdGcdrNet/Backends/Metal` — `MtlPipeline` (fused pipeline on SimdOnnx's Metal
backend); `Shaders` holds MSL sources (embedded, compiled to PSOs at run time)
- `bench/Sdcb.SimdGcdrNet.Benchmark` — `--check`, `--bench` (CPU), `--benchvk` (Vulkan e2e),
`--benchmtl` / `--checkgpu` / `--mtlprof` / `--mtrace` (Metal e2e, diff check, per-shader
profile, CPU-vs-Metal per-node trace), `--vkprof` (per-shader/per-dispatch GPU timing), `--vkcheck` / `--vknodes`
Expand Down Expand Up @@ -173,8 +174,10 @@ runs two waves in parallel, then merges them into one report (the run's summary
- Metal path requires macOS on Apple Silicon with Apple7+ (simdgroup-MMA, i.e. M1+; an x64 process
under Rosetta also qualifies); `Auto` checks `SupportsApple7` before choosing it,
`GcdrBackend.Metal` selects it unconditionally. Set `GCDRNET_MTL_VERBOSE=1` to print the chosen device.
- Thread-safety: `GcdrEnhancer` is thread-safe (CPU: per-size session pools; Vulkan: size-agnostic worker pool); individual
`InferenceSession`/`VkInferenceSession` objects are not.
- Thread-safety: `GcdrEnhancer` is thread-safe (CPU: per-size session pools; Vulkan: size-agnostic worker pool).
- 2.0 moved the engine out: `InferenceSession`, `CompiledModel`, `OnnxModel`, `VkInferenceSession` and
`MtlInferenceSession` are no longer in `Sdcb.SimdGcdrNet.*`; use the same types from
`Sdcb.SimdOnnx.*` (a dependency of this package). `GcdrEnhancer`'s API is unchanged.
- Not covered: batched inference (N>1), fp16/int8.
- Native AOT works (`IsAotCompatible`, no trim/AOT warnings; CPU and Vulkan output verified identical to JIT). On **x64** the executable
project must set the instruction set, otherwise ILC compiles for the SSE baseline, folds
Expand Down Expand Up @@ -202,8 +205,8 @@ are from the RealDAE dataset of the same paper.
## 中文

**Sdcb.SimdGcdrNet** 是 [GCDRNet](https://github.com/ZZZHANG-jx/GCDRNet)(相机拍摄文档去阴影/外观增强,
IEEE TAI 2023)的**纯 C# 推理库**——不依赖 onnxruntime 等第三方推理引擎,像 `Sdcb.SimdPaddleOCR`
一样自带 CompiledModel 推理引擎。
IEEE TAI 2023)的**纯 C# 推理库**——不依赖 onnxruntime 等第三方推理引擎,与 `Sdcb.SimdPaddleOCR`
共用纯 C# 推理引擎 [Sdcb.SimdOnnx](https://github.com/sdcb/SimdOnnx)(2.0 起引擎类型移到 `Sdcb.SimdOnnx.*`)。

模型为两级串联:**GC-Net** 估计逐像素光照/阴影图 `I_sm` → `I_GC = clamp(I_s/I_sm)` 除法校正 →
**DR-Net** 消费 6 通道 `[I_s; I_GC]` 输出增强图。
Expand Down
2 changes: 1 addition & 1 deletion bench/Sdcb.SimdGcdrNet.Benchmark/CiRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ private static JsonObject HostInfo()
string isa = RuntimeInformation.ProcessArchitecture switch
{
Architecture.X64 or Architecture.X86 =>
Kernels.Nhwc.UseAvx512 ? "avx512" : Avx2.IsSupported ? "avx2" : Avx.IsSupported ? "avx" :
Sdcb.SimdOnnx.Kernels.Nhwc.UseAvx512 ? "avx512" : Avx2.IsSupported ? "avx2" : Avx.IsSupported ? "avx" :
System.Numerics.Vector.IsHardwareAccelerated ? "sse" : "scalar",
Architecture.Arm64 => AdvSimd.IsSupported ? "neon" : "scalar",
_ => System.Numerics.Vector.IsHardwareAccelerated ? "vector" : "scalar",
Expand Down
Loading
Loading