Search Unity

Resolved Burst and IJobParallelFor vectorization

Discussion in 'Burst' started by dzamani, Jun 20, 2020.

  1. dzamani

    dzamani

    Joined:
    Feb 25, 2014
    Posts:
    122
    Hi everyone,

    I have a simple job that I'm wondering why I cannot vectorize.

    First the code:

    Code (CSharp):
    1. [BurstCompile]
    2. public struct Init : IJobParallelFor
    3. {
    4.     [WriteOnly]
    5.     public NativeArray<bool> Possibilities;
    6.     [ReadOnly]
    7.     public NativeArray<Direction> RuntimeTileData;
    8.     public int PossibilitiesPerSlotCount;
    9.  
    10.     public void Execute(int index)
    11.     {
    12.         int tileIndex = index % PossibilitiesPerSlotCount;
    13.         Possibilities[index] = RuntimeTileData[tileIndex] == 0;
    14.     }
    15. }
    • Direction is a basic enum.
    • I've removed a bunch of stuff so don't really look into the logic here, I just want to understand why it's not vectorizing correctly.

    And this is what I'm seeing int the diagnostic window:
    Any idea what I'm doing wrong here?

    Thanks!
     
  2. dzamani

    dzamani

    Joined:
    Feb 25, 2014
    Posts:
    122
    Hi thanks for the help but just tried what you suggested and it didn't change anything.
     
  3. dzamani

    dzamani

    Joined:
    Feb 25, 2014
    Posts:
    122
    Hum interesting, disabling SafetyChecks will generate the correct vectorized version.
    I have other jobs where I know vectorization will fail, they still have errors in the diagnostic window while the Init job doesn't when safety checks are disabled.

    So I guess this is more of an issue related to safety checks in editor?
     
    Last edited: Jun 20, 2020
  4. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    Generally speaking safety checks are significantly slower and there is little point in measuring with them enabled.
    They exist to ensure that in the editor there are no crashes and race conditions are detected accurately.
    In standalone builds they are disabled.
     
  5. dzamani

    dzamani

    Joined:
    Feb 25, 2014
    Posts:
    122
    Yes, for accurate profiling I'm always using a standalone build.
    But, as far as I know, there isn't any way to assure everything is bursted and vectorized other than the "LLVM IR Optimization Diagnostics" tab in the Burst debugger.
     
  6. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    Correct. In the burst inspector you can turn off safety checks when inspecting the codegen for a job.
     
    brunocoimbra and dzamani like this.
  7. eizenhorn

    eizenhorn

    Joined:
    Oct 17, 2016
    Posts:
    2,683
    Completely wrong. Of course, you can. You only can't write back to that variable and this is where native containers (pointers specifically) step into the scene. And he's not writing back to that variable and there is no need native container for simple read-only int field.
    A very long time ago, more than 1.5 years ago