Search Unity

How to properly debug crash with burst compiler?

Discussion in 'Burst' started by Deleted User, Mar 20, 2019.

  1. Deleted User

    Deleted User

    Guest

    Hey.
    Everything is fine when Job executed without Burst, but if enabled, that's makes Unity crash instantly without any info in .log files or whatsoever.
    It's about a week I'm trying to figure out what exactly is the reason of Unity Job system crashes in my case. I will try to describe the situation in detail.

    I am using Job which is work with NativeList's and manage some data from meshes for me. Mentioned Job basically writes the data in loop into the "NativeList<Vector3>" from provided for Job "NativeArray<Vector3>", but with some offset and with some rotation, like this:

    Code (CSharp):
    1. for (int i = 0; i < meshesCount; i++)
    2. {
    3.    angle.y = meshRotation[i];
    4.    rotation.eulerAngles = angle;
    5.  
    6.    for (int j = 0; j < vertexCount; j++)
    7.    {
    8.           vertices.Add((rotation * s_vertices[j) + offset[i]);
    9.    }
    10.  
    11. }
    Again, this code works fine without "[BurstCompiler]" attribute over Job. I also tryed to use NativeArray instead of NativeList, and also "float3" from Mathematics package instead of Vector3, but no luck - works only without Burst.

    So at some point without having any error text I simply just comment out the code and check it line by line. I found out that calling eulerAngles cause of crash and what's funny not only that. After disabling everything about rotation - Job started working again. But if you run the Job several times, even if it is exactly the same way and with the same data - you also get crash. Ussually Job works only once before crash.

    If you add to the list just some single regular "Vector3" - it's fine. If you do calculation like above - crash. If you do calculation in some temp variable is okay, but only if you not trying to add this to the list(or write in array) - then is crash, like this variable is something special about. Am I missing something? And when I do same calculation thing with any hardcoded values is also crashes.

    So I wonder how to debug here everything and make Job work with burst. I also wonder what I'm missing and why Burst is acting like this. I don't see anything about in the documentation.
     
  2. NoDumbQuestion

    NoDumbQuestion

    Joined:
    Nov 10, 2017
    Posts:
    186
    Enable Burst safety checks and other stuff inside Jobs/Burst/SafetyCheck.

    The thing broke inside burst here is "Vector3". Burst only support anything inside new
    math 
    library not
    Mathf
    (all Vector3 stuff)
     
    Deleted User likes this.
  3. Deleted User

    Deleted User

    Guest

    Thank you very much for your reply and pointing me towards math library. It was also nice to find documentation from package about that.
    But please, can you tell me what could be wrong with this code bellow then? That would be also very kind of you.

    Code (CSharp):
    1. [BurstCompile]
    2. private struct TestJob : IJob
    3. {
    4.     public NativeList<float3> vertex;
    5.     public float3 rotator;
    6.  
    7.     public void Execute()
    8.     {
    9.         rotator.y = 1.5708f;
    10.  
    11.         float3 a = new float3(0, 0, 10);
    12.         float3 b = new float3(0, 5, 0);
    13.  
    14.         vertex.Add(math.rotate(quaternion.Euler(rotator), a) + b);
    15.     }
    16. }
    Expecting here result is ~10, 5, 0, which work's only without Burst, as I can see it's crash because of euler&rotate part, just a + b it's fine.

    Also, returning to debug thing, I am still unable to get any error text in the log files or anything - enabling safety checks and other stuff there doesn't seem to change anything. I do understand that Burst is in development, but I'm fairly not sure I'm doing with it right.

    I also found "JobsUtility.JobDebuggerEnabled" at "Unity.Jobs.LowLevel.Unsafe", but this also doesn't help to have something about. Curious what that applies to then.
     
  4. eizenhorn

    eizenhorn

    Joined:
    Oct 17, 2016
    Posts:
    2,684
    It's not true. Vector3 works fine with burst, some Mathf stuff too, only things with static (exclude readonly\const) fields\properties not compatable with burst. Difference is math SIMD friendly and this why it's faster and better. Here fast sample, that it works fine with Mathf, Vector3 etc.
    Code (CSharp):
    1. [BurstCompile]
    2. public struct SomeBurstedJob : IJob
    3. {
    4.     public NativeList<Quaternion> list;
    5.     public Vector3 vector;
    6.     public void Execute()
    7.     {
    8.         Quaternion a = new Quaternion();
    9.         a.eulerAngles = vector;
    10.         list.Add(a);
    11.     }
    12. }
    13.  
    14. ...
    15.  
    16.  
    17. var list = new NativeList<Quaternion>(Allocator.TempJob);
    18.         SomeBurstedJob test = new SomeBurstedJob()
    19.         {
    20.             vector = new Vector3(90, 0, 0),
    21.             list   = list
    22.         };
    23.         test.Schedule().Complete();
    24.         Debug.Log(list[0].eulerAngles);
    25.         list.Dispose();
    upload_2019-3-21_12-45-0.png

    a.eulerAngles = vector.normalized;


    upload_2019-3-21_12-49-46.png


    vector = vector.normalized;
    vector.y = Mathf.PI;


    upload_2019-3-21_12-52-55.png
     
    Last edited: Mar 21, 2019
  5. NoDumbQuestion

    NoDumbQuestion

    Joined:
    Nov 10, 2017
    Posts:
    186
    hm, I didn't know Vector3 function also work.
    In my case, there are few times when Burst compile do some weird math and broke the game so I just stop using it all together.
    @SiriusRU you might want to double check Package Manager if you have lastest burst or have infinite loop add for
    public NativeList<float3> vertex
    before write bug report
    Also, Debug log not work inside Burst
     
  6. Deleted User

    Deleted User

    Guest

    Huh. Well, that's right - I am using last burst package version("1.0.0 preview6" to be exact), Unity 2018.3.9f1 version and there is no infinity loop for sure. I also not expecting "Debug.Log" to work in Job, but Burst were initially designed to give some info if something goes wrong and of course I'd like to know if I missing something about what is wrong here.

    Oh.. So it's suppose to actually work in that case then??
    I can see your result from the console clearly, but I copied your code and it's instant crash for me. To be honest, I'm kind of confused now what to do.

    Update: Copied code actually working. But I still don't get it overall, like why is there crash.
     
    Last edited by a moderator: Mar 21, 2019
  7. eizenhorn

    eizenhorn

    Joined:
    Oct 17, 2016
    Posts:
    2,684
    Just for clarification - Show Error (red icon) enabled in console?
     
  8. Deleted User

    Deleted User

    Guest

    Yes, sure. But it's instant crash, so there is no chance to read console in Unity, I am using log files to read if there any info and it has nothing about crash or any error message. In the end there is only regular last Unity logs.
     
  9. Deleted User

    Deleted User

    Guest

    I slightly modified your code like this to slighly more fit what I'm doing
    Code (CSharp):
    1. var vertices = new NativeList<Vector3>(Allocator.TempJob);
    2. SomeBurstedJob test = new SomeBurstedJob()
    3. {
    4.     vector = new Vector3(90, 0, 0),
    5.     vertices = vertices,
    6.     offset = new Vector3(7, 0, 0)
    7. };
    8.  
    9. test.Schedule().Complete();
    10. Debug.Log(vertices[0]);
    11. vertices.Dispose();
    Code (CSharp):
    1. [BurstCompile]
    2. public struct SomeBurstedJob : IJob
    3. {
    4.     public NativeList<Vector3> vertices;
    5.     public Vector3             vector;
    6.     public Vector3             offset;
    7.  
    8.     public void Execute()
    9.     {
    10.         Quaternion rotation = new Quaternion();
    11.         rotation.eulerAngles = vector;
    12.  
    13.         Vector3 vertex = (rotation * new Vector3(0, 0, 10)) + offset;
    14.  
    15.         vertices.Add(vertex);
    16.     }
    17. }

    And it's working fine like everything is okay.
    But if, for example, use math and float3 instead to do same thing like this:
    Code (CSharp):
    1. var vertices = new NativeList<float3>(Allocator.TempJob);
    2. SomeBurstedJob test = new SomeBurstedJob()
    3. {
    4.     angle   = new float3(0, 1.5708f, 0),
    5.     vertices = vertices,
    6.     offset   = new float3(0, 5, 0)
    7. };
    8.  
    9. test.Schedule().Complete();
    10. Debug.Log(vertices[0]);
    11. vertices.Dispose();
    12.  
    Code (CSharp):
    1. [BurstCompile]
    2.     public struct SomeBurstedJob : IJob
    3.     {
    4.         public NativeList<float3> vertices;
    5.         public float3             angle;
    6.         public float3             offset;
    7.  
    8.         public void Execute()
    9.         {          
    10.             float3 vertex = math.rotate(quaternion.Euler(angle), new float3(0, 0, 10)) + offset;
    11.  
    12.             vertices.Add(vertex);
    13.         }
    14.     }
    15.  

    It's also crashes. Again, only with Burst.
     
  10. Deleted User

    Deleted User

    Guest

    Well, because of the help from @eizenhorn (Thank you!!) I could continue investigation with my issue and after a series of tests I am inclined to believe now, that most of the problems since the beggining here somehow arose because of Unity.Mathematics usage.
    If I'm right, there is even no need to have use the whole package for crash, like I did above.
    For example here I made for loop based on the value obtained from "NativeArray<int2>"(I actually wanted to use int2 from the beginning).

    Code (CSharp):
    1. [BurstCompile]
    2.     private struct SomeBurstedJob : IJob
    3.     {
    4.         public NativeList<Vector3> vertices;
    5.         public NativeArray<int2> indexMax;
    6.         public Vector3             vector;
    7.         public Vector3             offset;
    8.         public void Execute()
    9.         {
    10.             Quaternion rotation = new Quaternion();
    11.             rotation.eulerAngles = vector;
    12.  
    13.             int tempIntForExample = indexMax[0].y;
    14.             for (int i = 0; i < tempIntForExample; i++)
    15.             {
    16.                 Vector3 vertex = (rotation * new Vector3(0, 0, 10)) + new Vector3(0, 5, 0);
    17.                 vertices.Add(vertex);
    18.             }
    19.         }
    20.     }
    And that's crash. At least for me. Am I suppose to "Report A Bug" it then?
    Also, "indexMax[0].y" here is equal to one hundred, and when I change it instead of "NativeArray<int2>" to just "NativeArray<int>" - it's not crashing. So that's why I think this is it.
    And also, I am using last available version of Mathematics(1.0.0 preview 1).
     
  11. recursive

    recursive

    Joined:
    Jul 12, 2012
    Posts:
    669
    What happens if you pull out the int2 and then access the y component? Does it still crash then?
     
  12. Deleted User

    Deleted User

    Guest

    Pull out of what?
    Mm, if y component not readed inside of the job and you just only read it after the job when it's Complete on main thread - it's fine. Even if int2 was modyfied to new value when inside of bursted job.

    So it's look's like write something to such NativeContainer it is okay here.
    But if I write from one "NativeArray<int2>" to another "NativeArray<int2>" with "=" it's also crash.
    I guess because it's acually reading from second NativeContainer.

    * If I do modify "NativeArray<int2>" with some "new Int2(0, 100)" in the job, but then read it inside the same job for some cause, whatsoever - it's still crash.
    * If it's same code like above in the post, but with other type temp value used after or if without some temp value at all - it's also crash. So it's acual issue with reading when, as I believe.
    * And again if it's not a "NativeContainer" and just int2 or if it's "NativeContainer<int>" - then it's fine to read&write or do something inside of bursted job with it.
     
  13. eizenhorn

    eizenhorn

    Joined:
    Oct 17, 2016
    Posts:
    2,684
    Show please your manifest.json inside Package folder
     
  14. Deleted User

    Deleted User

    Guest

    Here.
    Code (CSharp):
    1. {
    2.   "dependencies": {
    3.     "com.unity.ads": "2.0.8",
    4.     "com.unity.analytics": "3.2.2",
    5.     "com.unity.burst": "1.0.0-preview.6",
    6.     "com.unity.collab-proxy": "1.2.15",
    7.     "com.unity.collections": "0.0.9-preview.12",
    8.     "com.unity.mathematics": "1.0.0-preview.1",
    9.     "com.unity.package-manager-ui": "2.0.7",
    10.     "com.unity.postprocessing": "2.1.4",
    11.     "com.unity.purchasing": "2.0.3",
    12.     "com.unity.render-pipelines.high-definition": "4.10.0-preview",
    13.     "com.unity.shadergraph": "4.10.0-preview",
    14.     "com.unity.textmeshpro": "1.3.0",
    15.     "com.unity.visualeffectgraph": "4.10.0-preview",
    16.     "com.unity.modules.ai": "1.0.0",
    17.     "com.unity.modules.animation": "1.0.0",
    18.     "com.unity.modules.assetbundle": "1.0.0",
    19.     "com.unity.modules.audio": "1.0.0",
    20.     "com.unity.modules.cloth": "1.0.0",
    21.     "com.unity.modules.director": "1.0.0",
    22.     "com.unity.modules.imageconversion": "1.0.0",
    23.     "com.unity.modules.imgui": "1.0.0",
    24.     "com.unity.modules.jsonserialize": "1.0.0",
    25.     "com.unity.modules.particlesystem": "1.0.0",
    26.     "com.unity.modules.physics": "1.0.0",
    27.     "com.unity.modules.physics2d": "1.0.0",
    28.     "com.unity.modules.screencapture": "1.0.0",
    29.     "com.unity.modules.terrain": "1.0.0",
    30.     "com.unity.modules.terrainphysics": "1.0.0",
    31.     "com.unity.modules.tilemap": "1.0.0",
    32.     "com.unity.modules.ui": "1.0.0",
    33.     "com.unity.modules.uielements": "1.0.0",
    34.     "com.unity.modules.umbra": "1.0.0",
    35.     "com.unity.modules.unityanalytics": "1.0.0",
    36.     "com.unity.modules.unitywebrequest": "1.0.0",
    37.     "com.unity.modules.unitywebrequestassetbundle": "1.0.0",
    38.     "com.unity.modules.unitywebrequestaudio": "1.0.0",
    39.     "com.unity.modules.unitywebrequesttexture": "1.0.0",
    40.     "com.unity.modules.unitywebrequestwww": "1.0.0",
    41.     "com.unity.modules.vehicles": "1.0.0",
    42.     "com.unity.modules.video": "1.0.0",
    43.     "com.unity.modules.vr": "1.0.0",
    44.     "com.unity.modules.wind": "1.0.0",
    45.     "com.unity.modules.xr": "1.0.0"
    46.   }
    47. }
    48.  
     
  15. NoDumbQuestion

    NoDumbQuestion

    Joined:
    Nov 10, 2017
    Posts:
    186
    Are you still using Unity 2018.3 by any chance? (All my 2019 project have
    com.unity.package-manager-ui
    higher than 2.1.0)
    And I dont see Entities package. It possible that something go wrong internally when Burst not work with Entity.
     
    Deleted User likes this.
  16. eizenhorn

    eizenhorn

    Joined:
    Oct 17, 2016
    Posts:
    2,684
    Burst not related on Entities package.
    @SiriusRU
    But I too recommend use 2019 for latest Burst.
     
    Deleted User likes this.
  17. xoofx

    xoofx

    Unity Technologies

    Joined:
    Nov 5, 2016
    Posts:
    417
    Thanks for the report, we are going to investigate this problem.
     
    Deleted User likes this.
  18. Deleted User

    Deleted User

    Guest

    As I said above, yes, I am using Unity 2018.3.9f1. And this is true that the project does not contain an Entity package, although it's use is further were implied for creatures, NPCs, and some other things. But I added this package to the project, like - you never know, but no, in itself it did not change anything, so @eizenhorn is right, so it's not connected with issue here.

    Well, I have already tried to port project to 2019 version, briefly and without success, and now I should try again because
    I have made a separate empty project on the latest version of Unity 2019 with all the necessary packages - very glad to note that mentioned issue not occure there with all code samples from above. Definitely should have checked this like that earlier.

    Thank you very much for your help - although this does not solve the problem for 2018 version, which is sad, but it might actually solve issue at least for me, especially I was planning to move in for 2019 sooner or later anyway.

    It is lovely to hear that. Thank you!
     
  19. xoofx

    xoofx

    Unity Technologies

    Joined:
    Nov 5, 2016
    Posts:
    417
    @SiriusRU I'm not able to reproduce this with a very simple unit tests. Could you submit via the bug report a simple repro using the latest version of burst? (1.0.0-preview.6), post the link of the bug repro here so that I will work directly from it.
     
  20. Deleted User

    Deleted User

    Guest

    @xoofx sure. This link here?

    I also were wrong, trouble actually occure in 2019 version too -_-"
    It's Unity 2019.2.0a9 and burst 1.0.0 preview.6.
    Due to the fact that crash mostly does not happen immediately at first schedule - I thought that everything is okay - it's like working at first and after scheduling it's 2-10 times makes Unity instant crash and I just have to restart editor. That's exactly what happening in repro for me. Wonder what could possibly be the reason.

    If I do not use Mathematics and rely only on Vector3, Mathf, Quaternion, etc. - everything works stable. In fact, I am currently use a temporary solution that does not use Mathematics and it never crashes, although it uses Job with Burst almost constantly.
     
  21. xoofx

    xoofx

    Unity Technologies

    Joined:
    Nov 5, 2016
    Posts:
    417
    @SiriusRU could you post a screenshot of your CPU characteristics? (e.g using CPU-Z), I suspect that burst is generating some SSE4.x code that is actually not compatible with your CPU
     
  22. Deleted User

    Deleted User

    Guest

    Hm. If so, could you please tell - would it be fixable then?
    As I can see my CPU supports SSE4a, but not SSE4.1 or SSE4.2. Does it mean, that I am unable to fully use BurstCompiler?

    Coreinfo v3.31 - Dump information on system CPU and memory topology
    Copyright (C) 2008-2014 Mark Russinovich
    Sysinternals - www.sysinternals.com

    AMD Athlon(tm) II X2 280 Processor
    AMD64 Family 16 Model 6 Stepping 3, AuthenticAMD
    Microcode signature: 010000C8
    HTT * Multicore
    HYPERVISOR - Hypervisor is present
    VMX - Supports Intel hardware-assisted virtualization
    SVM * Supports AMD hardware-assisted virtualization
    X64 * Supports 64-bit mode

    SMX - Supports Intel trusted execution
    SKINIT * Supports AMD SKINIT

    NX * Supports no-execute page protection
    SMEP - Supports Supervisor Mode Execution Prevention
    SMAP - Supports Supervisor Mode Access Prevention
    PAGE1GB * Supports 1 GB large pages
    PAE * Supports > 32-bit physical addresses
    PAT * Supports Page Attribute Table
    PSE * Supports 4 MB pages
    PSE36 * Supports > 32-bit address 4 MB pages
    PGE * Supports global bit in page tables
    SS - Supports bus snooping for cache operations
    VME * Supports Virtual-8086 mode
    RDWRFSGSBASE - Supports direct GS/FS base access

    FPU * Implements i387 floating point instructions
    MMX * Supports MMX instruction set
    MMXEXT * Implements AMD MMX extensions
    3DNOW * Supports 3DNow! instructions
    3DNOWEXT * Supports 3DNow! extension instructions
    SSE * Supports Streaming SIMD Extensions
    SSE2 * Supports Streaming SIMD Extensions 2
    SSE3 * Supports Streaming SIMD Extensions 3
    SSSE3 - Supports Supplemental SIMD Extensions 3
    SSE4a * Supports Streaming SIMDR Extensions 4a
    SSE4.1 - Supports Streaming SIMD Extensions 4.1
    SSE4.2 - Supports Streaming SIMD Extensions 4.2

    AES - Supports AES extensions
    AVX - Supports AVX intruction extensions
    FMA - Supports FMA extensions using YMM state
    MSR * Implements RDMSR/WRMSR instructions
    MTRR * Supports Memory Type Range Registers
    XSAVE - Supports XSAVE/XRSTOR instructions
    OSXSAVE - Supports XSETBV/XGETBV instructions
    RDRAND - Supports RDRAND instruction
    RDSEED - Supports RDSEED instruction

    CMOV * Supports CMOVcc instruction
    CLFSH * Supports CLFLUSH instruction
    CX8 * Supports compare and exchange 8-byte instructions
    CX16 * Supports CMPXCHG16B instruction
    BMI1 - Supports bit manipulation extensions 1
    BMI2 - Supports bit manipulation extensions 2
    ADX - Supports ADCX/ADOX instructions
    DCA - Supports prefetch from memory-mapped device
    F16C - Supports half-precision instruction
    FXSR * Supports FXSAVE/FXSTOR instructions
    FFXSR * Supports optimized FXSAVE/FSRSTOR instruction
    MONITOR * Supports MONITOR and MWAIT instructions
    MOVBE - Supports MOVBE instruction
    ERMSB - Supports Enhanced REP MOVSB/STOSB
    PCLMULDQ - Supports PCLMULDQ instruction
    POPCNT * Supports POPCNT instruction
    LZCNT * Supports LZCNT instruction
    SEP * Supports fast system call instructions
    LAHF-SAHF * Supports LAHF/SAHF instructions in 64-bit mode
    HLE - Supports Hardware Lock Elision instructions
    RTM - Supports Restricted Transactional Memory instructions

    DE * Supports I/O breakpoints including CR4.DE
    DTES64 - Can write history of 64-bit branch addresses
    DS - Implements memory-resident debug buffer
    DS-CPL - Supports Debug Store feature with CPL
    PCID - Supports PCIDs and settable CR4.PCIDE
    INVPCID - Supports INVPCID instruction
    PDCM - Supports Performance Capabilities MSR
    RDTSCP * Supports RDTSCP instruction
    TSC * Supports RDTSC instruction
    TSC-DEADLINE - Local APIC supports one-shot deadline timer
    TSC-INVARIANT * TSC runs at constant rate
    xTPR - Supports disabling task priority messages

    EIST - Supports Enhanced Intel Speedstep
    ACPI - Implements MSR for power management
    TM - Implements thermal monitor circuitry
    TM2 - Implements Thermal Monitor 2 control
    APIC * Implements software-accessible local APIC
    x2APIC - Supports x2APIC

    CNXT-ID - L1 data cache mode adaptive or BIOS

    MCE * Supports Machine Check, INT18 and CR4.MCE
    MCA * Implements Machine Check Architecture
    PBE - Supports use of FERR#/PBE# pin

    PSN - Implements 96-bit processor serial number

    PREFETCHW * Supports PREFETCHW instruction

    Maximum implemented CPUID leaves: 00000005 (Basic), 8000001B (Extended).

    Up to this point, I thought my processor was quite suitable, I wouldn't say there were any problems.
     
    Last edited by a moderator: Mar 26, 2019
  23. xoofx

    xoofx

    Unity Technologies

    Joined:
    Nov 5, 2016
    Posts:
    417
    Yes, for now, it doesn't work on anything that is not SSE4.1/4.2

    We are evaluating if we can generate multiple codegen paths based on dynamic branching CPU supports at runtime, but we won't have a fix before next week.
     
    Deleted User likes this.
  24. xoofx

    xoofx

    Unity Technologies

    Joined:
    Nov 5, 2016
    Posts:
    417
    @SiriusRU we just released a new version of burst 1.0.0-preview.9 which is providing dynamic branching based CPU features available at runtime (both when entering playmode in the editor and from a player - only for Windows/Linux/Mac platforms). Could you check that it is resolving your issue?
     
  25. Deleted User

    Deleted User

    Guest

    Thank you for working on this. Well, I used the project attached to the report in Unity 2019.0.a9 and updated the packages. Burst kind of works, but for some reason, Jobs started work only on main thread. That's quite weird.
    But at least there is no crashes.

    See for "TestJob".
    I also increased the number of "for" iteration inside to make it litle bit longer and more obvious.


    With Burst "Enable Compilation" disabled.

    It would be probably right to mention that I'm going to change my CPU to another one with SSE4.1 + SSE4.2 support tomorrow, so I'm also not sure if I will be able to check Burst workability in same manner later.