源码模块化组织

Windows API 完整化阶段已经把源码模块化作为质量门禁,而不是单纯的可读性优化。

命名空间根规则

托管源码只允许两个产品根命名空间:TensorRT、工具和共享桥接类型归入 JYPPX.TensorRtSharp,CUDA 类型归入 JYPPX.CudaSharp。内部拆分程序集 JYPPX.Shared.dll 的类型使用 JYPPX.TensorRtSharp.Shared、JYPPX.TensorRtSharp.Shared.Interop 和 JYPPX.TensorRtSharp.Shared.Generated,不再暴露第三个 JYPPX.Shared 根。ManagedNamespaceRootPolicyTests 会扫描 src 和生成模板,阻止游离命名空间重新进入代码库。

原生桥接层

过大的原生桥接文件需要按部署功能区拆分,同时保持 C ABI 导出名和行为不变。

  • CUDA 模块放在 native/src/cuda/modules。
  • TensorRT 8 模块放在 native/src/tensorrt/v8/modules。
  • TensorRT 10 模块放在 native/src/tensorrt/v10/modules。

当前第一批已抽出的原生分组:

  • CUDA pitched memory 分配与 2D copy helper。
  • TensorRT convolution / scale / padding layer helper。
  • TensorRT execution-context 部署 helper。

这些模块当前仍由原来的 api.cpp include 进同一个翻译单元,而不是直接拆成独立 .cpp。这样可以继续使用既有匿名命名空间 helper,避免因为移动文件导致 ABI 或行为变化。只有当校验、所有权、版本守卫等 helper 都提升为可复用头文件后,模块才适合进一步变成独立 .cpp。

托管 interop 层

托管 interop 在 wrapper 分组稳定后按功能区拆分。

当前第一批托管拆分是 CUDA pitched-memory interop:

  • src/JYPPX.CudaSharp/Internal/Interop/Memory/NativeCudaApi.PitchedMemory.cs

其余手写 CUDA partial interop 也按公开 owner 的 feature area 归类:

  • Internal/Interop/Devices:device resource 与 primary execution-context 操作。
  • Internal/Interop/Diagnostics:复制型 runtime logs。
  • Internal/Interop/Drivers:可选 Driver capability、module 与 typed launch 操作。
  • Internal/Interop/IPC:owner-safe export/import token 操作。
  • Internal/Interop/Kernels:Runtime kernel-library owner 与 launch 操作。
  • Internal/Interop/RuntimeCompilation:可选 NVRTC program 操作。

NativeCudaApi.Deployment.cs 仍保留在 interop 根目录,因为它同时跨越 error、PCI、stream/event、pinned-memory、atomic capability 与 device selection;应在单独的行为拆分批次中处理,不能错误归入某一个 feature。

TensorRT 高层 wrapper 也开始按 layer feature 拆分:

  • src/JYPPX.TensorRtSharp/Network/TensorRtNetworkDefinition.Deconvolution.cs
  • src/JYPPX.TensorRtSharp/Network/TensorRtNetworkDefinition.Lrn.cs
  • src/JYPPX.TensorRtSharp/Network/TensorRtNetworkDefinition.Quantization.cs
  • src/JYPPX.TensorRtSharp/Layers/TensorRtLayer.Deconvolution.cs
  • src/JYPPX.TensorRtSharp/Layers/TensorRtLayer.Lrn.cs
  • src/JYPPX.TensorRtSharp/Layers/TensorRtLayer.Quantization.cs

剩余两份高层大 wrapper 现已沿用同一 feature 边界。Layers/TensorRtLayer.cs 只保留构造、通用 layer metadata、 owner lease、output index 校验、释放与共享 Dims 校验;Shuffle、MatrixMultiply、Reduce、SoftMax、Unary、TopK、 Gather、ElementWise、Activation、Pooling、Convolution、Scale、Padding、Resize、Concatenation、Slice、Fill 的 118 个方法进入 17 份 feature partial。Network/TensorRtNetworkDefinition.cs 只保留 input/output/layer ownership、 output mark/unmark、释放与共享 tensor 校验;对应 21 个 Add* 方法进入 21 份 feature partial。 ManagedWrapperFeatureLayoutTests 固定每份文件的精确方法集合,并按原顺序重组规范化源码;拆分前两份 Git blob 分别为 faa5fa87fb24247a86f9d166073cf3858bad9ac2 与 933e7b253ecfefa00034da2544912b6e20c353ae。 这次仅整理源码,不改变 public 签名、SafeHandle/owner-lease 行为、line 路由、校验顺序、native entrypoint、 generated binding、manifest 或 ABI 证据。

通用 Engine 与 ONNX Parser wrapper 也沿用同一模式。Engine/TensorRtEngine.cs 现为 124 行 handle、标量属性与 Dispose core;36 个 tensor/profile metadata、binding report、execution-context、refit 与 inspection 方法进入 5 份 feature partial,两个 binding-report 私有 helper 随 TensorRtEngine.BindingReports.cs 迁移。 Parsing/TensorRtOnnxParser.cs 现为 198 行构造、logger/config/initializer lifetime、标量属性、Dispose 与共享校验 core;32 个 model parsing/loading、TryParse、diagnostics、operator-support 与 flags 方法进入 6 份 feature partial。 Parser flag 校验与 model segment/stream copy helper 被多个 partial 共同消费,因此继续留在 core。 ManagedEngineParserFeatureLayoutTests 固定方法/helper 归属,并重组拆分前 Git blob fd6907a9e03eab3b6f9a1b5820eea9e6e1e82ea9 与 d8e3f135b71f9b2fd893146776da7d538db5d020。

BuilderConfig 与 ExecutionContext 的通用 wrapper 也已拆分,且不与既有 TRT11 partial 重叠。 Builder/TensorRtBuilderConfig.cs 现为 102 行 handle、progress-monitor lifetime、共享校验与 Dispose core; 34 个 profile/flag/compatibility/layer-device/memory-pool/scalar/tactic/timing-cache 方法和 7 个 feature 属性进入 8 份 partial。ValidateLayer、disposed-state 与 progress-monitor helper 仍被既有 diagnostics partial 消费,因此留 core。 Execution/TensorRtExecutionContext.cs 现为 176 行 metadata、profiler/aux-stream lifetime、cleanup 与 Dispose core; 20 个 shape/address/device-memory/event/enqueue 方法进入 5 份 feature partial。布局门禁可重组拆分前 Git blob 592ce09c4da5fb4f7a376800cd5a6b309a22481b 与 1614e46a4b0175ff9889302f977a0520be404b29。

