Skip to content

Commit b6c5f73

Browse files
committed
Android GPU support with vulkan
1 parent 63b79c5 commit b6c5f73

3 files changed

Lines changed: 32 additions & 5 deletions

File tree

Editor/LLMEditor.cs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -418,10 +418,23 @@ private void CopyToClipboard(string text)
418418

419419
public override void AddSetupExtras(SerializedObject llmScriptSO)
420420
{
421-
bool useCUBLAS = LLMUnitySetup.CUBLAS;
422-
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");
423-
bool newUseCUBLAS = !EditorGUILayout.Toggle(content, !useCUBLAS);
424-
if (newUseCUBLAS != useCUBLAS) LLMUnitySetup.SetCUBLAS(newUseCUBLAS);
421+
if (EditorUserBuildSettings.activeBuildTarget == BuildTarget.StandaloneWindows ||
422+
EditorUserBuildSettings.activeBuildTarget == BuildTarget.StandaloneWindows64 ||
423+
EditorUserBuildSettings.activeBuildTarget == BuildTarget.StandaloneLinux64)
424+
{
425+
bool useCUBLAS = LLMUnitySetup.CUBLAS;
426+
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");
427+
bool newUseCUBLAS = !EditorGUILayout.Toggle(contentCUBLAS, !useCUBLAS);
428+
if (newUseCUBLAS != useCUBLAS) LLMUnitySetup.SetCUBLAS(newUseCUBLAS);
429+
}
430+
431+
if (EditorUserBuildSettings.activeBuildTarget == BuildTarget.Android)
432+
{
433+
bool useAndroidVulkan = LLMUnitySetup.AndroidVulkan;
434+
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");
435+
bool newUseAndroidVulkan = EditorGUILayout.Toggle(contentAndroidVulkan, useAndroidVulkan);
436+
if (newUseAndroidVulkan != useAndroidVulkan) LLMUnitySetup.SetAndroidVulkan(newUseAndroidVulkan);
437+
}
425438
}
426439

427440
public override void OnInspectorGUI()

Runtime/LLMBuilder.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,10 @@ public static void BuildLibraryPlatforms(BuildTarget buildTarget)
267267
{
268268
foreach (string platform in platforms)
269269
{
270-
string source = Path.Combine(LLMUnitySetup.libraryPath, platform, "native", $"libllamalib_{platform}.{MobileSuffix(buildTarget)}");
270+
string archFilename = $"libllamalib_{platform}.{MobileSuffix(buildTarget)}";
271+
if (buildTarget == BuildTarget.Android && LLMUnitySetup.AndroidVulkan)
272+
archFilename = $"libllamalib_{platform}-vulkan.{MobileSuffix(buildTarget)}";
273+
string source = Path.Combine(LLMUnitySetup.libraryPath, platform, "native", archFilename);
271274
string target = MobilePluginPath(buildTarget, platform.Split("-")[1].ToUpper());
272275
string pluginDir = PluginDir(buildTarget.ToString());
273276
MoveAction(source, target);

Runtime/LLMUnitySetup.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,8 @@ public class LLMUnitySetup
168168
static string DebugModeKey = "DebugMode";
169169
public static bool CUBLAS = false;
170170
static string CUBLASKey = "CUBLAS";
171+
public static bool AndroidVulkan = false;
172+
static string AndroidVulkanKey = "AndroidVulkan";
171173
static List<Action<string>> errorCallbacks = new List<Action<string>>();
172174
static readonly object lockObject = new object();
173175
static Dictionary<string, Task> androidExtractTasks = new Dictionary<string, Task>();
@@ -205,6 +207,7 @@ static void LoadPlayerPrefs()
205207
{
206208
DebugMode = (DebugModeType)PlayerPrefs.GetInt(DebugModeKey, (int)DebugModeType.All);
207209
CUBLAS = PlayerPrefs.GetInt(CUBLASKey, 0) == 1;
210+
AndroidVulkan = PlayerPrefs.GetInt(AndroidVulkanKey, 0) == 1;
208211
}
209212

210213
public static void SetDebugMode(DebugModeType newDebugMode)
@@ -224,6 +227,14 @@ public static void SetCUBLAS(bool value)
224227
PlayerPrefs.Save();
225228
}
226229

230+
public static void SetAndroidVulkan(bool value)
231+
{
232+
if (AndroidVulkan == value) return;
233+
AndroidVulkan = value;
234+
PlayerPrefs.SetInt(AndroidVulkanKey, value ? 1 : 0);
235+
PlayerPrefs.Save();
236+
}
237+
227238
#endif
228239

229240
public static string GetAssetPath(string relPath = "")

0 commit comments

Comments
 (0)