Skip to content
This repository was archived by the owner on Apr 28, 2025. It is now read-only.

Add exhaustive/extensive tests #364

Closed
wants to merge 4 commits into from

Conversation

tgross35
Copy link
Contributor

@tgross35 tgross35 commented Dec 21, 2024

Add a generator that will test all inputs for input spaces u32::MAX or smaller (e.g. single-argument f32 routines). For anything larger, still run approximately u32::MAX tests, but distribute inputs evenly across the function domain.

Since we often only want to run one of these tests at a time, this implementation parallelizes within each test using rayon. A custom test runner is used so a progress bar is possible.

Specific tests must be enabled by setting the LIBM_EXTENSIVE_TESTS environment variable, e.g.

LIBM_EXTENSIVE_TESTS=all_f16,cos,cosf cargo run ...

Testing on a recent machine, most tests take about two minutes or less. The Bessel functions are quite slow and take closer to 10 minutes, and FMA is increased to run for about the same.

@tgross35 tgross35 marked this pull request as draft December 21, 2024 06:55
@tgross35
Copy link
Contributor Author

tgross35 commented Dec 21, 2024

A start at "extensive" tests that run up to u32::MAX inputs, only on requested functions. Requested tests are set via env with a few different options:

# Run one or more exhaustive test
LIBM_EXTENSIVE_TESTS=sinf,cosf cargo t --features test-multiprecision --release -- extensive
# Run all `f32` or `f64` tests
LIBM_EXTENSIVE_TESTS=all_f32 cargo t --features test-multiprecision --release -- extensive
# Run everything
LIBM_EXTENSIVE_TESTS=all cargo t --features test-multiprecision --release -- extensive

For single-arg f32 it tests with all possible values in the domain. For f64, it runs u32::MAX tests with a logspace. For functions with N > 1 arguments, it currently does a logspace for each arg, each with u32::MAX^(1/N) steps.

I ran a handful of tests on my 24-core machine, the current setup with Rayon ranges about 10m-1h depending on the test. That can probably be improved, I haven't looked at this from a perf perspective at all (though one thing I noticed quickly from htop is there is a lot of time spent in kthreads, maybe I need to double check if Rayon is doing batching).

After I get this a bit better sorted out, I am going to hook up CI to run relevant tests when source files change. Current state is very scratchy.

@beetrees you may be interested since I know you suggested this a few times.

@tgross35
Copy link
Contributor Author

I'm using the mimic harness so I can skip tests at runtime and show a progress bar, sample output.

running 90 tests
test mp_extensive_acos       ... ignored, extensive tests are only run if specified in RUST_LIBM_EXTENSIVE
test mp_extensive_acosf      ... starting extensive tests for `acosf`
[9m  100%] #################### acosf 4,294,967,295/4,294,967,295: 7,672,836.6102/s eta 0s
ok
test mp_extensive_acosh      ... ignored, extensive tests are only run if specified in RUST_LIBM_EXTENSIVE
test mp_extensive_acoshf     ... starting extensive tests for `acoshf`
[5m  73 %] ###############----- acoshf 3,139,620,000/4,294,967,295: 3,544,521.3401/s eta 5m (1.6715916e36,)

@tgross35
Copy link
Contributor Author

(though one thing I noticed quickly from htop is there is a lot of time spent in kthreads, maybe I need to double check if Rayon is doing batching)

Way faster with chunking, acosf (sample test with a small domain) completes in two minutes on my machine, asinhf (sample with an unbounded domain) completes in 5 minutes.

@tgross35 tgross35 force-pushed the extensive branch 3 times, most recently from ee66993 to 6da3286 Compare December 22, 2024 05:53
@tgross35 tgross35 changed the title [WIP] Add exhaustive/extensive tests Add exhaustive/extensive tests Dec 22, 2024
@tgross35 tgross35 force-pushed the extensive branch 21 times, most recently from 0b9a08c to 8ece7f7 Compare December 28, 2024 05:13
@tgross35 tgross35 force-pushed the extensive branch 5 times, most recently from a04c94e to d983a94 Compare December 30, 2024 10:50
@tgross35 tgross35 force-pushed the extensive branch 5 times, most recently from 2b59b84 to 06e329c Compare January 2, 2025 10:38
@tgross35 tgross35 marked this pull request as ready for review January 2, 2025 10:39
@tgross35
Copy link
Contributor Author

tgross35 commented Jan 2, 2025

One last thing I need to do here is figure out how to reduce the scope for jnf / ynf, on my machine MPFR hits GNU MP: Cannot allocate memory (size=3458764513820540808).

Add a generator that will test all inputs for input spaces `u32::MAX` or
smaller (e.g. single-argument `f32` routines).  For anything larger,
still run approximately `u32::MAX` tests, but distribute inputs evenly
across the function domain.

Since we often only want to run one of these tests at a time, this
implementation parallelizes within each test using `rayon`. A custom
test runner is used so a progress bar is possible.

Specific tests must be enabled by setting the `LIBM_EXTENSIVE_TESTS`
environment variable, e.g.

    LIBM_EXTENSIVE_TESTS=all_f16,cos,cosf cargo run ...

Testing on a recent machine, most tests take about two minutes or less.
The Bessel functions are quite slow and take closer to 10 minutes, and
FMA is increased to run for about the same.
Update the script to produce, in addition to the simple text list, a
JSON file listing routine names, the types they work with, and the
source files that contain a function with the routine name. This gets
consumed by another script and will be used to determine which extensive
CI jobs to run.
Add a CI job with a dynamically calculated matrix that runs extensive
jobs on changed files. This makes use of the new
`function-definitions.json` file to determine which changed files
require full tests for a routine to run.
@tgross35
Copy link
Contributor Author

tgross35 commented Jan 2, 2025

I wanted to move this to a rust-lang branch so I can point other PRs at it. Reopened as #388.

@tgross35 tgross35 closed this Jan 2, 2025
@tgross35 tgross35 deleted the extensive branch January 6, 2025 02:56
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant