burst编译器_使用Burst编译器提高移动性能

burst编译器

As part of a recent session at Unite Now, we discussed how technology in the Burst compiler enables developers who are building projects with Unity to take advantage of the Arm Neon instruction set. You can use the Burst compiler when targeting Android devices to improve the performance of Unity projects supported by Arm architecture.

作为最近在Unite Now上的会议的一部分,我们讨论了Burst编译器中的技术如何使正在使用Unity构建项目的开发人员能够利用Arm Neon指令集 。 以Android设备为目标时,可以使用Burst编译器来提高Arm架构支持的Unity项目的性能。

Unity and Arm have formed a partnership to enhance the mobile game development experience for the billion-plus Arm-powered mobile devices in the Android ecosystem. 

Unity和Arm建立了合作伙伴关系,以改善Android生态系统中超过十亿个Arm驱动的移动设备的移动游戏开发体验。

For game developers, performance is paramount. Year after year, Arm invests in improving its CPU and GPU technologies to provide the advances in performance and efficiency needed to build richer experiences. Recently, Arm announced two new products, Cortex-A78, which provides greatly improved power efficiency, and the even more impressive Cortex-X1. These hardware developments are complemented by advances in compiler technology for the Arm architecture. Compilers ensure that when you develop high-performance games, they are translated and optimized into efficient binaries that make the best use of the Arm architecture’s features.  

对于游戏开发人员而言,性能至关重要。 年复一年,Arm投入资金改进其CPU和GPU技术,以提供构建丰富体验所需的性能和效率方面的进步。 最近,Arm推出了两种新产品, Cortex-A78Cortex-X1Cortex-A78 大大提高了电源效率 。 这些硬件开发被Arm架构的编译器技术的进步所补充。 编译器可确保您在开发高性能游戏时将其翻译和优化为有效的二进制文件,以充分利用Arm架构的功能。

关于爆裂 (About Burst)

Burst is an ahead of time compiler technology that can be used to accelerate the performance of Unity projects made using the new Data-Oriented Technology Stack (DOTS) and the Unity Job System. Burst works by compiling a subset of the C# language, known as High-Performance C# (HPC#), to make efficient use of a device’s power by deploying advanced optimizations built on top of the LLVM compiler framework. 

Burst是一种先进的编译器技术,可用于加速使用新的面向数据的技术堆栈(DOTS)和Unity Job System制作的Unity项目的性能。 Burst通过编译C#语言的子集(称为高性能C#(HPC#))来工作,以通过部署基于LLVM编译器框架的高级优化来有效利用设备的功能。

Burst is great for exploiting hidden parallelism in your applications. Using Burst from a DOTS project is easy, and it can unlock big performance benefits in CPU-bound algorithms. In this video, you can see a side-by-side comparison of a scripted run through in a demo environment with and without Burst enabled. 

爆发非常适合在应用程序中利用隐藏的并行性。 在DOTS项目中使用Burst很容易,并且可以在CPU绑定算法中获得巨大的性能优势。 在 此视频中 ,您可以看到在演示环境中启用和不启用突发功能的脚本运行的并排比较。

演示地址

The demo shows three examples of simulations using Unity Physics. You will see that the Burst-compiled code is able to compute frames with higher numbers of physics elements faster, allowing for better performance, less thermal throttling, lower battery consumption, and more engaging content. 

该演示显示了使用Unity Physics进行仿真的三个示例。 您将看到,Burst编译的代码能够更快地计算具有更多物理元素的帧,从而实现更好的性能,更少的热节流,更低的电池消耗以及更多引人入胜的内容。

爆裂如何工作? (How does Burst work?)

We say that Burst brings performance for free, but how does that work?

我们说Burst是免费提供性能的,但是它是如何工作的呢?

Burst transforms HPC# code into LLVM IR, an intermediate language used by the LLVM compiler framework. This allows the compiler to take full advantage of LLVM’s support for code generation for the Arm architecture to generate efficient machine code optimized around the data flow of your program. A diagram of this flow is shown below. 

Burst将HPC#代码转换为LLVM IR,这是LLVM编译器框架使用的中间语言。 这使编译器可以充分利用LLVM对Arm架构的代码生成的支持,以生成围绕程序数据流进行优化的高效机器代码。 该流程的示意图如下所示。

Mike Acton has given a talk called “Data-oriented design and C++,” which features the key line “know your hardware, know your data” as a means of achieving maximum performance. Burst works well because it gives visibility to the constraints on array aliasing that are guaranteed by the HPC# language and the DOTS framework, and it can make use of LLVM’s knowledge of your hardware architecture. This enables Burst to make target-specific transformations based on the properties of scripts written against the Unity APIs.  

迈克·阿克顿(Mike Acton)进行了名为“ 面向数据的设计和C ++ ”的演讲,其重点是“了解硬件,了解数据”,以此来实现最佳性能。 爆裂效果很好,因为它可以使HPC#语言和DOTS框架保证的阵列别名约束的可见性,并且可以利用LLVM对您的硬件体系结构的了解。 这使Burst可以根据针对Unity API编写的脚本的属性进行特定于目标的转换。

如何编程爆裂 (How to program for Burst)

You can use Burst to compile C# scripts that make use of the Unity Jobs System in DOTS. This is done by adding the [BurstCompile] attribute to your Job definition: 

您可以使用Burst编译使用DOTS中的Unity Jobs系统的C#脚本。 这是通过在 您的Job定义中 添加 [BurstCompile] 属性来完成的:

1
2
3
4
5
6
7
8
9
10
11
12
13
[BurstCompile]
struct MyJob : IJob
{
  public NativeArray<float> Input;
  public NativeArray<float> Output;
  public void Execute()
  {
for (int I = 0; I < Input.Length; i++)
{
   Output[i] = Input[i] * Input[i];
}
  }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
[ BurstCompile ]
struct MyJob : IJob
{
   public NativeArray < float > Input ;
   public NativeArray < float > Output ;
   public void Execute ( )
   {
for ( int I = 0 ; I < Input . Length ; i ++ )
{
   Output [ i ] = Input [ i ] * Input [ i ] ;
}
   }
}

We can use the Burst Inspector, found in the Jobs menu, to see what code will be generated. Note that for this demonstration, we have disabled Safety Checks and are using Burst 1.3.3. 

我们可以使用Jobs菜单中的Burst Inspector来查看将生成什么代码。 请注意,在此演示中,我们禁用了“安全检查”,并使用了“爆发1.3.3”。

In the Burst Inspector that appears, we enable code generation for Armv8-A by selecting the ARMV8A_AARCH64 target.

在出现的Burst Inspector中,我们通过选择ARMV8A_AARCH64目标来启用Armv8-A的代码生成。

We can now see the AArch64 code that will be generated for our C# loop, including a core loop using the Neon instruction set.

现在我们可以看到将为C#循环生成的AArch64代码,包括使用Neon指令集的核心循环。

For more details on using the Burst compiler, please see the instruction manual, check out this Unite Now talk, where we go through the steps above in more detail, or head to the forums to get more information or ask questions about using Burst in your next project.

有关使用Burst编译器的更多详细信息,请参阅 说明手册 ,查看本“ Unite Now”演讲 ,我们将在其中详细介绍上述步骤,或者 前往论坛 获取更多信息或询问有关在您的Burst中使用Burst的问题。下一个项目。

翻译自: https://blogs.unity3d.com/2020/08/17/enhancing-mobile-performance-with-the-burst-compiler/

burst编译器