ai.muna.muna 0.0.42
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Editor/Build/AndroidBuildHandler.cs +96 -0
- package/Editor/Build/AndroidBuildHandler.cs.meta +11 -0
- package/Editor/Build/BuildHandler.cs +128 -0
- package/Editor/Build/BuildHandler.cs.meta +11 -0
- package/Editor/Build/LinuxBuildHandler.cs +26 -0
- package/Editor/Build/LinuxBuildHandler.cs.meta +11 -0
- package/Editor/Build/WebGLBuildHandler.cs +69 -0
- package/Editor/Build/WebGLBuildHandler.cs.meta +11 -0
- package/Editor/Build/WindowsBuildHandler.cs +24 -0
- package/Editor/Build/WindowsBuildHandler.cs.meta +11 -0
- package/Editor/Build/iOSBuildHandler.cs +119 -0
- package/Editor/Build/iOSBuildHandler.cs.meta +11 -0
- package/Editor/Build/macOSBuildHandler.cs +133 -0
- package/Editor/Build/macOSBuildHandler.cs.meta +11 -0
- package/Editor/Build.meta +8 -0
- package/Editor/Muna.Editor.asmdef +18 -0
- package/Editor/Muna.Editor.asmdef.meta +7 -0
- package/Editor/MunaMenu.cs +32 -0
- package/Editor/MunaMenu.cs.meta +11 -0
- package/Editor/MunaProjectSettings.cs +43 -0
- package/Editor/MunaProjectSettings.cs.meta +11 -0
- package/Editor/MunaSettingsProvider.cs +27 -0
- package/Editor/MunaSettingsProvider.cs.meta +11 -0
- package/Editor.meta +8 -0
- package/LICENSE +201 -0
- package/LICENSE.meta +7 -0
- package/Plugins/Android/Function.aar +0 -0
- package/Plugins/Android/Function.aar.meta +32 -0
- package/Plugins/Android.meta +8 -0
- package/Plugins/Linux/arm64/libFunction.so +0 -0
- package/Plugins/Linux/arm64/libFunction.so.meta +62 -0
- package/Plugins/Linux/arm64.meta +8 -0
- package/Plugins/Linux/x86_64/libFunction.so +0 -0
- package/Plugins/Linux/x86_64/libFunction.so.meta +82 -0
- package/Plugins/Linux/x86_64.meta +8 -0
- package/Plugins/Linux.meta +8 -0
- package/Plugins/Web/libFunction.a +0 -0
- package/Plugins/Web/libFunction.a.meta +87 -0
- package/Plugins/Web.meta +8 -0
- package/Plugins/Windows/arm64/Function.dll +0 -0
- package/Plugins/Windows/arm64/Function.dll.meta +58 -0
- package/Plugins/Windows/arm64.meta +8 -0
- package/Plugins/Windows/x86_64/Function.dll +0 -0
- package/Plugins/Windows/x86_64/Function.dll.meta +82 -0
- package/Plugins/Windows/x86_64.meta +8 -0
- package/Plugins/Windows.meta +8 -0
- package/Plugins/iOS/Function.xcframework/Info.plist +75 -0
- package/Plugins/iOS/Function.xcframework/ios-arm64/Function.framework/Function +0 -0
- package/Plugins/iOS/Function.xcframework/ios-arm64/Function.framework/Headers/FXNConfiguration.h +313 -0
- package/Plugins/iOS/Function.xcframework/ios-arm64/Function.framework/Headers/FXNPrediction.h +165 -0
- package/Plugins/iOS/Function.xcframework/ios-arm64/Function.framework/Headers/FXNPredictionStream.h +63 -0
- package/Plugins/iOS/Function.xcframework/ios-arm64/Function.framework/Headers/FXNPredictor.h +108 -0
- package/Plugins/iOS/Function.xcframework/ios-arm64/Function.framework/Headers/FXNStatus.h +42 -0
- package/Plugins/iOS/Function.xcframework/ios-arm64/Function.framework/Headers/FXNValue.h +395 -0
- package/Plugins/iOS/Function.xcframework/ios-arm64/Function.framework/Headers/FXNValueMap.h +148 -0
- package/Plugins/iOS/Function.xcframework/ios-arm64/Function.framework/Headers/FXNVersion.h +26 -0
- package/Plugins/iOS/Function.xcframework/ios-arm64/Function.framework/Headers/Function.h +18 -0
- package/Plugins/iOS/Function.xcframework/ios-arm64/Function.framework/Info.plist +0 -0
- package/Plugins/iOS/Function.xcframework/ios-arm64/Function.framework/Modules/module.modulemap +6 -0
- package/Plugins/iOS/Function.xcframework/ios-arm64/Function.framework/PrivacyInfo.xcprivacy +36 -0
- package/Plugins/iOS/Function.xcframework/ios-arm64/Function.framework/_CodeSignature/CodeResources +223 -0
- package/Plugins/iOS/Function.xcframework/ios-arm64_x86_64-simulator/Function.framework/Function +0 -0
- package/Plugins/iOS/Function.xcframework/ios-arm64_x86_64-simulator/Function.framework/Headers/FXNConfiguration.h +313 -0
- package/Plugins/iOS/Function.xcframework/ios-arm64_x86_64-simulator/Function.framework/Headers/FXNPrediction.h +165 -0
- package/Plugins/iOS/Function.xcframework/ios-arm64_x86_64-simulator/Function.framework/Headers/FXNPredictionStream.h +63 -0
- package/Plugins/iOS/Function.xcframework/ios-arm64_x86_64-simulator/Function.framework/Headers/FXNPredictor.h +108 -0
- package/Plugins/iOS/Function.xcframework/ios-arm64_x86_64-simulator/Function.framework/Headers/FXNStatus.h +42 -0
- package/Plugins/iOS/Function.xcframework/ios-arm64_x86_64-simulator/Function.framework/Headers/FXNValue.h +395 -0
- package/Plugins/iOS/Function.xcframework/ios-arm64_x86_64-simulator/Function.framework/Headers/FXNValueMap.h +148 -0
- package/Plugins/iOS/Function.xcframework/ios-arm64_x86_64-simulator/Function.framework/Headers/FXNVersion.h +26 -0
- package/Plugins/iOS/Function.xcframework/ios-arm64_x86_64-simulator/Function.framework/Headers/Function.h +18 -0
- package/Plugins/iOS/Function.xcframework/ios-arm64_x86_64-simulator/Function.framework/Info.plist +0 -0
- package/Plugins/iOS/Function.xcframework/ios-arm64_x86_64-simulator/Function.framework/Modules/module.modulemap +6 -0
- package/Plugins/iOS/Function.xcframework/ios-arm64_x86_64-simulator/Function.framework/PrivacyInfo.xcprivacy +36 -0
- package/Plugins/iOS/Function.xcframework/ios-arm64_x86_64-simulator/Function.framework/_CodeSignature/CodeResources +223 -0
- package/Plugins/iOS/Function.xcframework/xros-arm64/Function.framework/Function +0 -0
- package/Plugins/iOS/Function.xcframework/xros-arm64/Function.framework/Headers/FXNConfiguration.h +313 -0
- package/Plugins/iOS/Function.xcframework/xros-arm64/Function.framework/Headers/FXNPrediction.h +165 -0
- package/Plugins/iOS/Function.xcframework/xros-arm64/Function.framework/Headers/FXNPredictionStream.h +63 -0
- package/Plugins/iOS/Function.xcframework/xros-arm64/Function.framework/Headers/FXNPredictor.h +108 -0
- package/Plugins/iOS/Function.xcframework/xros-arm64/Function.framework/Headers/FXNStatus.h +42 -0
- package/Plugins/iOS/Function.xcframework/xros-arm64/Function.framework/Headers/FXNValue.h +395 -0
- package/Plugins/iOS/Function.xcframework/xros-arm64/Function.framework/Headers/FXNValueMap.h +148 -0
- package/Plugins/iOS/Function.xcframework/xros-arm64/Function.framework/Headers/FXNVersion.h +26 -0
- package/Plugins/iOS/Function.xcframework/xros-arm64/Function.framework/Headers/Function.h +18 -0
- package/Plugins/iOS/Function.xcframework/xros-arm64/Function.framework/Info.plist +0 -0
- package/Plugins/iOS/Function.xcframework/xros-arm64/Function.framework/Modules/module.modulemap +6 -0
- package/Plugins/iOS/Function.xcframework/xros-arm64/Function.framework/PrivacyInfo.xcprivacy +36 -0
- package/Plugins/iOS/Function.xcframework/xros-arm64/Function.framework/_CodeSignature/CodeResources +223 -0
- package/Plugins/iOS/Function.xcframework/xros-arm64_x86_64-simulator/Function.framework/Function +0 -0
- package/Plugins/iOS/Function.xcframework/xros-arm64_x86_64-simulator/Function.framework/Headers/FXNConfiguration.h +313 -0
- package/Plugins/iOS/Function.xcframework/xros-arm64_x86_64-simulator/Function.framework/Headers/FXNPrediction.h +165 -0
- package/Plugins/iOS/Function.xcframework/xros-arm64_x86_64-simulator/Function.framework/Headers/FXNPredictionStream.h +63 -0
- package/Plugins/iOS/Function.xcframework/xros-arm64_x86_64-simulator/Function.framework/Headers/FXNPredictor.h +108 -0
- package/Plugins/iOS/Function.xcframework/xros-arm64_x86_64-simulator/Function.framework/Headers/FXNStatus.h +42 -0
- package/Plugins/iOS/Function.xcframework/xros-arm64_x86_64-simulator/Function.framework/Headers/FXNValue.h +395 -0
- package/Plugins/iOS/Function.xcframework/xros-arm64_x86_64-simulator/Function.framework/Headers/FXNValueMap.h +148 -0
- package/Plugins/iOS/Function.xcframework/xros-arm64_x86_64-simulator/Function.framework/Headers/FXNVersion.h +26 -0
- package/Plugins/iOS/Function.xcframework/xros-arm64_x86_64-simulator/Function.framework/Headers/Function.h +18 -0
- package/Plugins/iOS/Function.xcframework/xros-arm64_x86_64-simulator/Function.framework/Info.plist +0 -0
- package/Plugins/iOS/Function.xcframework/xros-arm64_x86_64-simulator/Function.framework/Modules/module.modulemap +6 -0
- package/Plugins/iOS/Function.xcframework/xros-arm64_x86_64-simulator/Function.framework/PrivacyInfo.xcprivacy +36 -0
- package/Plugins/iOS/Function.xcframework/xros-arm64_x86_64-simulator/Function.framework/_CodeSignature/CodeResources +223 -0
- package/Plugins/iOS/Function.xcframework.meta +83 -0
- package/Plugins/iOS.meta +8 -0
- package/Plugins/macOS/Function.dylib +0 -0
- package/Plugins/macOS/Function.dylib.meta +82 -0
- package/Plugins/macOS.meta +8 -0
- package/Plugins.meta +8 -0
- package/README.md +79 -0
- package/README.md.meta +7 -0
- package/Runtime/API/DotNetClient.cs +106 -0
- package/Runtime/API/DotNetClient.cs.meta +11 -0
- package/Runtime/API/MunaClient.cs +96 -0
- package/Runtime/API/MunaClient.cs.meta +11 -0
- package/Runtime/API.meta +8 -0
- package/Runtime/Beta/BetaClient.cs +33 -0
- package/Runtime/Beta/BetaClient.cs.meta +11 -0
- package/Runtime/Beta/PredictionService.cs +32 -0
- package/Runtime/Beta/PredictionService.cs.meta +11 -0
- package/Runtime/Beta/RemoteAcceleration.cs +38 -0
- package/Runtime/Beta/RemoteAcceleration.cs.meta +11 -0
- package/Runtime/Beta/RemotePredictionService.cs +187 -0
- package/Runtime/Beta/RemotePredictionService.cs.meta +11 -0
- package/Runtime/Beta/Value.cs +92 -0
- package/Runtime/Beta/Value.cs.meta +11 -0
- package/Runtime/Beta.meta +8 -0
- package/Runtime/C/Configuration.cs +139 -0
- package/Runtime/C/Configuration.cs.meta +11 -0
- package/Runtime/C/Function.cs +294 -0
- package/Runtime/C/Function.cs.meta +11 -0
- package/Runtime/C/Prediction.cs +70 -0
- package/Runtime/C/Prediction.cs.meta +11 -0
- package/Runtime/C/PredictionStream.cs +36 -0
- package/Runtime/C/PredictionStream.cs.meta +11 -0
- package/Runtime/C/Predictor.cs +42 -0
- package/Runtime/C/Predictor.cs.meta +11 -0
- package/Runtime/C/Value.cs +194 -0
- package/Runtime/C/Value.cs.meta +11 -0
- package/Runtime/C/ValueMap.cs +50 -0
- package/Runtime/C/ValueMap.cs.meta +11 -0
- package/Runtime/C.meta +8 -0
- package/Runtime/Muna.Runtime.asmdef +27 -0
- package/Runtime/Muna.Runtime.asmdef.meta +7 -0
- package/Runtime/Muna.cs +109 -0
- package/Runtime/Muna.cs.meta +11 -0
- package/Runtime/Services/Prediction.cs +247 -0
- package/Runtime/Services/Prediction.cs.meta +11 -0
- package/Runtime/Services/Predictor.cs +44 -0
- package/Runtime/Services/Predictor.cs.meta +11 -0
- package/Runtime/Services/User.cs +43 -0
- package/Runtime/Services/User.cs.meta +11 -0
- package/Runtime/Services.meta +8 -0
- package/Runtime/Types/Dtype.cs +118 -0
- package/Runtime/Types/Dtype.cs.meta +11 -0
- package/Runtime/Types/Image.cs +93 -0
- package/Runtime/Types/Image.cs.meta +11 -0
- package/Runtime/Types/Prediction.cs +113 -0
- package/Runtime/Types/Prediction.cs.meta +11 -0
- package/Runtime/Types/Predictor.cs +193 -0
- package/Runtime/Types/Predictor.cs.meta +11 -0
- package/Runtime/Types/Tensor.cs +58 -0
- package/Runtime/Types/Tensor.cs.meta +11 -0
- package/Runtime/Types/User.cs +54 -0
- package/Runtime/Types/User.cs.meta +11 -0
- package/Runtime/Types.meta +8 -0
- package/Runtime.meta +8 -0
- package/Unity/API/PredictionCacheClient.cs +144 -0
- package/Unity/API/PredictionCacheClient.cs.meta +11 -0
- package/Unity/API/UnityClient.cs +147 -0
- package/Unity/API/UnityClient.cs.meta +11 -0
- package/Unity/API.meta +8 -0
- package/Unity/Internal/MunaSettings.cs +59 -0
- package/Unity/Internal/MunaSettings.cs.meta +11 -0
- package/Unity/Internal.meta +8 -0
- package/Unity/Muna.Unity.asmdef +29 -0
- package/Unity/Muna.Unity.asmdef.meta +7 -0
- package/Unity/MunaUnity.cs +130 -0
- package/Unity/MunaUnity.cs.meta +11 -0
- package/Unity/Types/CachedPrediction.cs +36 -0
- package/Unity/Types/CachedPrediction.cs.meta +11 -0
- package/Unity/Types.meta +8 -0
- package/Unity.meta +8 -0
- package/package.json +38 -0
- package/package.json.meta +7 -0
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Muna
|
|
3
|
+
* Copyright © 2025 NatML Inc. All rights reserved.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
#nullable enable
|
|
7
|
+
|
|
8
|
+
namespace Muna.Beta {
|
|
9
|
+
|
|
10
|
+
using System;
|
|
11
|
+
using System.IO;
|
|
12
|
+
using System.Linq;
|
|
13
|
+
using System.Runtime.CompilerServices;
|
|
14
|
+
using System.Runtime.Serialization;
|
|
15
|
+
using System.Text;
|
|
16
|
+
|
|
17
|
+
/// <summary>
|
|
18
|
+
/// Remote prediction value.
|
|
19
|
+
/// </summary>
|
|
20
|
+
[Preserve, Serializable]
|
|
21
|
+
internal class Value {
|
|
22
|
+
|
|
23
|
+
/// <summary>
|
|
24
|
+
/// Value URL.
|
|
25
|
+
/// </summary>
|
|
26
|
+
public string? data;
|
|
27
|
+
|
|
28
|
+
/// <summary>
|
|
29
|
+
/// Value type.
|
|
30
|
+
/// </summary>
|
|
31
|
+
public Dtype type;
|
|
32
|
+
|
|
33
|
+
/// <summary>
|
|
34
|
+
/// Value shape.
|
|
35
|
+
/// This is `null` if shape information is not available or applicable.
|
|
36
|
+
/// </summary>
|
|
37
|
+
public int[]? shape;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
internal static class ValueUtils {
|
|
41
|
+
|
|
42
|
+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
43
|
+
public static object ToObject<T>(this Stream stream, int[] shape) where T : unmanaged {
|
|
44
|
+
var data = stream.ToArray<T>();
|
|
45
|
+
return shape.Length > 0 ? new Tensor<T>(data, shape) : data[0];
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
49
|
+
public static object ToObject(this Enum value) {
|
|
50
|
+
var fieldInfo = value.GetType().GetField(value.ToString());
|
|
51
|
+
var attribute = fieldInfo?
|
|
52
|
+
.GetCustomAttributes(typeof(EnumMemberAttribute), false)?
|
|
53
|
+
.FirstOrDefault() as EnumMemberAttribute;
|
|
54
|
+
return (attribute?.IsValueSetExplicitly ?? false) ? attribute.Value : Convert.ToInt32(value);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
58
|
+
public static unsafe Stream ToStream<T>(this T[] data) where T : unmanaged {
|
|
59
|
+
if (data is byte[] raw)
|
|
60
|
+
return new MemoryStream(raw);
|
|
61
|
+
var size = data.Length * sizeof(T);
|
|
62
|
+
var array = new byte[size];
|
|
63
|
+
fixed (void* src = data, dst = array)
|
|
64
|
+
Buffer.MemoryCopy(src, dst, size, size);
|
|
65
|
+
return new MemoryStream(array);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
69
|
+
public static Stream ToStream(this string data) => new MemoryStream(Encoding.UTF8.GetBytes(data));
|
|
70
|
+
|
|
71
|
+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
72
|
+
public static unsafe T[] ToArray<T>(this Stream stream) where T : unmanaged {
|
|
73
|
+
var result = new T[stream.Length / sizeof(T)];
|
|
74
|
+
fixed (T* dst = result)
|
|
75
|
+
using (var dstStream = new UnmanagedMemoryStream(
|
|
76
|
+
(byte*)dst,
|
|
77
|
+
stream.Length,
|
|
78
|
+
stream.Length,
|
|
79
|
+
FileAccess.Write
|
|
80
|
+
))
|
|
81
|
+
stream.CopyTo(dstStream);
|
|
82
|
+
return result;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
86
|
+
public static Stream Clone(this Stream stream) {
|
|
87
|
+
var result = new MemoryStream();
|
|
88
|
+
stream.CopyTo(result);
|
|
89
|
+
return result;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Muna
|
|
3
|
+
* Copyright © 2025 NatML Inc. All rights reserved.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
#nullable enable
|
|
7
|
+
|
|
8
|
+
namespace Muna.C {
|
|
9
|
+
|
|
10
|
+
using System;
|
|
11
|
+
using System.Runtime.InteropServices;
|
|
12
|
+
using System.Text;
|
|
13
|
+
using System.Threading.Tasks;
|
|
14
|
+
using static Muna;
|
|
15
|
+
|
|
16
|
+
public sealed class Configuration : IDisposable {
|
|
17
|
+
|
|
18
|
+
#region --Client API--
|
|
19
|
+
|
|
20
|
+
public string tag {
|
|
21
|
+
get {
|
|
22
|
+
var sb = new StringBuilder(2048);
|
|
23
|
+
configuration.GetConfigurationTag(sb, sb.Capacity).Throw();
|
|
24
|
+
return sb.ToString();
|
|
25
|
+
}
|
|
26
|
+
set => configuration.SetConfigurationTag(value).Throw();
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
public string token {
|
|
30
|
+
get {
|
|
31
|
+
var sb = new StringBuilder(2048);
|
|
32
|
+
configuration.GetConfigurationToken(sb, sb.Capacity).Throw();
|
|
33
|
+
return sb.ToString();
|
|
34
|
+
}
|
|
35
|
+
set => configuration.SetConfigurationToken(value).Throw();
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
public Acceleration acceleration {
|
|
39
|
+
get => configuration.GetConfigurationAcceleration(out var acceleration).Throw() == Status.Ok ? acceleration : default;
|
|
40
|
+
set => configuration.SetConfigurationAcceleration(value).Throw();
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
public IntPtr device {
|
|
44
|
+
get => configuration.GetConfigurationDevice(out var device).Throw() == Status.Ok ? device : default;
|
|
45
|
+
set => configuration.SetConfigurationDevice(value).Throw();
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
public static string ConfigurationId {
|
|
49
|
+
get {
|
|
50
|
+
var sb = new StringBuilder(2048);
|
|
51
|
+
GetConfigurationUniqueID(sb, sb.Capacity).Throw();
|
|
52
|
+
return sb.ToString();
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
public static string ClientId {
|
|
57
|
+
get {
|
|
58
|
+
var sb = new StringBuilder(64);
|
|
59
|
+
GetConfigurationClientID(sb, sb.Capacity).Throw();
|
|
60
|
+
return sb.ToString();
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
public static Task InitializationTask {
|
|
65
|
+
get {
|
|
66
|
+
#if UNITY_WEBGL && !UNITY_EDITOR
|
|
67
|
+
var tcs = new TaskCompletionSource<bool>();
|
|
68
|
+
var context = GCHandle.Alloc(tcs, GCHandleType.Normal);
|
|
69
|
+
SetInitializationHandler(OnFunctionInitialized, (IntPtr)context);
|
|
70
|
+
return tcs.Task;
|
|
71
|
+
[DllImport(Muna.Assembly, EntryPoint = @"FXNSetInitializationHandler")]
|
|
72
|
+
static extern Status SetInitializationHandler (Action<IntPtr> handler, IntPtr context);
|
|
73
|
+
#else
|
|
74
|
+
return Task.CompletedTask;
|
|
75
|
+
#endif
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
public Configuration() {
|
|
80
|
+
CreateConfiguration(out var configuration).Throw();
|
|
81
|
+
this.configuration = configuration;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
public Task AddResource(string type, string path) {
|
|
85
|
+
#if UNITY_WEBGL && !UNITY_EDITOR
|
|
86
|
+
var tcs = new TaskCompletionSource<bool>();
|
|
87
|
+
var context = GCHandle.Alloc(tcs, GCHandleType.Normal);
|
|
88
|
+
AddConfigurationResource(configuration, type, path, OnAddConfigurationResource, (IntPtr)context);
|
|
89
|
+
return tcs.Task;
|
|
90
|
+
[DllImport(Muna.Assembly, EntryPoint = @"FXNConfigurationAddResourceAsync")]
|
|
91
|
+
static extern Status AddConfigurationResource(
|
|
92
|
+
IntPtr configuration,
|
|
93
|
+
[MarshalAs(UnmanagedType.LPUTF8Str)] string type,
|
|
94
|
+
[MarshalAs(UnmanagedType.LPUTF8Str)] string path,
|
|
95
|
+
Action<IntPtr, Status> handler,
|
|
96
|
+
IntPtr context
|
|
97
|
+
);
|
|
98
|
+
#else
|
|
99
|
+
try {
|
|
100
|
+
configuration.AddConfigurationResource(type, path).Throw();
|
|
101
|
+
return Task.CompletedTask;
|
|
102
|
+
} catch (Exception ex) {
|
|
103
|
+
return Task.FromException(ex);
|
|
104
|
+
}
|
|
105
|
+
#endif
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
public void Dispose() => configuration.ReleaseConfiguration();
|
|
109
|
+
#endregion
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
#region --Operations--
|
|
113
|
+
private readonly IntPtr configuration;
|
|
114
|
+
|
|
115
|
+
public static implicit operator IntPtr(Configuration configuration) => configuration.configuration;
|
|
116
|
+
|
|
117
|
+
[MonoPInvokeCallback(typeof(Action<IntPtr>))]
|
|
118
|
+
private static void OnFunctionInitialized(IntPtr context) {
|
|
119
|
+
var handle = (GCHandle)context;
|
|
120
|
+
var tcs = handle.Target as TaskCompletionSource<bool>;
|
|
121
|
+
handle.Free();
|
|
122
|
+
tcs?.SetResult(true);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
[MonoPInvokeCallback(typeof(Action<IntPtr, Status>))]
|
|
126
|
+
private static void OnAddConfigurationResource(IntPtr context, Status status) {
|
|
127
|
+
var handle = (GCHandle)context;
|
|
128
|
+
var tcs = handle.Target as TaskCompletionSource<bool>;
|
|
129
|
+
handle.Free();
|
|
130
|
+
try {
|
|
131
|
+
status.Throw();
|
|
132
|
+
tcs?.SetResult(true);
|
|
133
|
+
} catch (Exception ex) {
|
|
134
|
+
tcs?.SetException(ex);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
#endregion
|
|
138
|
+
}
|
|
139
|
+
}
|
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Muna
|
|
3
|
+
* Copyright © 2025 NatML Inc. All rights reserved.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
#nullable enable
|
|
7
|
+
|
|
8
|
+
namespace Muna.C {
|
|
9
|
+
|
|
10
|
+
using System;
|
|
11
|
+
using System.Runtime.InteropServices;
|
|
12
|
+
using System.Text;
|
|
13
|
+
|
|
14
|
+
internal static unsafe class Muna {
|
|
15
|
+
|
|
16
|
+
public const string Assembly =
|
|
17
|
+
#if (UNITY_IOS || UNITY_VISIONOS || UNITY_WEBGL) && !UNITY_EDITOR
|
|
18
|
+
@"__Internal";
|
|
19
|
+
#else
|
|
20
|
+
@"Function";
|
|
21
|
+
#endif
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
#region --Enumerations--
|
|
25
|
+
/// <summary>
|
|
26
|
+
/// Status codes.
|
|
27
|
+
/// </summary>
|
|
28
|
+
public enum Status : int {
|
|
29
|
+
Ok = 0,
|
|
30
|
+
InvalidArgument = 1,
|
|
31
|
+
InvalidOperation = 2,
|
|
32
|
+
NotImplemented = 3,
|
|
33
|
+
}
|
|
34
|
+
#endregion
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
#region --FXNValue--
|
|
38
|
+
[DllImport(Assembly, EntryPoint = @"FXNValueRelease")]
|
|
39
|
+
public static extern Status ReleaseValue(this IntPtr value);
|
|
40
|
+
[DllImport(Assembly, EntryPoint = @"FXNValueGetData")]
|
|
41
|
+
public static extern Status GetValueData(
|
|
42
|
+
this IntPtr value,
|
|
43
|
+
out IntPtr data
|
|
44
|
+
);
|
|
45
|
+
[DllImport(Assembly, EntryPoint = @"FXNValueGetType")]
|
|
46
|
+
public static extern Status GetValueType(
|
|
47
|
+
this IntPtr value,
|
|
48
|
+
out Dtype type
|
|
49
|
+
);
|
|
50
|
+
[DllImport(Assembly, EntryPoint = @"FXNValueGetDimensions")]
|
|
51
|
+
public static extern Status GetValueDimensions(
|
|
52
|
+
this IntPtr value,
|
|
53
|
+
out int dimensions
|
|
54
|
+
);
|
|
55
|
+
[DllImport(Assembly, EntryPoint = @"FXNValueGetShape")]
|
|
56
|
+
public static extern Status GetValueShape(
|
|
57
|
+
this IntPtr value,
|
|
58
|
+
[Out] int[] shape,
|
|
59
|
+
int shapeLen
|
|
60
|
+
);
|
|
61
|
+
[DllImport(Assembly, EntryPoint = @"FXNValueCreateArray")]
|
|
62
|
+
public static unsafe extern Status CreateArrayValue(
|
|
63
|
+
void* data,
|
|
64
|
+
[In] int[]? shape,
|
|
65
|
+
int dims,
|
|
66
|
+
Dtype dtype,
|
|
67
|
+
Value.Flags flags,
|
|
68
|
+
out IntPtr value
|
|
69
|
+
);
|
|
70
|
+
[DllImport(Assembly, EntryPoint = @"FXNValueCreateString")]
|
|
71
|
+
public static extern Status CreateStringValue(
|
|
72
|
+
[MarshalAs(UnmanagedType.LPUTF8Str)] string data,
|
|
73
|
+
out IntPtr value
|
|
74
|
+
);
|
|
75
|
+
[DllImport(Assembly, EntryPoint = @"FXNValueCreateList")]
|
|
76
|
+
public static extern Status CreateListValue(
|
|
77
|
+
[MarshalAs(UnmanagedType.LPUTF8Str)] string data,
|
|
78
|
+
out IntPtr value
|
|
79
|
+
);
|
|
80
|
+
[DllImport(Assembly, EntryPoint = @"FXNValueCreateDict")]
|
|
81
|
+
public static extern Status CreateDictValue(
|
|
82
|
+
[MarshalAs(UnmanagedType.LPUTF8Str)] string data,
|
|
83
|
+
out IntPtr value
|
|
84
|
+
);
|
|
85
|
+
[DllImport(Assembly, EntryPoint = @"FXNValueCreateImage")]
|
|
86
|
+
public static extern Status CreateImageValue(
|
|
87
|
+
byte* pixelBuffer,
|
|
88
|
+
int width,
|
|
89
|
+
int height,
|
|
90
|
+
int channels,
|
|
91
|
+
Value.Flags flags,
|
|
92
|
+
out IntPtr value
|
|
93
|
+
);
|
|
94
|
+
[DllImport(Assembly, EntryPoint = @"FXNValueCreateBinary")]
|
|
95
|
+
public static extern Status CreateBinaryValue(
|
|
96
|
+
[In] byte[] buffer,
|
|
97
|
+
int bufferLen,
|
|
98
|
+
Value.Flags flags,
|
|
99
|
+
out IntPtr value
|
|
100
|
+
);
|
|
101
|
+
[DllImport(Assembly, EntryPoint = @"FXNValueCreateNull")]
|
|
102
|
+
public static extern Status CreateNullValue(out IntPtr value);
|
|
103
|
+
#endregion
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
#region --FXNValueMap--
|
|
107
|
+
[DllImport(Assembly, EntryPoint = @"FXNValueMapCreate")]
|
|
108
|
+
public static extern Status CreateValueMap(out IntPtr map);
|
|
109
|
+
[DllImport(Assembly, EntryPoint = @"FXNValueMapRelease")]
|
|
110
|
+
public static extern Status ReleaseValueMap(this IntPtr map);
|
|
111
|
+
[DllImport(Assembly, EntryPoint = @"FXNValueMapGetSize")]
|
|
112
|
+
public static extern Status GetValueMapSize(
|
|
113
|
+
this IntPtr map,
|
|
114
|
+
out int size
|
|
115
|
+
);
|
|
116
|
+
[DllImport(Assembly, EntryPoint = @"FXNValueMapGetKey")]
|
|
117
|
+
public static extern Status GetValueMapKey(
|
|
118
|
+
this IntPtr map,
|
|
119
|
+
int index,
|
|
120
|
+
[MarshalAs(UnmanagedType.LPUTF8Str), Out] StringBuilder key,
|
|
121
|
+
int size
|
|
122
|
+
);
|
|
123
|
+
[DllImport(Assembly, EntryPoint = @"FXNValueMapGetValue")]
|
|
124
|
+
public static extern Status GetValueMapValue(
|
|
125
|
+
this IntPtr map,
|
|
126
|
+
[MarshalAs(UnmanagedType.LPUTF8Str)] string key,
|
|
127
|
+
out IntPtr value
|
|
128
|
+
);
|
|
129
|
+
[DllImport(Assembly, EntryPoint = @"FXNValueMapSetValue")]
|
|
130
|
+
public static extern Status SetValueMapValue(
|
|
131
|
+
this IntPtr map,
|
|
132
|
+
[MarshalAs(UnmanagedType.LPUTF8Str)] string key,
|
|
133
|
+
IntPtr value
|
|
134
|
+
);
|
|
135
|
+
#endregion
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
#region --FXNConfiguration--
|
|
139
|
+
[DllImport(Assembly, EntryPoint = @"FXNConfigurationGetUniqueID")]
|
|
140
|
+
public static extern Status GetConfigurationUniqueID(
|
|
141
|
+
[MarshalAs(UnmanagedType.LPUTF8Str), Out] StringBuilder identifier,
|
|
142
|
+
int size
|
|
143
|
+
);
|
|
144
|
+
[DllImport(Assembly, EntryPoint = @"FXNConfigurationGetClientID")]
|
|
145
|
+
public static extern Status GetConfigurationClientID(
|
|
146
|
+
[MarshalAs(UnmanagedType.LPUTF8Str), Out] StringBuilder identifier,
|
|
147
|
+
int size
|
|
148
|
+
);
|
|
149
|
+
[DllImport(Assembly, EntryPoint = @"FXNConfigurationCreate")]
|
|
150
|
+
public static extern Status CreateConfiguration(out IntPtr configuration);
|
|
151
|
+
[DllImport(Assembly, EntryPoint = @"FXNConfigurationRelease")]
|
|
152
|
+
public static extern Status ReleaseConfiguration(this IntPtr configuration);
|
|
153
|
+
[DllImport(Assembly, EntryPoint = @"FXNConfigurationGetTag")]
|
|
154
|
+
public static extern Status GetConfigurationTag(
|
|
155
|
+
this IntPtr configuration,
|
|
156
|
+
[MarshalAs(UnmanagedType.LPUTF8Str), Out] StringBuilder tag,
|
|
157
|
+
int size
|
|
158
|
+
);
|
|
159
|
+
[DllImport(Assembly, EntryPoint = @"FXNConfigurationSetTag")]
|
|
160
|
+
public static extern Status SetConfigurationTag(
|
|
161
|
+
this IntPtr configuration,
|
|
162
|
+
[MarshalAs(UnmanagedType.LPUTF8Str)] string? tag
|
|
163
|
+
);
|
|
164
|
+
[DllImport(Assembly, EntryPoint = @"FXNConfigurationGetToken")]
|
|
165
|
+
public static extern Status GetConfigurationToken(
|
|
166
|
+
this IntPtr configuration,
|
|
167
|
+
[MarshalAs(UnmanagedType.LPUTF8Str), Out] StringBuilder token,
|
|
168
|
+
int size
|
|
169
|
+
);
|
|
170
|
+
[DllImport(Assembly, EntryPoint = @"FXNConfigurationSetToken")]
|
|
171
|
+
public static extern Status SetConfigurationToken(
|
|
172
|
+
this IntPtr configuration,
|
|
173
|
+
[MarshalAs(UnmanagedType.LPUTF8Str)] string? token
|
|
174
|
+
);
|
|
175
|
+
[DllImport(Assembly, EntryPoint = @"FXNConfigurationGetAcceleration")]
|
|
176
|
+
public static extern Status GetConfigurationAcceleration(
|
|
177
|
+
this IntPtr configuration,
|
|
178
|
+
out Acceleration acceleration
|
|
179
|
+
);
|
|
180
|
+
[DllImport(Assembly, EntryPoint = @"FXNConfigurationSetAcceleration")]
|
|
181
|
+
public static extern Status SetConfigurationAcceleration(
|
|
182
|
+
this IntPtr configuration,
|
|
183
|
+
Acceleration acceleration
|
|
184
|
+
);
|
|
185
|
+
[DllImport(Assembly, EntryPoint = @"FXNConfigurationSetDevice")]
|
|
186
|
+
public static extern Status SetConfigurationDevice(
|
|
187
|
+
this IntPtr configuration,
|
|
188
|
+
IntPtr device
|
|
189
|
+
);
|
|
190
|
+
[DllImport(Assembly, EntryPoint = @"FXNConfigurationGetDevice")]
|
|
191
|
+
public static extern Status GetConfigurationDevice(
|
|
192
|
+
this IntPtr configuration,
|
|
193
|
+
out IntPtr device
|
|
194
|
+
);
|
|
195
|
+
[DllImport(Assembly, EntryPoint = @"FXNConfigurationAddResource")]
|
|
196
|
+
public static extern Status AddConfigurationResource(
|
|
197
|
+
this IntPtr configuration,
|
|
198
|
+
[MarshalAs(UnmanagedType.LPUTF8Str)] string type,
|
|
199
|
+
[MarshalAs(UnmanagedType.LPUTF8Str)] string path
|
|
200
|
+
);
|
|
201
|
+
#endregion
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
#region --FXNPrediction--
|
|
205
|
+
[DllImport(Assembly, EntryPoint = @"FXNPredictionRelease")]
|
|
206
|
+
public static extern Status ReleasePrediction(this IntPtr prediction);
|
|
207
|
+
[DllImport(Assembly, EntryPoint = @"FXNPredictionGetID")]
|
|
208
|
+
public static extern Status GetPredictionID(
|
|
209
|
+
this IntPtr prediction,
|
|
210
|
+
[MarshalAs(UnmanagedType.LPUTF8Str), Out] StringBuilder id,
|
|
211
|
+
int size
|
|
212
|
+
);
|
|
213
|
+
[DllImport(Assembly, EntryPoint = @"FXNPredictionGetLatency")]
|
|
214
|
+
public static extern Status GetPredictionLatency(
|
|
215
|
+
this IntPtr prediction,
|
|
216
|
+
out double latency
|
|
217
|
+
);
|
|
218
|
+
[DllImport(Assembly, EntryPoint = @"FXNPredictionGetResults")]
|
|
219
|
+
public static extern Status GetPredictionResults(
|
|
220
|
+
this IntPtr prediction,
|
|
221
|
+
out IntPtr map
|
|
222
|
+
);
|
|
223
|
+
[DllImport(Assembly, EntryPoint = @"FXNPredictionGetError")]
|
|
224
|
+
public static extern Status GetPredictionError(
|
|
225
|
+
this IntPtr prediction,
|
|
226
|
+
[MarshalAs(UnmanagedType.LPUTF8Str), Out] StringBuilder error,
|
|
227
|
+
int size
|
|
228
|
+
);
|
|
229
|
+
[DllImport(Assembly, EntryPoint = @"FXNPredictionGetLogs")]
|
|
230
|
+
public static extern Status GetPredictionLogs(
|
|
231
|
+
this IntPtr prediction,
|
|
232
|
+
[MarshalAs(UnmanagedType.LPUTF8Str), Out] StringBuilder logs,
|
|
233
|
+
int size
|
|
234
|
+
);
|
|
235
|
+
[DllImport(Assembly, EntryPoint = @"FXNPredictionGetLogLength")]
|
|
236
|
+
public static extern Status GetPredictionLogLength(
|
|
237
|
+
this IntPtr prediction,
|
|
238
|
+
out int size
|
|
239
|
+
);
|
|
240
|
+
#endregion
|
|
241
|
+
|
|
242
|
+
|
|
243
|
+
#region --FXNPredictionStream--
|
|
244
|
+
[DllImport(Assembly, EntryPoint = @"FXNPredictionStreamRelease")]
|
|
245
|
+
public static extern Status ReleasePredictionStream(this IntPtr stream);
|
|
246
|
+
[DllImport(Assembly, EntryPoint = @"FXNPredictionStreamReadNext")]
|
|
247
|
+
public static extern Status ReadNextPrediction(
|
|
248
|
+
this IntPtr stream,
|
|
249
|
+
out IntPtr prediction
|
|
250
|
+
);
|
|
251
|
+
#endregion
|
|
252
|
+
|
|
253
|
+
|
|
254
|
+
#region --FXNPredictor--
|
|
255
|
+
[DllImport(Assembly, EntryPoint = @"FXNPredictorCreate")]
|
|
256
|
+
public static extern Status CreatePredictor(
|
|
257
|
+
IntPtr configuration,
|
|
258
|
+
out IntPtr predictor
|
|
259
|
+
);
|
|
260
|
+
[DllImport(Assembly, EntryPoint = @"FXNPredictorRelease")]
|
|
261
|
+
public static extern Status ReleasePredictor(this IntPtr predictor);
|
|
262
|
+
[DllImport(Assembly, EntryPoint = @"FXNPredictorCreatePrediction")]
|
|
263
|
+
public static extern Status CreatePrediction(
|
|
264
|
+
this IntPtr predictor,
|
|
265
|
+
IntPtr inputs,
|
|
266
|
+
out IntPtr prediction
|
|
267
|
+
);
|
|
268
|
+
[DllImport(Assembly, EntryPoint = @"FXNPredictorStreamPrediction")]
|
|
269
|
+
public static extern Status StreamPrediction(
|
|
270
|
+
this IntPtr predictor,
|
|
271
|
+
IntPtr inputs,
|
|
272
|
+
out IntPtr stream
|
|
273
|
+
);
|
|
274
|
+
#endregion
|
|
275
|
+
|
|
276
|
+
|
|
277
|
+
#region --FXNVersion--
|
|
278
|
+
[DllImport(Assembly, EntryPoint = @"FXNGetVersion")]
|
|
279
|
+
public static extern IntPtr GetVersion();
|
|
280
|
+
#endregion
|
|
281
|
+
|
|
282
|
+
|
|
283
|
+
#region --Utilities--
|
|
284
|
+
|
|
285
|
+
public static Status Throw(this Status status) => status switch {
|
|
286
|
+
Status.Ok => status,
|
|
287
|
+
Status.InvalidArgument => throw new ArgumentException(),
|
|
288
|
+
Status.InvalidOperation => throw new InvalidOperationException(),
|
|
289
|
+
Status.NotImplemented => throw new NotImplementedException(),
|
|
290
|
+
_ => throw new InvalidOperationException(),
|
|
291
|
+
};
|
|
292
|
+
#endregion
|
|
293
|
+
}
|
|
294
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Muna
|
|
3
|
+
* Copyright © 2025 NatML Inc. All rights reserved.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
#nullable enable
|
|
7
|
+
|
|
8
|
+
namespace Muna.C {
|
|
9
|
+
|
|
10
|
+
using System;
|
|
11
|
+
using System.Text;
|
|
12
|
+
using static Muna;
|
|
13
|
+
|
|
14
|
+
public sealed class Prediction : IDisposable {
|
|
15
|
+
|
|
16
|
+
#region --Client API--
|
|
17
|
+
|
|
18
|
+
public string id {
|
|
19
|
+
get {
|
|
20
|
+
var id = new StringBuilder(64);
|
|
21
|
+
prediction.GetPredictionID(id, id.Capacity).Throw();
|
|
22
|
+
return id.ToString();
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
public double latency {
|
|
27
|
+
get {
|
|
28
|
+
prediction.GetPredictionLatency(out var latency).Throw();
|
|
29
|
+
return latency;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
public ValueMap? results {
|
|
34
|
+
get {
|
|
35
|
+
var map = prediction.GetPredictionResults(out var m).Throw() == Status.Ok ?
|
|
36
|
+
new ValueMap(m) :
|
|
37
|
+
default;
|
|
38
|
+
return map?.size > 0 ? map : default;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
public string? error {
|
|
43
|
+
get {
|
|
44
|
+
var error = new StringBuilder(2048);
|
|
45
|
+
return prediction.GetPredictionError(error, error.Capacity) == Status.Ok ? error.ToString() : null;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
public string logs {
|
|
50
|
+
get {
|
|
51
|
+
prediction.GetPredictionLogLength(out var length).Throw();
|
|
52
|
+
var logs = new StringBuilder(length + 1);
|
|
53
|
+
prediction.GetPredictionLogs(logs, logs.Capacity);
|
|
54
|
+
return logs.ToString();
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
public void Dispose() => prediction.ReleasePrediction();
|
|
59
|
+
#endregion
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
#region --Operations--
|
|
63
|
+
private readonly IntPtr prediction;
|
|
64
|
+
|
|
65
|
+
internal Prediction(IntPtr prediction) => this.prediction = prediction;
|
|
66
|
+
|
|
67
|
+
public static implicit operator IntPtr(Prediction prediction) => prediction.prediction;
|
|
68
|
+
#endregion
|
|
69
|
+
}
|
|
70
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Muna
|
|
3
|
+
* Copyright © 2025 NatML Inc. All rights reserved.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
#nullable enable
|
|
7
|
+
|
|
8
|
+
namespace Muna.C {
|
|
9
|
+
|
|
10
|
+
using System;
|
|
11
|
+
using static Muna;
|
|
12
|
+
|
|
13
|
+
public sealed class PredictionStream : IDisposable {
|
|
14
|
+
|
|
15
|
+
#region --Client API--
|
|
16
|
+
|
|
17
|
+
public Prediction? ReadNext() {
|
|
18
|
+
if (stream.ReadNextPrediction(out var prediction) == Status.Ok)
|
|
19
|
+
return new Prediction(prediction);
|
|
20
|
+
else
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
public void Dispose() => stream.ReleasePredictionStream();
|
|
25
|
+
#endregion
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
#region --Operations--
|
|
29
|
+
private readonly IntPtr stream;
|
|
30
|
+
|
|
31
|
+
internal PredictionStream(IntPtr stream) => this.stream = stream;
|
|
32
|
+
|
|
33
|
+
public static implicit operator IntPtr(PredictionStream stream) => stream.stream;
|
|
34
|
+
#endregion
|
|
35
|
+
}
|
|
36
|
+
}
|