ParserRefitter 与高层 InferenceBindings 也按调用阶段拆分。Parsing/TensorRtOnnxParserRefitter.cs 现为 114 行 native owner、refitter/logger borrower lifetime、initializer pin lifetime、共享 model segment/stream copy helper 与 Dispose core; 21 个 refit/model-proto/initializer/diagnostic 方法进入 4 份 feature partial。Inference/TensorRtInferenceBindings.cs 现为 124 行 engine/context 引用、buffer owner、共享 tensor lookup/report refresh、Dispose 与 disposed-state core; 15 个 geometry/buffer/host-transfer/address-binding/execution/diagnostic 方法进入 6 份 feature partial,feature 专属的 size estimation、buffer replacement 与 readiness helper 跟随各自 owner。布局门禁可重组拆分前 Git blob 07975ca6274fb64fcce06ca6e967515f07aa734c 与 6257b4c8ad3c0f8c4ec349208e8583b670359d0a。

环境探测与 plugin inventory 也已消除单文件多职责。Diagnostics/TensorRtEnvironmentProbe.cs 从 1,497 行降为 62 行跨 feature 异常分类、诊断格式化与 stage helper core;43 个公开静态入口进入 PluginInitialization、 RuntimeMetadata、GlobalPluginRegistry、BuilderPluginRegistry、DependencyProbes、ObjectCreation、BuildChains 七份 partial。 Plugins/TensorRtPluginRegistryInventory.cs 只保留主 inventory 聚合类;两个 enum、field/creator copied metadata、 creator/field summary 与 inventory diagnostics 分别进入 6 份独立文件。布局门禁可重组拆分前 Git blob bcd1301777f81d9de32625b4c7be952de3126d92 与 c39d9ec853987f50f452b0dfebc2658120aa95d2。

CUDA 高层 graph 与 device-memory wrapper 也按相同的 feature owner 规则归类。Graphs/CudaGraph.cs 从 1,630 行降为 206 行 graph handle、capture/conditional/allocation owner 生命周期、共享校验与 Dispose core;conditional handle、 graph composition、node creation、topology diagnostics、node inspection、node mutation、node relations 与 instantiation 进入 8 份 feature partial。Memory/CudaMemory.cs 从 951 行降为 114 行 allocation handle、IPC import metadata、共享 range 校验与 Dispose core;IPC、range diagnostics、async allocation、fill、prefetch/advice、host transfer、device transfer、async free 与 array conversion 进入 9 份 feature partial,并继续保留既有 registered-host partial。布局门禁 可重组拆分前 Git blob 5b7e06e4e59d6961c9c848f88d1f9ace6a9c0450 与 1d2085d8ffc527cfd280c2ba68836d14bb2c6334。

CUDA device 级 helper 与跨模块 enum 也不再集中在两个宽泛文件中。Devices/CudaDevice.cs 从 793 行降为 144 行 runtime/driver/device identity 与 property snapshot core;graph resources、runtime configuration、initialization/selection、 peer capabilities、memory pools、cache/RDMA、synchronization/error diagnostics 进入 7 份 feature partial。原 912 行 Core/CudaFlags.cs 已删除,其中 24 个 public enum 进入 Streams、Events、Memory、Devices、Graphs 下 10 个模块文件; enum 名称、底层类型、数值与 XML 注释保持不变。布局门禁可重组拆分前 Git blob df16e51427f82c9b99fa867819015539dd65ac0c 与 dca1aa594002506ce47bd247f47141201af6591d。

Pitched 与 CUDA array memory owner 也已按传输维度拆分,同时把共享校验保留在 owner core。 Memory/CudaPitchedMemory.cs 从 678 行降为 181 行 allocation/metadata、共享 pitch/extent/pinned-buffer validation 与 Dispose core;fill、2D transfer、3D transfer、array conversion 进入 4 份 feature partial。Memory/CudaArray.cs 从 609 行降为 208 行 allocation/metadata、共享 validation 与 Dispose core;复制型 requirements/sparse diagnostics、 1D/2D/3D transfer、array conversion 进入 5 份 feature partial。布局门禁可重组拆分前 Git blob e30004cce7cc55c7b62e19478de913d68be3c591 与 6de4bc82180a8539e3b6d6fa610c485c042d043e。

CUDA stream 与 memory-pool owner 也按调用阶段和职责边界拆分。Streams/CudaStream.cs 从 439 行降为 126 行 handle/property、capture owner-count 与 Dispose core;一般 diagnostics、capture diagnostics、capture dependencies、 synchronization/event 和 capture lifecycle 进入 5 份 feature partial。Memory/CudaMemoryPool.cs 从 372 行降为 31 行 handle/value core;factory、allocation、access 与 attributes 进入 4 份 feature partial,独立 owner CudaOwnedMemoryPool 与两个 pool enum 各自移入专用文件。布局门禁可重组拆分前 Git blob 379fd60f08beca36711507a6c83a2192d20b6562 与 7028220b628b3d2af9c3f007dda75ec4ff2f5fd3。

Tools 的 ONNX engine 构建服务也按构建阶段归类。Build/OnnxEngineBuildService.cs 从 3,214 行降为 540 行 selected-device thread、dry-run/build orchestration core;builder configuration、timing cache、result creation、refit、 diagnostics、runtime execution、benchmarking、runtime inputs、reference validation 与 deployment configuration 进入 10 份 feature partial,private lease/worker/runtime state type 跟随各自 feature。原 970 行 Build/OnnxEngineBuildResult.cs 降为 304 行主 result;timing-cache artifact、capability probe、loaded-engine diagnostics、 preflight metadata、model evidence 与 benchmark summary 六个独立 public 类型各自成文件。布局门禁可重组拆分前 Git blob 31f2c170c9c74b7278b4bc266eca76405dc33067 与 97f6e992fe582513fcf77b10ce05de4de32af1a5。

