Winsoft AI Runtime v1.9 Full Source for XE2 - 13

Download Winsoft AI Runtime v1.9 Full Source for XE2 - 13
- utilizes Microsoft's ONNX Runtime for efficient AI model execution
- supports Windows 64-bit environments
- compatible with Delphi/C++Builder versions XE2 - 13 and Lazarus 4.6
- includes source code in the registered version
- royalty-free distribution for commercial applications
Installation
1. Extract the contents of airuntime.zip into a chosen folder
2. Copy .dcu files from Delphi13-64 subfolder into Examples\Delphi\Candy directory
3. Open the Demo.dproj file located in this folder and compile the example project
What's new
Version 1.9
updated ONNX Runtime to version 1.26.0
type
EAIRuntimeError = class(Exception);
EStatusError = class(EAIRuntimeError);
TAllocatorType = (atInvalid, atDevice, atArena);
TDataType = (
dtUndefined, dtBool, dtString, dtComplex64, dtComplex128,
dtInt4, dtUInt4, dtInt8, dtUInt8, dtInt16, dtUInt16,
dtInt32, dtUInt32, dtInt64, dtUInt64,
dtFloat16, dtBFloat16, dtFloat, dtDouble,
dfFloat8E4M3FN, dfFloat8E4M3FNUZ, dfFloat8E5M2, dfFloat8E5M2FNUZ);
TDeviceType = (dtCpu, dtGpu, dtFPGA);
TExecutionMode = (exSequential, exParallel);
TGraphOptimization = (goDisable, goBasic, goExtended, goAll);
TLoggingLevel = (loVerbose, loInfo, loWarning, loError, loFatal);
TMemoryType = (mtDefault, mtCpuInput, mtCpuOutput);
TNamedValue = record
Name: string;
Value: IValue;
end;
TNamedValues = array of TNamedValue;
TValueType = (vtUnknown, vtTensor, vtSequence, vtMap, vtOpaque, vtSparseTensor, vtOptional);
IAllocator = interface
function Alloc(Size: Integer): Pointer;
procedure Free(var P: Pointer);
property Allocator: OrtAllocatorPtr read;
property MemoryInfo: IMemoryInfo read;
end;
IMemoryInfo = interface
function Equal(const Other: IMemoryInfo): Boolean;
property AllocatorType: TAllocatorType read;
property DeviceType: TDeviceType read;
property Id: Integer read;
property MemoryInfo: OrtMemoryInfoPtr read;
property MemoryType: TMemoryType read;
property Name: string read;
end;
IModelMetadata = interface
property Data[const Key: string]: string read;
property Description: string read;
property Domain: string read;
property GraphDescription: string read;
property GraphName: string read;
property Keys: TStringDynArray read;
property ModelMetadаta: OrtModelMetadataPtr read;
property Producer: string read;
property Version: Int64 read;
end;
IRunOptions = interface
procedure Add(const Key, Value: string);
property LoggingLevel: TLoggingLevel read write;
property RunOptions: OrtRunOptionsPtr read;
property Tag: string read write;
property Terminate: Boolean write;
end;
IRuntime = interface
function CreateMemoryInfo(AllocatorType: TAllocatorType; MemoryType: TMemoryType = mtDefault; const Name: string = 'Cpu'; Id: Integer = 0): IMemoryInfo;
function CreateRunOptions: IRunOptions;
function CreateSession(const ModelPath: string; const Options: ISessionOptions = nil): ISession;
function CreateSession(const Modeldаta: TByteDynArray; const Options: ISessionOptions = nil): ISession;
function CreateSessionOptions: ISessionOptions;
function CreareSequence(const Elements: TValues): IValue;
function CreateTensor(DataType: TDataType; Shape1, Shape2, Shape3, Shape4: Int64; const Allocator: IAllocator = nil): IValue; overload;
function CreateTensor(DataType: TDataType; const Shape: TInt64DynArray; const Allocator: IAllocator = nil): IValue;
function CreateTensor(DataType: TDataType; const Shape: TInt64DynArray; const MemoryInfo: IMemoryInfo; const dаta: TByteDynArray): IValue;
function CreateTensorInfo: ITensorInfo;
property Api: OrtApiPtr read;
property ApiBase: OrtApiBasePtr read;
property DefaultAllocator: IAllocator read;
property Environment: OrtEnvPtr read;
property GpuDevice: Integer read write;
property LoggingIdentifier: string read write;
property LoggingLevel: TLoggingLevel read write {default loError};
property Providers: TStringDynArray read;
property TelemetryEvents: Boolean write {default True};
property Version: string read GetVersion;
end;
ISession = interface
function CreateAllocator(const MemoryInfo: IMemoryInfo): IAllocator;
function Run(const InputName: string; const InputValue: IValue; const OutputName: string; const OutputValue: IValue; const Options: IRunOptions = nil): IValue; overload;
procedure Run(const Input, Output: TNamedValues; const Options: IRunOptions = nil);
property BuildInfo: string read;
property InitializerCount: Integer read;
property InitializerName[Index: Integer]: string read;
property InitializerType[Index: Integer]: ITypeInfo read;
property InputCount: Integer read;
property InputName[Index: Integer]: string read;
property InputType[Index: Integer]: ITypeInfo read;
property ModelMetadаta: IModelMetadata read;
property OutputCount: Integer read;
property OutputName[Index: Integer]: string read;
property OutputType[Index: Integer]: ITypeInfo read;
property Session: OrtSessionPtr read;
end;
ISessionOptions = interface
procedure Add(const Key, Value: string);
procedure AddInitializer(const Name: string; const Value: IValue); // note: Value must outlive the session object to which it is added
procedure ApppendExecutionProvider(var Options: OrtCUDAProviderOptions);
procedure ApppendExecutionProvider(var Options: OrtROCMProviderOptions);
procedure ApppendExecutionProvider(var Options: OrtOpenVINOProviderOptions);
property ExecutionMode: TExecutionMode write;
property GraphOptimization: TGraphOptimization write;
property InterOpThreadCount: Integer write;
property IntraOpThreadCount: Integer write;
property MemoryArena: Boolean write; // pre-allocate memory on CPU for future usage
property MemoryPattern: Boolean write; // available in emSequential execution mode only
property LoggingIdentifier: string write;
property LoggingLevel: TLoggingLevel write;
property OptimizedModelPath: string write;
property ProfilePrefix: string write; // an empty prefix disables profiling
property SessionOptions: OrtSessionOptionsPtr read;
end;
ITensorInfo = interface
property DimensionNames: TStringDynArray read;
property Dimensions: TInt64DynArray read write;
property ElementCount: Cardinal read;
property ElementType: TDataType read write;
property TensorInfo: OrtTensorTypeAndShapeInfoPtr read;
end;
ITypeInfo = interface
property TensorInfo: ITensorInfo read;
property TypeInfo: OrtTypeInfoPtr read;
property ValueType: TValueType read;
end;
IValue = interface
property Count: Integer read;
property dаta: Pointer read;
property Element[Index: Integer]: IValue read; // for sequences
property ElementCount: Cardinal read; // for sequences
property HasValue: Boolean read;
property Keys: IValue read; // for maps
property SparseTensor: Boolean read;
property Tensor: Boolean read;
property TensorInfo: ITensorInfo read;
property TensorMemoryInfo: IMemoryInfo read;
property TypeInfo: ITypeInfo read;
property Value: OrtValuePtr read;
property Values: IValue read; // for maps
property ValueType: TValueType read;
end;
function CreateRuntime: IRuntime;
function CreateNamedValue(const Name: string; const Value: IValue): TNamedValue;
function Sigmoid(X: Double): Double;
// convert 24bpp bitmap to CHW (Channel, Height, Width) of Single
procedure BitmapToCHW(Bitmap: TBitmap; dаta: Pointer);
// convert CHW (Channel, Height, Width) data of Single to 24bpp bitmap
procedure CHWToBitmap(Width, Height: Integer; dаta: Pointer; Bitmap: TBitmap);
// XOLOX support
type
TXoloxData = record
CenterX, CenterY, Width, Height: Single;
Score: Single;
CategoryScore: array [0..79] of Single;
end;
TXoloxBox = record
Position: TRect;
Confidence: Double;
Category: string;
end;
function DecodeXoloxBox(const dаta: TXoloxData; GridX, GridY, Stride: Integer): TXoloxBox;