Skip to content

Commit 124fda4

Browse files
committed
platform default
1 parent a764a32 commit 124fda4

File tree

4 files changed

+16
-5
lines changed

4 files changed

+16
-5
lines changed

src/Sdcb.PaddleInference/PaddleDevice.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System;
33
using System.Collections.Generic;
44
using System.IO;
5+
using System.Runtime.InteropServices;
56

67
namespace Sdcb.PaddleInference;
78

@@ -173,4 +174,16 @@ private static void CommonAction(PaddleConfig cfg, bool memoryOptimized, bool gl
173174
cfg.MemoryOptimized = memoryOptimized;
174175
//cfg.GLogEnabled = glogEnabled;
175176
}
177+
178+
/// <summary>
179+
/// Gets the default device configuration for Paddle operations based on the current operating system and
180+
/// architecture.
181+
/// </summary>
182+
public static Action<PaddleConfig> PlatformDefault => RuntimeInformation.IsOSPlatform(OSPlatform.OSX)
183+
? RuntimeInformation.OSArchitecture switch
184+
{
185+
Architecture.X64 => Onnx(),
186+
_ => Blas(),
187+
}
188+
: Mkldnn();
176189
}

src/Sdcb.PaddleInference/Sdcb.PaddleInference.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
</PackageReference>
3939
<PackageReference Include="System.Memory" Version="4.5.5" Condition="'$(TargetFramework)' == 'netstandard2.0'" />
4040
<PackageReference Include="System.Memory" Version="4.5.5" Condition="'$(TargetFramework)' == 'net45'" />
41+
<PackageReference Include="System.Runtime.InteropServices.RuntimeInformation" Version="4.3.0" />
4142
<PackageReference Include="System.Text.Encoding.CodePages" Version="8.0.0" Condition="'$(TargetFramework)' == 'netstandard2.0'" />
4243
</ItemGroup>
4344

src/Sdcb.PaddleOCR/OcrBaseModel.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,7 @@ public OcrBaseModel(ModelVersion version)
3333
/// <summary>
3434
/// Gets the default device for the model.
3535
/// </summary>
36-
public virtual Action<PaddleConfig> DefaultDevice =>
37-
RuntimeInformation.IsOSPlatform(OSPlatform.OSX)
38-
? PaddleDevice.Blas()
39-
: PaddleDevice.Mkldnn();
36+
public virtual Action<PaddleConfig> DefaultDevice => PaddleDevice.PlatformDefault;
4037

4138
/// <summary>
4239
/// Configure the device related config of the <see cref="PaddleConfig"/>.

src/Sdcb.PaddleOCR/PaddleOcrTableRecognizer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public class PaddleOcrTableRecognizer : IDisposable
3030
/// <param name="model">The table recognition model.</param>
3131
/// <param name="configure">The action to configure Paddle device.</param>
3232
public PaddleOcrTableRecognizer(TableRecognitionModel model, Action<PaddleConfig>? configure = null) : this(model,
33-
model.CreateConfig().Apply(configure ?? PaddleDevice.Mkldnn()).CreatePredictor())
33+
model.CreateConfig().Apply(configure ?? PaddleDevice.PlatformDefault).CreatePredictor())
3434
{
3535
}
3636

0 commit comments

Comments
 (0)