ONNX runtime artifact 与 build report 投影继续按输出职责拆分。原 1,052 行 Artifacts/OnnxEngineRuntimeArtifactWriter.cs 降为 85 行 dispatch/hash core;times、结构化 output、benchmark profile、 engine readback、raw bindings、proof boundary 与 file I/O 进入 7 份 feature partial,runtime artifact data 与 output record 成为独立 public 类型。原 776 行 Build/OnnxEngineBuildDiagnostics.cs 降为 37 行 report format dispatch core;JSON、 Markdown、option implementation status 与 report proof boundary 进入 4 份 feature partial,option status 与 report boundary record 各自成文件。布局门禁可重组拆分前 Git blob 5269b4685e87d8eb0e65b337499963b12de71aaa 与 c7c832f862d8c3d4bff2b93666e9f842b24cdd91。

Tools 的模型特定 MNIST runtime 与 trtexec-like parser 也在不改变命令和 proof 语义的前提下完成模块化。原 932 行 Runtime/MnistOnnxRuntime.cs 已删除;options、PGM image/reader、classification、environment、result 与 diagnostics 各自成文件,execution、artifact hash、tensor/shape 与 option validation 进入 4 份 MnistOnnxRuntimeService partial。 原 731 行 Trtexec/TrtexecLikeParser.cs 降为 262 行 Parse orchestration core;argument collection、 scalar/reference parsing、build-option values 与 memory units 进入 4 份 feature partial。布局门禁可重组拆分前 Git blob 116ff0707028cd234819b023f6b2b5e0ff3cbb43 与 3c94e7b5fe1ed741b722f71eb10f2888f76567b7。

trtexec deployment 投影与 build policy 继续遵循同一 owner 规则。原 644 行 Trtexec/TrtexecLikeDeploymentOptions.cs 降为 225 行 constructor/default/property core;argument projection、 diagnostics、tactic-source resolution、memory-pool projection 与共享 formatting 进入 5 份 partial, TrtexecLikeMemoryPoolSize 独立成文件。原 568 行 TrtexecLikeBuildPolicy.cs 降为 93 行 normalization/Apply orchestration core;parsing、IO formats、precision constraints、layer policies、rule validation、data-type/format parsing 进入 6 份 feature partial,IO-format 与 layer-rule model 成为独立 internal 类型。布局门禁可重组拆分前 Git blob d55d835f5dd934975af9a302391415e49030a14d 与 ef5b4bf488124bb1d37090cbf5cf1b75cf345dfb。

callback proof 编排与 allocator diagnostics 也在不放宽 non-proof 边界的前提下完成拆分。原 1,774 行 Callbacks/Debugging/TensorRtDebugListenerRuntimeProofPrecheck.cs 降为 379 行最终 evaluation core;design prerequisite、 native attach design、owner lifecycle、runtime scaffold 与 final runtime gate 进入 5 份 partial,复制型 precheck result 独立成文件。原 1,163 行 Callbacks/MemoryAllocation/TensorRtAllocatorCallbackOwner.cs 降为 120 行 state/constructor/property core;lifecycle、managed dry-run、native dry-run、state ledger、internal prototype 与 native result mapping 进入 6 份 partial,request/result/snapshot/delegate model 各自成文件。布局门禁可重组拆分前 Git blob c33e5795a35e4ef04836486ac0fb64552f608681 与 7c71b544fe40b1a4f5c77b42b3900e1ce62f899c,并固定全部 16 个 precheck overload 签名及 allocator release 顺序。

callback owner 与 family closure matrix 继续遵循相同边界。原 841 行 Callbacks/Debugging/TensorRtDebugListenerCallbackOwner.cs 降为 68 行 owner-state/constructor/property core; design diagnostic、snapshot mapping、lifecycle release、callback trampoline/state 与 shape formatting 进入 5 份 partial, request 和 snapshot model 各自成文件。原 648 行 Callbacks/Core/TensorRtCallbackOwnerClosureMatrix.cs 降为 47 行 Evaluate core;allocator rows、output/debug rows、stream IO、row construction 与 blocker aggregation 进入 5 份 partial, row/result model 独立成文件。布局门禁可重组拆分前 Git blob f5ed356884eb6aa4b5721501a77e3a299ebdd771 与 d36f22e8cf3040f169885637ce5be7801551bbf0,同时固定 callback drain/release 顺序和全部 5 个 family row。

DebugListener native lifecycle/trampoline 的公开诊断模型也各自拥有同名文件。原 561 行 native-owner lifecycle dry-run 分为 242 行 evaluator 与 324 行 result;原 552 行 process-debug-tensor trampoline 分为 247 行 evaluator、 67 行 copied metadata snapshot 与 244 行 result。布局门禁可重组拆分前 Git blob d88595940fa19e538438cf46a3eb942652284f0c 与 4eb5dd0f741855ca19ae29ff07a76f6558a008d7,并固定 owner lifecycle readiness、callback status、pointer non-exposure 和 real-runtime promotion 条件。

DebugListener lifecycle gate 与 no-throw callback stub 继续采用 evaluator/result owner 边界。原 509 行 lifecycle gate 分为 181 行 evaluator 与 333 行 result;原 493 行 callback stub 分为 207 行 evaluator 与 291 行 result。布局门禁 可重组拆分前 Git blob 56e5514b6eba4c4af339d61ca29e1856dce2375e 与 b44c97b554058ae331a3cf5eab861f56ba35094a,并固定 lifecycle readiness、callback metadata/status、pointer non-exposure、native-vtable disabled 与 deferred-row 语义。

DebugListener vtable install preflight 与 detach-before-release design gate 的 result 也已归入同名文件。原 479 行 preflight 分为 235 行 evaluator 与 249 行 result;原 465 行 detach gate 分为 217 行 evaluator 与 253 行 result。 布局门禁可重组拆分前 Git blob b7ed72fd9a5a604fe86f7b84972610615117ad8c 与 2e2d856b62c3e5998ea9b53c297cbc800a92dffb,并固定 install version/no-throw/ownership guard、detach/release/ in-flight/unpin ordering、pointer non-exposure 与 proof blocker 语义。

DebugListener native-owner vtable install experiment 与 owner-address design gate 的 result 也已归入同名文件。 原 459 行 experiment 分为 243 行 evaluator 与 221 行 result;原 456 行 owner-address gate 分为 235 行 evaluator 与 226 行 result。布局门禁可重组拆分前 Git blob f8cf4862f4fe9149e2210de18b2360473f7c4061 与 8a674a2138328c217902c6c94080dd789c73bd23,并固定 install guard/rollback、stable owner address、lifecycle/vtable readiness、pointer non-exposure 与 runtime-proof blocker。

