diff --git a/Editor/LLMEditor.cs b/Editor/LLMEditor.cs index adf34e87..b3e8d092 100644 --- a/Editor/LLMEditor.cs +++ b/Editor/LLMEditor.cs @@ -418,10 +418,23 @@ private void CopyToClipboard(string text) public override void AddSetupExtras(SerializedObject llmScriptSO) { - bool useCUBLAS = LLMUnitySetup.CUBLAS; - GUIContent content = new GUIContent("Light build for Nvidia GPUs", "Use tinyBLAS instead of cuBLAS that takes up less space and has similar performance for quants - doesn't work with i-quants and flash attention"); - bool newUseCUBLAS = !EditorGUILayout.Toggle(content, !useCUBLAS); - if (newUseCUBLAS != useCUBLAS) LLMUnitySetup.SetCUBLAS(newUseCUBLAS); + if (EditorUserBuildSettings.activeBuildTarget == BuildTarget.StandaloneWindows || + EditorUserBuildSettings.activeBuildTarget == BuildTarget.StandaloneWindows64 || + EditorUserBuildSettings.activeBuildTarget == BuildTarget.StandaloneLinux64) + { + bool useCUBLAS = LLMUnitySetup.CUBLAS; + GUIContent contentCUBLAS = new GUIContent("Light build for Nvidia GPUs", "Use tinyBLAS instead of cuBLAS that takes up less space and has similar performance for quants - doesn't work with i-quants and flash attention"); + bool newUseCUBLAS = !EditorGUILayout.Toggle(contentCUBLAS, !useCUBLAS); + if (newUseCUBLAS != useCUBLAS) LLMUnitySetup.SetCUBLAS(newUseCUBLAS); + } + + if (EditorUserBuildSettings.activeBuildTarget == BuildTarget.Android) + { + bool useAndroidVulkan = LLMUnitySetup.AndroidVulkan; + GUIContent contentAndroidVulkan = new GUIContent("Use Android GPU (Vulkan, API>=29)", "Use the Android Vulkan build that works with the Android GPU according to the number of GPU layers"); + bool newUseAndroidVulkan = EditorGUILayout.Toggle(contentAndroidVulkan, useAndroidVulkan); + if (newUseAndroidVulkan != useAndroidVulkan) LLMUnitySetup.SetAndroidVulkan(newUseAndroidVulkan); + } } public override void OnInspectorGUI() diff --git a/Runtime/LLMBuilder.cs b/Runtime/LLMBuilder.cs index 3576b850..fd7e3acb 100644 --- a/Runtime/LLMBuilder.cs +++ b/Runtime/LLMBuilder.cs @@ -267,7 +267,10 @@ public static void BuildLibraryPlatforms(BuildTarget buildTarget) { foreach (string platform in platforms) { - string source = Path.Combine(LLMUnitySetup.libraryPath, platform, "native", $"libllamalib_{platform}.{MobileSuffix(buildTarget)}"); + string archFilename = $"libllamalib_{platform}.{MobileSuffix(buildTarget)}"; + if (buildTarget == BuildTarget.Android && LLMUnitySetup.AndroidVulkan) + archFilename = $"libllamalib_{platform}-vulkan.{MobileSuffix(buildTarget)}"; + string source = Path.Combine(LLMUnitySetup.libraryPath, platform, "native", archFilename); string target = MobilePluginPath(buildTarget, platform.Split("-")[1].ToUpper()); string pluginDir = PluginDir(buildTarget.ToString()); MoveAction(source, target); diff --git a/Runtime/LLMUnitySetup.cs b/Runtime/LLMUnitySetup.cs index f12d5c54..e1f5af32 100644 --- a/Runtime/LLMUnitySetup.cs +++ b/Runtime/LLMUnitySetup.cs @@ -168,6 +168,8 @@ public class LLMUnitySetup static string DebugModeKey = "DebugMode"; public static bool CUBLAS = false; static string CUBLASKey = "CUBLAS"; + public static bool AndroidVulkan = false; + static string AndroidVulkanKey = "AndroidVulkan"; static List> errorCallbacks = new List>(); static readonly object lockObject = new object(); static Dictionary androidExtractTasks = new Dictionary(); @@ -205,6 +207,7 @@ static void LoadPlayerPrefs() { DebugMode = (DebugModeType)PlayerPrefs.GetInt(DebugModeKey, (int)DebugModeType.All); CUBLAS = PlayerPrefs.GetInt(CUBLASKey, 0) == 1; + AndroidVulkan = PlayerPrefs.GetInt(AndroidVulkanKey, 0) == 1; } public static void SetDebugMode(DebugModeType newDebugMode) @@ -224,6 +227,14 @@ public static void SetCUBLAS(bool value) PlayerPrefs.Save(); } + public static void SetAndroidVulkan(bool value) + { + if (AndroidVulkan == value) return; + AndroidVulkan = value; + PlayerPrefs.SetInt(AndroidVulkanKey, value ? 1 : 0); + PlayerPrefs.Save(); + } + #endif public static string GetAssetPath(string relPath = "")