Skip to content
This repository was archived by the owner on Nov 27, 2024. It is now read-only.

Commit 99573f0

Browse files
committed
Allocate a larger memory buffer for image processing
1 parent 1486e7d commit 99573f0

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

OnnxStack.StableDiffusion/Registration.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
using Microsoft.Extensions.DependencyInjection;
22
using OnnxStack.StableDiffusion.Common;
33
using OnnxStack.StableDiffusion.Services;
4+
using SixLabors.ImageSharp;
5+
using SixLabors.ImageSharp.Memory;
46

57
namespace OnnxStack.Core
68
{
@@ -15,10 +17,25 @@ public static class Registration
1517
/// <param name="serviceCollection">The service collection.</param>
1618
public static void AddOnnxStackStableDiffusion(this IServiceCollection serviceCollection)
1719
{
20+
ConfigureLibraries();
1821
serviceCollection.AddOnnxStack();
1922
serviceCollection.AddSingleton<IPromptService, PromptService>();
2023
serviceCollection.AddSingleton<ISchedulerService, SchedulerService>();
2124
serviceCollection.AddSingleton<IStableDiffusionService, StableDiffusionService>();
2225
}
26+
27+
28+
/// <summary>
29+
/// Configures any 3rd party libraries.
30+
/// </summary>
31+
private static void ConfigureLibraries()
32+
{
33+
// Create a 100MB image buffer pool
34+
Configuration.Default.PreferContiguousImageBuffers = true;
35+
Configuration.Default.MemoryAllocator = MemoryAllocator.Create(new MemoryAllocatorOptions
36+
{
37+
MaximumPoolSizeMegabytes = 100,
38+
});
39+
}
2340
}
2441
}

0 commit comments

Comments
 (0)