DebugListener real callback runtime proof 与 borrowed debug tensor metadata runtime gate 的 result 也已归入同名文件。 原 456 行 proof 分为 245 行 evaluator 与 216 行 result;原 447 行 metadata gate 分为 199 行 evaluator 与 253 行 result。布局门禁可重组拆分前 Git blob d37bcef3b9dc04e7f2ffc39776e9c069d062877e 与 8b9572ae4e081e820bc7ffe18c4fe257bf57cf03,并固定 opt-in/full-consumer promotion、invocation/detach/rollback、 copied metadata、borrowed lifetime、pointer non-exposure 与 deferred-row 语义。

DebugListener runtime-proof attempt preflight 与 real non-null attach runtime smoke 的 result 也已归入同名文件。 原 435 行 preflight 分为 217 行 evaluator 与 223 行 result;原 431 行 smoke 分为 221 行 evaluator 与 215 行 result。布局门禁可重组拆分前 Git blob 8c8a5eac71686750dc6bec5507f87e0baf1a08e2 与 90e290140a474ce02168e67f7c3ef1eb6489c7d8,并固定 attach/vtable/callback prerequisite、opt-in/full-consumer guard、 attempt/detach/rollback、counter、pointer non-exposure 与 real-runtime promotion 语义。

DebugListener callback proof-gap report 与 native attach-entry design gate 的 result 也已归入同名文件。原 414 行 proof-gap report 分为 159 行 evaluator 与 260 行 sealed result;原 408 行 attach-entry gate 分为 195 行 evaluator 与 218 行 result。布局门禁可重组拆分前 Git blob 5e672392bcdf68e4a4a2130644320388d3c9864c 与 3a6eca7d81dd5091ce60f67cd70ec5d6637cdb46,并固定 gap 顺序/category/owner action、attach/detach mapping、 lifecycle/vtable prerequisite、pointer non-exposure 与 deferred-row 语义。

DebugListener native no-throw vtable design gate 与 attach-entry minimal safety 的 result 也已归入同名文件。原 388 行 vtable gate 分为 177 行 evaluator 与 216 行 result;原 376 行 minimal safety 分为 185 行 evaluator 与 196 行 result。布局门禁可重组拆分前 Git blob 068e7a4e18b400445bdb897a95dfabd2f120e875 与 9876179f69f535a40996b02fab0db6450971ff47,并固定 vtable no-throw/version/ownership、line-specific attach/detach、 owner lifecycle、borrowed lifetime、pointer non-exposure 与 runtime-proof blocker。

DebugListener native attach-entry runtime scaffold 与 attach-vtable safety gate 的 result 也已归入同名文件。原 362 行 runtime scaffold 分为 178 行 evaluator 与 189 行 result;原 357 行 safety gate 分为 166 行 evaluator 与 196 行 result。布局门禁可重组拆分前 Git blob d90e00c816e24dc0854388c5f4562b8d55c53ab8 与 6db7a67044b1972e1cb52fe4f291fa89946bae44,并固定 line-specific attach/detach、version/no-throw/ownership、 owner lifecycle、vtable/keep-alive、borrowed lifetime、pointer non-exposure 与 runtime-proof blocker。

DebugListener native no-throw vtable scaffold gate 与 no-throw destructor 的 result 也已归入同名文件。原 354 行 vtable scaffold gate 分为 148 行 evaluator 与 211 行 result;原 331 行 destructor 分为 132 行 evaluator 与 204 行 result。布局门禁可重组拆分前 Git blob c8f31605e413c172dbf8cc1bb6eb6c21e60c5954 与 b51277e392df8069e7c9f47e2eede14e5819449b,并固定 vtable scaffold/exception/status/in-flight prerequisite、 native owner non-copyable/no-throw destructor、pointer non-exposure、deferred-row 与 runtime-proof blocker 语义。

DebugListener native owner non-copyable storage 与 borrowed tensor safety gate 的 result 也已归入同名文件。原 318 行 storage 分为 130 行 evaluator 与 193 行 result;原 317 行 borrowed tensor safety 分为 132 行 evaluator 与 190 行 result。布局门禁可重组拆分前 Git blob 0f395ae7dcb4b04c1189e8d1bc19b6eb1791eb7b 与 34bd7d9638321ef955730bc4126da254fc45935f,并固定 owner copy/move blocking、stable identity、borrowed metadata copy、lifetime/pointer escape blocking、deferred-row 与 runtime-proof blocker 语义。

DebugListener native attach bridge shape 与 in-flight accounting gate 的 result 也已归入同名文件。原 320 行 attach bridge gate 分为 134 行 evaluator 与 191 行 result;原 312 行 accounting gate 分为 119 行 evaluator 与 198 行 result。布局门禁可重组拆分前 Git blob 9f94f504f8807ac99f2c3dff926b0f92597f2c07 与 ce52bde9e23c9348818be104417db71857a93936,并固定 attach parameter/version/no-throw shape、pointer-free helper、 callback enter/leave、release-after-drain、unpin-after-drain、deferred-row 与 runtime-proof blocker 语义。

MemoryAllocation 的 allocator ledger safety gate 与 output allocator runtime proof precheck result 现在也各自归入同名文件。 原 405 行 ledger gate 分为 102 行 evaluator 与 309 行 result;原 384 行 output precheck 分为 175 行 evaluator 与 215 行 result。布局门禁可重组拆分前 Git blob 3920e6c4a520ddde03ca1907f2fdcca3ed580476 与 cd8385ec902b765cfcd4ce987e2f6b1ec855e57c,并固定 ledger snapshot/result mapping、三组 output precheck overload、 公开属性顺序、pointer non-exposure、deferred-row 与 runtime-proof blocker 语义。源码归类不提升任何 runtime proof。

OutputAllocator 的 output buffer ownership safety gate 与 attach/detach design gate result 现在也各自归入同名文件。 原 353 行 ownership gate 分为 157 行 evaluator 与 202 行 result;原 259 行 attach/detach gate 分为 118 行 evaluator 与 147 行 result。布局门禁可重组拆分前 Git blob ee3ae72d0750db446d8f44c7ca8f3e6aacd5e006 与 d8dcb0613a11b3b9570ae708063846576261eb11,并固定 ownership metadata/rule mapping、attach/detach lifecycle、 公开属性顺序、pointer non-exposure、deferred-row 与 runtime-proof blocker 语义。源码归类不提升任何 runtime proof。

Callback Core 的 algorithm snapshot design gate 与 MemoryAllocation 的 allocator interface-info design gate result 现在也各自归入同名文件。原 314 行 algorithm gate 分为 113 行 evaluator 与 207 行 result;原 283 行 allocator interface-info gate 分为 114 行 evaluator 与 175 行 result。布局门禁可重组拆分前 Git blob a7c9cca0316d8a52986b5ca3a1da64845b1afae8 与 695650b21a5bf5036728c26c3a4ece03798fd1f3,并固定候选接口/ 方法集合、copied metadata shape、pointer non-exposure、deferred-row 与 runtime-proof blocker 语义。

MemoryAllocation 的 callback/allocator readiness evaluator 与 snapshot 现在也各自归入同名文件。原 261 行 TensorRtCallbackAllocatorReadiness.cs 分为 128 行 evaluator 与 138 行 snapshot。布局门禁可重组拆分前 Git blob 133d913042fa2cd7aa0d13e0628b4bc1a485d1ae,并固定 gate 聚合顺序、blocked prerequisite 复制、公开属性顺序、 summary、pointer non-exposure 与 managed-readiness/non-proof 语义。

Runtime deserialization boundary precheck 与 dependency diagnostics result 现在也各自归入同名文件。原 388 行 boundary precheck 分为 176 行 evaluator 与 218 行 result;原 393 行 dependency diagnostics 分为 122 行 evaluator 与 277 行 result。布局门禁可重组拆分前 Git blob 9ab81dadc09b84d03ad39d094acf16c97f25100a 与 85c565c4094b240fc76b5c0d1f4d66b308de6374,并固定 scoped-buffer/engine ownership、dependency/driver 分类、 公开属性顺序、pointer non-exposure、deferred-row 与 runtime-proof blocker 语义。

TensorRtExecutionContextDeploymentSummary.cs 与 TensorRtBuilderConfigDeploymentSummary.cs 现在也各自拥有 对应顶层 summary。原 424 行 TensorRtExecutionContextDeploymentSnapshot.cs 分为 270 行 snapshot 与 157 行 summary;原 408 行 TensorRtBuilderConfigDeploymentSnapshot.cs 分为 254 行 snapshot 与 157 行 summary。布局门禁可重组拆分前 Git blob e0413b02864fae42c4d0c6872b96f2cee3f53e70 与 d7501f3ba89e00f9bb373d8892b0804f5cb91637,并固定 snapshot-to-summary 映射、公开属性顺序、diagnostic count、pointer-free summary 与 non-proof 语义。

TensorRtExecutionContextRuntimeDiagnosticSummary.cs 与 TensorRtEngineDeploymentSummary.cs 现在分别拥有 剩余的 execution runtime-diagnostic summary 与 engine deployment summary。原 411 行 runtime-diagnostic snapshot 分为 198 行 snapshot 与 217 行 summary;原 380 行 engine deployment snapshot 分为 251 行 snapshot 与 133 行 summary。布局门禁可重组 Git blob 46eea3f13e19f01f9b927738c2c9dbad76172feb 与 6c4a5c3234857443ea45e84e4b8e61f1fe5a786c,并固定 summary 映射、callback-status 诊断、engine metadata count、 pointer non-exposure 与 non-proof 语义。

Dimension-expression snapshot 与 PluginCreatorV3 metadata 两个 design gate 也已将 *DesignGateResult 移入独立同名 文件。原 312 行 dimension gate 分为 108 行 evaluator 与 210 行 result;原 300 行 plugin gate 分为 113 行 evaluator 与 193 行 result。readiness 与 test source-set 保持 known-surface evaluation、candidate metadata、blocker 顺序、pointer non-exposure、deferred row 与 design-gate-only proof 分类。

TensorRtRuntimeDiagnosticSummary.cs 与 TensorRtRefitterDiagnosticSummary.cs 现在分别拥有 runtime/refitter diagnostic summary。原 308 行 runtime snapshot 分为 141 行 snapshot 与 172 行 summary;原 300 行 refitter snapshot 分为 159 行 snapshot 与 146 行 summary。布局门禁可重组 Git blob 6003269ee021488f519fe6944a1a6827cd9232c7 与 504a003346f84915b7bf3af4924feeaeaeb0bcbf,并固定 copied diagnostics、error/inventory count、公开属性顺序、pointer non-exposure 与 non-proof 语义。

Calibrator metadata 与 RNNv2 borrowed-state 两个 design gate 的 Result 也已进入独立同名文件。原 268 行 calibrator gate 分为 105 行 evaluator 与 169 行 result;原 199 行 RNNv2 gate 分为 53 行 evaluator 与 151 行 result。布局门禁可重组 Git blob db5eb26e158d64f94dd678351a260f8bd41c7138 与 d1a7c4a34dde13ffa3fce824f5a95e0f0c528f30,并固定 known-surface evaluation、triage/candidate count、blocker 顺序、pointer non-exposure 与 proof classification。

ONNX parser 与 ParserRefitter diagnostic summary 也已进入独立同名文件。原 226 行 parser snapshot 分为 105 行 snapshot 与 126 行 summary;原 188 行 ParserRefitter snapshot 分为 85 行 snapshot 与 108 行 summary。 布局门禁可重组 Git blob 7a2fde67837713343938bc73130707d696b699d6 与 725939901e71733723097025d1ee3e48a344ca2b,并固定 copied diagnostics、public constructor/property 顺序、 pointer non-exposure 与 copied-summary proof classification。

RuntimeConfig 与 SerializationConfig summary 也已进入独立同名文件。原 97 行 runtime config 分为 66 行 owner 与 37 行 summary;原 130 行 serialization config 分为 99 行 owner 与 37 行 summary。布局门禁可重组 Git blob 19c0362741927f9a3ad6f5fbf100da487e23d707 与 6d06225295c20fcfe6c2642ef749b8a241680faf,并固定 handle ownership、readback mapping、公开属性顺序、pointer non-exposure 与 non-proof 语义。

ONNX config 与 model-support record 也在 Parsing 中落实一份公开类型一个文件。原 364 行 TensorRtOnnxConfig.cs 分为 175 行 owner、TensorRtOnnxConfigSnapshot.cs 与 TensorRtOnnxConfigSummary.cs;原 235 行 model-support 文件分为 106 行 TensorRtOnnxModelSupportReport.cs、TensorRtOnnxModelSupportSummary.cs 与 TensorRtOnnxSubgraphSupportInfo.cs。布局门禁保持原声明顺序、构造函数、复制值映射、pointer non-exposure 与 non-proof classification,并可重组 Git blob 98d53f7b30535840e919f97c76b852c90b61a7ff 与 f3ab3a0aa7b1f5e00089cb373293250addb2649a。

dependency 与 runtime probe record 也落实一份公开类型一个文件。TensorRtNativeDependencySource.cs、 TensorRtNativeDependencyInfo.cs、TensorRtDependencyProbeReport.cs 保持 dependency source/info/report 顺序; TensorRtGlobalRuntimeVersion.cs、TensorRtRuntimeProbeStage.cs、TensorRtRuntimeProbeReport.cs 保持 runtime version/stage/report 顺序。由于两份原 Report 文件名实际对应第三个声明,source-set reader 显式固定历史顺序。 布局门禁可重组 Git blob bafe37487e85385883d315c3f1b91a879e944a25 与 3cb8df75eea08200938d55170359572abc315d90;这次源码归类不构成 runtime 或 release proof。

TRT8 legacy parser snapshot 现分别由 TensorRtLegacyUffRequiredVersionSnapshot.cs 与 TensorRtCaffeBinaryProtoSnapshot.cs 拥有;原 plural snapshot 文件删除,同时通过 test reader key 兼容历史源码消费者。 Plugin V2 复制型 metadata 保留在 TensorRtPluginV2LayerMetadata.cs,network-owned layer 查询 partial 移入 TensorRtLayer.PluginV2Metadata.cs。布局门禁可重组 Git blob 4930556a64895570a168168179f1316496def931 与 41c7fb535a6effe3ecf47833bb371480b7f8acb9,并保持 copied data、owner lease 检查、方法顺序、pointer non-exposure 与 non-proof 语义。

OutputAllocator diagnostics 继续按 public design owner 与 internal managed runtime gate 分层。原 637 行 Callbacks/MemoryAllocation/TensorRtOutputAllocatorRuntimeGate.cs 降为 38 行 state/constructor core;entries、snapshots、 lifecycle、shared invocation、trampoline/state 与 formatting 进入 6 份 partial,request/result 类型各自成文件。原 503 行 TensorRtOutputAllocatorCallbackOwner.cs 降为 58 行 state/constructor/property core;design diagnostic、snapshot、 lifecycle 进入 3 份 partial,public request/snapshot model 各自成文件。布局门禁可重组拆分前 Git blob b26930b226288afb17459e77e02fc6b8c8c1b686 与 a9bbaccad3401f179b86fde1e3af224a321b6eae,同时固定两份 GCHandle 的释放顺序和 runtime-gate-before-native-ledger Dispose 顺序。

Monitoring callback owner 也采用相同的 feature 布局。原 489 行 Callbacks/Monitoring/TensorRtLogger.cs 降为 125 行 state/constructor/basic-property core,原 461 行 TensorRtProfiler.cs 降为 104 行 core。copied interface metadata、diagnostic emission、borrower lifecycle 与 callback trampoline/state 分别进入每个 owner 的 4 份 partial; TensorRtLogSeverity、TensorRtLogHandler 与 TensorRtProfilerHandler 各自成文件。布局门禁可重组拆分前 Git blob f0b481c27e249872e2819f80964739d41500b10e 与 ddf7c33de5699bcb0647aa1267d3c35205bccb60,并保持 deferred handle release、delegate keep-alive、callback-state GCHandle 释放和 exception-to-status 行为。源码归类不会把 copied metadata 或 diagnostic smoke 提升为 real logger/profiler callback runtime proof。

Monitoring 剩余复合文件也按相同 ownership 边界归类。原 576 行 Callbacks/Monitoring/TensorRtProgressMonitor.cs 降为 112 行 core;interface metadata、diagnostic emission、lifecycle 与 trampoline/state 进入 4 份 partial,event kind/event/diagnostic result/handler 各自成文件。原 377 行 ErrorRecorder diagnostics 与 Stream IO interface-info design gate 分别降为 164 行和 103 行 evaluator,result struct 各自成文件。 布局门禁可重组拆分前 Git blob 96a830dfd38c8a2a5b6ccf50acada1ee0ff7902e、 61894aedb6a7cf5784f08d53645545bf644ddbd9 与 6e4622a90f33bed569ad54c1fc79eac5bd4a3f7b;callback continue/cancel、释放顺序、prerequisite diagnostic、pointer non-exposure 与 non-proof 分类均保持不变。

Monitoring 的顶层公开 model/gate 类型也各自拥有同名文件。原 270 行 TensorRtErrorRecorderSnapshot.cs 中的 TensorRtErrorRecord、snapshot 与 summary 分为 49/123/106 行三个文件;原 232 行 LoggerFinder metadata gate 分为 85 行 evaluator 与 152 行 result。布局门禁可重组拆分前 Git blob 1dadb6ce8429d5191a05ab874665b071b5b8c609 与 6429d9a087012cd4c3f063ff76e645b29077806a,并固定 summary 字段映射、blocker 顺序、pointer non-exposure 与 non-proof 分类。

TensorRT 的 public enum 也不再集中在 2,456 行的 Core/TensorRtEnums.cs。其中 64 个 enum 按 Core tensor 基础类型、 Network、Parsing、Execution、Serialization、Engine、Runtime、Builder、Profiles、ControlFlow,以及 Layers 下的 RNN、operation、resize、metadata、attention 分入 15 个模块文件;单值/flags 配对保持同文件,名称、underlying type、 数值、Flags 与 XML 文档不变。布局门禁可按原顺序重组拆分前 Git blob 861460b834d7d415fc0497f6c5b05fecaba03707。

手写 TensorRT partial interop 也开始按相同职责模块归类:

  • Internal/Interop/Builder:builder creation/capabilities、serialized build outputs、builder boundary controls、 timing-cache lifecycle/TRT11 controls、builder-config core/scalar controls、diagnostics、plugin serialization 与 runtime controls; ControlFlow:loop/conditional 操作。
  • Internal/Interop/Callbacks:allocator dry-run、callback interface/state 复制、logger/profiler/progress-monitor delegate 签名与 managed callback diagnostics。
  • Internal/Interop/Diagnostics:复制型 error-code metadata 与仅由 environment probe 使用的跨版本/TRT11 build-chain probes; Internal/Interop/Interfaces:owner-scoped versioned-interface metadata 复制。
  • Internal/Interop/Engine:core/deployment engine metadata、inspector lifecycle/information/boundary/diagnostics、 tensor/profile copied values、Dims64、error-recorder controls 与 weight-streaming/stat runtime controls;Execution: execution-context core creation、binding/address/enqueue/aux-stream controls、boundary controls、copied engine metadata、runtime-config 创建、 allocation-strategy、deployment metadata、Dims64、diagnostics 与 allocator/event presence controls。
  • Internal/Interop/Inference:同步 execute/enqueue 操作;Weights:复制型 layer-weight metadata。
  • Internal/Interop/Layers:identity/constant/convolution/deconvolution/scale/padding/element-wise/matrix-multiply/shuffle/reduce、 softmax、unary、TopK、gather feature、 activation、pooling、LRN feature、共用 optional-weight helper、quantization、attention、fill-int64、 resize、concatenation、slice feature、兼容/部署型 layer attributes、Dims64、tensor metadata、 shape、select、fill feature、core layer metadata、transformer 与 RNNv2 操作; Network:core definition input/output/name/flags、network boundary controls、部署型 network layer 创建、core tensor name/type/shape/range metadata、tensor/network Dims64、debug/shape diagnostics、 refittable-weight 标记与 safe network-v2 操作。
  • Internal/Interop/Parsing:global ONNX parser version、parser lifecycle/input/diagnostics/flags、legacy parser diagnostics、 ONNX config/model buffer/support、builder-config attachment、layer-output metadata、weight-descriptor parsing、 parser-refitter diagnostics 与共用复制字符串 helper。
  • Internal/Interop/Plugins:plugin initialization、global/builder/runtime registry inventories,以及复制型 V2/V3 layer metadata/query snapshot。
  • Internal/Interop/Profiles:optimization-profile core creation/shape controls、Dims64 与 shape-value 查询。
  • Internal/Interop/Runtime:adapter information、runtime creation diagnostics、跨版本 line-binding helper、 global runtime version/logger probes、runtime deployment controls 与复制型 diagnostics; Serialization:engine deserialization/serialization、serialization-config flags 与 host-memory buffer/metadata;Refit:async refit、weights/dynamic-range、 entry metadata 与 refitter diagnostics。

NativeBridgeApi.GlobalProbeShared.cs 仅为拆分后的 global Runtime、Parsing、Plugins partial 保存共用的 unsupported-line 异常 helper,因此继续保留在 interop 根目录;它不包含公开方法。 NativeBridgeApi.OwnerErrorRecorderSnapshotShared.cs 仅为 Builder、EngineInspector、Execution 与 Network owner 保存 复制型 error-recorder snapshot mapper,因此继续保留根目录;它不包含公开方法。

只有当 version-prefixed 文件的方法集合仍跨 owner/feature 且需要单独行为拆分时才保留根目录;不会仅依据文件名前缀分类。 原 Trt11DeploymentAdditions 已按方法 owner 拆为 Network/NativeBridgeApi.DeploymentNetworkLayers.cs 与 Layers/NativeBridgeApi.DeploymentLayerAttributes.cs;两部分重组后的 Git blob 必须与拆分前原文件一致。 原 Trt11RuntimeSerializationRefit 也已拆入 Runtime、Serialization、Execution 与 Refit;四部分按原片段顺序 重组后必须恢复拆分前 Git blob。 原 DeploymentMetadata 已拆入 Engine、Execution、Layers、Refit;仅 delegate 与跨 owner 私有 helper 保留为 根目录 NativeBridgeApi.DeploymentMetadataShared.cs,五部分按原片段顺序重组后必须恢复拆分前 Git blob。 原 Trt11Dims64 已拆入 Network、Engine、Execution、Profiles 与 Layers;layer getter delegate/helper 随 Layers 移动,五部分按原片段顺序重组后必须恢复拆分前 Git blob。 原 Trt11RuntimeControls 已按连续 owner 区段拆入 Engine、Execution 与 Builder;三部分按原片段顺序重组后 必须恢复拆分前 Git blob。 原 Trt11Diagnostics 已拆入 Builder、Network、Engine 与 Execution;四部分按原片段顺序重组后必须恢复 拆分前 Git blob。 原 GlobalRuntimePluginProbe 已拆入 Runtime、Parsing、Plugins 与仅含 helper 的根目录 Shared partial;四部分 按原片段顺序重组后必须恢复拆分前 Git blob。 原 SafeDeferredUplift 已拆入 Plugins 与 Parsing;两部分按原片段顺序重组后必须恢复拆分前 Git blob。文件归类 不会改变既有 deferred 历史,也不等于 plugin/parser runtime 与 lifetime proof。 原 Trt11BoundaryControls 已拆入 Builder、Engine、Execution、Network 与仅含 helper 的根目录 Shared partial; 五部分按原片段顺序重组后必须恢复拆分前 Git blob。 原 Trt11FourteenthBatch 已拆入两个 Builder feature 文件以及 Serialization、Profiles、Execution;serialized-network 结果 struct 随 Builder build-output 方法移动,五部分按原片段顺序重组后必须恢复拆分前 Git blob。 原 Trt11FifteenthBatch 已拆入两个 Engine feature 文件与 Execution;profile-value validation helper 随 Engine profile 方法移动,三部分按原片段顺序重组后必须恢复拆分前 Git blob。 根 NativeBridgeApi.cs 开始按小批 owner/feature 区段持续瘦身:跨版本 timing-cache create/set/serialize 片段已移入 Builder/NativeBridgeApi.TimingCacheLifecycle.cs,将该片段插回原位置后必须恢复拆分前的根文件 Git blob。 根文件的 ONNX parser core 已拆为 Parsing lifecycle/input、diagnostics、flags/operator-support 与仅含字符串读取 helper 的 Shared partial。parser 专属 diagnostic helper 随 diagnostics 移动,delegate 与复制字符串 allocator 继续由 parser、 parser-refitter、support 共用;按原片段顺序重组后必须恢复拆分前的根文件 Git blob。 根文件尾部 owner 区段已拆为 Engine inspector core、ExecutionContext binding/enqueue、Serialization host-memory buffer 与 Engine core metadata partial。engine-information 与 IO-tensor-name getter helper 随 owner 移动。BuilderConfig bit-flag helper 最初继续留在根文件;Tensor/Layer name helper 随后与 core owner partial 一起移动,且仍要求按原顺序重组。 跨版本 line-binding delegate、私有 bindings class 与版本路由已移入 helper-only Runtime partial;六个 environment-probe 操作及 minimal build-chain helper 已移入 Diagnostics。生成的 bindings/helper 仍消费同一 partial 私有类型,按原顺序 重组后必须恢复拆分前根文件 blob。 根文件的 Network definition core 已移入 Network/NativeBridgeApi.NetworkCore.cs,包含 input/output ownership、layer lookup、name/flags metadata 与专属 name getter。Layer creation 最初留在根文件等待按 feature 拆分;optional-weight helper 继续随 weighted-layer 消费方法保留。 Identity/constant、convolution、deconvolution、scale creation 已分别移入 Layers feature partial。Scale 保留仅供自身使用 的 data-type selector;convolution/deconvolution/scale 共用的 pin/validation helper 进入 helper-only Layers Shared partial。 重组时必须保持原 helper 顺序。 Padding、element-wise、matrix-multiply creation/attributes 已移入三个独立 Layers feature partial,且这些区段没有私有 helper。Shuffle creation、reshape/transpose attributes 与 zero-placeholder controls 已移入第四个 partial,该区段同样没有 私有 helper,且仍要求按原顺序直接重组。Reduce creation 与 readonly operation/axes/keep-dimensions attributes 也已移入 另一个无 helper 的 partial。 SoftMax、unary、TopK、gather creation/attributes 已移入四个独立的无 helper partial。Activation、pooling、LRN creation/attributes 已移入另外三个独立的无 helper partial。Resize、concatenation、slice creation/attributes 已移入 另外三个无 helper partial,resize 的数组 pinning 留在 feature 文件内。Shape、select、fill creation/attributes 已移入 三个无 helper feature partial;根文件随后从 GetLayerOutput 进入通用 Layer metadata 区段。 通用 Layer metadata 已连同 MapLayerType 和专属 name getter 移入 Layers/NativeBridgeApi.LayerCoreMetadata.cs;通用 Tensor metadata 与专属 name getter 移入 Network/NativeBridgeApi.TensorCoreMetadata.cs。 剩余 adapter/callback/runtime/builder/network/serialization/execution/profile/config 实现已移入十份 owner partial,其中 Builder/NativeBridgeApi.BuilderConfigCore.cs 接管 bit-flag helper。根 NativeBridgeApi.cs 现为 13 行声明 shell,不含 public/private static 实现;将十个主体插回 shell header 与 close brace 之间即可恢复拆分前 root blob。

生成文件继续保留在各自 Generated 文件夹下,不手工拆分。若需要调整生成文件布局,必须通过 generator 本身完成,并通过生成器确定性门禁。

托管公开 API 目录

公开 API 文件按职责放入模块目录,文件移动不改变现有 namespace、类型名或 public API。SDK 风格项目会递归编译这些目录,因此项目文件不需要维护逐文件 Compile 清单。

项目 模块目录
JYPPX.CudaSharp Core、Devices、Diagnostics、Drivers、Events、Graphs、IPC、Kernels、Memory、RuntimeCompilation、Streams
JYPPX.TensorRtSharp Builder、ControlFlow、Core、Diagnostics、Engine、Execution、Inference、Interfaces、Layers、Network、Parsing、Plugins、Profiles、Refit、Runtime、Serialization、Weights
JYPPX.TensorRtSharp/Callbacks Core、Debugging、MemoryAllocation、Monitoring
JYPPX.TensorRtSharp.Tools Artifacts、Build、Core、Refit、Runtime、Trtexec

当前整理覆盖三个项目原根目录中的 294 个 .cs 文件。ManagedSourceModuleLayoutTests 会验证项目根目录不再堆放公开 API 源文件,并检查所有约定模块至少包含一个源码文件。

CUDA Driver capability 入口、复制型 module owner 和 typed launch owner 统一放入 JYPPX.CudaSharp/Drivers。Kernels 则继续负责 CUDA Runtime kernel-library owner,以及 typed argument/configuration 值对象。

TensorRT 复制型 versioned-interface metadata 与 owner-scoped metadata query 统一放入 JYPPX.TensorRtSharp/Interfaces。托管 weights payload、复制型 weights metadata 与 refit weights role 放入 JYPPX.TensorRtSharp/Weights;Core 只保留共享异常、维度、枚举与库信息。

ONNX stripped-plan refit 生命周期与持久化 plan 重载 snapshot 统一放入 JYPPX.TensorRtSharp.Tools/Refit。Build 模块继续负责 build options、service、diagnostics 与 result,并消费这些复制型证据模型。

Callbacks/Debugging 中的 DebugListener gate 也按 evaluator/result 职责归类。TensorRtDebugListenerNativeAttachNoThrowPreflight.cs 与 TensorRtDebugListenerNativeOwnerStableIdentity.cs 只保留评估入口和 blocker 聚合;对应的 TensorRtDebugListenerNativeAttachNoThrowPreflightResult.cs、TensorRtDebugListenerNativeOwnerStableIdentityResult.cs 只保留 pointer-free 结果构造、属性和诊断。

TensorRtDebugListenerAttachDetachDesignGate.cs 与 TensorRtDebugListenerExceptionStatusMappingGate.cs 也只保留 evaluator/helper;对应的 *Result.cs 文件拥有 internal constructor、公开属性、diagnostic 与 ToString。

规则

  • 模块化时不得改名 C ABI 导出入口。
  • 不得为了移动代码改变 manifest 语义。
  • 不得在源码整理过程中向普通 C# 用户暴露裸 IntPtr。
  • 新增公开 API 时应选择已有职责模块;只有形成独立职责边界时才增加新目录。
  • 每次拆分后都必须回归原生构建、托管构建和 binding generator 确定性验证。