forked from derenlei/Unity_Detection2AR
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Barracuda GPU worker supports (derenlei#14)
- Loading branch information
ROBYER1
authored
Jan 22, 2021
1 parent
23351d3
commit 9a64408
Showing
4 changed files
with
74 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,7 +48,6 @@ public class DetectorYolo2 : MonoBehaviour, Detector | |
// 1.08F, 1.19F, 3.42F, 4.41F, 6.63F, 11.38F, 9.42F, 5.11F, 16.62F, 10.52F // yolov2-tiny-voc | ||
//0.57273F, 0.677385F, 1.87446F, 2.06253F, 3.33843F, 5.47434F, 7.88282F, 3.52778F, 9.77052F, 9.16828F // yolov2-tiny | ||
0.57273F, 0.677385F, 1.87446F, 2.06253F, 3.33843F, 5.47434F, 7.88282F, 3.52778F, 9.77052F, 9.16828F // yolov2-tiny-food | ||
//0.57273F, 0.677385F, 1.87446F, 2.06253F, 3.33843F, 5.47434F, 7.88282F, 3.52778F, 9.77052F, 9.16828F // yolov3 | ||
}; | ||
|
||
|
||
|
@@ -58,9 +57,8 @@ public void Start() | |
.Where(s => !String.IsNullOrEmpty(s)).ToArray(); | ||
var model = ModelLoader.Load(this.modelFile); | ||
// https://docs.unity3d.com/Packages/[email protected]/manual/Worker.html | ||
// var workerType = WorkerFactory.Type.ComputePrecompiled; // GPU | ||
var workerType = WorkerFactory.Type.CSharpBurst; // CPU | ||
this.worker = WorkerFactory.CreateWorker(workerType, model); | ||
//These checks all check for GPU before CPU as GPU is preferred if the platform + rendering pipeline support it | ||
this.worker = GraphicsWorker.GetWorker(model); | ||
} | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,10 +51,6 @@ public class DetectorYolo3 : MonoBehaviour, Detector | |
|
||
private float[] anchors = new float[] | ||
{ | ||
// 1.08F, 1.19F, 3.42F, 4.41F, 6.63F, 11.38F, 9.42F, 5.11F, 16.62F, 10.52F // yolov2-tiny-voc | ||
//0.57273F, 0.677385F, 1.87446F, 2.06253F, 3.33843F, 5.47434F, 7.88282F, 3.52778F, 9.77052F, 9.16828F // yolov2-tiny | ||
//0.57273F, 0.677385F, 1.87446F, 2.06253F, 3.33843F, 5.47434F, 7.88282F, 3.52778F, 9.77052F, 9.16828F // yolov2-tiny-food | ||
//0.57273F, 0.677385F, 1.87446F, 2.06253F, 3.33843F, 5.47434F, 7.88282F, 3.52778F, 9.77052F, 9.16828F // yolov3 | ||
10F, 14F, 23F, 27F, 37F, 58F, 81F, 82F, 135F, 169F, 344F, 319F // yolov3-tiny | ||
}; | ||
|
||
|
@@ -65,9 +61,8 @@ public void Start() | |
.Where(s => !String.IsNullOrEmpty(s)).ToArray(); | ||
var model = ModelLoader.Load(this.modelFile); | ||
// https://docs.unity3d.com/Packages/[email protected]/manual/Worker.html | ||
//var workerType = WorkerFactory.Type.ComputePrecompiled; // GPU | ||
var workerType = WorkerFactory.Type.CSharpBurst; // CPU | ||
this.worker = WorkerFactory.CreateWorker(workerType, model); | ||
//These checks all check for GPU before CPU as GPU is preferred if the platform + rendering pipeline support it | ||
this.worker = GraphicsWorker.GetWorker(model); | ||
} | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
|
||
using UnityEngine; | ||
using System.Collections; | ||
using Unity.Barracuda; | ||
|
||
public class GraphicsWorker: MonoBehaviour | ||
{ | ||
|
||
public static IWorker GetWorker(Model model) | ||
{ | ||
IWorker worker; | ||
#if UNITY_IOS //Only IOS | ||
Debug.Log("Graphics API: " + SystemInfo.graphicsDeviceType); | ||
if (SystemInfo.graphicsDeviceType == UnityEngine.Rendering.GraphicsDeviceType.Metal) | ||
{ | ||
//IOS 11 needed for ARKit, IOS 11 has Metal support only, therefore GPU can run | ||
var workerType = WorkerFactory.Type.ComputePrecompiled; // GPU | ||
worker = WorkerFactory.CreateWorker(workerType, model); | ||
} | ||
else | ||
{ | ||
//If Metal support is dropped for some reason, fall back to CPU | ||
var workerType = WorkerFactory.Type.CSharpBurst; // CPU | ||
worker = WorkerFactory.CreateWorker(workerType, model); | ||
} | ||
|
||
#elif UNITY_ANDROID //Only Android | ||
Debug.Log("Graphics API: " + SystemInfo.graphicsDeviceType); | ||
if (SystemInfo.graphicsDeviceType == UnityEngine.Rendering.GraphicsDeviceType.Vulkan) | ||
{ | ||
//Vulkan on Android supports GPU | ||
//However, ARCore does not currently support Vulkan, when it does, this line will work | ||
var workerType = WorkerFactory.Type.ComputePrecompiled; // GPU | ||
worker = WorkerFactory.CreateWorker(workerType, model); | ||
} | ||
else | ||
{ | ||
//If not vulkan, fall back to CPU | ||
var workerType = WorkerFactory.Type.CSharpBurst; // CPU | ||
worker = WorkerFactory.CreateWorker(workerType, model); | ||
} | ||
|
||
#elif UNITY_WEBGL //Only WebGL | ||
Debug.Log("Graphics API: " + SystemInfo.graphicsDeviceType); | ||
//WebGL only supports CPU | ||
var workerType = WorkerFactory.Type.CSharpBurst; // CPU | ||
worker = WorkerFactory.CreateWorker(workerType, model); | ||
|
||
#else //Any other platform | ||
Debug.Log("Graphics API: " + SystemInfo.graphicsDeviceType); | ||
// https://docs.unity3d.com/Packages/[email protected]/manual/SupportedPlatforms.html | ||
//var workerType = WorkerFactory.Type.CSharpBurst; // CPU | ||
var workerType = WorkerFactory.Type.ComputePrecompiled; // GPU | ||
worker = WorkerFactory.CreateWorker(workerType, model); | ||
#endif | ||
|
||
return worker; | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.