Tests to check the determinism of the basic floating point arithmetic operations on different devices, using Unity and Rust.

This repo contains tests to check the determinism (consistency) of the basic floating point arithmetic operations (add, subtract, multiply, divide) on different devices. The arithmetic is performed both in a managed C# environment, as well as via external calls to a native binary (written in Rust) for comparison. Determinism has many applications, and is essential for some real-time networking paradigms in video games.

Shows image of completed test of 2002084 operations with no errors.

Tests normal numbers, denormal numbers, NaN and infinities, each against themselves and against each other. See all tests in the DeterminismTest class. It does not currently test the consistency of other operations, like hardware trigonometry (note that these can be implemented in software provided the basic operations are deterministic; see Rapier for an example of cross platform float determinism using this approach).

Disclaimer

The author of this repo is not an expert in floating point arithmetic determinism. If you have any improvements to add please feel free to contribute or correct any oversights.

Results

Platform Device Backend Float errors Dfloat errors Notes
Windows 10 Intel(R) Core(TM) i7-10700K Editor/IL2CPP 0 0 IL2CPP used as ground truth
Android Samsung Galaxy S6 IL2CPP 0 0

Where Float errors refers to arithmetic run in the managed C# environment, and Dfloat errors in the calls to the native binary.

Notes

  • Operations involving NaN floats return non-deterministic results. This should not be an issue for applications that require determinism, as either
    • NaNs create serious enough bugs that desyncs no longer matter.
    • The developer can choose to check for NaNs after each operation and resolve the issue there (this repo simply treats all NaN results as if they were the same bit sequence).
  • Unity's documentation does not make any statement on float determinism either way, so even with consistent results there is no guarantee future versions do not change this.
  • ARMv7 apparently handles denormal numbers differently from ARMv8, so should not be a surprise if it desyncs there.
  • Not sure if the .NET runtime itself makes any guarantee of cross platform float determinism, or has any settings for that.
  • Calls to native binaries in C# have a lot of overhead, so using it to solve determinism is not really practical where performance is critical, and is used here mainly for comparison.
  • Casting to and from ints is not tested. This operation is probably required to be deterministic for most applications and should be explored.

Running the tests

You can run the tests by loading the pre-built Windows or Android builds on your devices. If you want to test on other platforms, build the binary for it per the steps in the Native Rust Binaries section. To make your own Unity builds, do the following:

  • Open the Unity project. (It contains pre-built binaries for Windows and Android, as well as the files used as ground truth. If you want to test on other platforms, build the binary for it per the steps below.)
  • Open the Main scene and press play and Run test to validate the test is functioning correctly. It will display any arithmetic results that did not match the ground truth (up to DeterminismTest.LogOutputLimit) as well as a summary of all the results.
  • Build to your target platform to run the test on it.
  • If you want to re-generate the random numbers used in the test, select the Generate random inputs + ground truth button. This will write a file containing randomly generated floats to use for tests, as well as the results of the tests using arithmetic in the managed environment and using the native binary.

Building the native Rust binaries

  • Install Rust
    • For Windows run cargo build --target x86_64-pc-windows-msvc --release
    • For Android, install cargo-ndk. Run cargo ndk -t aarch64-linux-android build --release
    • For other platforms...no idea? The author learned Rust specifically for this experiment :)
Similar Resources

CSE-7th-Semester-IIT-KGP - Tests, programming assignments and their solution for some courses offered by Department of Computer Science and Engineering, IIT Kharagpur

CSE-7th-Semester-IIT-KGP Disclaimer: Do not copy codes though. Heavy penalization for plagiarism. Programming assignments and their solution for some

Dec 30, 2021

Generalized easy to use SPI library for Arduino designed mainly for immense data transfer through multiple slaves. This library features Cyclic Redundancy Check (CRC) and user defined data transfer which inspired by Nick Gammon.

SPI Master and Slave Library If you don't have VS Code you can install from here. After downloading click extensions and type and install PlatformIO I

Oct 6, 2021

Tests and validation for the Hive Helsinki GET_Next_Line project.

gnl-eval Tests and validation for the Hive Helsinki GET_Next_Line project. This is not meant to completely replace careful evaluation, but to give som

May 12, 2022

A collection of tools, libraries, and tests for Vulkan shader compilation.

Shaderc A collection of tools, libraries and tests for shader compilation. At the moment it includes: glslc, a command line compiler for GLSL/HLSL to

Nov 27, 2022

LoadLibrary for offensive operations

DarkLoadLibrary LoadLibrary for offensive operations. How does is work? https://www.mdsec.co.uk/2021/06/bypassing-image-load-kernel-callbacks/ Usage D

Nov 27, 2022

Azure Outlook Command & Control (C2) - Remotely control a compromised Windows Device from your Outlook mailbox. Threat Emulation Tool for North Korean APT InkySquid / ScarCruft / APT37. TTP: Use Microsoft Graph API for C2 Operations.

Azure Outlook Command & Control (C2) - Remotely control a compromised Windows Device from your Outlook mailbox. Threat Emulation Tool for North Korean APT InkySquid / ScarCruft / APT37. TTP: Use Microsoft Graph API for C2 Operations.

Azure Outlook C2 Azure Outlook Command & Control that uses Microsoft Graph API for C2 communications & data exfiltration. Remotely Control a compromis

Nov 29, 2022

Grand Programs for every Data Structure including all their operations

Grand-Programs-UE20CS203 Grand Programs for every Data Structure including all their operations Some idioms that I use, so you won't get confused I pr

Jul 28, 2022

Finite Field Operations on GPGPU

ff-gpu Finite Field Operations on GPGPU Background In recent times, I've been interested in Finite Field operations, so I decided to implement few fie

Nov 7, 2022

Python module for geometric Line operations

FastLine Python module for geometric Line operations implmented in C++ then binded to python, and it is optimized for speed. I created this module to

Nov 22, 2022
tabbed window manager that can tile windows inside floating containers

shod ┌───────────────────────┐ │ │ ┌─────┼────

Nov 19, 2022
A fwakin floating window manager, that just works perfectly.
A fwakin floating window manager, that just works perfectly.

ewm ( Elite optimized* Window Manager ) + ewm is a very simple and lightweight floating window manager. + I will try to stay under 400 SLOC. Features

Nov 1, 2022
A console application using CPP that manages the guest details and check in and quarantine period of individual

A console application using CPP that manages the guest details and check in and quarantine period of individual(14 days). Efficient searching of guest, sorting and availability of room details can be found using the applications.

Nov 24, 2021
A basic, MQTT integration point service for the Waveshare 8 channel relay board

relayboard-control A basic, MQTT integration point service for the Waveshare 8 channel relay board. This was built specifically for our own home's rel

Mar 22, 2022
Identify I2C devices from a database of the most popular I2C sensors and other devices

I2C Detective Identify I2C devices from a database of the most popular I2C sensors and other devices. For more information see http://www.technoblogy.

Oct 14, 2022
This is a repository entirely dedicated to all kind of questions ranging from basic DSA to CP. It aims to provide a solution to different questions. 📚

?? CP-DSA-Questions ?? This is a repository entirely dedicated to all kind of questions ranging from basic DSA to CP. It aims to provide a solution to

Oct 6, 2022
A single-header C/C++ library for parsing and evaluation of arithmetic expressions

ceval A C/C++ header for parsing and evaluation of arithmetic expressions. [README file is almost identical to that of the ceval library] Functions ac

Oct 10, 2022
A single-header C/C++ library for parsing and evaluation of arithmetic expressions

ceval A C/C++ header for parsing and evaluation of arithmetic expressions. [README file is almost identical to that of the ceval library] Functions ac

Oct 10, 2022
A C/C++ library for parsing and evaluation of arithmetic expressions.

ceval A C/C++ header for parsing and evaluation of arithmetic expressions. Functions accessibe from main() Function Argument(s) Return Value ceval_res

Nov 8, 2022
This is a very short tool that predicts the number of cycles and execution time in Fulcrum when the operands and operations are known.

fulcrum-analytical-tool This is a very short tool that predicts the number of cycles and execution time in Fulcrum when the operands and operations ar

Feb 6, 2022