Skip to content

feat: simd double unary math ops - #19768

Open
clintropolis wants to merge 1 commit into
apache:masterfrom
clintropolis:simd-double-math-ops
Open

feat: simd double unary math ops#19768
clintropolis wants to merge 1 commit into
apache:masterfrom
clintropolis:simd-double-math-ops

Conversation

@clintropolis

Copy link
Copy Markdown
Member

Description

Adds a bunch of simd optimizations of the remaining double unary operators. The operators do not have direct intrinsics but are backed by a vectorized math library that depends on platform and jdk build, so performance may vary.

Along the way I found sinh, cosh, and tanh were not wired up to SQL, so have added those
Testing with a M1 mac I generally saw a pretty nice improvement:

SELECT SUM(LN(double1)) FROM expressions
SELECT SUM(LN(long1)) FROM expressions
SELECT SUM(EXP(double1)) FROM expressions
SELECT SUM(EXP(long1)) FROM expressions
SELECT SUM(LOG10(double1)) FROM expressions
SELECT SUM(LOG10(long1)) FROM expressions
SELECT SUM(CBRT(double1)) FROM expressions
SELECT SUM(CBRT(long1)) FROM expressions
SELECT SUM(SIN(double1)) FROM expressions
SELECT SUM(SIN(long1)) FROM expressions
SELECT SUM(COS(double1)) FROM expressions
SELECT SUM(COS(long1)) FROM expressions
SELECT SUM(TAN(double1)) FROM expressions
SELECT SUM(TAN(long1)) FROM expressions
SELECT SUM(ASIN(double1)) FROM expressions
SELECT SUM(ASIN(long1)) FROM expressions
SELECT SUM(ACOS(double1)) FROM expressions
SELECT SUM(ACOS(long1)) FROM expressions
SELECT SUM(ATAN(double1)) FROM expressions
SELECT SUM(ATAN(long1)) FROM expressions
SELECT SUM(SINH(double1)) FROM expressions
SELECT SUM(SINH(long1)) FROM expressions
SELECT SUM(COSH(double1)) FROM expressions
SELECT SUM(COSH(long1)) FROM expressions
SELECT SUM(TANH(double1)) FROM expressions
SELECT SUM(TANH(long1)) FROM expressions
Benchmark                        (complexCompression)  (deferExpressionDimensions)  (jsonObjectStorageEncoding)  (query)  (rowsPerSegment)  (schemaType)  (storageType)  (stringEncoding)  (useVectorApi)  (vectorize)  Mode  Cnt   Score   Error  Units
SqlExpressionBenchmark.querySql                  NONE                 singleString                        SMILE       71           1500000      explicit           MMAP              UTF8           false        force  avgt    5  30.285 ± 1.411  ms/op
SqlExpressionBenchmark.querySql                  NONE                 singleString                        SMILE       71           1500000      explicit           MMAP              UTF8            true        force  avgt    5  12.606 ± 2.843  ms/op
SqlExpressionBenchmark.querySql                  NONE                 singleString                        SMILE       72           1500000      explicit           MMAP              UTF8           false        force  avgt    5  28.189 ± 1.549  ms/op
SqlExpressionBenchmark.querySql                  NONE                 singleString                        SMILE       72           1500000      explicit           MMAP              UTF8            true        force  avgt    5  14.588 ± 0.554  ms/op
SqlExpressionBenchmark.querySql                  NONE                 singleString                        SMILE       73           1500000      explicit           MMAP              UTF8           false        force  avgt    5  29.777 ± 1.107  ms/op
SqlExpressionBenchmark.querySql                  NONE                 singleString                        SMILE       73           1500000      explicit           MMAP              UTF8            true        force  avgt    5  10.653 ± 0.623  ms/op
SqlExpressionBenchmark.querySql                  NONE                 singleString                        SMILE       74           1500000      explicit           MMAP              UTF8           false        force  avgt    5  22.288 ± 4.846  ms/op
SqlExpressionBenchmark.querySql                  NONE                 singleString                        SMILE       74           1500000      explicit           MMAP              UTF8            true        force  avgt    5  11.983 ± 0.744  ms/op
SqlExpressionBenchmark.querySql                  NONE                 singleString                        SMILE       75           1500000      explicit           MMAP              UTF8           false        force  avgt    5  35.076 ± 1.976  ms/op
SqlExpressionBenchmark.querySql                  NONE                 singleString                        SMILE       75           1500000      explicit           MMAP              UTF8            true        force  avgt    5  13.469 ± 0.812  ms/op
SqlExpressionBenchmark.querySql                  NONE                 singleString                        SMILE       76           1500000      explicit           MMAP              UTF8           false        force  avgt    5  33.361 ± 0.889  ms/op
SqlExpressionBenchmark.querySql                  NONE                 singleString                        SMILE       76           1500000      explicit           MMAP              UTF8            true        force  avgt    5  14.979 ± 0.777  ms/op
SqlExpressionBenchmark.querySql                  NONE                 singleString                        SMILE       79           1500000      explicit           MMAP              UTF8           false        force  avgt    5  33.913 ± 1.415  ms/op
SqlExpressionBenchmark.querySql                  NONE                 singleString                        SMILE       79           1500000      explicit           MMAP              UTF8            true        force  avgt    5  14.416 ± 1.236  ms/op
SqlExpressionBenchmark.querySql                  NONE                 singleString                        SMILE       80           1500000      explicit           MMAP              UTF8           false        force  avgt    5  28.261 ± 1.315  ms/op
SqlExpressionBenchmark.querySql                  NONE                 singleString                        SMILE       80           1500000      explicit           MMAP              UTF8            true        force  avgt    5  17.651 ± 1.072  ms/op
SqlExpressionBenchmark.querySql                  NONE                 singleString                        SMILE       81           1500000      explicit           MMAP              UTF8           false        force  avgt    5  34.117 ± 1.413  ms/op
SqlExpressionBenchmark.querySql                  NONE                 singleString                        SMILE       81           1500000      explicit           MMAP              UTF8            true        force  avgt    5  15.238 ± 0.762  ms/op
SqlExpressionBenchmark.querySql                  NONE                 singleString                        SMILE       82           1500000      explicit           MMAP              UTF8           false        force  avgt    5  28.001 ± 1.855  ms/op
SqlExpressionBenchmark.querySql                  NONE                 singleString                        SMILE       82           1500000      explicit           MMAP              UTF8            true        force  avgt    5  18.244 ± 0.971  ms/op
SqlExpressionBenchmark.querySql                  NONE                 singleString                        SMILE       83           1500000      explicit           MMAP              UTF8           false        force  avgt    5  46.805 ± 2.455  ms/op
SqlExpressionBenchmark.querySql                  NONE                 singleString                        SMILE       83           1500000      explicit           MMAP              UTF8            true        force  avgt    5  17.212 ± 0.605  ms/op
SqlExpressionBenchmark.querySql                  NONE                 singleString                        SMILE       84           1500000      explicit           MMAP              UTF8           false        force  avgt    5  47.951 ± 1.824  ms/op
SqlExpressionBenchmark.querySql                  NONE                 singleString                        SMILE       84           1500000      explicit           MMAP              UTF8            true        force  avgt    5  23.149 ± 0.962  ms/op
SqlExpressionBenchmark.querySql                  NONE                 singleString                        SMILE       85           1500000      explicit           MMAP              UTF8           false        force  avgt    5  28.384 ± 0.810  ms/op
SqlExpressionBenchmark.querySql                  NONE                 singleString                        SMILE       85           1500000      explicit           MMAP              UTF8            true        force  avgt    5  11.907 ± 1.053  ms/op
SqlExpressionBenchmark.querySql                  NONE                 singleString                        SMILE       86           1500000      explicit           MMAP              UTF8           false        force  avgt    5  22.639 ± 1.056  ms/op
SqlExpressionBenchmark.querySql                  NONE                 singleString                        SMILE       86           1500000      explicit           MMAP              UTF8            true        force  avgt    5  13.509 ± 0.615  ms/op
SqlExpressionBenchmark.querySql                  NONE                 singleString                        SMILE       87           1500000      explicit           MMAP              UTF8           false        force  avgt    5  29.227 ± 5.817  ms/op
SqlExpressionBenchmark.querySql                  NONE                 singleString                        SMILE       87           1500000      explicit           MMAP              UTF8            true        force  avgt    5  12.091 ± 0.466  ms/op
SqlExpressionBenchmark.querySql                  NONE                 singleString                        SMILE       88           1500000      explicit           MMAP              UTF8           false        force  avgt    5  22.917 ± 0.659  ms/op
SqlExpressionBenchmark.querySql                  NONE                 singleString                        SMILE       88           1500000      explicit           MMAP              UTF8            true        force  avgt    5  14.683 ± 1.046  ms/op
SqlExpressionBenchmark.querySql                  NONE                 singleString                        SMILE       89           1500000      explicit           MMAP              UTF8           false        force  avgt    5  34.433 ± 2.669  ms/op
SqlExpressionBenchmark.querySql                  NONE                 singleString                        SMILE       89           1500000      explicit           MMAP              UTF8            true        force  avgt    5  15.296 ± 0.497  ms/op
SqlExpressionBenchmark.querySql                  NONE                 singleString                        SMILE       90           1500000      explicit           MMAP              UTF8           false        force  avgt    5  27.284 ± 0.832  ms/op
SqlExpressionBenchmark.querySql                  NONE                 singleString                        SMILE       90           1500000      explicit           MMAP              UTF8            true        force  avgt    5  16.977 ± 1.177  ms/op
SqlExpressionBenchmark.querySql                  NONE                 singleString                        SMILE       91           1500000      explicit           MMAP              UTF8           false        force  avgt    5  38.460 ± 1.404  ms/op
SqlExpressionBenchmark.querySql                  NONE                 singleString                        SMILE       91           1500000      explicit           MMAP              UTF8            true        force  avgt    5  16.669 ± 0.656  ms/op
SqlExpressionBenchmark.querySql                  NONE                 singleString                        SMILE       92           1500000      explicit           MMAP              UTF8           false        force  avgt    5  22.888 ± 0.748  ms/op
SqlExpressionBenchmark.querySql                  NONE                 singleString                        SMILE       92           1500000      explicit           MMAP              UTF8            true        force  avgt    5  17.944 ± 1.868  ms/op
SqlExpressionBenchmark.querySql                  NONE                 singleString                        SMILE       93           1500000      explicit           MMAP              UTF8           false        force  avgt    5  35.114 ± 2.037  ms/op
SqlExpressionBenchmark.querySql                  NONE                 singleString                        SMILE       93           1500000      explicit           MMAP              UTF8            true        force  avgt    5  16.522 ± 1.252  ms/op
SqlExpressionBenchmark.querySql                  NONE                 singleString                        SMILE       94           1500000      explicit           MMAP              UTF8           false        force  avgt    5  22.599 ± 0.924  ms/op
SqlExpressionBenchmark.querySql                  NONE                 singleString                        SMILE       94           1500000      explicit           MMAP              UTF8            true        force  avgt    5  17.941 ± 0.951  ms/op
SqlExpressionBenchmark.querySql                  NONE                 singleString                        SMILE       95           1500000      explicit           MMAP              UTF8           false        force  avgt    5  35.517 ± 0.967  ms/op
SqlExpressionBenchmark.querySql                  NONE                 singleString                        SMILE       95           1500000      explicit           MMAP              UTF8            true        force  avgt    5  37.003 ± 1.007  ms/op
SqlExpressionBenchmark.querySql                  NONE                 singleString                        SMILE       96           1500000      explicit           MMAP              UTF8           false        force  avgt    5  20.983 ± 0.902  ms/op
SqlExpressionBenchmark.querySql                  NONE                 singleString                        SMILE       96           1500000      explicit           MMAP              UTF8            true        force  avgt    5  16.690 ± 0.919  ms/op

@FrankChen021 FrankChen021 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Severity Findings
P0 0
P1 1
P2 0
P3 0
Total 1
Severity Findings
P0 0
P1 1
P2 0
P3 0
Total 1

Reviewed 36 of 36 changed files.


This is an automated review by Codex GPT-5.6-Sol

final int upperBound = SPECIES.loopBound(currentSize);
int i = 0;
for (; i < upperBound; i += laneCount) {
DoubleVector.fromArray(SPECIES, input, i).lanewise(VectorOperators.SIN).intoArray(outValues, i);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P1] Keep transcendental results stable across JIT warmup

VectorOperators.SIN initially matches Math.sin, but compiled SLEEF/SVML output can differ. On JDK 25/AArch64, this exact loop changed 665 of 8,192 lanes after warmup; most other added VO_MATHLIB operations also diverged. Compilation mid-query can therefore give identical inputs different bits, affecting exact filters or group keys. Keep these operations scalar unless stable semantics are established, and add warmed parity tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants