Marking code for Burst compilation
阅读时间2 分钟最后更新于 21 天前
Apply the attribute to the parts of your code you want Burst to compile. You can apply the attribute to the following:
[BurstCompile][BurstCompile]- Jobs: When you apply to a job definition, Burst compiles everything within the job. For more information on jobs, refer to Job system.
[BurstCompile] - Classes: Apply to a class definition if the class contains static methods that are also marked with
[BurstCompile]. Burst can't compile the class itself but only its member methods.[BurstCompile] - Structs: Apply to a regular (non-job) struct definition if the struct contains static methods that are also marked with
[BurstCompile].[BurstCompile] - Static methods: Apply to the method and its parent type. To work with dynamic functions that process data based on other data states, refer to Function pointers.
[BurstCompile] - Assemblies: Apply to an assembly to set options for all Burst jobs and function-pointers within the assembly. For more information, refer to Defining Burst options for an assembly.
[BurstCompile]
Configure Burst compilation with parameters
You can supply parameters to the attribute to modify aspects of compilation and improve Burst's performance. You can use attribute parameters to:
[BurstCompile]- Use a different accuracy for math functions (for example, sin, cos).
- Relax the order of math computations so that Burst can rearrange the floating point calculations.
- Force a synchronous compilation of a job (only for just-in-time compilation).
For example, you can use the attribute to change the floating precision and float mode of Burst as follows:
[BurstCompile][BurstCompile(FloatPrecision.Medium, FloatMode.Fast)]
For more information on configuring precision and determinism in floating point calculations, refer to Float precision and determinism.